buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long a = sc.NextLong(); long b = sc.NextLong(); long c = sc.NextLong(); long k = sc.NextLong(); long answer = 0; if (k > a) { k -= a; answer += a; } else { answer += a; k = 0; } if (k > b) { k -= b; } else { k = 0; } if (k > 0) { answer -= k; } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long a = sc.NextLong(); long b = sc.NextLong(); long c = sc.NextLong(); long k = sc.NextLong(); long answer = 0; if (k > a) { k -= a; answer += a; } else { answer += k; k = 0; } if (k > b) { k -= b; } else { k = 0; } if (k > 0) { answer -= k; } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22]]
8
440
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace Atcoder { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var input = ReadTexts(); long a = input[0].ToLong(); long b = input[1].ToLong(); long c = input[2].ToLong(); long k = input[3].ToLong(); if (k <= a) { return a; } else if (k <= a + b) { return a; } else { return a - (k - a - b); } } #region Console public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } #endregion } public static class CastExtention { public static long ToLong(this string a) { return long.Parse(a); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace Atcoder { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var input = ReadTexts(); long a = input[0].ToLong(); long b = input[1].ToLong(); long c = input[2].ToLong(); long k = input[3].ToLong(); if (k <= a) { return k; } else if (k <= a + b) { return a; } else { return a - (k - a - b); } } #region Console public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } #endregion } public static class CastExtention { public static long ToLong(this string a) { return long.Parse(a); } } }
[["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 22]]
8
234
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.AtCoder_Begginer_Contest_167 { class B { 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 = CalcSum(A, B, C, K); Console.WriteLine(sum); // Console.ReadKey(); } private static int CalcSum(int A, int B, int C, int K) { int k = K; int sum = 0; if (k <= A) { sum += k * 1; return sum; } else { sum += A; k = k - A; } if (k <= B) { sum += k * 0; return sum; } else { sum += B; k = k - B; } if (k <= C) { sum += k * -1; return sum; } else { sum += C; k = k - C; } return sum; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.AtCoder_Begginer_Contest_167 { class B { 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 = CalcSum(A, B, C, K); Console.WriteLine(sum); // Console.ReadKey(); } private static int CalcSum(int A, int B, int C, int K) { int k = K; int sum = 0; if (k <= A) { sum += k * 1; return sum; } else { sum += A; k = k - A; } if (k <= B) { sum += k * 0; return sum; } else { sum += B * 0; k = k - B; } if (k <= C) { sum += k * -1; return sum; } else { sum += C * -1; k = k - C; } return sum; } } }
[["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 12, 241, 0, 33], ["+", 0, 1, 0, 11, 12, 16, 12, 241, 0, 203]]
8
263
5
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var a = inputs[0]; var b = inputs[1]; var c = inputs[2]; var k = inputs[3]; if (a >= k) { Console.WriteLine(a); return; } else { k -= a; } if (b >= k) { Console.WriteLine(a); return; } else { k -= b; } Console.WriteLine(a - k); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var a = inputs[0]; var b = inputs[1]; var c = inputs[2]; var k = inputs[3]; if (a >= k) { Console.WriteLine(k); return; } else { k -= a; } if (b >= k) { Console.WriteLine(a); return; } else { k -= b; } Console.WriteLine(a - k); } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
146
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace AtCorder { public static class Program { static public void Main(string[] args) { var input = Console.ReadLine().Split().Select(long.Parse).ToArray(); // var ans = 0; if (input[0] >= input[3]) { Console.WriteLine(input[3].ToString()); } else if ((input[0] + input[1]) >= input[3]) { Console.WriteLine(input[3].ToString()); } else if (((input[0] + input[1] + input[2]) >= input[3])) { var num = input[0] + input[1]; input[3] = input[3] - num; num = input[0] - input[3]; Console.WriteLine(num.ToString()); } else { Console.WriteLine(0.ToString()); } // for (var i = input[3]; i > 0; i--) //{ // if (input[0] > 0) // { // ans = ans + 1; // input[0] = input[0] - 1; // } // else if (input[1] > 0) // { // ans = ans + 0; // input[1] = input[1] - 1; // } // else // { // ans = ans - 1; // input[2] = input[2] - 1; // } //} } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace AtCorder { public static class Program { static public void Main(string[] args) { var input = Console.ReadLine().Split().Select(long.Parse).ToArray(); // var ans = 0; if (input[0] >= input[3]) { Console.WriteLine(input[3].ToString()); } else if ((input[0] + input[1]) >= input[3]) { Console.WriteLine(input[0].ToString()); } else if (((input[0] + input[1] + input[2]) >= input[3])) { var num = input[0] + input[1]; input[3] = input[3] - num; num = input[0] - input[3]; Console.WriteLine(num.ToString()); } else { Console.WriteLine(0.ToString()); } // for (var i = input[3]; i > 0; i--) //{ // if (input[0] > 0) // { // ans = ans + 1; // input[0] = input[0] - 1; // } // else if (input[1] > 0) // { // ans = ans + 0; // input[1] = input[1] - 1; // } // else // { // ans = ans - 1; // input[2] = input[2] - 1; // } //} } } }
[["-", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203]]
8
240
2
using System; class Program { static void Main(string[] args) { int a, b, k; string[] s = Console.ReadLine().Split(' '); a = int.Parse(s[0]); b = int.Parse(s[1]); k = int.Parse(s[3]); if (k <= a) { Console.WriteLine(a); } else if (k - a < b) { Console.WriteLine(a); } else { Console.WriteLine(2 * a - k + b); } } }
using System; class Program { static void Main(string[] args) { int a, b, k; string[] s = Console.ReadLine().Split(' '); a = int.Parse(s[0]); b = int.Parse(s[1]); k = int.Parse(s[3]); if (k <= a) { Console.WriteLine(k); } else if (k - a < b) { Console.WriteLine(a); } else { Console.WriteLine(2 * a - k + b); } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
128
2
using System; namespace AtCoder { public class Program { public static void Main() { ulong a, b, c, k; string line = System.Console.ReadLine(); string[] input = line.Split(' '); a = ulong.Parse(input[0]); b = ulong.Parse(input[1]); c = ulong.Parse(input[2]); k = ulong.Parse(input[3]); ulong rest = 0; if (k <= a) rest = k; else if (k <= a + b) rest = a; else { rest = a - (k - (a + b)); } Console.WriteLine(rest.ToString()); } } }
using System; namespace AtCoder { public class Program { public static void Main() { long a, b, c, k; string line = System.Console.ReadLine(); string[] input = line.Split(' '); a = long.Parse(input[0]); b = long.Parse(input[1]); c = long.Parse(input[2]); k = long.Parse(input[3]); long rest = 0; if (k <= a) rest = k; else if (k <= a + b) rest = a; else { rest = a - (k - (a + b)); } Console.WriteLine(rest.ToString()); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199]]
8
158
12
public class Hello { public static void Main() { string line1 = System.Console.ReadLine(); string[] array = line1.Split(' '); int a = int.Parse(array[0]); int b = int.Parse(array[1]); int c = int.Parse(array[2]); int k = int.Parse(array[3]); int result = 0; if (a > k) { result = a; } else { result += a; k -= a; if (k > 0) { if (b <= k) { k -= b; if (k > 0) { result -= k; } } } } System.Console.WriteLine(result); } }
public class Hello { public static void Main() { string line1 = System.Console.ReadLine(); string[] array = line1.Split(' '); int a = int.Parse(array[0]); int b = int.Parse(array[1]); int c = int.Parse(array[2]); int k = int.Parse(array[3]); int result = 0; if (a > k) { result = k; } else { result += a; k -= a; if (k > 0) { if (b <= k) { k -= b; if (k > 0) { result -= k; } } } } System.Console.WriteLine(result); } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22]]
8
159
2
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 _ = LnLngs(); var A = _[0]; var B = _[1]; var C = _[2]; var K = _[3]; if (A >= K) { print(A); } else if (A + B >= K) { print(A); } else { var min = K - A - B; print(A - min); } } 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, int mod = (int)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 _ = LnLngs(); var A = _[0]; var B = _[1]; var C = _[2]; var K = _[3]; if (A >= K) { print(K); } else if (A + B >= K) { print(A); } else { var min = K - A - B; print(A - min); } } 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, int mod = (int)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; } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
979
2
using System; using static System.Console; using System.Linq; namespace Main { class Program { static void Main(string[] args) { long[] tmp = ReadLine().Split(' ').Select(long.Parse).ToArray(); long A = tmp[0]; long B = tmp[1]; long C = tmp[2]; long K = tmp[3]; if (K <= A) { WriteLine(K); } else if (K <= A + B) { WriteLine(A); } else { WriteLine(K - 2 * B); } } } }
using System; using static System.Console; using System.Linq; namespace Main { class Program { static void Main(string[] args) { long[] tmp = ReadLine().Split(' ').Select(long.Parse).ToArray(); long A = tmp[0]; long B = tmp[1]; long C = tmp[2]; long K = tmp[3]; if (K <= A) { WriteLine(K); } else if (K <= A + B) { WriteLine(A); } else { WriteLine(2 * A + B - K); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
133
6
using System; 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; int remain = k; if (a >= k) { Console.WriteLine(a); return; } else if (a != 0) { sum += a; remain -= a; } if (b >= remain) { Console.WriteLine(sum); return; } else if (b != 0) { remain -= b; } sum -= remain; Console.WriteLine(sum); } }
using System; 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; int remain = k; if (a >= k) { Console.WriteLine(k); return; } else if (a != 0) { sum += a; remain -= a; } if (b >= remain) { Console.WriteLine(sum); return; } else if (b != 0) { remain -= b; } sum -= remain; Console.WriteLine(sum); } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
173
2
using System; using System.Linq; using System.Collections.Generic; namespace ABC167 { class B { static void Main(string[] args) { var ABCK = Console.ReadLine().Split().Select(long.Parse).ToArray(); var A = ABCK[0]; var B = ABCK[1]; var C = ABCK[2]; var K = ABCK[3]; var res = 0L; if (K <= A) res = A; else if (K <= A + B) res = A; else res = A + (K - (A + B)) * -1; Console.WriteLine(res); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC167 { class B { static void Main(string[] args) { var ABCK = Console.ReadLine().Split().Select(long.Parse).ToArray(); var A = ABCK[0]; var B = ABCK[1]; var C = ABCK[2]; var K = ABCK[3]; var res = 0L; if (K <= A) res = K; else if (K <= A + B) res = A; else res = A + (K - (A + B)) * -1; Console.WriteLine(res); } } }
[["-", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22]]
8
143
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication6 { class Program { static void Main(string[] args) { // var length = c2i(RL()); var rl = spr(RL()).Select(x => c2i(x)).ToList(); var A = rl[0]; var B = rl[1]; var C = rl[2]; var K = rl[3]; long ret = 0; if (K <= A) { ret = A; } else if (K <= (A + B)) { ret = A; } else { ret = A + ((A + B) - K); } Console.WriteLine((ret)); // Console.ReadLine(); } static string RL() { return Console.ReadLine().Trim(); } static IEnumerable<string> spr(string s) { return s.Split(' '); } static Int64 c2i(string c) { return Int64.Parse(c); } // static double c2d(string c) { return double.Parse(c); } static string bool2ret(bool b) { return b ? "Yes" : "No"; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication6 { class Program { static void Main(string[] args) { // var length = c2i(RL()); var rl = spr(RL()).Select(x => c2i(x)).ToList(); var A = rl[0]; var B = rl[1]; var C = rl[2]; var K = rl[3]; long ret = 0; if (K <= A) { ret = K; } else if (K <= (A + B)) { ret = A; } else { ret = A + ((A + B) - K); } Console.WriteLine((ret)); // Console.ReadLine(); } static string RL() { return Console.ReadLine().Trim(); } static IEnumerable<string> spr(string s) { return s.Split(' '); } static Int64 c2i(string c) { return Int64.Parse(c); } // static double c2d(string c) { return double.Parse(c); } static string bool2ret(bool b) { return b ? "Yes" : "No"; } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22]]
8
242
2
using System; namespace AtCoder { public static class AtCoder { public static void Main() { var input = Console.ReadLine().Split(' '); var a = int.Parse(input[0]); var b = int.Parse(input[1]); var c = int.Parse(input[2]); var k = int.Parse(input[3]); if (k <= a) { Console.WriteLine(k); } else if (k <= a + b) { Console.WriteLine(a); } else { Console.WriteLine(a - (k - a + b)); } } } }
using System; namespace AtCoder { public static class AtCoder { public static void Main() { var input = Console.ReadLine().Split(' '); var a = int.Parse(input[0]); var b = int.Parse(input[1]); var c = int.Parse(input[2]); var k = int.Parse(input[3]); if (k <= a) { Console.WriteLine(k); } else if (k <= a + b) { Console.WriteLine(a); } else { Console.WriteLine(a - (k - a - b)); } } } }
[["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33]]
8
140
2
using System; using static System.Console; using System.Linq; namespace AC { public class shiokara { static void Main(string[] args) { long[] data = ReadLine().Split(' ').Select(long.Parse).ToArray(); if (data[0] >= data[3]) { WriteLine(data[3]); } else if (data[0] + data[1] >= data[3]) { WriteLine(data[0]); } else if (data[0] + data[1] + data[2] >= data[3]) { long tmp = data[3] - data[1] - data[0]; WriteLine(data[1] - tmp); } } } }
using System; using static System.Console; using System.Linq; namespace AC { public class shiokara { static void Main(string[] args) { long[] data = ReadLine().Split(' ').Select(long.Parse).ToArray(); if (data[0] >= data[3]) { WriteLine(data[3]); } else if (data[0] + data[1] >= data[3]) { WriteLine(data[0]); } else if (data[0] + data[1] + data[2] >= data[3]) { long tmp = data[3] - data[1] - data[0]; WriteLine(data[0] - tmp); } } } }
[["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203]]
8
164
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var ABCK = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); var A = ABCK[0]; var B = ABCK[1]; var C = ABCK[2]; var K = ABCK[3]; long ans = 0; if (0 < K) { if (K < A) { ans += A - K; K = 0; } else { ans += A; K -= A; } } if (0 < K) { K -= B; } if (0 < K) { ans -= K; } Console.WriteLine(ans); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var ABCK = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); var A = ABCK[0]; var B = ABCK[1]; var C = ABCK[2]; var K = ABCK[3]; long ans = 0; if (0 < K) { if (K < A) { ans += K; K = 0; } else { ans += A; K -= A; } } if (0 < K) { K -= B; } if (0 < K) { ans -= K; } Console.WriteLine(ans); } } }
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33]]
8
195
4
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static ABC167.abc167_b.Cin; using static ABC167.abc167_b.Util; using Pair = ABC167.abc167_b.VTuple<long, long>; /// <summary> /// ABC167 /// B - Easy Linear Programming /// https://atcoder.jp/contests/ABC167/tasks/abc167_b /// </summary> namespace ABC167.abc167_b { public class Program { public static void Main(string[] args) { long A = rl; long B = rl; long C = rl; long K = rl; if (K <= A) { Console.WriteLine(A); return; } long ans = A; K -= A; if (K <= B) { Console.WriteLine(ans); return; } K -= B; ans -= K; Console.WriteLine(ans); } } /// <summary> /// 競プロライブラリ /// https://github.com/ha2ne2/ABC/tree/master/Lib /// </summary> public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long val) { Value = val % MOD; if (Value < 0) Value += MOD; } private static Mint Ctor(long val) { return new Mint() { Value = val }; } public static Mint operator +(Mint a, Mint b) { long res = a.Value + b.Value; if (res > MOD) res -= MOD; return Ctor(res); } public static Mint operator -(Mint a, Mint b) { long res = a.Value - b.Value; if (res < 0) res += MOD; return Ctor(res); } public static Mint operator *(Mint a, Mint b) { long res = a.Value * b.Value; if (res > MOD) res %= MOD; return Ctor(res); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object obj) { return obj is Mint && Value == ((Mint)obj).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public override string ToString() { return Value.ToString(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long n) { if (n == 0) return new Mint(1); Mint b = Pow(a, n >> 1); b *= b; if ((n & 1) == 1) b *= a; return b; } public static Mint Inv(Mint n) { long a = n.Value; long b = MOD; long x = 1; long u = 0; while (b != 0) { long k = a / b; long _x = u; u = x - k * u; x = _x; long _a = a; a = b; b = _a - (k * b); } return new Mint(x); } public bool Equals(Mint other) { return Value == other.Value; } public int CompareTo(Mint other) { return Comparer<long>.Default.Compare(Value, other.Value); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { private V DefaultValue; private static Func<V> CreateInstance = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V defaultValue) { DefaultValue = defaultValue; } new public V this[K i] { get { V v; if (TryGetValue(i, out v)) { return v; } else { return base[i] = DefaultValue != null ? DefaultValue : CreateInstance(); } } set { base[i] = value; } } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 Item1; public T2 Item2; public T1 First { get { return Item1; } } public T2 Second { get { return Item2; } } public VTuple(T1 item1, T2 item2) { Item1 = item1; Item2 = item2; } public override bool Equals(object obj) { return obj is VTuple<T1, T2> && Equals((VTuple<T1, T2>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ")"; } public bool Equals(VTuple<T1, T2> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2); } public int CompareTo(VTuple<T1, T2> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; return Comparer<T2>.Default.Compare(Item2, other.Item2); } } public struct VTuple3<T1, T2, T3> : System.IComparable<VTuple3<T1, T2, T3>>, System.IEquatable<VTuple3<T1, T2, T3>> { public T1 Item1; public T2 Item2; public T3 Item3; public VTuple3(T1 item1, T2 item2, T3 item3) { Item1 = item1; Item2 = item2; Item3 = item3; } public override bool Equals(object obj) { return obj is VTuple3<T1, T2, T3> && Equals((VTuple3<T1, T2, T3>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; int h3 = Item3 != null ? Item3.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2, h3); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ")"; } public bool Equals(VTuple3<T1, T2, T3> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2) && EqualityComparer<T3>.Default.Equals(Item3, other.Item3); } public int CompareTo(VTuple3<T1, T2, T3> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; c = Comparer<T2>.Default.Compare(Item2, other.Item2); if (c != 0) return c; return Comparer<T3>.Default.Compare(Item3, other.Item3); } } public struct VTuple4<T1, T2, T3, T4> : System.IComparable<VTuple4<T1, T2, T3, T4>>, System.IEquatable<VTuple4<T1, T2, T3, T4>> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public VTuple4(T1 item1, T2 item2, T3 item3, T4 item4) { Item1 = item1; Item2 = item2; Item3 = item3; Item4 = item4; } public override bool Equals(object obj) { return obj is VTuple4<T1, T2, T3, T4> && Equals((VTuple4<T1, T2, T3, T4>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; int h3 = Item3 != null ? Item3.GetHashCode() : 0; int h4 = Item3 != null ? Item4.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2, h3, h4); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ")"; } public bool Equals(VTuple4<T1, T2, T3, T4> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2) && EqualityComparer<T3>.Default.Equals(Item3, other.Item3) && EqualityComparer<T4>.Default.Equals(Item4, other.Item4); } public int CompareTo(VTuple4<T1, T2, T3, T4> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; c = Comparer<T2>.Default.Compare(Item2, other.Item2); if (c != 0) return c; c = Comparer<T3>.Default.Compare(Item3, other.Item3); if (c != 0) return c; return Comparer<T4>.Default.Compare(Item4, other.Item4); } } public static class HashHelpers { public static readonly int RandomSeed = new System.Random().Next(int.MinValue, int.MaxValue); public static int Combine(int h1, int h2) { uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27); return ((int)rol5 + h1) ^ h2; } public static int CombineHashCodes(int h1, int h2) { return Combine(Combine(RandomSeed, h1), h2); } public static int CombineHashCodes(int h1, int h2, int h3) { return Combine(CombineHashCodes(h1, h2), h3); } public static int CombineHashCodes(int h1, int h2, int h3, int h4) { return Combine(CombineHashCodes(h1, h2, h3), h4); } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(Next()); } public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static string ReadString() { return Next(); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { Tokens = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long N) { a = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[,] ReadIntTable(int h, int w) { Tokens = null; int[,] ret = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadInt(); } } return ret; } public static long[,] ReadLongTable(long h, long w) { Tokens = null; long[,] ret = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadLong(); } } return ret; } public static char[,] ReadCharTable(int h, int w) { Tokens = null; char[,] res = new char[h, w]; for (int i = 0; i < h; i++) { string s = ReadString(); for (int j = 0; j < w; j++) { res[i, j] = s[j]; } } return res; } private static string[] Tokens; private static int Pointer; private static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { if (Console.IsOutputRedirected) return; var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } public static long GCD(long a, long b) { while (b != 0) { long _a = a; a = b; b = _a % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } public static long[] Accumulate(long[] array) { long[] acc = new long[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } public static double[] Accumulate(double[] array) { double[] acc = new double[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static ABC167.abc167_b.Cin; using static ABC167.abc167_b.Util; using Pair = ABC167.abc167_b.VTuple<long, long>; /// <summary> /// ABC167 /// B - Easy Linear Programming /// https://atcoder.jp/contests/ABC167/tasks/abc167_b /// </summary> namespace ABC167.abc167_b { public class Program { public static void Main(string[] args) { long A = rl; long B = rl; long C = rl; long K = rl; if (K <= A) { Console.WriteLine(K); return; } long ans = A; K -= A; if (K <= B) { Console.WriteLine(ans); return; } K -= B; ans -= K; Console.WriteLine(ans); } } /// <summary> /// 競プロライブラリ /// https://github.com/ha2ne2/ABC/tree/master/Lib /// </summary> public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long val) { Value = val % MOD; if (Value < 0) Value += MOD; } private static Mint Ctor(long val) { return new Mint() { Value = val }; } public static Mint operator +(Mint a, Mint b) { long res = a.Value + b.Value; if (res > MOD) res -= MOD; return Ctor(res); } public static Mint operator -(Mint a, Mint b) { long res = a.Value - b.Value; if (res < 0) res += MOD; return Ctor(res); } public static Mint operator *(Mint a, Mint b) { long res = a.Value * b.Value; if (res > MOD) res %= MOD; return Ctor(res); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object obj) { return obj is Mint && Value == ((Mint)obj).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public override string ToString() { return Value.ToString(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long n) { if (n == 0) return new Mint(1); Mint b = Pow(a, n >> 1); b *= b; if ((n & 1) == 1) b *= a; return b; } public static Mint Inv(Mint n) { long a = n.Value; long b = MOD; long x = 1; long u = 0; while (b != 0) { long k = a / b; long _x = u; u = x - k * u; x = _x; long _a = a; a = b; b = _a - (k * b); } return new Mint(x); } public bool Equals(Mint other) { return Value == other.Value; } public int CompareTo(Mint other) { return Comparer<long>.Default.Compare(Value, other.Value); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { private V DefaultValue; private static Func<V> CreateInstance = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V defaultValue) { DefaultValue = defaultValue; } new public V this[K i] { get { V v; if (TryGetValue(i, out v)) { return v; } else { return base[i] = DefaultValue != null ? DefaultValue : CreateInstance(); } } set { base[i] = value; } } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 Item1; public T2 Item2; public T1 First { get { return Item1; } } public T2 Second { get { return Item2; } } public VTuple(T1 item1, T2 item2) { Item1 = item1; Item2 = item2; } public override bool Equals(object obj) { return obj is VTuple<T1, T2> && Equals((VTuple<T1, T2>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ")"; } public bool Equals(VTuple<T1, T2> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2); } public int CompareTo(VTuple<T1, T2> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; return Comparer<T2>.Default.Compare(Item2, other.Item2); } } public struct VTuple3<T1, T2, T3> : System.IComparable<VTuple3<T1, T2, T3>>, System.IEquatable<VTuple3<T1, T2, T3>> { public T1 Item1; public T2 Item2; public T3 Item3; public VTuple3(T1 item1, T2 item2, T3 item3) { Item1 = item1; Item2 = item2; Item3 = item3; } public override bool Equals(object obj) { return obj is VTuple3<T1, T2, T3> && Equals((VTuple3<T1, T2, T3>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; int h3 = Item3 != null ? Item3.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2, h3); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ")"; } public bool Equals(VTuple3<T1, T2, T3> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2) && EqualityComparer<T3>.Default.Equals(Item3, other.Item3); } public int CompareTo(VTuple3<T1, T2, T3> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; c = Comparer<T2>.Default.Compare(Item2, other.Item2); if (c != 0) return c; return Comparer<T3>.Default.Compare(Item3, other.Item3); } } public struct VTuple4<T1, T2, T3, T4> : System.IComparable<VTuple4<T1, T2, T3, T4>>, System.IEquatable<VTuple4<T1, T2, T3, T4>> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public VTuple4(T1 item1, T2 item2, T3 item3, T4 item4) { Item1 = item1; Item2 = item2; Item3 = item3; Item4 = item4; } public override bool Equals(object obj) { return obj is VTuple4<T1, T2, T3, T4> && Equals((VTuple4<T1, T2, T3, T4>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; int h3 = Item3 != null ? Item3.GetHashCode() : 0; int h4 = Item3 != null ? Item4.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2, h3, h4); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ")"; } public bool Equals(VTuple4<T1, T2, T3, T4> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2) && EqualityComparer<T3>.Default.Equals(Item3, other.Item3) && EqualityComparer<T4>.Default.Equals(Item4, other.Item4); } public int CompareTo(VTuple4<T1, T2, T3, T4> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; c = Comparer<T2>.Default.Compare(Item2, other.Item2); if (c != 0) return c; c = Comparer<T3>.Default.Compare(Item3, other.Item3); if (c != 0) return c; return Comparer<T4>.Default.Compare(Item4, other.Item4); } } public static class HashHelpers { public static readonly int RandomSeed = new System.Random().Next(int.MinValue, int.MaxValue); public static int Combine(int h1, int h2) { uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27); return ((int)rol5 + h1) ^ h2; } public static int CombineHashCodes(int h1, int h2) { return Combine(Combine(RandomSeed, h1), h2); } public static int CombineHashCodes(int h1, int h2, int h3) { return Combine(CombineHashCodes(h1, h2), h3); } public static int CombineHashCodes(int h1, int h2, int h3, int h4) { return Combine(CombineHashCodes(h1, h2, h3), h4); } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(Next()); } public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static string ReadString() { return Next(); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { Tokens = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long N) { a = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[,] ReadIntTable(int h, int w) { Tokens = null; int[,] ret = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadInt(); } } return ret; } public static long[,] ReadLongTable(long h, long w) { Tokens = null; long[,] ret = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadLong(); } } return ret; } public static char[,] ReadCharTable(int h, int w) { Tokens = null; char[,] res = new char[h, w]; for (int i = 0; i < h; i++) { string s = ReadString(); for (int j = 0; j < w; j++) { res[i, j] = s[j]; } } return res; } private static string[] Tokens; private static int Pointer; private static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { if (Console.IsOutputRedirected) return; var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } public static long GCD(long a, long b) { while (b != 0) { long _a = a; a = b; b = _a % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } public static long[] Accumulate(long[] array) { long[] acc = new long[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } public static double[] Accumulate(double[] array) { double[] acc = new double[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
3,783
2
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 A, B, C, K; intReadLine(out A, out B, out C, out K); if (K <= A + B) { WriteLine(A); } else { int d = K - (A + B); WriteLine(A - d); } // ReadLine(); } } 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 int[] intArrayReadLine() { return ReadLine().Split().Select(int.Parse).ToArray(); } public static long[] longArrayReadLine() { return ReadLine().Split().Select(long.Parse).ToArray(); } public static List<int> intListReadLine() { return ReadLine().Split().Select(int.Parse).ToList(); } public static List<long> longListReadLine() { return 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 A, B, C, K; intReadLine(out A, out B, out C, out K); if (K <= A + B) { WriteLine(Min(A, K)); } else { int d = K - (A + B); WriteLine(A - d); } // ReadLine(); } } 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 int[] intArrayReadLine() { return ReadLine().Split().Select(int.Parse).ToArray(); } public static long[] longArrayReadLine() { return ReadLine().Split().Select(long.Parse).ToArray(); } public static List<int> intListReadLine() { return ReadLine().Split().Select(int.Parse).ToList(); } public static List<long> longListReadLine() { return 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); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
842
5
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { long A; long B; long C; long K; Multi(out A, out B, out C, out K); var ans = A + B >= K ? A : A - (K - A - B); Console.WriteLine(ans); } } public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } static public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } static public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } static public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } static public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } static public void WriteObjects<T>(IReadOnlyCollection<T> values) { var array = values.ToArray(); var num = array.Length; if (num == 0) return; Console.Write(array[0]); for (int i = 1; i < num; i++) { Console.Write(" " + array[i]); } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { long A; long B; long C; long K; Multi(out A, out B, out C, out K); var ans = A > K ? K : A + B >= K ? A : A - (K - A - B); Console.WriteLine(ans); } } public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } static public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } static public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } static public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } static public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } static public void WriteObjects<T>(IReadOnlyCollection<T> values) { var array = values.ToArray(); var num = array.Length; if (num == 0) return; Console.Write(array[0]); for (int i = 1; i < num; i++) { Console.Write(" " + array[i]); } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } }
[["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 47], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 64, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 41, 75, 41, 15, 16, 31, 16, 31, 22]]
8
1,539
6
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using static System.Math; using static System.Array; using static AtCoder.IO_ShortCut; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); /*var th = new Thread(Run, 1 << 26); th.Start(); th.Join();*/ Run(); Console.Out.Flush(); } static void Run() { int t = 1; for (var _ = 0; _ < t; _++) Solve(); } static void Solve() { long A, B, C, K; Input(out A, out B, out C, out K); long ans = 0; if (A + B >= K) { OutL(A); } else { ans += A; K -= (A + B); OutL(ans - K); } } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class Priority_Queue<T> { private List<T> Q; private readonly Comparison<T> Func_Compare; public Priority_Queue(Comparison<T> comp) { Func_Compare = comp; Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (Func_Compare(list[n], list[pIndex]) < 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = Func_Compare(list[c1], list[c2]) < 0 ? c1 : c2; } if (Func_Compare(list[cur], list[comp]) > 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Any() { return Q.Any(); } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; public static ModInt Modpow(ModInt a, long n) { var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } public static ModInt nCr(long n, long r) { return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } static class IO_ShortCut { public static string[] _ReadSplit => Console.ReadLine().Split(); public static int[] _ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] _ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] _ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Input<T, U>(out T a, out U b) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Input<T, U, V>(out T a, out U b, out V c) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void Input<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); } public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long Gcd(long a, long b) { if (a == 0 || b == 0) return Max(a, b); return a % b == 0 ? b : Gcd(b, a % b); } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using static System.Math; using static System.Array; using static AtCoder.IO_ShortCut; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); /*var th = new Thread(Run, 1 << 26); th.Start(); th.Join();*/ Run(); Console.Out.Flush(); } static void Run() { int t = 1; for (var _ = 0; _ < t; _++) Solve(); } static void Solve() { long A, B, C, K; Input(out A, out B, out C, out K); long ans = 0; if (A + B >= K) { OutL(Min(A, K)); } else { ans += A; K -= (A + B); OutL(ans - K); } } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class Priority_Queue<T> { private List<T> Q; private readonly Comparison<T> Func_Compare; public Priority_Queue(Comparison<T> comp) { Func_Compare = comp; Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (Func_Compare(list[n], list[pIndex]) < 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = Func_Compare(list[c1], list[c2]) < 0 ? c1 : c2; } if (Func_Compare(list[cur], list[comp]) > 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Any() { return Q.Any(); } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; public static ModInt Modpow(ModInt a, long n) { var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } public static ModInt nCr(long n, long r) { return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } static class IO_ShortCut { public static string[] _ReadSplit => Console.ReadLine().Split(); public static int[] _ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] _ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] _ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Input<T, U>(out T a, out U b) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Input<T, U, V>(out T a, out U b, out V c) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void Input<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); } public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long Gcd(long a, long b) { if (a == 0 || b == 0) return Max(a, b); return a % b == 0 ? b : Gcd(b, a % b); } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
2,237
5
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ABC167B { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var A = NN; var B = NN; var C = NN; var K = NN; var a = Min(A, K); var nokori = K - a; a -= nokori - B; Console.WriteLine(a); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } public LIB_FastIODebug() {} public override string Scan() => NextString(); public override long Long() => long.Parse(NextString()); public override double Double() => double.Parse(NextString()); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ABC167B { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var A = NN; var B = NN; var C = NN; var K = NN; var a = Min(A, K); var nokori = K - a; a -= Max(0, nokori - B); Console.WriteLine(a); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } public LIB_FastIODebug() {} public override string Scan() => NextString(); public override long Long() => long.Parse(NextString()); public override double Double() => double.Parse(NextString()); } }
[["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
1,453
5
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; namespace AtCoder { class Program { private static void Main(string[] args) { var s = Scanner.ArrayInt(3); var max = s[2]; var columnCount = s[1] + 1; var books = new List<int[]>(); for (int i = 0; i < s[0]; i++) { books.Add(Scanner.ArrayInt(columnCount).ToArray()); } for (int i = 1; i < columnCount; i++) { if (books.Select(xs => xs[i]).Sum() < max) { Console.WriteLine("-1"); return; } } var patternAll = (int)Math.Pow(2, s[0]); var array = new BitArray(); var indexArray = Enumerable.Range(0, patternAll) .Select(x => array.Integer(x, s[0])) .ToList(); for (int i = 1; i < s[1]; i++) { var removeArray = new List<List<int>>(); foreach (var indArray in indexArray) { if (indArray.Sum(x => books[x][i]) < max) { removeArray.Add(indArray); } } indexArray = indexArray.Except(removeArray).ToList(); } Console.WriteLine(indexArray.Select(xs => xs.Sum(x => books[x][0])).Min()); } #region Utility static readonly StreamScanner Scanner = new StreamScanner(Console.OpenStandardInput()); /// <summary> 一括出力 </summary> private static void OutAllLine(IEnumerable<dynamic> items) { var sb = new StringBuilder(); foreach (var result in items) { sb.Append(result + "\n"); } sb = sb.Remove(sb.Length - 1, 1); Console.WriteLine(sb); } /// <summary> 素数判定 </summary> public static bool IsPrime(int num) { if (num < 2) { return false; } if (num == 2) { return true; } 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; } public static IEnumerable<int> PrimeFactors(int n) { int i = 2; int tmp = n; while (i * i <= n) //※1 { if (tmp % i == 0) { tmp /= i; yield return i; } else { i++; } } if (tmp != 1) yield return tmp; } #endregion } #region Utility Class public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } /// <summary> 数値読み込み </summary> public List<long> ArrayLong(int count = 0) { var scan = new List<long>(); for (int i = 0; i < count; i++) { scan.Add(Long()); } return scan; } /// <summary> 数値読み込み </summary> public List<int> ArrayInt(int count = 0) { var scan = new List<int>(); for (int i = 0; i < count; i++) { scan.Add(Integer()); } return scan; } } public class Mod109 { public const int _7 = 1000000007; public const int _9 = 1000000009; public const int _3 = 998244353; private readonly int ModValue; public Mod109(int modValue = Mod109._7) { ModValue = modValue; } /// <summary> 和 </summary> public long Addition(IEnumerable<long> nums) { return nums.Aggregate<long, long>( 0, (current, num) => ModifyPositive((current + num) % ModValue)); } /// <summary> 差 </summary> public long Subtraction(IEnumerable<long> nums) { return nums.Aggregate<long, long>( 0, (current, num) => ModifyPositive((current - num) % ModValue)); } /// <summary> 積 </summary> public long Multiplication(IEnumerable<long> nums) { return nums.Aggregate<long, long>( 1, (current, num) => ModifyPositive((current * num) % ModValue)); } private long ModifyPositive(long value) { return value < 0 ? (value + ModValue) : value; } } public class BitArray { public List<int> Integer(int bitValue, int length) { var list = new List<int>(); for (int i = 0; i < length; i++) { if (bitValue % 2 == 1) { list.Add(i); } bitValue /= 2; } return list; } } #endregion }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; namespace AtCoder { class Program { private static void Main(string[] args) { var s = Scanner.ArrayInt(3); var max = s[2]; var columnCount = s[1] + 1; var books = new List<int[]>(); for (int i = 0; i < s[0]; i++) { books.Add(Scanner.ArrayInt(columnCount).ToArray()); } for (int i = 1; i < columnCount; i++) { if (books.Select(xs => xs[i]).Sum() < max) { Console.WriteLine("-1"); return; } } var patternAll = (int)Math.Pow(2, s[0]); var array = new BitArray(); var indexArray = Enumerable.Range(0, patternAll) .Select(x => array.Integer(x, s[0])) .ToList(); for (int i = 1; i < columnCount; i++) { var removeArray = new List<List<int>>(); foreach (var indArray in indexArray) { if (indArray.Sum(x => books[x][i]) < max) { removeArray.Add(indArray); } } indexArray = indexArray.Except(removeArray).ToList(); } Console.WriteLine(indexArray.Select(xs => xs.Sum(x => books[x][0])).Min()); } #region Utility static readonly StreamScanner Scanner = new StreamScanner(Console.OpenStandardInput()); /// <summary> 一括出力 </summary> private static void OutAllLine(IEnumerable<dynamic> items) { var sb = new StringBuilder(); foreach (var result in items) { sb.Append(result + "\n"); } sb = sb.Remove(sb.Length - 1, 1); Console.WriteLine(sb); } /// <summary> 素数判定 </summary> public static bool IsPrime(int num) { if (num < 2) { return false; } if (num == 2) { return true; } 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; } public static IEnumerable<int> PrimeFactors(int n) { int i = 2; int tmp = n; while (i * i <= n) //※1 { if (tmp % i == 0) { tmp /= i; yield return i; } else { i++; } } if (tmp != 1) yield return tmp; } #endregion } #region Utility Class public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } /// <summary> 数値読み込み </summary> public List<long> ArrayLong(int count = 0) { var scan = new List<long>(); for (int i = 0; i < count; i++) { scan.Add(Long()); } return scan; } /// <summary> 数値読み込み </summary> public List<int> ArrayInt(int count = 0) { var scan = new List<int>(); for (int i = 0; i < count; i++) { scan.Add(Integer()); } return scan; } } public class Mod109 { public const int _7 = 1000000007; public const int _9 = 1000000009; public const int _3 = 998244353; private readonly int ModValue; public Mod109(int modValue = Mod109._7) { ModValue = modValue; } /// <summary> 和 </summary> public long Addition(IEnumerable<long> nums) { return nums.Aggregate<long, long>( 0, (current, num) => ModifyPositive((current + num) % ModValue)); } /// <summary> 差 </summary> public long Subtraction(IEnumerable<long> nums) { return nums.Aggregate<long, long>( 0, (current, num) => ModifyPositive((current - num) % ModValue)); } /// <summary> 積 </summary> public long Multiplication(IEnumerable<long> nums) { return nums.Aggregate<long, long>( 1, (current, num) => ModifyPositive((current * num) % ModValue)); } private long ModifyPositive(long value) { return value < 0 ? (value + ModValue) : value; } } public class BitArray { public List<int> Integer(int bitValue, int length) { var list = new List<int>(); for (int i = 0; i < length; i++) { if (bitValue % 2 == 1) { list.Add(i); } bitValue /= 2; } return list; } } #endregion }
[["-", 8, 196, 0, 7, 15, 16, 12, 204, 205, 22], ["-", 0, 7, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 7, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
1,340
5
using System; using System.Linq; namespace Contest { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int n = input[0]; int m = input[1]; int x = input[2]; int[] c = new int[n]; int[,] a = new int[n, m]; for (int i = 0; i < n; i++) { input = Console.ReadLine().Split().Select(int.Parse).ToArray(); c[i] = input[0]; for (int j = 0; j < m; j++) { a[i, j] = input[j + 1]; } } long ans = 10000000; for (int i = 1; i < (1 << n) - 1; i++) { int bit = 1; int shift = 0; long cost = 0; long[] skills = new long[m]; while (i >= bit) { if ((i & bit) == bit) { cost += c[shift]; for (int j = 0; j < m; j++) { skills[j] += a[shift, j]; } } shift++; bit = bit << 1; } bool over = true; foreach (var skill in skills) { if (skill < x) { over = false; break; } } if (over && ans > cost) { ans = cost; } } if (ans == 10000000) { Console.WriteLine(-1); } else { Console.WriteLine(ans); } } } }
using System; using System.Linq; namespace Contest { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int n = input[0]; int m = input[1]; int x = input[2]; int[] c = new int[n]; int[,] a = new int[n, m]; for (int i = 0; i < n; i++) { input = Console.ReadLine().Split().Select(int.Parse).ToArray(); c[i] = input[0]; for (int j = 0; j < m; j++) { a[i, j] = input[j + 1]; } } long ans = 10000000; for (int i = 1; i < (1 << n); i++) { int bit = 1; int shift = 0; long cost = 0; long[] skills = new long[m]; while (i >= bit) { if ((i & bit) == bit) { cost += c[shift]; for (int j = 0; j < m; j++) { skills[j] += a[shift, j]; } } shift++; bit = bit << 1; } bool over = true; foreach (var skill in skills) { if (skill < x) { over = false; break; } } if (over && ans > cost) { ans = cost; } } if (ans == 10000000) { Console.WriteLine(-1); } else { Console.WriteLine(ans); } } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
364
2
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { //入力を保持する var NMX = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); //本の種類N var N = NMX[0]; //アルゴリズムの種類M var M = NMX[1]; //目標経験値 var X = NMX[2]; //経験値群の二次元配列 var exs = new int[N, M + 1]; //書籍の値段リスト var prices = new int[N]; var index = new int[N]; for (int n = 0; n < N; n++) { var ex = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); prices[n] = ex[0]; index[n] = n; for (int m = 1; m < M + 1; m++) { exs[n, m - 1] = ex[m]; } } var ans = int.MaxValue; for (int cnt = 1; cnt < N + 1; cnt++) { foreach (var cases in CasesReturn<int>(index, cnt)) { var contFlg = true; for (var m = 0; m < M - 1; m++) { var check = 0; foreach (var c in cases) { check = check + exs[c, m]; } // Console.WriteLine(check); if (check < X) { contFlg = false; break; } } if (contFlg) { // Console.WriteLine("Yes"); var priceCheck = 0; foreach (var c in cases) { priceCheck = priceCheck + prices[c]; } // Console.WriteLine(ans); // Console.WriteLine(priceCheck); if (priceCheck < ans) { // Console.WriteLine("Yes"); ans = priceCheck; } } } } if (ans == int.MaxValue) { Console.WriteLine("-1"); } else { Console.WriteLine(ans); } } public static IEnumerable<T[]> CasesReturn<T>(IEnumerable<T> prices, int cnt) { if (cnt == 1) { foreach (var p in prices) { yield return new T[] { p }; } yield break; } else { foreach (var p in prices) { var left = new T[] { p }; // Console.WriteLine("left : " + p); // pより前にある要素をすべてスキップして要素pもスキップする var used = prices.SkipWhile(e => !e.Equals(p)).Skip(1).ToArray(); // var strUs = "used : "; // foreach(var u in used) //{ // strUs = strUs + u; //} // Console.WriteLine(strUs); foreach (var cases in CasesReturn(used, cnt - 1)) { yield return left.Concat(cases).ToArray(); } } } } }
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var NMX = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); var N = NMX[0]; //本の種類N var M = NMX[1]; //アルゴリズムの種類M var X = NMX[2]; //目標経験値 var exs = new int[N, M + 1]; //経験値群の二次元配列 var prices = new int[N]; //書籍の値段リスト var index = new int[N]; //全件検索チェック用の配列 //書籍から得られるアルゴリズムごとの経験値を二次元配列で保持する for (int n = 0; n < N; n++) { var ex = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); prices[n] = ex[0]; index[n] = n; for (int m = 1; m < M + 1; m++) { exs[n, m - 1] = ex[m]; } } var ans = int.MaxValue; //書籍の数分ループする for (int cnt = 1; cnt < N + 1; cnt++) { //全件検索のためIEnumerableインターフェースを返すメソッドをループする foreach (var cases in CasesReturn<int>(index, cnt)) { var contFlg = true; // Xを上回っているか判断するためのフラグ for (var m = 0; m < M; m++) { //チェック変数ですべての書籍による経験値がXを上回っていることを確認する var check = 0; foreach (var c in cases) { check = check + exs[c, m]; } // Xより下回っている場合、ループを抜ける、また継続フラグをfalseにする if (check < X) { contFlg = false; break; } } if (contFlg) { //継続フラグ==>Trueの場合、条件を満たすので、解答用変数に結果を入力する var priceCheck = 0; foreach (var c in cases) { priceCheck = priceCheck + prices[c]; } if (priceCheck < ans) { //最小値を算出するため、これまでの最小値であることを確かめる ans = priceCheck; } } } } if (ans == int.MaxValue) { Console.WriteLine("-1"); } else { Console.WriteLine(ans); } } // public static IEnumerable<T[]> CasesReturn<T>(IEnumerable<T> prices, int cnt) { //カウントが1の場合、配列の要素をひとつずつ返却する if (cnt == 1) { foreach (var p in prices) { yield return new T[] { p }; } yield break; } else { //カウントが1より大きい場合、再帰的にCaseReturnを呼び出す foreach (var p in prices) { var left = new T[] { p }; // pより前にある要素をすべてスキップして要素pもスキップする var used = prices.SkipWhile(e => !e.Equals(p)).Skip(1).ToArray(); foreach (var cases in CasesReturn(used, cnt - 1)) { //最も左側の要素と返された配列の要素を結合する yield return left.Concat(cases).ToArray(); } } } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
532
4
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { //入力を保持する var NMX = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); //本の種類N var N = NMX[0]; //アルゴリズムの種類M var M = NMX[1]; //目標経験値 var X = NMX[2]; //経験値群の二次元配列 var exs = new int[N, M + 1]; //書籍の値段リスト var prices = new int[N]; var index = new int[N]; for (int n = 0; n < N; n++) { var ex = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); prices[n] = ex[0]; index[n] = n; for (int m = 1; m < M + 1; m++) { exs[n, m - 1] = ex[m]; } } var ans = int.MaxValue; for (int cnt = 1; cnt < N + 1; cnt++) { foreach (var cases in CasesReturn<int>(index, cnt)) { var contFlg = true; for (var m = 0; m < M - 1; m++) { var check = 0; foreach (var c in cases) { check = check + exs[c, m]; } // Console.WriteLine(check); if (check < X) { contFlg = false; break; } } if (contFlg) { // Console.WriteLine("Yes"); var priceCheck = 0; foreach (var c in cases) { priceCheck = priceCheck + prices[c]; } // Console.WriteLine(ans); // Console.WriteLine(priceCheck); if (priceCheck < ans) { // Console.WriteLine("Yes"); ans = priceCheck; } } } } if (ans == int.MaxValue) { Console.WriteLine("-1"); } else { Console.WriteLine(ans); } } public static IEnumerable<T[]> CasesReturn<T>(IEnumerable<T> prices, int cnt) { if (cnt == 1) { foreach (var p in prices) { yield return new T[] { p }; } yield break; } else { foreach (var p in prices) { var left = new T[] { p }; // Console.WriteLine("left : " + p); // pより前にある要素をすべてスキップして要素pもスキップする var used = prices.SkipWhile(e => !e.Equals(p)).Skip(1).ToArray(); // var strUs = "used : "; // foreach(var u in used) //{ // strUs = strUs + u; //} // Console.WriteLine(strUs); foreach (var cases in CasesReturn(used, cnt - 1)) { yield return left.Concat(cases).ToArray(); } } } } }
using System; using System.Collections.Generic; using System.Linq; public class AtCoder { public static void Main() { //入力を保持する var NMX = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); //本の種類N var N = NMX[0]; //アルゴリズムの種類M var M = NMX[1]; //目標経験値 var X = NMX[2]; //経験値群の二次元配列 var exs = new int[N, M + 1]; //書籍の値段リスト var prices = new int[N]; var index = new int[N]; for (int n = 0; n < N; n++) { var ex = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); prices[n] = ex[0]; index[n] = n; for (int m = 1; m < M + 1; m++) { exs[n, m - 1] = ex[m]; } } var ans = int.MaxValue; for (int cnt = 1; cnt < N + 1; cnt++) { foreach (var cases in CasesReturn<int>(index, cnt)) { var contFlg = true; for (var m = 0; m < M; m++) { var check = 0; foreach (var c in cases) { check = check + exs[c, m]; } // Console.WriteLine(check); if (check < X) { contFlg = false; break; } } if (contFlg) { // Console.WriteLine("Yes"); var priceCheck = 0; foreach (var c in cases) { priceCheck = priceCheck + prices[c]; } // Console.WriteLine(ans); // Console.WriteLine(priceCheck); if (priceCheck < ans) { // Console.WriteLine("Yes"); ans = priceCheck; } } } } if (ans == int.MaxValue) { Console.WriteLine("-1"); } else { Console.WriteLine(ans); } } public static IEnumerable<T[]> CasesReturn<T>(IEnumerable<T> prices, int cnt) { if (cnt == 1) { foreach (var p in prices) { yield return new T[] { p }; } yield break; } else { foreach (var p in prices) { var left = new T[] { p }; // Console.WriteLine("left : " + p); // pより前にある要素をすべてスキップして要素pもスキップする var used = prices.SkipWhile(e => !e.Equals(p)).Skip(1).ToArray(); // var strUs = "used : "; // foreach(var u in used) //{ // strUs = strUs + u; //} // Console.WriteLine(strUs); foreach (var cases in CasesReturn(used, cnt - 1)) { yield return left.Concat(cases).ToArray(); } } } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
532
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { private static int largeV = 999999; static void Main(string[] args) { var list = new List<int[]>(); int[] arr = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int n = arr[0]; int m = arr[1]; int minValue = arr[2]; int min = largeV; for (int i = 1; i <= n; i++) { list.Add( Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray()); } for (int bit = 0; bit < (1 << n); bit++) { var sumList = new List<int[]>(); for (int i = 0; i < n; i++) { if ((bit & (1 << i)) > 0) { sumList.Add(list[i]); } } if (sumList.Count == 0) continue; var ansE = new ctrlSum(sumList, minValue); if (ansE.line) { if (ansE.sumV < min) min = ansE.sumV; } } if (min == largeV) Console.WriteLine(-1); else Console.WriteLine(min); } } class ctrlSum { public int sumV; public bool line = true; public ctrlSum(List<int[]> sumList, int minValue) { int len = sumList[0].Length; int[] sumA = new int[len - 1]; foreach (int[] eleA in sumList) { int ind = 1; this.sumV += eleA[0]; while (ind < len) { sumA[ind - 1] += eleA[ind]; ind++; } } foreach (int ele in sumA) { if (ele < minValue) this.line = false; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { private static int largeV = 9999999; static void Main(string[] args) { var list = new List<int[]>(); int[] arr = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int n = arr[0]; int m = arr[1]; int minValue = arr[2]; int min = largeV; for (int i = 1; i <= n; i++) { list.Add( Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray()); } for (int bit = 0; bit < (1 << n); bit++) { var sumList = new List<int[]>(); for (int i = 0; i < n; i++) { if ((bit & (1 << i)) > 0) { sumList.Add(list[i]); } } if (sumList.Count == 0) continue; var ansE = new ctrlSum(sumList, minValue); if (ansE.line) { if (ansE.sumV < min) min = ansE.sumV; } } if (min == largeV) Console.WriteLine(-1); else Console.WriteLine(min); } } class ctrlSum { public int sumV; public bool line = true; public ctrlSum(List<int[]> sumList, int minValue) { int len = sumList[0].Length; int[] sumA = new int[len - 1]; foreach (int[] eleA in sumList) { int ind = 1; this.sumV += eleA[0]; while (ind < len) { sumA[ind - 1] += eleA[ind]; ind++; } } foreach (int ele in sumA) { if (ele < minValue) this.line = false; } } }
[["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203]]
8
430
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { var list = new List<int[]>(); int[] arr = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int n = arr[0]; int m = arr[1]; int minValue = arr[2]; int min = 999999; for (int i = 1; i <= n; i++) { list.Add( Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray()); } for (int bit = 0; bit < (1 << n); bit++) { var sumList = new List<int[]>(); for (int i = 0; i < n; i++) { if ((bit & (1 << i)) > 0) { sumList.Add(list[i]); } } int sumMinValue = checkSumValue(sumList, minValue); if (sumMinValue < min) min = sumMinValue; } if (min == 999999) Console.WriteLine(-1); else Console.WriteLine(min); } static int checkSumValue(List<int[]> sumList, int minValue) { int lenList = sumList.Count(); if (lenList == 0) return 999999; int lenArr = sumList[0].Length; int[] sumArr = new int[lenArr]; int value = 0; for (int i = 0; i < lenList; i++) { for (int j = 1; j < lenArr; j++) { sumArr[j] += sumList[i][j]; } value += sumList[i][0]; } for (int j = 1; j < lenArr; j++) { if (sumArr[j] < minValue) return 999999; } return value; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { var list = new List<int[]>(); int[] arr = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int n = arr[0]; int m = arr[1]; int minValue = arr[2]; int min = 9999999; for (int i = 1; i <= n; i++) { list.Add( Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray()); } for (int bit = 0; bit < (1 << n); bit++) { var sumList = new List<int[]>(); for (int i = 0; i < n; i++) { if ((bit & (1 << i)) > 0) { sumList.Add(list[i]); } } int sumMinValue = checkSumValue(sumList, minValue); if (sumMinValue < min) min = sumMinValue; } if (min == 9999999) Console.WriteLine(-1); else Console.WriteLine(min); } static int checkSumValue(List<int[]> sumList, int minValue) { int lenList = sumList.Count(); if (lenList == 0) return 9999999; int lenArr = sumList[0].Length; int[] sumArr = new int[lenArr]; int value = 0; for (int i = 0; i < lenList; i++) { for (int j = 1; j < lenArr; j++) { sumArr[j] += sumList[i][j]; } value += sumList[i][0]; } for (int j = 1; j < lenArr; j++) { if (sumArr[j] < minValue) return 9999999; } return value; } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["-", 0, 7, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 37, 0, 203]]
8
425
8
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static AtCoderTemplate.MyLibrary; namespace AtCoderTemplate { class Program { static void Main(string[] args) { long ans = long.MaxValue; string[] str1 = Console.ReadLine().Split(' '); var N = int.Parse(str1[0]); var M = int.Parse(str1[1]); var X = int.Parse(str1[2]); var C = new int[N]; var A = new int[12, 12]; for (int i = 0; i < N; i++) { string[] str2 = Console.ReadLine().Split(' '); C[i] = int.Parse(str2[0]); for (int j = 0; j < M; j++) { A[i, j] = int.Parse(str2[j]); } } long total = 0; for (int bit = 1; bit < (1 << N); bit++) { total = 0; int[] sum = new int[M]; for (int i = 0; i < N; i++) { if ((bit & (1 << i)) > 0) { total += C[i]; for (int j = 0; j < M; j++) { sum[j] += A[i, j]; } } } for (int j = 0; j < M; j++) { if (sum[j] < X) total = long.MaxValue; } if (total < ans) ans = total; } if (ans == long.MaxValue) Console.WriteLine(-1); else Console.WriteLine(ans); } } class MyLibrary { // 自作の関数 public static int MyFunction(int n) { return 0; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static AtCoderTemplate.MyLibrary; namespace AtCoderTemplate { class Program { static void Main(string[] args) { long ans = long.MaxValue; string[] str1 = Console.ReadLine().Split(' '); var N = int.Parse(str1[0]); var M = int.Parse(str1[1]); var X = int.Parse(str1[2]); var C = new int[N]; var A = new int[12, 12]; for (int i = 0; i < N; i++) { string[] str2 = Console.ReadLine().Split(' '); C[i] = int.Parse(str2[0]); for (int j = 0; j < M; j++) { A[i, j] = int.Parse(str2[j + 1]); } } long total = 0; for (int bit = 0; bit < (1 << N); bit++) { total = 0; int[] sum = new int[M]; for (int i = 0; i < N; i++) { if ((bit & (1 << i)) > 0) { total += C[i]; for (int j = 0; j < M; j++) { sum[j] += A[i, j]; } } } for (int j = 0; j < M; j++) { if (sum[j] < X) total = long.MaxValue; } if (total < ans) ans = total; } if (ans == long.MaxValue) Console.WriteLine(-1); else Console.WriteLine(ans); } } class MyLibrary { // 自作の関数 public static int MyFunction(int n) { return 0; } } }
[["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
418
4
using System; using System.Collections.Generic; using System.Linq; class abc167_c { public static void Main() { String[] str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); int m = int.Parse(str[1]); int x = int.Parse(str[2]); int[] cost = new int[n]; int[,] val = new int[n, m]; for (int i = 0; i < n; i++) { int[] temp = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); cost[i] = temp[0]; for (int j = 0; j < m; j++) { val[i, j] = temp[j + 1]; } } List<Cl> list = new List<Cl>(); Cl c = new Cl(m); list.Add(c); for (int i = 0; i < n; i++) { int num = list.Count; for (int j = 0; j < num; j++) { Cl nc = new Cl(m); nc.sum = list[j].sum + cost[i]; for (int k = 0; k < m; k++) { nc.sut[k] = val[i, k] + list[j].sut[k]; } list.Add(nc); } Cl nc2 = new Cl(m); nc2.sum = cost[i]; for (int j = 0; j < m; j++) { nc2.sut[j] = val[i, j]; } } int min = 1000000; bool flag = true; /*for(int i=0; i<list.Count; i++){ Console.Write("sum: {0} // ",list[i].sum); for(int j=0; j<m; j++){ Console.Write("{0} ",list[i].sut[j]); } Console.WriteLine(""); }*/ for (int i = 0; i < list.Count; i++) { Cl c2 = list[i]; flag = true; for (int j = 0; j < m && flag; j++) { if (c2.sut[j] < x) { flag = false; } } if (flag) { if (min > c2.sum) { min = c2.sum; } } } if (min == 1000000) { Console.WriteLine("-1"); } else Console.WriteLine(min); } } class Cl { public int sum; public int[] sut; public Cl(int m) { sum = 0; sut = new int[m]; } }
using System; using System.Collections.Generic; using System.Linq; class abc167_c { public static void Main() { String[] str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); int m = int.Parse(str[1]); int x = int.Parse(str[2]); int[] cost = new int[n]; int[,] val = new int[n, m]; for (int i = 0; i < n; i++) { int[] temp = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); cost[i] = temp[0]; for (int j = 0; j < m; j++) { val[i, j] = temp[j + 1]; } } List<Cl> list = new List<Cl>(); Cl c = new Cl(m); list.Add(c); for (int i = 0; i < n; i++) { int num = list.Count; for (int j = 0; j < num; j++) { Cl nc = new Cl(m); nc.sum = list[j].sum + cost[i]; for (int k = 0; k < m; k++) { nc.sut[k] = val[i, k] + list[j].sut[k]; } list.Add(nc); } Cl nc2 = new Cl(m); nc2.sum = cost[i]; for (int j = 0; j < m; j++) { nc2.sut[j] = val[i, j]; } } int min = Int32.MaxValue; bool flag = true; /*for(int i=0; i<list.Count; i++){ Console.Write("sum: {0} // ",list[i].sum); for(int j=0; j<m; j++){ Console.Write("{0} ",list[i].sut[j]); } Console.WriteLine(""); }*/ for (int i = 0; i < list.Count; i++) { Cl c2 = list[i]; flag = true; for (int j = 0; j < m && flag; j++) { if (c2.sut[j] < x) { flag = false; } } if (flag) { if (min > c2.sum) { min = c2.sum; } } } if (min == Int32.MaxValue) { Console.WriteLine("-1"); } else Console.WriteLine(min); } } class Cl { public int sum; public int[] sut; public Cl(int m) { sum = 0; sut = new int[m]; } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 22], ["+", 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, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22]]
8
545
8
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; using System.Text.RegularExpressions; namespace Yuzuki { class Yukari { static int n, m, x; static int[] cs; static int[,] As; public static void Main(string[] args) { input(); int ans = int.MaxValue; for (int s = 1; s < 1 << n; s++) { int res = 0; int[] ac = new int[n]; for (int i = 0; i < n; i++) { if ((s >> i & 1) == 1) { res += cs[i]; for (int j = 0; j < m; j++) { ac[j] += As[i, j]; } } } if (ac.All(x => Yukari.x <= x)) { ans = Min(ans, res); } } if (ans == int.MaxValue) { ans = -1; } Console.WriteLine(ans); } public static void input() { string[] buf = Console.ReadLine().Split(); n = int.Parse(buf[0]); m = int.Parse(buf[1]); x = int.Parse(buf[2]); cs = new int[n]; As = new int[n, m]; for (int i = 0; i < n; i++) { buf = Console.ReadLine().Split(); cs[i] = int.Parse(buf[0]); for (int j = 0; j < m; j++) { As[i, j] = int.Parse(buf[j + 1]); } } } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; using System.Text.RegularExpressions; namespace Yuzuki { class Yukari { static int n, m, x; static int[] cs; static int[,] As; public static void Main(string[] args) { input(); int ans = int.MaxValue; for (int s = 1; s < 1 << n; s++) { int res = 0; int[] ac = new int[m]; for (int i = 0; i < n; i++) { if ((s >> i & 1) == 1) { res += cs[i]; for (int j = 0; j < m; j++) { ac[j] += As[i, j]; } } } if (ac.All(x => Yukari.x <= x)) { ans = Min(ans, res); } } if (ans == int.MaxValue) { ans = -1; } Console.WriteLine(ans); } public static void input() { string[] buf = Console.ReadLine().Split(); n = int.Parse(buf[0]); m = int.Parse(buf[1]); x = int.Parse(buf[2]); cs = new int[n]; As = new int[n, m]; for (int i = 0; i < n; i++) { buf = Console.ReadLine().Split(); cs[i] = int.Parse(buf[0]); for (int j = 0; j < m; j++) { As[i, j] = int.Parse(buf[j + 1]); } } } } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22]]
8
398
2
using System; using System.Collections.Generic; using System.Linq; class Program { private static readonly int INF = 100000000; static void Main(string[] args) { string[] nmx = Console.ReadLine().Split(' '); int n = int.Parse(nmx[0]); int m = int.Parse(nmx[1]); int x = int.Parse(nmx[2]); int[,] a = new int[12, 12]; List<int> c; List<int> price = new List<int>(); for (int i = 0; i < n; i++) { c = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); price.Add(c[0]); for (int j = 0; j < m; j++) { a[i, j] = c[j + 1]; } } int ans = INF; for (int bit = 0; bit < (1 << n); bit++) { int cost = 0; int[] d = new int[n]; for (int i = 0; i < n; i++) { if ((bit & (1 << i)) > 0) { cost += price[i]; for (int j = 0; j < m; j++) { d[j] += a[i, j]; } } } bool ok = true; for (int 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.Generic; using System.Linq; class Program { private static readonly int INF = 1001001001; static void Main(string[] args) { string[] nmx = Console.ReadLine().Split(' '); int n = int.Parse(nmx[0]); int m = int.Parse(nmx[1]); int x = int.Parse(nmx[2]); int[,] a = new int[12, 12]; List<int> c; List<int> price = new List<int>(); for (int i = 0; i < n; i++) { c = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); price.Add(c[0]); for (int j = 0; j < m; j++) { a[i, j] = c[j + 1]; } } int ans = INF; for (int bit = 0; bit < (1 << n); bit++) { int cost = 0; int[] d = new int[12]; for (int i = 0; i < n; i++) { if ((bit & (1 << i)) > 0) { cost += price[i]; for (int j = 0; j < m; j++) { d[j] += a[i, j]; } } } bool ok = true; for (int 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); } } }
[["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203]]
8
399
4
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { public class Value { public long money { get; set; } public List<long> skill { get; set; } } static void Main(string[] args) { var inputNum = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var N = inputNum[0]; var M = inputNum[1]; var X = inputNum[2]; var valueList = new List<Value>(); // 整数を格納するキュー var que = new Queue<Value>(); var nextQue = new Queue<Value>(); for (int i = 0; i < N; i++) { que = nextQue; nextQue = new Queue<Value>(); var inputSkillNum = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if (que.Any()) { // キューから全てを取り出す while (que.Count > 0) { var value = que.Dequeue(); var newValue = new Value(); newValue.money = value.money + inputSkillNum[0]; newValue.skill = new List<long>(); for (int x = 0; x < M; x++) { newValue.skill.Add(value.skill[x] + inputSkillNum[x + 1]); } nextQue.Enqueue(newValue); nextQue.Enqueue(value); } /* foreach (var value in valueList) { var newValue = new Value(); newValue.money = value.money + inputSkillNum[0]; newValue.skill = new List<int>(); for(int x = 0; x < M; x++) { newValue.skill.Add(value.skill[x] + inputSkillNum[x + 1]); } valueList.Add(newValue); } */ } var addValue = new Value(); addValue.skill = new List<long>(); addValue.money = inputSkillNum[0]; for (int x = 0; x < M; x++) { addValue.skill.Add(inputSkillNum[x + 1]); } nextQue.Enqueue(addValue); } var flag = false; long answer = 1000000; while (nextQue.Count > 0) { var targetValue = nextQue.Dequeue(); if (targetValue.skill.All(x => x >= X)) { flag = true; if (answer > targetValue.money) answer = targetValue.money; } } if (flag) { Console.WriteLine(answer); } else { Console.WriteLine(-1); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { public class Value { public long money { get; set; } public List<long> skill { get; set; } } static void Main(string[] args) { var inputNum = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var N = inputNum[0]; var M = inputNum[1]; var X = inputNum[2]; var valueList = new List<Value>(); // 整数を格納するキュー var que = new Queue<Value>(); var nextQue = new Queue<Value>(); for (int i = 0; i < N; i++) { que = nextQue; nextQue = new Queue<Value>(); var inputSkillNum = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if (que.Any()) { // キューから全てを取り出す while (que.Count > 0) { var value = que.Dequeue(); var newValue = new Value(); newValue.money = value.money + inputSkillNum[0]; newValue.skill = new List<long>(); for (int x = 0; x < M; x++) { newValue.skill.Add(value.skill[x] + inputSkillNum[x + 1]); } nextQue.Enqueue(newValue); nextQue.Enqueue(value); } /* foreach (var value in valueList) { var newValue = new Value(); newValue.money = value.money + inputSkillNum[0]; newValue.skill = new List<int>(); for(int x = 0; x < M; x++) { newValue.skill.Add(value.skill[x] + inputSkillNum[x + 1]); } valueList.Add(newValue); } */ } var addValue = new Value(); addValue.skill = new List<long>(); addValue.money = inputSkillNum[0]; for (int x = 0; x < M; x++) { addValue.skill.Add(inputSkillNum[x + 1]); } nextQue.Enqueue(addValue); } var flag = false; long answer = 1000000000000000000; while (nextQue.Count > 0) { var targetValue = nextQue.Dequeue(); if (targetValue.skill.All(x => x >= X)) { flag = true; if (answer > targetValue.money) answer = targetValue.money; } } if (flag) { Console.WriteLine(answer); } else { Console.WriteLine(-1); } } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
471
2
using System; namespace ABC167C { class Program { static void Main(string[] args) { var target = Console.ReadLine().Split(' '); int N = int.Parse(target[0]); int M = int.Parse(target[1]); int X = int.Parse(target[2]); int[] cost = new int[N]; int[,] text = new int[N, M]; int min_cost = 10000000; bool s_f = false; for (int i = 0; i < N; i++) { target = Console.ReadLine().Split(' '); cost[i] = int.Parse(target[0]); for (int j = 0; j < M; j++) text[i, j] = int.Parse(target[j + 1]); } int[] skill = new int[N]; int perm = 1 << N; for (int i = 0; i < perm; i++) { int tmp_cost = 0; for (int j = 0; j < M; j++) skill[j] = 0; for (int j = 0; j < N; j++) { if ((i & (1 << j)) == (1 << j)) { for (int k = 0; k < M; k++) skill[k] += text[j, k]; tmp_cost += cost[j]; } } bool f = true; for (int k = 0; k < M; k++) if (skill[k] < X) { f = false; } if (f && (tmp_cost < min_cost)) { min_cost = tmp_cost; s_f = true; } } if (!s_f) Console.WriteLine("-1"); else Console.WriteLine(min_cost); } } }
using System; namespace ABC167C { class Program { static void Main(string[] args) { var target = Console.ReadLine().Split(' '); int N = int.Parse(target[0]); int M = int.Parse(target[1]); int X = int.Parse(target[2]); int[] cost = new int[12]; int[,] text = new int[12, 12]; int min_cost = 10000000; bool s_f = false; for (int i = 0; i < N; i++) { target = Console.ReadLine().Split(' '); cost[i] = int.Parse(target[0]); for (int j = 0; j < M; j++) text[i, j] = int.Parse(target[j + 1]); } int[] skill = new int[12]; int perm = 1 << N; for (int i = 0; i < perm; i++) { int tmp_cost = 0; for (int j = 0; j < M; j++) skill[j] = 0; for (int j = 0; j < N; j++) { if ((i & (1 << j)) == (1 << j)) { for (int k = 0; k < M; k++) skill[k] += text[j, k]; tmp_cost += cost[j]; } } bool f = true; for (int k = 0; k < M; k++) if (skill[k] < X) { f = false; } if (f && (tmp_cost < min_cost)) { min_cost = tmp_cost; s_f = true; } } if (!s_f) Console.WriteLine("-1"); else Console.WriteLine(min_cost); } } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203]]
8
396
8
using System; namespace AtC167 { class Program { static void Main(string[] args) { string[] NMX; NMX = Console.ReadLine().Split(' '); int N = int.Parse(NMX[0]); int M = int.Parse(NMX[1]); int X = int.Parse(NMX[2]); int[][] A = new int [N][]; for (int i = 0; i < N; i++) { string[] CA = Console.ReadLine().Split(' '); A[i] = new int[M + 1]; for (int j = 0; j < M + 1; j++) A[i][j] = int.Parse(CA[j]); } int ans = 100000000; int bitflag = 0; int[] flag = new int[13] { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 }; while (bitflag < 10000) { int[] Rikai = new int[M]; int Money = 0; bitflag++; for (int i = 0; i < N; i++) { if ((bitflag & flag[i]) >= 1) { Money += A[i][0]; for (int j = 0; j < M; j++) Rikai[j] += A[i][j + 1]; } } bool tmp = false; for (int i = 0; i < M; i++) if (Rikai[i] < X) tmp = true; if (tmp) continue; ans = Math.Min(ans, Money); } if (ans == 1000000) ans = -1; Console.WriteLine(ans); } } }
using System; namespace AtC167 { class Program { static void Main(string[] args) { string[] NMX; NMX = Console.ReadLine().Split(' '); int N = int.Parse(NMX[0]); int M = int.Parse(NMX[1]); int X = int.Parse(NMX[2]); int[][] A = new int [N][]; for (int i = 0; i < N; i++) { string[] CA = Console.ReadLine().Split(' '); A[i] = new int[M + 1]; for (int j = 0; j < M + 1; j++) A[i][j] = int.Parse(CA[j]); } int ans = 100000000; int bitflag = 0; int[] flag = new int[13] { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 }; while (bitflag < 10000) { int[] Rikai = new int[M]; int Money = 0; bitflag++; for (int i = 0; i < N; i++) { if ((bitflag & flag[i]) >= 1) { Money += A[i][0]; for (int j = 0; j < M; j++) Rikai[j] += A[i][j + 1]; } } bool tmp = false; for (int i = 0; i < M; i++) if (Rikai[i] < X) tmp = true; if (tmp) continue; ans = Math.Min(ans, Money); } if (ans == 100000000) ans = -1; Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
389
2
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int x = int.Parse(input[2]); int[,] value = new int[n, m]; int[] price = new int[n]; int[] algoCheck = new int[m]; for (int i = 0; i < n; i++) { string[] input2 = Console.ReadLine().Split(' '); price[i] = int.Parse(input2[0]); for (int j = 0; j < m; j++) { value[i, j] = int.Parse(input2[j + 1]); algoCheck[j] += value[i, j]; } } for (int j = 0; j < m; j++) { if (algoCheck[j] < x) { Console.WriteLine(-1); return; } } /*for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ Console.Write(value[i,j]+" "); } Console.WriteLine(); }*/ int min = 1000000; int sum = 0; int[] algoPoint = new int[m]; bool flag = true; for (int bit = 0; bit < (1 << n); ++bit) { // n=2であれば100未満(=3)まで調べる sum = 0; flag = true; for (int i = 0; i < n; i++) { // N=3であれば0001(=1), 0010(=2), 0100(=4)まで調べる if ((bit & (1 << i)) == (1 << i)) { // bitが1である部分に関して何らかの処理を行う sum += price[i]; for (int j = 0; j < m; j++) { algoPoint[j] += value[i, j]; } } } for (int k = 0; k < m; k++) { if (algoPoint[k] < x) flag = false; algoPoint[k] = 0; } if (flag && (min > sum)) min = sum; } Console.WriteLine(min); } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int x = int.Parse(input[2]); int[,] value = new int[n, m]; int[] price = new int[n]; int[] algoCheck = new int[m]; for (int i = 0; i < n; i++) { string[] input2 = Console.ReadLine().Split(' '); price[i] = int.Parse(input2[0]); for (int j = 0; j < m; j++) { value[i, j] = int.Parse(input2[j + 1]); algoCheck[j] += value[i, j]; } } for (int j = 0; j < m; j++) { if (algoCheck[j] < x) { Console.WriteLine(-1); return; } } /*for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ Console.Write(value[i,j]+" "); } Console.WriteLine(); }*/ int min = 100000000; int sum = 0; int[] algoPoint = new int[m]; bool flag = true; for (int bit = 0; bit < (1 << n); ++bit) { // n=2であれば100未満(=3)まで調べる sum = 0; flag = true; for (int i = 0; i < n; i++) { // N=3であれば0001(=1), 0010(=2), 0100(=4)まで調べる if ((bit & (1 << i)) == (1 << i)) { // bitが1である部分に関して何らかの処理を行う sum += price[i]; for (int j = 0; j < m; j++) { algoPoint[j] += value[i, j]; } } } for (int k = 0; k < m; k++) { if (algoPoint[k] < x) flag = false; algoPoint[k] = 0; } if (flag && (min > sum)) min = sum; } Console.WriteLine(min); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
430
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N; long K; Multi(out N, out K); var A = GetIntArray(); var dic = new Dictionary<long, long>(); long now = 1; long roop; for (long i = 0;; i++) { if (dic.ContainsKey(now)) { roop = i - dic[now]; break; } else { dic.Add(now, i); now = A[now - 1]; } } long ans = K < dic[now] ? dic.First(d => d.Value == dic[K]).Key : dic.First(d => d.Value == (K - dic[now]) % roop + dic[now]).Key; Console.WriteLine(ans); } } public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } static public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } static public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } static public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } static public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } static public void WriteObjects<T>(IReadOnlyCollection<T> values) { var array = values.ToArray(); var num = array.Length; if (num == 0) return; Console.Write(array[0]); for (int i = 1; i < num; i++) { Console.Write(" " + array[i]); } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N; long K; Multi(out N, out K); var A = GetIntArray(); var dic = new Dictionary<long, long>(); long now = 1; long roop; for (long i = 0;; i++) { if (dic.ContainsKey(now)) { roop = i - dic[now]; break; } else { dic.Add(now, i); now = A[now - 1]; } } long ans = K < dic[now] ? dic.First(d => d.Value == K).Key : dic.First(d => d.Value == (K - dic[now]) % roop + dic[now]).Key; Console.WriteLine(ans); } } public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } static public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } static public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } static public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } static public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } static public void WriteObjects<T>(IReadOnlyCollection<T> values) { var array = values.ToArray(); var num = array.Length; if (num == 0) return; Console.Write(array[0]); for (int i = 1; i < num; i++) { Console.Write(" " + array[i]); } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } }
[["-", 0, 28, 0, 218, 8, 16, 12, 204, 205, 22], ["-", 0, 218, 8, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 218, 8, 16, 12, 204, 206, 207, 0, 73]]
8
1,647
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class316 { static int N; static long K; static int[] A; static long loop = 1; static long s = 0; static int[] T1; static int[] T2; static void Main() { var NK = Console.ReadLine().Split().Select(long.Parse).ToArray(); N = (int)NK[0]; K = NK[1]; A = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); T1 = Enumerable.Repeat(-1, N).ToArray(); T2 = Enumerable.Repeat(-1, N).ToArray(); Search(0, 0); if (K > s) { Console.WriteLine(T2.ToList().IndexOf((int)((K - s) % loop)) + 1); } else { Console.WriteLine(T1.ToList().IndexOf((int)K) + 1); } } static void Search(int now, int count) { T1[now] = count; if (T1[A[now]] == -1) { Search(A[now], ++count); } else { Search2(A[now], 0); s = count + 1; } } static void Search2(int now, int count) { T2[now] = count; if (T2[A[now]] == -1) { Search2(A[now], ++count); } else { loop = count + 1; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class316 { static int N; static long K; static int[] A; static long loop = 0; static long s = 0; static int[] T1; static int[] T2; static void Main() { var NK = Console.ReadLine().Split().Select(long.Parse).ToArray(); N = (int)NK[0]; K = NK[1]; A = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); T1 = Enumerable.Repeat(-1, N).ToArray(); T2 = Enumerable.Repeat(-1, N).ToArray(); Search(0, 0); if (K >= s) { Console.WriteLine(T2.ToList().IndexOf((int)((K - s) % loop)) + 1); } else { Console.WriteLine(T1.ToList().IndexOf((int)K) + 1); } } static void Search(int now, int count) { T1[now] = count; if (T1[A[now]] == -1) { Search(A[now], ++count); } else { Search2(A[now], 0); s = count + 1; } } static void Search2(int now, int count) { T2[now] = count; if (T2[A[now]] == -1) { Search2(A[now], ++count); } else { loop = count + 1; } } } }
[["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
369
4
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 nk = IO.RSLong; var a = IO.RSInt; // var nk = new long[] { 200000, 100000000000000000 }; // var a = new int[nk[0]]; // for (int i = 0; i < a.Length; i++) //{ // a[i] = a.Length - 1; //} var visited = new List<int>(); visited.Add(1); int now = 1; int roop; int firstRoopPoint; var hash = new HashSet<int>(); hash.Add(now); while (true) { now = a[now - 1]; if (!hash.Add(now)) { firstRoopPoint = visited.IndexOf(now); roop = visited.Count - firstRoopPoint; break; } else { visited.Add(now); } } if (nk[1] <= firstRoopPoint) { WriteLine(visited[(int)nk[1] - 1]); return; } else { long add = (nk[1] - firstRoopPoint) % roop; WriteLine(visited[firstRoopPoint + (int)add]); return; } } } 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 nk = IO.RSLong; var a = IO.RSInt; // var nk = new long[] { 200000, 100000000000000000 }; // var a = new int[nk[0]]; // for (int i = 0; i < a.Length; i++) //{ // a[i] = a.Length - 1; //} var visited = new List<int>(); visited.Add(1); int now = 1; int roop; int firstRoopPoint; var hash = new HashSet<int>(); hash.Add(now); while (true) { now = a[now - 1]; if (!hash.Add(now)) { firstRoopPoint = visited.IndexOf(now); roop = visited.Count - firstRoopPoint; break; } else { visited.Add(now); } } if (nk[1] <= firstRoopPoint) { WriteLine(visited[(int)nk[1]]); return; } else { long add = (nk[1] - firstRoopPoint) % roop; WriteLine(visited[firstRoopPoint + (int)add]); return; } } } 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 } }
[["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
648
2
using System; using static System.Console; using static System.Math; using System.IO; using System.Collections.Generic; namespace 水色コーダーに俺はなった { class Inonoa { /* ここに書け */ static void Main() { long[] nk = ILongs(); long n = nk[0]; long k = nk[1]; long[] a = ILongs(); long[] last = new long[n]; for (int i = 0; i < last.Length; i++) { last[i] = -1; } long ima_turn = 0; long ima_idx = 0; long[] rireki = new long[300000]; while (true) { long tsugi = a[ima_idx] - 1; if (ima_turn == (k - 1)) { Console.WriteLine(tsugi + 1); return; } else if (tsugi == 0) { long shuki = ima_turn + 1; long amari = k % shuki; long ans = amari == 0 ? 0 : rireki[amari - 1]; WriteLine(ans + 1); return; } else if (last[tsugi] == -1) { last[tsugi] = ima_turn; } else { long shuki = ima_turn - last[tsugi]; long amari = (k - last[tsugi]) % shuki; long ans = rireki[last[tsugi] + amari - 1]; WriteLine(ans + 1); return; } ima_idx = tsugi; rireki[ima_turn] = tsugi; ima_turn++; } } static readonly long MOD = 1000000007; ///< summary>a_1, a_2, a_3, ...みたいなの</summary> static long[] ILongs() { string[] s = ReadLine().Split(); long[] re = new long[s.Length]; for (long i = 0; i < s.Length; i++) { re[i] = long.Parse(s[i]); } return re; } ///< summary>xooxoxoxxoxo...みたいなの</summary> static char[] IChars() { return ReadLine().ToCharArray(); } ///< summary>n m とかをちょっとはやくかくだけ</summary> static string[] IStrings() { return ReadLine().Split(); } ///< summary>n行の入力を取ったり</summary> static long[][] ILongLongs(long n) { long[][] re = new long [n][]; for (long i = 0; i < n; i++) { string[] s = ReadLine().Split(); re[i] = new long[s.Length]; for (long j = 0; j < s.Length; j++) { re[i][j] = long.Parse(s[j]); } } return re; } ///< summary>n行の文字列を取ったり</summary> static char[][] ICharsChars(long n) { char[][] re = new char [n][]; for (long i = 0; i < n; i++) { re[i] = ReadLine().ToCharArray(); } return re; } } }
using System; using static System.Console; using static System.Math; using System.IO; using System.Collections.Generic; namespace 水色コーダーに俺はなった { class Inonoa { /* ここに書け */ static void Main() { long[] nk = ILongs(); long n = nk[0]; long k = nk[1]; long[] a = ILongs(); long[] last = new long[n]; for (int i = 0; i < last.Length; i++) { last[i] = -1; } long ima_turn = 0; long ima_idx = 0; long[] rireki = new long[300000]; while (true) { long tsugi = a[ima_idx] - 1; if (ima_turn == (k - 1)) { Console.WriteLine(tsugi + 1); return; } else if (tsugi == 0) { long shuki = ima_turn + 1; long amari = k % shuki; long ans = amari == 0 ? 0 : rireki[amari - 1]; WriteLine(ans + 1); return; } else if (last[tsugi] == -1) { last[tsugi] = ima_turn; } else { long shuki = ima_turn - last[tsugi]; long amari = (k - (last[tsugi] + 1)) % shuki; long ans = rireki[last[tsugi] + amari]; WriteLine(ans + 1); return; } ima_idx = tsugi; rireki[ima_turn] = tsugi; ima_turn++; } } static readonly long MOD = 1000000007; ///< summary>a_1, a_2, a_3, ...みたいなの</summary> static long[] ILongs() { string[] s = ReadLine().Split(); long[] re = new long[s.Length]; for (long i = 0; i < s.Length; i++) { re[i] = long.Parse(s[i]); } return re; } ///< summary>xooxoxoxxoxo...みたいなの</summary> static char[] IChars() { return ReadLine().ToCharArray(); } ///< summary>n m とかをちょっとはやくかくだけ</summary> static string[] IStrings() { return ReadLine().Split(); } ///< summary>n行の入力を取ったり</summary> static long[][] ILongLongs(long n) { long[][] re = new long [n][]; for (long i = 0; i < n; i++) { string[] s = ReadLine().Split(); re[i] = new long[s.Length]; for (long j = 0; j < s.Length; j++) { re[i][j] = long.Parse(s[j]); } } return re; } ///< summary>n行の文字列を取ったり</summary> static char[][] ICharsChars(long n) { char[][] re = new char [n][]; for (long i = 0; i < n; i++) { re[i] = ReadLine().ToCharArray(); } return re; } } }
[["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
598
6
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var (N, K) = Cin<int, long>(); var A = Cinarr<int>().Select(x => x - 1).ToArray(); var visited = Enumerable.Repeat(-1, N).ToArray(); var loop = 0; int cur = 0; int cnt = 0; visited[0] = 0; while (true) { cur = A[cur]; cnt++; --K; if (visited[cur] >= 0) { loop = cnt - visited[cur]; break; } visited[cur] = cnt; } if (K <= cnt) { int ans = 0; for (int i = 0; i < K; ++i) { ans = A[ans]; } Put(ans + 1); } else { int ans = cur; K %= loop; for (int i = 0; i < K; ++i) { ans = A[ans]; } Put(ans + 1); } } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { if (r > n - r) r = n - r; long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno = (Deno * i) % MOD; Nume = Nume * (n - i + 1) % MOD; } return (Nume * inv(Deno)) % MOD; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } public static long inv(long x, int MOD = 1000000007) { return Power(x, MOD - 2, MOD); } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(string N) { int ret = 0; for (int i = 0; i < N.Length; ++i) ret += N[i] - '0'; return ret; } public static string ConvertBase(long N, int K) { StringBuilder ret = new StringBuilder(); while (N > 0) { var r = N % K; N /= K; ret.Append(r); } return new string(ret.ToString().ToCharArray().Reverse().ToArray()); } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static void Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void PutV<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("No"); } public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static bool IsTypeEqual<T, U>() => typeof(T).Equals(typeof(U)); public static T ConvertType<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); public static T Cast<T>(string s) { if (IsTypeEqual<T, int>()) return ConvertType<T, int>(int.Parse(s)); else if (IsTypeEqual<T, long>()) return ConvertType<T, long>(long.Parse(s)); else if (IsTypeEqual<T, double>()) return ConvertType<T, double>(double.Parse(s)); else if (IsTypeEqual<T, char>()) return ConvertType<T, char>(char.Parse(s)); else return ConvertType<T, string>(s); } public static T[] Castarr<T>(string[] s) { var ret = new T[s.Length]; int i = 0; foreach (var t in s) { if (IsTypeEqual<T, int>()) ret[i++] = ConvertType<T, int>(int.Parse(t)); else if (IsTypeEqual<T, long>()) ret[i++] = ConvertType<T, long>(long.Parse(t)); else if (IsTypeEqual<T, double>()) ret[i++] = ConvertType<T, double>(double.Parse(t)); else if (IsTypeEqual<T, char>()) ret[i++] = ConvertType<T, char>(char.Parse(t)); else ret[i++] = ConvertType<T, string>(t); } return ret; } public static T Cin<T>() { var t = Strs; return (Cast<T>(t[0])); } public static (T, U) Cin<T, U>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1])); } public static (T, U, V) Cin<T, U, V>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2])); } public static (T, U, V, W) Cin<T, U, V, W>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3])); } public static (T, U, V, W, X) Cin<T, U, V, W, X>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3]), Cast<X>(t[4])); } public static (T, U, V, W, X, Y) Cin<T, U, V, W, X, Y>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3]), Cast<X>(t[4]), Cast<Y>(t[5])); } public static (T, U, V, W, X, Y, Z) Cin<T, U, V, W, X, Y, Z>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3]), Cast<X>(t[4]), Cast<Y>(t[5]), Cast<Z>(t[6])); } public static T[] Cinarr<T>() { var t = Strs; return Castarr<T>(t); } public static T[] CinV<T>(int n) { var ret = new T[n]; for (int i = 0; i < n; ++i) { ret[i] = Cin<T>(); } return ret; } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var (N, K) = Cin<int, long>(); var kk = K; var A = Cinarr<int>().Select(x => x - 1).ToArray(); var visited = Enumerable.Repeat(-1, N).ToArray(); var loop = 0; int cur = 0; int cnt = 0; visited[0] = 0; while (true) { cur = A[cur]; cnt++; --K; if (visited[cur] >= 0) { loop = cnt - visited[cur]; break; } visited[cur] = cnt; } if (K <= cnt) { int ans = 0; for (int i = 0; i < kk; ++i) { ans = A[ans]; } Put(ans + 1); } else { int ans = cur; K %= loop; for (int i = 0; i < K; ++i) { ans = A[ans]; } Put(ans + 1); } } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { if (r > n - r) r = n - r; long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno = (Deno * i) % MOD; Nume = Nume * (n - i + 1) % MOD; } return (Nume * inv(Deno)) % MOD; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } public static long inv(long x, int MOD = 1000000007) { return Power(x, MOD - 2, MOD); } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(string N) { int ret = 0; for (int i = 0; i < N.Length; ++i) ret += N[i] - '0'; return ret; } public static string ConvertBase(long N, int K) { StringBuilder ret = new StringBuilder(); while (N > 0) { var r = N % K; N /= K; ret.Append(r); } return new string(ret.ToString().ToCharArray().Reverse().ToArray()); } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static void Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void PutV<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("No"); } public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static bool IsTypeEqual<T, U>() => typeof(T).Equals(typeof(U)); public static T ConvertType<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); public static T Cast<T>(string s) { if (IsTypeEqual<T, int>()) return ConvertType<T, int>(int.Parse(s)); else if (IsTypeEqual<T, long>()) return ConvertType<T, long>(long.Parse(s)); else if (IsTypeEqual<T, double>()) return ConvertType<T, double>(double.Parse(s)); else if (IsTypeEqual<T, char>()) return ConvertType<T, char>(char.Parse(s)); else return ConvertType<T, string>(s); } public static T[] Castarr<T>(string[] s) { var ret = new T[s.Length]; int i = 0; foreach (var t in s) { if (IsTypeEqual<T, int>()) ret[i++] = ConvertType<T, int>(int.Parse(t)); else if (IsTypeEqual<T, long>()) ret[i++] = ConvertType<T, long>(long.Parse(t)); else if (IsTypeEqual<T, double>()) ret[i++] = ConvertType<T, double>(double.Parse(t)); else if (IsTypeEqual<T, char>()) ret[i++] = ConvertType<T, char>(char.Parse(t)); else ret[i++] = ConvertType<T, string>(t); } return ret; } public static T Cin<T>() { var t = Strs; return (Cast<T>(t[0])); } public static (T, U) Cin<T, U>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1])); } public static (T, U, V) Cin<T, U, V>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2])); } public static (T, U, V, W) Cin<T, U, V, W>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3])); } public static (T, U, V, W, X) Cin<T, U, V, W, X>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3]), Cast<X>(t[4])); } public static (T, U, V, W, X, Y) Cin<T, U, V, W, X, Y>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3]), Cast<X>(t[4]), Cast<Y>(t[5])); } public static (T, U, V, W, X, Y, Z) Cin<T, U, V, W, X, Y, Z>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3]), Cast<X>(t[4]), Cast<Y>(t[5]), Cast<Z>(t[6])); } public static T[] Cinarr<T>() { var t = Strs; return Castarr<T>(t); } public static T[] CinV<T>(int n) { var ret = new T[n]; for (int i = 0; i < n; ++i) { ret[i] = Cin<T>(); } return ret; } }
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 12, 22]]
8
2,074
7
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 k = long.Parse(spl[1]); var aa = ToIntArray(input.ReadLine(), n); var hash = new HashSet<int>(); var list = new List<int>(); int i = 0; while (true) { if (k == 0) { return list.Last() + 1; } if (hash.Contains(i)) { var ll = new List<int>(); bool sw = false; for (int z = 0; z < list.Count; z++) { var v = list[z]; if (v == i) { sw = true; } if (sw) ll.Add(v); } return ll[(int)(k % (long)ll.Count)] + 1; } list.Add(i); hash.Add(i); k--; i = aa[i] - 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 k = long.Parse(spl[1]); var aa = ToIntArray(input.ReadLine(), n); var hash = new HashSet<int>(); var list = new List<int>(); int i = 0; while (true) { if (k == 0) { return i + 1; } if (hash.Contains(i)) { var ll = new List<int>(); bool sw = false; for (int z = 0; z < list.Count; z++) { var v = list[z]; if (v == i) { sw = true; } if (sw) ll.Add(v); } return ll[(int)(k % (long)ll.Count)] + 1; } list.Add(i); hash.Add(i); k--; i = aa[i] - 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, 37, 0, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 37, 0, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 37, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 37, 0, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 37, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 57, 64, 196, 0, 37, 0, 16, 31, 22]]
8
419
6
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var N = sc.ReadInt(); var K = sc.ReadLong(); var A = sc.ReadIntArray(N); // 0-indexed にしておく for (int i = 0; i < N; i++) A[i]--; // 0からの距離を記録しておく var dist = new long[N]; for (int i = 0; i < N; i++) { dist[i] = -1; } // ループ開始地点, ループ終了地点(次のテレポートでloopSに戻る) var loopS = 0; var loopE = 0; var now = 0; var d = 0; // ループするまでテレポートを繰り返す while (dist[now] == -1) { dist[now] = d++; loopE = now; now = A[now]; // K回テレポートができたので終了 if (d == K) { Console.WriteLine(now); return; } } loopS = now; // ループ1周の長さ var loopdist = dist[loopE] - dist[loopS] + 1; // ループの長さで余りをとる K = (K - dist[loopS]) % loopdist; // ループの開始地点からあまり分テレポートする now = loopS; while (K > 0) { K--; now = A[now]; } var ans = now + 1; Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var N = sc.ReadInt(); var K = sc.ReadLong(); var A = sc.ReadIntArray(N); // 0-indexed にしておく for (int i = 0; i < N; i++) A[i]--; // 0からの距離を記録しておく var dist = new long[N]; for (int i = 0; i < N; i++) { dist[i] = -1; } // ループ開始地点, ループ終了地点(次のテレポートでloopSに戻る) var loopS = 0; var loopE = 0; var now = 0; var d = 0; // ループするまでテレポートを繰り返す while (dist[now] == -1) { dist[now] = d++; loopE = now; now = A[now]; // K回テレポートができたので終了 if (d == K) { Console.WriteLine(now + 1); return; } } loopS = now; // ループ1周の長さ var loopdist = dist[loopE] - dist[loopS] + 1; // ループの長さで余りをとる K = (K - dist[loopS]) % loopdist; // ループの開始地点からあまり分テレポートする now = loopS; while (K > 0) { K--; now = A[now]; } var ans = now + 1; Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
1,280
2
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); // var n = long.Parse(Console.ReadLine()); long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray(); long n = input[0]; long k = input[1]; long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray(); int[] visited = new int[n]; var list = new List<long>(); long i = 0; int count = 0; int loopstart = 0; int loopend = 0; while (true) { if (visited[i] == 2) { loopend = count + 1; break; } else if (visited[i] == 1 && loopstart == 0) { loopstart = count + 1; visited[i]++; list.Add(i); i = a[i] - 1; } else { visited[i]++; list.Add(i); i = a[i] - 1; } count++; } long ans = 0; if (k < list.Count) { ans = list[(int)(k - 1)]; } else { long tmp = k % (loopend - loopstart); long tmp2 = 0; for (int t = loopstart - 1; t < loopend - 1; t++) { if (tmp == t % (loopend - loopstart)) { tmp2 = t; break; } } ans = list[(int)tmp2] + 1; } // 出力 Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); // var n = long.Parse(Console.ReadLine()); long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray(); long n = input[0]; long k = input[1]; long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray(); int[] visited = new int[n]; var list = new List<long>(); long i = 0; int count = 0; int loopstart = 0; int loopend = 0; while (true) { if (visited[i] == 2) { loopend = count + 1; break; } else if (visited[i] == 1 && loopstart == 0) { loopstart = count + 1; visited[i]++; list.Add(i); i = a[i] - 1; } else { visited[i]++; list.Add(i); i = a[i] - 1; } count++; } long ans = 0; if (k < list.Count) { ans = list[(int)(k)] + 1; } else { long tmp = k % (loopend - loopstart); long tmp2 = 0; for (int t = loopstart - 1; t < loopend - 1; t++) { if (tmp == t % (loopend - loopstart)) { tmp2 = t; break; } } ans = list[(int)tmp2] + 1; } // 出力 Console.WriteLine(ans); } }
[["-", 0, 28, 0, 74, 51, 23, 0, 16, 17, 33], ["-", 0, 28, 0, 74, 51, 23, 0, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
358
4
using System; using System.Linq; using System.Collections.Generic; namespace ABC167 { class C { static void Main(string[] args) { var NK = Console.ReadLine().Split().Select(long.Parse).ToArray(); var N = NK[0]; var K = NK[1]; var A = Console.ReadLine().Split().Select(long.Parse).ToArray(); var B = new long[N + 1]; // N回目の移動でいるます var Visited = new bool[N]; B[0] = 1; Visited[0] = true; for (int i = 1; i < N + 1; i++) { B[i] = A[B[i - 1] - 1]; } if (K <= N) { Console.WriteLine(B[N]); return; } long index = 0; for (int i = 1; i < N + 1; i++) { if (!Visited[B[i] - 1]) Visited[B[i] - 1] = true; else { index = i; break; } } var num = B[index]; // Console.WriteLine(num); // Console.WriteLine(index); long start = 0; for (int i = 0; i < N + 1; i++) { if (B[i] == num) { start = i; break; } } // Console.WriteLine(start); // start 番目に num がでる // idnex 番目に num がまたでる K = (K - start) % (index - start); var ans = B[start + K]; Console.WriteLine(ans); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC167 { class C { static void Main(string[] args) { var NK = Console.ReadLine().Split().Select(long.Parse).ToArray(); var N = NK[0]; var K = NK[1]; var A = Console.ReadLine().Split().Select(long.Parse).ToArray(); var B = new long[N + 1]; // N回目の移動でいるます var Visited = new bool[N]; B[0] = 1; Visited[0] = true; for (int i = 1; i < N + 1; i++) { B[i] = A[B[i - 1] - 1]; } if (K <= N) { Console.WriteLine(B[K]); return; } long index = 0; for (int i = 1; i < N + 1; i++) { if (!Visited[B[i] - 1]) Visited[B[i] - 1] = true; else { index = i; break; } } var num = B[index]; // Console.WriteLine(num); // Console.WriteLine(index); long start = 0; for (int i = 0; i < N + 1; i++) { if (B[i] == num) { start = i; break; } } // Console.WriteLine(start); // start 番目に num がでる // idnex 番目に num がまたでる K = (K - start) % (index - start); var ans = B[start + K]; Console.WriteLine(ans); } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22]]
8
329
2
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 K = long.Parse(input[1]); int[] A = new int[N]; long[] temp = new long[N]; input = Console.ReadLine().Split(); for (int i = 0; i < N; i++) { A[i] = int.Parse(input[i]); temp[i] = 0; } int now = 0; long counter = 1; int ans = -1; for (long i = 0; i < K; i++) { if (temp[now] == 0) { temp[now] = counter; now = A[now] - 1; counter++; } else if (now == A[now] - 1) { ans = now + 1; i = K; } else { K = K % (counter - temp[now]); for (int x = 0; x < K; x++) { now = A[now] - 1; } } } if (ans == -1) { ans = now + 1; } 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 K = long.Parse(input[1]); int[] A = new int[N]; long[] temp = new long[N]; input = Console.ReadLine().Split(); for (int i = 0; i < N; i++) { A[i] = int.Parse(input[i]); temp[i] = 0; } int now = 0; long counter = 1; int ans = -1; for (long i = 0; i < K; i++) { if (temp[now] == 0) { temp[now] = counter; now = A[now] - 1; counter++; } else if (now == A[now] - 1) { ans = now + 1; i = K; } else { K = (K - counter + 1) % (counter - temp[now]); for (int x = 0; x < K; x++) { now = A[now] - 1; } } } if (ans == -1) { ans = now + 1; } Console.WriteLine(ans); } }
[["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25]]
8
294
6
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; } private static int[] ReadIntArr() { string[] s = ReadStringArr(); int[] l = new int[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = int.Parse(s[i]); } return l; } static void Main(string[] args) { var NN = ReadLongArr(); var AA = ReadLongArr(); var G = new long[NN[0] + 1]; G[0] = 1; HashSet<long> visited = new HashSet<long>(); visited.Add(1); long c = 1; for (long i = 1; i < NN[0] + 1; i++) { c = AA[G[i - 1] - 1]; if (i + 1 == NN[1]) { Console.WriteLine(c); return; } if (visited.Contains(c)) { break; } visited.Add(c); G[i] = c; } for (long i = 0; i < NN[0] + 1; i++) { long cnt = NN[1]; if (G[i] == c) { cnt -= i; long mod = cnt % (visited.Count - i); Console.WriteLine(G[i + mod]); return; } } } } }
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; } private static int[] ReadIntArr() { string[] s = ReadStringArr(); int[] l = new int[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = int.Parse(s[i]); } return l; } static void Main(string[] args) { var NN = ReadLongArr(); var AA = ReadLongArr(); var G = new long[NN[0] + 1]; G[0] = 1; HashSet<long> visited = new HashSet<long>(); visited.Add(1); long c = 1; for (long i = 1; i < NN[0] + 1; i++) { c = AA[G[i - 1] - 1]; if (i == NN[1]) { Console.WriteLine(c); return; } if (visited.Contains(c)) { break; } visited.Add(c); G[i] = c; } for (long i = 0; i < NN[0] + 1; i++) { long cnt = NN[1]; if (G[i] == c) { cnt -= i; long mod = cnt % (visited.Count - i); Console.WriteLine(G[i + mod]); return; } } } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
2,216
2
using System; class MainClass { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int S = int.Parse(input[0]); int W = int.Parse(input[1]); string result; if (S <= W) { Console.WriteLine("Unsafe"); } else { Console.WriteLine("Safe"); } } }
using System; class MainClass { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int S = int.Parse(input[0]); int W = int.Parse(input[1]); string result; if (S <= W) { Console.WriteLine("unsafe"); } else { Console.WriteLine("safe"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
95
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static int S; static int W; static void INPUT() { S = NextInt(); W = NextInt(); } static void OUT() { Console.WriteLine(S < W ? "safe" : "unsafe"); } static void Main(string[] args) { #if DEBUG // TESTINPUT(); INPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() {} } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static int S; static int W; static void INPUT() { S = NextInt(); W = NextInt(); } static void OUT() { Console.WriteLine(S <= W ? "unsafe" : "safe"); } static void Main(string[] args) { #if DEBUG // TESTINPUT(); INPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() {} } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19], ["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
437
6
using System; namespace _164_1 { class Program { static void Main(string[] args) { string a = Console.ReadLine(); var b = a.Split(' '); if (int.Parse(b[0]) > int.Parse(b[1])) { Console.WriteLine("safe"); } else { Console.WriteLine("unsefe"); } } } }
using System; namespace _164_1 { class Program { static void Main(string[] args) { string a = Console.ReadLine(); var b = a.Split(' '); if (int.Parse(b[0]) > int.Parse(b[1])) { Console.WriteLine("safe"); } else { Console.WriteLine("unsafe"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
88
2
using System; namespace ConsoleApp23 { class Program { static void Main(string[] args) { string line = Console.ReadLine(); string[] array = line.Split(' '); int a = int.Parse(array[0]); int b = int.Parse(array[1]); int c = int.Parse(array[2]); int d = int.Parse(array[3]); int ar = 0; int br = 0; if (c % b == 0) { ar = c / b; } else { ar = c / b; ar += 1; } if (a % d == 0) { br = a / d; } else { br = a / d; br += 1; } if (ar >= br) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; namespace ConsoleApp23 { class Program { static void Main(string[] args) { string line = Console.ReadLine(); string[] array = line.Split(' '); int a = int.Parse(array[0]); int b = int.Parse(array[1]); int c = int.Parse(array[2]); int d = int.Parse(array[3]); int ar = 0; int br = 0; if (c % b == 0) { ar = c / b; } else { ar = c / b; ar += 1; } if (a % d == 0) { br = a / d; } else { br = a / d; br += 1; } if (ar <= br) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
8
194
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _20_0362_Atcorder { 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 D = int.Parse(input[3]); Duerist duerist1 = new Duerist(); duerist1.Name = "高橋"; duerist1.HP = A; duerist1.ATTACK = C; Duerist duerist2 = new Duerist(); duerist2.Name = "青木"; duerist2.HP = B; duerist2.ATTACK = D; while (true) { B -= D; if (B <= 0) { Console.Write("Yes"); break; } A -= C; if (A <= 0) { Console.Write("No"); break; } } Console.Read(); } public class Duerist { public string Name; public int HP; public int ATTACK; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _20_0362_Atcorder { 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 D = int.Parse(input[3]); Duerist duerist1 = new Duerist(); duerist1.Name = "高橋"; duerist1.HP = A; duerist1.ATTACK = B; Duerist duerist2 = new Duerist(); duerist2.Name = "青木"; duerist2.HP = C; duerist2.ATTACK = D; while (true) { C -= B; if (C <= 0) { Console.Write("Yes"); break; } A -= D; if (A <= 0) { Console.Write("No"); break; } } Console.Read(); } public class Duerist { public string Name; public int HP; public int ATTACK; } } }
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22]]
8
247
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Battle_0528_1問目 { class Program { static void Main(string[] args) { string[] A = Console.ReadLine().Split(' '); int W = int.Parse(A[0]); int X = int.Parse(A[1]); int Y = int.Parse(A[2]); int Z = int.Parse(A[3]); Duelist duelist1 = new Duelist(); duelist1.Name = "高橋"; duelist1.HP = W; duelist1.Attack = Y; Duelist duelist2 = new Duelist(); duelist2.Name = "青木"; duelist2.HP = Y; duelist2.Attack = Z; while (true) { duelist2.HP -= duelist1.Attack; if (duelist2.HP <= 0) { Console.WriteLine("Yes"); break; } duelist1.HP -= duelist2.Attack; if (duelist1.HP <= 0) { Console.WriteLine("No"); break; } } Console.Read(); } } class Duelist { public string Name; public int HP; public int Attack; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Battle_0528_1問目 { class Program { static void Main(string[] args) { string[] A = Console.ReadLine().Split(' '); int W = int.Parse(A[0]); int X = int.Parse(A[1]); int Y = int.Parse(A[2]); int Z = int.Parse(A[3]); Duelist duelist1 = new Duelist(); duelist1.Name = "高橋"; duelist1.HP = W; duelist1.Attack = X; Duelist duelist2 = new Duelist(); duelist2.Name = "青木"; duelist2.HP = Y; duelist2.Attack = Z; while (true) { duelist2.HP -= duelist1.Attack; if (duelist2.HP <= 0) { Console.WriteLine("Yes"); break; } duelist1.HP -= duelist2.Attack; if (duelist1.HP <= 0) { Console.WriteLine("No"); break; } } Console.Read(); } } class Duelist { public string Name; public int HP; public int Attack; } }
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22]]
8
259
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _20200528kensyu { 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 D = int.Parse(input[3]); //高橋君のインスタンス Duelist duelist1 = new Duelist(); duelist1.Name = "高橋"; duelist1.HP = A; duelist1.Attack = B; //青木君のインスタンス Duelist duelist2 = new Duelist(); duelist2.Name = "青木"; duelist2.HP = C; duelist2.Attack = D; while (true) { duelist2.HP -= duelist1.Attack; //高橋君が青木君に攻撃 if (duelist2.HP <= 0) { Console.WriteLine("Yes"); break; } A -= D; //青木君が高橋君に攻撃 if (duelist1.HP <= 0) { Console.WriteLine("No"); break; } } Console.Read(); } } class Duelist //名前、HP、攻撃力 { public string Name; public int HP; public int Attack; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _20200528kensyu { 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 D = int.Parse(input[3]); //高橋君のインスタンス Duelist duelist1 = new Duelist(); duelist1.Name = "高橋"; duelist1.HP = A; duelist1.Attack = B; //青木君のインスタンス Duelist duelist2 = new Duelist(); duelist2.Name = "青木"; duelist2.HP = C; duelist2.Attack = D; while (true) { duelist2.HP -= duelist1.Attack; //高橋君が青木君に攻撃 if (duelist2.HP <= 0) { Console.WriteLine("Yes"); break; } duelist1.HP -= duelist2.Attack; //青木君が高橋君に攻撃 if (duelist1.HP <= 0) { Console.WriteLine("No"); break; } } Console.Read(); } } class Duelist //名前、HP、攻撃力 { public string Name; public int HP; public int Attack; } }
[["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 11, 31, 214, 141, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 141, 22]]
8
259
8
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.Contests.ABC164 { /// <summary> /// /// </summary> static class B { static void Main(string[] args) { var a = NextInt(); var b = NextInt(); var c = NextInt(); var d = NextInt(); Console.WriteLine((d + b - 1) / b <= (a + c - 1) / c ? "Yes" : "No"); } #region Console static int _index = 0; static string[] _buffer; static string Next() { if (_buffer == null || _index >= _buffer.Length) { _buffer = Console.ReadLine().Split(); _index = 0; } return _buffer[_index++]; } static int NextInt() { return int.Parse(Next()); } static long NextLong() { return long.Parse(Next()); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } static List<T> ReadObjects<T>(int n, Func<int[], T> creator) { var l = new List<T>(n); for (int i = 0; i < n; i++) { var a = ReadIntArray(); l.Add(creator(a)); } return l; } static int[,] ReadMatrix(int n, int m) { var r = new int[n, m]; for (int i = 0; i < n; i++) { var a = ReadIntArray(); for (int j = 0; j < m; j++) { r[i, j] = a[j]; } } return r; } #endregion } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.Contests.ABC164 { /// <summary> /// /// </summary> static class B { static void Main(string[] args) { var a = NextInt(); var b = NextInt(); var c = NextInt(); var d = NextInt(); Console.WriteLine((c + b - 1) / b <= (a + d - 1) / d ? "Yes" : "No"); } #region Console static int _index = 0; static string[] _buffer; static string Next() { if (_buffer == null || _index >= _buffer.Length) { _buffer = Console.ReadLine().Split(); _index = 0; } return _buffer[_index++]; } static int NextInt() { return int.Parse(Next()); } static long NextLong() { return long.Parse(Next()); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } static List<T> ReadObjects<T>(int n, Func<int[], T> creator) { var l = new List<T>(n); for (int i = 0; i < n; i++) { var a = ReadIntArray(); l.Add(creator(a)); } return l; } static int[,] ReadMatrix(int n, int m) { var r = new int[n, m]; for (int i = 0; i < n; i++) { var a = ReadIntArray(); for (int j = 0; j < m; j++) { r[i, j] = a[j]; } } return r; } #endregion } }
[["-", 31, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 31, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["-", 12, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["-", 0, 28, 0, 41, 15, 16, 12, 16, 12, 22], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 12, 22]]
8
553
6
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace Atcoder { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var input = ReadTexts(); string result; long takahasiHP = input[0].ToLong(); long takahasiATK = input[1].ToLong(); long aokiHP = input[2].ToLong(); long aokiATK = input[3].ToLong(); if (((aokiHP / takahasiATK) + (aokiHP % takahasiATK == 0 ? 0 : 1)) <= ((takahasiHP / aokiATK) + (takahasiHP % aokiATK == 0 ? 0 : 1))) { result = "yes"; } else { result = "no"; } return result; } #region Console public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } #endregion } public static class CastExtention { public static long ToLong(this string a) { return long.Parse(a); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace Atcoder { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var input = ReadTexts(); string result; long takahasiHP = input[0].ToLong(); long takahasiATK = input[1].ToLong(); long aokiHP = input[2].ToLong(); long aokiATK = input[3].ToLong(); if (((aokiHP / takahasiATK) + (aokiHP % takahasiATK == 0 ? 0 : 1)) <= ((takahasiHP / aokiATK) + (takahasiHP % aokiATK == 0 ? 0 : 1))) { result = "Yes"; } else { result = "No"; } return result; } #region Console public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } #endregion } public static class CastExtention { public static long ToLong(this string a) { return long.Parse(a); } } }
[["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["-", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
260
4
using System; // using System.Collections.Generic; public class TestC { public static void Main() { string line = Console.ReadLine(); string[] numbers = line.Split(' '); int takahashi_HP = int.Parse(numbers[0]); int takahashi_AP = int.Parse(numbers[1]); int aoki_HP = int.Parse(numbers[2]); int aoki_AP = int.Parse(numbers[3]); while (takahashi_HP > 0 || aoki_HP > 0) { aoki_HP = aoki_HP - takahashi_AP; takahashi_HP = takahashi_HP - aoki_AP; } if (aoki_HP <= 0) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
using System; // using System.Collections.Generic; public class TestC { public static void Main() { string line = Console.ReadLine(); string[] numbers = line.Split(' '); int takahashi_HP = int.Parse(numbers[0]); int takahashi_AP = int.Parse(numbers[1]); int aoki_HP = int.Parse(numbers[2]); int aoki_AP = int.Parse(numbers[3]); while (takahashi_HP > 0 && aoki_HP > 0) { aoki_HP = aoki_HP - takahashi_AP; takahashi_HP = takahashi_HP - aoki_AP; } if (aoki_HP <= 0) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 106], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 98]]
8
141
2
using System; namespace B { class Program { static int[] ToInt(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[] IntAry = ToInt(Console.ReadLine().Split(' ')); int Count = 0, Player; int[] HP = new int[2]; HP[0] = IntAry[0]; HP[1] = IntAry[2]; int[] ATK = new int[2]; ATK[0] = IntAry[1]; ATK[1] = IntAry[3]; string[] Output = new string[2] { "No", "Yes" }; while (true) { Player = Count % 2; if (Player == 0) { HP[1] -= ATK[Player]; } else { HP[0] -= ATK[Player]; } if (HP[0] < 0 || HP[1] < 0) { Console.WriteLine(Output[Player]); break; } Count++; } } } }
using System; namespace B { class Program { static int[] ToInt(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[] IntAry = ToInt(Console.ReadLine().Split(' ')); int Count = 0, Player; int[] HP = new int[2]; HP[0] = IntAry[0]; HP[1] = IntAry[2]; int[] ATK = new int[2]; ATK[0] = IntAry[1]; ATK[1] = IntAry[3]; string[] Output = new string[2] { "Yes", "No" }; while (true) { Player = Count % 2; if (Player == 0) { HP[1] -= ATK[Player]; } else { HP[0] -= ATK[Player]; } if (HP[0] <= 0 || HP[1] <= 0) { Console.WriteLine(Output[Player]); break; } Count++; } } } }
[["-", 0, 212, 0, 227, 0, 229, 0, 5, 0, 222], ["+", 0, 212, 0, 227, 0, 229, 0, 5, 0, 222], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
8
273
8
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var a = ni(); var b = ni(); var c = ni(); var d = ni(); cout.WriteLine(Solve(a, b, c, d) ? "Yes" : "No"); } bool Solve(int a, int b, int c, int d) { if (a <= 0) return true; return !Solve(c - b, d, a, b); } } // PREWRITEN CODE BEGINS FROM HERE internal partial class Solver : Scanner { public static void Main() { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) { Console.SetIn(reader); new Solver(Console.In, Console.Out).Run(); } #else Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } internal static class LinqPadExtension { [Conditional("DEBUG")] public static void Dump<T>(this T obj) { #if DEBUG LINQPad.Extensions.Dump(obj); #endif } } public class Scanner { private readonly TextReader Reader; private readonly CultureInfo ci = CultureInfo.InvariantCulture; private readonly char[] buffer = new char[2 * 1024]; private int cursor = 0, length = 0; private string Token; private readonly StringBuilder sb = new StringBuilder(1024); public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return checked((int)NextLong()); } public long NextLong() { var s = Next(); long r = 0; int i = 0; bool negative = false; if (s[i] == '-') { negative = true; i++; } for (; i < s.Length; i++) { r = r * 10 + (s[i] - '0'); #if DEBUG if (!char.IsDigit(s[i])) throw new FormatException(); #endif } return negative ? -r : r; } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (Token == null) { if (!StockToken()) { throw new Exception(); } } var token = Token; Token = null; return token; } public bool HasNext() { if (Token != null) { return true; } return StockToken(); } private bool StockToken() { while (true) { sb.Clear(); while (true) { if (cursor >= length) { cursor = 0; if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) { break; } } var c = buffer[cursor++]; if (33 <= c && c <= 126) { sb.Append(c); } else { if (sb.Length > 0) break; } } if (sb.Length > 0) { Token = sb.ToString(); return true; } return false; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var a = ni(); var b = ni(); var c = ni(); var d = ni(); cout.WriteLine(Solve(a, b, c, d) ? "Yes" : "No"); } bool Solve(int a, int b, int c, int d) { if (a <= 0) return false; return !Solve(c - b, d, a, b); } } // PREWRITEN CODE BEGINS FROM HERE internal partial class Solver : Scanner { public static void Main() { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) { Console.SetIn(reader); new Solver(Console.In, Console.Out).Run(); } #else Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } internal static class LinqPadExtension { [Conditional("DEBUG")] public static void Dump<T>(this T obj) { #if DEBUG LINQPad.Extensions.Dump(obj); #endif } } public class Scanner { private readonly TextReader Reader; private readonly CultureInfo ci = CultureInfo.InvariantCulture; private readonly char[] buffer = new char[2 * 1024]; private int cursor = 0, length = 0; private string Token; private readonly StringBuilder sb = new StringBuilder(1024); public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return checked((int)NextLong()); } public long NextLong() { var s = Next(); long r = 0; int i = 0; bool negative = false; if (s[i] == '-') { negative = true; i++; } for (; i < s.Length; i++) { r = r * 10 + (s[i] - '0'); #if DEBUG if (!char.IsDigit(s[i])) throw new FormatException(); #endif } return negative ? -r : r; } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (Token == null) { if (!StockToken()) { throw new Exception(); } } var token = Token; Token = null; return token; } public bool HasNext() { if (Token != null) { return true; } return StockToken(); } private bool StockToken() { while (true) { sb.Clear(); while (true) { if (cursor >= length) { cursor = 0; if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) { break; } } var c = buffer[cursor++]; if (33 <= c && c <= 126) { sb.Append(c); } else { if (sb.Length > 0) break; } } if (sb.Length > 0) { Token = sb.ToString(); return true; } return false; } } }
[["-", 8, 196, 0, 57, 64, 37, 0, 211, 0, 146], ["+", 8, 196, 0, 57, 64, 37, 0, 211, 0, 147]]
8
1,161
2
using System; using static System.Console; using System.Linq; namespace AC { public class shiokara { static void Main(string[] args) { int[] a = ReadLine().Split(' ').Select(int.Parse).ToArray(); int[] takahasi = new int[] { a[0], a[1] }; int[] aoki = new int[] { a[2], a[3] }; int taka = takahasi[0] / aoki[1]; if (takahasi[0] % aoki[1] != 0) taka++; int ao = aoki[0] / takahasi[1]; if (aoki[0] % takahasi[1] != 0) ao++; if (taka <= ao) WriteLine("Yes"); else WriteLine("No"); } } }
using System; using static System.Console; using System.Linq; namespace AC { public class shiokara { static void Main(string[] args) { int[] a = ReadLine().Split(' ').Select(int.Parse).ToArray(); int[] takahasi = new int[] { a[0], a[1] }; int[] aoki = new int[] { a[2], a[3] }; int taka = takahasi[0] / aoki[1]; if (takahasi[0] % aoki[1] != 0) taka++; int ao = aoki[0] / takahasi[1]; if (aoki[0] % takahasi[1] != 0) ao++; if (taka >= ao) WriteLine("Yes"); else WriteLine("No"); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
184
2
using System; using System.Collections.Generic; using System.Linq; using System.Net.WebSockets; namespace AtCoderApp { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var param = new int[input.Length]; for (int i = 0; i < param.Length; i++) { param[i] = int.Parse(input[i]); } while (param[0] > 0 || param[2] > 0) { param[2] = param[2] - param[1]; if (param[2] == 0) { Console.WriteLine("Yes"); return; } param[0] = param[0] - param[3]; if (param[0] == 0) { Console.WriteLine("No"); return; } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Net.WebSockets; namespace AtCoderApp { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var param = new int[input.Length]; for (int i = 0; i < param.Length; i++) { param[i] = int.Parse(input[i]); } while (param[0] > 0 || param[2] > 0) { param[2] = param[2] - param[1]; if (param[2] <= 0) { Console.WriteLine("Yes"); return; } param[0] = param[0] - param[3]; if (param[0] <= 0) { Console.WriteLine("No"); return; } } } } }
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 19]]
8
193
4
using System; using System.Linq; using CompLib.Util; public class Program { public void Solve() { var sc = new Scanner(); int a = sc.NextInt(); int b = sc.NextInt(); int c = sc.NextInt(); int d = sc.NextInt(); for (int i = 0;; i++) { if (i % 2 == 0) { c -= b; if (c <= 0) { Console.WriteLine("Yes"); return; } } else { a -= d; if (a <= 0) { Console.WriteLine("NO"); return; } } } } 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 a = sc.NextInt(); int b = sc.NextInt(); int c = sc.NextInt(); int d = sc.NextInt(); for (int i = 0;; i++) { if (i % 2 == 0) { c -= b; if (c <= 0) { Console.WriteLine("Yes"); return; } } else { a -= d; if (a <= 0) { Console.WriteLine("No"); return; } } } } 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(); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
469
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C_gacha { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] Thg = new string[N]; for (int i = 0; i <= N; i++) { Thg[i] = Console.ReadLine(); } Console.WriteLine(Thg.Distinct().ToArray().Length); Console.Read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C_gacha { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] Thg = new string[N]; for (int i = 0; i < N; i++) { Thg[i] = Console.ReadLine(); } Console.WriteLine(Thg.Distinct().ToArray().Length); Console.Read(); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18]]
8
121
2
using System; using System.Collections.Generic; namespace AtCoder { public static class AtCoder { public static void Main() { long n = long.Parse(Console.ReadLine()); var l = new string[n]; long ans = 0; for (long i = 0; i < n; i++) { var s = Console.ReadLine(); l[i] = s; } Array.Sort(l); string tmp = string.Empty; for (long i = 1; i < n; i++) { if (tmp != l[i]) { ans++; } tmp = l[i]; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; namespace AtCoder { public static class AtCoder { public static void Main() { long n = long.Parse(Console.ReadLine()); var l = new string[n]; long ans = 0; for (long i = 0; i < n; i++) { var s = Console.ReadLine(); l[i] = s; } Array.Sort(l); string tmp = string.Empty; for (long i = 0; i < n; i++) { if (tmp != l[i]) { ans++; } tmp = l[i]; } Console.WriteLine(ans); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
146
2
using System; using System.ComponentModel; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var NK = Console.ReadLine().Split(" "); int[] num = new int[int.Parse(NK[0]) + 1]; for (int i = 1; i <= int.Parse(NK[1]); i++) { int d = int.Parse(Console.ReadLine()); int[] A = Console.ReadLine().Split(" ").Select(int.Parse).ToArray(); foreach (int j in A) { num[j] += 1; } } int res = 0; for (int i = 1; i < int.Parse(NK[0]); i++) { if (num[i] == 0) { res += 1; } } Console.WriteLine(res); } } }
using System; using System.ComponentModel; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var NK = Console.ReadLine().Split(" "); int[] num = new int[int.Parse(NK[0]) + 1]; for (int i = 1; i <= int.Parse(NK[1]); i++) { int d = int.Parse(Console.ReadLine()); int[] A = Console.ReadLine().Split(" ").Select(int.Parse).ToArray(); foreach (int j in A) { num[j] += 1; } } int res = 0; for (int i = 1; i <= int.Parse(NK[0]); i++) { if (num[i] == 0) { res += 1; } } Console.WriteLine(res); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
203
2
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Abc166B { public static void Main() { var nk = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); var n = nk[0]; var k = nk[1]; var sunuke = new bool[n]; for (int i = 0; i < k; i++) { var d = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(j => int.Parse(j) - 1).ToArray(); for (int j = 0; j < a.Length; j++) sunuke[j] = true; } Console.WriteLine(sunuke.Count(i => !i)); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Abc166B { public static void Main() { var nk = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); var n = nk[0]; var k = nk[1]; var sunuke = new bool[n]; for (int i = 0; i < k; i++) { var d = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(j => int.Parse(j) - 1).ToArray(); for (int j = 0; j < a.Length; j++) sunuke[a[j]] = true; } Console.WriteLine(sunuke.Count(i => !i)); } } }
[["+", 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]]
8
190
3
using System; using System.Numerics; using System.Linq; using System.Collections.Generic; using System.Text; namespace debug { class ProgramB { static void Main(string[] args) { //入力 string[] a = Console.ReadLine().Split(' '); int n = int.Parse(a[0]); int k = int.Parse(a[0]); int[] sunuke = new int[n]; for (int i = 0; i < n; i++) { int d = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); for (int j = 0; j < d; j++) { sunuke[int.Parse(s[j]) - 1] = 1; } } int count = 0; for (int i = 0; i < n; i++) { if (sunuke[i] == 0) count++; } Console.WriteLine(count); } } }
using System; using System.Numerics; using System.Linq; using System.Collections.Generic; using System.Text; namespace debug { class ProgramB { static void Main(string[] args) { //入力 string[] a = Console.ReadLine().Split(' '); int n = int.Parse(a[0]); int k = int.Parse(a[1]); int[] sunuke = new int[n]; for (int i = 0; i < k; i++) { int d = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); for (int j = 0; j < d; j++) { sunuke[int.Parse(s[j]) - 1] = 1; } } int count = 0; for (int i = 0; i < n; i++) { if (sunuke[i] == 0) count++; } Console.WriteLine(count); } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
221
4
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; namespace ForAtcoder { class Program { static void Main(string[] args) { long[] nm = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); var n = nm[0]; var m = nm[1]; long[] h = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long[,] abs = new long[2, m]; for (var i = 0; i < m; i++) { long[] ab = Console.ReadLine().Split(' ').Select(j => long.Parse(j)).ToArray(); abs[0, i] = ab[0]; abs[1, i] = ab[1]; } var count = 0; var bad = new HashSet<long>(); for (var i = 0; i < m; i++) { if (h[abs[0, i] - 1] >= h[abs[1, i] - 1]) bad.Add(abs[1, i]); else if (h[abs[0, i] - 1] <= h[abs[1, i] - 1]) bad.Add(abs[0, i]); } Console.WriteLine(n - bad.Count); } } }
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; namespace ForAtcoder { class Program { static void Main(string[] args) { long[] nm = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); var n = nm[0]; var m = nm[1]; long[] h = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long[,] abs = new long[2, m]; for (var i = 0; i < m; i++) { long[] ab = Console.ReadLine().Split(' ').Select(j => long.Parse(j)).ToArray(); abs[0, i] = ab[0]; abs[1, i] = ab[1]; } var bad = new HashSet<long>(); for (var i = 0; i < m; i++) { if (h[abs[0, i] - 1] >= h[abs[1, i] - 1]) bad.Add(abs[1, i]); if (h[abs[0, i] - 1] <= h[abs[1, i] - 1]) bad.Add(abs[0, i]); } Console.WriteLine(n - bad.Count); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
8
331
6
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var NM = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray(); //展望台の数 var N = NM[0]; //道の数 var M = NM[1]; //高さを高さ配列に保持する var height = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray(); var conn = new Dictionary<int, List<int>>(); var havePath = new bool[N]; for (int num = 0; num < M; num++) { var path = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray(); var A = path[0]; var B = path[1]; if (!conn.ContainsKey(A)) { conn[A] = new List<int>(); conn[A].Add(B); } else { conn[A].Add(B); } if (!conn.ContainsKey(B)) { conn[B] = new List<int>(); conn[B].Add(A); } else { conn[B].Add(A); } havePath[A - 1] = true; havePath[B - 1] = true; } var ans = 0; foreach (var c in conn) { var heightNow = height[c.Key - 1]; var flg = true; foreach (var val in c.Value) { if (heightNow < height[val - 1]) { flg = false; break; } } if (flg) { ans++; } } Console.WriteLine(ans + havePath.Count(e => e == false)); } }
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var NM = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray(); //展望台の数 var N = NM[0]; //道の数 var M = NM[1]; //高さを高さ配列に保持する var height = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray(); var conn = new Dictionary<int, List<int>>(); var havePath = new bool[N]; for (int num = 0; num < M; num++) { var path = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray(); var A = path[0]; var B = path[1]; if (!conn.ContainsKey(A)) { conn[A] = new List<int>(); conn[A].Add(B); } else { conn[A].Add(B); } if (!conn.ContainsKey(B)) { conn[B] = new List<int>(); conn[B].Add(A); } else { conn[B].Add(A); } havePath[A - 1] = true; havePath[B - 1] = true; } var ans = 0; foreach (var c in conn) { var heightNow = height[c.Key - 1]; var flg = true; foreach (var val in c.Value) { if (heightNow <= height[val - 1]) { flg = false; break; } } if (flg) { ans++; } } Console.WriteLine(ans + havePath.Count(e => e == false)); } }
[["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 19]]
8
393
2
using System; using System.Linq; public class ABC166C { private static void Main(string[] args) { var inputs = ReadIntsAsArray(); var n = inputs[0]; var m = inputs[1]; var h = ReadIntsAsArray(); var isPeakArray = Enumerable.Repeat(true, n).ToArray(); for (var i = 0; i < m; i++) { inputs = ReadIntsAsArray(); var a = inputs[0]; var b = inputs[1]; if (h[a - 1] < h[b - 1]) isPeakArray[a - 1] = false; if (h[b - 1] < h[a - 1]) isPeakArray[b - 1] = false; } var answer = isPeakArray.Count(isPeak => isPeak); Console.WriteLine(answer); } private static int[] ReadIntsAsArray() => Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToArray(); }
using System; using System.Linq; public class ABC166C { private static void Main(string[] args) { var inputs = ReadIntsAsArray(); var n = inputs[0]; var m = inputs[1]; var h = ReadIntsAsArray(); var isPeakArray = Enumerable.Repeat(true, n).ToArray(); for (var i = 0; i < m; i++) { inputs = ReadIntsAsArray(); var a = inputs[0]; var b = inputs[1]; if (h[a - 1] <= h[b - 1]) isPeakArray[a - 1] = false; if (h[b - 1] <= h[a - 1]) isPeakArray[b - 1] = false; } var answer = isPeakArray.Count(isPeak => isPeak); Console.WriteLine(answer); } private static int[] ReadIntsAsArray() => Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToArray(); }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
217
4
using System; namespace peaks { class Program { const int N = 100000; const long M = 100000000; static void Main(string[] args) { int n, m; int[] h = new int[M]; int[] ma = new int[N]; string inD0 = Console.ReadLine(); string[] cngD0 = inD0.Split(' '); n = int.Parse(cngD0[0]); m = int.Parse(cngD0[1]); string inD1 = Console.ReadLine(); string[] cngD1 = inD1.Split(' '); for (int i = 0; i <= n - 1; i++) { h[i] = int.Parse(cngD1[i]); ma[i] = 0; } for (int i = 0; i <= m - 1; i++) { string inD2 = Console.ReadLine(); string[] cngD2 = inD2.Split(' '); int a = int.Parse(cngD2[0]); int b = int.Parse(cngD2[1]); ma[a] = Math.Max(ma[a], h[b]); ma[b] = Math.Max(ma[b], h[a]); } int ans = 0; for (int i = 0; i <= n - 1; i++) { if (h[i] > ma[i]) { ans += 1; } } Console.WriteLine(ans); } } }
using System; namespace peaks { class Program { const int N = 100000; const int M = 100000000; static void Main(string[] args) { int n, m; int[] h = new int[M]; int[] ma = new int[N]; string inD0 = Console.ReadLine(); string[] cngD0 = inD0.Split(' '); n = int.Parse(cngD0[0]); m = int.Parse(cngD0[1]); string inD1 = Console.ReadLine(); string[] cngD1 = inD1.Split(' '); for (int i = 0; i <= n - 1; i++) { h[i] = int.Parse(cngD1[i]); ma[i] = 0; } for (int i = 0; i <= m - 1; i++) { string inD2 = Console.ReadLine(); string[] cngD2 = inD2.Split(' '); int a = int.Parse(cngD2[0]) - 1; int b = int.Parse(cngD2[1]) - 1; ma[a] = Math.Max(ma[a], h[b]); ma[b] = Math.Max(ma[b], h[a]); } int ans = 0; for (int i = 0; i <= n - 1; i++) { if (h[i] > ma[i]) { ans += 1; } } Console.WriteLine(ans); } } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
326
6
using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Peaks { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var number = int.Parse(input[0]); var roads = int.Parse(input[1]); var heights = Console.ReadLine().Split(' '); int[] numberList = new int[number]; for (var i = 0; i < roads; i++) { var check = Console.ReadLine().Split(' '); int first = int.Parse(check[0]) - 1; int second = int.Parse(check[1]) - 1; if (int.Parse(heights[first]) > int.Parse(heights[second])) { numberList[second] = 1; } else if (int.Parse(heights[first]) < int.Parse(heights[second])) { numberList[first] = 1; } else { numberList[first] = 1; numberList[second] = 1; } } int intCount = numberList.Count(value => value == 1); Console.WriteLine(intCount); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Peaks { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var number = int.Parse(input[0]); var roads = int.Parse(input[1]); var heights = Console.ReadLine().Split(' '); int[] numberList = new int[number]; for (var i = 0; i < roads; i++) { var check = Console.ReadLine().Split(' '); int first = int.Parse(check[0]) - 1; int second = int.Parse(check[1]) - 1; if (int.Parse(heights[first]) > int.Parse(heights[second])) { numberList[second] = 1; } else if (int.Parse(heights[first]) < int.Parse(heights[second])) { numberList[first] = 1; } else { numberList[first] = 1; numberList[second] = 1; } } int intCount = numberList.Count(value => value == 0); Console.WriteLine(intCount); } }
[["-", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203]]
8
267
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var N = sc.ReadInt(); var M = sc.ReadInt(); var H = sc.ReadIntArray(N); var G = new List<int>[N]; var max = new bool[N]; for (int i = 0; i < N; i++) { max[i] = true; } for (int i = 0; i < M; i++) { var a = sc.ReadInt(); var b = sc.ReadInt(); a--; b--; if (H[a] >= H[b]) max[b] = false; else if (H[b] >= H[a]) max[a] = false; } var ans = max.Count(f => f); Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var N = sc.ReadInt(); var M = sc.ReadInt(); var H = sc.ReadIntArray(N); var G = new List<int>[N]; var max = new bool[N]; for (int i = 0; i < N; i++) { max[i] = true; } for (int i = 0; i < M; i++) { var a = sc.ReadInt(); var b = sc.ReadInt(); a--; b--; if (H[a] >= H[b]) max[b] = false; if (H[b] >= H[a]) max[a] = false; } var ans = max.Count(f => f); Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
8
1,220
1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC166 { class Program { static void Main(string[] args) { c(); } public static void c() { long[] nm = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long[] h = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long n = nm[0], m = nm[1]; bool[] hi = new bool[n]; for (long i = 0; i < n; i++) { hi[i] = true; } long ans = n; for (long i = 0; i < m; i++) { long[] ab = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long a = ab[0], b = ab[1]; if (h[a - 1] < h[b - 1] && hi[a - 1] == true) { ans--; hi[a - 1] = false; } else if (h[a - 1] > h[b - 1] && hi[b - 1] == true) { ans--; hi[b - 1] = false; } else if (h[a - 1] == h[b - 1]) { if (hi[a - 1] == true) { ans--; hi[a - 1] = false; } else if (hi[b - 1] == true) { ans--; hi[b - 1] = false; } } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC166 { class Program { static void Main(string[] args) { c(); } public static void c() { long[] nm = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long[] h = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long n = nm[0], m = nm[1]; bool[] hi = new bool[n]; for (long i = 0; i < n; i++) { hi[i] = true; } long ans = n; for (long i = 0; i < m; i++) { long[] ab = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long a = ab[0], b = ab[1]; if (h[a - 1] < h[b - 1] && hi[a - 1] == true) { ans--; hi[a - 1] = false; } else if (h[a - 1] > h[b - 1] && hi[b - 1] == true) { ans--; hi[b - 1] = false; } else if (h[a - 1] == h[b - 1]) { if (hi[a - 1] == true) { ans--; hi[a - 1] = false; } if (hi[b - 1] == true) { ans--; hi[b - 1] = false; } } } Console.WriteLine(ans); } } }
[["-", 75, 57, 75, 57, 64, 196, 0, 57, 0, 95]]
8
386
1
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); // var n = int.Parse(Console.ReadLine()); long[] nm = Console.ReadLine().Split().Select(long.Parse).ToArray(); var n = nm[0]; var m = nm[1]; long[] h = Console.ReadLine().Split().Select(long.Parse).ToArray(); long[] a = new long[m]; long[] b = new long[m]; for (int i = 0; i < m; i++) { long[] tmp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a[i] = tmp[0]; b[i] = tmp[1]; } var tbd = new Dictionary<long, long>() {}; for (int i = 0; i < a.Length; i++) { if (!tbd.ContainsKey(a[i] - 1)) { tbd.Add(a[i] - 1, h[b[i] - 1]); } else { if (tbd[a[i] - 1] < h[b[i] - 1]) { tbd[a[i] - 1] = h[b[i] - 1]; } } if (!tbd.ContainsKey(b[i] - 1)) { tbd.Add(b[i] - 1, h[a[i] - 1]); } else { if (tbd[b[i] - 1] < h[a[i] - 1]) { tbd[b[i] - 1] = h[a[i] - 1]; } } } long ans = 0; for (int i = 0; i < tbd.Count; i++) { if (tbd.ContainsKey(i)) { if (tbd[i] < h[i]) { ans++; } } else { ans++; } } // 出力 Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); // var n = int.Parse(Console.ReadLine()); long[] nm = Console.ReadLine().Split().Select(long.Parse).ToArray(); var n = nm[0]; var m = nm[1]; long[] h = Console.ReadLine().Split().Select(long.Parse).ToArray(); long[] a = new long[m]; long[] b = new long[m]; for (int i = 0; i < m; i++) { long[] tmp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a[i] = tmp[0]; b[i] = tmp[1]; } var tbd = new Dictionary<long, long>() {}; for (int i = 0; i < a.Length; i++) { if (!tbd.ContainsKey(a[i] - 1)) { tbd.Add(a[i] - 1, h[b[i] - 1]); } else { if (tbd[a[i] - 1] < h[b[i] - 1]) { tbd[a[i] - 1] = h[b[i] - 1]; } } if (!tbd.ContainsKey(b[i] - 1)) { tbd.Add(b[i] - 1, h[a[i] - 1]); } else { if (tbd[b[i] - 1] < h[a[i] - 1]) { tbd[b[i] - 1] = h[a[i] - 1]; } } } long ans = 0; for (int i = 0; i < n; i++) { if (tbd.ContainsKey(i)) { if (tbd[i] < h[i]) { ans++; } } else { ans++; } } // 出力 Console.WriteLine(ans); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
465
4
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; class Program { public Program() {} public static int Main() { cin = new Scanner(); new Program().calc(); return 0; } static Scanner cin; void calc() { long N, M; N = cin.nextLong(); M = cin.nextLong(); long[] H = new long[N]; bool[] notGood = new bool[N]; for (long i = 0; i < N; i++) { H[i] = cin.nextLong() - 1; } for (long i = 0; i < M; i++) { long A = cin.nextLong() - 1; long B = cin.nextLong() - 1; if (H[A] >= H[B]) notGood[B] = true; if (H[B] >= H[A]) notGood[A] = true; } long ans = 0; for (long i = 0; i < N; i++) { if (notGood[i]) ans++; } Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class XRand { uint x, y, z, w; public XRand() { init(); } public XRand(uint s) { init(); init_xor128(s); } void init() { x = 314159265; y = 358979323; z = 846264338; w = 327950288; } public void init_xor128(uint s) { z ^= s; z ^= z >> 21; z ^= z << 35; z ^= z >> 4; z *= 736338717; } uint next() { uint t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8; } public long nextLong(long m) { return (long)((((ulong)next() << 32) + next()) % (ulong)m); } public int nextInt(int m) { return (int)(next() % m); } public int nextIntP(int a) { return (int)Math.Pow(a, nextDouble()); } public int nextInt(int min, int max) { return min + nextInt(max - min + 1); } public double nextDouble() { return (double)next() / uint.MaxValue; } public double nextDoubleP(double a) { return Math.Pow(a, nextDouble()); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; class Program { public Program() {} public static int Main() { cin = new Scanner(); new Program().calc(); return 0; } static Scanner cin; void calc() { long N, M; N = cin.nextLong(); M = cin.nextLong(); long[] H = new long[N]; bool[] notGood = new bool[N]; for (long i = 0; i < N; i++) { H[i] = cin.nextLong() - 1; } for (long i = 0; i < M; i++) { long A = cin.nextLong() - 1; long B = cin.nextLong() - 1; if (H[A] >= H[B]) notGood[B] = true; if (H[B] >= H[A]) notGood[A] = true; } long ans = 0; for (long i = 0; i < N; i++) { if (!notGood[i]) ans++; } Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class XRand { uint x, y, z, w; public XRand() { init(); } public XRand(uint s) { init(); init_xor128(s); } void init() { x = 314159265; y = 358979323; z = 846264338; w = 327950288; } public void init_xor128(uint s) { z ^= s; z ^= z >> 21; z ^= z << 35; z ^= z >> 4; z *= 736338717; } uint next() { uint t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8; } public long nextLong(long m) { return (long)((((ulong)next() << 32) + next()) % (ulong)m); } public int nextInt(int m) { return (int)(next() % m); } public int nextIntP(int a) { return (int)Math.Pow(a, nextDouble()); } public int nextInt(int min, int max) { return min + nextInt(max - min + 1); } public double nextDouble() { return (double)next() / uint.MaxValue; } public double nextDoubleP(double a) { return Math.Pow(a, nextDouble()); } }
[["+", 0, 7, 8, 196, 0, 57, 15, 241, 0, 111]]
8
898
1
using System; using static System.Console; using static System.Math; using System.Numerics; using System.Collections.Generic; using System.Linq; public class Program { public static void Main(string[] args) { bool end = false; long a = myRead.readLong(); string ans = ""; for (int i = -120; i < 120; i++) { long A = MyMath.Pow(i, 5); for (int j = -120; j < 120; j++) { long B = MyMath.Pow(j, 5); if (A - B == a) { ans += A + " " + B; end = true; break; } } if (end == true) break; } WriteLine(ans); Out.Flush(); } } public static class myRead { public static int readInt() { return int.Parse(ReadLine()); } public static long readLong() { return long.Parse(ReadLine()); } public static string reatStr() { return ReadLine(); } public static int[] readIntArray() { return ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] readLongArray() { return ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] readStrArray() { return ReadLine().Split(' '); } } public static class MyMath { public static long Factorical(long n) { return n <= 1 ? 1L : n * Factorical(n - 1); } public static long Permutation(long n, long m) { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); } public static long Combination(long n, long m) { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); } public static long Gcd(long n, long m) { return n % m == 0 ? m : Gcd(m, n % m); } public static long Lcm(long n, long m) { return n * m / Gcd(n, m); } public static long Pow(long n, long m) { return m == 0 ? 1L : m == 1 ? n : n * Pow(n, m - 1); } }
using System; using static System.Console; using static System.Math; using System.Numerics; using System.Collections.Generic; using System.Linq; public class Program { public static void Main(string[] args) { bool end = false; long a = myRead.readLong(); string ans = ""; for (int i = -120; i < 120; i++) { long A = MyMath.Pow(i, 5); for (int j = -120; j < 120; j++) { long B = MyMath.Pow(j, 5); if (A - B == a) { ans += i + " " + j; end = true; break; } } if (end == true) break; } WriteLine(ans); Out.Flush(); } } public static class myRead { public static int readInt() { return int.Parse(ReadLine()); } public static long readLong() { return long.Parse(ReadLine()); } public static string reatStr() { return ReadLine(); } public static int[] readIntArray() { return ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] readLongArray() { return ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] readStrArray() { return ReadLine().Split(' '); } } public static class MyMath { public static long Factorical(long n) { return n <= 1 ? 1L : n * Factorical(n - 1); } public static long Permutation(long n, long m) { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); } public static long Combination(long n, long m) { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); } public static long Gcd(long n, long m) { return n % m == 0 ? m : Gcd(m, n % m); } public static long Lcm(long n, long m) { return n * m / Gcd(n, m); } public static long Pow(long n, long m) { return m == 0 ? 1L : m == 1 ? n : n * Pow(n, m - 1); } }
[["-", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
536
4
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass { static void Main() { long X = long.Parse(ReadLine()); for (long i = -1000; i < 1000; i++) { for (long j = -1000; j < 1000; j++) { if (Pow(i, 5) + Pow(j, 5) == X) { WriteLine($"{i} {j}"); return; } } } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass { static void Main() { long X = long.Parse(ReadLine()); for (long i = -1000; i < 1000; i++) { for (long j = -1000; j < 1000; j++) { if (Pow(i, 5) - Pow(j, 5) == X) { WriteLine($"{i} {j}"); return; } } } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33]]
8
119
2
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { public class Class1 { static void Main(string[] args) { var X = int.Parse(Console.ReadLine()); for (var i = -1000; i < 1000; i++) { for (var j = -1000; j < 1000; j++) { var A = Math.Pow(i, 5); var B = Math.Pow(j, 5); if (A - B == X) { Console.Write("{0} {1}", A, B); return; } } } } } }
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { public class Class1 { static void Main(string[] args) { var X = int.Parse(Console.ReadLine()); for (var i = -1000; i < 1000; i++) { for (var j = -1000; j < 1000; j++) { var A = Math.Pow(i, 5); var B = Math.Pow(j, 5); if (A - B == X) { Console.Write("{0} {1}", i, j); return; } } } } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
132
4
using System; namespace D { class Program { static void Main(string[] args) { var x = int.Parse(Console.ReadLine()); for (int a = -199; a < 200; a++) { for (int b = -200; b < a; b++) { if (x == a * a * a * a - b * b * b * b * b) { Console.WriteLine(a + " " + b); goto label; } } } label:; } } }
using System; namespace D { class Program { static void Main(string[] args) { var x = int.Parse(Console.ReadLine()); for (int a = -199; a < 200; a++) { for (int b = -200; b < a; b++) { if (x == a * a * a * a * a - b * b * b * b * b) { Console.WriteLine(a + " " + b); goto label; } } } label:; } } }
[["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22]]
8
113
2
using System; namespace ForAtCoder { class Program { static void Main() { int x = int.Parse(Console.ReadLine()); for (int i = -10000; i < 10000; i++) { for (int j = -10000; j < 10000; j++) { if ((i * i * i * i * i) - (j * j * j * j * j) == x) { Console.WriteLine(i.ToString() + " " + j.ToString()); return; } } } } } }
using System; namespace ForAtCoder { class Program { static void Main() { int x = int.Parse(Console.ReadLine()); for (int i = 0; i < 10000; i++) { for (int j = -10000; j < 10000; j++) { if ((i * i * i * i * i) - (j * j * j * j * j) == x) { Console.WriteLine(i.ToString() + " " + j.ToString()); return; } } } } } }
[["-", 10, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["-", 10, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
119
3
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var answerList = new Dictionary<double, Tuple<long, long>>(); const int num = 2000; foreach (var A in Enumerable.Range(0, num).Select(elem => elem - (num / 2))) { foreach (var B in Enumerable.Range(0, num).Select(elem => elem - (num / 2))) { var answer = Math.Pow(A, 5) - Math.Pow(B, 5); if (answer >= 1) { answerList[answer] = new Tuple<long, long>(A, B); } } } var X = long.Parse(Console.ReadLine()); var tuple = answerList[X]; Console.WriteLine($"{tuple.Item1}, {tuple.Item2}"); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var answerList = new Dictionary<double, Tuple<long, long>>(); const int num = 2000; foreach (var A in Enumerable.Range(0, num).Select(elem => elem - (num / 2))) { foreach (var B in Enumerable.Range(0, num).Select(elem => elem - (num / 2))) { var answer = Math.Pow(A, 5) - Math.Pow(B, 5); if (answer >= 1) { answerList[answer] = new Tuple<long, long>(A, B); } } } var X = long.Parse(Console.ReadLine()); var tuple = answerList[X]; Console.WriteLine($"{tuple.Item1} {tuple.Item2}"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296]]
8
290
2
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 hegihtArray = retreiveLongArray(); var overSet = new Dictionary<long, long>(); for (int i = 0; i < N; i++) { var code = i - hegihtArray[i]; if (overSet.ContainsKey(code)) { overSet[code]++; } else { overSet.Add(code, 1); } } var underSet = new Dictionary<long, long>(); for (int i = 0; i < N; i++) { var code = i + hegihtArray[i]; if (underSet.ContainsKey(code)) { overSet[code]++; } else { underSet.Add(code, 1); } } long count = 0; for (int i = 0; i < N; i++) { var condition = i + hegihtArray[i]; long num = 0; if (overSet.ContainsKey(condition)) { num = overSet[condition]; } count += num; } for (int i = 0; i < N; i++) { var condition = i - hegihtArray[i]; long num = 0; if (overSet.ContainsKey(condition)) { num = overSet[condition]; } count += num; } //答えの出力 var ans = count / 2; 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 hegihtArray = retreiveLongArray(); var overSet = new Dictionary<long, long>(); for (int i = 0; i < N; i++) { var code = i - hegihtArray[i]; if (overSet.ContainsKey(code)) { overSet[code]++; } else { overSet.Add(code, 1); } } var underSet = new Dictionary<long, long>(); for (int i = 0; i < N; i++) { var code = i + hegihtArray[i]; if (underSet.ContainsKey(code)) { underSet[code]++; } else { underSet.Add(code, 1); } } long count = 0; for (int i = 0; i < N; i++) { var condition = i + hegihtArray[i]; long num = 0; if (overSet.ContainsKey(condition)) { num = overSet[condition]; } count += num; } for (int i = 0; i < N; i++) { var condition = i - hegihtArray[i]; long num = 0; if (underSet.ContainsKey(condition)) { num = underSet[condition]; } count += num; } //答えの出力 var ans = count / 2; 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(); } } }
[["-", 64, 196, 0, 1, 0, 223, 0, 204, 205, 22], ["+", 64, 196, 0, 1, 0, 223, 0, 204, 205, 22], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22]]
8
444
6
// C# program to build the smallest number // by removing n digits from a given number using System; using System.Collections.Generic; using System.Linq; class GFG { public static void Main(String[] args) { var n = int.Parse(Console.ReadLine()); var arr = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); Secret(n, arr); } public static void Secret(int n, long[] h) { Dictionary<long, long> dic = new Dictionary<long, long>(); for (int i = 0; i < n; i++) { if (dic.ContainsKey(h[i] + i)) { dic[h[i] + 1]++; } else { dic.Add(h[i] + i, 1); } } long count = 0; for (int i = 0; i < n; i++) { if (dic.ContainsKey(i - h[i])) count += dic[i - h[i]]; } Console.Write(count); } }
// C# program to build the smallest number // by removing n digits from a given number using System; using System.Collections.Generic; using System.Linq; class GFG { public static void Main(String[] args) { var n = int.Parse(Console.ReadLine()); var arr = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); Secret(n, arr); } public static void Secret(int n, long[] h) { Dictionary<long, long> dic = new Dictionary<long, long>(); for (int i = 0; i < n; i++) { if (dic.ContainsKey(h[i] + i)) { dic[h[i] + i]++; } else { dic.Add(h[i] + i, 1); } } long count = 0; for (int i = 0; i < n; i++) { if (dic.ContainsKey(i - h[i])) count += dic[i - h[i]]; } Console.Write(count); } }
[["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 22]]
8
233
2
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 => int.Parse(x)).ToList(); var N = vals[0]; var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); int large = 100; long count = 0; long[] valset = new long[large * 2]; for (int i = 0; i < N; i++) { if (i - A[i] > -large) { valset[i - A[i] + large]++; } } for (int i = 0; i < N; i++) { if (i - A[i] > -large) { valset[i - A[i] + large]--; } if (i + A[i] < large) { if (true) { count += valset[i + A[i] + large]; } } } Console.WriteLine(count); } } 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 => int.Parse(x)).ToList(); var N = vals[0]; var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); int large = 200000; long count = 0; long[] valset = new long[large * 2]; for (int i = 0; i < N; i++) { if (i - A[i] > -large) { valset[i - A[i] + large]++; } } for (int i = 0; i < N; i++) { if (i - A[i] > -large) { valset[i - A[i] + large]--; } if (i + A[i] < large) { if (true) { count += valset[i + A[i] + large]; } } } Console.WriteLine(count); } } 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, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
707
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { string S = RString(); int N = S.Length; var dp = new long[2019]; Modular num = 0; dp[0] = 1; for (int i = N - 1; i >= 0; i--) { num += (S[i] - '0') * Modular.Pow(10, N - i - 1); dp[(int)num]++; } long ans = 0; for (int i = 0; i < 2019; i++) { ans += dp[i] * (dp[i] - 1) / 2; } WriteLine(ans); } } class Modular { private const int M = 2019; private const int arysize = 2000001; private long value; public Modular(long value = 0) { this.value = value; } public override string ToString() { return value.ToString(); } public static implicit operator Modular(long a) { var m = a % M; return new Modular((m < 0) ? m + M : m); } public static Modular operator +(Modular a, Modular b) => a.value + b.value; public static Modular operator -(Modular a, Modular b) => a.value - b.value; public static Modular operator *(Modular a, Modular b) => a.value * b.value; public static Modular Pow(Modular a, long n) { Modular ans = 1; for (; n > 0; n >>= 1, a *= a) { if ((n & 1) == 0) ans *= a; } return ans; } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, M - 2); } private static int[] facs = new int[arysize]; private static int facscount = -1; public static Modular Fac(int n) //階乗 { facs[0] = 1; while (++facscount <= n) { facs[facscount + 1] = (int)(Math.BigMul(facs[facscount], facscount + 1) % M); } return facs[n]; } public static Modular Fac(int r, int n) //記録しない階乗 { int temp = 1; for (int i = r; i <= n; i++) { temp = (int)(Math.BigMul(temp, i) % M); } return temp; } public static Modular Ncr(int n, int r) // nCr { return (n < r) ? 0 : (n == r) ? 1 : (Math.Max(n, r) <= arysize) ? Fac(n) / (Fac(r) * Fac(n - r)) : Fac(n - r + 1, n) / Fac(r); } public static explicit operator int(Modular a) { return (int)a.value; } } class Scanner { public static string RString() => Console.ReadLine(); public static int RInt() => ReadTuple<int>(); public static long RLong() => ReadTuple<long>(); public static double RDouble() => ReadTuple<double>(); public static string[] RStrings() => Console.ReadLine().Split(); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadTuple<T1>() { var r = RString(); var r1 = (T1)Convert.ChangeType(r, typeof(T1)); return r1; } public static (T1, T2) ReadTuple<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadTuple<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { string S = RString(); int N = S.Length; var dp = new long[2019]; Modular num = 0; dp[0] = 1; for (int i = N - 1; i >= 0; i--) { num += (S[i] - '0') * Modular.Pow(10, N - i - 1); dp[(int)num]++; } long ans = 0; for (int i = 0; i < 2019; i++) { ans += dp[i] * (dp[i] - 1) / 2; } WriteLine(ans); } } class Modular { private const int M = 2019; private const int arysize = 2000001; private long value; public Modular(long value = 0) { this.value = value; } public override string ToString() { return value.ToString(); } public static implicit operator Modular(long a) { var m = a % M; return new Modular((m < 0) ? m + M : m); } public static Modular operator +(Modular a, Modular b) => a.value + b.value; public static Modular operator -(Modular a, Modular b) => a.value - b.value; public static Modular operator *(Modular a, Modular b) => a.value * b.value; public static Modular Pow(Modular a, long n) { Modular ans = 1; for (; n > 0; n >>= 1, a = a * a) { if ((n & 1) > 0) ans *= a; } return ans; } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, M - 2); } private static int[] facs = new int[arysize]; private static int facscount = -1; public static Modular Fac(int n) //階乗 { facs[0] = 1; while (++facscount <= n) { facs[facscount + 1] = (int)(Math.BigMul(facs[facscount], facscount + 1) % M); } return facs[n]; } public static Modular Fac(int r, int n) //記録しない階乗 { int temp = 1; for (int i = r; i <= n; i++) { temp = (int)(Math.BigMul(temp, i) % M); } return temp; } public static Modular Ncr(int n, int r) // nCr { return (n < r) ? 0 : (n == r) ? 1 : (Math.Max(n, r) <= arysize) ? Fac(n) / (Fac(r) * Fac(n - r)) : Fac(n - r + 1, n) / Fac(r); } public static explicit operator int(Modular a) { return (int)a.value; } } class Scanner { public static string RString() => Console.ReadLine(); public static int RInt() => ReadTuple<int>(); public static long RLong() => ReadTuple<long>(); public static double RDouble() => ReadTuple<double>(); public static string[] RStrings() => Console.ReadLine().Split(); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadTuple<T1>() { var r = RString(); var r1 = (T1)Convert.ChangeType(r, typeof(T1)); return r1; } public static (T1, T2) ReadTuple<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadTuple<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
[["-", 8, 196, 0, 7, 26, 11, 0, 202, 0, 108], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 7, 26, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 7, 26, 11, 12, 16, 17, 48], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47]]
8
1,245
6
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var S = sc.ReadStr(); var N = S.Length; var P = 2019; var pow = new long[N + 1]; pow[0] = 1; for (int i = 0; i < N; i++) { pow[i + 1] = pow[i] * 10; pow[i + 1] %= P; } var T = new string(S.Reverse().ToArray()); var x = new long[N + 1]; for (int i = 0; i < N; i++) { x[i + 1] = x[i] + (T[i] - '0') * pow[i]; x[i + 1] %= P; } var count = new int[2000]; for (int i = 0; i < N + 1; i++) { count[x[i]]++; } ModInt ans = 0; for (int i = 0; i < 2000; i++) { ans += ModInt.nCr(count[i], 2); } Console.WriteLine(ans); } public struct ModInt { public const long Mod = (int)1e9 + 7; public long num; public ModInt(long n) { num = n; } public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static ModInt operator /(ModInt l, ModInt r) { return l * Inverse(r); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } public static ModInt Pow(long v, long k) { long res = 1; while (k > 0) { if ((k & 1) == 1) res = res * v % Mod; v = v * v % Mod; k >>= 1; } return new ModInt(res); } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } private static List<ModInt> Facs = new List<ModInt> { 1 }; private static List<ModInt> iFacs = new List<ModInt> { 1 }; public static ModInt Fac(int n) { for (int i = Facs.Count; i <= n; i++) { Facs.Add(i * Facs[i - 1]); iFacs.Add(Inverse(Facs[i])); } return Facs[n]; } public static ModInt iFac(int n) { Fac(n); return iFacs[n]; } public static ModInt nCr(int n, int r, bool loop = false) { if (n < r) return 0; if (n == r) return 1; if (loop && n > (int)1e6) return nCrLoop(n, r); return Fac(n) * iFac(r) * iFac(n - r); } public static ModInt nCrLoop(long n, long r) { ModInt num = 1; for (long i = 1; i <= r; i++) { num = num * (n - i + 1) / i; } return num; } public static ModInt nHr(int n, int r) { return nCr(n + r - 1, r); } } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var S = sc.ReadStr(); var N = S.Length; var P = 2019; var pow = new long[N + 1]; pow[0] = 1; for (int i = 0; i < N; i++) { pow[i + 1] = pow[i] * 10; pow[i + 1] %= P; } var T = new string(S.Reverse().ToArray()); var x = new long[N + 1]; for (int i = 0; i < N; i++) { x[i + 1] = x[i] + (T[i] - '0') * pow[i]; x[i + 1] %= P; } var count = new int[2020]; for (int i = 0; i < N + 1; i++) { count[x[i]]++; } ModInt ans = 0; for (int i = 0; i < 2020; i++) { ans += ModInt.nCr(count[i], 2); } Console.WriteLine(ans); } public struct ModInt { public const long Mod = (int)1e9 + 7; public long num; public ModInt(long n) { num = n; } public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static ModInt operator /(ModInt l, ModInt r) { return l * Inverse(r); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } public static ModInt Pow(long v, long k) { long res = 1; while (k > 0) { if ((k & 1) == 1) res = res * v % Mod; v = v * v % Mod; k >>= 1; } return new ModInt(res); } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } private static List<ModInt> Facs = new List<ModInt> { 1 }; private static List<ModInt> iFacs = new List<ModInt> { 1 }; public static ModInt Fac(int n) { for (int i = Facs.Count; i <= n; i++) { Facs.Add(i * Facs[i - 1]); iFacs.Add(Inverse(Facs[i])); } return Facs[n]; } public static ModInt iFac(int n) { Fac(n); return iFacs[n]; } public static ModInt nCr(int n, int r, bool loop = false) { if (n < r) return 0; if (n == r) return 1; if (loop && n > (int)1e6) return nCrLoop(n, r); return Fac(n) * iFac(r) * iFac(n - r); } public static ModInt nCrLoop(long n, long r) { ModInt num = 1; for (long i = 1; i <= r; i++) { num = num * (n - i + 1) / i; } return num; } public static ModInt nHr(int n, int r) { return nCr(n + r - 1, r); } } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
8
1,872
4
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)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)(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); } } } // 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 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() { string S = Console.ReadLine(); int N = S.Length; int[] s = new int[N + 1]; int[] tensForMod = new int[N + 1]; tensForMod[N] = 1; for (int i = N - 1; i >= 0; i--) { tensForMod[i] = tensForMod[i + 1] * 10; tensForMod[i] %= 2019; } s[N] = int.Parse(S[N - 1].ToString()); for (int i = 1; i < N; i++) { int targetint = int.Parse(S[N - 1 - i].ToString()); long temp = targetint; temp *= tensForMod[N - i]; temp += s[N - i + 1]; temp %= 2019; s[N - i] = (int)temp; } Array.Sort(s); Dictionary<int, int> dict = new Dictionary<int, int>(); for (int i = 0; i < s.Length - 1; i++) { if (dict.ContainsKey(s[i])) { dict[s[i]]++; } else { dict[s[i]] = 1; } } long output = 0; foreach (int key in dict.Keys) { long temp = dict[key]; temp *= (temp - 1); temp /= 2; output += temp; } Console.WriteLine(output); } }
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)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)(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); } } } // 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 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() { string S = Console.ReadLine(); int N = S.Length; int[] s = new int[N + 1]; int[] tensForMod = new int[N + 1]; tensForMod[N] = 1; for (int i = N - 1; i >= 0; i--) { tensForMod[i] = tensForMod[i + 1] * 10; tensForMod[i] %= 2019; } s[N] = int.Parse(S[N - 1].ToString()); for (int i = 1; i < N; i++) { int targetint = int.Parse(S[N - 1 - i].ToString()); long temp = targetint; temp *= tensForMod[N - i]; temp += s[N - i + 1]; temp %= 2019; s[N - i] = (int)temp; } Array.Sort(s); Dictionary<int, int> dict = new Dictionary<int, int>(); for (int i = 0; i < s.Length; i++) { if (dict.ContainsKey(s[i])) { dict[s[i]]++; } else { dict[s[i]] = 1; } } long output = 0; foreach (int key in dict.Keys) { long temp = dict[key]; temp *= (temp - 1); temp /= 2; output += temp; } Console.WriteLine(output); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
4,636
2
using System; using System.Collections.Generic; using System.Linq; public class Solution { public static void Main() { const int mod = 2019; const int len = mod + 1; var S = Console.ReadLine(); long all = 0; var cur = new long[len]; foreach (var c in S) { var nexts = new long[len]; var v = c - '0'; for (int i = 0; i < len; i++) { var j = (i * 10 + v) % mod; nexts[j] = cur[i]; } nexts[v]++; cur = nexts; all += cur[0]; } Console.WriteLine(all); } }
using System; using System.Collections.Generic; using System.Linq; public class Solution { public static void Main() { const int mod = 2019; const int len = mod + 1; var S = Console.ReadLine(); long all = 0; var cur = new long[len]; foreach (var c in S) { var nexts = new long[len]; var v = c - '0'; for (int i = 0; i < len; i++) { var j = (i * 10 + v) % mod; nexts[j] += cur[i]; } nexts[v]++; cur = nexts; all += cur[0]; } Console.WriteLine(all); } }
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107]]
8
155
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // Initialize var iR = cin.ReadInt; var Pi = 3.141592; // Process // Output WriteLine(iR * Pi); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // Initialize var iR = cin.ReadInt; var Pi = 3.141592; // Process // Output WriteLine(iR * 2 * Pi); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48]]
8
446
2
using System; namespace q1 { class q2 { static void Main() { double R = double.Parse(Console.ReadLine()); Console.WriteLine(R * 3.14159); } } }
using System; namespace q1 { class q2 { static void Main() { double R = double.Parse(Console.ReadLine()); Console.WriteLine(R * 6.28318530717958623200); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 250], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 250]]
8
41
2
using System; using System.Linq; namespace ConsoleApp1 { public class Class1 { static void Main(string[] args) { int read = int.Parse(Console.ReadLine()); Console.Write(read * Math.PI); } } }
using System; using System.Linq; namespace ConsoleApp1 { public class Class1 { static void Main(string[] args) { int read = int.Parse(Console.ReadLine()); Console.Write(read * 2 * Math.PI); } } }
[["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48]]
8
53
2
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; public static void Main() { // •ûj // var s = rstr(); double a = double.Parse(s); WriteLine(a * PI); } // 1‚©‚ça‚܂ł̔š•À‚בւ¦‘S’Ê‚è•Ô‚·‚â‚ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } 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) { 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; } //Šeí“Çæ 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; public static void Main() { // •ûj // var s = rstr(); var n = double.Parse(s); WriteLine(2 * n * PI); } // 1‚©‚ça‚܂ł̔š•À‚בւ¦‘S’Ê‚è•Ô‚·‚â‚ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } 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) { 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; } //Šeí“Çæ 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, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22]]
8
1,278
8
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; using System.Text.RegularExpressions; namespace Yuzuki { class Yukari { public static void Main(string[] args) { double r = double.Parse(Console.ReadLine()); Console.WriteLine(r * PI); } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; using System.Text.RegularExpressions; namespace Yuzuki { class Yukari { public static void Main(string[] args) { double r = double.Parse(Console.ReadLine()); Console.WriteLine(r * 2 * PI); } } }
[["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48]]
8
87
2
using System; namespace Circle { class Program { static void Main(string[] args) { var R = 0; R = int.Parse(Console.ReadLine()); Console.WriteLine((double)R * Math.PI); } } }
using System; namespace Circle { class Program { static void Main(string[] args) { var R = 0; R = int.Parse(Console.ReadLine()); Console.WriteLine((double)R * Math.PI * 2.0); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 250]]
8
54
2
/******************************************************************************* * Author: Nirushuu * Date: 2020-04-17 *******************************************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.IO; using System.Globalization; using System.Numerics; /******************************************************************************* * IO from Kattio.cs from open.kattis.com/help/csharp */ public class NoMoreTokensException : Exception {} public class Tokenizer { string[] tokens = new string[0]; private int pos; StreamReader reader; public Tokenizer(Stream inStream) { var bs = new BufferedStream(inStream); reader = new StreamReader(bs); } public Tokenizer() : this(Console.OpenStandardInput()) { // Nothing more to do } private string PeekNext() { if (pos < 0) // pos < 0 indicates that there are no more tokens return null; if (pos < tokens.Length) { if (tokens[pos].Length == 0) { ++pos; return PeekNext(); } return tokens[pos]; } string line = reader.ReadLine(); if (line == null) { // There is no more data to read pos = -1; return null; } // Split the line that was read on white space characters tokens = line.Split(null); pos = 0; return PeekNext(); } public bool HasNext() { return (PeekNext() != null); } public string Next() { string next = PeekNext(); if (next == null) throw new NoMoreTokensException(); ++pos; return next; } } public class Scanner : Tokenizer { public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public float NextFloat() { return float.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } } public class BufferedStdoutWriter : StreamWriter { public BufferedStdoutWriter() : base(new BufferedStream(Console.OpenStandardOutput())) {} } /******************************************************************************/ /******************************************************************************* * DisjointSet datastructure */ public struct DisjointSet { public int[] parent; public int[] rank; public DisjointSet(int n) { parent = new int[n]; for (int i = 0; i < n; ++i) { parent[i] = i; } rank = new int[n]; } public int Find(int i) { int idx = i; var compress = new List<int>(); while (idx != parent[idx]) { compress.Add(idx); idx = parent[idx]; } foreach (var e in compress) { // path compress parent[e] = idx; } return idx; } public void Union(int a, int b) { int aPar = this.Find(a); int bPar = this.Find(b); if (rank[aPar] > rank[bPar]) { // by rank parent[bPar] = aPar; } else { parent[aPar] = bPar; } if (rank[aPar] == rank[bPar]) { ++rank[bPar]; } } } class MaxHeap { List<int> data; public MaxHeap() { data = new List<int>(); } public void Push(int a) { data.Add(a); int idx = data.Count - 1; int parent = (int)Math.Floor((double)(idx - 1) / 2); while (idx != 0 && (data[idx] > data[parent])) { int tmp = data[parent]; data[parent] = data[idx]; data[idx] = tmp; idx = parent; parent = (int)Math.Floor((double)(idx - 1) / 2); } } public int Pop() { int res = data[0]; data[0] = data[data.Count - 1]; data.RemoveAt(data.Count - 1); int idx = 0; while (true) { int child1 = (2 * idx) + 1; int child2 = (2 * idx) + 2; if (child1 >= data.Count) { // no children break; } else if (child2 >= data.Count) { // one child if (data[idx] < data[child1]) { int tmp = data[idx]; data[idx] = data[child1]; data[child1] = tmp; } break; } else { // two children int maxChild = data[child1] > data[child2] ? child1 : child2; if (data[idx] < data[maxChild]) { int tmp = data[idx]; data[idx] = data[maxChild]; data[maxChild] = tmp; idx = maxChild; continue; } else { // no swap break; } } } return res; } } class Dequeue { public Dictionary<int, int> data = new Dictionary<int, int>(); int firstIdx; public int Count; public Dequeue() { data = new Dictionary<int, int>(); firstIdx = 1; Count = 0; } public void PushFront(int a) { data[firstIdx - 1] = a; ++Count; --firstIdx; } public void PushBack(int a) { data[firstIdx + Count] = a; ++Count; } public int PopFront() { --Count; ++firstIdx; return data[firstIdx - 1]; } public int PopBack() { --Count; return data[firstIdx + Count]; } public int Get(int n) { return data[firstIdx + n]; } } /******************************************************************************/ class MainClass { // Debug functions static void debug<T>(IEnumerable<T> a, string s = "") { Console.WriteLine($"name: {s}"); int i = 0; foreach (var e in a) { Console.WriteLine($"value {i}: {e}"); ++i; } } static void dbg<T>(T a, string s = "") { Console.WriteLine($"name: {s} value: {a}"); } //////////////////// static int gcd(int a, int b) { while (b != 0) { int t = b; b = a % b; a = t; } return a; } public static void Main() { var sc = new Scanner(); var wr = new BufferedStdoutWriter(); var dot = new NumberFormatInfo(); dot.NumberDecimalSeparator = "."; int r = sc.NextInt(); wr.Write((r * Math.PI).ToString(dot)); wr.Flush(); } }
/******************************************************************************* * Author: Nirushuu * Date: 2020-04-17 *******************************************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.IO; using System.Globalization; using System.Numerics; /******************************************************************************* * IO from Kattio.cs from open.kattis.com/help/csharp */ public class NoMoreTokensException : Exception {} public class Tokenizer { string[] tokens = new string[0]; private int pos; StreamReader reader; public Tokenizer(Stream inStream) { var bs = new BufferedStream(inStream); reader = new StreamReader(bs); } public Tokenizer() : this(Console.OpenStandardInput()) { // Nothing more to do } private string PeekNext() { if (pos < 0) // pos < 0 indicates that there are no more tokens return null; if (pos < tokens.Length) { if (tokens[pos].Length == 0) { ++pos; return PeekNext(); } return tokens[pos]; } string line = reader.ReadLine(); if (line == null) { // There is no more data to read pos = -1; return null; } // Split the line that was read on white space characters tokens = line.Split(null); pos = 0; return PeekNext(); } public bool HasNext() { return (PeekNext() != null); } public string Next() { string next = PeekNext(); if (next == null) throw new NoMoreTokensException(); ++pos; return next; } } public class Scanner : Tokenizer { public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public float NextFloat() { return float.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } } public class BufferedStdoutWriter : StreamWriter { public BufferedStdoutWriter() : base(new BufferedStream(Console.OpenStandardOutput())) {} } /******************************************************************************/ /******************************************************************************* * DisjointSet datastructure */ public struct DisjointSet { public int[] parent; public int[] rank; public DisjointSet(int n) { parent = new int[n]; for (int i = 0; i < n; ++i) { parent[i] = i; } rank = new int[n]; } public int Find(int i) { int idx = i; var compress = new List<int>(); while (idx != parent[idx]) { compress.Add(idx); idx = parent[idx]; } foreach (var e in compress) { // path compress parent[e] = idx; } return idx; } public void Union(int a, int b) { int aPar = this.Find(a); int bPar = this.Find(b); if (rank[aPar] > rank[bPar]) { // by rank parent[bPar] = aPar; } else { parent[aPar] = bPar; } if (rank[aPar] == rank[bPar]) { ++rank[bPar]; } } } class MaxHeap { List<int> data; public MaxHeap() { data = new List<int>(); } public void Push(int a) { data.Add(a); int idx = data.Count - 1; int parent = (int)Math.Floor((double)(idx - 1) / 2); while (idx != 0 && (data[idx] > data[parent])) { int tmp = data[parent]; data[parent] = data[idx]; data[idx] = tmp; idx = parent; parent = (int)Math.Floor((double)(idx - 1) / 2); } } public int Pop() { int res = data[0]; data[0] = data[data.Count - 1]; data.RemoveAt(data.Count - 1); int idx = 0; while (true) { int child1 = (2 * idx) + 1; int child2 = (2 * idx) + 2; if (child1 >= data.Count) { // no children break; } else if (child2 >= data.Count) { // one child if (data[idx] < data[child1]) { int tmp = data[idx]; data[idx] = data[child1]; data[child1] = tmp; } break; } else { // two children int maxChild = data[child1] > data[child2] ? child1 : child2; if (data[idx] < data[maxChild]) { int tmp = data[idx]; data[idx] = data[maxChild]; data[maxChild] = tmp; idx = maxChild; continue; } else { // no swap break; } } } return res; } } class Dequeue { public Dictionary<int, int> data = new Dictionary<int, int>(); int firstIdx; public int Count; public Dequeue() { data = new Dictionary<int, int>(); firstIdx = 1; Count = 0; } public void PushFront(int a) { data[firstIdx - 1] = a; ++Count; --firstIdx; } public void PushBack(int a) { data[firstIdx + Count] = a; ++Count; } public int PopFront() { --Count; ++firstIdx; return data[firstIdx - 1]; } public int PopBack() { --Count; return data[firstIdx + Count]; } public int Get(int n) { return data[firstIdx + n]; } } /******************************************************************************/ class MainClass { // Debug functions static void debug<T>(IEnumerable<T> a, string s = "") { Console.WriteLine($"name: {s}"); int i = 0; foreach (var e in a) { Console.WriteLine($"value {i}: {e}"); ++i; } } static void dbg<T>(T a, string s = "") { Console.WriteLine($"name: {s} value: {a}"); } //////////////////// static int gcd(int a, int b) { while (b != 0) { int t = b; b = a % b; a = t; } return a; } public static void Main() { var sc = new Scanner(); var wr = new BufferedStdoutWriter(); var dot = new NumberFormatInfo(); dot.NumberDecimalSeparator = "."; int r = sc.NextInt(); wr.Write((2 * r * Math.PI).ToString(dot)); wr.Flush(); } }
[["+", 63, 214, 205, 23, 0, 16, 31, 16, 31, 203], ["+", 63, 214, 205, 23, 0, 16, 31, 16, 17, 48]]
8
1,308
2
using System; namespace AtCoder { public static class AtCoder { public static void Main() { var input = int.Parse(Console.ReadLine()); var ans = input * Math.PI; Console.WriteLine(ans); } } }
using System; namespace AtCoder { public static class AtCoder { public static void Main() { var input = int.Parse(Console.ReadLine()); var ans = input * 2 * Math.PI; Console.WriteLine(ans); } } }
[["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48]]
8
51
2
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace Main { class Program { static void Main(string[] args) { //ここから // string[] str = Console.ReadLine().Split(' '); // int n = int.Parse(Console.ReadLine()); int n = int.Parse(Console.ReadLine()); Console.WriteLine((long)n * 3.1415926535); //ここまで } static long Max(long a, long b) { if (a >= b) return a; else return b; } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace Main { class Program { static void Main(string[] args) { //ここから // string[] str = Console.ReadLine().Split(' '); // int n = int.Parse(Console.ReadLine()); int n = int.Parse(Console.ReadLine()); Console.WriteLine((long)n * 3.1415926535 * 2); //ここまで } static long Max(long a, long b) { if (a >= b) return a; else return b; } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
94
2
using System; namespace AtCoder { class Program { static void Main() { int n = int.Parse(Console.ReadLine()); Console.WriteLine(n * Math.PI); } } }
using System; namespace AtCoder { class Program { static void Main() { int n = int.Parse(Console.ReadLine()); Console.WriteLine(n * 2.0 * Math.PI); } } }
[["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 250], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48]]
8
43
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Math; namespace CSharpSpiral { class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = #if DEBUG true #else false #endif }; Console.SetOut(sw); new Program().Solve(new ConsoleInput( #if DEBUG new StreamReader("../../../inputData.txt") #else Console.In #endif , ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var R = cin.ReadInt; Console.WriteLine(R * PI); } } static class ExtendClass { public static void Swap<T>(this T[] A, int x, int y) { var tmp = A[x]; A[x] = A[y]; A[y] = tmp; } public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X); public static IEnumerable<int> Indices<T>(this T[] X) => Enumerable.Range(0, X.Length); public static IEnumerable<int> Indices<T>(this T[,] X, int dim) => Enumerable.Range(0, X.GetLength(dim)); public static string Join<T>(this T[,] X, string separatorD2 = ",", string separatorD1 = "\n") => X.Indices(0) .Select(i => X.Indices(1).Select(j => X[i, j]).Join(separatorD2)) .Join(separatorD1); } class ConsoleInput { private readonly TextReader _stream; private readonly char _separator = ' '; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } public bool isEOF { get { return _stream.Peek() == -1; } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Math; namespace CSharpSpiral { class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = #if DEBUG true #else false #endif }; Console.SetOut(sw); new Program().Solve(new ConsoleInput( #if DEBUG new StreamReader("../../../inputData.txt") #else Console.In #endif , ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; Console.WriteLine(N * PI * 2); } } static class ExtendClass { public static void Swap<T>(this T[] A, int x, int y) { var tmp = A[x]; A[x] = A[y]; A[y] = tmp; } public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X); public static IEnumerable<int> Indices<T>(this T[] X) => Enumerable.Range(0, X.Length); public static IEnumerable<int> Indices<T>(this T[,] X, int dim) => Enumerable.Range(0, X.GetLength(dim)); public static string Join<T>(this T[,] X, string separatorD2 = ",", string separatorD1 = "\n") => X.Indices(0) .Select(i => X.Indices(1).Select(j => X[i, j]).Join(separatorD2)) .Join(separatorD1); } class ConsoleInput { private readonly TextReader _stream; private readonly char _separator = ' '; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } public bool isEOF { get { return _stream.Peek() == -1; } } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
769
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; using static System.Console; namespace AtCoder_1 { class Program { static void Main(string[] args) { var N = CinT(); double p = 2.0 * N + Math.PI; Cout(p); Cin(); } 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[] yakusuu(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.Threading.Tasks; using System.Text.RegularExpressions; using static System.Console; namespace AtCoder_1 { class Program { static void Main(string[] args) { var N = CinT(); double p = 2.0 * N * Math.PI; Cout(p); Cin(); } 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[] yakusuu(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; } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48]]
8
1,095
2