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 static System.Console; namespace abc122_c { class Program { static void Main(string[] args) { foreach (var result in Solve()) { WriteLine(result); } } static IEnumerable<long> Solve() { var q = int.Parse(ReadLine().Split()[1]); var s = ReadLine(); var prev = default(char); var summary = new int[s.Length]; for (int i = 0; i < s.Length; i++) { char c = s[i]; if (prev == 'A' && c == 'C') summary[i] = summary[i - 1] + 1; else summary[i] = summary[i - 1]; prev = c; } for (int i = 0; i < q; i++) { var lr = ReadLine().Split().Select(int.Parse).ToArray(); yield return summary[lr[1] - 1] - summary[lr[0] - 1]; } } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; namespace AtCoder.BeginnersSelections { class D_EnoughArray { static void Main(string[] args) { foreach (var result in Solve()) { WriteLine(result); } } static IEnumerable<long> Solve() { var q = int.Parse(ReadLine().Split()[1]); var s = ReadLine(); var prev = s[0]; var summary = new int[s.Length]; for (int i = 1; i < s.Length; i++) { char c = s[i]; if (prev == 'A' && c == 'C') summary[i] = summary[i - 1] + 1; else summary[i] = summary[i - 1]; prev = c; } for (int i = 0; i < q; i++) { var lr = ReadLine().Split().Select(int.Parse).ToArray(); yield return summary[lr[1] - 1] - summary[lr[0] - 1]; } } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["+", 36, 36, 0, 208, 0, 209, 141, 232, 234, 22], ["+", 36, 36, 0, 208, 0, 209, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 209, 141, 232, 141, 22], ["-", 0, 208, 0, 209, 8, 201, 0, 235, 141, 22], ["+", 0, 208, 0, 209, 8, 201, 0, 235, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 304, 0, 162], ["-", 0, 198, 0, 200, 0, 212, 0, 304, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 304, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 304, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
242
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; class Program { static void Main() { int[] nq = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int N = nq[0]; int Q = nq[1]; var S = Console.ReadLine(); var lrList = Enumerable.Range(0, Q) .Select(n => Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) - 1) .ToArray()) .ToList(); //累積和を使う。 var ruisekiA = new int[N + 1]; var ruisekiC = new int[N + 1]; // ruisekiA[i]は、S[i]よりも左がわにACのAが何回登場するかを表すこととする。 // ruisekiC[i]は、S[i]よりも左側にACのCが何回登場するかを表すこととする。 for (int i = 1; i <= N; i++) { if (i == N) ruisekiA[i] = ruisekiA[i - 1]; else ruisekiA[i] = ruisekiA[i - 1] + ((S[i - 1] == 'A' && S[i] == 'C') ? 1 : 0); } for (int i = 2; i <= N; i++) { ruisekiC[i] = ruisekiC[i - 1] + ((S[i - 2] == 'A' && S[i - 1] == 'C') ? 1 : 0); } foreach (var lr in lrList) { //区間内のACのAの数 var aCount = ruisekiA[lr[1] + 1] - ruisekiA[lr[0]]; //区間内のACのCの数 var cCount = ruisekiC[lr[1] + 1] - ruisekiC[lr[0]]; //ただし、Cから始まる場合は区間内のCの数をマイナス補正する。 if (S[lr[0]] == 'C') cCount--; //区間内のACの数は、これらの小さい方 Console.WriteLine(Math.Min(aCount, cCount)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; class Program { static void Main() { int[] nq = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int N = nq[0]; int Q = nq[1]; var S = Console.ReadLine(); var lrList = Enumerable.Range(0, Q) .Select(n => Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) - 1) .ToArray()) .ToList(); var ruisekiA = new int[N + 1]; var ruisekiC = new int[N + 1]; // ruisekiA[i]は、S[i]よりも左がわにACのAが何回登場するかを表すこととする。 // ruisekiC[i]は、S[i]よりも左側にACのCが何回登場するかを表すこととする。 for (int i = 1; i <= N; i++) { if (i == N) ruisekiA[i] = ruisekiA[i - 1]; else ruisekiA[i] = ruisekiA[i - 1] + ((S[i - 1] == 'A' && S[i] == 'C') ? 1 : 0); } for (int i = 2; i <= N; i++) { ruisekiC[i] = ruisekiC[i - 1] + ((S[i - 2] == 'A' && S[i - 1] == 'C') ? 1 : 0); } foreach (var lr in lrList) { //区間内のACのAの数 var aCount = ruisekiA[lr[1] + 1] - ruisekiA[lr[0]]; //区間内のACのCの数 var cCount = ruisekiC[lr[1] + 1] - ruisekiC[lr[0]]; //ただし、Cから始まる場合は区間内のCの数をマイナス補正する。 if (ruisekiC[lr[0] + 1] - ruisekiC[lr[0]] == 1) cCount--; //区間内のACの数は、これらの小さい方 Console.WriteLine(Math.Min(aCount, cCount)); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 104], ["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203]]
8
405
16
using System; using System.Collections.Generic; using System.Linq; namespace ziyuutyou { class Program { static void Main(string[] args) { var aaa = Console.ReadLine().Split(' '); var n = int.Parse(aaa[0]); var q = int.Parse(aaa[1]); var str = Console.ReadLine(); var s = new int[n + 1]; s[0] = 0; for (var i = 0; i + 1 <= n; ++i) { if (str[i].ToString() == "A" && str[i + 1].ToString() == "C") { s[i + 1] = s[i] + 1; } else { s[i + 1] = s[i]; } } var ans = new List<int>(); for (var i = 0; i < q; ++i) { var qua = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var anan = s[qua[1] - 1] - s[qua[0] - 1]; ans.Add(anan); } foreach (var ch in ans) { Console.WriteLine(ch); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace ziyuutyou { class Program { static void Main(string[] args) { var aaa = Console.ReadLine().Split(' '); var n = int.Parse(aaa[0]); var q = int.Parse(aaa[1]); var str = Console.ReadLine(); var s = new int[n]; for (var i = 0; i + 1 < n; ++i) { if (str[i].ToString() == "A" && str[i + 1].ToString() == "C") { if (i == 0) { s[i + 1] = 0 + 1; } else { s[i + 1] = s[i] + 1; } } else { s[i + 1] = s[i]; } } var ans = new List<int>(); for (var i = 0; i < q; ++i) { var qua = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var anan = s[qua[1] - 1] - s[qua[0] - 1]; ans.Add(anan); } foreach (var ch in ans) { Console.WriteLine(ch); } } } }
[["-", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
8
280
33
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { var str = Console.ReadLine(); var strs = str.Split(' '); var N = int.Parse(strs[0]); var Q = int.Parse(strs[1]); var S = Console.ReadLine(); var ls = new int[Q]; var rs = new int[Q]; for (int i = 0; i < Q; i++) { str = Console.ReadLine(); strs = str.Split(' '); ls[i] = int.Parse(strs[0]); rs[i] = int.Parse(strs[1]); } var AC = new int[N + 1]; for (int i = 0; i < N - 1; i++) { if (S[i] == 'A') { if (S[i + 1] == 'C') { AC[i + 1] = AC[i] + 1; i++; AC[i + 1] = AC[i]; } } else { AC[i + 1] = AC[i]; } } AC[N] = AC[N - 1]; for (int i = 0; i < Q; i++) { Console.WriteLine(AC[rs[i] - 1] - AC[ls[i] - 1]); } } } }
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { var str = Console.ReadLine(); var strs = str.Split(' '); var N = int.Parse(strs[0]); var Q = int.Parse(strs[1]); var S = Console.ReadLine(); var ls = new int[Q]; var rs = new int[Q]; for (int i = 0; i < Q; i++) { str = Console.ReadLine(); strs = str.Split(' '); ls[i] = int.Parse(strs[0]); rs[i] = int.Parse(strs[1]); } var AC = new int[N + 1]; for (int i = 0; i < N - 1; i++) { if (S[i] == 'A') { if (S[i + 1] == 'C') { AC[i + 1] = AC[i] + 1; i++; AC[i + 1] = AC[i]; } else { AC[i + 1] = AC[i]; } } else { AC[i + 1] = AC[i]; } } AC[N] = AC[N - 1]; for (int i = 0; i < Q; i++) { Console.WriteLine(AC[rs[i] - 1] - AC[ls[i] - 1]); } } } }
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
315
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; static class Program { const int mod = 1000000007; static void Main() { Sc sc = new Sc(); int[] s = sc.Ia; string t = " " + sc.S; int[] r = new int[s[0] + 1]; int a = 0; for (int i = 1; i <= s[0]; i++) { if (t[i] == 'A') { a++; } else if (t[i] == 'C') { if (a > 0) { a--; r[i]++; } } r[i] += r[i - 1]; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < s[1]; i++) { int[] q = sc.Ia; sb.Append((r[q[1]] - r[q[0]]) + "\n"); } Console.Write(sb); } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; static class Program { const int mod = 1000000007; static void Main() { Sc sc = new Sc(); int[] s = sc.Ia; string t = " " + sc.S; int[] r = new int[s[0] + 1]; for (int i = 1; i <= s[0]; i++) { if (t[i - 1] == 'A' && t[i] == 'C') { r[i]++; } r[i] += r[i - 1]; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < s[1]; i++) { int[] q = sc.Ia; sb.Append((r[q[1]] - r[q[0]]) + "\n"); } Console.Write(sb); } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 0, 7, 8, 196, 0, 57, 75, 57, 0, 121], ["-", 0, 7, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 75, 57, 64, 196, 0, 57, 0, 121], ["-", 0, 57, 75, 57, 64, 196, 0, 57, 0, 24], ["-", 75, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["-", 75, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["-", 75, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 57, 75, 57, 64, 196, 0, 57, 0, 25], ["-", 75, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 68], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 75, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
503
28
using System.Collections.Generic; using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var q = int.Parse(line[1]); var s = Console.ReadLine().Trim(); var z = new List<int>(); for (int i = 0; i < n - 1; i++) if (s[i] == 'A' && s[i + 1] == 'C') z.Add(i + 1); var a = z.ToArray(); for (int i = 0; i < q; i++) { line = Console.ReadLine().Trim().Split(' '); var L = int.Parse(line[0]); var r = int.Parse(line[1]); var ansr = getAns(a, r); var ansL = getAns(a, L); Console.WriteLine(ansr - ansL); } } static int getAns(int[] a, int b) { var t = UpperBound(a, b); var ep = a[t - 1] + 1; return b < ep ? t - 1 : t; } public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } }
using System.Collections.Generic; using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var q = int.Parse(line[1]); var s = Console.ReadLine().Trim(); var z = new List<int>(); for (int i = 0; i < n - 1; i++) if (s[i] == 'A' && s[i + 1] == 'C') z.Add(i + 1); var a = z.ToArray(); for (int i = 0; i < q; i++) { line = Console.ReadLine().Trim().Split(' '); var L = int.Parse(line[0]); var r = int.Parse(line[1]); if (a.Length == 0) { Console.WriteLine(0); goto next; } var ansr = getAns(a, r); var ansL = getAns(a, L); Console.WriteLine(ansr - ansL); next:; } } static int getAns(int[] a, int b) { var t = UpperBound(a, b); if (t <= 0) return 0; var ep = a[t - 1] + 1; return b < ep ? t - 1 : t; } public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 126, 0, 127], ["+", 8, 196, 0, 57, 64, 196, 0, 126, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 126, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 97, 0, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 97, 0, 102], ["+", 0, 7, 8, 196, 0, 97, 0, 260, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203]]
8
422
32
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder.ABC122.B { class Program { static void Main() { var sc = new Scanner(); var N = sc.Nextint(); var Q = sc.Nextint(); var S = sc.Next(); var l = new int[Q]; var r = new int[Q]; for (int i = 0; i < Q; i++) { l[i] = sc.Nextint() - 1; r[i] = sc.Nextint() - 1; } var comCount = new int[N]; for (int i = 0; i < N; i++) { if (i == 0) { continue; } else if (S[i] == 'C' && S[i - 1] == 'A') { comCount[i] = comCount[i - 1] + 1; } else { comCount[i] = comCount[i - 1]; } } Console.Error.WriteLine(string.Join(", ", comCount)); for (int i = 0; i < Q; i++) { var count = comCount[r[i]] - comCount[l[i]]; if (count > 0 && l[i] > 0 && comCount[l[i]] == comCount[l[i] - 1] + 1) { count--; } Console.WriteLine(count); } } } class Scanner { string[] s; long 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 (long i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(long N, double add = 0) { double[] Array = new double[N]; for (long i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } public decimal NextDecimal() { return decimal.Parse(Next()); } public decimal[] ArrayDecimal(long N, decimal add = 0) { decimal[] Array = new decimal[N]; for (long i = 0; i < N; i++) { Array[i] = NextDecimal(); } return Array; } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder.ABC122.B { class Program { static void Main() { var sc = new Scanner(); var N = sc.Nextint(); var Q = sc.Nextint(); var S = sc.Next(); var l = new int[Q]; var r = new int[Q]; for (int i = 0; i < Q; i++) { l[i] = sc.Nextint() - 1; r[i] = sc.Nextint() - 1; } var comCount = new int[N]; for (int i = 0; i < N; i++) { if (i == 0) { continue; } else if (S[i] == 'C' && S[i - 1] == 'A') { comCount[i] = comCount[i - 1] + 1; } else { comCount[i] = comCount[i - 1]; } } Console.Error.WriteLine(string.Join(", ", comCount)); for (int i = 0; i < Q; i++) { var count = comCount[r[i]] - comCount[l[i]]; Console.WriteLine(count); } } } class Scanner { string[] s; long 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 (long i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(long N, double add = 0) { double[] Array = new double[N]; for (long i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } public decimal NextDecimal() { return decimal.Parse(Next()); } public decimal[] ArrayDecimal(long N, decimal add = 0) { decimal[] Array = new decimal[N]; for (long i = 0; i < N; i++) { Array[i] = NextDecimal(); } return Array; } } }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 47], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["-", 15, 16, 31, 16, 12, 16, 31, 204, 205, 22], ["-", 31, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 31, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 47], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 15, 16, 12, 16, 12, 16, 31, 204, 205, 22], ["-", 12, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 206, 207, 0, 28, 0, 16, 31, 204, 205, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 12, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 17, 72], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 68], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
760
38
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace C { public class Program { public static void Main(string[] args) { int[] nq = RIntAr(); string s = RSt(); int cnt = 0; bool aFlg = false; int[] cnts = new int[s.Length]; for (int i = 0; i < s.Length; i++) { if (s[i] == 'A') aFlg = true; if (s[i] == 'C' && aFlg == true) { cnt++; aFlg = false; } cnts[i] = cnt; } for (int k = 0; k < nq[1]; k++) { int[] vs = RIntAr(); Console.WriteLine(cnts[vs[1] - 1] - cnts[vs[0] - 1]); } } static string RSt() { return Console.ReadLine(); } static int RInt() { return int.Parse(Console.ReadLine().Trim()); } static long RLong() { return long.Parse(Console.ReadLine().Trim()); } static double RDouble() { return double.Parse(Console.ReadLine()); } static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); } static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); } static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); } static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); } static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace C { public class Program { public static void Main(string[] args) { int[] nq = RIntAr(); string s = RSt(); int cnt = 0; bool aFlg = false; int[] cnts = new int[s.Length]; for (int i = 0; i < s.Length; i++) { if (s[i] == 'C' && aFlg == true) { cnt++; aFlg = false; } cnts[i] = cnt; if (s[i] == 'A') aFlg = true; else aFlg = false; } for (int k = 0; k < nq[1]; k++) { int[] vs = RIntAr(); Console.WriteLine(cnts[vs[1] - 1] - cnts[vs[0] - 1]); } } static string RSt() { return Console.ReadLine(); } static int RInt() { return int.Parse(Console.ReadLine().Trim()); } static long RLong() { return long.Parse(Console.ReadLine().Trim()); } static double RDouble() { return double.Parse(Console.ReadLine()); } static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); } static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); } static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); } static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); } static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 104], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 1, 0, 11, 12, 211, 0, 146], ["-", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 16, 31, 16, 12, 252, 0, 104], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 104], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 211, 0, 146], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 1, 0, 11, 12, 211, 0, 147]]
8
489
35
using System; using System.Collections.Generic; class Program { // static List<string> str = new List<string>(); static void Main(string[] args) { // 入力フェーズ string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int Q = int.Parse(input[1]); string S = Console.ReadLine(); int[] l = new int[Q]; int[] r = new int[Q]; for (int i = 0; i < Q; i++) { input = Console.ReadLine().Split(' '); l[i] = int.Parse(input[0]); r[i] = int.Parse(input[1]); } // ?文字目からAC List<int> ac = new List<int>(); // Console.WriteLine((N-1) + " len"); for (int i = 0; i < N - 1; i++) { // Console.WriteLine(S[i] + " " + S[i+1] + " " + i); if (S[i] == 'A' && S[i + 1] == 'C') { ac.Add(i + 1); // Console.Write((i+1)+" "); } } // Console.WriteLine(); int len = ac.Count - 1; for (int i = 0; i < Q; i++) { //各Qに答える if (len < 0) { Console.WriteLine("0"); continue; } // l[i]より大きくて一番近い数字が入ってるac[?]を探す // Console.WriteLine(i + " l " + l[i]); int start = getStart(ac, l[i], 0, len); // Console.WriteLine(l[i] + " start " + start ); // r[i]より小さくて一番近い数字が入ってるac[?]を探す // Console.WriteLine(i + " r " + r[i]); int end = getEnd(ac, r[i] - 1, 0, len); // Console.WriteLine(r[i] + " end " + end ); Console.WriteLine((end - start + 1)); } } static int getStart(List<int> ac, int l, int str, int end) { if (end - str <= 1) { if (ac[str] >= l) return str; else return end; } int mid = (str + end) / 2; // Console.WriteLine("chukan " + l + " " + str + " " + end);//+ // ((str+end)/2) + ac[(str+end)/2]); if (ac[mid] < l) { return getStart(ac, l, mid, end); } else { return getStart(ac, l, str, mid); } } static int getEnd(List<int> ac, int r, int str, int end) { if (end - str <= 1) { if (ac[end] <= r) return end; else return str; } int mid = (str + end) / 2; // Console.WriteLine("chukan2 " + ((str+end)/2) + ac[(str+end)/2]); if (ac[mid] > r) { return getEnd(ac, r, str, mid); } else { return getEnd(ac, r, mid, end); } } }
using System; using System.Collections.Generic; class Program { // static List<string> str = new List<string>(); static void Main(string[] args) { // 入力フェーズ string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int Q = int.Parse(input[1]); string S = Console.ReadLine(); int[] l = new int[Q]; int[] r = new int[Q]; for (int i = 0; i < Q; i++) { input = Console.ReadLine().Split(' '); l[i] = int.Parse(input[0]); r[i] = int.Parse(input[1]); } // ?文字目からAC List<int> ac = new List<int>(); // Console.WriteLine((N-1) + " len"); for (int i = 0; i < N - 1; i++) { // Console.WriteLine(S[i] + " " + S[i+1] + " " + i); if (S[i] == 'A' && S[i + 1] == 'C') { ac.Add(i + 1); // Console.Write((i+1)+" "); } } // Console.WriteLine(); int len = ac.Count - 1; for (int i = 0; i < Q; i++) { //各Qに答える if (len < 0) { Console.WriteLine("0"); continue; } // l[i]より大きくて一番近い数字が入ってるac[?]を探す // Console.WriteLine(i + " l " + l[i]); int start = getStart(ac, l[i], 0, len); // Console.WriteLine(l[i] + " start " + start ); // r[i]より小さくて一番近い数字が入ってるac[?]を探す // Console.WriteLine(i + " r " + r[i]); int end = getEnd(ac, r[i] - 1, 0, len); // Console.WriteLine(r[i] + " end " + end ); Console.WriteLine((end - start + 1)); } } static int getStart(List<int> ac, int l, int str, int end) { if (end - str <= 1) { if (ac[str] >= l) return str; else if (ac[end] >= l) return end; else return end + 1; } int mid = (str + end) / 2; // Console.WriteLine("chukan " + l + " " + str + " " + end);//+ // ((str+end)/2) + ac[(str+end)/2]); if (ac[mid] < l) { return getStart(ac, l, mid, end); } else { return getStart(ac, l, str, mid); } } static int getEnd(List<int> ac, int r, int str, int end) { if (end - str <= 1) { if (ac[end] <= r) return end; else if (ac[str] <= r) return str; else return str - 1; } int mid = (str + end) / 2; // Console.WriteLine("chukan2 " + ((str+end)/2) + ac[(str+end)/2]); if (ac[mid] > r) { return getEnd(ac, r, str, mid); } else { return getEnd(ac, r, mid, end); } } }
[["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 204, 205, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 57, 75, 57, 15, 16, 17, 20], ["+", 64, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 25], ["+", 64, 196, 0, 57, 75, 57, 64, 37, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 95], ["+", 64, 196, 0, 57, 75, 57, 75, 37, 0, 38], ["+", 0, 57, 75, 57, 75, 37, 0, 16, 31, 22], ["+", 0, 57, 75, 57, 75, 37, 0, 16, 17, 72], ["+", 0, 57, 75, 57, 75, 37, 0, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 64, 196, 0, 57, 75, 57, 15, 16, 17, 19], ["+", 64, 196, 0, 57, 75, 57, 64, 37, 0, 38], ["+", 64, 196, 0, 57, 75, 57, 64, 37, 0, 22], ["+", 0, 57, 75, 57, 75, 37, 0, 16, 17, 33]]
8
528
30
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static int[] cnt_ac_toend; static int AC_Cnt(string S, int start, int end) { int cnt_AC = 0; for (int i = end - 1; i >= start - 1; i--) { char now = S[i]; if (now == 'A') { if (i < end - 1) { if (S[i + 1] == 'C') { cnt_AC++; } } } cnt_ac_toend[i] = cnt_AC; } return cnt_AC; } static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int Q = int.Parse(input[1]); string S = Console.ReadLine(); cnt_ac_toend = new int[N]; AC_Cnt(S, 1, N); Console.WriteLine(string.Join("", cnt_ac_toend)); for (int i = 0; i < Q; i++) { string[] input2 = Console.ReadLine().Split(' '); int start = int.Parse(input2[0]); int end = int.Parse(input2[1]); Console.WriteLine(cnt_ac_toend[start - 1] - cnt_ac_toend[end - 1]); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static int[] cnt_ac_toend; static int AC_Cnt(string S, int start, int end) { int cnt_AC = 0; for (int i = end - 1; i >= start - 1; i--) { char now = S[i]; if (now == 'A') { if (i < end - 1) { if (S[i + 1] == 'C') { cnt_AC++; } } } cnt_ac_toend[i] = cnt_AC; } return cnt_AC; } static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int Q = int.Parse(input[1]); string S = Console.ReadLine(); cnt_ac_toend = new int[N]; AC_Cnt(S, 1, N); for (int i = 0; i < Q; i++) { string[] input2 = Console.ReadLine().Split(' '); int start = int.Parse(input2[0]); int end = int.Parse(input2[1]); Console.WriteLine(cnt_ac_toend[start - 1] - cnt_ac_toend[end - 1]); } } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 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, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
300
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.ABC_122 { class C { static void Main(string[] args) { Method(args); ReadLine(); } static void Method(string[] args) { int[] nq = ReadInts(); int n = nq[0]; int q = nq[1]; string s = Read(); int[][] lrs = new int [q][]; for (int i = 0; i < q; i++) { lrs[i] = ReadInts(); lrs[i][0]--; lrs[i][1]--; } int[] cnts = new int[n]; for (int i = 1; i < n; i++) { cnts[i] = cnts[i - 1]; if (s[i - 1] == 'A' && s[i] == 'C') { if (i > 1) { cnts[i] = cnts[i - 2] + 1; } else { cnts[i] = 1; } } Write(cnts[i] + " "); } WriteLine(); for (int i = 0; i < q; i++) { int val = cnts[lrs[i][1]]; val -= cnts[lrs[i][0]]; WriteLine(val); } } private static string Read() { return ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.ABC_122 { class C { static void Main(string[] args) { Method(args); ReadLine(); } static void Method(string[] args) { int[] nq = ReadInts(); int n = nq[0]; int q = nq[1]; string s = Read(); int[][] lrs = new int [q][]; for (int i = 0; i < q; i++) { lrs[i] = ReadInts(); lrs[i][0]--; lrs[i][1]--; } int[] cnts = new int[n]; for (int i = 1; i < n; i++) { cnts[i] = cnts[i - 1]; if (s[i - 1] == 'A' && s[i] == 'C') { if (i > 1) { cnts[i] = cnts[i - 2] + 1; } else { cnts[i] = 1; } } // Write(cnts[i] + " "); } // WriteLine(); for (int i = 0; i < q; i++) { int val = cnts[lrs[i][1]]; val -= cnts[lrs[i][0]]; WriteLine(val); } } private static string Read() { return ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 5, 0, 62], ["-", 3, 4, 0, 28, 0, 16, 12, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
473
16
using System; using System.Collections.Generic; using System.Linq; namespace ABC122D { static class MainClass { static int[] s; static long[,,,] dp = new long[101, 4, 4, 4]; static bool[,,,] done = new bool[101, 4, 4, 4]; static long mod = 1000000007; public static void Main(string[] args) { s = Array.ConvertAll(Console.ReadLine().Split().ToArray(), int.Parse); long ptn = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { done[3, i, j, k] = true; if (Ok(3, i, j, k)) { dp[3, i, j, k]++; } } } } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { ptn += Dfs(s[0], i, j, k); } } } Console.WriteLine(ptn); } public static long Dfs(int n, int w1, int w2, int w3) { if (n == 0) { return 1; } else if (done[n, w1, w2, w3]) { return dp[n, w1, w2, w3]; } else { long ptn = 0; for (int i = 0; i < 4; i++) { if (Ok(i, w1, w2, w3)) { // Console.WriteLine("OK: i : " + i + " w1 " + w1 + " w2 " + w2 + " // w3 " + w3); ptn += Dfs(n - 1, i, w1, w2) % mod; } else { // Console.WriteLine("NG: i : " + i + " w1 " + w1 + " w2 " + w2 + " // w3 " + w3); } } done[n, w1, w2, w3] = true; dp[n, w1, w2, w3] = ptn; // Console.WriteLine("ptn: " + ptn + " n " + n + " w1 " + w1 + " w2 " + w2 // + " w3 " + w3); return ptn; } } public static bool Ok(int w1, int w2, int w3, int a) { string s1 = w1.ToString(); string s2 = w2.ToString(); string s3 = w3.ToString(); string sa = a.ToString(); if ((s1 + s2 + s3 + sa).Contains("012")) return false; if ((s2 + s1 + s3 + sa).Contains("012")) return false; if ((s1 + s3 + s2 + sa).Contains("012")) return false; if ((s1 + s2 + sa + s3).Contains("012")) return false; return true; } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC122D { static class MainClass { static int[] s; static long[,,,] dp = new long[101, 4, 4, 4]; static bool[,,,] done = new bool[101, 4, 4, 4]; static long mod = (long)Math.Pow(10, 9) + 7; public static void Main(string[] args) { s = Array.ConvertAll(Console.ReadLine().Split().ToArray(), int.Parse); long ptn = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { done[3, i, j, k] = true; if (Ok(3, i, j, k)) { dp[3, i, j, k]++; } } } } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { ptn += Dfs(s[0], i, j, k); } } } Console.WriteLine(ptn % mod); } public static long Dfs(int n, int w1, int w2, int w3) { if (n == 0) { return 1; } else if (done[n, w1, w2, w3]) { return dp[n, w1, w2, w3]; } else { long ptn = 0; for (int i = 0; i < 4; i++) { if (Ok(i, w1, w2, w3)) { // Console.WriteLine("OK: i : " + i + " w1 " + w1 + " w2 " + w2 + " // w3 " + w3); ptn += Dfs(n - 1, i, w1, w2); } else { // Console.WriteLine("NG: i : " + i + " w1 " + w1 + " w2 " + w2 + " // w3 " + w3); } } done[n, w1, w2, w3] = true; dp[n, w1, w2, w3] = ptn % mod; // Console.WriteLine("ptn: " + ptn + " n " + n + " w1 " + w1 + " w2 " + w2 // + " w3 " + w3); return dp[n, w1, w2, w3]; } } public static bool Ok(int w1, int w2, int w3, int a) { string s1 = w1.ToString(); string s2 = w2.ToString(); string s3 = w3.ToString(); string sa = a.ToString(); if ((s1 + s2 + s3 + sa).Contains("012")) return false; if ((s2 + s1 + s3 + sa).Contains("012")) return false; if ((s1 + s3 + s2 + sa).Contains("012")) return false; if ((s1 + s2 + sa + s3).Contains("012")) return false; return true; } } }
[["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25], ["+", 0, 16, 31, 74, 51, 213, 63, 214, 205, 22], ["+", 0, 16, 31, 74, 51, 213, 63, 214, 0, 131], ["+", 0, 16, 31, 74, 51, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 74, 51, 213, 3, 4, 0, 24], ["+", 31, 74, 51, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 16, 31, 74, 51, 213, 3, 4, 0, 21], ["+", 0, 16, 31, 74, 51, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 57, 75, 57, 75, 196, 0, 37, 0, 22], ["+", 75, 57, 75, 196, 0, 37, 0, 204, 205, 22], ["+", 75, 196, 0, 37, 0, 204, 206, 207, 0, 70], ["+", 0, 37, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 196, 0, 37, 0, 204, 206, 207, 0, 21], ["+", 75, 196, 0, 37, 0, 204, 206, 207, 0, 73]]
8
577
31
using System; using System.Collections.Generic; using System.Linq; class Procon { public Procon() {} static void Main(string[] agrs) { new Procon().Do(); } Scanner cin; int N; Dictionary<string, long>[] last4str; string[] Alphabet = new string[4] { "A", "G", "C", "T" }; public bool Check(string key) { if (key.Contains("AGC")) { return true; } for (int i = 1; i < key.Length; i++) { char[] tmpCharArray = key.ToCharArray(); char tmp = tmpCharArray[i]; tmpCharArray[i] = tmpCharArray[i - 1]; tmpCharArray[i - 1] = tmp; string tmpKey = new string(tmpCharArray); if (tmpKey.Contains("AGC")) { return true; } } return false; } public long Count(long i) { last4str[i] = new Dictionary<string, long>(); if (i == 0) { last4str[i]["A"] = 1; last4str[i]["G"] = 1; last4str[i]["C"] = 1; last4str[i]["T"] = 1; } else { foreach (string k in last4str[i - 1].Keys) { foreach (string a in Alphabet) { var newKey = k + a; if (Check(newKey)) { continue; } newKey = newKey.Substring(Math.Max(newKey.Length - 3, 0)); if (last4str[i].ContainsKey(newKey)) { last4str[i][newKey] = (last4str[i][newKey] + last4str[i - 1][k]) % 1000000007; } else { last4str[i].Add(newKey, last4str[i - 1][k]); } } } } long ans = 0; foreach (long v in last4str[i].Values) { ans += v; } return ans; } public void Do() { cin = new Scanner(); N = cin.nextInt(); last4str = new Dictionary<string, long>[N]; long ans = 0; for (int i = 0; i < N; i++) { ans = Count(i); } Console.WriteLine(ans); } } class Scanner { string[] s; int i; int max_i; public Scanner() { s = new string[0]; max_i = 0; i = 0; } public string nextString() { if (i >= s.Length) { s = Console.ReadLine().Split(' '); max_i = s.Length; i = 0; if (max_i == 0) { return ""; } return s[i++]; } else { return s[i++]; } } public int nextInt() { return int.Parse(nextString()); } public long nextLong() { return long.Parse(nextString()); } public double nextDouble() { return double.Parse(nextString()); } public string[] arrayString() { return Console.ReadLine().Split(' '); } public int[] arrayInt() { string[] str = Console.ReadLine().Split(' '); int[] array = new int[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = int.Parse(str[i]); } return array; } public long[] arrayLong() { string[] str = Console.ReadLine().Split(' '); long[] array = new long[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = long.Parse(str[i]); } return array; } public double[] arrayDouble() { string[] str = Console.ReadLine().Split(' '); double[] array = new double[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = double.Parse(str[i]); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Procon { public Procon() {} static void Main(string[] agrs) { new Procon().Do(); } Scanner cin; int N; Dictionary<string, long>[] last4str; string[] Alphabet = new string[4] { "A", "G", "C", "T" }; public bool Check(string key) { if (key.Contains("AGC")) { return true; } for (int i = 1; i < key.Length; i++) { char[] tmpCharArray = key.ToCharArray(); char tmp = tmpCharArray[i]; tmpCharArray[i] = tmpCharArray[i - 1]; tmpCharArray[i - 1] = tmp; string tmpKey = new string(tmpCharArray); if (tmpKey.Contains("AGC")) { return true; } } return false; } public long Count(long i) { last4str[i] = new Dictionary<string, long>(); if (i == 0) { last4str[i]["A"] = 1; last4str[i]["G"] = 1; last4str[i]["C"] = 1; last4str[i]["T"] = 1; } else { foreach (string k in last4str[i - 1].Keys) { foreach (string a in Alphabet) { var newKey = k + a; if (Check(newKey)) { continue; } newKey = newKey.Substring(Math.Max(newKey.Length - 3, 0)); if (last4str[i].ContainsKey(newKey)) { last4str[i][newKey] = (last4str[i][newKey] + last4str[i - 1][k]) % 1000000007; } else { last4str[i].Add(newKey, last4str[i - 1][k]); } } } } long ans = 0; foreach (long v in last4str[i].Values) { ans = (ans + v) % 1000000007; } return ans; } public void Do() { cin = new Scanner(); N = cin.nextInt(); last4str = new Dictionary<string, long>[N]; long ans = 0; for (int i = 0; i < N; i++) { ans = Count(i); } Console.WriteLine(ans); } } class Scanner { string[] s; int i; int max_i; public Scanner() { s = new string[0]; max_i = 0; i = 0; } public string nextString() { if (i >= s.Length) { s = Console.ReadLine().Split(' '); max_i = s.Length; i = 0; if (max_i == 0) { return ""; } return s[i++]; } else { return s[i++]; } } public int nextInt() { return int.Parse(nextString()); } public long nextLong() { return long.Parse(nextString()); } public double nextDouble() { return double.Parse(nextString()); } public string[] arrayString() { return Console.ReadLine().Split(' '); } public int[] arrayInt() { string[] str = Console.ReadLine().Split(' '); int[] array = new int[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = int.Parse(str[i]); } return array; } public long[] arrayLong() { string[] str = Console.ReadLine().Split(' '); long[] array = new long[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = long.Parse(str[i]); } return array; } public double[] arrayDouble() { string[] str = Console.ReadLine().Split(' '); double[] array = new double[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = double.Parse(str[i]); } return array; } }
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
919
8
using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Linq; using static System.Math; class Program { static long mod = (long)1e9 + 7; static void Main() { int n = int.Parse(Console.ReadLine()); long[,] dp = new long[n + 1, 16]; for (int i = 0; i < 16; i++) { dp[2, i] = 1; } for (int i = 3; i <= n; i++) { dp[i, 0] = (dp[i, 0] + dp[i - 1, 0]) % mod; dp[i, 0] = (dp[i, 0] + dp[i - 1, 4]) % mod; dp[i, 0] = (dp[i, 0] + dp[i - 1, 8]) % mod; dp[i, 0] = (dp[i, 0] + dp[i - 1, 12]) % mod; dp[i, 1] = (dp[i, 1] + dp[i - 1, 0]) % mod; dp[i, 1] = (dp[i, 1] + dp[i - 1, 4]) % mod; dp[i, 1] = (dp[i, 1] + dp[i - 1, 12]) % mod; dp[i, 1] = (dp[i, 1] - dp[i - 2, 2] + mod) % mod; dp[i, 2] = (dp[i, 2] + dp[i - 1, 0]) % mod; dp[i, 2] = (dp[i, 2] + dp[i - 1, 4]) % mod; dp[i, 2] = (dp[i, 2] + dp[i - 1, 8]) % mod; dp[i, 2] = (dp[i, 2] + dp[i - 1, 12]) % mod; dp[i, 3] = (dp[i, 3] + dp[i - 1, 0]) % mod; dp[i, 3] = (dp[i, 3] + dp[i - 1, 4]) % mod; dp[i, 3] = (dp[i, 3] + dp[i - 1, 8]) % mod; dp[i, 3] = (dp[i, 3] + dp[i - 1, 12]) % mod; dp[i, 4] = (dp[i, 4] + dp[i - 1, 1]) % mod; dp[i, 4] = (dp[i, 4] + dp[i - 1, 5]) % mod; dp[i, 4] = (dp[i, 4] + dp[i - 1, 9]) % mod; dp[i, 4] = (dp[i, 4] + dp[i - 1, 13]) % mod; dp[i, 5] = (dp[i, 5] + dp[i - 1, 1]) % mod; dp[i, 5] = (dp[i, 5] + dp[i - 1, 5]) % mod; dp[i, 5] = (dp[i, 5] + dp[i - 1, 9]) % mod; dp[i, 5] = (dp[i, 5] + dp[i - 1, 13]) % mod; dp[i, 6] = (dp[i, 6] + dp[i - 1, 5]) % mod; dp[i, 6] = (dp[i, 6] + dp[i - 1, 9]) % mod; dp[i, 6] = (dp[i, 6] + dp[i - 1, 13]) % mod; dp[i, 7] = (dp[i, 7] + dp[i - 1, 1]) % mod; dp[i, 7] = (dp[i, 7] + dp[i - 1, 5]) % mod; dp[i, 7] = (dp[i, 7] + dp[i - 1, 9]) % mod; dp[i, 7] = (dp[i, 7] + dp[i - 1, 13]) % mod; dp[i, 8] = (dp[i, 8] + dp[i - 1, 2]) % mod; dp[i, 8] = (dp[i, 8] + dp[i - 1, 6]) % mod; dp[i, 8] = (dp[i, 8] + dp[i - 1, 10]) % mod; dp[i, 8] = (dp[i, 8] + dp[i - 1, 14]) % mod; dp[i, 9] = (dp[i, 9] + dp[i - 1, 6]) % mod; dp[i, 9] = (dp[i, 9] + dp[i - 1, 10]) % mod; dp[i, 9] = (dp[i, 9] + dp[i - 1, 14]) % mod; dp[i, 9] = (dp[i, 9] - dp[i - 2, 2] + mod) % mod; dp[i, 10] = (dp[i, 10] + dp[i - 1, 2]) % mod; dp[i, 10] = (dp[i, 10] + dp[i - 1, 6]) % mod; dp[i, 10] = (dp[i, 10] + dp[i - 1, 10]) % mod; dp[i, 10] = (dp[i, 10] + dp[i - 1, 14]) % mod; dp[i, 11] = (dp[i, 11] + dp[i - 1, 2]) % mod; dp[i, 11] = (dp[i, 11] + dp[i - 1, 6]) % mod; dp[i, 11] = (dp[i, 11] + dp[i - 1, 10]) % mod; dp[i, 11] = (dp[i, 11] + dp[i - 1, 14]) % mod; dp[i, 12] = (dp[i, 12] + dp[i - 1, 3]) % mod; dp[i, 12] = (dp[i, 12] + dp[i - 1, 7]) % mod; dp[i, 12] = (dp[i, 12] + dp[i - 1, 11]) % mod; dp[i, 12] = (dp[i, 12] + dp[i - 1, 15]) % mod; dp[i, 13] = (dp[i, 13] + dp[i - 1, 3]) % mod; dp[i, 13] = (dp[i, 13] + dp[i - 1, 7]) % mod; dp[i, 13] = (dp[i, 13] + dp[i - 1, 11]) % mod; dp[i, 13] = (dp[i, 13] + dp[i - 1, 15]) % mod; dp[i, 13] = (dp[i, 13] - dp[i - 2, 2] + mod) % mod; dp[i, 14] = (dp[i, 14] + dp[i - 1, 3]) % mod; dp[i, 14] = (dp[i, 14] + dp[i - 1, 7]) % mod; dp[i, 14] = (dp[i, 14] + dp[i - 1, 11]) % mod; dp[i, 14] = (dp[i, 14] + dp[i - 1, 15]) % mod; dp[i, 15] = (dp[i, 15] + dp[i - 1, 3]) % mod; dp[i, 15] = (dp[i, 15] + dp[i - 1, 7]) % mod; dp[i, 15] = (dp[i, 15] + dp[i - 1, 11]) % mod; dp[i, 15] = (dp[i, 15] + dp[i - 1, 15]) % mod; } long ans = 0; for (int i = 0; i < 16; i++) { ans += dp[n, i]; ans %= mod; } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Linq; using static System.Math; class Program { static long mod = (long)1e9 + 7; static void Main() { int n = int.Parse(Console.ReadLine()); long[,] dp = new long[n + 1, 16]; for (int i = 0; i < 16; i++) { dp[2, i] = 1; } for (int i = 3; i <= n; i++) { dp[i, 0] = (dp[i, 0] + dp[i - 1, 0]) % mod; dp[i, 0] = (dp[i, 0] + dp[i - 1, 4]) % mod; dp[i, 0] = (dp[i, 0] + dp[i - 1, 8]) % mod; dp[i, 0] = (dp[i, 0] + dp[i - 1, 12]) % mod; dp[i, 1] = (dp[i, 1] + dp[i - 1, 0]) % mod; dp[i, 1] = (dp[i, 1] + dp[i - 1, 4]) % mod; dp[i, 1] = (dp[i, 1] + dp[i - 1, 12]) % mod; dp[i, 2] = (dp[i, 2] + dp[i - 1, 0]) % mod; dp[i, 2] = (dp[i, 2] + dp[i - 1, 4]) % mod; dp[i, 2] = (dp[i, 2] + dp[i - 1, 8]) % mod; dp[i, 2] = (dp[i, 2] + dp[i - 1, 12]) % mod; dp[i, 3] = (dp[i, 3] + dp[i - 1, 0]) % mod; dp[i, 3] = (dp[i, 3] + dp[i - 1, 4]) % mod; dp[i, 3] = (dp[i, 3] + dp[i - 1, 8]) % mod; dp[i, 3] = (dp[i, 3] + dp[i - 1, 12]) % mod; dp[i, 4] = (dp[i, 4] + dp[i - 1, 1]) % mod; dp[i, 4] = (dp[i, 4] + dp[i - 1, 5]) % mod; dp[i, 4] = (dp[i, 4] + dp[i - 1, 9]) % mod; dp[i, 4] = (dp[i, 4] + dp[i - 1, 13]) % mod; dp[i, 5] = (dp[i, 5] + dp[i - 1, 1]) % mod; dp[i, 5] = (dp[i, 5] + dp[i - 1, 5]) % mod; dp[i, 5] = (dp[i, 5] + dp[i - 1, 9]) % mod; dp[i, 5] = (dp[i, 5] + dp[i - 1, 13]) % mod; dp[i, 6] = (dp[i, 6] + dp[i - 1, 5]) % mod; dp[i, 6] = (dp[i, 6] + dp[i - 1, 9]) % mod; dp[i, 6] = (dp[i, 6] + dp[i - 1, 13]) % mod; dp[i, 7] = (dp[i, 7] + dp[i - 1, 1]) % mod; dp[i, 7] = (dp[i, 7] + dp[i - 1, 5]) % mod; dp[i, 7] = (dp[i, 7] + dp[i - 1, 9]) % mod; dp[i, 7] = (dp[i, 7] + dp[i - 1, 13]) % mod; dp[i, 8] = (dp[i, 8] + dp[i - 1, 2]) % mod; dp[i, 8] = (dp[i, 8] + dp[i - 1, 6]) % mod; dp[i, 8] = (dp[i, 8] + dp[i - 1, 10]) % mod; dp[i, 8] = (dp[i, 8] + dp[i - 1, 14]) % mod; dp[i, 9] = (dp[i, 9] + dp[i - 1, 6]) % mod; dp[i, 9] = (dp[i, 9] + dp[i - 1, 10]) % mod; dp[i, 9] = (dp[i, 9] + dp[i - 1, 14]) % mod; dp[i, 9] = (dp[i, 9] - dp[i - 2, 2] - dp[i - 2, 3] + 2 * mod) % mod; dp[i, 10] = (dp[i, 10] + dp[i - 1, 2]) % mod; dp[i, 10] = (dp[i, 10] + dp[i - 1, 6]) % mod; dp[i, 10] = (dp[i, 10] + dp[i - 1, 10]) % mod; dp[i, 10] = (dp[i, 10] + dp[i - 1, 14]) % mod; dp[i, 11] = (dp[i, 11] + dp[i - 1, 2]) % mod; dp[i, 11] = (dp[i, 11] + dp[i - 1, 6]) % mod; dp[i, 11] = (dp[i, 11] + dp[i - 1, 10]) % mod; dp[i, 11] = (dp[i, 11] + dp[i - 1, 14]) % mod; dp[i, 12] = (dp[i, 12] + dp[i - 1, 3]) % mod; dp[i, 12] = (dp[i, 12] + dp[i - 1, 7]) % mod; dp[i, 12] = (dp[i, 12] + dp[i - 1, 11]) % mod; dp[i, 12] = (dp[i, 12] + dp[i - 1, 15]) % mod; dp[i, 13] = (dp[i, 13] + dp[i - 1, 3]) % mod; dp[i, 13] = (dp[i, 13] + dp[i - 1, 7]) % mod; dp[i, 13] = (dp[i, 13] + dp[i - 1, 11]) % mod; dp[i, 13] = (dp[i, 13] + dp[i - 1, 15]) % mod; dp[i, 13] = (dp[i, 13] - dp[i - 2, 2] + mod) % mod; dp[i, 14] = (dp[i, 14] + dp[i - 1, 3]) % mod; dp[i, 14] = (dp[i, 14] + dp[i - 1, 7]) % mod; dp[i, 14] = (dp[i, 14] + dp[i - 1, 11]) % mod; dp[i, 14] = (dp[i, 14] + dp[i - 1, 15]) % mod; dp[i, 15] = (dp[i, 15] + dp[i - 1, 3]) % mod; dp[i, 15] = (dp[i, 15] + dp[i - 1, 7]) % mod; dp[i, 15] = (dp[i, 15] + dp[i - 1, 11]) % mod; dp[i, 15] = (dp[i, 15] + dp[i - 1, 15]) % mod; } long ans = 0; for (int i = 0; i < 16; i++) { ans += dp[n, i]; ans %= mod; } Console.WriteLine(ans); } }
[["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 31, 23, 0, 16, 31, 16, 31, 204, 205, 22], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 21], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 12, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["-", 31, 23, 0, 16, 31, 16, 12, 204, 205, 22], ["-", 0, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 16, 31, 16, 12, 204, 206, 207, 0, 21], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 31, 23, 0, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 21], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 31, 203], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 17, 48]]
8
1,899
40
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { int n = int.Parse(ReadLine()); List<int> b = ReadLine().Split().ToList().ConvertAll(x => int.Parse(x)); List<int> ans = new List<int>(); for (int i = 0; i < n; i++) { for (int j = b.Count - 1; j >= 0; j--) { if ((j + 1) == b[j]) { ans.Add(j + 1); b.RemoveAt(j); break; } } } ans.Reverse(); foreach (var i in ans) { WriteLine(i); } } }
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { int n = int.Parse(ReadLine()); List<int> b = ReadLine().Split().ToList().ConvertAll(x => int.Parse(x)); List<int> ans = new List<int>(); for (int i = 0; i < n; i++) { for (int j = b.Count - 1; j >= 0; j--) { if ((j + 1) == b[j]) { ans.Add(j + 1); b.RemoveAt(j); break; } } } ans.Reverse(); if (ans.Count == n) { foreach (var i in ans) { WriteLine(i); } } else { WriteLine(-1); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 210, 8, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 213, 63, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203]]
8
181
19
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long n = sc.NextLong(); long[] bb = sc.LongArray(); List<long> bList = bb.ToList(); List<long> answers = new List<long>(); while (answers.Count != n) { long tmpAnswer = 0; for (int i = 0; i < bList.Count(); i++) { if (i + 1 == bList.IndexOf(i)) { tmpAnswer = Math.Max(i + 1, tmpAnswer); } } answers.Add(tmpAnswer); bList.RemoveAt((int)(tmpAnswer - 1)); } foreach (var answer in answers) { Console.WriteLine(answer); } } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long n = sc.NextLong(); long[] bb = sc.LongArray(); List<long> bList = bb.ToList(); List<long> answers = new List<long>(); while (answers.Count != n) { long tmpAnswer = 0; for (int i = 0; i < bList.Count(); i++) { if (i + 1 == bList[i]) { tmpAnswer = Math.Max(i + 1, tmpAnswer); } } if (tmpAnswer == 0) { Console.WriteLine(-1); return; } answers.Add(tmpAnswer); bList.RemoveAt((int)(tmpAnswer - 1)); } answers.Reverse(); foreach (var answer in answers) { 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, 15, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 52, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
480
30
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static long Mod = (long)1e9 + 7; static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var // N = Sarray()[0]; var N = Sarray()[0]; var Bi = Sarray(); var ans = new long[N]; for (var i = N - 1; 0 <= i; --i) { var cnt = 0; for (var j = 0; j < N; ++j) { if (0 == ans[j]) { ++cnt; if (cnt == Bi[i]) { ans[j] = Bi[i]; break; } } } } foreach (var a in ans) WriteLine(a); // Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static long Mod = (long)1e9 + 7; static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var // N = Sarray()[0]; var N = Sarray()[0]; var Bi = Sarray(); var ans = new long[N]; for (var i = N - 1; 0 <= i; --i) { var cnt = 0; for (var j = 0; j < N; ++j) { if (0 == ans[j]) { ++cnt; if (cnt == Bi[i]) { ans[j] = Bi[i]; break; } } if (j == N - 1) { WriteLine(-1); return; } } } foreach (var a in ans) WriteLine(a); // Out.Flush(); } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46]]
8
245
18
using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.Numerics; class AtCoder { public void Slove() { int n = int.Parse(Console.ReadLine()); var a = Console.ReadLine() .Split() .Select(int.Parse) .Select(x => x - 1) .ToArray(); var b = a.ToList(); var result = new Stack<int>(); foreach (int i in Enumerable.Range(1, n)) { int bLen = b.Count; foreach (int j in Enumerable.Range(0, Math.Min(i + 1, bLen)).Reverse()) { if (b[j] == j) { b.RemoveAt(j); result.Push(j + 1); // System.Console.WriteLine(j + 1); break; } } if (b.Count == bLen) { System.Console.WriteLine(-1); return; } } System.Console.WriteLine(string.Join("\n", result)); // var ts = new List<int>(); // foreach(int i in result) // { // ts.Insert(i - 1, i); // } // System.Console.WriteLine(string.Join(" ", ts)); // System.Console.WriteLine(ts.SequenceEqual(a.Select(x => x + 1))); } static void Main() { var ac = new AtCoder(); ac.Slove(); } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.Numerics; class AtCoder { public void Slove() { int n = int.Parse(Console.ReadLine()); var a = Console.ReadLine() .Split() .Select(int.Parse) .Select(x => x - 1) .ToArray(); var b = a.ToList(); var result = new Stack<int>(); foreach (int i in Enumerable.Range(1, n).Reverse()) { int bLen = b.Count; foreach (int j in Enumerable.Range(0, i).Reverse()) { if (b[j] == j) { b.RemoveAt(j); result.Push(j + 1); // System.Console.WriteLine(j + 1); break; } } if (b.Count == bLen) { System.Console.WriteLine(-1); return; } } System.Console.WriteLine(string.Join("\n", result)); // var ts = new List<int>(); // foreach(int i in result) // { // ts.Insert(i - 1, i); // } // System.Console.WriteLine(string.Join(" ", ts)); // System.Console.WriteLine(ts.SequenceEqual(a.Select(x => x + 1))); } static void Main() { var ac = new AtCoder(); ac.Slove(); } }
[["+", 8, 196, 0, 210, 12, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 210, 12, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 210, 12, 213, 3, 4, 0, 25], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
253
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC032 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] h = Console.ReadLine().Split(' ').Select(z => int.Parse(z)).ToArray(); List<int> a = h.ToList(); List<int> list = new List<int>(); for (int i = 0; i < N; i++) { for (int j = N - i - 1; j >= 0; j--) { int k = a[j]; if (k == j + 1) { list.Add(k); a.RemoveAt(j); break; } Console.WriteLine(-1); return; } } list.Reverse(); foreach (int r in list) { Console.WriteLine(r); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC032 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] h = Console.ReadLine().Split(' ').Select(z => int.Parse(z)).ToArray(); List<int> a = h.ToList(); List<int> list = new List<int>(); for (int i = 0; i < N; i++) { int j = 0; for (j = N - i - 1; j >= 0; j--) { int k = a[j]; if (k == j + 1) { list.Add(k); a.RemoveAt(j); break; } } if (j < 0) { Console.WriteLine(-1); return; } } list.Reverse(); foreach (int r in list) { Console.WriteLine(r); } } } }
[["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45]]
8
222
14
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var N = Int1; var ans = new List<Tuple<int, int>>(); int cnt = 0; for (int i = 1; i <= N; ++i) { for (int j = i + 1; j <= N; ++j) { if (i + j == N) continue; ans.Add(new Tuple<int, int>(i, j)); ++cnt; } } Write(cnt); foreach (var x in ans) { Write(x.Item1, x.Item2); } } } 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) { long ret = 1; long x = 1; for (long i = n; i >= n - r + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } 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 class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); // public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", // a)); public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var N = Int1; var ans = new List<Tuple<int, int>>(); int cnt = 0; int NN = N; if (N % 2 == 0) ++NN; for (int i = 1; i <= N; ++i) { for (int j = i + 1; j <= N; ++j) { if (i + j == NN) continue; ans.Add(new Tuple<int, int>(i, j)); ++cnt; } } Write(cnt); foreach (var x in ans) { Write(x.Item1, x.Item2); } } } 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) { long ret = 1; long x = 1; for (long i = n; i >= n - r + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } 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 class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); // public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", // a)); public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 241, 0, 29], ["+", 8, 196, 0, 57, 64, 1, 0, 241, 0, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
8
980
18
using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.Numerics; class AtCoder { public void Slove() { var inputs = Console.ReadLine().Split(); int n = int.Parse(inputs[0]); long a = int.Parse(inputs[1]); long b = int.Parse(inputs[2]); var array = Console.ReadLine().Split().Select(int.Parse).ToArray(); long[] dp = Enumerable.Repeat((long)int.MaxValue, n + 1).ToArray(); long[] imos = new long[n + 2]; dp[0] = 0; foreach (int num in array) { dp[num] = dp.Take(num).Min(); foreach (int i in Enumerable.Range(0, num)) { dp[i] += a; } foreach (int i in Enumerable.Range(0, n + 1).Skip(num + 1)) { dp[i] += b; } System.Console.WriteLine(string.Join(" ", dp)); } System.Console.WriteLine(dp.Min()); } static void Main() { var ac = new AtCoder(); ac.Slove(); } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.Numerics; class AtCoder { public void Slove() { var inputs = Console.ReadLine().Split(); int n = int.Parse(inputs[0]); long a = int.Parse(inputs[1]); long b = int.Parse(inputs[2]); var array = Console.ReadLine().Split().Select(int.Parse).ToArray(); long[] dp = Enumerable.Repeat((long)int.MaxValue, n + 1).ToArray(); dp[0] = 0; foreach (int num in array) { dp[num] = dp.Take(num).Min(); foreach (int i in Enumerable.Range(0, num)) { dp[i] += a; } foreach (int i in Enumerable.Range(0, n + 1).Skip(num + 1)) { dp[i] += b; } // System.Console.WriteLine(string.Join(" ", dp)); } System.Console.WriteLine(dp.Min()); } static void Main() { var ac = new AtCoder(); ac.Slove(); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 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, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35]]
8
289
31
using System; using System.Text; using System.Collections.Generic; using static System.Math; using System.Linq; class Program { static void Main(string[] args) { var HWK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var A = HWK[0]; var B = HWK[1]; if (A <= B && B % A == 0) { Console.WriteLine(A + B); } else { Console.WriteLine(A - B); } } }
using System; using System.Text; using System.Collections.Generic; using static System.Math; using System.Linq; class Program { static void Main(string[] args) { var HWK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var A = HWK[0]; var B = HWK[1]; if (B % A == 0) { Console.WriteLine(A + B); } else { Console.WriteLine(B - A); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
124
8
using System; using System.Linq; namespace ABC118_A { class Program { static void Main(string[] args) { var ab = Console.ReadLine().Split().Select(int.Parse).ToArray(); var a = ab[0]; var b = ab[1]; Console.WriteLine(a % b == 0 ? a + b : a - b); } } }
using System; using System.Linq; namespace ABC118_A { class Program { static void Main(string[] args) { var ab = Console.ReadLine().Split().Select(int.Parse).ToArray(); var a = ab[0]; var b = ab[1]; Console.WriteLine(b % a == 0 ? a + b : b - a); } } }
[["-", 0, 28, 0, 41, 15, 16, 31, 16, 31, 22], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 12, 22], ["-", 3, 4, 0, 28, 0, 41, 75, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 41, 75, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 12, 22]]
8
86
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc_a { class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray(); int A = inputs[0]; int B = inputs[1]; if (B % A == 0) { Console.WriteLine(A + B); } else { Console.WriteLine(A - B); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc_a { class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray(); int A = inputs[0]; int B = inputs[1]; if (B % A == 0) { Console.WriteLine(A + B); } else { Console.WriteLine(B - A); } Console.ReadLine(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
122
10
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("4 12"); // 16 } else if (InputPattern == "Input2") { WillReturn.Add("8 20"); // 12 } else if (InputPattern == "Input3") { WillReturn.Add("1 1"); // 2 } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray(); int A = wkArr[0]; int B = wkArr[1]; if (B % A == 0) { Console.WriteLine(A + B); } else { Console.WriteLine(B - A); } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("4 12"); // 16 } else if (InputPattern == "Input2") { WillReturn.Add("8 20"); // 12 } else if (InputPattern == "Input3") { WillReturn.Add("1 1"); // 2 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray(); int A = wkArr[0]; int B = wkArr[1]; if (B % A == 0) { Console.WriteLine(A + B); } else { Console.WriteLine(B - A); } } }
[["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 95], ["+", 0, 57, 75, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 75, 57, 75, 57, 75, 196, 0, 197, 0, 35], ["+", 75, 57, 75, 57, 75, 196, 0, 52, 0, 89], ["+", 75, 57, 75, 57, 75, 196, 0, 52, 0, 24], ["+", 75, 196, 0, 52, 15, 16, 31, 23, 0, 24], ["+", 0, 52, 15, 16, 31, 23, 0, 11, 31, 22], ["+", 15, 16, 31, 23, 0, 11, 0, 202, 0, 32], ["+", 31, 23, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 31, 23, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 31, 23, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 31, 23, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 31, 23, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 75, 196, 0, 52, 15, 16, 31, 23, 0, 25], ["+", 75, 57, 75, 196, 0, 52, 15, 16, 17, 79], ["+", 75, 57, 75, 196, 0, 52, 15, 16, 12, 215], ["+", 75, 57, 75, 57, 75, 196, 0, 52, 0, 25], ["+", 0, 52, 8, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 52, 8, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 52, 8, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 52, 8, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 52, 8, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 57, 75, 196, 0, 52, 8, 1, 0, 35], ["+", 0, 57, 75, 57, 75, 57, 75, 196, 0, 46]]
8
210
27
using System; using System.Linq; class Procon { public Procon() {} static void Main(string[] agrs) { new Procon().Do(); } Scanner cin; public void Do() { cin = new Scanner(); int N = cin.nextInt(); int M = cin.nextInt(); int[] ret = new int[M]; for (int i = 0; i < M; i++) { ret[i] = 0; } for (int i = 0; i < N; i++) { int[] line = cin.arrayInt(); for (int k = 0; k < line[0]; k++) { ret[line[k]]++; } } int count = 0; for (int i = 0; i < M; i++) { if (ret[i] == N) { count++; } } Console.WriteLine(count); } } class Scanner { string[] s; int i; int max_i; public Scanner() { s = new string[0]; max_i = 0; i = 0; } public string nextString() { if (i >= s.Length) { s = Console.ReadLine().Split(' '); max_i = s.Length; i = 0; if (max_i == 0) { return ""; } return s[i++]; } else { return s[i++]; } } public int nextInt() { return int.Parse(nextString()); } public long nextLong() { return long.Parse(nextString()); } public double nextDouble() { return double.Parse(nextString()); } public string[] arrayString() { return Console.ReadLine().Split(' '); } public int[] arrayInt() { string[] str = Console.ReadLine().Split(' '); int[] array = new int[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = int.Parse(str[i]); } return array; } public long[] arrayLong() { string[] str = Console.ReadLine().Split(' '); long[] array = new long[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = long.Parse(str[i]); } return array; } public double[] arrayDouble() { string[] str = Console.ReadLine().Split(' '); double[] array = new double[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = double.Parse(str[i]); } return array; } }
using System; using System.Linq; class Procon { public Procon() {} static void Main(string[] agrs) { new Procon().Do(); } Scanner cin; public void Do() { cin = new Scanner(); int N = cin.nextInt(); int M = cin.nextInt(); int[] ret = new int[M]; for (int i = 0; i < M; i++) { ret[i] = 0; } for (int i = 0; i < N; i++) { int k = cin.nextInt(); for (int j = 0; j < k; j++) { int a = cin.nextInt(); ret[a - 1]++; } } int count = 0; for (int i = 0; i < M; i++) { if (ret[i] == N) { count++; } } Console.WriteLine(count); } } class Scanner { string[] s; int i; int max_i; public Scanner() { s = new string[0]; max_i = 0; i = 0; } public string nextString() { if (i >= s.Length) { s = Console.ReadLine().Split(' '); max_i = s.Length; i = 0; if (max_i == 0) { return ""; } return s[i++]; } else { return s[i++]; } } public int nextInt() { return int.Parse(nextString()); } public long nextLong() { return long.Parse(nextString()); } public double nextDouble() { return double.Parse(nextString()); } public string[] arrayString() { return Console.ReadLine().Split(' '); } public int[] arrayInt() { string[] str = Console.ReadLine().Split(' '); int[] array = new int[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = int.Parse(str[i]); } return array; } public long[] arrayLong() { string[] str = Console.ReadLine().Split(' '); long[] array = new long[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = long.Parse(str[i]); } return array; } public double[] arrayDouble() { string[] str = Console.ReadLine().Split(' '); double[] array = new double[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = double.Parse(str[i]); } return array; } }
[["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 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], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
614
33
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { string[] tmp = Console.ReadLine().Split(' '); int n = int.Parse(tmp[0]); int m = int.Parse(tmp[1]); bool[] data = new bool[m]; for (int i = 0; i < m; i++) { data[i] = true; } for (int i = 0; i < n; i++) { string[] tmp2 = Console.ReadLine().Split(' '); int k = int.Parse(tmp2[0]); for (int j = 0; j < k; j++) { data[int.Parse(tmp2[j + 1]) - 1] = false; } } Console.WriteLine(data.Count(b => b)); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { string[] tmp = Console.ReadLine().Split(' '); int n = int.Parse(tmp[0]); int m = int.Parse(tmp[1]); int[] data = new int[m]; for (int i = 0; i < m; i++) { data[i] = 0; } for (int i = 0; i < n; i++) { string[] tmp2 = Console.ReadLine().Split(' '); int k = int.Parse(tmp2[0]); for (int j = 0; j < k; j++) { data[int.Parse(tmp2[j + 1]) - 1]++; } } Console.WriteLine(data.Count(b => b == n)); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 22]]
8
204
11
using System; using System.Collections.Generic; public class S { public static void Main() { var input = Array.ConvertAll(Console.ReadLine().Split('/'), int.Parse); if (input[0] == 2019) { if (input[1] <= 4) { Console.WriteLine("Heisei"); } } else { if (input[0] < 2019) { Console.WriteLine("Heisei"); } else { Console.WriteLine("TBD"); } } } }
using System; using System.Collections.Generic; public class S { public static void Main() { var input = Array.ConvertAll(Console.ReadLine().Split('/'), int.Parse); if (input[0] == 2019) { if (input[1] <= 4) { Console.WriteLine("Heisei"); } else { Console.WriteLine("TBD"); } } else { if (input[0] < 2019) { Console.WriteLine("Heisei"); } else { Console.WriteLine("TBD"); } } } }
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
8
114
12
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { public static void Main(string[] args) { string[] S = Console.ReadLine().Split('/'); int year = int.Parse(S[0]); int month = int.Parse(S[1]); int day = int.Parse(S[2]); Console.WriteLine("{0} {1} {2}", year, month, day); if (year < 2019) { Console.WriteLine("Heisei"); } else if (year == 2019 && month < 4) { Console.WriteLine("Heisei"); } else if (year == 2019 && month == 4 && day < 31) { Console.WriteLine("Heisei"); } else { Console.WriteLine("TBD"); } } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { public static void Main(string[] args) { string[] S = Console.ReadLine().Split('/'); int year = int.Parse(S[0]); int month = int.Parse(S[1]); int day = int.Parse(S[2]); if (year < 2019) { Console.WriteLine("Heisei"); } else if (year == 2019 && month < 4) { Console.WriteLine("Heisei"); } else if (year == 2019 && month == 4 && day < 31) { Console.WriteLine("Heisei"); } else { Console.WriteLine("TBD"); } } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
184
15
using System; using System.Collections.Generic; using System.Linq; class Program { static string ans = "Heisei"; static int Main() { string[] nyu = Console.ReadLine().Split('/'); int y = int.Parse(nyu[0]); int m = int.Parse(nyu[1]); int d = int.Parse(nyu[1]); // ここまで入力 if (y > 2019) { if (m > 4) { ans = "TBD"; } } Console.WriteLine("{0}", ans); return 0; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static string ans = "Heisei"; static int Main() { string[] nyu = Console.ReadLine().Split('/'); int y = int.Parse(nyu[0]); int m = int.Parse(nyu[1]); int d = int.Parse(nyu[1]); // ここまで入力 if (y > 2019) { ans = "TBD"; } else { if (m > 4) { ans = "TBD"; } } Console.WriteLine("{0}", ans); return 0; } }
[["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 62], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45]]
8
128
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CompCsharp { class Program { private const double BTCJPY = 380000.0; static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List<double> ret = new List<double>(); for (int i = 0; i < n; i++) { string[] s = Console.ReadLine().Split(' '); double x = int.Parse(s[0]); if (s[1] == "BTC") { x *= BTCJPY; } ret.Add(x); } Console.WriteLine(ret.Sum()); } } }
using System; using System.Collections.Generic; using System.Linq; namespace CompCsharp { class Program { private const double BTCJPY = 380000.0; static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List<double> ret = new List<double>(); for (int i = 0; i < n; i++) { string[] s = Console.ReadLine().Split(' '); double x = double.Parse(s[0]); if (s[1] == "BTC") { x *= BTCJPY; } ret.Add(x); } Console.WriteLine(ret.Sum()); } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
163
14
using System; using System.Collections.Generic; using static AtCoderer.Exter; using static System.Math; using System.Linq; namespace AtCoderer { public class App { public static void Solve() { int n, a, b, c; ParseArray(out n, out a, out b, out c); int[] l = new int[n]; for (int i = 0; i < n; i++) l[i] = Parse(); var en = new EnumAll(4, n); int mincost = -1; while (en.Next()) { int Cost = -30; int[] bamboo = new int[3]; for (int i = 0; i < n; i++) { if (3 != en.Current[i]) { Cost += 10; bamboo[en.Current[i]] += l[i]; } } Cost += Abs(a - bamboo[0]); Cost += Abs(b - bamboo[1]); Cost += Abs(c - bamboo[2]); if (mincost > Cost || mincost == -1) mincost = Cost; } Console.WriteLine(mincost); } public static void Main(string[] args) { Solve(); Console.ReadKey(); } } public static class Exter { public class Point { public int a; public int b; public Point(int x, int y) { a = x; b = y; } } public static int[] OrderBy(this int[] IArr) { int[] arr = new int[IArr.Length]; Array.Copy(IArr, arr, IArr.Length); Array.Sort(arr); return arr; } public static long nCm(long n, long m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m % 1000000007; } public static int Max(params int[] p) => p.Max(); public static long Max(params long[] p) => p.Max(); public static int Min(params int[] p) => p.Min(); public static long Min(params long[] p) => p.Min(); public static IEnumerable<int> Factor(int n) { int i = 2; int tmp = n; while (i * i <= n) { if (tmp % i == 0) { tmp /= i; yield return i; } else { i++; } } if (tmp != 1) yield return tmp; } public static int Parse() { return int.Parse(Console.ReadLine()); } public static int[] ParseArray(this string s) { return s.Split().Select(v => int.Parse(v)).ToArray(); } public static int[] ParseArray(this string[] s) { return s.Select(v => int.Parse(v)).ToArray(); } public static long[] ParseArrayL(this string s) { return s.Split().Select(v => long.Parse(v)).ToArray(); } public static void ParseArray(out int a, out int b) { var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); a = r[0]; b = r[1]; } public static void ParseArray(out int a, out int b, out int c) { var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; } public static void ParseArray(out int a, out int b, out int c, out int d) { var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; d = r[3]; } public static void ParseArray(out long a, out long b) { var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); a = r[0]; b = r[1]; } public static void ParseArray(out long a, out long b, out long c) { var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; } public static void ParseArray(out long a, out long b, out long c, out long d) { var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; d = r[3]; } public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static int GcdRecursive(int x, int y) => y == 0 ? x : GcdRecursive(y, x % y); public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static long GcdRecursive(long x, long y) => y == 0 ? x : GcdRecursive(y, x % y); public static string ToString(this IEnumerable<char> v) { return string.Join("", v); } public static string Join<T>(this IEnumerable<T> v, char c) { return string.Join(c.ToString(), v); } public static string Join<T>(this IEnumerable<T> v, string s) { return string.Join(s, v); } public static int[] ReadArr { get { return Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); } } public class EnumAll { bool Over = false; int UpperValue; int Dimension; public int[] Current { private set; get; } public EnumAll(int Value, int Dimension) { this.Dimension = Dimension; UpperValue = Value; Current = new int[Dimension]; Current[0] = -1; } public bool Next() { if (Over) return false; bool flag = false; for (int i = 0; i < Dimension; i++) { if (++Current[i] >= UpperValue) Current[i] = 0; else { flag = true; break; } } if (!flag) { Over = true; return false; } return true; } public bool IsOver() { return Over; } } public class UnionFind { private int[] Parent; private int GetRoot(int v) { if (Parent[v] < 0) return v; else return Parent[v] = GetRoot(Parent[v]); } public UnionFind(int size) { Parent = new int[size]; for (int i = 0; i < size; i++) Parent[i] = -1; } public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); } public void Connect(int a, int b) { a = GetRoot(a); b = GetRoot(b); if (a == b) return; if (Parent[b] < Parent[a]) { Parent[b] += Parent[a]; Parent[a] = b; } else { Parent[a] += Parent[b]; Parent[b] = a; } } public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; } } } }
using System; using System.Collections.Generic; using static AtCoderer.Exter; using static System.Math; using System.Linq; namespace AtCoderer { public class App { public static void Solve() { int n, a, b, c; ParseArray(out n, out a, out b, out c); int[] l = new int[n]; for (int i = 0; i < n; i++) l[i] = Parse(); var en = new EnumAll(4, n); int mincost = -1; while (en.Next()) { int Cost = -30; int[] bamboo = new int[3]; for (int i = 0; i < n; i++) { if (3 != en.Current[i]) { Cost += 10; bamboo[en.Current[i]] += l[i]; } } if (bamboo[0] == 0 || bamboo[1] == 0 || bamboo[2] == 0) continue; Cost += Abs(a - bamboo[0]); Cost += Abs(b - bamboo[1]); Cost += Abs(c - bamboo[2]); if (mincost > Cost || mincost == -1) mincost = Cost; } Console.WriteLine(mincost); } public static void Main(string[] args) { Solve(); Console.ReadKey(); } } public static class Exter { public class Point { public int a; public int b; public Point(int x, int y) { a = x; b = y; } } public static int[] OrderBy(this int[] IArr) { int[] arr = new int[IArr.Length]; Array.Copy(IArr, arr, IArr.Length); Array.Sort(arr); return arr; } public static long nCm(long n, long m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m % 1000000007; } public static int Max(params int[] p) => p.Max(); public static long Max(params long[] p) => p.Max(); public static int Min(params int[] p) => p.Min(); public static long Min(params long[] p) => p.Min(); public static IEnumerable<int> Factor(int n) { int i = 2; int tmp = n; while (i * i <= n) { if (tmp % i == 0) { tmp /= i; yield return i; } else { i++; } } if (tmp != 1) yield return tmp; } public static int Parse() { return int.Parse(Console.ReadLine()); } public static int[] ParseArray(this string s) { return s.Split().Select(v => int.Parse(v)).ToArray(); } public static int[] ParseArray(this string[] s) { return s.Select(v => int.Parse(v)).ToArray(); } public static long[] ParseArrayL(this string s) { return s.Split().Select(v => long.Parse(v)).ToArray(); } public static void ParseArray(out int a, out int b) { var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); a = r[0]; b = r[1]; } public static void ParseArray(out int a, out int b, out int c) { var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; } public static void ParseArray(out int a, out int b, out int c, out int d) { var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; d = r[3]; } public static void ParseArray(out long a, out long b) { var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); a = r[0]; b = r[1]; } public static void ParseArray(out long a, out long b, out long c) { var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; } public static void ParseArray(out long a, out long b, out long c, out long d) { var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; d = r[3]; } public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static int GcdRecursive(int x, int y) => y == 0 ? x : GcdRecursive(y, x % y); public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static long GcdRecursive(long x, long y) => y == 0 ? x : GcdRecursive(y, x % y); public static string ToString(this IEnumerable<char> v) { return string.Join("", v); } public static string Join<T>(this IEnumerable<T> v, char c) { return string.Join(c.ToString(), v); } public static string Join<T>(this IEnumerable<T> v, string s) { return string.Join(s, v); } public static int[] ReadArr { get { return Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); } } public class EnumAll { bool Over = false; int UpperValue; int Dimension; public int[] Current { private set; get; } public EnumAll(int Value, int Dimension) { this.Dimension = Dimension; UpperValue = Value; Current = new int[Dimension]; Current[0] = -1; } public bool Next() { if (Over) return false; bool flag = false; for (int i = 0; i < Dimension; i++) { if (++Current[i] >= UpperValue) Current[i] = 0; else { flag = true; break; } } if (!flag) { Over = true; return false; } return true; } public bool IsOver() { return Over; } } public class UnionFind { private int[] Parent; private int GetRoot(int v) { if (Parent[v] < 0) return v; else return Parent[v] = GetRoot(Parent[v]); } public UnionFind(int size) { Parent = new int[size]; for (int i = 0; i < size; i++) Parent[i] = -1; } public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); } public void Connect(int a, int b) { a = GetRoot(a); b = GetRoot(b); if (a == b) return; if (Parent[b] < Parent[a]) { Parent[b] += Parent[a]; Parent[a] = b; } else { Parent[a] += Parent[b]; Parent[b] = a; } } public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; } } } }
[["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["+", 15, 16, 31, 16, 31, 16, 31, 204, 205, 22], ["+", 31, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 15, 16, 31, 16, 12, 16, 31, 204, 205, 22], ["+", 31, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["+", 0, 52, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 52, 8, 196, 0, 57, 64, 116, 0, 35]]
8
1,697
25
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static int N; static int A; static int B; static int C; static int[] l; static int DFS(int depth, int a, int b, int c) { if (depth == N) { return Math.Abs(A - a) + Math.Abs(B - b) + Math.Abs(C - c) - 30; } int ret = INF; ret = Math.Min(ret, DFS(depth + 1, a + l[depth], b, c) + 10); ret = Math.Min(ret, DFS(depth + 1, a, b + l[depth], c) + 10); ret = Math.Min(ret, DFS(depth + 1, a, b, c + l[depth]) + 10); ret = Math.Min(ret, DFS(depth + 1, a, b, c)); return ret; } static void Solve() { Scan sc = new Scan(); write wr = new write(); var ss = sc.intarr; N = ss[0]; A = ss[1]; B = ss[2]; C = ss[3]; l = new int[N]; for (int i = 0; i < N; ++i) l[i] = sc.intarr[0]; wr.wri(DFS(0, 0, 0, 0)); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static int N; static int A; static int B; static int C; static int[] l; static int DFS(int depth, int a, int b, int c) { if (depth == N) { if (a == 0 || b == 0 || c == 0) return INF; return Math.Abs(A - a) + Math.Abs(B - b) + Math.Abs(C - c) - 30; } int ret = INF; ret = Math.Min(ret, DFS(depth + 1, a + l[depth], b, c) + 10); ret = Math.Min(ret, DFS(depth + 1, a, b + l[depth], c) + 10); ret = Math.Min(ret, DFS(depth + 1, a, b, c + l[depth]) + 10); ret = Math.Min(ret, DFS(depth + 1, a, b, c)); return ret; } static void Solve() { Scan sc = new Scan(); write wr = new write(); var ss = sc.intarr; N = ss[0]; A = ss[1]; B = ss[2]; C = ss[3]; l = new int[N]; for (int i = 0; i < N; ++i) l[i] = sc.intarr[0]; wr.wri(DFS(0, 0, 0, 0)); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } }
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 106], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 37, 0, 22], ["+", 0, 57, 64, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
8
465
17
using System; class Data { public int count, sum, n; public Data(int count, int sum, int n) { this.count = count; this.sum = sum; this.n = n; } } class Program { static void Main(string[] args) { var nabc = Console.ReadLine().Split(' '); var n = int.Parse(nabc[0]); var a = int.Parse(nabc[1]); var b = int.Parse(nabc[2]); var c = int.Parse(nabc[3]); var d = new int[n]; for (int i = 0; i < n; i++) { d[i] = int.Parse(Console.ReadLine()); } var datas = new Data[] { new Data(0, 0, 0), new Data(0, 0, a), new Data(0, 0, b), new Data(0, 0, c), }; var ans = m1(d, 0, datas); Console.WriteLine(ans); } static int m1(int[] d, int n, Data[] datas) { if (d.Length <= n) { var sum = 0; for (int i = 1; i < datas.Length; i++) { sum += (datas[i].count - 1) * 10 + Math.Abs(datas[i].sum - datas[i].n); } return sum; } var min = int.MaxValue; for (int i = 0; i < datas.Length; i++) { datas[i].count++; datas[i].sum += d[n]; min = Math.Min(min, m1(d, n + 1, datas)); datas[i].count--; datas[i].sum -= d[n]; } return min; } }
using System; class Data { public int count, sum, n; public Data(int count, int sum, int n) { this.count = count; this.sum = sum; this.n = n; } } class Program { static void Main(string[] args) { var nabc = Console.ReadLine().Split(' '); var n = int.Parse(nabc[0]); var a = int.Parse(nabc[1]); var b = int.Parse(nabc[2]); var c = int.Parse(nabc[3]); var d = new int[n]; for (int i = 0; i < n; i++) { d[i] = int.Parse(Console.ReadLine()); } var datas = new Data[] { new Data(0, 0, 0), new Data(0, 0, a), new Data(0, 0, b), new Data(0, 0, c), }; var ans = m1(d, 0, datas); Console.WriteLine(ans); } static int m1(int[] d, int n, Data[] datas) { if (d.Length <= n) { var sum = 0; for (int i = 1; i < datas.Length; i++) { if (datas[i].count == 0) { return int.MaxValue; } sum += (datas[i].count - 1) * 10 + Math.Abs(datas[i].sum - datas[i].n); } return sum; } var min = int.MaxValue; for (int i = 0; i < datas.Length; i++) { datas[i].count++; datas[i].sum += d[n]; min = Math.Min(min, m1(d, n + 1, datas)); datas[i].count--; datas[i].sum -= d[n]; } return min; } }
[["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 214, 205, 204, 205, 22], ["+", 15, 16, 31, 214, 205, 204, 206, 207, 0, 70], ["+", 31, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 214, 205, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 37, 0, 214, 205, 199], ["+", 0, 57, 64, 196, 0, 37, 0, 214, 0, 131], ["+", 0, 57, 64, 196, 0, 37, 0, 214, 141, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
417
18
using System; using System.Linq; using System.Collections.Generic; using E = System.Linq.Enumerable; public class Program { public static void Main() { var nabc = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var n = nabc[0]; var a = nabc[1]; var b = nabc[2]; var c = nabc[3]; var ls = new int[n]; for (int i = 0; i < ls.Length; i++) { ls[i] = int.Parse(Console.ReadLine()); } var abc = nabc.Skip(1).ToArray(); var min = Dfs(ls, 0, abc, new int[abc.Length], abc.Sum()); Console.WriteLine(min); } static int Dfs(int[] ls, int i, int[] bs, int[] ks, int mp) { if (i >= ls.Length) { return ks.Any(x => x == 0) ? int.MaxValue : mp; } var min = Dfs(ls, i + 1, bs, ks, mp); for (int j = 0; j < bs.Length; j++) { if (bs[j] <= 10 && ls[i] > 10) { continue; } var d = 0 <= bs[j] && bs[j] < ls[i] ? bs[j] + bs[j] - ls[i] : ls[i] <= bs[j] ? ls[i] : -ls[i]; if (ks[j] > 0) { mp += 10; } ks[j]++; mp -= d; bs[j] -= ls[i]; min = Math.Min(min, Dfs(ls, i + 1, bs, ks, mp)); bs[j] += ls[i]; mp += d; ks[j]--; if (ks[j] > 0) { mp -= 10; } } return min; } }
using System; using System.Linq; using System.Collections.Generic; using E = System.Linq.Enumerable; public class Program { public static void Main() { var nabc = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var n = nabc[0]; var a = nabc[1]; var b = nabc[2]; var c = nabc[3]; var ls = new int[n]; for (int i = 0; i < ls.Length; i++) { ls[i] = int.Parse(Console.ReadLine()); } var abc = nabc.Skip(1).ToArray(); var min = Dfs(ls, 0, abc, new int[abc.Length], abc.Sum()); Console.WriteLine(min); } static int Dfs(int[] ls, int i, int[] bs, int[] ks, int mp) { if (i >= ls.Length) { return ks.Any(x => x == 0) ? int.MaxValue : mp; } var min = Dfs(ls, i + 1, bs, ks, mp); for (int j = 0; j < bs.Length; j++) { var d = 0 <= bs[j] && bs[j] < ls[i] ? bs[j] + bs[j] - ls[i] : ls[i] <= bs[j] ? ls[i] : -ls[i]; if (ks[j] > 0) { mp += 10; } ks[j]++; mp -= d; bs[j] -= ls[i]; min = Math.Min(min, Dfs(ls, i + 1, bs, ks, mp)); bs[j] += ls[i]; mp += d; ks[j]--; if (ks[j] > 0) { mp -= 10; } } return min; } }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
452
20
using System; using System.Linq; namespace ABC119_C { class Program { static int A, B, C, N; static int[] l; static void Main(string[] args) { var NABC = Console.ReadLine().Split().Select(int.Parse).ToArray(); N = NABC[0]; A = NABC[1]; B = NABC[2]; C = NABC[3]; l = new int[N]; for (int i = 0; i < N; i++) { l[i] = int.Parse(Console.ReadLine()); } Console.WriteLine(Calc(0, 0, 0, 0)); } static int Calc(int cnt, int a, int b, int c) { if (cnt == N) return a + b + c == 0 ? int.MaxValue : Math.Abs(A - a) + Math.Abs(B - b) + Math.Abs(C - c) - 30; var pattern = new int[4]; pattern[0] = Calc(cnt + 1, a, b, c); pattern[2] = Calc(cnt + 1, a + l[cnt], b, c) + 10; pattern[1] = Calc(cnt + 1, a, b + l[cnt], c) + 10; pattern[3] = Calc(cnt + 1, a, b, c + l[cnt]) + 10; return pattern.Min(); } } }
using System; using System.Linq; namespace ABC119_C { class Program { static int A, B, C, N; static int[] l; static void Main(string[] args) { var NABC = Console.ReadLine().Split().Select(int.Parse).ToArray(); N = NABC[0]; A = NABC[1]; B = NABC[2]; C = NABC[3]; l = new int[N]; for (int i = 0; i < N; i++) { l[i] = int.Parse(Console.ReadLine()); } Console.WriteLine(Calc(0, 0, 0, 0)); } static int Calc(int cnt, int a, int b, int c) { if (cnt == N) return a == 0 || b == 0 || c == 0 ? 100000 : Math.Abs(A - a) + Math.Abs(B - b) + Math.Abs(C - c) - 30; var pattern = new int[4]; pattern[0] = Calc(cnt + 1, a, b, c); pattern[1] = Calc(cnt + 1, a + l[cnt], b, c) + 10; pattern[2] = Calc(cnt + 1, a, b + l[cnt], c) + 10; pattern[3] = Calc(cnt + 1, a, b, c + l[cnt]) + 10; return pattern.Min(); } } }
[["-", 0, 41, 15, 16, 31, 16, 31, 16, 17, 72], ["+", 0, 41, 15, 16, 31, 16, 31, 16, 17, 60], ["+", 0, 41, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 64, 37, 0, 41, 15, 16, 31, 16, 17, 106], ["-", 64, 37, 0, 41, 15, 16, 31, 16, 17, 72], ["+", 0, 41, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 41, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 37, 0, 41, 15, 16, 17, 106], ["-", 0, 57, 64, 37, 0, 41, 64, 214, 205, 199], ["-", 0, 57, 64, 37, 0, 41, 64, 214, 0, 131], ["-", 0, 57, 64, 37, 0, 41, 64, 214, 141, 22], ["+", 8, 196, 0, 57, 64, 37, 0, 41, 64, 203], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203]]
8
326
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; using ll = System.Int64; public class Contest { static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) Swap1(ref a, ref b); } // b の方が小さければ交換 static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } // b の方が大きければ a を更新 static T[][] InitMat<T>(long len1, long len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; } static T[][][] InitMat<T>(long len1, long len2, long len3, T val) { T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2, len3, val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public static void Main() { Solve_D(); } public static void Solve_A() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_B() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_C() { long n, a, b, c; MyIO.ReadMulti(out n, out a, out b, out c); ll[] l; MyIO.ReadLines(n, out l); long ans = int.MaxValue; for (int i = 0; i < 1 << (2 * (int)n); i++) { ll la = 0; ll ma = 0; ll lb = 0; ll mb = 0; ll lc = 0; ll mc = 0; for (int j = 0; j < n; j++) { int v = (i >> (2 * j)) & 3; if (v == 1) { if (la != 0) ma += 10; la += l[j]; } if (v == 2) { if (lb != 0) mb += 10; lb += l[j]; } if (v == 3) { if (lc != 0) mc += 10; lc += l[j]; } } if (la == 0 || lb == 0 || lc == 0) continue; ma += Math.Abs(a - la); mb += Math.Abs(b - lb); mc += Math.Abs(c - lc); Chmin(ref ans, ma + mb + mc); } MyIO.WriteMulti(ans); } public static void Solve_D() { long a, b, q; MyIO.ReadMulti(out a, out b, out q); ll[] s, t, x; MyIO.ReadLines(a, out s); MyIO.ReadLines(b, out t); MyIO.ReadLines(q, out x); VT<ll, ll>[] al = new VT<ll, ll>[a + b + q]; int id = 0; foreach (var i in x) { al[id] = new VT<ll, ll>(i, id); id++; } foreach (var i in s) { al[id++] = new VT<ll, ll>(i, -1); } foreach (var i in t) { al[id++] = new VT<ll, ll>(i, -2); } Array.Sort(al, (y, z) => (int)(y.Item1 - z.Item1)); VT<ll, ll, ll, ll>[] xl = new VT<ll, ll, ll, ll>[q]; int[] li = new int[q]; ll sd = -100000000000; ll td = -100000000000; ll xi = 0; foreach (var e in al) { if (0 <= e.Item2) xl[xi++] = new VT<ll, ll, ll, ll>(e.Item1 - sd, e.Item1 - td, -2, -2); if (e.Item2 == -1) sd = e.Item1; if (e.Item2 == -2) td = e.Item1; } Array.Reverse(al); sd = 100000000000; td = 100000000000; xi = q - 1; foreach (var e in al) { if (0 <= e.Item2) { xl[xi].Item3 = sd - e.Item1; xl[xi].Item4 = td - e.Item1; li[xi] = (int)e.Item2; xi--; } if (e.Item2 == -1) sd = e.Item1; if (e.Item2 == -2) td = e.Item1; } ll[] ans = new ll[q]; for (int i = 0; i < q; i++) { ll di = 100000000000; Chmin(ref di, Math.Max(xl[i].Item1, xl[i].Item2)); Chmin(ref di, Math.Max(xl[i].Item3, xl[i].Item4)); Chmin(ref di, 2 * xl[i].Item1 + xl[i].Item4); Chmin(ref di, xl[i].Item1 + 2 * xl[i].Item4); Chmin(ref di, 2 * xl[i].Item2 + xl[i].Item3); Chmin(ref di, xl[i].Item2 + 2 * xl[i].Item3); ans[li[i]] = di; } MyIO.WriteLines(ans); } public static void Solve_E() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_F() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } } #region MyIO public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(long n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(long n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; using ll = System.Int64; public class Contest { static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) Swap1(ref a, ref b); } // b の方が小さければ交換 static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } // b の方が大きければ a を更新 static T[][] InitMat<T>(long len1, long len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; } static T[][][] InitMat<T>(long len1, long len2, long len3, T val) { T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2, len3, val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public static void Main() { Solve_D(); } public static void Solve_A() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_B() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_C() { long n, a, b, c; MyIO.ReadMulti(out n, out a, out b, out c); ll[] l; MyIO.ReadLines(n, out l); long ans = int.MaxValue; for (int i = 0; i < 1 << (2 * (int)n); i++) { ll la = 0; ll ma = 0; ll lb = 0; ll mb = 0; ll lc = 0; ll mc = 0; for (int j = 0; j < n; j++) { int v = (i >> (2 * j)) & 3; if (v == 1) { if (la != 0) ma += 10; la += l[j]; } if (v == 2) { if (lb != 0) mb += 10; lb += l[j]; } if (v == 3) { if (lc != 0) mc += 10; lc += l[j]; } } if (la == 0 || lb == 0 || lc == 0) continue; ma += Math.Abs(a - la); mb += Math.Abs(b - lb); mc += Math.Abs(c - lc); Chmin(ref ans, ma + mb + mc); } MyIO.WriteMulti(ans); } public static void Solve_D() { long a, b, q; MyIO.ReadMulti(out a, out b, out q); ll[] s, t, x; MyIO.ReadLines(a, out s); MyIO.ReadLines(b, out t); MyIO.ReadLines(q, out x); VT<ll, ll>[] al = new VT<ll, ll>[a + b + q]; int id = 0; foreach (var i in x) { al[id] = new VT<ll, ll>(i, id); id++; } foreach (var i in s) { al[id++] = new VT<ll, ll>(i, -1); } foreach (var i in t) { al[id++] = new VT<ll, ll>(i, -2); } Array.Sort(al, (y, z) => y.Item1.CompareTo(z.Item1)); VT<ll, ll, ll, ll>[] xl = new VT<ll, ll, ll, ll>[q]; int[] li = new int[q]; ll sd = -100000000000; ll td = -100000000000; ll xi = 0; foreach (var e in al) { if (0 <= e.Item2) xl[xi++] = new VT<ll, ll, ll, ll>(e.Item1 - sd, e.Item1 - td, -2, -2); if (e.Item2 == -1) sd = e.Item1; if (e.Item2 == -2) td = e.Item1; } Array.Reverse(al); sd = 100000000000; td = 100000000000; xi = q - 1; foreach (var e in al) { if (0 <= e.Item2) { xl[xi].Item3 = sd - e.Item1; xl[xi].Item4 = td - e.Item1; li[xi] = (int)e.Item2; xi--; } if (e.Item2 == -1) sd = e.Item1; if (e.Item2 == -2) td = e.Item1; } ll[] ans = new ll[q]; for (int i = 0; i < q; i++) { ll di = 100000000000; Chmin(ref di, Math.Max(xl[i].Item1, xl[i].Item2)); Chmin(ref di, Math.Max(xl[i].Item3, xl[i].Item4)); Chmin(ref di, 2 * xl[i].Item1 + xl[i].Item4); Chmin(ref di, xl[i].Item1 + 2 * xl[i].Item4); Chmin(ref di, 2 * xl[i].Item2 + xl[i].Item3); Chmin(ref di, xl[i].Item2 + 2 * xl[i].Item3); ans[li[i]] = di; } MyIO.WriteLines(ans); } public static void Solve_E() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_F() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } } #region MyIO public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(long n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(long n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } } #endregion
[["-", 3, 4, 0, 28, 0, 218, 8, 74, 0, 24], ["-", 3, 4, 0, 28, 0, 218, 8, 74, 39, 199], ["-", 3, 4, 0, 28, 0, 218, 8, 74, 0, 25], ["-", 0, 28, 0, 218, 8, 74, 51, 23, 0, 24], ["-", 0, 218, 8, 74, 51, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 24]]
8
3,235
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_D { class D119 { static void Main(string[] args) { int[] p = Console.ReadLine().Split(' ').Select(xx => int.Parse(xx)).ToArray(); int A = p[0], B = p[1], C = p[2]; long[] s = new long[A]; for (int i = 0; i < A; i++) { s[i] = long.Parse(Console.ReadLine()); } long[] t = new long[B]; for (int i = 0; i < B; i++) { t[i] = long.Parse(Console.ReadLine()); } long[] x = new long[C]; for (int i = 0; i < C; i++) { x[i] = long.Parse(Console.ReadLine()); } for (int i = 0; i < C; i++) { int lbs = LowerBound(s, x[i]); if (lbs == A) lbs = lbs - 1; int lbt = LowerBound(t, x[i]); if (lbt == B) lbt = lbt - 1; long s1 = s[lbs]; long s2 = lbs == 0 ? s[lbs] : s[lbs - 1]; long t1 = t[lbt]; long t2 = lbt == 0 ? t[lbt] : t[lbt - 1]; long mx = long.MaxValue; long d = distance(s1, t1, x[i]); if (d < mx) mx = d; d = distance(s1, t2, x[i]); if (d < mx) mx = d; d = distance(s2, t1, x[i]); if (d < mx) mx = d; d = distance(s2, t2, x[i]); if (d < mx) mx = d; Console.WriteLine(mx); } } static long distance(long s, long t, long p) { long x = s - p, y = t - p; if (x * y >= 0) { return Math.Max(Math.Abs(x), Math.Abs(y)); } else { long w = Math.Min(Math.Abs(x), Math.Abs(y)); long r = Math.Max(Math.Abs(x), Math.Abs(y)); return r + 2 * w; } } /// <summary> /// 指定した値以上の先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_D { class D119 { static void Main(string[] args) { int[] p = Console.ReadLine().Split(' ').Select(xx => int.Parse(xx)).ToArray(); int A = p[0], B = p[1], C = p[2]; long[] s = new long[A]; for (int i = 0; i < A; i++) { s[i] = long.Parse(Console.ReadLine()); } long[] t = new long[B]; for (int i = 0; i < B; i++) { t[i] = long.Parse(Console.ReadLine()); } long[] x = new long[C]; for (int i = 0; i < C; i++) { x[i] = long.Parse(Console.ReadLine()); } for (int i = 0; i < C; i++) { int lbs = LowerBound(s, x[i]); if (lbs == A) lbs = lbs - 1; int lbt = LowerBound(t, x[i]); if (lbt == B) lbt = lbt - 1; long s1 = s[lbs]; long s2 = lbs == 0 ? s[lbs] : s[lbs - 1]; long t1 = t[lbt]; long t2 = lbt == 0 ? t[lbt] : t[lbt - 1]; long mx = long.MaxValue; long d = distance(s1, t1, x[i]); if (d < mx) mx = d; d = distance(s1, t2, x[i]); if (d < mx) mx = d; d = distance(s2, t1, x[i]); if (d < mx) mx = d; d = distance(s2, t2, x[i]); if (d < mx) mx = d; Console.WriteLine(mx); } } static long distance(long s, long t, long p) { long x = s - p, y = t - p; if (Math.Sign(x) == Math.Sign(y)) { return Math.Max(Math.Abs(x), Math.Abs(y)); } else { long w = Math.Min(Math.Abs(x), Math.Abs(y)); long r = Math.Max(Math.Abs(x), Math.Abs(y)); return r + 2 * w; } } /// <summary> /// 指定した値以上の先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } } }
[["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25]]
8
723
14
using System; using System.Linq; using System.Collections.Generic; public class Test { public static void Main() { var input = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray(); Console.WriteLine(Math.Max(input[1] / input[0], input[2])); } }
using System; using System.Linq; using System.Collections.Generic; public class Test { public static void Main() { var input = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray(); Console.WriteLine(Math.Min(input[1] / input[0], input[2])); Console.ReadKey(); } }
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
8
85
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class394 { static void Main() { var abk = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = abk[0], b = abk[1], k = abk[2]; int count = 0; for (int i = 1; i <= a; i++) { if (a % i == 0 && b % i == 0) count++; if (count == k) { Console.WriteLine(i); return; } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class394 { static void Main() { var abk = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = abk[0], b = abk[1], k = abk[2]; int count = 0; for (int i = Math.Min(a, b); i >= 1; i--) { if (a % i == 0 && b % i == 0) count++; if (count == k) { Console.WriteLine(i); return; } } } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
143
15
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; 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 k = int.Parse(input[2]); int cnt = 0; int r = a; if (a > b) { r = b; } while (cnt < k) { if (a % r == 0 && b % r == 0) { cnt++; } r--; } Console.WriteLine(r); } }
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; 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 k = int.Parse(input[2]); int cnt = 0; int r = a; if (a > b) { r = b; } while (cnt < k) { if (a % r == 0 && b % r == 0) { cnt++; if (cnt == k) { break; } } r--; } Console.WriteLine(r); } }
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46]]
8
163
10
using System; using System.Collections.Generic; using System.Linq; static class MainClass { public struct City { public long num; public City(long n) { num = n; } } public static void Main(string[] args) { var temp = Console.ReadLine().Split(' '); var A = int.Parse(temp.ElementAt(0)); var B = int.Parse(temp.ElementAt(1)); var K = int.Parse(temp.ElementAt(2)); var ans = 0; for (var i = 1; i <= A; i++) { ans += A % i == 0 && B % i == 0 ? 1 : 0; if (ans == K) break; } Console.WriteLine(ans); } public static long Euclidean(long a, long b) { if (a % b == 0) { return b; } return Euclidean(b, a % b); } }
using System; using System.Collections.Generic; using System.Linq; static class MainClass { public struct City { public long num; public City(long n) { num = n; } } public static void Main(string[] args) { var temp = Console.ReadLine().Split(' '); var A = int.Parse(temp.ElementAt(0)); var B = int.Parse(temp.ElementAt(1)); var K = int.Parse(temp.ElementAt(2)); var ans = 0; for (var i = Math.Min(A, B); i >= 1; i--) { ans += A % i == 0 && B % i == 0 ? 1 : 0; if (ans == K) { ans = i; break; } } Console.WriteLine(ans); } public static long Euclidean(long a, long b) { if (a % b == 0) { return b; } return Euclidean(b, a % b); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
204
21
using System; namespace ABC120B { class Program { static void Main(string[] args) { var s = Console.ReadLine().Split(' '); int A = int.Parse(s[0]); int B = int.Parse(s[1]); int K = int.Parse(s[2]); int count = 1; for (int i = 1; i <= 100; i++) { if (A % i != 0) { continue; } if (B % i != 0) { continue; } if (count != K) { count++; continue; } Console.WriteLine(i); return; } } } }
using System; namespace ABC120B { class Program { static void Main(string[] args) { var s = Console.ReadLine().Split(' '); int A = int.Parse(s[0]); int B = int.Parse(s[1]); int K = int.Parse(s[2]); int count = 1; for (int i = 100; i >= 1; i--) { if (A % i != 0) { continue; } if (B % i != 0) { continue; } if (count != K) { count++; continue; } Console.WriteLine(i); return; } } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
144
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp60 { class Program { static void Main(string[] args) { var st = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = st[0]; int B = st[1]; int K = st[2]; int max = Gcd(A, B); // Console.WriteLine(max); int cnt = 0; int ans = 0; for (int i = 1; i <= max; i++) { if (max % i == 0) { cnt++; } if (cnt == K) { ans = i; break; } } Console.WriteLine(ans); } static int Gcd(int a, int b) { if (a < b) { return Gcd(b, a); } while (b != 0) { int remain = a % b; a = b; b = remain; } return a; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp60 { class Program { static void Main(string[] args) { var st = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = st[0]; int B = st[1]; int K = st[2]; int max = Gcd(A, B); // Console.WriteLine(max); int cnt = 0; int ans = 0; for (int i = max; i >= 1; i--) { if (max % i == 0) { cnt++; } if (cnt == K) { ans = i; break; } } Console.WriteLine(ans); } static int Gcd(int a, int b) { if (a < b) { return Gcd(b, a); } while (b != 0) { int remain = a % b; a = b; b = remain; } return a; } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
219
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AIZUproject08 { // 128B /*class Data { public int ID { get; set; } public string Name { get; set; } public int Evaluation { get; set; } } class Program { static void Main() { List<Data> datalist = new List<Data>(); Data data; int N = int.Parse(Console.ReadLine()); for (int i=0;i< N;i++) { var temp = Console.ReadLine().Split(' '); data = new Data(); data.ID = i + 1; data.Name = temp[0]; data.Evaluation = int.Parse(temp[1]); datalist.Add(data); } datalist = datalist.OrderBy(n => n.Name).ThenByDescending(n => n.Evaluation).ToList(); foreach (var ans in datalist) { Console.WriteLine(ans.ID); } } }*/ // 127B /*class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int r = input[0]; int D = input[1]; int X = input[2]; for (int i=0;i<10;i++) { var ans = r * X - D; Console.WriteLine(ans); X = ans; } } }*/ // 126B /*class Program { static void Main() { List<int> mae = new List<int>(); List<int> ushiro = new List<int>(); string input = Console.ReadLine(); var rabel = "NA"; for (int i = 0; i < 2; i++) { char moji = input[i]; mae.Add(int.Parse(string.Join("",moji))); } for (int i = 2; i < 4; i++) { char moji = input[i]; ushiro.Add(int.Parse(string.Join("", moji))); } int A = 10 * mae[0] + 1 * mae[1]; int B = 10 * ushiro[0] + 1 * ushiro[1]; if (0 <= A && A <= 99 && 0 < B && B < 13) { rabel = "YYMM"; if (0 < A && A < 13 && 0 < B && B < 13) { rabel = "AMBIGUOUS"; } } else if (0 <= B && B <= 99 && 0 < A && A < 13) { rabel = "MMYY"; if (0 < A && A < 13 && 0 < B && B < 13) { rabel = "AMBIGUOUS"; } } Console.WriteLine(rabel); } }*/ // 125B /*class Program { static void Main() { int N = int.Parse(Console.ReadLine()); int[] V = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] C = Console.ReadLine().Split().Select(int.Parse).ToArray(); int Answer = 0; for (int i=0;i<N;i++) { var temp = V[i] - C[i]; if (temp > 0) { Answer += temp; } } Console.WriteLine(Answer); } }*/ // 124B // count変数の初期化忘れがち!! /*class Program { static void Main() { int Ans = 0; int count = 0; int N = int.Parse(Console.ReadLine()); int[] Height = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i =0;i<Height.Length;i++) { for (int j=0;j<i;j++) { if (Height[i] >= Height[j]) { Ans++; } } if (Ans == i) { count++; } Ans = 0; } Console.WriteLine(count); } }*/ // 123B /*class Program { static void Main() { List<int> time = new List<int>(); List<int> sample = new List<int>(); int[] aa = new int[5]; for (int i = 0;i<5;i++) { int dish = int.Parse(Console.ReadLine()); time.Add(dish); } time.CopyTo(aa); int ans = 0; foreach (int a in time) { var temp = a % 10; sample.Add(temp); } var jj = sample.IndexOf(sample.Min()); time.RemoveAt(jj); time.Add(aa[jj]); foreach (int n in time) { ans += n; if (ans % 10 != 0) { ans += 10 - (ans % 10); } } Console.WriteLine(ans); } }*/ // 122B /*class Program { static void Main() { int anscount = 0; List<int> Answer = new List<int>(); string S = Console.ReadLine(); char[] Cstr = new char[S.Length]; for (int i=0;i<S.Length;i++) { Cstr[i] = S[i]; } for (int i=0;i<Cstr.Length;i++) { var temp = i; while (true) { if (temp < Cstr.Length) { if (Cstr[temp] == 'A' || Cstr[temp] == 'C' || Cstr[temp] == 'G' || Cstr[temp] == 'T') { anscount++; temp++; } else { Answer.Add(anscount); anscount = 0; break; } } else { Answer.Add(anscount); anscount = 0; break; } } } Console.WriteLine(Answer.Max()); } }*/ // 122B /*class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int C = input[2]; int[] B = Console.ReadLine().Split().Select(int.Parse).ToArray(); List<int[]> AA = new List<int[]>(); for (int i =0;i< N;i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); AA.Add(a); } int Ans = 0; List<int> mans = new List<int>(); for (int i =0;i<N;i++) { for (int j=0;j<M;j++) { Ans += AA[i][j] * B[j]; } var ans =Ans + C; mans.Add(ans); Ans = 0; } int count = 0; foreach (int n in mans) { if (n > 0) { count++; } } Console.WriteLine(count); } }*/ // 120B class Program { static void Main() { List<int> Array1 = new List<int>(); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int B = input[1]; int K = input[2]; int index = 1; List<int> a = new List<int>(); a.Add(A); a.Add(B); var aa = a.Max(); while (true) { if (aa == index) { break; } if (A % index == 0 && B % index == 0) { Array1.Add(index); index++; } else { index++; } } //配列逆になってない Array1.Sort(); Array1.Reverse(); Console.WriteLine(Array1[K - 1]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AIZUproject08 { // 128B /*class Data { public int ID { get; set; } public string Name { get; set; } public int Evaluation { get; set; } } class Program { static void Main() { List<Data> datalist = new List<Data>(); Data data; int N = int.Parse(Console.ReadLine()); for (int i=0;i< N;i++) { var temp = Console.ReadLine().Split(' '); data = new Data(); data.ID = i + 1; data.Name = temp[0]; data.Evaluation = int.Parse(temp[1]); datalist.Add(data); } datalist = datalist.OrderBy(n => n.Name).ThenByDescending(n => n.Evaluation).ToList(); foreach (var ans in datalist) { Console.WriteLine(ans.ID); } } }*/ // 127B /*class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int r = input[0]; int D = input[1]; int X = input[2]; for (int i=0;i<10;i++) { var ans = r * X - D; Console.WriteLine(ans); X = ans; } } }*/ // 126B /*class Program { static void Main() { List<int> mae = new List<int>(); List<int> ushiro = new List<int>(); string input = Console.ReadLine(); var rabel = "NA"; for (int i = 0; i < 2; i++) { char moji = input[i]; mae.Add(int.Parse(string.Join("",moji))); } for (int i = 2; i < 4; i++) { char moji = input[i]; ushiro.Add(int.Parse(string.Join("", moji))); } int A = 10 * mae[0] + 1 * mae[1]; int B = 10 * ushiro[0] + 1 * ushiro[1]; if (0 <= A && A <= 99 && 0 < B && B < 13) { rabel = "YYMM"; if (0 < A && A < 13 && 0 < B && B < 13) { rabel = "AMBIGUOUS"; } } else if (0 <= B && B <= 99 && 0 < A && A < 13) { rabel = "MMYY"; if (0 < A && A < 13 && 0 < B && B < 13) { rabel = "AMBIGUOUS"; } } Console.WriteLine(rabel); } }*/ // 125B /*class Program { static void Main() { int N = int.Parse(Console.ReadLine()); int[] V = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] C = Console.ReadLine().Split().Select(int.Parse).ToArray(); int Answer = 0; for (int i=0;i<N;i++) { var temp = V[i] - C[i]; if (temp > 0) { Answer += temp; } } Console.WriteLine(Answer); } }*/ // 124B // count変数の初期化忘れがち!! /*class Program { static void Main() { int Ans = 0; int count = 0; int N = int.Parse(Console.ReadLine()); int[] Height = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i =0;i<Height.Length;i++) { for (int j=0;j<i;j++) { if (Height[i] >= Height[j]) { Ans++; } } if (Ans == i) { count++; } Ans = 0; } Console.WriteLine(count); } }*/ // 123B /*class Program { static void Main() { List<int> time = new List<int>(); List<int> sample = new List<int>(); int[] aa = new int[5]; for (int i = 0;i<5;i++) { int dish = int.Parse(Console.ReadLine()); time.Add(dish); } time.CopyTo(aa); int ans = 0; foreach (int a in time) { var temp = a % 10; sample.Add(temp); } var jj = sample.IndexOf(sample.Min()); time.RemoveAt(jj); time.Add(aa[jj]); foreach (int n in time) { ans += n; if (ans % 10 != 0) { ans += 10 - (ans % 10); } } Console.WriteLine(ans); } }*/ // 122B /*class Program { static void Main() { int anscount = 0; List<int> Answer = new List<int>(); string S = Console.ReadLine(); char[] Cstr = new char[S.Length]; for (int i=0;i<S.Length;i++) { Cstr[i] = S[i]; } for (int i=0;i<Cstr.Length;i++) { var temp = i; while (true) { if (temp < Cstr.Length) { if (Cstr[temp] == 'A' || Cstr[temp] == 'C' || Cstr[temp] == 'G' || Cstr[temp] == 'T') { anscount++; temp++; } else { Answer.Add(anscount); anscount = 0; break; } } else { Answer.Add(anscount); anscount = 0; break; } } } Console.WriteLine(Answer.Max()); } }*/ // 122B /*class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int C = input[2]; int[] B = Console.ReadLine().Split().Select(int.Parse).ToArray(); List<int[]> AA = new List<int[]>(); for (int i =0;i< N;i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); AA.Add(a); } int Ans = 0; List<int> mans = new List<int>(); for (int i =0;i<N;i++) { for (int j=0;j<M;j++) { Ans += AA[i][j] * B[j]; } var ans =Ans + C; mans.Add(ans); Ans = 0; } int count = 0; foreach (int n in mans) { if (n > 0) { count++; } } Console.WriteLine(count); } }*/ // 120B class Program { static void Main() { List<int> Array1 = new List<int>(); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int B = input[1]; int K = input[2]; int index = 1; List<int> a = new List<int>(); a.Add(A); a.Add(B); var aa = a.Max(); while (true) { if (A % index == 0 && B % index == 0) { Array1.Add(index); index++; } else { index++; } if (aa + 1 == index) { break; } } //配列逆になってない // 100 100 1 100 // 16 16 4 2 // 16 16 3 4 Array1.Sort(); Array1.Reverse(); Console.WriteLine(Array1[K - 1]); } } }
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["-", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
8
239
22
using System; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.Linq; using System.Text; using static System.Console; namespace ABC120B { static class Program { static void Main(string[] args) { var line = ReadLine().SplitTryParseToList<int>(); var k = new int[line[2]]; int i = 0; int j = 1; while (i < line[2]) { if (line[0] % j == 0 && line[1] % j == 0) { k[i] = j; i++; } j++; } WriteLine(k[line[2] - 1]); } public static T TryParse<T>(this String input) { try { var converter = TypeDescriptor.GetConverter(typeof(T)); if (converter != null) { return (T)converter.ConvertFromString(input); } else { throw new InvalidCastException(""); } } catch { throw new InvalidCastException(typeof(T) + " is not supported."); } } public static List<T> SplitTryParseToList<T>(this String input) { return input.Split().Select(n => n.TryParse<T>()).ToList(); } public static List<T> ListSwap<T>(this List<T> list, Int32 index1, Int32 index2) { var t = list[index1]; list[index1] = list[index2]; list[index2] = t; return list; } public static List<Tuple<T, int>> DuplicateCount<T>(this IEnumerable<T> list) { return list.GroupBy(i => i) .Where(g => g.Any()) .Select(g => Tuple.Create(g.Key, g.Count())) .ToList(); } public static List<Tuple<T, int>> DuplicateSort<T>(this IEnumerable<Tuple<T, int>> list) { return list.OrderByDescending((x) => x.Item2).ToList(); } public static List<T> ReadLineOne<T>(int n) { var list = new List<T>(); foreach (var i in Enumerable.Range(1, n)) { list.Add(Console.ReadLine().TryParse<T>()); } return list; } public static void PrintAll<T>(this IEnumerable<T> list) { foreach (var i in list) { Console.Write($"{i} "); } Console.WriteLine(); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.Linq; using System.Text; using static System.Console; namespace ABC120B { static class Program { static void Main(string[] args) { var line = ReadLine().SplitTryParseToList<int>(); var k = new int[line[2]]; int i = Math.Max(line[0], line[1]); int j = 1; while (i > 0 && j <= line[2]) { if (line[0] % i == 0 && line[1] % i == 0) { k[j - 1] = i; j++; } i--; } WriteLine(k[line[2] - 1]); } public static T TryParse<T>(this String input) { try { var converter = TypeDescriptor.GetConverter(typeof(T)); if (converter != null) { return (T)converter.ConvertFromString(input); } else { throw new InvalidCastException(""); } } catch { throw new InvalidCastException(typeof(T) + " is not supported."); } } public static List<T> SplitTryParseToList<T>(this String input) { return input.Split().Select(n => n.TryParse<T>()).ToList(); } public static List<T> ListSwap<T>(this List<T> list, Int32 index1, Int32 index2) { var t = list[index1]; list[index1] = list[index2]; list[index2] = t; return list; } public static List<Tuple<T, int>> DuplicateCount<T>(this IEnumerable<T> list) { return list.GroupBy(i => i) .Where(g => g.Any()) .Select(g => Tuple.Create(g.Key, g.Count())) .ToList(); } public static List<Tuple<T, int>> DuplicateSort<T>(this IEnumerable<Tuple<T, int>> list) { return list.OrderByDescending((x) => x.Item2).ToList(); } public static List<T> ReadLineOne<T>(int n) { var list = new List<T>(); foreach (var i in Enumerable.Range(1, n)) { list.Add(Console.ReadLine().TryParse<T>()); } return list; } public static void PrintAll<T>(this IEnumerable<T> list) { foreach (var i in list) { Console.Write($"{i} "); } Console.WriteLine(); } } }
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 98], ["+", 8, 196, 0, 52, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 52, 15, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68]]
8
550
35
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' '); var A = int.Parse(inputs[0]); var B = int.Parse(inputs[1]); var K = int.Parse(inputs[2]); var gcd = Gcd(A, B); var count = 0; var result = 0; for (int i = 1; i <= gcd; i++) { if ((A % i) * (B % i) == 0) count++; if (count == K) { result = i; break; } } Console.WriteLine(result); } /** * ユークリッド互除法 * <see cref="https://qiita.com/gushwell/items/e9614b4ac2bea3fc6486"/> */ 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; } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' '); var A = int.Parse(inputs[0]); var B = int.Parse(inputs[1]); var K = int.Parse(inputs[2]); var gcd = Gcd(A, B); var count = 0; var result = 0L; for (long i = gcd; i >= 1; i--) { if ((A % i) == 0 && (B % i) == 0) count++; if (count == K) { result = i; break; } } Console.WriteLine(result); } /** * ユークリッド互除法(最大公約数) * <see cref="https://qiita.com/gushwell/items/e9614b4ac2bea3fc6486"/> */ 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; } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
8
216
16
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Program { public static Scanner cin; static void Main() { cin = new Scanner(); int[] abk = cin.arrayInt(3); int a = abk[0]; int b = abk[1]; int k = abk[2]; int count = 0; for (int c = Math.Min(a, b); c > 0; c--) { if (a % c == 0 && b % c == 0) count++; if (count == k) break; } WriteLine(k); ReadLine(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string input() { 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 input(); i = 0; return s[i++]; } public int inputInt() { return int.Parse(input()); } public int[] arrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = inputInt() + add; } return Array; } public long inputLong() { return long.Parse(input()); } public long[] arrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = inputLong() + add; } return Array; } public double inputDouble() { return double.Parse(input()); } public double[] arrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = inputDouble() + add; } return Array; } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Program { public static Scanner cin; static void Main() { cin = new Scanner(); int[] abk = cin.arrayInt(3); int a = abk[0]; int b = abk[1]; int k = abk[2]; int count = 0; int ans = 0; for (int c = Math.Min(a, b); c > 0; c--) { if (a % c == 0 && b % c == 0) count++; if (count == k) { ans = c; break; } } WriteLine(ans); ReadLine(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string input() { 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 input(); i = 0; return s[i++]; } public int inputInt() { return int.Parse(input()); } public int[] arrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = inputInt() + add; } return Array; } public long inputLong() { return long.Parse(input()); } public long[] arrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = inputLong() + add; } return Array; } public double inputDouble() { return double.Parse(input()); } public double[] arrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = inputDouble() + add; } return Array; } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
519
13
using System; using System.Linq; using System.IO; using System.Collections.Generic; using System.Text; namespace AtCoder { public class Program { static int[] getKeys(char delimiter = ' ') { var Keys = Console.ReadLine().Split(delimiter); int N = Keys.Length; int[] Ns = new int[N]; for (int i = 0; i < N; i++) { Ns[i] = int.Parse(Keys[i]); } return Ns; } static long[] getKeys_L(char delimiter = ' ') { var Keys = Console.ReadLine().Split(delimiter); int N = Keys.Length; long[] Ns = new long[N]; for (int i = 0; i < N; i++) { Ns[i] = long.Parse(Keys[i]); } return Ns; } static double[] getKeys_D(char delimiter = ' ') { var Keys = Console.ReadLine().Split(delimiter); int N = Keys.Length; var Ns = new double[N]; for (int i = 0; i < N; i++) { Ns[i] = double.Parse(Keys[i]); } return Ns; } static int[] getLines(int N, char delimiter = ' ') { int[] Ns = new int[N]; for (int i = 0; i < N; i++) { Ns[i] = int.Parse(Console.ReadLine()); } return Ns; } static long[] getLines_L(int N, char delimiter = ' ') { long[] Ns = new long[N]; for (int i = 0; i < N; i++) { Ns[i] = long.Parse(Console.ReadLine()); } return Ns; } static double[] getLines_D(int N, char delimiter = ' ') { double[] Ns = new double[N]; for (int i = 0; i < N; i++) { Ns[i] = double.Parse(Console.ReadLine()); } return Ns; } public static void Show<T>(T[,] map) { int H = map.GetLength(0); int W = map.GetLength(1); Console.WriteLine("-------------------------"); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { Console.Write(map[i, j] + " "); } Console.WriteLine(); } Console.WriteLine("-------------------------"); } public static void Show<T>(T[,] map, string delimiter) { int H = map.GetLength(0); int W = map.GetLength(1); Console.WriteLine("-------------------------"); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { Console.Write(map[i, j] + delimiter); } Console.WriteLine(); } Console.WriteLine("-------------------------"); } public static void Show<T>(IEnumerable<T> ts) { foreach (var item in ts) { Console.Write(item + " "); } Console.WriteLine(); } public static void Show<T>(IEnumerable<T> ts, string delimiter) { foreach (var item in ts) { Console.Write(item + delimiter); } Console.WriteLine(); } public static void ShowDictionary<T1, T2>(Dictionary<T1, T2> dictionary) { foreach (var item in dictionary) { Console.WriteLine(item); } } static T[] getUniform<T>(int length, T value) { T[] Ts = new T[length]; for (int i = 0; i < length; i++) { Ts[i] = value; } return Ts; } static void setUniform<T>(T[] ts, T value) { int length = ts.Length; for (int i = 0; i < length; i++) { ts[i] = value; } } static T[,] getUniform_Diag<T>(int row, int col, T value, T defaultValue = default(T)) { T[,] Ts = new T[row, col]; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { Ts[j, i] = i == j ? defaultValue : value; } } return Ts; } static T[,] getUniform<T>(int row, int col, T value) { T[,] Ts = new T[row, col]; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { Ts[j, i] = value; } } return Ts; } static void setUniform<T>(T[,] ts, T value) { int N = ts.GetLength(0); int M = ts.GetLength(1); for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { ts[j, i] = value; } } } static void setUniform_Diag<T>(T[,] ts, T value, T defaultValue = default(T)) { int N = ts.GetLength(0); int M = ts.GetLength(1); for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { ts[j, i] = i == j ? defaultValue : value; } } } static Tuple<int, int> findIndex<T>(T[,] map, T value) where T : IComparable { int row = map.GetLength(0); int col = map.GetLength(1); for (int i = 0; i < col; i++) { for (int j = 0; j < row; j++) { if (value.CompareTo(map[j, i]) == 0) return new Tuple<int, int>(j, i); } } return new Tuple<int, int>(-1, -1); } static void Main() { var keys = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var Max = keys.Max(); var Count = 0; for (int i = 1; i <= Max; i++) { if (keys[0] % i == 0 && keys[1] % i == 0) Count++; if (Count == keys[2]) { Console.WriteLine(i); return; } } } } }
using System; using System.Linq; using System.IO; using System.Collections.Generic; using System.Text; namespace AtCoder { public class Program { static int[] getKeys(char delimiter = ' ') { var Keys = Console.ReadLine().Split(delimiter); int N = Keys.Length; int[] Ns = new int[N]; for (int i = 0; i < N; i++) { Ns[i] = int.Parse(Keys[i]); } return Ns; } static long[] getKeys_L(char delimiter = ' ') { var Keys = Console.ReadLine().Split(delimiter); int N = Keys.Length; long[] Ns = new long[N]; for (int i = 0; i < N; i++) { Ns[i] = long.Parse(Keys[i]); } return Ns; } static double[] getKeys_D(char delimiter = ' ') { var Keys = Console.ReadLine().Split(delimiter); int N = Keys.Length; var Ns = new double[N]; for (int i = 0; i < N; i++) { Ns[i] = double.Parse(Keys[i]); } return Ns; } static int[] getLines(int N, char delimiter = ' ') { int[] Ns = new int[N]; for (int i = 0; i < N; i++) { Ns[i] = int.Parse(Console.ReadLine()); } return Ns; } static long[] getLines_L(int N, char delimiter = ' ') { long[] Ns = new long[N]; for (int i = 0; i < N; i++) { Ns[i] = long.Parse(Console.ReadLine()); } return Ns; } static double[] getLines_D(int N, char delimiter = ' ') { double[] Ns = new double[N]; for (int i = 0; i < N; i++) { Ns[i] = double.Parse(Console.ReadLine()); } return Ns; } public static void Show<T>(T[,] map) { int H = map.GetLength(0); int W = map.GetLength(1); Console.WriteLine("-------------------------"); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { Console.Write(map[i, j] + " "); } Console.WriteLine(); } Console.WriteLine("-------------------------"); } public static void Show<T>(T[,] map, string delimiter) { int H = map.GetLength(0); int W = map.GetLength(1); Console.WriteLine("-------------------------"); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { Console.Write(map[i, j] + delimiter); } Console.WriteLine(); } Console.WriteLine("-------------------------"); } public static void Show<T>(IEnumerable<T> ts) { foreach (var item in ts) { Console.Write(item + " "); } Console.WriteLine(); } public static void Show<T>(IEnumerable<T> ts, string delimiter) { foreach (var item in ts) { Console.Write(item + delimiter); } Console.WriteLine(); } public static void ShowDictionary<T1, T2>(Dictionary<T1, T2> dictionary) { foreach (var item in dictionary) { Console.WriteLine(item); } } static T[] getUniform<T>(int length, T value) { T[] Ts = new T[length]; for (int i = 0; i < length; i++) { Ts[i] = value; } return Ts; } static void setUniform<T>(T[] ts, T value) { int length = ts.Length; for (int i = 0; i < length; i++) { ts[i] = value; } } static T[,] getUniform_Diag<T>(int row, int col, T value, T defaultValue = default(T)) { T[,] Ts = new T[row, col]; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { Ts[j, i] = i == j ? defaultValue : value; } } return Ts; } static T[,] getUniform<T>(int row, int col, T value) { T[,] Ts = new T[row, col]; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { Ts[j, i] = value; } } return Ts; } static void setUniform<T>(T[,] ts, T value) { int N = ts.GetLength(0); int M = ts.GetLength(1); for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { ts[j, i] = value; } } } static void setUniform_Diag<T>(T[,] ts, T value, T defaultValue = default(T)) { int N = ts.GetLength(0); int M = ts.GetLength(1); for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { ts[j, i] = i == j ? defaultValue : value; } } } static Tuple<int, int> findIndex<T>(T[,] map, T value) where T : IComparable { int row = map.GetLength(0); int col = map.GetLength(1); for (int i = 0; i < col; i++) { for (int j = 0; j < row; j++) { if (value.CompareTo(map[j, i]) == 0) return new Tuple<int, int>(j, i); } } return new Tuple<int, int>(-1, -1); } static void Main() { var keys = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var Max = keys.Max(); var Count = 0; for (int i = Max; i > 0; i--) { if (keys[0] % i == 0 && keys[1] % i == 0) Count++; if (Count == keys[2]) { Console.WriteLine(i); return; } } } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
1,487
8
using System; using System.Linq; namespace b120B { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var a = input[0]; var b = input[1]; var k = input[2]; var count = 0; for (int i = 1; i <= Math.Min(a, b); i++) { if (a % i == 0 && b % i == 0) { count++; if (count == k) { Console.WriteLine(i); return; } } } } } }
using System; using System.Linq; namespace b120B { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var a = input[0]; var b = input[1]; var k = input[2]; for (int i = Math.Min(a, b); i > 0; i--) { if (a % i == 0 && b % i == 0) { // Console.WriteLine(i); k--; if (k == 0) { Console.WriteLine(i); return; } } } } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 68], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203]]
8
142
23
using System; public class c { public static void Main() { string[] A_B_K = Console.ReadLine().Split(' '); int A = int.Parse(A_B_K[0]); int B = int.Parse(A_B_K[1]); int K = int.Parse(A_B_K[2]); int n = A; int count = 0; int ans = 0; if (n > B) n = B; for (int i = 1; i <= n; i++) { if (A % i == 0 && B % i == 0) count++; if (count == K) { ans = i; break; } } Console.WriteLine(ans); } }
using System; public class c { public static void Main() { string[] A_B_K = Console.ReadLine().Split(' '); int A = int.Parse(A_B_K[0]); int B = int.Parse(A_B_K[1]); int K = int.Parse(A_B_K[2]); int n = A; int ans = 0; if (n > B) n = B; for (int i = n; i >= 1; i--) { if (A % i == 0 && B % i == 0) K--; if (K == 0) { ans = i; break; } } Console.WriteLine(ans); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 68], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203]]
8
152
21
using System; using System.Linq; public class Program { // limit static int A, B, C, N; static int[] l; public static void Main(string[] args) { // スペース区切りの整数の入力 var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var A = input[0]; var B = input[1]; var K = input[2]; var answer = 0; var flag = true; var counter = 0; while (flag) { answer++; if (A % answer == 0 & B % answer == 0) { counter++; if (counter == K) flag = false; } } Console.WriteLine(answer); } }
using System; using System.Linq; public class Program { // limit static int A, B, C, N; static int[] l; public static void Main(string[] args) { // スペース区切りの整数の入力 var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var A = input[0]; var B = input[1]; var K = input[2]; var answer = 101; var flag = true; var counter = 0; while (flag) { answer--; var aAnswer = A % answer; var bAnswer = B % answer; if (aAnswer == 0 & bAnswer == 0) { counter++; if (counter == K) flag = false; } } Console.WriteLine(answer); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 67], ["+", 8, 196, 0, 52, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 67], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22]]
8
154
24
using System; namespace ConsoleApp3 { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int A = int.Parse(s[0]); int B = int.Parse(s[1]); int K = int.Parse(s[2]); int counter = 0; for (int i = 1; i <= 100; i++) { if (A % i == 0 && B % i == 0) { counter++; if (counter == K) { Console.WriteLine(i.ToString()); return; } } } // Console.ReadKey(); } } }
using System; namespace ConsoleApp3 { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int A = int.Parse(s[0]); int B = int.Parse(s[1]); int K = int.Parse(s[2]); int counter = 0; for (int i = 100; i > 0; i--) { if (A % i == 0 && B % i == 0) { counter++; if (counter == K) { Console.WriteLine(i.ToString()); return; } } } Console.ReadKey(); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
141
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _20190304_04 { class Program { static void Main(string[] args) { var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var a = line[0]; var b = line[1]; var k = line[2]; var count = 0; for (int i = 1; i <= Math.Min(a, b); i++) { if (a % i == 0 && b % i == 0) { count++; if (count == k) { Console.WriteLine(i); return; } } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _20190304_04 { class Program { static void Main(string[] args) { var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var a = line[0]; var b = line[1]; var k = line[2]; var count = 0; for (int i = Math.Min(a, b); i > 0; i--) { if (a % i == 0 && b % i == 0) { count++; if (count == k) { Console.WriteLine(i); return; } } } } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
166
10
using System; using System.Linq; using System.Collections.Generic; 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 K = int.Parse(input[2]); var result = new List<int>(); for (var i = 1; i <= 100; i++) { if (A % i == 0) { if (B % i == 0) { result.Add(i); } } if (A <= i || B <= i) { break; } } Console.WriteLine(result[K - 1]); } }
using System; using System.Linq; using System.Collections.Generic; 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 K = int.Parse(input[2]); var result = new List<int>(); for (var i = 1; i <= 100; i++) { if (A % i == 0) { if (B % i == 0) { result.Add(i); } } if (A <= i || B <= i) { break; } } var c = result.Count(); var d = c - K; Console.WriteLine(result[d]); } }
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22]]
8
167
20
using System; class Program { static void Main(string[] args) { // 解 int ans = 0; // 入力 string[] inp = Console.ReadLine().Split(' '); int a = int.Parse(inp[0]); int b = int.Parse(inp[1]); int c = int.Parse(inp[2]); int cnt = 0; for (int i = 1; i <= 100; i++) { if ((a % i == 0) && (b % i == 0)) { cnt++; } if (cnt == c) { ans = i; break; } } //出力 Console.WriteLine(ans); } }
using System; class Program { static void Main(string[] args) { // 解 int ans = 0; // 入力 string[] inp = Console.ReadLine().Split(' '); int a = int.Parse(inp[0]); int b = int.Parse(inp[1]); int c = int.Parse(inp[2]); int cnt = 0; for (int i = 100; i >= 1; i--) { if ((a % i == 0) && (b % i == 0)) { cnt++; } if (cnt == c) { ans = i; break; } } //出力 Console.WriteLine(ans); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
148
8
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<int, int>; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { int A = cin.nextint; int B = cin.nextint; int K = cin.nextint; int cnt = 0; var L = new List<int>(); for (int i = 1; i <= Min(A, B); i++) { if (A % i == 0 && B % i == 0) { cnt++; } if (cnt == K) { L.Add(i); } } WriteLine(L[L.Count - K]); } long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; } long lcm(long a, long b) { return a / gcd(a, b) * b; } // ax + by = gcd(a, b)となるx, yを求める long extgcd(long a, long b, out long x, out long y) { long g = a; if (b != 0) { g = extgcd(b, a % b, out y, out x); y -= (a / b) * x; } else { x = 1; y = 0; } return g; } } static class Ex { public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values)); public static string concat<T>(this IEnumerable<T> values) => string.Concat(values); public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); public override string ToString() => $"{f} {s}"; } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan => ReadLine().Split(); public int[] scanint => Array.ConvertAll(scan, int.Parse); public long[] scanlong => Array.ConvertAll(scan, long.Parse); public double[] scandouble => Array.ConvertAll(scan, double.Parse); public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint => int.Parse(next); public long nextlong => long.Parse(next); public double nextdouble => double.Parse(next); }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<int, int>; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { int A = cin.nextint; int B = cin.nextint; int K = cin.nextint; int cnt = 0; var L = new List<int>(); for (int i = 1; i <= Min(A, B); i++) { if (A % i == 0 && B % i == 0) { L.Add(i); } } WriteLine(L[L.Count - K]); } long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; } long lcm(long a, long b) { return a / gcd(a, b) * b; } // ax + by = gcd(a, b)となるx, yを求める long extgcd(long a, long b, out long x, out long y) { long g = a; if (b != 0) { g = extgcd(b, a % b, out y, out x); y -= (a / b) * x; } else { x = 1; y = 0; } return g; } } static class Ex { public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values)); public static string concat<T>(this IEnumerable<T> values) => string.Concat(values); public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); public override string ToString() => $"{f} {s}"; } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan => ReadLine().Split(); public int[] scanint => Array.ConvertAll(scan, int.Parse); public long[] scanlong => Array.ConvertAll(scan, long.Parse); public double[] scandouble => Array.ConvertAll(scan, double.Parse); public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint => int.Parse(next); public long nextlong => long.Parse(next); public double nextdouble => double.Parse(next); }
[["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45]]
8
1,062
11
using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Linq; class Program { static void Main() { int[] inp = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = inp[0]; int b = inp[1]; int k = inp[2]; int c = 0; for (int i = 1;; i++) { if (a % i == 0 && b % i == 0) c++; if (c == k) { Console.WriteLine(i); return; } } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Linq; class Program { static void Main() { int[] inp = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = inp[0]; int b = inp[1]; int k = inp[2]; int c = 0; for (int i = Math.Min(a, b);; i--) { if (a % i == 0 && b % i == 0) c++; if (c == k) { Console.WriteLine(i); return; } } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
138
11
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; 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) { // WriteLine ("入力"); var S = cin.ReadLine; int N = S.Length; List<int> s = new List<int>(); for (int i = 0; i < N; i++) { s.Add(int.Parse(S[i].ToString())); } int index = 0; int count = 0; while (true) { if (index + 1 >= s.Count) break; if (s[index] != s[index + 1]) { count++; s.RemoveAt(index); s.RemoveAt(index + 1); if (index != 0) index--; } else { index++; } } WriteLine(count * 2); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; 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) { // WriteLine ("入力"); var S = cin.ReadLine; int N = S.Length; List<int> s = new List<int>(); for (int i = 0; i < N; i++) { s.Add(int.Parse(S[i].ToString())); } int index = 0; int count = 0; while (true) { if (index + 1 >= s.Count) break; if (s[index] != s[index + 1]) { count++; s.RemoveAt(index); s.RemoveAt(index); if (index != 0) index--; } else { if (index + 1 == s.Count) break; index++; } } WriteLine(count * 2); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 75, 196, 0, 57, 15, 16, 12, 214, 205, 22], ["+", 75, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 75, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 57, 75, 196, 0, 57, 64, 93, 0, 35]]
8
573
14
using System; namespace ConsoleApp3 { class Program { static void Main(string[] args) { string s = Console.ReadLine(); int zero = 0; int one = 0; for (int i = 0; i < s.Length; i++) { if (s[i].Equals('0')) zero++; else one++; } if (zero > one) Console.WriteLine((zero - one).ToString()); else Console.WriteLine((one - zero).ToString()); } } }
using System; namespace ConsoleApp3 { class Program { static void Main(string[] args) { string s = Console.ReadLine(); int zero = 0; int one = 0; for (int i = 0; i < s.Length; i++) { if (s[i].Equals('0')) zero++; else one++; } if (zero > one) Console.WriteLine((one * 2).ToString()); else Console.WriteLine((zero * 2).ToString()); } } }
[["-", 0, 213, 63, 214, 205, 23, 0, 16, 31, 22], ["-", 0, 213, 63, 214, 205, 23, 0, 16, 17, 33], ["+", 0, 213, 63, 214, 205, 23, 0, 16, 17, 48], ["+", 0, 213, 63, 214, 205, 23, 0, 16, 12, 203]]
8
117
8
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { char[] input = ReadChar(); //配列→list List<char> numList = new List<char>(); for (int jj = 0; jj < input.Length; jj++) { numList.Add(input[jj]); } //答え用カウンター int answer = 0; //隣合う0と1を取り除いてカウントしていく for (int ii = 0; ii < numList.Count - 1; ii++) { if (numList[ii] != numList[ii + 1]) { numList.RemoveAt(ii); numList.RemoveAt(ii); answer = answer + 2; if (ii < 2) { ii = -1; } else { ii = ii - 2; } } } } //読み取り用 static String Read() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static char[] ReadChar() { return Console.ReadLine().ToCharArray(); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { //入力の受け取り char[] input = ReadChar(); //配列→list List<char> numList = new List<char>(); for (int jj = 0; jj < input.Length; jj++) { numList.Add(input[jj]); } //隣合う0と1を取り除いてカウントしていく int answer = Puyo(numList); //回答提出 Console.WriteLine(answer); } static int Puyo(List<char> numList) { int answer = 0; for (int ii = 0; ii < numList.Count - 1; ii++) { if (numList[ii] != numList[ii + 1]) { numList.RemoveAt(ii); numList.RemoveAt(ii); answer = answer + 2; if (ii < 2) { ii = -1; } else { ii = ii - 2; } } } return answer; } //読み取り用 static String Read() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static char[] ReadChar() { return Console.ReadLine().ToCharArray(); } }
[["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 115], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 0, 195, 54, 55, 0, 220, 39, 236, 141, 22], ["+", 54, 55, 0, 220, 39, 236, 237, 238, 0, 18], ["+", 54, 55, 0, 220, 39, 236, 237, 238, 0, 199], ["+", 54, 55, 0, 220, 39, 236, 237, 238, 0, 47], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 35]]
8
216
7
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { char[] input = ReadChar(); //配列→list List<char> numList = new List<char>(); for (int jj = 0; jj < input.Length; jj++) { numList.Add(input[jj]); } //答え用カウンター int answer = 0; //隣合う0と1を取り除いてカウントしていく for (int ii = 0; ii < numList.Count - 1; ii++) { if (numList[ii] != numList[ii + 1]) { numList.RemoveAt(ii); numList.RemoveAt(ii); answer = answer + 2; if (ii < 2) { ii = -1; } else { ii = ii - 2; } } } } //読み取り用 static String Read() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static char[] ReadChar() { return Console.ReadLine().ToCharArray(); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { //入力の受け取り char[] input = ReadChar(); //配列→list List<char> numList = new List<char>(); for (int jj = 0; jj < input.Length; jj++) { numList.Add(input[jj]); } //答え用カウンター int answer = 0; //隣合う0と1を取り除いてカウントしていく for (int ii = 0; ii < numList.Count - 1; ii++) { if (numList[ii] != numList[ii + 1]) { numList.RemoveAt(ii); numList.RemoveAt(ii); answer = answer + 2; if (ii < 2) { ii = -1; } else { ii = ii - 2; } } } //回答提出 Console.WriteLine(answer); } //読み取り用 static String Read() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static char[] ReadChar() { return Console.ReadLine().ToCharArray(); } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
216
7
using System; using System.Linq; using System.Collections.Generic; using E = System.Linq.Enumerable; public class Program { public static void Main() { var s = Console.ReadLine().Trim().Select(x => (int)x - '0').ToArray(); var rest = 1; var color = s[0]; var k = 0; for (int i = 1; i < s.Length; i++) { if (color + s[i] == 1) { rest--; k++; continue; } color = s[i]; rest++; } Console.WriteLine(k * 2); } }
using System; using System.Linq; using System.Collections.Generic; using E = System.Linq.Enumerable; public class Program { public static void Main() { var s = Console.ReadLine().Trim().Select(x => (int)x - '0').ToArray(); var rest = 1; var color = s[0]; var k = 0; for (int i = 1; i < s.Length; i++) { if (color + s[i] == 1) { rest--; k++; if (rest == 0) { color = -1; } continue; } color = s[i]; rest++; } Console.WriteLine(k * 2); } }
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
144
13
using System; using System.Collections.Generic; using System.Linq; class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int Int() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } } class Program { static Scanner cin = new Scanner(); static void Main() { string S = Console.ReadLine(); int one = 0, zero = 0; int ans = 0; for (int i = 0; i < S.Length; i++) { if (S[i] == '1') one++; else zero++; if (one == zero) { ans += one + zero; one = 0; zero = 0; } } Console.WriteLine(ans); Console.ReadLine(); } }
using System; using System.Collections.Generic; using System.Linq; class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int Int() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } } class Program { static Scanner cin = new Scanner(); static void Main() { string S = Console.ReadLine(); int one = 0, zero = 0; int tmp = 0, tmp2 = 0; // for (int i = 0; i < S.Length; i++) { // if (S[i] == '1') one++; // else zero++; // if(one == zero) { // tmp += one + zero; // one = 0; // zero = 0; // } //} // one = 0; // zero = 0; // for(int i = S.Length - 1; i >= 0; i--) { // if (S[i] == '1') one++; // else zero++; // if (one == zero) { // tmp2 += one + zero; // one = 0; // zero = 0; // } //} // Console.WriteLine(Math.Max(tmp, tmp2)); for (int i = 0; i < S.Length; i++) { if (S[i] == '0') zero++; else one++; if (one > 0 && zero > 0) { int num = Math.Min(one, zero); tmp += 2 * Math.Min(one, zero); one -= num; zero -= num; } } Console.WriteLine(tmp); Console.ReadLine(); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["-", 8, 196, 0, 57, 75, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 75, 1, 0, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 16, 12, 213, 3, 4, 0, 24], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 11, 12, 16, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 16, 12, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
405
51
using System; using System.Collections.Generic; using System.Linq; namespace ABC120D { class Program { static void Main(string[] args) { var NM = ReadInt(); long N = NM[0]; int M = NM[1]; long[] anss = new long[M]; int[] A = new int[M]; int[] B = new int[M]; for (int i = 0; i < M; i++) { var input = ReadInt(); A[i] = input[0] - 1; B[i] = input[1] - 1; } var uf = new UnionFind((int)N); anss[M - 1] = N * (N - 1) / 2; //初期化 for (int i = M - 2; i >= 0; i--) { if (uf.Same(A[i + 1], B[i + 1])) { //変化なし } else { anss[i] = anss[i + 1] - uf.count[uf.Find(A[i + 1])] * uf.count[uf.Find(B[i + 1])]; } uf.Unite(A[i + 1], B[i + 1]); } foreach (var a in anss) { Console.WriteLine(a); } Console.ReadKey(); } static int[] ReadInt() { int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray(); return ret; } static long[] ReadLong() { long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray(); return ret; } } class UnionFind { int[] par; int[] rank; public long[] count; public UnionFind(int n) { init(n); } void init(int n) { par = new int[n]; rank = new int[n]; count = new long[n]; for (int i = 0; i < n; i++) { par[i] = i; rank[i] = 0; count[i] = 1; } } public int Find(int x) { if (par[x] == x) { return x; } else { return par[x] = Find(par[x]); } } public void Unite(int x, int y) { x = Find(x); y = Find(y); if (x == y) return; if (rank[x] < rank[y]) { par[x] = y; count[y] += count[x]; } else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; count[x] += count[y]; } } public bool Same(int x, int y) { return Find(x) == Find(y); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC120D { class Program { static void Main(string[] args) { var NM = ReadInt(); long N = NM[0]; int M = NM[1]; long[] anss = new long[M]; int[] A = new int[M]; int[] B = new int[M]; for (int i = 0; i < M; i++) { var input = ReadInt(); A[i] = input[0] - 1; B[i] = input[1] - 1; } var uf = new UnionFind((int)N); anss[M - 1] = N * (N - 1) / 2; //初期化 for (int i = M - 2; i >= 0; i--) { if (uf.Same(A[i + 1], B[i + 1])) { //変化なし anss[i] = anss[i + 1]; } else { anss[i] = anss[i + 1] - uf.count[uf.Find(A[i + 1])] * uf.count[uf.Find(B[i + 1])]; } uf.Unite(A[i + 1], B[i + 1]); } foreach (var a in anss) { Console.WriteLine(a); } Console.ReadKey(); } static int[] ReadInt() { int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray(); return ret; } static long[] ReadLong() { long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray(); return ret; } } class UnionFind { int[] par; int[] rank; public long[] count; public UnionFind(int n) { init(n); } void init(int n) { par = new int[n]; rank = new int[n]; count = new long[n]; for (int i = 0; i < n; i++) { par[i] = i; rank[i] = 0; count[i] = 1; } } public int Find(int x) { if (par[x] == x) { return x; } else { return par[x] = Find(par[x]); } } public void Unite(int x, int y) { x = Find(x); y = Find(y); if (x == y) return; if (rank[x] < rank[y]) { par[x] = y; count[y] += count[x]; } else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; count[x] += count[y]; } } public bool Same(int x, int y) { return Find(x) == Find(y); } } }
[["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
643
12
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 o = Ints; var N = o[0]; var M = o[1]; var uf = new UnionFind(N); var ab = new Tuple<int, int>[M]; for (int i = 0; i < M; ++i) { var oo = Ints; --oo[0]; --oo[1]; ab[M - 1 - i] = new Tuple<int, int>(oo[0], oo[1]); } long cur = (long)N * (N - 1) / 2; var lis = new List<long>(); for (int i = 0; i < M; ++i) { lis.Add(cur); cur -= (long)uf.Size(ab[i].Item1) * uf.Size(ab[i].Item2); cur = Max(0, cur); uf.Merge(ab[i].Item1, ab[i].Item2); } lis.Reverse(); foreach (var a in lis) Put(a); } } public class UnionFind { int _count; int[] par, sizes, rank; public UnionFind(int N) { _count = N; par = new int[N]; sizes = new int[N]; rank = new int[N]; for (int i = 0; i < N; ++i) { par[i] = i; sizes[i] = 1; rank[i] = 0; } } int Root(int X) { if (par[X] == X) { return X; } else return (par[X] = Root(par[X])); } public bool Merge(int X, int Y) { X = Root(X); Y = Root(Y); if (X == Y) return false; --_count; if (rank[X] < rank[Y]) { par[X] = Y; sizes[Y] += sizes[X]; } else { par[Y] = X; sizes[X] += sizes[Y]; if (rank[X] == rank[Y]) ++rank[X]; } return true; } public bool IsSame(int X, int Y) => Root(X) == Root(Y); // count group public int Count => _count; public bool IsParent(int X) => X == Root(X); public int GetParent(int X) => Root(X); // size of group containing X public int Size(int X) => sizes[Root(X)]; } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { if (r > n - r) r = n - r; long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno = (Deno * i) % MOD; Nume = Nume * (n - i + 1) % MOD; } return (Nume * inv(Deno)) % MOD; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } public static long inv(long x, int MOD = 1000000007) { return Power(x, MOD - 2, MOD); } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } public static string ConvertBase(long N, int K) { StringBuilder ret = new StringBuilder(); while (N > 0) { var r = N % K; N /= K; ret.Append(r); } return new string(ret.ToString().ToCharArray().Reverse().ToArray()); } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void VerticalPut<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("No"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var o = Ints; var N = o[0]; var M = o[1]; var uf = new UnionFind(N); var ab = new Tuple<int, int>[M]; for (int i = 0; i < M; ++i) { var oo = Ints; --oo[0]; --oo[1]; ab[M - 1 - i] = new Tuple<int, int>(oo[0], oo[1]); } long cur = (long)N * (N - 1) / 2; var lis = new List<long>(); for (int i = 0; i < M; ++i) { lis.Add(cur); if (uf.GetParent(ab[i].Item1) != uf.GetParent(ab[i].Item2)) cur -= (long)uf.Size(ab[i].Item1) * uf.Size(ab[i].Item2); uf.Merge(ab[i].Item1, ab[i].Item2); } lis.Reverse(); foreach (var a in lis) Put(a); } } public class UnionFind { int _count; int[] par, sizes, rank; public UnionFind(int N) { _count = N; par = new int[N]; sizes = new int[N]; rank = new int[N]; for (int i = 0; i < N; ++i) { par[i] = i; sizes[i] = 1; rank[i] = 0; } } int Root(int X) { if (par[X] == X) { return X; } else return (par[X] = Root(par[X])); } public bool Merge(int X, int Y) { X = Root(X); Y = Root(Y); if (X == Y) return false; --_count; if (rank[X] < rank[Y]) { par[X] = Y; sizes[Y] += sizes[X]; } else { par[Y] = X; sizes[X] += sizes[Y]; if (rank[X] == rank[Y]) ++rank[X]; } return true; } public bool IsSame(int X, int Y) => Root(X) == Root(Y); // count group public int Count => _count; public bool IsParent(int X) => X == Root(X); public int GetParent(int X) => Root(X); // size of group containing X public int Size(int X) => sizes[Root(X)]; } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { if (r > n - r) r = n - r; long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno = (Deno * i) % MOD; Nume = Nume * (n - i + 1) % MOD; } return (Nume * inv(Deno)) % MOD; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } public static long inv(long x, int MOD = 1000000007) { return Power(x, MOD - 2, MOD); } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } public static string ConvertBase(long N, int K) { StringBuilder ret = new StringBuilder(); while (N > 0) { var r = N % K; N /= K; ret.Append(r); } return new string(ret.ToString().ToCharArray().Reverse().ToArray()); } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void VerticalPut<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("No"); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 214, 205, 204, 205, 22], ["+", 0, 28, 0, 214, 205, 204, 206, 207, 0, 70], ["+", 0, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 214, 205, 204, 206, 207, 0, 73], ["+", 31, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 31, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 12, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 11, 12, 16, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 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, 11, 12, 213, 3, 4, 0, 28, 0, 22]]
8
1,572
35
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 n = inputs[0]; var m = inputs[1]; var briges = new Tuple<int, int>[m]; for (int i = 0; i < m; i++) { var tmp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); briges[i] = new Tuple<int, int>(tmp[0], tmp[1]); } var trees = new UnionFind<int>(); for (int i = 1; i <= n; i++) trees.Add(i); var answers = new long[m]; answers[0] = (n - 1) * n / 2; for (long i = 1; i < m; i++) { var a = briges[i].Item1; var b = briges[i].Item2; if (trees.IsSame(a, b)) { answers[i] = answers[i - 1]; continue; } // 不便さを調べる answers[i] = answers[i - 1] - (trees.Size(a) * trees.Size(b)); // 結合をする trees.Unite(a, b); } foreach (var item in answers.Reverse()) Console.WriteLine(item); } } public class UnionFind<T> { private Dictionary<T, Node> _nodes; public UnionFind() { _nodes = new Dictionary<T, Node>(); } /// <summary> /// 要素を追加する /// </summary> public void Add(T item) { _nodes[item] = new Node(item); } /// <summary> /// 集合を結合する /// </summary> public void Unite(T x, T y) { Node.Unite(_nodes[x], _nodes[y]); } /// <summary> /// 同じ集合に属するか /// </summary> public bool IsSame(T x, T y) { return _nodes[x].Find() == _nodes[y].Find(); } /// <summary> /// グループに属する頂点の数を返す /// </summary> public long Size(T x) { return _nodes[x].Size; } class Node { private int _rank; private long _size; private Node _parent; public T Item; // 常に根がグループに属する頂点数を保持するように public long Size => Find()._size; public Node(T item) { _rank = 0; _size = 1; Item = item; _parent = this; } public Node Find() { if (_parent == this) return this; // 根を見つけるとともに、親が根になるようにつなぎ変える Node parent = _parent.Find(); _parent = parent; return parent; } public static void Unite(Node x, Node y) { var rootX = x.Find(); var rootY = y.Find(); // ランク(木の高さ)が低い方を高い方につなげる if (rootX._rank < rootY._rank) { rootX._parent = rootY; rootY._rank = Math.Max(rootX._rank + 1, rootY._rank); rootY._size = rootX._size + rootY._size; } else { rootY._parent = rootX; rootX._rank = Math.Max(rootY._rank + 1, rootX._rank); rootX._size = rootX._size + rootY._size; } } } }
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 n = inputs[0]; var m = inputs[1]; var briges = new Tuple<int, int>[m]; for (int i = 0; i < m; i++) { var tmp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); briges[i] = new Tuple<int, int>(tmp[0], tmp[1]); } var trees = new UnionFind<int>(); for (int i = 1; i <= n; i++) trees.Add(i); var answers = new long[m]; answers[0] = (long)(n - 1) * n / 2; for (long i = 1; i < m; i++) { var a = briges[m - i].Item1; var b = briges[m - i].Item2; if (trees.IsSame(a, b)) { answers[i] = answers[i - 1]; continue; } // 不便さを調べる answers[i] = answers[i - 1] - (trees.Size(a) * trees.Size(b)); // 結合をする trees.Unite(a, b); } foreach (var item in answers.Reverse()) Console.WriteLine(item); } } public class UnionFind<T> { private Dictionary<T, Node> _nodes; public UnionFind() { _nodes = new Dictionary<T, Node>(); } /// <summary> /// 要素を追加する /// </summary> public void Add(T item) { _nodes[item] = new Node(item); } /// <summary> /// 集合を結合する /// </summary> public void Unite(T x, T y) { Node.Unite(_nodes[x], _nodes[y]); } /// <summary> /// 同じ集合に属するか /// </summary> public bool IsSame(T x, T y) { return _nodes[x].Find() == _nodes[y].Find(); } /// <summary> /// グループに属する頂点の数を返す /// </summary> public long Size(T x) { return _nodes[x].Size; } class Node { private int _rank; private long _size; private Node _parent; // 常に根がグループに属する頂点数を保持するように public long Size => Find()._size; public Node(T item) { _rank = 0; _size = 1; _parent = this; } public Node Find() { if (_parent == this) return this; // 根を見つけるとともに、親が根になるようにつなぎ変える Node parent = _parent.Find(); _parent = parent; return parent; } public static bool Unite(Node x, Node y) { var rootX = x.Find(); var rootY = y.Find(); if (rootX == rootY) return false; // ランク(木の高さ)が低い方を高い方につなげる if (rootX._rank < rootY._rank) { rootX._parent = rootY; rootY._rank = Math.Max(rootX._rank + 1, rootY._rank); rootY._size = rootX._size + rootY._size; } else { rootY._parent = rootX; rootX._rank = Math.Max(rootY._rank + 1, rootX._rank); rootX._size = rootX._size + rootY._size; } return true; } } }
[["+", 0, 11, 12, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 25], ["+", 12, 16, 31, 16, 31, 74, 51, 23, 0, 24], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 8, 201, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 235, 8, 201, 0, 124, 0, 251, 0, 259], ["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 22], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 0, 263, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 263, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 201, 0, 263, 8, 196, 0, 1, 0, 35], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 37, 0, 211, 0, 147], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 37, 0, 211, 0, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 35]]
8
681
29
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using static System.Globalization.CultureInfo; class Program { static void Main(string[] args) { var nm = Add.ar; var res = new long[nm[1]]; var ct = (long)nm[0] * (nm[0] - 1) / 2; res[nm[1] - 1] = ct; var ad = new int[nm[1]][]; for (var i = 0; i < nm[1]; i++) { var inp = Add.ar; ad[i] = inp; } var un = new UnionFind<int>(); for (var i = 0; i < nm[0]; i++) un.MakeSet(i + 1); for (var i = nm[1] - 2; i >= 0; i--) { if (un.IsSame(ad[i + 1][1], ad[i + 1][0])) continue; var d0 = un.Rank(ad[i + 1][0]); var d1 = un.Rank(ad[i + 1][1]); un.Union(ad[i + 1][1], ad[i + 1][0]); res[i] = res[i + 1] - (long)d0 * d1; } WriteLine(string.Join("\n", res)); } } public class Add { public static string read => ReadLine(); public static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse); public static int num => ToInt32(read); public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse); public static long numL => ToInt64(read); public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; } public class UnionFind<T> { private class Vertex { public T Key { get; set; } public Vertex Parent { get; set; } public int Rank { get; set; } public int ct { get; set; } public Vertex(T key) : this(key, null, 0) {} public Vertex(T key, Vertex Parent, int rank) { this.Key = key; this.Parent = Parent; this.Rank = rank; ct = 1; } } private readonly Dictionary<T, Vertex> dics; private readonly Vertex NIL; public int Count { get; private set; } public UnionFind() { NIL = new Vertex(default(T)); dics = new Dictionary<T, Vertex>(); } public T parent(T key) => FindSet(dics[key].Parent).Key; public int Rank(T key) => FindSet(dics[key].Parent).ct; public bool IsSame(T key1, T key2) { if (!dics.ContainsKey(key1) || !dics.ContainsKey(key2)) throw new ArgumentException("対応する頂点が存在しません"); return ReferenceEquals(FindSet(dics[key1]), FindSet(dics[key2])); } public bool MakeSet(T key) { if (dics.ContainsKey(key)) throw new ArgumentException($"{key}をキーとして持つ頂点が既に存在します"); dics[key] = new Vertex(key, NIL, 0); dics[key].Parent = dics[key]; Count++; return true; } public bool Union(T key1, T key2) { if (!dics.ContainsKey(key1) || !dics.ContainsKey(key2)) throw new ArgumentException("対応する頂点が存在しません"); if (IsSame(key1, key2)) return false; Link(FindSet(dics[key1]), FindSet(dics[key2])); Count--; return true; } private bool Link(Vertex vex1, Vertex vex2) { if (vex1.Rank > vex2.Rank) { vex1.ct += vex2.ct; vex2.Parent = vex1; } else { vex2.ct += vex1.ct; vex1.Parent = vex2; if (vex1.Rank == vex2.Rank) vex2.Rank++; } return true; } private Vertex FindSet(Vertex vex) { if (!ReferenceEquals(vex.Parent, vex)) vex.Parent = FindSet(vex.Parent); return vex.Parent; } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using static System.Globalization.CultureInfo; class Program { static void Main(string[] args) { var nm = Add.ar; var res = new long[nm[1]]; var ct = (long)nm[0] * (nm[0] - 1) / 2; res[nm[1] - 1] = ct; var ad = new int[nm[1]][]; for (var i = 0; i < nm[1]; i++) { var inp = Add.ar; ad[i] = inp; } var un = new UnionFind<int>(); for (var i = 0; i < nm[0]; i++) un.MakeSet(i + 1); for (var i = nm[1] - 2; i >= 0; i--) { if (un.IsSame(ad[i + 1][1], ad[i + 1][0])) { res[i] = res[i + 1]; continue; } var d0 = un.Rank(ad[i + 1][0]); var d1 = un.Rank(ad[i + 1][1]); un.Union(ad[i + 1][1], ad[i + 1][0]); res[i] = res[i + 1] - (long)d0 * d1; } WriteLine(string.Join("\n", res)); } } public class Add { public static string read => ReadLine(); public static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse); public static int num => ToInt32(read); public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse); public static long numL => ToInt64(read); public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; } public class UnionFind<T> { private class Vertex { public T Key { get; set; } public Vertex Parent { get; set; } public int Rank { get; set; } public int ct { get; set; } public Vertex(T key) : this(key, null, 0) {} public Vertex(T key, Vertex Parent, int rank) { this.Key = key; this.Parent = Parent; this.Rank = rank; ct = 1; } } private readonly Dictionary<T, Vertex> dics; private readonly Vertex NIL; public int Count { get; private set; } public UnionFind() { NIL = new Vertex(default(T)); dics = new Dictionary<T, Vertex>(); } public T parent(T key) => FindSet(dics[key].Parent).Key; public int Rank(T key) => FindSet(dics[key].Parent).ct; public bool IsSame(T key1, T key2) { if (!dics.ContainsKey(key1) || !dics.ContainsKey(key2)) throw new ArgumentException("対応する頂点が存在しません"); return ReferenceEquals(FindSet(dics[key1]), FindSet(dics[key2])); } public bool MakeSet(T key) { if (dics.ContainsKey(key)) throw new ArgumentException($"{key}をキーとして持つ頂点が既に存在します"); dics[key] = new Vertex(key, NIL, 0); dics[key].Parent = dics[key]; Count++; return true; } public bool Union(T key1, T key2) { if (!dics.ContainsKey(key1) || !dics.ContainsKey(key2)) throw new ArgumentException("対応する頂点が存在しません"); if (IsSame(key1, key2)) return false; Link(FindSet(dics[key1]), FindSet(dics[key2])); Count--; return true; } private bool Link(Vertex vex1, Vertex vex2) { if (vex1.Rank > vex2.Rank) { vex1.ct += vex2.ct; vex2.Parent = vex1; } else { vex2.ct += vex1.ct; vex1.Parent = vex2; if (vex1.Rank == vex2.Rank) vex2.Rank++; } return true; } private Vertex FindSet(Vertex vex) { if (!ReferenceEquals(vex.Parent, vex)) vex.Parent = FindSet(vex.Parent); return vex.Parent; } }
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
934
14
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { private const int INF = 1000000007; public struct Pair<T> { public T x, y; public Pair(T x, T y) { this.x = x; this.y = y; } } public static void Solve() { long N = NextLong(); int M = NextInt(); List<Tuple<int, int>> e = Enumerable.Range(0, M) .Select(v => new Tuple<int, int>(NextInt() - 1, NextInt() - 1)) .ToList(); e.Reverse(); UnionFind UF = new UnionFind((int)N); List<long> ans = new List<long>(); long sum = N * (N - 1) / 2; ans.Add(sum); for (int i = 0; i < M - 1; i++) { //くっつけていく long a = UF.GetItem(e[i].Item1); long b = UF.GetItem(e[i].Item2); ans.Add(Math.Max(0, sum - a * b)); sum -= a * b; UF.Unite(e[i].Item1, e[i].Item2); } ans.Reverse(); ans.ForEach(Console.WriteLine); } public static void Main() { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } } public class UnionFind { private int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int GetItem(int x) { return -data[Root(x)]; } private int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } public class Input { 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 char NextChar() { Confirm(); return char.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(); } }
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { private const int INF = 1000000007; public struct Pair<T> { public T x, y; public Pair(T x, T y) { this.x = x; this.y = y; } } public static void Solve() { long N = NextLong(); int M = NextInt(); List<Tuple<int, int>> e = Enumerable.Range(0, M) .Select(v => new Tuple<int, int>(NextInt() - 1, NextInt() - 1)) .ToList(); e.Reverse(); UnionFind UF = new UnionFind((int)N); List<long> ans = new List<long>(); long sum = N * (N - 1) / 2; ans.Add(sum); for (int i = 0; i < M - 1; i++) { //くっつけていく long a = UF.GetItem(e[i].Item1); long b = UF.GetItem(e[i].Item2); if (UF.IsSameGroup(e[i].Item1, e[i].Item2)) { ans.Add(Math.Max(sum, 0)); continue; } else ans.Add(Math.Max(0, sum - a * b)); sum -= a * b; UF.Unite(e[i].Item1, e[i].Item2); } ans.Reverse(); ans.ForEach(Console.WriteLine); } public static void Main() { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } } public class UnionFind { private int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int GetItem(int x) { return -data[Root(x)]; } private int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } public class Input { 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 char NextChar() { Confirm(); return char.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(); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 214, 205, 204, 205, 22], ["+", 0, 28, 0, 214, 205, 204, 206, 207, 0, 70], ["+", 0, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 214, 205, 204, 206, 207, 0, 73], ["+", 15, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 15, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22]]
8
864
40
using System; using System.Collections.Generic; using static AtCoderer.Exter; using static System.Console; using static System.Math; using System.Linq; namespace AtCoderer { public class App { public static void Main(string[] args) { long n, m; { long[] r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); n = r[0]; m = r[1]; } Tuple<int, int>[] query = new Tuple<int, int>[m]; UnionFind uf = new UnionFind((int)n); for (int i = 0; i < m; i++) { int[] r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); query[i] = Tuple.Create(r[0] - 1, r[1] - 1); } long[] UnconfortableIndex = new long[m]; UnconfortableIndex[m - 1] = n * (n - 1) / 2; for (long i = m - 1; i > 0; i--) { if (!uf.AreGrouped(query[i].Item1, query[i].Item2)) UnconfortableIndex[i - 1] = UnconfortableIndex[i] - (long)uf.GetGroupSize(query[i].Item1) * (long)uf.GetGroupSize(query[i].Item2); uf.Connect(query[i].Item1, query[i].Item2); } for (int i = 0; i < m; i++) Console.WriteLine(UnconfortableIndex[i]); Console.ReadKey(); } } public static class Exter { public static void rep(int loop, Action<int> act) { for (int i = 0; i < loop; i++) act(i); } public static int ToInt(this string v) => int.Parse(v); public static int Max(params int[] p) => p.Max(); public static long Max(params long[] p) => p.Max(); public static int Min(params int[] p) => p.Min(); public static long Min(params long[] p) => p.Min(); public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static int GcdRecursive(int a, int b) => b == 0 ? a : GcdRecursive(b, a % b); public static object cout { set { Console.Write(value.ToString()); Console.WriteLine(); } } public static void ToCout<t>(this IEnumerable<t> v) { cout = string.Join(",", v); } public static string ToString(this IEnumerable<char> v) { return string.Join(",", v); } public static int[] readarr { get { return Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); } } public class UnionFind { private int[] Parent; private int GetRoot(int v) { if (Parent[v] < 0) return v; else return Parent[v] = GetRoot(Parent[v]); } public UnionFind(int size) { Parent = new int[size]; for (int i = 0; i < size; i++) Parent[i] = -1; } public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); } public void Connect(int a, int b) { a = GetRoot(a); b = GetRoot(b); if (a == b) return; Parent[b] += Parent[a]; Parent[a] = b; } public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; } } public class TreeBuilder { public int Size; public List<Tuple<int, int>>[] Child; public TreeBuilder(int size) { Size = size; Child = new List<Tuple<int, int>>[size]; for (int i = 0; i < size; i++) { Child[i] = new List<Tuple<int, int>>(); } } public void RegistEdge(int a, int b, int cost) { Child[a].Add(Tuple.Create(b, cost)); Child[b].Add(Tuple.Create(a, cost)); } public Tree BuildTree(int Root) { int[] Parent = new int[Size]; Queue<int> Search = new Queue<int>(); Search.Enqueue(Root); var Prev = Root; while (Search.Count > 0) { } return null; } } public class Tree { public int[] Parent; public int[] ParentDist; private int GetRoot(int v) { if (Parent[v] == v) return v; else return Parent[v] = GetRoot(Parent[v]); } public Tree() {} public void Add(int Target, int cost) {} } } }
using System; using System.Collections.Generic; using static AtCoderer.Exter; using static System.Console; using static System.Math; using System.Linq; namespace AtCoderer { public class App { public static void Main(string[] args) { long n, m; { long[] r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); n = r[0]; m = r[1]; } Tuple<int, int>[] query = new Tuple<int, int>[m]; UnionFind uf = new UnionFind((int)n); for (int i = 0; i < m; i++) { int[] r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); query[i] = Tuple.Create(r[0] - 1, r[1] - 1); } long[] UnconfortableIndex = new long[m]; UnconfortableIndex[m - 1] = n * (n - 1) / 2; for (long i = m - 1; i > 0; i--) { if (!uf.AreGrouped(query[i].Item1, query[i].Item2)) UnconfortableIndex[i - 1] = UnconfortableIndex[i] - (long)uf.GetGroupSize(query[i].Item1) * (long)uf.GetGroupSize(query[i].Item2); else UnconfortableIndex[i - 1] = UnconfortableIndex[i]; uf.Connect(query[i].Item1, query[i].Item2); } for (int i = 0; i < m; i++) Console.WriteLine(UnconfortableIndex[i]); Console.ReadKey(); } } public static class Exter { public static void rep(int loop, Action<int> act) { for (int i = 0; i < loop; i++) act(i); } public static int ToInt(this string v) => int.Parse(v); public static int Max(params int[] p) => p.Max(); public static long Max(params long[] p) => p.Max(); public static int Min(params int[] p) => p.Min(); public static long Min(params long[] p) => p.Min(); public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static int GcdRecursive(int a, int b) => b == 0 ? a : GcdRecursive(b, a % b); public static object cout { set { Console.Write(value.ToString()); Console.WriteLine(); } } public static void ToCout<t>(this IEnumerable<t> v) { cout = string.Join(",", v); } public static string ToString(this IEnumerable<char> v) { return string.Join(",", v); } public static int[] readarr { get { return Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); } } public class UnionFind { private int[] Parent; private int GetRoot(int v) { if (Parent[v] < 0) return v; else return Parent[v] = GetRoot(Parent[v]); } public UnionFind(int size) { Parent = new int[size]; for (int i = 0; i < size; i++) Parent[i] = -1; } public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); } public void Connect(int a, int b) { a = GetRoot(a); b = GetRoot(b); if (a == b) return; Parent[b] += Parent[a]; Parent[a] = b; } public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; } } public class TreeBuilder { public int Size; public List<Tuple<int, int>>[] Child; public TreeBuilder(int size) { Size = size; Child = new List<Tuple<int, int>>[size]; for (int i = 0; i < size; i++) { Child[i] = new List<Tuple<int, int>>(); } } public void RegistEdge(int a, int b, int cost) { Child[a].Add(Tuple.Create(b, cost)); Child[b].Add(Tuple.Create(a, cost)); } public Tree BuildTree(int Root) { int[] Parent = new int[Size]; Queue<int> Search = new Queue<int>(); Search.Enqueue(Root); var Prev = Root; while (Search.Count > 0) { } return null; } } public class Tree { public int[] Parent; public int[] ParentDist; private int GetRoot(int v) { if (Parent[v] == v) return v; else return Parent[v] = GetRoot(Parent[v]); } public Tree() {} public void Add(int Target, int cost) {} } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 11, 31, 204, 205, 22], ["+", 75, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 75, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 1, 0, 11, 12, 204, 205, 22], ["+", 75, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 75, 1, 0, 35]]
8
1,118
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_120 { class UnionFind { private int N; private int[] parents; //親の番号を格納. 親の場合は-(メンバサイズ) public UnionFind(int n) { parents = new int[n]; for (int i = 0; i < n; i++) parents[i] = -1; N = n; } //グループのボスを取得 public int Root(int x) { if (parents[x] < 0) return x; parents[x] = Root(parents[x]); //次からはボスに直結するように構造を変える return parents[x]; } //グループのメンバ数 public int Size(int x) { int r = Root(x); return -parents[x]; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return false; //メンバサイズが大きい方をボスとして合併 if (Size(x) < Size(y)) { parents[y] += parents[x]; parents[x] = y; } else { parents[x] += parents[y]; parents[y] = x; } return true; } } class D { static void Main(string[] args) { int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int N = a[0], M = a[1]; List<int[]> list = new List<int[]>(); for (int i = 0; i < M; i++) { int[] b = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); list.Add(b); } UnionFind uf = new UnionFind(N); long r = (long)N * (N - 1) / 2; long[] numUnconnected = new long[M]; numUnconnected[M - 1] = r; for (int i = 0; i < M - 1; i++) { int[] b = list[M - 1 - i]; int A = b[0] - 1, B = b[1] - 1; if (uf.Root(A) != uf.Root(B)) { r -= uf.Size(A) * uf.Size(B); uf.Unite(A, B); } // long r = uf.GetInvalid(); numUnconnected[M - 2 - i] = r; } for (int i = 0; i < M; i++) { Console.WriteLine(numUnconnected[i]); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_120 { class UnionFind { private int N; private int[] parents; //親の番号を格納. 親の場合は-(メンバサイズ) public UnionFind(int n) { parents = new int[n]; for (int i = 0; i < n; i++) parents[i] = -1; N = n; } //グループのボスを取得 public int Root(int x) { if (parents[x] < 0) return x; parents[x] = Root(parents[x]); //次からはボスに直結するように構造を変える return parents[x]; } //グループのメンバ数 public int Size(int x) { int r = Root(x); return -parents[r]; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return false; //メンバサイズが大きい方をボスとして合併 if (Size(x) < Size(y)) { parents[y] += parents[x]; parents[x] = y; } else { parents[x] += parents[y]; parents[y] = x; } return true; } } class D { static void Main(string[] args) { int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int N = a[0], M = a[1]; List<int[]> list = new List<int[]>(); for (int i = 0; i < M; i++) { int[] b = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); list.Add(b); } UnionFind uf = new UnionFind(N); long r = (long)N * (N - 1) / 2; long[] numUnconnected = new long[M]; numUnconnected[M - 1] = r; for (int i = 0; i < M - 1; i++) { int[] b = list[M - 1 - i]; int A = b[0] - 1, B = b[1] - 1; if (uf.Root(A) != uf.Root(B)) { long sa = (long)uf.Size(A); long sb = (long)uf.Size(B); r -= sa * sb; uf.Unite(A, B); } numUnconnected[M - 2 - i] = r; } for (int i = 0; i < M; i++) { Console.WriteLine(numUnconnected[i]); } } } }
[["-", 0, 241, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 241, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
561
24
using System; using System.Collections.Generic; using System.Linq; namespace test { class Program { static void Main(string[] args) { var input = ReadArrayInt(); var N = input[0]; var M = input[1]; var bridge = new int[M, 2]; for (int i = 0; i < M; i++) { input = ReadArrayInt(); bridge[i, 0] = input[0] - 1; bridge[i, 1] = input[1] - 1; } var uf = new UnionFind(N); var ans = new long[M]; ans[M - 1] = (long)N * (N - 1) / 2; for (int i = M - 1; i > 0; i--) { var A = bridge[i, 0]; var B = bridge[i, 1]; if (!uf.Same(A, B)) { ans[i - 1] = ans[i] - uf.Size(A) * uf.Size(B); uf.Unite(A, B); } } foreach (var a in ans) Console.WriteLine(a); Console.WriteLine(); Console.ReadLine(); } static string Read() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Read()); } static long ReadLong() { return long.Parse(Read()); } static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); } static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); } } class UnionFind { int[] par; int[] sizes; public UnionFind(int n) { par = new int[n]; sizes = new int[n]; for (var i = 0; i < n; i++) { par[i] = i; sizes[i] = 1; } } public int Root(int x) { return par[x] == x ? x : par[x] = Root(par[x]); } public bool Same(int x, int y) { return Root(x) == Root(y); } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return; if (sizes[x] < sizes[y]) { par[x] = y; sizes[y] += sizes[x]; sizes[x] = 0; } else { par[y] = x; sizes[x] += sizes[y]; sizes[y] = 0; } } public int Size(int x) { return sizes[Root(x)]; } } }
using System; using System.Collections.Generic; using System.Linq; namespace test { class Program { static void Main(string[] args) { var input = ReadArrayInt(); var N = input[0]; var M = input[1]; var bridge = new int[M, 2]; for (int i = 0; i < M; i++) { input = ReadArrayInt(); bridge[i, 0] = input[0] - 1; bridge[i, 1] = input[1] - 1; } var uf = new UnionFind(N); var ans = new long[M]; ans[M - 1] = (long)N * (N - 1) / 2; for (int i = M - 1; i > 0; i--) { var A = bridge[i, 0]; var B = bridge[i, 1]; if (!uf.Same(A, B)) { ans[i - 1] = ans[i] - uf.Size(A) * uf.Size(B); uf.Unite(A, B); } else { ans[i - 1] = ans[i]; } } foreach (var a in ans) Console.WriteLine(a); Console.WriteLine(); Console.ReadLine(); } static string Read() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Read()); } static long ReadLong() { return long.Parse(Read()); } static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); } static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); } } class UnionFind { int[] par; int[] sizes; public UnionFind(int n) { par = new int[n]; sizes = new int[n]; for (var i = 0; i < n; i++) { par[i] = i; sizes[i] = 1; } } public int Root(int x) { return par[x] == x ? x : par[x] = Root(par[x]); } public bool Same(int x, int y) { return Root(x) == Root(y); } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return; if (sizes[x] < sizes[y]) { par[x] = y; sizes[y] += sizes[x]; sizes[x] = 0; } else { par[y] = x; sizes[x] += sizes[y]; sizes[y] = 0; } } public int Size(int x) { return sizes[Root(x)]; } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
631
15
#define TEST using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Linq; using UnionFind; class Program { static int N; static int M; static int[] A; static int[] B; static void Main() { int[] inp = Console.ReadLine().Split().Select(int.Parse).ToArray(); N = inp[0]; M = inp[1]; A = new int[M]; B = new int[M]; for (int i = 0; i < M; i++) { inp = Console.ReadLine().Split().Select(int.Parse).ToArray(); A[i] = inp[0] - 1; B[i] = inp[1] - 1; } long[] ans = new long[M]; ans[M - 1] = (long)N * (N - 1) / 2; UF uf = new UF(N); for (int i = M - 1; i > 0; i--) { long a = uf.siz[A[i]]; long b = uf.siz[B[i]]; if (uf.Unite(A[i], B[i])) { ans[i - 1] = ans[i] - (a * b); continue; } ans[i - 1] = ans[i]; } foreach (var i in ans) Console.WriteLine(i); } } namespace UnionFind { class UF { private int[] 親; //親[i] : iの親の番号 public int[] siz; public int size; public UF(int N) //コンストラクタ、すべてが根として初期化 { 親 = new int[N]; for (int i = 0; i < N; i++) 親[i] = i; size = N; siz = new int[N]; for (int i = 0; i < N; i++) siz[i] = 1; } public int Root(int x) // xの属する木の根を返す { if (親[x] == x) return x; return 親[x] = Root(親[x]); } public bool Unite(int x, int y) // xとyの木を統合 { int rx = Root(x); int ry = Root(y); if (rx == ry) return false; 親[rx] = ry; size--; int t = siz[rx]; siz[rx] += siz[ry]; siz[ry] += t; return true; } public bool Same(int x, int y) // xとyが同じ木に属するかどうかを返す { return Root(x) == Root(y); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Linq; using UnionFind; class Program { static int N; static int M; static int[] A; static int[] B; static void Main() { int[] inp = Console.ReadLine().Split().Select(int.Parse).ToArray(); N = inp[0]; M = inp[1]; A = new int[M]; B = new int[M]; for (int i = 0; i < M; i++) { inp = Console.ReadLine().Split().Select(int.Parse).ToArray(); A[i] = inp[0] - 1; B[i] = inp[1] - 1; } long[] ans = new long[M]; ans[M - 1] = (long)N * (N - 1) / 2; UF uf = new UF(N); for (int i = M - 1; i > 0; i--) { long a = uf.siz[uf.Root(A[i])]; long b = uf.siz[uf.Root(B[i])]; if (uf.Unite(A[i], B[i])) { ans[i - 1] = ans[i] - (a * b); continue; } ans[i - 1] = ans[i]; } foreach (var i in ans) Console.WriteLine(i); } } namespace UnionFind { class UF { private int[] 親; //親[i] : iの親の番号 public int[] siz; public int size; public UF(int N) //コンストラクタ、すべてが根として初期化 { 親 = new int[N]; for (int i = 0; i < N; i++) 親[i] = i; size = N; siz = new int[N]; for (int i = 0; i < N; i++) siz[i] = 1; } public int Root(int x) // xの属する木の根を返す { if (親[x] == x) return x; return 親[x] = Root(親[x]); } public bool Unite(int x, int y) // xとyの木を統合 { int rx = Root(x); int ry = Root(y); if (rx == ry) return false; 親[rx] = ry; size--; int t = siz[rx]; siz[rx] += siz[ry]; siz[ry] += t; return true; } public bool Same(int x, int y) // xとyが同じ木に属するかどうかを返す { return Root(x) == Root(y); } } }
[["-", 36, 36, 36, 36, 36, 36, 36, 36, 0, 208], ["-", 36, 36, 36, 36, 36, 36, 0, 208, 0, 323], ["-", 36, 36, 36, 36, 0, 208, 0, 323, 0, 22], ["-", 36, 36, 0, 208, 0, 323, 0, 22, 0, 231], ["-", 0, 208, 0, 323, 0, 22, 0, 231, 141, 22], ["-", 0, 323, 0, 22, 0, 231, 141, 22, 0, 231], ["-", 0, 22, 0, 231, 141, 22, 0, 231, 141, 232], ["-", 0, 231, 141, 22, 0, 231, 141, 232, 234, 232], ["-", 141, 22, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 0, 231, 141, 232, 234, 232, 141, 22, 0, 231], ["-", 141, 232, 234, 232, 141, 22, 0, 231, 141, 232], ["-", 234, 232, 141, 22, 0, 231, 141, 232, 234, 22], ["-", 141, 22, 0, 231, 141, 232, 234, 22, 141, 22], ["-", 0, 231, 141, 232, 234, 22, 141, 22, 0, 231], ["-", 141, 232, 234, 22, 141, 22, 0, 231, 141, 232], ["-", 234, 22, 141, 22, 0, 231, 141, 232, 234, 22], ["-", 141, 232, 234, 22, 141, 22, 0, 231, 141, 22], ["-", 234, 22, 141, 22, 0, 231, 141, 22, 0, 235], ["-", 141, 22, 0, 231, 141, 22, 0, 235, 141, 22], ["-", 0, 231, 141, 22, 0, 235, 141, 22, 8, 201], ["-", 141, 22, 0, 235, 141, 22, 8, 201, 0, 124], ["-", 0, 235, 141, 22, 8, 201, 0, 124, 0, 124], ["-", 141, 22, 8, 201, 0, 124, 0, 124, 0, 124], ["-", 8, 201, 0, 124, 0, 124, 0, 124, 0, 124], ["-", 0, 124, 0, 124, 0, 124, 0, 124, 0, 195], ["-", 0, 124, 0, 124, 0, 124, 0, 195, 0, 209], ["-", 0, 124, 0, 124, 0, 195, 0, 209, 141, 22], ["-", 0, 124, 0, 195, 0, 209, 141, 22, 8, 201], ["-", 0, 195, 0, 209, 141, 22, 8, 201, 0, 235], ["-", 36, 36, 36, 36, 0, 208, 0, 323, 0, 324], ["+", 206, 207, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 206, 207, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 206, 207, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 206, 207, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 206, 207, 0, 28, 0, 213, 3, 4, 0, 25]]
8
562
13
using System; namespace ABC119 { class A { static void Main(string[] args) { string s = Console.ReadLine(); Console.WriteLine(s.CompareTo("2019/04/30")); if (0 < s.CompareTo("2019/04/30")) Console.WriteLine("TBD"); else Console.WriteLine("Heisei"); } } }
using System; namespace ABC119 { class A { static void Main(string[] args) { string s = Console.ReadLine(); if (0 < s.CompareTo("2019/04/30")) Console.WriteLine("TBD"); else Console.WriteLine("Heisei"); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
77
14
using System; using System.Linq; using System.IO; using System.Collections.Generic; using System.Text; namespace AtCoder { public class Program { static int[] getKeys() { var Keys = Console.ReadLine().Split(' '); int N = Keys.Length; int[] Ns = new int[N]; for (int i = 0; i < N; i++) { Ns[i] = int.Parse(Keys[i]); } return Ns; } static int[] getKeys(char delimiter) { var Keys = Console.ReadLine().Split(delimiter); int N = Keys.Length; int[] Ns = new int[N]; for (int i = 0; i < N; i++) { Ns[i] = int.Parse(Keys[i]); } return Ns; } public static void Show<T>(T[,] map) { int H = map.GetLength(0); int W = map.GetLength(1); Console.WriteLine("-------------------------"); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { Console.Write(map[i, j] + " "); } Console.WriteLine(); } Console.WriteLine("-------------------------"); } public static void Show<T>(T[,] map, string delimiter) { int H = map.GetLength(0); int W = map.GetLength(1); Console.WriteLine("-------------------------"); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { Console.Write(map[i, j] + delimiter); } Console.WriteLine(); } Console.WriteLine("-------------------------"); } public static void Show<T>(IEnumerable<T> ts) { foreach (var item in ts) { Console.Write(item + " "); } Console.WriteLine(); } public static void Show<T>(IEnumerable<T> ts, string delimiter) { foreach (var item in ts) { Console.Write(item + delimiter); } Console.WriteLine(); } static void Main() { t(); Console.Read(); var input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); long K = long.Parse(input[1]); int digits = Convert.ToString(K, 2).Length; int[] isOne = new int[digits]; input = Console.ReadLine().Split(' '); var Keys = new long[N]; for (int i = 0; i < N; i++) { Keys[i] = long.Parse(input[i]); var bits = Convert.ToString(Keys[i], 2); int length = Math.Min(bits.Length, digits); for (int j = 0; j < length; j++) { if (bits[bits.Length - j - 1] == '1') { isOne[j]++; } } } long X = 0; for (int i = 0; i < digits; i++) { if (isOne[i] < N - isOne[i]) { //多数決で0が多かった桁->1 X += (long)Math.Pow(2, i); } } if (X > K) { string Kbin = Convert.ToString(K, 2); string Xbin = Convert.ToString(X, 2); // Console.WriteLine(Kbin); // Console.WriteLine(Xbin); int errorBit = 0; for (int i = 0; i < Kbin.Length; i++) { if (Xbin[i] - Kbin[i] > 0) { errorBit = Kbin.Length - i - 1; X -= (long)Math.Pow(2, Kbin.Length - i - 1); if (X <= K) break; } } } long answer = 0; for (int i = 0; i < N; i++) { // Console.WriteLine("{0}^{1}={2}", X, Keys[i], X ^ // Keys[i]); answer += X ^ Keys[i]; } Console.WriteLine(answer); } static void t() { long X = 32 + 16 + 8 + 2; long K = 32 + 4; string Kbin = Convert.ToString(K, 2); string Xbin = Convert.ToString(X, 2); // Console.WriteLine(Kbin); // Console.WriteLine(Xbin); int errorBit = 0; for (int i = 0; i < Kbin.Length; i++) { if (Xbin[i] - Kbin[i] > 0) { errorBit = Kbin.Length - i - 1; X -= (long)Math.Pow(2, Kbin.Length - i - 1); } } Console.WriteLine(X); } } }
using System; using System.Linq; using System.IO; using System.Collections.Generic; using System.Text; namespace AtCoder { public class Program { static int[] getKeys() { var Keys = Console.ReadLine().Split(' '); int N = Keys.Length; int[] Ns = new int[N]; for (int i = 0; i < N; i++) { Ns[i] = int.Parse(Keys[i]); } return Ns; } static int[] getKeys(char delimiter) { var Keys = Console.ReadLine().Split(delimiter); int N = Keys.Length; int[] Ns = new int[N]; for (int i = 0; i < N; i++) { Ns[i] = int.Parse(Keys[i]); } return Ns; } public static void Show<T>(T[,] map) { int H = map.GetLength(0); int W = map.GetLength(1); Console.WriteLine("-------------------------"); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { Console.Write(map[i, j] + " "); } Console.WriteLine(); } Console.WriteLine("-------------------------"); } public static void Show<T>(T[,] map, string delimiter) { int H = map.GetLength(0); int W = map.GetLength(1); Console.WriteLine("-------------------------"); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { Console.Write(map[i, j] + delimiter); } Console.WriteLine(); } Console.WriteLine("-------------------------"); } public static void Show<T>(IEnumerable<T> ts) { foreach (var item in ts) { Console.Write(item + " "); } Console.WriteLine(); } public static void Show<T>(IEnumerable<T> ts, string delimiter) { foreach (var item in ts) { Console.Write(item + delimiter); } Console.WriteLine(); } static void Main() { var input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); long K = long.Parse(input[1]); int digits = Convert.ToString(K, 2).Length; int[] isOne = new int[digits]; input = Console.ReadLine().Split(' '); var Keys = new long[N]; for (int i = 0; i < N; i++) { Keys[i] = long.Parse(input[i]); var bits = Convert.ToString(Keys[i], 2); int length = Math.Min(bits.Length, digits); for (int j = 0; j < length; j++) { if (bits[bits.Length - j - 1] == '1') { isOne[j]++; } } } long X = 0; for (int i = 0; i < digits; i++) { if (isOne[i] < N - isOne[i]) { //多数決で0が多かった桁->1 X += (long)Math.Pow(2, i); } } if (X > K) { string Kbin = Convert.ToString(K, 2); string Xbin = Convert.ToString(X, 2); // Console.WriteLine(Kbin); // Console.WriteLine(Xbin); int errorBit = 0; for (int i = 0; i < Kbin.Length; i++) { if (Xbin[i] - Kbin[i] > 0) { errorBit = Kbin.Length - i - 1; X -= (long)Math.Pow(2, Kbin.Length - i - 1); if (X <= K) break; } } } long answer = 0; for (int i = 0; i < N; i++) { // Console.WriteLine("{0}^{1}={2}", X, Keys[i], X ^ // Keys[i]); answer += X ^ Keys[i]; } Console.WriteLine(answer); } static void t() { long X = 32 + 16 + 8 + 2; long K = 32 + 4; string Kbin = Convert.ToString(K, 2); string Xbin = Convert.ToString(X, 2); // Console.WriteLine(Kbin); // Console.WriteLine(Xbin); int errorBit = 0; for (int i = 0; i < Kbin.Length; i++) { if (Xbin[i] - Kbin[i] > 0) { errorBit = Kbin.Length - i - 1; X -= (long)Math.Pow(2, Kbin.Length - i - 1); } } Console.WriteLine(X); } } }
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22]]
8
1,028
10
using System; namespace Subscribers { class Program { static void Main(string[] args) { String[] s = Console.ReadLine().Split(' '); int n = int.Parse(s[0]); int a = int.Parse(s[1]); int b = int.Parse(s[2]); Console.WriteLine(String.Format("{0} {1}", a < b ? a : b, a + b - n)); } } }
using System; namespace Subscribers { class Program { static void Main(string[] args) { String[] s = Console.ReadLine().Split(' '); int n = int.Parse(s[0]); int a = int.Parse(s[1]); int b = int.Parse(s[2]); int min = a + b - n; Console.WriteLine( String.Format("{0} {1}", a < b ? a : b, min < 0 ? 0 : min)); } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 22]]
8
107
21
using System; namespace AtCoder { class Program { public static void Main(string[] args) { string line = Console.ReadLine(); int N = int.Parse(line); string A = Console.ReadLine(); string B = Console.ReadLine(); string C = Console.ReadLine(); int ans = 0; for (int i = 0; i < N - 1; i++) { if (A[i] == B[i] && A[i] == C[i]) { } else if (A[i] != B[i] && A[i] != C[i] && B[i] == C[i]) { ans++; } else if (A[i] == B[i] && A[i] != C[i]) { ans++; } else if (A[i] != B[i] && A[i] == C[i]) { ans++; } else { ans += 2; } } Console.WriteLine("{0}", ans); } } }
using System; namespace AtCoder { class Program { public static void Main(string[] args) { string line = Console.ReadLine(); int N = int.Parse(line); string A = Console.ReadLine(); string B = Console.ReadLine(); string C = Console.ReadLine(); int ans = 0; for (int i = 0; i < N; i++) { if (A[i] == B[i] && A[i] == C[i]) { } else if (A[i] != B[i] && B[i] == C[i]) { ans++; } else if (A[i] == B[i] && B[i] != C[i]) { ans++; } else if (A[i] != B[i] && A[i] == C[i]) { ans++; } else { ans += 2; } } Console.WriteLine("{0}", ans); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 31, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 31, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 98], ["-", 15, 16, 31, 16, 12, 16, 31, 204, 205, 22], ["-", 31, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 31, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 75, 57, 15, 16, 31, 16, 12, 16, 17, 79], ["-", 15, 16, 31, 16, 12, 16, 12, 204, 205, 22], ["-", 75, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 75, 57, 15, 16, 12, 16, 31, 204, 205, 22]]
8
228
14
using System; using System.Linq; using System.Collections.Generic; class Program { /// <summary> /// The main entry point for the application /// </summary> [STAThread] public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); long[] a = new long[n]; long[] b = new long[n]; long[] c = new long[n]; for (int i = 0; i < n; i++) { string[] s = Console.ReadLine().Split(' '); a[i] = int.Parse(s[0]); b[i] = int.Parse(s[1]); } for (int i = 0; i < n; i++) { c[i] = a[i] + b[i]; } Array.Reverse(c); long ans = c.Where((_, i) => i % 2 == 0).Sum() - b.Sum(); Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; class Program { /// <summary> /// The main entry point for the application /// </summary> [STAThread] public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); long[] a = new long[n]; long[] b = new long[n]; long[] c = new long[n]; for (int i = 0; i < n; i++) { string[] s = Console.ReadLine().Split(' '); a[i] = int.Parse(s[0]); b[i] = int.Parse(s[1]); } for (int i = 0; i < n; i++) { c[i] = a[i] + b[i]; } Array.Sort(c); Array.Reverse(c); long ans = c.Where((value, index) => index % 2 == 0).Sum() - b.Sum(); Console.WriteLine(ans); } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["+", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["-", 0, 28, 0, 218, 8, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 31, 22]]
8
223
13
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Collections; namespace AtCoder { class Program { static void Main(string[] args) { var ir = new Resolver(new ConsoleReader()); Console.WriteLine(ir.Resolve()); } } public class Resolver { IInputReader InputReader { get; } public List<string> Messages { get; set; } = new List<string>(); int n; List<long[]> ls = new List<long[]>(); public void ParseLines() { n = int.Parse(InputReader.ReadLine()); foreach (var i in Enumerable.Range(0, n)) { ls.Add(InputReader.ReadLine() .Split(' ') .Select(x => long.Parse(x)) .ToArray()); } } public class Table { public long PointA { get; set; } = 0; Person A { get; } Person B { get; } int[] _dishes; public Table(Person a, Person b, int ndish) { this.A = a; this.B = b; this._dishes = Enumerable.Range(0, ndish).ToArray(); } public long CalculatePoint() { _dishes.Select(x => A.Taste[x] + B.Taste[x]) .OrderBy(x => -x) .Select((x, i) => { if (i % 2 == 0) { PointA += x; } return 0; }); PointA -= B.Taste.Values.Sum(x => x); return PointA; } } public class Person { public Dictionary<int, long> Taste { get; } public long HappyScore { get; set; } = 0; public Person(Dictionary<int, long> taste) { Taste = taste; } } public string Resolve() { var range = Enumerable.Range(0, n); var a = new Person(range.ToDictionary(i => i, i => ls[i][0])); var b = new Person(range.ToDictionary(i => i, i => ls[i][1])); var table = new Table(a, b, n); return table.CalculatePoint().ToString(); } public Resolver(IInputReader inputReader) { InputReader = inputReader; ParseLines(); } } public interface IInputReader { string ReadLine(); } class ConsoleReader : IInputReader { string IInputReader.ReadLine() { return Console.ReadLine(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Collections; namespace AtCoder { class Program { static void Main(string[] args) { var ir = new Resolver(new ConsoleReader()); Console.WriteLine(ir.Resolve()); } } public class Resolver { IInputReader InputReader { get; } public List<string> Messages { get; set; } = new List<string>(); int n; List<long[]> ls = new List<long[]>(); public void ParseLines() { n = int.Parse(InputReader.ReadLine()); foreach (var i in Enumerable.Range(0, n)) { ls.Add(InputReader.ReadLine() .Split(' ') .Select(x => long.Parse(x)) .ToArray()); } } public class Table { public long PointA { get; set; } = 0; Person A { get; } Person B { get; } int[] _dishes; public Table(Person a, Person b, int ndish) { this.A = a; this.B = b; this._dishes = Enumerable.Range(0, ndish).ToArray(); } public long CalculatePoint() { PointA = _dishes.Select(x => A.Taste[x] + B.Taste[x]) .OrderBy(x => -x) .Where((x, i) => i % 2 == 0) .Sum(); PointA -= B.Taste.Values.Sum(x => x); return PointA; } } public class Person { public Dictionary<int, long> Taste { get; } public long HappyScore { get; set; } = 0; public Person(Dictionary<int, long> taste) { Taste = taste; } } public string Resolve() { var range = Enumerable.Range(0, n); var a = new Person(range.ToDictionary(i => i, i => ls[i][0])); var b = new Person(range.ToDictionary(i => i, i => ls[i][1])); var table = new Table(a, b, n); return table.CalculatePoint().ToString(); } public Resolver(IInputReader inputReader) { InputReader = inputReader; ParseLines(); } } public interface IInputReader { string ReadLine(); } class ConsoleReader : IInputReader { string IInputReader.ReadLine() { return Console.ReadLine(); } } }
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 196, 0, 45], ["-", 0, 28, 0, 218, 8, 196, 0, 57, 0, 121], ["-", 0, 28, 0, 218, 8, 196, 0, 57, 0, 24], ["-", 0, 218, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 218, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 28, 0, 218, 8, 196, 0, 37, 0, 38], ["-", 0, 28, 0, 218, 8, 196, 0, 37, 0, 203], ["-", 0, 28, 0, 218, 8, 196, 0, 37, 0, 35], ["-", 3, 4, 0, 28, 0, 218, 8, 196, 0, 46], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24]]
8
540
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List<test> list幸福度 = new List<test>(); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int kouhuku = A + B; test 幸福度 = new test(kouhuku, A, B); list幸福度.Add(幸福度); } list幸福度 = new List<test>(list幸福度.OrderByDescending(x => x.幸福度)); int 高橋 = 0; int 青木 = 0; for (int i = 0; i < list幸福度.Count; i++) { if (i % 2 == 1) { 青木 += list幸福度[i].B; } else { 高橋 += list幸福度[i].A; } } Console.WriteLine(高橋 - 青木); } } class test { public int 幸福度 { get; set; } public int A { get; set; } public int B { get; set; } public test(int 幸福度, int A, int B) { this.幸福度 = 幸福度; this.A = A; this.B = B; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List<test> list幸福度 = new List<test>(); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(' '); long A = long.Parse(input[0]); long B = long.Parse(input[1]); long kouhuku = A + B; test 幸福度 = new test(kouhuku, A, B); list幸福度.Add(幸福度); } list幸福度 = new List<test>(list幸福度.OrderByDescending(x => x.幸福度)); long 高橋 = 0; long 青木 = 0; for (int i = 0; i < list幸福度.Count; i++) { if (i % 2 == 1) { 青木 += list幸福度[i].B; } else { 高橋 += list幸福度[i].A; } } Console.WriteLine(高橋 - 青木); } } class test { public long 幸福度 { get; set; } public long A { get; set; } public long B { get; set; } public test(long 幸福度, long A, long B) { this.幸福度 = 幸福度; this.A = A; this.B = B; } }
[["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 201, 0, 195, 8, 196, 0, 42, 0, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 42, 0, 199], ["-", 0, 235, 8, 201, 0, 277, 0, 42, 0, 199], ["+", 0, 235, 8, 201, 0, 277, 0, 42, 0, 199], ["-", 0, 208, 0, 235, 8, 201, 0, 277, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 277, 39, 199], ["-", 8, 201, 0, 263, 54, 55, 0, 42, 0, 199], ["+", 8, 201, 0, 263, 54, 55, 0, 42, 0, 199], ["-", 8, 201, 0, 263, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 263, 54, 55, 0, 220, 39, 199]]
8
309
26
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { Sc sc = new Sc(); int n = sc.I; long[][] a = new long [n][]; long ans = 0; for (int i = 0; i < n; i++) { a[i] = sc.La; } Array.Sort(a, ca); for (int i = 0; i < n; i++) { ans += i % 2 == 0 ? a[i][0] : -a[i][1]; } Console.WriteLine("{0}", ans); } static int ca(long[] a, long[] b) { if (a[0] + b[0] < a[0] + b[0]) { return 1; } else if (a[0] + b[0] > a[0] + b[0]) { return -1; } else { return 0; } } } class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { Sc sc = new Sc(); int n = sc.I; long[][] a = new long [n][]; long ans = 0; for (int i = 0; i < n; i++) { a[i] = sc.La; } Array.Sort(a, ca); for (int i = 0; i < n; i++) { ans += i % 2 == 0 ? a[i][0] : -a[i][1]; } Console.WriteLine("{0}", ans); } static int ca(long[] a, long[] b) { if (a[0] + a[1] < b[0] + b[1]) { return 1; } else if (a[0] + a[1] > b[0] + b[1]) { return -1; } else { return 0; } } } class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } }
[["-", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 75, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 75, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["-", 75, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 75, 57, 15, 16, 12, 16, 31, 204, 205, 22]]
8
394
16
using System; class NIKKEIC { static void Main(string[] args) { Method(args); } static void Method(string[] args) { int n = int.Parse(Console.ReadLine()); long[] a = new long[n]; long[] b = new long[n]; for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(' '); a[i] = long.Parse(input[0]); b[i] = long.Parse(input[1]); } long[] c = new long[n]; for (int i = 0; i < n; i++) { c[i] = a[i] - b[i]; } QuickSort(c, a, 0, n - 1); long taka = 0; long aoki = 0; for (int i = 0; i < n - 1; i += 2) { taka += a[i]; aoki += a[i + 1] - c[i + 1]; } if (n % 2 == 1) taka += a[n - 1]; Console.WriteLine(taka - aoki); } public static void QuickSort<T>(T[] array, T[] srray, int left, int right) where T : IComparable<T> { if (left < right) { // ピボット決定(配列の先頭、真ん中、末尾の3つの値の中央値とする) T pivot = Median(array[left], array[(left + (right - left) / 2)], array[right]); int l = left; int r = right; // ピボットを中心に、分ける while (true) { // ピボットより小さいデータのインデックスを見つける while (array[l].CompareTo(pivot) < 0) l++; // ピボットより大きいデータのインデックスを見つける while (array[r].CompareTo(pivot) > 0) r--; // 見つかったインデックスの大小が逆転していれば、終了 if (l >= r) break; // 見つかった要素を交換 Swap(ref array[l], ref array[r], ref srray[l], ref srray[r]); l++; r--; } // 左右に分けた配列を再帰的にソート QuickSort(array, srray, left, l - 1); QuickSort(array, srray, r + 1, right); } } // 3値の中から中央値を返す public static T Median<T>(T x, T y, T z) where T : IComparable<T> { if (x.CompareTo(y) < 0) { return x.CompareTo(z) < 0 ? (y.CompareTo(z) < 0 ? y : z) : x; } else { return y.CompareTo(z) < 0 ? (x.CompareTo(z) < 0 ? x : z) : y; } } public static void Swap<T>(ref T a, ref T b, ref T c, ref T d) { var tmp = a; var temp = c; a = b; b = tmp; c = d; d = temp; } }
using System; class NIKKEIC { static void Main(string[] args) { Method(args); } static void Method(string[] args) { int n = int.Parse(Console.ReadLine()); long[] a = new long[n]; long[] b = new long[n]; for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(' '); a[i] = long.Parse(input[0]); b[i] = long.Parse(input[1]); } long[] c = new long[n]; for (int i = 0; i < n; i++) { c[i] = a[i] + b[i]; } QuickSort(c, a, 0, n - 1); long taka = 0; long aoki = 0; for (int i = n - 1; i > 0; i -= 2) { taka += a[i]; aoki += c[i - 1] - a[i - 1]; } if (n % 2 != 0) taka += a[0]; Console.WriteLine(taka - aoki); } public static void QuickSort<T>(T[] array, T[] srray, int left, int right) where T : IComparable<T> { if (left < right) { // ピボット決定(配列の先頭、真ん中、末尾の3つの値の中央値とする) T pivot = Median(array[left], array[(left + (right - left) / 2)], array[right]); int l = left; int r = right; // ピボットを中心に、分ける while (true) { // ピボットより小さいデータのインデックスを見つける while (array[l].CompareTo(pivot) < 0) l++; // ピボットより大きいデータのインデックスを見つける while (array[r].CompareTo(pivot) > 0) r--; // 見つかったインデックスの大小が逆転していれば、終了 if (l >= r) break; // 見つかった要素を交換 Swap(ref array[l], ref array[r], ref srray[l], ref srray[r]); l++; r--; } // 左右に分けた配列を再帰的にソート QuickSort(array, srray, left, l - 1); QuickSort(array, srray, r + 1, right); } } // 3値の中から中央値を返す public static T Median<T>(T x, T y, T z) where T : IComparable<T> { if (x.CompareTo(y) < 0) { return x.CompareTo(z) < 0 ? (y.CompareTo(z) < 0 ? y : z) : x; } else { return y.CompareTo(z) < 0 ? (x.CompareTo(z) < 0 ? x : z) : y; } } public static void Swap<T>(ref T a, ref T b, ref T c, ref T d) { var tmp = a; var temp = c; a = b; b = tmp; c = d; d = temp; } }
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 31, 22], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 110], ["-", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203]]
8
612
28
using System; using System.Collections.Generic; using System.Linq; public class Dish { public int A; public int B; public int Max; public Dish(int a, int b) { A = a; B = b; Max = Math.Max(a, b); } } public class Solution { public static void Main() { var n = int.Parse(Console.ReadLine()); var dishs = new Dish[n]; for (int i = 0; i < n; i++) { var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); dishs[i] = new Dish(vals[0], vals[1]); } dishs = dishs.OrderBy(d => d.Max).ToArray(); long diff = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { diff += dishs[i].A; } else { diff -= dishs[i].B; } } Console.WriteLine(diff); } }
using System; using System.Collections.Generic; using System.Linq; public class Dish { public int A; public int B; public Dish(int a, int b) { A = a; B = b; } } public class Solution { public static void Main() { var n = int.Parse(Console.ReadLine()); var dishs = new Dish[n]; for (int i = 0; i < n; i++) { var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); dishs[i] = new Dish(vals[0], vals[1]); } dishs = dishs.OrderByDescending(d => d.A + d.B).ToArray(); long diff = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { diff += dishs[i].A; } else { diff -= dishs[i].B; } } Console.WriteLine(diff); } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 0, 208, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 235, 8, 201, 0, 263, 0, 251, 0, 259], ["-", 0, 263, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 263, 8, 196, 0, 1, 0, 35], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 72], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 141, 22]]
8
236
23
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Competitive { internal class Solution { public int N; public long MOD = 1000000007; public long[] A, B, X; public void Run() { N = Input.ReadInt(); A = new long[N]; B = new long[N]; X = new long[N]; for (int i = 0; i < N; i++) { var line = Input.ReadIntArray(); A[i] = line[0]; B[i] = line[1]; X[i] = A[i] + B[i]; } Data[] D = new Data[N]; for (int i = 0; i < N; i++) { D[i] = new Data(X[i], i); } Array.Sort(D, Data.CompareTo); long ret = 0; for (int i = 0; i < N; i++) { int ii = D[i].index; if (i % 2 == 0) ret += A[ii]; else ret -= B[ii]; } Console.WriteLine(ret); } } // libs ---------- // 比較のみ class Data { public long x; public int index; public Data(long x, int index) { this.x = x; this.index = index; } // SortするときのComparerは明示的に指定する public static int CompareTo(Data d1, Data d2) { int result = d1.x.CompareTo(d2.x); if (result == 0) result = d1.index.CompareTo(d2.index); return result; } } // common ---------- internal static class Input { public static string ReadString() { string line = Console.ReadLine(); return line; } public static int ReadInt() { string line = Console.ReadLine(); return int.Parse(line); } public static int[] ReadIntArray() { string line = Console.ReadLine(); return line.Split(' ').Select(int.Parse).ToArray(); } public static long ReadLong() { string line = Console.ReadLine(); return long.Parse(line); } public static long[] ReadLongArray() { string line = Console.ReadLine(); return line.Split(' ').Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { string line = Console.ReadLine(); return line.Split(' ').Select(double.Parse).ToArray(); } } internal class Program { public static void Main(string[] args) { var s = new Solution(); s.Run(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Competitive { internal class Solution { public int N; public long MOD = 1000000007; public long[] A, B, X; public void Run() { N = Input.ReadInt(); A = new long[N]; B = new long[N]; X = new long[N]; for (int i = 0; i < N; i++) { var line = Input.ReadIntArray(); A[i] = line[0]; B[i] = line[1]; X[i] = A[i] + B[i]; } // 順位は Data[] D = new Data[N]; for (int i = 0; i < N; i++) { D[i] = new Data(X[i], i); } Array.Sort(D, Data.CompareTo); Array.Reverse(D); long ret = 0; for (int i = 0; i < N; i++) { // 選ぶのはソート順 int index = D[i].index; if (i % 2 == 0) ret += A[index]; else ret -= B[index]; } Console.WriteLine(ret); } } // libs ---------- // 比較のみ class Data { public long x; public int index; public Data(long x, int index) { this.x = x; this.index = index; } // SortするときのComparerは明示的に指定する public static int CompareTo(Data d1, Data d2) { int result = d1.x.CompareTo(d2.x); if (result == 0) result = d1.index.CompareTo(d2.index); return result; } } // common ---------- internal static class Input { public static string ReadString() { string line = Console.ReadLine(); return line; } public static int ReadInt() { string line = Console.ReadLine(); return int.Parse(line); } public static int[] ReadIntArray() { string line = Console.ReadLine(); return line.Split(' ').Select(int.Parse).ToArray(); } public static long ReadLong() { string line = Console.ReadLine(); return long.Parse(line); } public static long[] ReadLongArray() { string line = Console.ReadLine(); return line.Split(' ').Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { string line = Console.ReadLine(); return line.Split(' ').Select(double.Parse).ToArray(); } } internal class Program { public static void Main(string[] args) { var s = new Solution(); s.Run(); } } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22]]
8
578
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Numerics; namespace AtcoderC { class Program { /*static void Main(string[] args) { }*/ // ABC132C //全探索法 /*static void Main() { BigInteger N = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int min = input.Min(); int max = input.Max(); int countARC = 0; int countABC = 0; int Answer = 0; for (int i = min; i <= max; i++) { countABC = 0; countARC = 0; foreach (int n in input) { if (n > i) { countARC++; } else { countABC++; } } if (countABC == countARC) { Answer++; } } Console.WriteLine(Answer); }*/ // 2回目 /*static void Main() { int N = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(input); int min = input[(N / 2) - 1]; int max = input[N / 2]; Console.WriteLine(max - min); }*/ // ABC131C //ユーグリッドの互除法の応用 /*static void Main() { BigInteger[] input = Console.ReadLine().Split().Select(BigInteger.Parse).ToArray(); BigInteger A = input[0]; BigInteger B = input[1]; BigInteger C = input[2]; BigInteger D = input[3]; BigInteger ans = (B / C) + (B / D); //最小公倍数 var ans2 = C * D / lcm(C, D); BigInteger ans3 = B / ans2; var BB = B - ans + ans3; ans = (A - 1) / C + (A - 1) / D; ans3 = (A - 1) / ans2; var AA = (A - 1) - ans + ans3; Console.WriteLine(BB - AA); } static public BigInteger lcm(BigInteger a, BigInteger b) { var r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; }*/ // 129C //動的計画法 // TLEになる時間がかかり過ぎる /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int> ttt = new List<int>(); for (int i = 0;i < M;i++) { var temp = int.Parse(Console.ReadLine()); ttt.Add(temp); } int[] dparray = new int[N+2]; dparray[N] = 1; dparray[N - 1] = 1; for (int i = N-1; i >= 0; i--) { if (ttt.Contains(i)) { dparray[i] = 0; } dparray[i] = (dparray[i + 1] + dparray[i + 2]) % 1000000007; } Console.WriteLine(dparray[0]); }*/ // ABC128 /*static void Main() { }*/ // ABC134A /*static void Main() { int r = int.Parse(Console.ReadLine()); var ans = 3 * r * r; Console.WriteLine(ans); }*/ // ABC134B /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int D = input[1]; int count = 0; int ans = N; while (true) { ans = ans - (D * 2 + 1); count++; if (ans <= 0) { break; } } Console.WriteLine(count); }*/ // ABC134C /*static void Main() { int N = int.Parse(Console.ReadLine()); List<int> array = new List<int>(); for (int i =0;i<N; i++) { array.Add(int.Parse(Console.ReadLine())); } List<int> ans = new List<int>(); int max = array.Max(); var temp = new List<int>(); foreach (int n in array) { temp.Add(n); } temp.Sort(); temp.Reverse(); int second = temp[1]; foreach (int nn in array) { if (nn == max) { Console.WriteLine(second); } else { Console.WriteLine(max); } } }*/ // 134ABCD /*static void Main() { int N = int.Parse(Console.ReadLine()); int count = 0; int ans = 0; int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0;i<N;i++) { for (int j =0;j<N; j++) { if ((j+1)%(i+1)==0) { count += input[j]; } } if (count % 2 == input[i]) { ans++; } count = 0; } if (ans != 0) { } }*/ // AGC036 /*static void Main() { long S = long.Parse(Console.ReadLine()); long X1 = 1000000000; long Y1 = 0; /*while (true) { Y1 = S / X1 + S % X1; } Y1 = S / X1 + S % X1; Console.WriteLine("0 0 " + X1 + " 0 0 " + Y1); /*int tempX = 0; List<long> ss = new List<long>(); while (tempX < S) { var ans = S % tempX; if (ans == 0) { ss.Add(ans); } tempX++; } Console.WriteLine(tempX);*/ /*long X1 = 0; long Y1 = 1; while (true) { X1 = S % Y1; if (X1 <= 1000000000) { break; } Y1++; } Console.WriteLine("0 0 "+X1+" 0 0 "+Y1); }*/ // ABC82A /*static void Main() { double[] input = Console.ReadLine().Split().Select(double.Parse).ToArray(); double a = input[0]; double b = input[1]; double sum = (a + b) / 2; Console.WriteLine(Math.Ceiling(sum)); }*/ // ABC128C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int ans = 0; List<int[]> K = new List<int[]>(); for (int i = 0;i<M;i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); K.Add(temp); } int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] light = new int[M]; for (int i = 0;i < Math.Pow(2,N);i++) { var isrow = 0; var temp = int.Parse(Convert.ToString(i, 2)).ToString("0000000000"); for (int j =0;j < M;j++) { var ison = 0; for (int k = 0; k < K[j][0];k++) { var index = K[j][k] - 1; if (temp[9-index] == '1') { ison++; } } if (ison % 2 == P[j]) { isrow++; } else { break; } } if (isrow == M) { ans++; } } Console.WriteLine(ans);*/ /*nt[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = input[0]; int b = input[1]; var temp = a * b % 2; if (temp == 0) { Console.WriteLine("even"); } else { Console.WriteLine("odd"); } }*/ // ABC127C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } if (M == 1) { Console.WriteLine(N); } else { List<int> card = new List<int>(); for (int i = gate[0][0]; i <= gate[0][1]; i++) { card.Add(i); } for (int j = 1; j < gate.Count; j++) { List<int> ans = new List<int>(); var count = 0; for (int i = gate[j][0]; i <= gate[j][1]; i++) { if (card.Contains(i)) { count++; ans.Add(i); } } if (count == 0) { break; } card = new List<int>(ans); } Console.WriteLine(card.Count()); } }*/ // 127C Revenge TLE /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } int Ans = 0; for (int i =1;i<=N;i++) { var count = 0; for (int j = 0;j < gate.Count;j++) { if (gate[j][0] <= i && i <= gate[j][1]) { count++; } } if (count == gate.Count) { Ans++; } } Console.WriteLine(Ans); }*/ // 127C RevengeVer2 /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } List<int> Max = new List<int>(); List<int> Min = new List<int>(); for (int i =0;i< M;i++) { Max.Add(gate[i][1]); Min.Add(gate[i][0]); } int max = Max.Min(); int min = Min.Max(); if (min <= max) { Console.WriteLine(max - min + 1); } else { Console.WriteLine("0"); } }*/ // ABC126C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; double ans = 0.0; for (int i = 1; i<= N;i++) { double tempP = (double)1 / N; int point = i; while (point<M) { tempP = tempP * 1 / 2; point *= 2; } ans += tempP; } Console.WriteLine(ans); }*/ // ABC125C ユーグリッド互除法 /*static void Main() { int N = int.Parse(Console.ReadLine()); int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(A); int lcmr, lcml = 0; List<int> answer = new List<int>(); for (int i =0;i<A.Length;i++) { lcmr = 0; for (int x = 0;x < i;x++) { if (lcmr - A[x] >= 0) { lcmr = lcm(lcmr, A[x]); } else { lcmr = lcm(A[x], lcmr); } } lcml = 0; for (int y = i+1; y < A.Length; y++) { if (lcml - A[y] >= 0) { lcml = lcm(lcml, A[y]); } else { lcml = lcm(A[y],lcml); } } var tempans = 0; if (lcmr > lcml) { tempans = lcm(lcmr, lcml); } else { tempans = lcm(lcml, lcmr); } answer.Add(tempans); } Console.WriteLine(answer.Max()); } static public int lcm(int a, int b) { if (b == 0) { return a; } var r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; }*/ // 124C /*static void Main() { string inputstr = Console.ReadLine(); int count = 0; if (inputstr[0] == '0') { for (int i = 0; i < inputstr.Length; i++) { if (i % 2 == 0) { if (inputstr[i] == '1') { count++; } } else { if (inputstr[i] == '0') { count++; } } } } else { for (int i = 0; i < inputstr.Length; i++) { if (i % 2 == 1) { if (inputstr[i] == '1') { count++; } } else { if (inputstr[i] == '0') { count++; } } } } Console.WriteLine(count); }*/ // 123C /*static void Main() { double N = double.Parse(Console.ReadLine()); List<double> city = new List<double>(); for (int i = 0; i < 5; i++) { city.Add(double.Parse(Console.ReadLine())); } var ans = Math.Ceiling(N / city.Min()) + 4; Console.WriteLine(ans); }*/ // 82C /*static void Main() { double[] input = Console.ReadLine().Split().Select(double.Parse).ToArray(); double a = input[0]; double b = input[1]; double answer = (a + b) / 2; Console.WriteLine(Math.Ceiling(answer)); }*/ // 128B /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int P = input[1]; var ans = (P + A * 3) / 2; Console.WriteLine(ans); int a,b cin << a << b; cout >> (P + A * 3) / 2 >> endl; }*/ // 119A /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int B = input[1]; if (B % A == 0) { Console.WriteLine(A + B); } else { Console.WriteLine(B-A); } }*/ // 116A static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int B = input[1]; Console.WriteLine((A + B) / 2); } } } // 125C難しい /*namespace CSharp { class Program { static IEnumerable<long> EnumerateDivisors(long n) { for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; if (n / i != i) { yield return n / i; } } } } static void Main(string[] args) { ReadString(); long[] A = ReadLongArray(); long[] divisors = Enumerable.Concat(EnumerateDivisors(A[0]), EnumerateDivisors(A[1])) .Distinct().ToArray(); long ans = divisors.Select(x => new { Value = x, Count = A.Count(v => v % x == 0) }) .Where(x => x.Count >= A.Length - 1) .OrderByDescending(x => x.Value) .First().Value; Console.WriteLine(ans); } #region Helpers static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray(); static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray(); static string ReadString() => Console.ReadLine(); static int ReadInt() => int.Parse(Console.ReadLine()); static long ReadLong() => long.Parse(Console.ReadLine()); static void ReadInt(out int first) { var array = ReadIntArray(); first = array[0]; } static void ReadInt(out int first, out int second) { var array = ReadIntArray(); first = array[0]; second = array[1]; } static void ReadInt(out int first, out int second, out int third) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadInt(out int first, out int second, out int third, out int fourth) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } static void ReadLong(out long first) { var array = ReadLongArray(); first = array[0]; } static void ReadLong(out long first, out long second) { var array = ReadLongArray(); first = array[0]; second = array[1]; } static void ReadLong(out long first, out long second, out long third) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadLong(out long first, out long second, out long third, out long fourth) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } #endregion } }*/
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Numerics; namespace AtcoderC { class Program { /*static void Main(string[] args) { }*/ // ABC132C //全探索法 /*static void Main() { BigInteger N = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int min = input.Min(); int max = input.Max(); int countARC = 0; int countABC = 0; int Answer = 0; for (int i = min; i <= max; i++) { countABC = 0; countARC = 0; foreach (int n in input) { if (n > i) { countARC++; } else { countABC++; } } if (countABC == countARC) { Answer++; } } Console.WriteLine(Answer); }*/ // 2回目 /*static void Main() { int N = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(input); int min = input[(N / 2) - 1]; int max = input[N / 2]; Console.WriteLine(max - min); }*/ // ABC131C //ユーグリッドの互除法の応用 /*static void Main() { BigInteger[] input = Console.ReadLine().Split().Select(BigInteger.Parse).ToArray(); BigInteger A = input[0]; BigInteger B = input[1]; BigInteger C = input[2]; BigInteger D = input[3]; BigInteger ans = (B / C) + (B / D); //最小公倍数 var ans2 = C * D / lcm(C, D); BigInteger ans3 = B / ans2; var BB = B - ans + ans3; ans = (A - 1) / C + (A - 1) / D; ans3 = (A - 1) / ans2; var AA = (A - 1) - ans + ans3; Console.WriteLine(BB - AA); } static public BigInteger lcm(BigInteger a, BigInteger b) { var r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; }*/ // 129C //動的計画法 // TLEになる時間がかかり過ぎる /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int> ttt = new List<int>(); for (int i = 0;i < M;i++) { var temp = int.Parse(Console.ReadLine()); ttt.Add(temp); } int[] dparray = new int[N+2]; dparray[N] = 1; dparray[N - 1] = 1; for (int i = N-1; i >= 0; i--) { if (ttt.Contains(i)) { dparray[i] = 0; } dparray[i] = (dparray[i + 1] + dparray[i + 2]) % 1000000007; } Console.WriteLine(dparray[0]); }*/ // ABC128 /*static void Main() { }*/ // ABC134A /*static void Main() { int r = int.Parse(Console.ReadLine()); var ans = 3 * r * r; Console.WriteLine(ans); }*/ // ABC134B /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int D = input[1]; int count = 0; int ans = N; while (true) { ans = ans - (D * 2 + 1); count++; if (ans <= 0) { break; } } Console.WriteLine(count); }*/ // ABC134C /*static void Main() { int N = int.Parse(Console.ReadLine()); List<int> array = new List<int>(); for (int i =0;i<N; i++) { array.Add(int.Parse(Console.ReadLine())); } List<int> ans = new List<int>(); int max = array.Max(); var temp = new List<int>(); foreach (int n in array) { temp.Add(n); } temp.Sort(); temp.Reverse(); int second = temp[1]; foreach (int nn in array) { if (nn == max) { Console.WriteLine(second); } else { Console.WriteLine(max); } } }*/ // 134ABCD /*static void Main() { int N = int.Parse(Console.ReadLine()); int count = 0; int ans = 0; int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0;i<N;i++) { for (int j =0;j<N; j++) { if ((j+1)%(i+1)==0) { count += input[j]; } } if (count % 2 == input[i]) { ans++; } count = 0; } if (ans != 0) { } }*/ // AGC036 /*static void Main() { long S = long.Parse(Console.ReadLine()); long X1 = 1000000000; long Y1 = 0; /*while (true) { Y1 = S / X1 + S % X1; } Y1 = S / X1 + S % X1; Console.WriteLine("0 0 " + X1 + " 0 0 " + Y1); /*int tempX = 0; List<long> ss = new List<long>(); while (tempX < S) { var ans = S % tempX; if (ans == 0) { ss.Add(ans); } tempX++; } Console.WriteLine(tempX);*/ /*long X1 = 0; long Y1 = 1; while (true) { X1 = S % Y1; if (X1 <= 1000000000) { break; } Y1++; } Console.WriteLine("0 0 "+X1+" 0 0 "+Y1); }*/ // ABC82A /*static void Main() { double[] input = Console.ReadLine().Split().Select(double.Parse).ToArray(); double a = input[0]; double b = input[1]; double sum = (a + b) / 2; Console.WriteLine(Math.Ceiling(sum)); }*/ // ABC128C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int ans = 0; List<int[]> K = new List<int[]>(); for (int i = 0;i<M;i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); K.Add(temp); } int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] light = new int[M]; for (int i = 0;i < Math.Pow(2,N);i++) { var isrow = 0; var temp = int.Parse(Convert.ToString(i, 2)).ToString("0000000000"); for (int j =0;j < M;j++) { var ison = 0; for (int k = 0; k < K[j][0];k++) { var index = K[j][k] - 1; if (temp[9-index] == '1') { ison++; } } if (ison % 2 == P[j]) { isrow++; } else { break; } } if (isrow == M) { ans++; } } Console.WriteLine(ans);*/ /*nt[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = input[0]; int b = input[1]; var temp = a * b % 2; if (temp == 0) { Console.WriteLine("even"); } else { Console.WriteLine("odd"); } }*/ // ABC127C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } if (M == 1) { Console.WriteLine(N); } else { List<int> card = new List<int>(); for (int i = gate[0][0]; i <= gate[0][1]; i++) { card.Add(i); } for (int j = 1; j < gate.Count; j++) { List<int> ans = new List<int>(); var count = 0; for (int i = gate[j][0]; i <= gate[j][1]; i++) { if (card.Contains(i)) { count++; ans.Add(i); } } if (count == 0) { break; } card = new List<int>(ans); } Console.WriteLine(card.Count()); } }*/ // 127C Revenge TLE /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } int Ans = 0; for (int i =1;i<=N;i++) { var count = 0; for (int j = 0;j < gate.Count;j++) { if (gate[j][0] <= i && i <= gate[j][1]) { count++; } } if (count == gate.Count) { Ans++; } } Console.WriteLine(Ans); }*/ // 127C RevengeVer2 /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } List<int> Max = new List<int>(); List<int> Min = new List<int>(); for (int i =0;i< M;i++) { Max.Add(gate[i][1]); Min.Add(gate[i][0]); } int max = Max.Min(); int min = Min.Max(); if (min <= max) { Console.WriteLine(max - min + 1); } else { Console.WriteLine("0"); } }*/ // ABC126C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; double ans = 0.0; for (int i = 1; i<= N;i++) { double tempP = (double)1 / N; int point = i; while (point<M) { tempP = tempP * 1 / 2; point *= 2; } ans += tempP; } Console.WriteLine(ans); }*/ // ABC125C ユーグリッド互除法 /*static void Main() { int N = int.Parse(Console.ReadLine()); int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(A); int lcmr, lcml = 0; List<int> answer = new List<int>(); for (int i =0;i<A.Length;i++) { lcmr = 0; for (int x = 0;x < i;x++) { if (lcmr - A[x] >= 0) { lcmr = lcm(lcmr, A[x]); } else { lcmr = lcm(A[x], lcmr); } } lcml = 0; for (int y = i+1; y < A.Length; y++) { if (lcml - A[y] >= 0) { lcml = lcm(lcml, A[y]); } else { lcml = lcm(A[y],lcml); } } var tempans = 0; if (lcmr > lcml) { tempans = lcm(lcmr, lcml); } else { tempans = lcm(lcml, lcmr); } answer.Add(tempans); } Console.WriteLine(answer.Max()); } static public int lcm(int a, int b) { if (b == 0) { return a; } var r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; }*/ // 124C /*static void Main() { string inputstr = Console.ReadLine(); int count = 0; if (inputstr[0] == '0') { for (int i = 0; i < inputstr.Length; i++) { if (i % 2 == 0) { if (inputstr[i] == '1') { count++; } } else { if (inputstr[i] == '0') { count++; } } } } else { for (int i = 0; i < inputstr.Length; i++) { if (i % 2 == 1) { if (inputstr[i] == '1') { count++; } } else { if (inputstr[i] == '0') { count++; } } } } Console.WriteLine(count); }*/ // 123C /*static void Main() { double N = double.Parse(Console.ReadLine()); List<double> city = new List<double>(); for (int i = 0; i < 5; i++) { city.Add(double.Parse(Console.ReadLine())); } var ans = Math.Ceiling(N / city.Min()) + 4; Console.WriteLine(ans); }*/ // 82C /*static void Main() { double[] input = Console.ReadLine().Split().Select(double.Parse).ToArray(); double a = input[0]; double b = input[1]; double answer = (a + b) / 2; Console.WriteLine(Math.Ceiling(answer)); }*/ // 128B /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int P = input[1]; var ans = (P + A * 3) / 2; Console.WriteLine(ans); int a,b cin << a << b; cout >> (P + A * 3) / 2 >> endl; }*/ // 119A /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int B = input[1]; if (B % A == 0) { Console.WriteLine(A + B); } else { Console.WriteLine(B-A); } }*/ // 116A static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int B = input[1]; int C = input[2]; Console.WriteLine((A * B) / 2); } } } // 125C難しい /*namespace CSharp { class Program { static IEnumerable<long> EnumerateDivisors(long n) { for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; if (n / i != i) { yield return n / i; } } } } static void Main(string[] args) { ReadString(); long[] A = ReadLongArray(); long[] divisors = Enumerable.Concat(EnumerateDivisors(A[0]), EnumerateDivisors(A[1])) .Distinct().ToArray(); long ans = divisors.Select(x => new { Value = x, Count = A.Count(v => v % x == 0) }) .Where(x => x.Count >= A.Length - 1) .OrderByDescending(x => x.Value) .First().Value; Console.WriteLine(ans); } #region Helpers static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray(); static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray(); static string ReadString() => Console.ReadLine(); static int ReadInt() => int.Parse(Console.ReadLine()); static long ReadLong() => long.Parse(Console.ReadLine()); static void ReadInt(out int first) { var array = ReadIntArray(); first = array[0]; } static void ReadInt(out int first, out int second) { var array = ReadIntArray(); first = array[0]; second = array[1]; } static void ReadInt(out int first, out int second, out int third) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadInt(out int first, out int second, out int third, out int fourth) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } static void ReadLong(out long first) { var array = ReadLongArray(); first = array[0]; } static void ReadLong(out long first, out long second) { var array = ReadLongArray(); first = array[0]; second = array[1]; } static void ReadLong(out long first, out long second, out long third) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadLong(out long first, out long second, out long third, out long fourth) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } #endregion } }*/
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 48]]
8
156
10
using System; class program { static void Main(string[] args) { program p = new program(); p.Run(); } void Run() { string[] inp = Console.ReadLine().Split(); int ab = int.Parse(inp[0]); int bc = int.Parse(inp[1]); Console.WriteLine((ab * bc).ToString()); } }
using System; class program { static void Main(string[] args) { program p = new program(); p.Run(); } void Run() { string[] inp = Console.ReadLine().Split(); int ab = int.Parse(inp[0]); int bc = int.Parse(inp[1]); int res = (int)(ab * bc / 2); Console.WriteLine(res.ToString()); } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 0, 212, 0, 74, 51, 23, 0, 16, 17, 85], ["+", 0, 212, 0, 74, 51, 23, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22]]
8
94
16
using System; using System.Collections.Generic; using System.Linq; class Scanner //標準入力 { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int Int() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } } class Program { static Scanner cin = new Scanner(); static void Main(string[] args) { var n = cin.ArrayInt(3); Array.Sort(n); Console.WriteLine(n[0] * n[1]); Console.ReadLine(); } }
using System; using System.Collections.Generic; using System.Linq; class Scanner //標準入力 { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int Int() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } } class Program { static Scanner cin = new Scanner(); static void Main(string[] args) { var n = cin.ArrayInt(3); Console.WriteLine(n[0] * n[1] / 2); Console.ReadLine(); } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
354
9
using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using static System.Math; class P { static void Main() { int[] tx = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine(tx[1] / (double)tx[0]); } }
using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using static System.Math; class P { static void Main() { int[] tx = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine((double)tx[0] / (double)tx[1]); } }
[["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 74, 51, 204, 206, 207, 0, 28, 0, 203], ["-", 12, 74, 51, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 74, 51, 204, 206, 207, 0, 28, 0, 203]]
8
129
7
using System; class Program { static void Main(string[] args) { // 整数の入力 // int a = int.Parse(Console.ReadLine()); // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); int T = int.Parse(input[0]); int X = int.Parse(input[1]); // 文字列の入力 // string s = Console.ReadLine(); //出力 // T*X int ret = T / X; Console.WriteLine(ret + ""); } }
using System; class Program { static void Main(string[] args) { // 整数の入力 // int a = int.Parse(Console.ReadLine()); // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); int T = int.Parse(input[0]); int X = int.Parse(input[1]); // 文字列の入力 // string s = Console.ReadLine(); //出力 // T*X decimal ret = (decimal)T / (decimal)X; Console.WriteLine(ret + ""); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 0, 25]]
8
86
8
using System; using System.Linq; namespace Sample { class Sample { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); int[] L = str.Select(int.Parse).ToArray(); Array.Sort(L); Array.Reverse(L); int[] Lsub = new int[N - 1]; L.CopyTo(Lsub, 1); if (L[0] < Lsub.Sum()) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Linq; namespace Sample { class Sample { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); int[] L = str.Select(int.Parse).ToArray(); Array.Sort(L); Array.Reverse(L); // int[] Lsub=new int[N-1]; // L.CopyTo(Lsub,1); if (L[0] < L.Sum() - L[0]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 17, 33], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
8
149
29
using System; using System.Linq; namespace ConsoleApp18 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); string line = Console.ReadLine(); string[] array = line.Split(' '); int[] arr = new int[n]; for (int index = 0; index < n; index++) { arr[index] = int.Parse(array[index]); ; } int m = arr.Max(); int sum = 0; for (int i = 0; i < arr.Length; i++) { sum += arr[i]; } if (m <= sum - m) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } int[] numbers = new int[n]; } } }
using System; using System.Linq; namespace ConsoleApp18 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string line = Console.ReadLine(); string[] array = line.Split(' '); int[] arr = new int[n]; for (int index = 0; index < n; index++) { int num = int.Parse(array[index]); arr[index] = num; } int m = arr.Max(); int sum = 0; for (int i = 0; i < arr.Length; i++) { sum += arr[i]; } if (m < sum - m) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } int[] numbers = new int[n]; } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
8
188
16
using System; using System.Collections.Generic; using System.Linq; using System.Security.AccessControl; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var n = ReadLineInt(); var l = ReadLineIntSpilit(); var t = 0; for (int i = 0; i < n; i++) { if (l[i] != l.Max()) t += l[i]; } Console.WriteLine((l.Max() < t) ? "Yes" : "No"); ReadLine(); } //メモ //アルゴリズム //・全探索解 /* * 例 [A, B, C] * * A - B, A - C * B - C * for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { array[i], array[j] } } */ // ・配列の前後を見る /* * 例 array[1, 2, 3, 4, 5] * * r = 3; * * array[i - 1] => 1 * array[i] => 2 * array[i + 1] => 3 * * //範囲 * int r = 3; * * for(int i = 1; i <= array.Length - r; i++) { } * */ //配列 //降順 // var sort = array.OrderBy(x => -x).ToArray(); //合計値 // array.Sum(); //切り捨て // double d = Math.Floor(n); //切り上げ // double d = Math.Celling(n); // kのn乗 //(int) Math.Pow(k, n); // for文の逆 // for(int i = array.Length - 1; i >= 0; i--) { } /// <summary> /// 最大公約数 /// </summary> static int gcd(int a, int b) { if (a > b) { return gcd(b, a); } while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } //最小公倍数 static int lcm(int a, int b) => a * b / gcd(a, b); /// <summary> /// コンビネーション /// </summary> static int nCm(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } /// <summary> /// 数字配列の重複をカウント /// </summary> public static int DistinctInt(IEnumerable<int> array) { var q = array.Distinct().Count(); return array.Count() - q; } /// <summary> /// 文字配列の重複をカウント /// </summary> /// <param name="array"></param> /// <returns></returns> public static int DistinctString(IEnumerable<string> array) { var q = array.Distinct().Count(); return array.Count() - q; } public static string ReadLine() => Console.ReadLine(); public static int ReadLineInt() => int.Parse(Console.ReadLine()); public static long ReadLineLongInt() => long.Parse(Console.ReadLine()); public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray(); public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray(); public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray(); static string[] GetAlphaLowerArray() => 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 string[] GetAlphaUpperArray() => 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" }; } }
using System; using System.Collections.Generic; using System.Linq; using System.Security.AccessControl; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var n = ReadLineInt(); var l = ReadLineIntSpilit().ToList(); l.Sort(); var t = 0; for (int i = 0; i < n - 1; i++) { t += l[i]; } Console.WriteLine((l[l.Count() - 1] < t) ? "Yes" : "No"); ReadLine(); } //メモ //アルゴリズム //・全探索解 /* * 例 [A, B, C] * * A - B, A - C * B - C * for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { array[i], array[j] } } */ // ・配列の前後を見る /* * 例 array[1, 2, 3, 4, 5] * * r = 3; * * array[i - 1] => 1 * array[i] => 2 * array[i + 1] => 3 * * //範囲 * int r = 3; * * for(int i = 1; i <= array.Length - r; i++) { } * */ //配列 //降順 // var sort = array.OrderBy(x => -x).ToArray(); //合計値 // array.Sum(); //切り捨て // double d = Math.Floor(n); //切り上げ // double d = Math.Celling(n); // kのn乗 //(int) Math.Pow(k, n); // for文の逆 // for(int i = array.Length - 1; i >= 0; i--) { } /// <summary> /// 最大公約数 /// </summary> static int gcd(int a, int b) { if (a > b) { return gcd(b, a); } while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } //最小公倍数 static int lcm(int a, int b) => a * b / gcd(a, b); /// <summary> /// コンビネーション /// </summary> static int nCm(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } /// <summary> /// 数字配列の重複をカウント /// </summary> public static int DistinctInt(IEnumerable<int> array) { var q = array.Distinct().Count(); return array.Count() - q; } /// <summary> /// 文字配列の重複をカウント /// </summary> /// <param name="array"></param> /// <returns></returns> public static int DistinctString(IEnumerable<string> array) { var q = array.Distinct().Count(); return array.Count() - q; } public static string ReadLine() => Console.ReadLine(); public static int ReadLineInt() => int.Parse(Console.ReadLine()); public static long ReadLineLongInt() => long.Parse(Console.ReadLine()); public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray(); public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray(); public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray(); static string[] GetAlphaLowerArray() => 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 string[] GetAlphaUpperArray() => 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" }; } }
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 15, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 205, 22], ["-", 15, 23, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 15, 23, 0, 16, 31, 204, 206, 207, 0, 73]]
8
761
32
using System; using System.Collections.Generic; using System.Linq; namespace CsProgramSpace { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List<int> li = RLl(); int max = li.Max(); int lon = li.IndexOf(max); int sum = 0; for (int i = 0; i < n; i++) { if (li[i] != max) sum += li[i]; } if (max < sum) Console.WriteLine("Yes"); else Console.WriteLine("No"); } private static List<int> RLl() => Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToList(); } }
using System; using System.Collections.Generic; using System.Linq; namespace CsProgramSpace { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List<int> li = RLl(); int max = li.Max(); int lon = li.IndexOf(max); int sum = 0; for (int i = 0; i < n; i++) { if (i == lon) continue; sum += li[i]; } if (max < sum) Console.WriteLine("Yes"); else Console.WriteLine("No"); } private static List<int> RLl() => Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToList(); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35]]
8
178
9
using System; using System.Collections.Generic; using System.Linq; using static System.Console; namespace AtCoder { class Program { #region private static int ReadInt() => int.Parse(ReadLine()); private static IEnumerable<int> ReadSplitInt() => Console.ReadLine().Split(' ').Select(i => int.Parse(i)); private static IEnumerable<double> ReadSplitDouble() => Console.ReadLine().Split(' ').Select(i => double.Parse(i)); private static bool IsEven(int n) => n % 2 == 0; #endregion public static void Main(string[] args) { var n = ReadInt(); var l = ReadSplitInt().ToArray(); var others = l.Where(val => val != l.Max()).Sum(); if (l.Max() < others) WriteLine("Yes"); else WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; namespace AtCoder { class Program { #region private static int ReadInt() => int.Parse(ReadLine()); private static IEnumerable<int> ReadSplitInt() => Console.ReadLine().Split(' ').Select(i => int.Parse(i)); private static IEnumerable<double> ReadSplitDouble() => Console.ReadLine().Split(' ').Select(i => double.Parse(i)); private static bool IsEven(int n) => n % 2 == 0; #endregion public static void Main(string[] args) { var n = ReadInt(); var l = ReadSplitInt().ToArray(); var others = l.Sum() - l.Max(); if (l.Max() < others) WriteLine("Yes"); else WriteLine("No"); } } }
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 79], ["+", 0, 212, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 218, 8, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 218, 8, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
211
13
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! int N = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();     int max = a.Max(); int sum = 0; for (int i = 0; i < N; i++) { if (a[i] == max) continue; else { sum += a[i]; } } if (max < sum) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! int N = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();     int max = a.Max(); int sum = 0; int count = 0; for (int i = 0; i < N; i++) { if (a[i] == max) { if (count == 0) { count++; continue; } else { sum += a[i]; } } else { sum += a[i]; } } if (max < sum) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
147
28
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var n = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); input.Sort((x, y) => y - x); if (input[0] != input[1] && input.First() < input.Skip(1).Sum()) { Console.WriteLine("Yes"); return; } Console.WriteLine("No"); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var n = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); input.Sort((x, y) => y - x); if (input.First() < input.Skip(1).Sum()) { Console.WriteLine("Yes"); return; } Console.WriteLine("No"); } }
[["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["-", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["-", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 15, 16, 12, 16, 31, 213, 63, 214, 205, 22]]
8
138
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static ABC.Cin; using static ABC.Cout; using static ABC.Tool; namespace ABC { class Program { static void Main(string[] args) { Scanf(out int n, out int m); var x = ReadSplitInt.ToList(); x.Sort(); if (m == 1) { OutL(x.Max() - x.Min()); return; } var dif = new List<int>(); for (int i = 0; i < m - 1; i++) { dif.Add(x[i + 1] - x[i]); } dif.Sort(); dif.Reverse(); var ans = x.Max() - x.Min(); for (int i = 0; i < n - 1; i++) { ans -= dif[i]; } OutL(ans); } } static class Cin { public static string[] ReadSplit => Console.ReadLine().Split(); public static int[] ReadSplitInt => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] ReadSplitLong => Console.ReadLine().Split().Select(long.Parse).ToArray(); 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) { return (T)Convert.ChangeType(input, typeof(T)); } public static void Scanf<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Scanf<T, U>(out T a, out U b) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Scanf<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 Scanf<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]); } } static class Cout { public static void OutL(object s) => Console.WriteLine(s); } static class Tool { public static long Gcd(long a, long b) { if (a % b == 0) { return b; } else { return Gcd(b, a % b); } } public static long Lcm(long a, long b) => a * b / Gcd(a, b); public static long[] PrimeFac(long n) { var result = new long[n + 1]; for (int i = 2; i * i <= n; i++) { if (n % i != 0) { continue; } var cnt = 0; while (n % i == 0) { cnt++; n /= i; } result[i] = cnt; } if (n != 1) { result[n] = 1; } return result; } public static long DivsCnt(long n) { var result = 1L; for (int i = 2; i * i <= n; i++) { if (n % i != 0) { continue; } var cnt = 0; while (n % i == 0) { cnt++; n /= i; } result *= (cnt + 1); } if (n != 1) { result *= 2; } return result; } public static string Reversed(string s) { return string.Join("", s.Reverse()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static ABC.Cin; using static ABC.Cout; using static ABC.Tool; namespace ABC { class Program { static void Main(string[] args) { Scanf(out int n, out int m); var x = ReadSplitInt.ToList(); x.Sort(); if (n >= m) { OutL(0); return; } var dif = new List<int>(); for (int i = 0; i < m - 1; i++) { dif.Add(x[i + 1] - x[i]); } dif.Sort(); dif.Reverse(); var ans = x.Max() - x.Min(); for (int i = 0; i < n - 1; i++) { ans -= dif[i]; } OutL(ans); } } static class Cin { public static string[] ReadSplit => Console.ReadLine().Split(); public static int[] ReadSplitInt => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] ReadSplitLong => Console.ReadLine().Split().Select(long.Parse).ToArray(); 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) { return (T)Convert.ChangeType(input, typeof(T)); } public static void Scanf<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Scanf<T, U>(out T a, out U b) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Scanf<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 Scanf<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]); } } static class Cout { public static void OutL(object s) => Console.WriteLine(s); } static class Tool { public static long Gcd(long a, long b) { if (a % b == 0) { return b; } else { return Gcd(b, a % b); } } public static long Lcm(long a, long b) => a * b / Gcd(a, b); public static long[] PrimeFac(long n) { var result = new long[n + 1]; for (int i = 2; i * i <= n; i++) { if (n % i != 0) { continue; } var cnt = 0; while (n % i == 0) { cnt++; n /= i; } result[i] = cnt; } if (n != 1) { result[n] = 1; } return result; } public static long DivsCnt(long n) { var result = 1L; for (int i = 2; i * i <= n; i++) { if (n % i != 0) { continue; } var cnt = 0; while (n % i == 0) { cnt++; n /= i; } result *= (cnt + 1); } if (n != 1) { result *= 2; } return result; } public static string Reversed(string s) { return string.Join("", s.Reverse()); } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
917
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp11 { class Class69 { static void Main() { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NM[0], M = NM[1]; var X = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(X); if (M > 1) { Console.WriteLine(0); return; } if (N > M) N = M; var dif = new int[M - 1]; for (int i = 0; i < M - 1; i++) { dif[i] = X[i + 1] - X[i]; } int ans = dif.Sum(); Array.Sort(dif); for (int i = 0; i < N - 1; i++) { ans -= dif[M - 2 - i]; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp11 { class Class69 { static void Main() { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NM[0], M = NM[1]; var X = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(X); int ans = 0; if (M > 1) { if (N > M) N = M; var dif = new int[M - 1]; for (int i = 0; i < M - 1; i++) dif[i] = X[i + 1] - X[i]; Array.Sort(dif); ans = dif.Sum(); for (int i = 0; i < N - 1; i++) ans -= dif[M - 2 - i]; } Console.WriteLine(ans); } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
237
33
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramC { static void Main(string[] args) { var inputs = Console.ReadLine().Split(" "); var n = int.Parse(inputs[0]); var m = int.Parse(inputs[1]); var list = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToList(); list.Sort(); var diffs = new List<int>(); for (var i = 1; i < m; i++) { diffs.Add(list[i] - list[i - 1]); } diffs.Sort((a, b) => b - a); var result = 0; Console.WriteLine(result); for (var i = n - 1; i < m - 1; i++) { result += diffs[i]; Console.WriteLine(result); } Console.WriteLine(result); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramC { static void Main(string[] args) { var inputs = Console.ReadLine().Split(" "); var n = int.Parse(inputs[0]); var m = int.Parse(inputs[1]); var list = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToList(); list.Sort(); var diffs = new List<int>(); for (var i = 1; i < m; i++) { diffs.Add(list[i] - list[i - 1]); } diffs.Sort((a, b) => b - a); var result = 0; for (var i = n - 1; i < m - 1; i++) { result += diffs[i]; } Console.WriteLine(result); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
226
14
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Element : IComparable<Element> { public static bool sortIndex = false; public int leftIndex; public int distanceToRight; public int CompareTo(Element e) { if (sortIndex) { return leftIndex.CompareTo(e.leftIndex); } return distanceToRight.CompareTo(e.distanceToRight); } } class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int M = int.Parse(s[1]); if (N >= M) { Console.WriteLine(0); return; } int[] v = new int[M]; s = Console.ReadLine().Split(' '); for (int i = 0; i < M; i++) { v[i] = int.Parse(s[i]); } Array.Sort(v); List<Element> elist = new List<Element>(); for (int i = 0; i < M - 1; i++) { Element e = new Element(); e.leftIndex = i; e.distanceToRight = v[i + 1] - v[i]; elist.Add(e); } elist.Sort(); elist.Reverse(); elist.RemoveRange(N - 1, M - N); Element.sortIndex = true; elist.Sort(); int ans = v[elist[0].leftIndex] - v[0]; ans += v[M - 1] - v[elist[elist.Count - 1].leftIndex + 1]; for (int i = 0; i < elist.Count - 1; i++) { ans += v[elist[i + 1].leftIndex] - v[elist[i].leftIndex + 1]; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Element : IComparable<Element> { public static bool sortIndex = false; public int leftIndex; public int distanceToRight; public int CompareTo(Element e) { if (sortIndex) { return leftIndex.CompareTo(e.leftIndex); } return distanceToRight.CompareTo(e.distanceToRight); } } class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int M = int.Parse(s[1]); if (N >= M) { Console.WriteLine(0); return; } int[] v = new int[M]; s = Console.ReadLine().Split(' '); for (int i = 0; i < M; i++) { v[i] = int.Parse(s[i]); } Array.Sort(v); if (1 == N) { Console.WriteLine(v[M - 1] - v[0]); return; } List<Element> elist = new List<Element>(); for (int i = 0; i < M - 1; i++) { Element e = new Element(); e.leftIndex = i; e.distanceToRight = v[i + 1] - v[i]; elist.Add(e); } elist.Sort(); elist.Reverse(); elist.RemoveRange(N - 1, M - N); Element.sortIndex = true; elist.Sort(); int ans = v[elist[0].leftIndex] - v[0]; ans += v[M - 1] - v[elist[elist.Count - 1].leftIndex + 1]; for (int i = 0; i < elist.Count - 1; i++) { ans += v[elist[i + 1].leftIndex] - v[elist[i].leftIndex + 1]; } Console.WriteLine(ans); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
430
27