buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); List<string> list = new List<string>(); string before = sc.Next(); list.Add(before); bool ok = true; for (int i = 0; i < n - 1; i++) { string after = sc.Next(); if (before.Last() != after.First()) { ok = false; break; } if (list.Contains(after)) { ok = false; break; } list.Add(after); } string answer = ok ? "Yes" : "No"; 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(); int n = sc.NextInt(); List<string> list = new List<string>(); string before = sc.Next(); list.Add(before); bool ok = true; for (int i = 0; i < n - 1; i++) { string after = sc.Next(); if (before.Last() != after.First()) { ok = false; break; } if (list.Contains(after)) { ok = false; break; } list.Add(after); before = after; } string answer = ok ? "Yes" : "No"; 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, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
471
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionB { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 var n = int.Parse(Console.ReadLine()); var w = new string[n]; for (int i = 0; i < n; i++) { w[i] = Console.ReadLine(); } var myHash = new HashSet<string>(); var last = ""; foreach (var s in w) { if (string.IsNullOrWhiteSpace(last) == false) { if (s[0] == last.Last() == false) { Console.WriteLine("No"); Console.Out.Flush(); return; } } else if (myHash.Contains(s)) { Console.WriteLine("No"); Console.Out.Flush(); return; } myHash.Add(s); } Console.WriteLine("Yes"); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionB { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 var n = int.Parse(Console.ReadLine()); var w = new string[n]; for (int i = 0; i < n; i++) { w[i] = Console.ReadLine(); } var myHash = new HashSet<string>(); var last = ""; foreach (var s in w) { if (string.IsNullOrWhiteSpace(last) == false) { if (s[0] == last.Last() == false) { Console.WriteLine("No"); Console.Out.Flush(); return; } } if (myHash.Contains(s)) { Console.WriteLine("No"); Console.Out.Flush(); return; } myHash.Add(s); last = s; } Console.WriteLine("Yes"); Console.Out.Flush(); } } }
[["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 12, 22]]
8
259
5
using Atcoder; using System; using System.Collections.Generic; using System.ComponentModel.Design; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); List<string> spokeList = new List<string>(); for (int i = 0; i < N; i++) { var tmpSpoke = Console.ReadLine(); if (spokeList.Count > 0 && spokeList.Last().Last() != tmpSpoke.Last() && spokeList.Contains(tmpSpoke)) { Console.WriteLine("No"); return; } spokeList.Add(tmpSpoke); } Console.WriteLine("Yes"); } // static void Main(string[] args) //{ // var temp = new Atcoder.ABC130.D(); // temp.Run(); //} } }
using Atcoder; using System; using System.Collections.Generic; using System.ComponentModel.Design; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); List<string> spokeList = new List<string>(); for (int i = 0; i < N; i++) { var tmpSpoke = Console.ReadLine(); if (spokeList.Count > 0 && (spokeList.Last().Last() != tmpSpoke.First() || spokeList.Contains(tmpSpoke))) { Console.WriteLine("No"); return; } spokeList.Add(tmpSpoke); } Console.WriteLine("Yes"); } // static void Main(string[] args) //{ // var temp = new Atcoder.ABC130.D(); // temp.Run(); //} } }
[["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["-", 31, 16, 12, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 106], ["+", 12, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
8
174
6
using System; using System.Linq; public class c { public static void Main() { int n = int.Parse(Console.ReadLine()); string[] siritori = new string[n]; string ans = "Yes"; for (int i = 0; i < n; i++) { siritori[i] = Console.ReadLine(); } for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (siritori[i] == siritori[j]) { ans = "No"; goto end; } } if (siritori[i][siritori[i].Length - 1] == siritori[i + 1][0]) { ans = "No"; goto end; } } end: Console.WriteLine(ans); } }
using System; using System.Linq; public class c { public static void Main() { int n = int.Parse(Console.ReadLine()); string[] siritori = new string[n]; string ans = "Yes"; for (int i = 0; i < n; i++) { siritori[i] = Console.ReadLine(); } for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (siritori[i] == siritori[j]) { ans = "No"; goto end; } } if (siritori[i][siritori[i].Length - 1] != siritori[i + 1][0]) { ans = "No"; goto end; } } end: Console.WriteLine(ans); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79]]
8
186
2
using System; using System.Linq; using System.Collections.Generic; class Plogram { static void Main() { int num = int.Parse(Console.ReadLine()); var W = new List<string>(); string str; string ans = "Yes"; for (int i = 0; i < num; i++) { str = Console.ReadLine(); if (W.Contains(str)) { ans = "No"; break; } W.Add(str); } for (int i = 0; i < num - 1; i++) { if (W[i].Last() != W[i + 1].First()) { ans = "No"; break; } } Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; class Plogram { static void Main() { int num = int.Parse(Console.ReadLine()); var W = new List<string>(); string str; string ans = "Yes"; for (int i = 0; i < num; i++) { str = Console.ReadLine(); if (W.Contains(str)) { ans = "No"; } W.Add(str); } for (int i = 0; i < num - 1; i++) { if (W[i].Last() != W[i + 1].First()) { ans = "No"; break; } } Console.WriteLine(ans); } }
[["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35]]
8
168
2
using System; class Program { static void Main(string[] args) { var n = Read(); string[] w = new string[n]; bool b = true; for (int i = 0; i < n; i++) { w[i] = ReadStr(); for (int j = 0; j < i; j++) { if (w[j] == w[i]) { b = false; break; } } if (i > 0 && w[i - 1][w[i - 1].Length - 2] != w[i][0]) { b = false; } if (!b) { break; } } Yn(b); } static void Write(string s) { Console.WriteLine(s); return; } static void Write(long n) { Console.WriteLine(n.ToString()); return; } static string ReadStr() { return Console.ReadLine(); } static string[] ReadStrs() { return Console.ReadLine().Split(' '); } static long Read() { return long.Parse(Console.ReadLine()); } static long[] Read(long n) { long[] p = new long[n]; string[] t = Console.ReadLine().Split(' '); for (long i = 0; i < n; i++) { p[i] = long.Parse(t[i]); } return p; } static long abs(long n) { return (n > 0) ? n : -n; } static long gcd(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = gcd(p, n[i]); } return p; } static long gcd(long a, long b) { return (a == 0) ? b : gcd(b % a, a); } static long lcm(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = lcm(p, n[i]); } return p; } static long lcm(long a, long b) { return a * b / gcd(a, b); } static long max(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } static long min(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } static void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } static void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } static void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } static string clip(string s, int start, int count) { if (start + count < s.Length) { s = s.Remove(start + count); } if (start > 0) { s = s.Remove(0, start); } return s; } static long ConvToLong(string n, int b) { long m = 0; long t = 1; for (int i = n.Length - 1; i >= 0; i--) { int k = int.Parse(n[i].ToString()); m += t * k; t *= b; } return m; } }
using System; class Program { static void Main(string[] args) { var n = Read(); string[] w = new string[n]; bool b = true; for (int i = 0; i < n; i++) { w[i] = ReadStr(); for (int j = 0; j < i; j++) { if (w[j] == w[i]) { b = false; break; } } if (i > 0 && w[i - 1][w[i - 1].Length - 1] != w[i][0]) { b = false; } if (!b) { break; } } Yn(b); } static void Write(string s) { Console.WriteLine(s); return; } static void Write(long n) { Console.WriteLine(n.ToString()); return; } static string ReadStr() { return Console.ReadLine(); } static string[] ReadStrs() { return Console.ReadLine().Split(' '); } static long Read() { return long.Parse(Console.ReadLine()); } static long[] Read(long n) { long[] p = new long[n]; string[] t = Console.ReadLine().Split(' '); for (long i = 0; i < n; i++) { p[i] = long.Parse(t[i]); } return p; } static long abs(long n) { return (n > 0) ? n : -n; } static long gcd(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = gcd(p, n[i]); } return p; } static long gcd(long a, long b) { return (a == 0) ? b : gcd(b % a, a); } static long lcm(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = lcm(p, n[i]); } return p; } static long lcm(long a, long b) { return a * b / gcd(a, b); } static long max(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } static long min(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } static void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } static void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } static void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } static string clip(string s, int start, int count) { if (start + count < s.Length) { s = s.Remove(start + count); } if (start > 0) { s = s.Remove(0, start); } return s; } static long ConvToLong(string n, int b) { long m = 0; long t = 1; for (int i = n.Length - 1; i >= 0; i--) { int k = int.Parse(n[i].ToString()); m += t * k; t *= b; } return m; } }
[["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
828
2
using System; namespace ABC109_B_Shiritori { internal class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] words = new string[n]; string ans = "Yes"; for (int i = 0; i < n; i++) { words[i] = Console.ReadLine(); if (i > 1) { string firstWord = words[i].Substring(0, 1); string lastWord = words[i - 1].Substring(words[i - 1].Length - 1, 1); if (firstWord != lastWord) { ans = "No"; } } } for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (words[i] == words[j]) { ans = "No"; } } } Console.WriteLine(ans); } } }
using System; namespace ABC109_B_Shiritori { internal class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] words = new string[n]; string ans = "Yes"; for (int i = 0; i < n; i++) { words[i] = Console.ReadLine(); if (i >= 1) { string firstWord = words[i].Substring(0, 1); string lastWord = words[i - 1].Substring(words[i - 1].Length - 1, 1); if (firstWord != lastWord) { ans = "No"; } } } for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (words[i] == words[j]) { ans = "No"; } } } Console.WriteLine(ans); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
8
209
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderbeginner109 { class Program { static void Main(string[] args) { int n; Int32.TryParse(Console.ReadLine(), out n); var ret = new B(n).Do(); Console.WriteLine(ret ? "Yes" : "no"); } } class B { private List<string> words; private int n; public B(int n) { this.n = n; words = new List<string>(); } public bool Do() { for (int i = 0; i < n; i++) { var word = Console.ReadLine(); if (words.Contains(word)) { return false; } if (words.Any() && word[0] != words.Last().Last()) { return false; } words.Add(word); } return true; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderbeginner109 { class Program { static void Main(string[] args) { int n; Int32.TryParse(Console.ReadLine(), out n); var ret = new B(n).Do(); Console.WriteLine(ret ? "Yes" : "No"); } } class B { private List<string> words; private int n; public B(int n) { this.n = n; words = new List<string>(); } public bool Do() { for (int i = 0; i < n; i++) { var word = Console.ReadLine(); if (words.Contains(word)) { return false; } if (words.Any() && word[0] != words.Last().Last()) { return false; } words.Add(word); } return true; } } }
[["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
214
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { var h = new HashSet<String>(); for (int i = 0; i < N; i++) { if (h.Contains(S[i])) { Console.WriteLine("No"); return; } if (i > 1) { char last = S[i - 1][S[i - 1].Length - 1]; char first = S[i][0]; if (last != first) { Console.WriteLine("No"); return; } } h.Add(S[i]); } Console.WriteLine("Yes"); } int N; String[] S; public Sol() { N = ri(); S = new String[N]; for (int i = 0; i < N; i++) S[i] = rs(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { var h = new HashSet<String>(); for (int i = 0; i < N; i++) { if (h.Contains(S[i])) { Console.WriteLine("No"); return; } if (i > 0) { char last = S[i - 1][S[i - 1].Length - 1]; char first = S[i][0]; if (last != first) { Console.WriteLine("No"); return; } } h.Add(S[i]); } Console.WriteLine("Yes"); } int N; String[] S; public Sol() { N = ri(); S = new String[N]; for (int i = 0; i < N; i++) S[i] = rs(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203]]
8
464
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; // using System.Text; // 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(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; } void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; } void solve() { int n = cin.nextint; var H = new HashSet<string>(); char before = 'a'; for (int i = 0; i < n; i++) { var S = ReadLine(); if (H.Contains(S)) { WriteLine("No"); } if (i > 0 && S[0] != before) { WriteLine("No"); } H.Add(S); before = S[S.Count() - 1]; } WriteLine("Yes"); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return 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 { get { return int.Parse(next); } } public long nextlong { get { return long.Parse(next); } } public double nextdouble { get { return double.Parse(next); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; // using System.Text; // 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(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; } void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; } void solve() { int n = cin.nextint; var H = new HashSet<string>(); char before = 'a'; for (int i = 0; i < n; i++) { var S = ReadLine(); if (H.Contains(S)) { WriteLine("No"); return; } if (i > 0 && S[0] != before) { WriteLine("No"); return; } H.Add(S); before = S[S.Count() - 1]; } WriteLine("Yes"); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return 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 { get { return int.Parse(next); } } public long nextlong { get { return long.Parse(next); } } public double nextdouble { get { return double.Parse(next); } } }
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
530
4
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 long[] nx = Console.ReadLine().Split().Select(long.Parse).ToArray(); long n = nx[0]; long x = nx[1]; long[] xcity = Console.ReadLine().Split().Select(long.Parse).ToArray(); long[] tmp = new long[n + 1]; tmp[0] = x; for (int i = 1; i < n + 1; i++) { tmp[i] = xcity[i - 1]; } Array.Sort(tmp); long[] diff = new long[n]; for (int i = 0; i < n; i++) { diff[i] = tmp[i + 1] - tmp[i]; } //配列の最大公約数を求める long ans = 0; if (x == 1) { ans = diff[0]; } else { ans = Gcd(diff[0], diff[1]); for (int i = 2; i < diff.Length; i++) { ans = Gcd(ans, diff[2]); } } Console.WriteLine(ans); } // ユークリッドの互除法 // 最大公約数を求める 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; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 long[] nx = Console.ReadLine().Split().Select(long.Parse).ToArray(); long n = nx[0]; long x = nx[1]; long[] xcity = Console.ReadLine().Split().Select(long.Parse).ToArray(); long[] tmp = new long[n + 1]; tmp[0] = x; for (int i = 1; i < n + 1; i++) { tmp[i] = xcity[i - 1]; } Array.Sort(tmp); long[] diff = new long[n]; for (int i = 0; i < n; i++) { diff[i] = tmp[i + 1] - tmp[i]; } //配列の最大公約数を求める long ans = 0; if (n == 1) { ans = diff[0]; } else { ans = Gcd(diff[0], diff[1]); for (int i = 2; i < n; i++) { ans = Gcd(ans, diff[i]); } } Console.WriteLine(ans); } // ユークリッドの互除法 // 最大公約数を求める 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, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 75, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 75, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 75, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 57, 75, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22]]
8
342
8
using System; using System.Collections.Generic; namespace MyProgram { class AtCoder { static void Main(string[] args) { long[] input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long N = input[0]; long X = input[1]; long[] x = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); for (var i = 0; i < N; i++) { x[i] += -X; } long temp = x[0]; for (var i = 1; i < N; i++) { temp = Gcd(Math.Abs(temp), Math.Abs(x[i])); } Console.WriteLine(temp); } static long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } } }
using System; using System.Collections.Generic; namespace MyProgram { class AtCoder { static void Main(string[] args) { long[] input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long N = input[0]; long X = input[1]; long[] x = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); for (var i = 0; i < N; i++) { x[i] += -X; } long temp = Math.Abs(x[0]); for (var i = 1; i < N; i++) { temp = Gcd(Math.Abs(temp), Math.Abs(x[i])); } Console.WriteLine(temp); } static long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } } }
[["+", 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
218
5
// optional using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; public static class Program { private const int MAX = 10000000; public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion try { var nx = ReadLib.ReadAsIntArray(); var d = ReadLib.ReadAsIntArray() .Select(v => (long)Math.Abs(v - nx[0])) .Aggregate((a, b) => MyMath.Gcd(a, b)); Console.WriteLine(d); } finally { #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } private static long Calculate(IEnumerable<long> particalArr, Dictionary<long, int> targetNums) { var vs = particalArr.CountUp(); var digitNum = new List<long>(); foreach (var targetNum in targetNums) { var localScore = MyMath.Combination(vs[targetNum.Key], targetNum.Value); Console.WriteLine( $"{vs[targetNum.Key]} {targetNum.Value} -> {localScore}"); digitNum.Add(localScore); } return digitNum.Aggregate((a, b) => a * b); } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static char[][] ReadNTimesAsCharArray(int n) { return Enumerable.Range(1, n) .Select(i => Console.ReadLine().ToArray()) .ToArray(); } public static long[] ReadNTimesAsLong(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => long.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } public static char[,] ReadMapAsChar(int hSize, int wSize) { var map = new char[hSize, wSize]; for (int h = 0; h < hSize; h++) { var a = Console.ReadLine(); for (int w = 0; w < wSize; w++) { map[h, w] = a[w]; } } return map; } } namespace Heaps { /// <summary>優先度付きキュー</summary> public class PriorityQueue<T> : IEnumerable<T>, IReadOnlyCollection<T> where T : IComparable<T> { public List<T> HeapArray { get; } public T NIL { get; } public bool IsMax { get; } public int Count => HeapArray.Count; /// <param name="heapArray">ヒープ</param> /// <param name="NIL">NILの値</param> /// <param /// name="IsMax">True時:大きい方から取り出す、False時:小さい方から取り出す</param> public PriorityQueue(T NIL, IEnumerable<T> heapArray = null, bool IsMax = true) { this.HeapArray = heapArray == null ? new List<T>() : heapArray.ToList(); this.NIL = NIL; this.IsMax = IsMax; Update(); } /// <summary>KeyのValueを取得</summary> public T this[int id] { get { if (id <= 0 || id > HeapArray.Count) { return NIL; } return HeapArray[id - 1]; } } class Node { public int Key { get; } public T Value => outer[Key]; readonly PriorityQueue<T> outer; public Node(int key, PriorityQueue<T> outer) { Key = key; this.outer = outer; } public Node Left { get { var leftKey = 2 * Key; return new Node(leftKey, outer); } } public Node Right { get { var rightkey = 2 * Key + 1; return new Node(rightkey, outer); } } public Node Parent { get { var parentKey = Key / 2; return new Node(parentKey, outer); } } } private Node GetNode(int key) { return new Node(key, this); } /// <summary>max Heap木とする O(N)</summary> public void Update() { var n = HeapArray.Count() / 2; /// <summary>葉から順に処理を行う</summary> for (int i = n; i >= 1; i--) { Heapify(i); } } /// <summary>idを根とする部分木について、Heap木を維持したまま、idを下降させる</summary> private void Heapify(int key) { var current = GetNode(key); var left = current.Left; var right = current.Right; var largest = current; var sign = IsMax ? 1 : -1; if (left.Value.CompareTo(NIL) != 0 && left.Value.CompareTo(current.Value) * sign > 0) { largest = left; } if (right.Value.CompareTo(NIL) != 0 && right.Value.CompareTo(largest.Value) * sign > 0) { largest = right; } if (largest.Key != key) { HeapArray.Swap(key - 1, largest.Key - 1); // 元と異なるときはSwapする Heapify( largest .Key); // largest.Key は元のkeyの場所。葉で更にMaxHeaptyを行う。 } } /// <summary>keyの値を挿入する</summary> public void Enqueue(T value) { HeapArray.Add(value); var inserted = GetNode(HeapArray.Count); // 末尾に挿入 var parent = inserted.Parent; var sign = IsMax ? 1 : -1; // 挿入Nodeが根になる or 親 > 子になるまで親とNodeを交換 while (inserted.Key > 1 && value.CompareTo(parent.Value) * sign > 0) { HeapArray.Swap(inserted.Key - 1, parent.Key - 1); inserted = parent; parent = inserted.Parent; } } public T Dequeue() { if (HeapArray.Count == 0) { return NIL; } var popVal = HeapArray.First(); var newRootVal = HeapArray.Last(); // 新しい根となる。 HeapArray.RemoveAt(HeapArray.Count - 1); // del last if (HeapArray.Count > 0) { HeapArray[0] = newRootVal; Heapify(1); } return popVal; } public T Peek() { return HeapArray.First(); } public IEnumerator<T> GetEnumerator() { while (HeapArray.Count > 0) { yield return Dequeue(); } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public void Clear() { HeapArray.Clear(); } public bool Contains(T val) { return HeapArray.Contains(val); } public PriorityQueue<T> Clone() { return new PriorityQueue<T>(NIL, HeapArray.DeepCopy()); } } } /// <summary>拡張メソッドs</summary> static class MyExtention { /// <summary>iとjを入れ替える</summary> public static void Swap<T>(this T[] arr, int i, int j) { var buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } public static void Swap<T>(this List<T> list, int i, int j) { var buf = list[i]; list[i] = list[j]; list[j] = buf; } /// <summary> /// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。 /// </summary> /// <param name="sArr"></param> /// <param name="p">partitionの先頭の添字</param> /// <param name="r">partitionの末尾の添字</param> /// <returns>partitionの基準が存在する添字</returns> public static int Partition(this int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } /// <summary>深いコピーをする</summary> public static T DeepCopy<T>(this T obj) { T result; var b = new BinaryFormatter(); using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } public static string Left(this string str, int length) { return str.Substring(0, length); } public static string Right(this string str, int length) { return str.Substring(str.Length - length, length); } public static int Find<T>(this T[] array, T obj) { return Array.IndexOf(array, obj); } public static int LastFind<T>(this T[] array, T obj) { return Array.LastIndexOf(array, obj); } /// <summary>同一の値で埋める</summary> public static void Initialize<T>(this T[,] array, T value) { for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { array[i, j] = value; } } } /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(this IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } /// <summary>ある要素を持つindexをすべて返す</summary> public static int[] InducesOfValue<T>(this T[] arr, T searchValue) { return arr.Select((v, i) => new { v, i }) .Where(o => searchValue.Equals(o.v)) .Select(o => o.i) .ToArray(); } /// <summary>ある要素を持つindexをすべて返す</summary> public static int[] Induces<T>(this IEnumerable<T> arr, T searchValue) { return arr.ToArray().InducesOfValue(searchValue); } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } public static ModCombination ModCombination(int maxN, int mod = 1000000007) { return new ModCombination(maxN, mod); } /// <summary>a^n mod</summary> public static int ModPow(long a, long n, int mod = 1000000007) { long res = 1; long pow = a; while (n > 0) { if ((n & 1) == 1) { res = (pow * res) % mod; // resにaをかける } pow = (pow * pow) % mod; // 次のaはa^2 n >>= 1; } return (int)res; } /// <summary>約数を列挙</summary> public static long[] Divisors(long n) { var ret = new List<long>(); var sqrt = Math.Ceiling(Math.Sqrt(n)); for (long i = 1; i <= sqrt; i++) { if (i * i > n) { continue; } if (n % i != 0) { continue; } ret.Add(i); if (n / i == i) { continue; } ret.Add(n / i); } return ret.ToArray(); } /// <summary>Combination。nCk。O(nk)</summary> /// <see cref="http://caprest.hatenablog.com/entry/2016/05/29/181102"/> public static long Combination(int n, int k) { if (n < k) { return 0; } var dp = new long [n + 1][]; // nCkのdp for (int i = 0; i <= n; i++) { dp[i] = new long[n + 1]; } for (int i = 0; i <= n; i++) { dp[i][0] = 1; dp[i][i] = 1; } for (int i = 1; i <= n; i++) { for (int j = 1; j < i; j++) { // nCk = n-1Ck-1 + n-1Ck dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]; } } return dp[n][k]; } } /// <summary>組み合わせ</summary> /// * Combination, nCk mod p を求める /// https://ja.wikipedia.org/wiki/%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%A9%E9%80%86%E6%95%B0 /// http://drken1215.hatenablog.com/entry/2018/06/08/210000 class ModCombination { private int mod; private int[] fac; private int[] finv; /// <summary> /// /// </summary> /// <param name="nMax"></param> /// <param name="mod"></param> public ModCombination(int nMax, int mod = 1000000007) { this.mod = mod; fac = new int[nMax]; // modが法のn!の列 fac[0] = 1; fac[1] = 1; finv = new int[nMax]; // modを法とした、invの累積の累積 finv[0] = 1; finv[1] = 1; var inv = new int[nMax]; // indexの逆元(モジュラ逆数)の列 inv[1] = 1; for (int i = 2; i < nMax; i++) { fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める // mod % i < i // modの倍数を加えても逆元である var s = Math.BigMul(inv[mod % i], mod / i) % mod; inv[i] = (int)(mod - s);   // iに対する逆元を求める finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod); } } /// <summary>nCk</summary> public int Calculation(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (int)(Math.BigMul(fac[n], (int)(Math.BigMul(finv[k], finv[n - k]) % mod)) % mod); } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator -(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value - item2.Value; if (value < 0) { value += item1.Mod; } return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { return item1 + new ModInt(item2, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { return item1 * new ModInt(item2, item1.Mod); } public static ModInt operator -(ModInt item1, int item2) { return item1 - new ModInt(item2, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } }
// optional using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; public static class Program { private const int MAX = 10000000; public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion try { var nx = ReadLib.ReadAsIntArray(); var d = ReadLib.ReadAsIntArray() .Select(v => (long)Math.Abs(v - nx[1])) .Aggregate((a, b) => MyMath.Gcd(a, b)); Console.WriteLine(d); } finally { #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } private static long Calculate(IEnumerable<long> particalArr, Dictionary<long, int> targetNums) { var vs = particalArr.CountUp(); var digitNum = new List<long>(); foreach (var targetNum in targetNums) { var localScore = MyMath.Combination(vs[targetNum.Key], targetNum.Value); Console.WriteLine( $"{vs[targetNum.Key]} {targetNum.Value} -> {localScore}"); digitNum.Add(localScore); } return digitNum.Aggregate((a, b) => a * b); } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static char[][] ReadNTimesAsCharArray(int n) { return Enumerable.Range(1, n) .Select(i => Console.ReadLine().ToArray()) .ToArray(); } public static long[] ReadNTimesAsLong(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => long.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } public static char[,] ReadMapAsChar(int hSize, int wSize) { var map = new char[hSize, wSize]; for (int h = 0; h < hSize; h++) { var a = Console.ReadLine(); for (int w = 0; w < wSize; w++) { map[h, w] = a[w]; } } return map; } } namespace Heaps { /// <summary>優先度付きキュー</summary> public class PriorityQueue<T> : IEnumerable<T>, IReadOnlyCollection<T> where T : IComparable<T> { public List<T> HeapArray { get; } public T NIL { get; } public bool IsMax { get; } public int Count => HeapArray.Count; /// <param name="heapArray">ヒープ</param> /// <param name="NIL">NILの値</param> /// <param /// name="IsMax">True時:大きい方から取り出す、False時:小さい方から取り出す</param> public PriorityQueue(T NIL, IEnumerable<T> heapArray = null, bool IsMax = true) { this.HeapArray = heapArray == null ? new List<T>() : heapArray.ToList(); this.NIL = NIL; this.IsMax = IsMax; Update(); } /// <summary>KeyのValueを取得</summary> public T this[int id] { get { if (id <= 0 || id > HeapArray.Count) { return NIL; } return HeapArray[id - 1]; } } class Node { public int Key { get; } public T Value => outer[Key]; readonly PriorityQueue<T> outer; public Node(int key, PriorityQueue<T> outer) { Key = key; this.outer = outer; } public Node Left { get { var leftKey = 2 * Key; return new Node(leftKey, outer); } } public Node Right { get { var rightkey = 2 * Key + 1; return new Node(rightkey, outer); } } public Node Parent { get { var parentKey = Key / 2; return new Node(parentKey, outer); } } } private Node GetNode(int key) { return new Node(key, this); } /// <summary>max Heap木とする O(N)</summary> public void Update() { var n = HeapArray.Count() / 2; /// <summary>葉から順に処理を行う</summary> for (int i = n; i >= 1; i--) { Heapify(i); } } /// <summary>idを根とする部分木について、Heap木を維持したまま、idを下降させる</summary> private void Heapify(int key) { var current = GetNode(key); var left = current.Left; var right = current.Right; var largest = current; var sign = IsMax ? 1 : -1; if (left.Value.CompareTo(NIL) != 0 && left.Value.CompareTo(current.Value) * sign > 0) { largest = left; } if (right.Value.CompareTo(NIL) != 0 && right.Value.CompareTo(largest.Value) * sign > 0) { largest = right; } if (largest.Key != key) { HeapArray.Swap(key - 1, largest.Key - 1); // 元と異なるときはSwapする Heapify( largest .Key); // largest.Key は元のkeyの場所。葉で更にMaxHeaptyを行う。 } } /// <summary>keyの値を挿入する</summary> public void Enqueue(T value) { HeapArray.Add(value); var inserted = GetNode(HeapArray.Count); // 末尾に挿入 var parent = inserted.Parent; var sign = IsMax ? 1 : -1; // 挿入Nodeが根になる or 親 > 子になるまで親とNodeを交換 while (inserted.Key > 1 && value.CompareTo(parent.Value) * sign > 0) { HeapArray.Swap(inserted.Key - 1, parent.Key - 1); inserted = parent; parent = inserted.Parent; } } public T Dequeue() { if (HeapArray.Count == 0) { return NIL; } var popVal = HeapArray.First(); var newRootVal = HeapArray.Last(); // 新しい根となる。 HeapArray.RemoveAt(HeapArray.Count - 1); // del last if (HeapArray.Count > 0) { HeapArray[0] = newRootVal; Heapify(1); } return popVal; } public T Peek() { return HeapArray.First(); } public IEnumerator<T> GetEnumerator() { while (HeapArray.Count > 0) { yield return Dequeue(); } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public void Clear() { HeapArray.Clear(); } public bool Contains(T val) { return HeapArray.Contains(val); } public PriorityQueue<T> Clone() { return new PriorityQueue<T>(NIL, HeapArray.DeepCopy()); } } } /// <summary>拡張メソッドs</summary> static class MyExtention { /// <summary>iとjを入れ替える</summary> public static void Swap<T>(this T[] arr, int i, int j) { var buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } public static void Swap<T>(this List<T> list, int i, int j) { var buf = list[i]; list[i] = list[j]; list[j] = buf; } /// <summary> /// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。 /// </summary> /// <param name="sArr"></param> /// <param name="p">partitionの先頭の添字</param> /// <param name="r">partitionの末尾の添字</param> /// <returns>partitionの基準が存在する添字</returns> public static int Partition(this int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } /// <summary>深いコピーをする</summary> public static T DeepCopy<T>(this T obj) { T result; var b = new BinaryFormatter(); using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } public static string Left(this string str, int length) { return str.Substring(0, length); } public static string Right(this string str, int length) { return str.Substring(str.Length - length, length); } public static int Find<T>(this T[] array, T obj) { return Array.IndexOf(array, obj); } public static int LastFind<T>(this T[] array, T obj) { return Array.LastIndexOf(array, obj); } /// <summary>同一の値で埋める</summary> public static void Initialize<T>(this T[,] array, T value) { for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { array[i, j] = value; } } } /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(this IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } /// <summary>ある要素を持つindexをすべて返す</summary> public static int[] InducesOfValue<T>(this T[] arr, T searchValue) { return arr.Select((v, i) => new { v, i }) .Where(o => searchValue.Equals(o.v)) .Select(o => o.i) .ToArray(); } /// <summary>ある要素を持つindexをすべて返す</summary> public static int[] Induces<T>(this IEnumerable<T> arr, T searchValue) { return arr.ToArray().InducesOfValue(searchValue); } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } public static ModCombination ModCombination(int maxN, int mod = 1000000007) { return new ModCombination(maxN, mod); } /// <summary>a^n mod</summary> public static int ModPow(long a, long n, int mod = 1000000007) { long res = 1; long pow = a; while (n > 0) { if ((n & 1) == 1) { res = (pow * res) % mod; // resにaをかける } pow = (pow * pow) % mod; // 次のaはa^2 n >>= 1; } return (int)res; } /// <summary>約数を列挙</summary> public static long[] Divisors(long n) { var ret = new List<long>(); var sqrt = Math.Ceiling(Math.Sqrt(n)); for (long i = 1; i <= sqrt; i++) { if (i * i > n) { continue; } if (n % i != 0) { continue; } ret.Add(i); if (n / i == i) { continue; } ret.Add(n / i); } return ret.ToArray(); } /// <summary>Combination。nCk。O(nk)</summary> /// <see cref="http://caprest.hatenablog.com/entry/2016/05/29/181102"/> public static long Combination(int n, int k) { if (n < k) { return 0; } var dp = new long [n + 1][]; // nCkのdp for (int i = 0; i <= n; i++) { dp[i] = new long[n + 1]; } for (int i = 0; i <= n; i++) { dp[i][0] = 1; dp[i][i] = 1; } for (int i = 1; i <= n; i++) { for (int j = 1; j < i; j++) { // nCk = n-1Ck-1 + n-1Ck dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]; } } return dp[n][k]; } } /// <summary>組み合わせ</summary> /// * Combination, nCk mod p を求める /// https://ja.wikipedia.org/wiki/%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%A9%E9%80%86%E6%95%B0 /// http://drken1215.hatenablog.com/entry/2018/06/08/210000 class ModCombination { private int mod; private int[] fac; private int[] finv; /// <summary> /// /// </summary> /// <param name="nMax"></param> /// <param name="mod"></param> public ModCombination(int nMax, int mod = 1000000007) { this.mod = mod; fac = new int[nMax]; // modが法のn!の列 fac[0] = 1; fac[1] = 1; finv = new int[nMax]; // modを法とした、invの累積の累積 finv[0] = 1; finv[1] = 1; var inv = new int[nMax]; // indexの逆元(モジュラ逆数)の列 inv[1] = 1; for (int i = 2; i < nMax; i++) { fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める // mod % i < i // modの倍数を加えても逆元である var s = Math.BigMul(inv[mod % i], mod / i) % mod; inv[i] = (int)(mod - s);   // iに対する逆元を求める finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod); } } /// <summary>nCk</summary> public int Calculation(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (int)(Math.BigMul(fac[n], (int)(Math.BigMul(finv[k], finv[n - k]) % mod)) % mod); } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator -(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value - item2.Value; if (value < 0) { value += item1.Mod; } return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { return item1 + new ModInt(item2, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { return item1 * new ModInt(item2, item1.Mod); } public static ModInt operator -(ModInt item1, int item2) { return item1 - new ModInt(item2, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } }
[["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
3,908
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static int[] hs; static long ans; static void Main(string[] args) { long[] nx = ReadLine().Split(' ').Select(long.Parse).ToArray(); long n = nx[0]; long x = nx[1]; long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray(); var ls = new List<long>(); ls.AddRange(s); ls.Add(x); ls.Sort(); var SaLs = new List<long>(); for (int i = 0; i < ls.Count - 1; i++) { SaLs.Add(ls[i + 1] - ls[i]); } if (n > 1) { long tmp = Gcd(SaLs[0], SaLs[1]); for (int i = 2; i < n; i++) { tmp = Gcd(tmp, SaLs[i]); } WriteLine(tmp); } else WriteLine(s[0] - x); } static long Gcd(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static int[] hs; static long ans; static void Main(string[] args) { long[] nx = ReadLine().Split(' ').Select(long.Parse).ToArray(); long n = nx[0]; long x = nx[1]; long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray(); var ls = new List<long>(); ls.AddRange(s); ls.Add(x); ls.Sort(); var SaLs = new List<long>(); for (int i = 0; i < ls.Count - 1; i++) { SaLs.Add(ls[i + 1] - ls[i]); } if (n > 1) { long tmp = Gcd(SaLs[0], SaLs[1]); for (int i = 2; i < n; i++) { tmp = Gcd(tmp, SaLs[i]); } WriteLine(tmp); } else WriteLine(Abs(s[0] - x)); } static long Gcd(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
346
3
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! int[] a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int[] x = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int N = a[0]; int X = a[1]; int ans = X - x[0]; for (int i = 1; i < N; i++) { ans = gcd(ans, Math.Abs(X - x[i])); } Console.WriteLine(ans); } public static int gcd(int a, int b) //最大公約数を求める { if (a < b) // a < bのとき,aとbを入れ替える. { int tmp = a; a = b; b = tmp; } if (b < 1) // aとbは自然数でないとだめ.bが自然数でないならば-1を返す. { return -1; } int r = a % b; //終了条件 if (r == 0) { return b; } return gcd(b, r); } }
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! int[] a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int[] x = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int N = a[0]; int X = a[1]; int ans = Math.Abs(X - x[0]); for (int i = 1; i < N; i++) { ans = gcd(ans, Math.Abs(X - x[i])); } Console.WriteLine(ans); } public static int gcd(int a, int b) //最大公約数を求める { if (a < b) // a < bのとき,aとbを入れ替える. { int tmp = a; a = b; b = tmp; } if (b < 1) // aとbは自然数でないとだめ.bが自然数でないならば-1を返す. { return -1; } int r = a % b; //終了条件 if (r == 0) { return b; } return gcd(b, r); } }
[["+", 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
234
5
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math; public class Hello { public static void Main() { string[] input = ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); // int a = int.Parse(input[2]); // int b = int.Parse(input[3]);*/ // string temp = ReadLine(); // int a = int.Parse(ReadLine()); // int b = int.Parse(ReadLine()); // int c = int.Parse(ReadLine()); // int d = int.Parse(ReadLine()); // string a = ReadLine(); // string b = ReadLine(); // string c = ReadLine(); WriteLine(n - m - 1); } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math; public class Hello { public static void Main() { string[] input = ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); // int a = int.Parse(input[2]); // int b = int.Parse(input[3]);*/ // string temp = ReadLine(); // int a = int.Parse(ReadLine()); // int b = int.Parse(ReadLine()); // int c = int.Parse(ReadLine()); // int d = int.Parse(ReadLine()); // string a = ReadLine(); // string b = ReadLine(); // string c = ReadLine(); WriteLine(n - m + 1); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
101
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; using Pair = System.Tuple<long, long>; /// <summary> /// https://atcoder.jp/contests/abc107 /// 2020/02/01 3完 R1330相当 /// </summary> namespace ABC107 { public class Program { public static void Main(string[] args) { START: // A(); 3m // B(); 13m // C(); 58m D(); // 分からん降参 #if DEBUG goto START; #endif } public static void D() {} public static void C() {} public static void B() {} public static void A() { long N = rl; long i = rl; Console.WriteLine(N + 1 - i); } public static void C2() { long N = rl; long K = rl; long[] xs = rla; long ans = INF; for (int i = 0; i <= N - K; i++) { long x = Abs(xs[i] - xs[i + K - 1]); long left = x + Abs(xs[i]); long right = x + Abs(xs[i + K - 1]); long res = Min(left, right); ChMin(ref ans, res); } Console.WriteLine(ans); } public static void B2() { long H = rl; long W = rl; string[] table = new string[H]; for (int i = 0; i < H; i++) { table[i] = ReadString(); } bool[] row = new bool[H]; bool[] col = new bool[W]; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (table[i][j] == '#') { row[i] = true; col[i] = true; } } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < H; i++) { if (!row[i]) continue; for (int j = 0; j < W; j++) { if (col[j]) sb.Append(table[i][j]); } sb.AppendLine(); } Write(sb.ToString()); } public static void A2() { long N = rl; long A = rl; Console.WriteLine(N - A + 1); } } } namespace Ha2ne2Util { public static class Cin { private static string[] Tokens { get; set; } private static int Pointer { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } public static int ReadInt() { return int.Parse(Next()); } public static long rl => ReadLong(); public static long[] rla => ReadLongArray(); public static double rd => ReadDouble(); public static double[] rda => ReadDoubleArray(); public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadArrays(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadArrays(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 降順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static long ModAdd(long a, long b) { long res = a + b; if (res >= MOD) return res % MOD; return res; } public static long ModMul(long a, long b) { long res = a * b; if (res >= MOD) return res % MOD; return res; } public static void ModAddEqual(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { public int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; using Pair = System.Tuple<long, long>; /// <summary> /// https://atcoder.jp/contests/abc107 /// 2020/02/01 3完 R1330相当 /// </summary> namespace ABC107 { public class Program { public static void Main(string[] args) { START: A(); // A(); 3m // B(); 13m // C(); 58m // D(); // 分からん降参 #if DEBUG goto START; #endif } public static void D() {} public static void C() {} public static void B() {} public static void A() { long N = rl; long i = rl; Console.WriteLine(N + 1 - i); } public static void C2() { long N = rl; long K = rl; long[] xs = rla; long ans = INF; for (int i = 0; i <= N - K; i++) { long x = Abs(xs[i] - xs[i + K - 1]); long left = x + Abs(xs[i]); long right = x + Abs(xs[i + K - 1]); long res = Min(left, right); ChMin(ref ans, res); } Console.WriteLine(ans); } public static void B2() { long H = rl; long W = rl; string[] table = new string[H]; for (int i = 0; i < H; i++) { table[i] = ReadString(); } bool[] row = new bool[H]; bool[] col = new bool[W]; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (table[i][j] == '#') { row[i] = true; col[i] = true; } } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < H; i++) { if (!row[i]) continue; for (int j = 0; j < W; j++) { if (col[j]) sb.Append(table[i][j]); } sb.AppendLine(); } Write(sb.ToString()); } public static void A2() { long N = rl; long A = rl; Console.WriteLine(N - A + 1); } } } namespace Ha2ne2Util { public static class Cin { private static string[] Tokens { get; set; } private static int Pointer { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } public static int ReadInt() { return int.Parse(Next()); } public static long rl => ReadLong(); public static long[] rla => ReadLongArray(); public static double rd => ReadDouble(); public static double[] rda => ReadDoubleArray(); public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadArrays(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadArrays(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 降順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static long ModAdd(long a, long b) { long res = a + b; if (res >= MOD) return res % MOD; return res; } public static long ModMul(long a, long b) { long res = a * b; if (res >= MOD) return res % MOD; return res; } public static void ModAddEqual(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { public int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
[["-", 8, 196, 0, 97, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 97, 0, 1, 0, 213, 63, 22]]
8
3,686
2
using System; using System.Linq; class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); // int a=int.Parse(Console.ReadLine()); // string a = Console.ReadLine(); Console.WriteLine(input[0] - input[1]); Console.ReadLine(); } }
using System; using System.Linq; class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); // int a=int.Parse(Console.ReadLine()); // string a = Console.ReadLine(); Console.WriteLine(input[0] - input[1] + 1); Console.ReadLine(); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
73
2
using System; using System.Linq; class P { static void Main() { int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = n[0]; int K = n[1]; Console.WriteLine(N + K - 1); } }
using System; using System.Linq; class P { static void Main() { int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = n[0]; int K = n[1]; Console.WriteLine(N - K + 1); } }
[["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
72
4
using System; using System.Linq; class P { static void Main() { int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = n[0]; int i = n[1]; Console.WriteLine(N - i); } }
using System; using System.Linq; class P { static void Main() { int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = n[0]; int i = n[1]; Console.WriteLine(N - i + 1); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
70
2
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var arr = Console.ReadLine().Split().Select(int.Parse).ToArray(); int h = arr[0]; int w = arr[1]; var a = new List<string>(); while (h-- > 0) { var s = Console.ReadLine(); if (s.All(x => x == '.')) continue; a.Add(s); } var c = new HashSet<int>(); for (int i = 0; i < a.Count; i++) { for (int j = 0; j < w; j++) { if (a[i][j] == '#') c.Add(j); } } for (int i = 0; i < a.Count; i++) { foreach (var j in c) { Console.Write(a[i][j]); } Console.WriteLine(); } } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var arr = Console.ReadLine().Split().Select(int.Parse).ToArray(); int h = arr[0]; int w = arr[1]; var a = new List<string>(); while (h-- > 0) { var s = Console.ReadLine(); if (s.All(x => x == '.')) continue; a.Add(s); } var c = new SortedSet<int>(); for (int i = 0; i < a.Count; i++) { for (int j = 0; j < w; j++) { if (a[i][j] == '#') c.Add(j); } } for (int i = 0; i < a.Count; i++) { foreach (var j in c) { Console.Write(a[i][j]); } Console.WriteLine(); } } }
[["-", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22]]
8
231
2
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.IO; using System.Linq; using System.Diagnostics; using System.Globalization; using static System.Console; using static System.Math; namespace abc107_b { class Program { static void Main(string[] args) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); int x = input[0]; int y = input[1]; string[,] arr = new string[x, y]; //データを入力 for (int i = 0; i < x; i++) { string str = Console.ReadLine(); for (int j = 0; j < y; j++) { arr[i, j] = str[j].ToString(); } } var row = new List<int>(); var colomn = new List<int>(); //横に'#'が含まれているか for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if (arr[i, j] == '#'.ToString()) { colomn.Add(j); break; } } } //縦に'#'が含まれているか for (int i = 0; i < y; i++) { for (int j = 0; j < x; j++) { if (arr[j, i] == '#'.ToString()) { row.Add(j); break; } } } for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if (row.Contains(i) && colomn.Contains(j)) { Write(arr[i, j]); } } if (colomn.Contains(i)) WriteLine(); } } } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.IO; using System.Linq; using System.Diagnostics; using System.Globalization; using static System.Console; using static System.Math; namespace abc107_b { class Program { static void Main(string[] args) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); int x = input[0]; int y = input[1]; string[,] arr = new string[x, y]; //データを入力 for (int i = 0; i < x; i++) { string str = Console.ReadLine(); for (int j = 0; j < y; j++) { arr[i, j] = str[j].ToString(); } } var row = new List<int>(); // #が一つでも入っている列 var colomn = new List<int>(); // #が一つでも入っている行 //横に'#'が含まれているか for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if (arr[i, j] == '#'.ToString()) { colomn.Add(i); break; } } } //縦に'#'が含まれているか for (int i = 0; i < y; i++) { for (int j = 0; j < x; j++) { if (arr[j, i] == '#'.ToString()) { row.Add(i); break; } } } for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if (row.Contains(j) && colomn.Contains(i)) { Write(arr[i, j]); } } if (colomn.Contains(i)) WriteLine(); } } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 15, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 15, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22]]
8
400
8
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace FertiLib.Contest.C { static class Program { public static void Solve(Scanner cin) { var (n, k) = cin.ReadValue<int, int>(); var a = cin.ReadIntArray(n); var neg = a.Where(x => x < 0).ToArray(); var pos = a.Where(x => x >= 0).ToArray(); int ans = int.MaxValue; for (int i = 0; i <= k; i++) { if (i > neg.Length) continue; if (k - i > pos.Length) continue; if (i == 0) Chmin(ref ans, pos[k - 1]); else if (k - i == 0) Chmin(ref ans, neg[neg.Length - k]); else { var t = pos[k - 1 - i] - neg[neg.Length - i]; t += Math.Min(pos[k - 1 - i], (-1) * neg[neg.Length - i]); Chmin(ref ans, t); } } Console.WriteLine(ans); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace FertiLib.Contest.C { static class Program { public static void Solve(Scanner cin) { var (n, k) = cin.ReadValue<int, int>(); var a = cin.ReadIntArray(n); var neg = a.Where(x => x < 0).ToArray(); var pos = a.Where(x => x >= 0).ToArray(); int ans = int.MaxValue; for (int i = 0; i <= k; i++) { if (i > neg.Length) continue; if (k - i > pos.Length) continue; if (i == 0) Chmin(ref ans, pos[k - 1]); else if (k - i == 0) Chmin(ref ans, (-1) * neg[neg.Length - k]); else { var t = pos[k - 1 - i] - neg[neg.Length - i]; t += Math.Min(pos[k - 1 - i], (-1) * neg[neg.Length - i]); Chmin(ref ans, t); } } Console.WriteLine(ans); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 241, 0, 33], ["+", 0, 28, 0, 16, 31, 23, 0, 241, 0, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48]]
8
2,839
5
using System; using System.Collections.Generic; using System.Linq; namespace Astar { /*class Node { Node((int x, int y) _pos, int _status, int _cost, int _h, int _score, Node node) { pos = _pos; status = _status; cost = _cost; h = _h; score = _score; parent = node; } public (int x, int y) pos; public int status; public int cost; public int h; public int score; public Node parent; }*/ /* class Program { static Node AddNode(int dx, int dy, int H, int W, int X, Node node, List<List<string>> s) { if (node.pos.x + dx < 0 || node.pos.y + dy < 0 || node.pos.x + dx >= W || node.pos.y + dy >= H) return null; int cost; int status; switch(s[node.pos.y + dy][node.pos.x + dx]) { case ".": cost = 1; status = 0; break; case "S": cost = 1; status = 1; break; case "G": cost = 1; status = 2; break; case "#": cost = X; status = 0; break; } Node result = new Node((dx, dy), ) } void Process(string[] args) { var inputs1 = InputIntValues(3); int H, W, T; H = inputs1[0]; W = inputs1[1]; T = inputs1[2]; var s = new List<List<string>>(); for(int y = 0; y < H; y++) { s[y] = new List<string>(); string row = Console.ReadLine(); for(int x = 0; x < W; x++) { s[y][x] = row.Split()[x]; } } } static List<int> InputIntValues(int length) { string rowInput = Console.ReadLine(); string[] strings = rowInput.Split(' '); List<int> returnvalue = new List<int>(length); for(int i = 0; i < length; i++) { returnvalue[i] = int.Parse(strings[i]); } return returnvalue; } static List<List<int>> InputIntMatrix(int X, int Y) { var matrix = new List<List<int>>(); for(int i = 0; i < Y; i++) { string row = Console.ReadLine(); string[] strings = row.Split(' '); matrix[i] = new List<int>(); for (int j = 0; j < X; j++) { matrix[i][j] = int.Parse(strings[j]); } } return matrix; } static List<List<string>> InputStringMatrix(int X, int Y) { var matrix = new List<List<string>>(); for (int i = 0; i < Y; i++) { string row = Console.ReadLine(); string[] strings = row.Split(' '); matrix[i] = new List<string>(); for (int j = 0; j < X; j++) { matrix[i][j] = strings[j]; } } return matrix; } }*/ } namespace ProCon { class Program { static void Main(string[] args) { int A, B; var tmp = InputIntValues(2); A = tmp[0]; B = tmp[1]; Console.WriteLine((A - 1) * (B - 1)); } static List<int> InputIntValues(int length) { string rowInput = Console.ReadLine(); string[] strings = rowInput.Split(' '); List<int> returnvalue = new List<int>(length); for (int i = 0; i < length; i++) { returnvalue[i] = int.Parse(strings[i]); } return returnvalue; } static List<List<int>> InputIntMatrix(int X, int Y) { var matrix = new List<List<int>>(); for (int i = 0; i < Y; i++) { string row = Console.ReadLine(); string[] strings = row.Split(' '); matrix[i] = new List<int>(); for (int j = 0; j < X; j++) { matrix[i][j] = int.Parse(strings[j]); } } return matrix; } static List<List<string>> InputStringMatrix(int X, int Y) { var matrix = new List<List<string>>(); for (int i = 0; i < Y; i++) { string row = Console.ReadLine(); string[] strings = row.Split(' '); matrix[i] = new List<string>(); for (int j = 0; j < X; j++) { matrix[i][j] = strings[j]; } } return matrix; } } }
using System; using System.Collections.Generic; using System.Linq; namespace Astar { /*class Node { Node((int x, int y) _pos, int _status, int _cost, int _h, int _score, Node node) { pos = _pos; status = _status; cost = _cost; h = _h; score = _score; parent = node; } public (int x, int y) pos; public int status; public int cost; public int h; public int score; public Node parent; }*/ /* class Program { static Node AddNode(int dx, int dy, int H, int W, int X, Node node, List<List<string>> s) { if (node.pos.x + dx < 0 || node.pos.y + dy < 0 || node.pos.x + dx >= W || node.pos.y + dy >= H) return null; int cost; int status; switch(s[node.pos.y + dy][node.pos.x + dx]) { case ".": cost = 1; status = 0; break; case "S": cost = 1; status = 1; break; case "G": cost = 1; status = 2; break; case "#": cost = X; status = 0; break; } Node result = new Node((dx, dy), ) } void Process(string[] args) { var inputs1 = InputIntValues(3); int H, W, T; H = inputs1[0]; W = inputs1[1]; T = inputs1[2]; var s = new List<List<string>>(); for(int y = 0; y < H; y++) { s[y] = new List<string>(); string row = Console.ReadLine(); for(int x = 0; x < W; x++) { s[y][x] = row.Split()[x]; } } } static List<int> InputIntValues(int length) { string rowInput = Console.ReadLine(); string[] strings = rowInput.Split(' '); List<int> returnvalue = new List<int>(length); for(int i = 0; i < length; i++) { returnvalue[i] = int.Parse(strings[i]); } return returnvalue; } static List<List<int>> InputIntMatrix(int X, int Y) { var matrix = new List<List<int>>(); for(int i = 0; i < Y; i++) { string row = Console.ReadLine(); string[] strings = row.Split(' '); matrix[i] = new List<int>(); for (int j = 0; j < X; j++) { matrix[i][j] = int.Parse(strings[j]); } } return matrix; } static List<List<string>> InputStringMatrix(int X, int Y) { var matrix = new List<List<string>>(); for (int i = 0; i < Y; i++) { string row = Console.ReadLine(); string[] strings = row.Split(' '); matrix[i] = new List<string>(); for (int j = 0; j < X; j++) { matrix[i][j] = strings[j]; } } return matrix; } }*/ } namespace ProCon { class Program { static void Main(string[] args) { int A, B; var tmp = InputIntValues(2); A = tmp[0]; B = tmp[1]; Console.WriteLine((A - 1) * (B - 1)); } static List<int> InputIntValues(int length) { string rowInput = Console.ReadLine(); string[] strings = rowInput.Split(' '); List<int> returnvalue = new List<int>(length); for (int i = 0; i < length; i++) { returnvalue.Add(int.Parse(strings[i])); } return returnvalue; } static List<List<int>> InputIntMatrix(int X, int Y) { var matrix = new List<List<int>>(); for (int i = 0; i < Y; i++) { string row = Console.ReadLine(); string[] strings = row.Split(' '); matrix[i] = new List<int>(); for (int j = 0; j < X; j++) { matrix[i][j] = int.Parse(strings[j]); } } return matrix; } static List<List<string>> InputStringMatrix(int X, int Y) { var matrix = new List<List<string>>(); for (int i = 0; i < Y; i++) { string row = Console.ReadLine(); string[] strings = row.Split(' '); matrix[i] = new List<string>(); for (int j = 0; j < X; j++) { matrix[i][j] = strings[j]; } } return matrix; } } }
[["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 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, 3, 4, 0, 25]]
8
405
8
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int n = 100; /* long n = long.Parse(Console.ReadLine()); long[] input = new long[5]; for(int a = 0; a < 5; a++) { input[a]=long.Parse(Console.ReadLine()); } */ int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); Console.WriteLine(input[0] * input[1] + input[0] + input[1] - 1); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int n = 100; /* long n = long.Parse(Console.ReadLine()); long[] input = new long[5]; for(int a = 0; a < 5; a++) { input[a]=long.Parse(Console.ReadLine()); } */ int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); Console.WriteLine(input[0] * input[1] - input[0] - input[1] + 1); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
[["-", 0, 28, 0, 16, 31, 16, 31, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 17, 33], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
105
6
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication9 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int count = 0; for (int i = 1; i < N; i++) { if (i % 2 == 1 && DivisorsNum(i) == 8) { count++; } } Console.WriteLine(count); } public static int DivisorsNum(int N) { int count = 0; for (int i = 1; i < N; i++) { if (N % i == 0) { count++; } } return count; } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication9 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int count = 0; for (int i = 1; i <= N; i++) { if (i % 2 == 1 && DivisorsNum(i) == 8) { count++; } } Console.WriteLine(count); } public static int DivisorsNum(int N) { int count = 0; for (int i = 1; i <= N; i++) { if (N % i == 0) { count++; } } return count; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
160
4
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var count = 0; for (int i = 1; i < N; i = i + 2) { if (CountDivisor(i) == 8) count++; } Console.WriteLine(count); } private static int CountDivisor(int num) { var count = 0; for (int i = 1; i <= num; i++) { if (num % i == 0) count++; } return count; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var count = 0; for (int i = 1; i <= N; i = i + 2) { if (CountDivisor(i) == 8) count++; } Console.WriteLine(count); } private static int CountDivisor(int num) { var count = 0; for (int i = 1; i <= num; i++) { if (num % i == 0) count++; } return count; } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
132
2
using System; using System.Linq; namespace atcoder { class Program { static void Main(string[] args) { B105(int.Parse(args[0])); } static void B105(int N) { var count = 0; for (var i = 1; i <= N; i += 2) { if (Counting(i) == 8) count++; } Console.WriteLine(count); } static int Counting(int n) { var count = 0; for (var i = 1; i <= n; i++) { if (n % i == 0) count++; } return count; } } }
using System; using System.Linq; namespace atcoder { class Program { static void Main(string[] args) { B105(int.Parse(Console.ReadLine())); } static void B105(int N) { var count = 0; for (var i = 1; i <= N; i += 2) { if (Counting(i) == 8) count++; } Console.WriteLine(count); } static int Counting(int n) { var count = 0; for (var i = 1; i <= n; i++) { if (n % i == 0) count++; } return count; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
134
9
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 void Solve() { Scan sc = new Scan(); write wr = new write(); var N = sc.intarr[0]; if (N <= 104) wr.wri(0); else if (N <= 134) wr.wri(1); else if (N <= 165) wr.wri(2); else if (N <= 189) wr.wri(3); else if (N <= 194) wr.wri(4); else wr.wri(5); } } 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 void Solve() { Scan sc = new Scan(); write wr = new write(); var N = sc.intarr[0]; if (N <= 104) wr.wri(0); else if (N <= 134) wr.wri(1); else if (N <= 164) wr.wri(2); else if (N <= 188) wr.wri(3); else if (N <= 194) wr.wri(4); else wr.wri(5); } } 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); } }
[["-", 0, 57, 75, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 203], ["-", 75, 57, 75, 57, 75, 57, 15, 16, 12, 203], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 12, 203]]
8
272
4
using System; using System.Collections.Generic; using System.Linq; public static class Program { public static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var result = 0; for (int i = 1; i <= n; i += 2) { var cnt = 0; for (int j = 1; j <= i; j++) { if (j % 2 == 0) cnt++; if (cnt > 8) break; } cnt++; if (cnt == 8) result++; } Console.WriteLine(result); } }
using System; using System.Collections.Generic; using System.Linq; public static class Program { public static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var result = 0; for (int i = 1; i <= n; i += 2) { var cnt = 0; for (int j = 1; j <= i; j++) { if (i % j == 0) cnt++; if (cnt > 8) break; } if (cnt == 8) result++; } Console.WriteLine(result); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
128
7
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using static kyoupuro.Input; using static kyoupuro.MyMath; using static kyoupuro.Modular; namespace kyoupuro { class MainClass { public static void Main() { var N = NextInt; int count = 0; if (N >= 105) count++; if (N >= 135) count++; if (N >= 165) count++; if (N >= 189) count++; if (N >= 185) count++; Console.WriteLine(count); } } class MyMath { public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); } public static long Sqrt(long n) { if (n < 0) return 0; long a = 0, tmp = 0, b = 0; for (int i = 62; i >= 0; i -= 2) { tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0; a = a << 1 | tmp; n -= (((b << 1) + 1) * tmp) << i; b = (b << 1) + tmp + tmp; } return a; } } class Modular { public const int mod = 1000000007; public readonly long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % mod; return new Modular((m < 0) ? m + mod : m); } public static Modular operator +(Modular a, Modular b) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return a.value * b.value; } private static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, mod - 2); } private static readonly List<int> facs = new List<int> { 1 }; private static Modular Fac(int n) { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % mod)); } return facs[n]; } public static Modular Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } } public class PriorityQueue<T> { readonly List<T> _heap = new List<T>(); readonly Comparison<T> _comparison; public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; } public PriorityQueue() : this(Comparer<T>.Default.Compare) {} public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {} public void Enqueue(T item) { _heap.Add(item); int childID = _heap.Count - 1; int parentID = (childID - 1) / 2; while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); childID = parentID; parentID = (parentID - 1) / 2; } } public T Dequeue() { var first = _heap.First(); _heap[0] = _heap.Last(); _heap.RemoveAt(_heap.Count - 1); int parentID = 0; int childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; while (childID < _heap.Count && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); parentID = childID; childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; } return first; } void Swap(int parent, int child) { var tmp = _heap[parent]; _heap[parent] = _heap[child]; _heap[child] = tmp; } public T Peek() { return _heap[0]; } public int Count => _heap.Count; public bool Any() { return _heap.Any(); } public List<T> Data => _heap; } public class UnionFind { public int[] Parents { get; set; } public UnionFind(int size) { Parents = Enumerable.Repeat(-1, size).ToArray(); } public int Find(int num) { if (Parents[num] < 0) return num; Parents[num] = Find(Parents[num]); return Parents[num]; } public int Size(int num) { return -Parents[Find(num)]; } public bool Same(int a, int b) { return Find(a) == Find(b); } public void Unite(int a, int b) { int x = Find(a), y = Find(b); if (Size(x) > Size(y)) { Parents[x] += Parents[y]; Parents[y] = x; } else { Parents[y] += Parents[x]; Parents[x] = y; } } } class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line => Console.ReadLine(); public static string[] StrArr => Line.Split(' '); public static int NextInt => int.Parse(NextWord()); public static long NextLong => long.Parse(NextWord()); public static List<int> IntList => StrArr.Select(int.Parse).ToList(); public static List<long> LongList => StrArr.Select(long.Parse).ToList(); public static string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using static kyoupuro.Input; using static kyoupuro.MyMath; using static kyoupuro.Modular; namespace kyoupuro { class MainClass { public static void Main() { var N = NextInt; int count = 0; if (N >= 105) count++; if (N >= 135) count++; if (N >= 165) count++; if (N >= 189) count++; if (N >= 195) count++; Console.WriteLine(count); } } class MyMath { public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); } public static long Sqrt(long n) { if (n < 0) return 0; long a = 0, tmp = 0, b = 0; for (int i = 62; i >= 0; i -= 2) { tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0; a = a << 1 | tmp; n -= (((b << 1) + 1) * tmp) << i; b = (b << 1) + tmp + tmp; } return a; } } class Modular { public const int mod = 1000000007; public readonly long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % mod; return new Modular((m < 0) ? m + mod : m); } public static Modular operator +(Modular a, Modular b) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return a.value * b.value; } private static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, mod - 2); } private static readonly List<int> facs = new List<int> { 1 }; private static Modular Fac(int n) { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % mod)); } return facs[n]; } public static Modular Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } } public class PriorityQueue<T> { readonly List<T> _heap = new List<T>(); readonly Comparison<T> _comparison; public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; } public PriorityQueue() : this(Comparer<T>.Default.Compare) {} public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {} public void Enqueue(T item) { _heap.Add(item); int childID = _heap.Count - 1; int parentID = (childID - 1) / 2; while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); childID = parentID; parentID = (parentID - 1) / 2; } } public T Dequeue() { var first = _heap.First(); _heap[0] = _heap.Last(); _heap.RemoveAt(_heap.Count - 1); int parentID = 0; int childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; while (childID < _heap.Count && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); parentID = childID; childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; } return first; } void Swap(int parent, int child) { var tmp = _heap[parent]; _heap[parent] = _heap[child]; _heap[child] = tmp; } public T Peek() { return _heap[0]; } public int Count => _heap.Count; public bool Any() { return _heap.Any(); } public List<T> Data => _heap; } public class UnionFind { public int[] Parents { get; set; } public UnionFind(int size) { Parents = Enumerable.Repeat(-1, size).ToArray(); } public int Find(int num) { if (Parents[num] < 0) return num; Parents[num] = Find(Parents[num]); return Parents[num]; } public int Size(int num) { return -Parents[Find(num)]; } public bool Same(int a, int b) { return Find(a) == Find(b); } public void Unite(int a, int b) { int x = Find(a), y = Find(b); if (Size(x) > Size(y)) { Parents[x] += Parents[y]; Parents[y] = x; } else { Parents[y] += Parents[x]; Parents[x] = y; } } } class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line => Console.ReadLine(); public static string[] StrArr => Line.Split(' '); public static int NextInt => int.Parse(NextWord()); public static long NextLong => long.Parse(NextWord()); public static List<int> IntList => StrArr.Select(int.Parse).ToList(); public static List<long> LongList => StrArr.Select(long.Parse).ToList(); public static string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
1,380
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; using Pair = System.Tuple<long, long>; /// <summary> /// https://atcoder.jp/contests/abc106 /// 2020/02/01 3完 パフォ1050 /// </summary> namespace ABC106 { public class Program { public static void Main(string[] args) { DontAutoFlush(); // A(); 4m // B(); 9m // C(); 28m // D(); 降参 // 2回目 A(); // B(); // C(); // D(); Flush(); } public static void D() {} public static void C() {} public static void B() { long N = rl; long ans = 0; for (int i = 1; i <= N; i += 2) { long cnt = 0; for (int j = 1; j <= N; j++) { if (i % j == 0) cnt++; } if (cnt == 8) ans++; } Console.WriteLine(ans); } public static void A() { Console.WriteLine((rl - 1) * (rl - 1)); } // public static void D() //{ // long N = rl; // long M = rl; // long Q = rl; // long[,] table = new long[N, N]; // for (int i = 0; i < M; i++) // { // table[rl - 1, rl - 1]++; // } // long[,] S = new long[N + 1, N + 1]; // for (int i = 0; i < N; i++) // { // for (int j = 0; j < N; j++) // { // S[i, j] = table[i, j]; // if (i - 1 >= 0) S[i, j] += S[i - 1, j]; // if (j - 1 >= 0) S[i, j] += S[i, j - 1]; // if (i - 1 >= 0 && j - 1 >= 0) S[i, j] -= S[i - 1, j - 1]; // } // } // for (int i = 0; i < Q; i++) // { // long left = rl - 1; // long right = rl - 1; // long x1 = left, y1 = left; // long x2 = right, y2 = right; // long res = S[x2, y2]; // if (x1 - 1 >= 0) res -= S[x1 - 1, y2]; // if (y1 - 1 >= 0) res -= S[x2, y1 - 1]; // if (x1 - 1 >= 0 && y1 - 1 >= 0) res += S[x1 - 1, y1 - 1]; // Console.WriteLine(res); // } //} // public static void C() //{ // string S = ReadString(); // long K = rl; // for (int i = 0; i < K; i++) // { // if (S[i] != '1') // { // Console.WriteLine(S[i]); // return; // } // } // Console.WriteLine(1); //} // public static void B() //{ // long N = rl; // long[] res = new long[N+1]; // for (int i = 1; i <= N; i += 2) // { // long divisor = 1; // for (int j = 3; j <= i; j++) // { // if (i % j == 0) // divisor++; // } // res[i] = divisor; // } // long ans = 0; // foreach (var div in res) // { // if (div == 8) // ans++; // } // Console.WriteLine(ans); //} // public static void A() //{ // long A = rl; // long B = rl; // long ans = A * B - A - B + 1; // Console.WriteLine(ans); //} } } namespace Ha2ne2Util { public static class Cin { private static string[] Tokens { get; set; } private static int Pointer { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } public static int ReadInt() { return int.Parse(Next()); } public static long rl => ReadLong(); public static long[] rla => ReadLongArray(); public static double rd => ReadDouble(); public static double[] rda => ReadDoubleArray(); public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadArrays(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadArrays(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 降順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static long ModAdd(long a, long b) { long res = a + b; if (res >= MOD) return res % MOD; return res; } public static long ModMul(long a, long b) { long res = a * b; if (res >= MOD) return res % MOD; return res; } public static void ModAddEqual(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { public int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; using Pair = System.Tuple<long, long>; /// <summary> /// https://atcoder.jp/contests/abc106 /// 2020/02/01 3完 パフォ1050 /// </summary> namespace ABC106 { public class Program { public static void Main(string[] args) { DontAutoFlush(); // A(); 4m // B(); 9m // C(); 28m // D(); 降参 // 2回目 // A(); B(); // C(); // D(); Flush(); } public static void D() {} public static void C() {} public static void B() { long N = rl; long ans = 0; for (int i = 1; i <= N; i += 2) { long cnt = 0; for (int j = 1; j <= N; j++) { if (i % j == 0) cnt++; } if (cnt == 8) ans++; } Console.WriteLine(ans); } public static void A() { Console.WriteLine((rl - 1) * (rl - 1)); } // public static void D() //{ // long N = rl; // long M = rl; // long Q = rl; // long[,] table = new long[N, N]; // for (int i = 0; i < M; i++) // { // table[rl - 1, rl - 1]++; // } // long[,] S = new long[N + 1, N + 1]; // for (int i = 0; i < N; i++) // { // for (int j = 0; j < N; j++) // { // S[i, j] = table[i, j]; // if (i - 1 >= 0) S[i, j] += S[i - 1, j]; // if (j - 1 >= 0) S[i, j] += S[i, j - 1]; // if (i - 1 >= 0 && j - 1 >= 0) S[i, j] -= S[i - 1, j - 1]; // } // } // for (int i = 0; i < Q; i++) // { // long left = rl - 1; // long right = rl - 1; // long x1 = left, y1 = left; // long x2 = right, y2 = right; // long res = S[x2, y2]; // if (x1 - 1 >= 0) res -= S[x1 - 1, y2]; // if (y1 - 1 >= 0) res -= S[x2, y1 - 1]; // if (x1 - 1 >= 0 && y1 - 1 >= 0) res += S[x1 - 1, y1 - 1]; // Console.WriteLine(res); // } //} // public static void C() //{ // string S = ReadString(); // long K = rl; // for (int i = 0; i < K; i++) // { // if (S[i] != '1') // { // Console.WriteLine(S[i]); // return; // } // } // Console.WriteLine(1); //} // public static void B() //{ // long N = rl; // long[] res = new long[N+1]; // for (int i = 1; i <= N; i += 2) // { // long divisor = 1; // for (int j = 3; j <= i; j++) // { // if (i % j == 0) // divisor++; // } // res[i] = divisor; // } // long ans = 0; // foreach (var div in res) // { // if (div == 8) // ans++; // } // Console.WriteLine(ans); //} // public static void A() //{ // long A = rl; // long B = rl; // long ans = A * B - A - B + 1; // Console.WriteLine(ans); //} } } namespace Ha2ne2Util { public static class Cin { private static string[] Tokens { get; set; } private static int Pointer { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } public static int ReadInt() { return int.Parse(Next()); } public static long rl => ReadLong(); public static long[] rla => ReadLongArray(); public static double rd => ReadDouble(); public static double[] rda => ReadDoubleArray(); public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadArrays(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadArrays(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 降順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static long ModAdd(long a, long b) { long res = a + b; if (res >= MOD) return res % MOD; return res; } public static long ModMul(long a, long b) { long res = a * b; if (res >= MOD) return res % MOD; return res; } public static void ModAddEqual(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { public int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22]]
8
3,461
2
using System; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); if (N == 105) { Console.WriteLine(1); return; } else if (N < 105) { Console.WriteLine(0); return; } int ret = 1; for (int i = 106; i < N; i++) { if (i % 2 == 0) { continue; } int tmpRet = 0; for (int j = 1; j < N; j++) { if (i % j == 0) { tmpRet++; } } if (tmpRet == 8) { ret++; } } Console.WriteLine(ret); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); if (N == 105) { Console.WriteLine(1); return; } else if (N < 105) { Console.WriteLine(0); return; } int ret = 1; for (int i = 106; i <= N; i++) { if (i % 2 == 0) { continue; } int tmpRet = 0; for (int j = 1; j <= N; j++) { if (i % j == 0) { tmpRet++; } } if (tmpRet == 8) { ret++; } } Console.WriteLine(ret); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
168
4
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 N = int.Parse(Console.ReadLine()); // 3,5,7,11,13 // 3,3,3,5->135 // 3,5,7->105 // 3,5,11->165 // 3,5,13->195 int[] nums = new int[] { 105, 135, 165, 195 }; Console.WriteLine(nums.TakeWhile(itm => itm <= N).Count()); } } static class MathUtil { public static IEnumerable<IEnumerable<int>> GetPermutation(int n) { if (n == 0) { yield return Single(0); yield break; } for (int i = 0; i <= n; i++) { foreach (var x in GetPermutation(n - 1)) { yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1)); } } } private static IEnumerable<int> Single(int x) { yield return x; } public static IEnumerable<int> EnumeratePrimeNumbers() { List<int> primes = new List<int>() { 2 }; yield return 2; for (int i = 3; i < int.MaxValue; i++) { bool isPrime = true; int Sqrt = (int)Math.Sqrt(i) + 1; foreach (var prime in primes) { if (prime > Sqrt) { break; } if (i % prime == 0) { isPrime = false; break; } } if (isPrime) { primes.Add(i); yield return i; } } } }
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 N = int.Parse(Console.ReadLine()); // 3,5,7,11,13 // 3,3,3,5->135 // 3,3,3,7->189 // 3,5,7->105 // 3,5,11->165 // 3,5,13->195 int[] nums = new int[] { 105, 135, 165, 189, 195 }; Console.WriteLine(nums.TakeWhile(itm => itm <= N).Count()); } } static class MathUtil { public static IEnumerable<IEnumerable<int>> GetPermutation(int n) { if (n == 0) { yield return Single(0); yield break; } for (int i = 0; i <= n; i++) { foreach (var x in GetPermutation(n - 1)) { yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1)); } } } private static IEnumerable<int> Single(int x) { yield return x; } public static IEnumerable<int> EnumeratePrimeNumbers() { List<int> primes = new List<int>() { 2 }; yield return 2; for (int i = 3; i < int.MaxValue; i++) { bool isPrime = true; int Sqrt = (int)Math.Sqrt(i) + 1; foreach (var prime in primes) { if (prime > Sqrt) { break; } if (i % prime == 0) { isPrime = false; break; } } if (isPrime) { primes.Add(i); yield return i; } } } }
[["+", 0, 200, 0, 212, 0, 227, 0, 229, 0, 203], ["+", 0, 200, 0, 212, 0, 227, 0, 229, 0, 21]]
8
343
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace MyProgram { public class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int cnt = 0; int a = 0; for (int i = 1; i <= n; i += 2) { for (int j = 1; j <= i; j += 2) { if (n % j == 0) a++; } if (a == 8) cnt++; } Console.WriteLine(cnt); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace MyProgram { public class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int cnt = 0; int a = 0; for (int i = 1; i <= n; i += 2) { a = 0; for (int j = 1; j <= i; j += 2) { if (i % j == 0) a++; } if (a == 8) cnt++; } Console.WriteLine(cnt); } } }
[["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22]]
8
126
6
using System; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); int ans = 1; for (int i = 107; i <= n; i += 2) { int cnt = 0; for (int j = 1; j <= i; j += 2) { if (i % j == 0) cnt++; } if (cnt == 8) ans++; } Console.WriteLine(ans); } }
using System; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); int ans = 0; for (int i = 105; i <= n; i += 2) { int cnt = 0; for (int j = 1; j <= i; j += 2) { if (i % j == 0) cnt++; } if (cnt == 8) ans++; } Console.WriteLine(ans); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
99
4
using System; public class B { public static void Main() { string[] args = Console.ReadLine().Split(' '); int n = Int32.Parse(args[0]); int result = 0; if (n >= 115) { result = 1; // 115 for (int i = 117; i <= n; i += 2) { int counter = 1; // 1 for (int j = 2; j <= i; j++) { if (i % j == 0) counter++; if (counter > 8) break; } if (counter == 8) result++; } } Console.WriteLine(result); } }
using System; public class B { public static void Main() { string[] args = Console.ReadLine().Split(' '); int n = Int32.Parse(args[0]); int result = 0; if (n >= 105) { result = 1; // 105 for (int i = 117; i <= n; i += 2) { int counter = 1; // 1 for (int j = 2; j <= i; j++) { if (i % j == 0) counter++; if (counter > 8) break; } if (counter == 8) result++; } } Console.WriteLine(result); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
139
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder105 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int n = Convert.ToInt32(input); var divisor = new Divisor(); int ans = divisor.Count(n, 8); Console.WriteLine(ans); } } class Divisor { public int Count(int n) { int ans = 0; int max = (int)Math.Sqrt(n); for (int i = 1; i < max; i += 2) { if (n % i == 0) ans++; } return ans * 2; } public int Count(int n, int c) { // 1 以上 n 以下の奇数のうち, 正の約数を ちょうど c // 個持つようなものの個数を返す int ans = 0; for (int i = 105; i <= n; i += 2) { if (Count(i) == c) ans++; } return ans; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder105 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int n = Convert.ToInt32(input); var divisor = new Divisor(); int ans = divisor.Count(n, 8); Console.WriteLine(ans); } } public class Divisor { public int Count(int n) { int ans = 0; int max = (int)Math.Sqrt(n); for (int i = 1; i <= max; i += 2) { // max以下(!)にすること if (n % i == 0) ans++; } return ans * 2; } public int Count(int n, int c) { // 1 以上 n 以下の奇数のうち, 正の約数を ちょうど c // 個持つようなものの個数を返す int ans = 0; for (int i = 105; i <= n; i += 2) { if (Count(i) == c) { ans++; // Console.WriteLine(i); } } return ans; } } }
[["+", 0, 209, 8, 201, 0, 235, 0, 251, 0, 259], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
207
5
using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); if (n < 104) { Console.WriteLine(0); goto end; } if (n == 105) { Console.WriteLine(1); goto end; } var res = 1; for (int i = 106; i <= n; i++) { if (i % 2 == 1) { var count = 0; for (int j = 1; j <= n; j++) if (i % j == 0) count++; if (count == 8) res++; } } Console.WriteLine(res); end:; } }
using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); if (n <= 104) { Console.WriteLine(0); goto end; } if (n == 105) { Console.WriteLine(1); goto end; } var res = 0; for (int i = 10; i <= n; i++) { if (i % 2 == 1) { var count = 0; for (int j = 1; j <= n; j++) if (i % j == 0) count++; if (count == 8) res++; } } Console.WriteLine(res); end:; } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
150
6
using Yorukatsu035.Questions; using Yorukatsu035.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Yorukatsu035.Questions { /// <summary> /// ABC106 C /// </summary> public class QuestionB : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var s = inputStream.ReadLine(); var k = inputStream.ReadLong() - 1; for (int i = 0; i < k; i++) { if (s[i] != '1' || i == k) { yield return s[i]; yield break; } } } } } namespace Yorukatsu035 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionB(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace Yorukatsu035.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace Yorukatsu035.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
using Yorukatsu035.Questions; using Yorukatsu035.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Yorukatsu035.Questions { /// <summary> /// ABC106 C /// </summary> public class QuestionB : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var s = inputStream.ReadLine(); var k = inputStream.ReadLong(); for (int i = 0; i < k; i++) { if (s[i] != '1' || i == k - 1) { yield return s[i]; yield break; } } } } } namespace Yorukatsu035 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionB(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace Yorukatsu035.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace Yorukatsu035.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203]]
8
520
4
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace C { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var s = Console.ReadLine(); var k = long.Parse(Console.ReadLine()); var not1 = '0'; var index = 0; for (var i = 0; i < s.Length; i++) { if (s[i] != '1') { not1 = s[i]; index = i + 1; break; } } Console.WriteLine(k < index ? '1' : not1); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace C { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var s = Console.ReadLine(); var k = long.Parse(Console.ReadLine()); var not1 = '1'; var index = 0; for (var i = 0; i < s.Length; i++) { if (s[i] != '1') { not1 = s[i]; index = i + 1; break; } } Console.WriteLine(k < index ? '1' : not1); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 252, 0, 253], ["+", 0, 198, 0, 200, 0, 212, 0, 252, 0, 253]]
8
186
2
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC106C { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var K = ReadInt; int ans = 1; for (int i = 0; i < S.Length; i++) { if (S[i] != '1') { ans = int.Parse(S[i].ToString()); break; } } bool ok = true; for (int i = 0; i < Math.Min(K, S.Length); i++) { if (S[i] != '1') ok = false; } if (ok) ans = 1; Console.WriteLine(ans); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String ReadNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int ReadInt => int.Parse(ReadNext()); public static long ReadLong => long.Parse(ReadNext()); public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] ReadLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); } static class Debug { static public void Draw2D(int[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); int[,] map2 = new int[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0; else if (i == 0) map2[i, j] = j - 1; else if (j == 0) map2[i, j] = i - 1; else map2[i, j] = map[i - 1, j - 1]; } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j] % 10); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D(int[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC106C { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var K = ReadLong; int ans = 1; for (int i = 0; i < S.Length; i++) { if (S[i] != '1') { ans = int.Parse(S[i].ToString()); break; } } bool ok = true; for (int i = 0; i < Math.Min(K, S.Length); i++) { if (S[i] != '1') ok = false; } if (ok) ans = 1; Console.WriteLine(ans); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String ReadNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int ReadInt => int.Parse(ReadNext()); public static long ReadLong => long.Parse(ReadNext()); public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] ReadLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); } static class Debug { static public void Draw2D(int[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); int[,] map2 = new int[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0; else if (i == 0) map2[i, j] = j - 1; else if (j == 0) map2[i, j] = i - 1; else map2[i, j] = map[i - 1, j - 1]; } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j] % 10); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D(int[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
8
632
2
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 var s = Console.ReadLine(); var k = long.Parse(Console.ReadLine()); var ans = '1'; for (int i = 0; i < s.Length; i++) { if (s[i] != '1') { ans = s[i]; break; } } Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 var s = Console.ReadLine(); var k = long.Parse(Console.ReadLine()); var ans = '1'; for (int i = 0; i < k; i++) { if (s[i] != '1') { ans = s[i]; break; } } Console.WriteLine(ans); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
118
4
using System; using System.Linq; using System.Collections.Generic; using System.IO; class MainClass { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var s = Console.ReadLine(); var k = Read(); int memo = -1; for (int i = 0; i < s.Length; i++) { if (s[i] != '1') { memo = i; break; } } if (k - 1 < memo) { Console.WriteLine(1); } else { Console.WriteLine(s[memo]); } Console.Out.Flush(); } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; class MainClass { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var s = Console.ReadLine(); var k = Read(); int memo = 0; for (int i = 0; i < s.Length; i++) { if (s[i] != '1') { memo = i; break; } } if (k - 1 < memo) { Console.WriteLine(1); } else { Console.WriteLine(s[memo]); } Console.Out.Flush(); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
210
3
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; class Program { static void Main(string[] args) { var s = ReadLine(); var k = ToInt64(ReadLine()); for (var i = 0; i < s.Length; i++) if (s[i] != '1') { WriteLine(s.Substring(i, 1)); break; } else if (i == k) { WriteLine("1"); break; } } private const string ALFA = "abcdefghijklmnopqrstuvwxyz"; private const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; class Program { static void Main(string[] args) { var s = ReadLine(); var k = ToInt64(ReadLine()); for (var i = 0; i < s.Length; i++) if (s[i] != '1') { WriteLine(s.Substring(i, 1)); break; } else if (i + 1 == k) { WriteLine("1"); break; } } private const string ALFA = "abcdefghijklmnopqrstuvwxyz"; private const int MOD = 1000000007; }
[["+", 8, 57, 75, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 57, 75, 57, 15, 16, 31, 16, 12, 203]]
8
142
2
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var index = 0; for (var i = 0; i < S.Length; i++) { if (S[i] != '1') { index = i; break; } } var K = long.Parse(Console.ReadLine()); if (index > K) Console.WriteLine(S[0]); else Console.WriteLine(S[index]); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var index = 0; for (var i = 0; i < S.Length; i++) { if (S[i] != '1') { index = i; break; } } var K = long.Parse(Console.ReadLine()); if (index >= K) Console.WriteLine(S[0]); else Console.WriteLine(S[index]); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
126
2
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace ConsoleApp1 { class Program { static void Main(string[] args) { A(); } static void A() { var S = Read().ToList(); var K = ReadLong(); for (int i = 0; i < S.Count; i++) { if (S[i] != '1' && i + 1 < K) { Println(S[i]); return; } } Println(1); } static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int DigitsSum(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b); static bool IsPrime(int x) { if (x <= 1 || (x != 2 && x % 2 == 0)) return false; if (x == 2) return true; for (int i = 3; i < x; i += 2) if (x % i == 0) return false; return true; } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static List<string> ReadSplit() => Read().Split().ToList(); static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList(); static void Print(object value) => Console.Write(value.ToString()); static void Println(object value) => Console.WriteLine(value.ToString()); static string Join<T>(IEnumerable<T> list) => string.Join("", list); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace ConsoleApp1 { class Program { static void Main(string[] args) { A(); } static void A() { var S = Read().ToList(); var K = ReadLong(); for (int i = 0; i < S.Count; i++) { if (S[i] != '1' && i + 1 <= K) { Println(S[i]); return; } } Println(1); } static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int DigitsSum(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b); static bool IsPrime(int x) { if (x <= 1 || (x != 2 && x % 2 == 0)) return false; if (x == 2) return true; for (int i = 3; i < x; i += 2) if (x % i == 0) return false; return true; } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static List<string> ReadSplit() => Read().Split().ToList(); static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList(); static void Print(object value) => Console.Write(value.ToString()); static void Println(object value) => Console.WriteLine(value.ToString()); static string Join<T>(IEnumerable<T> list) => string.Join("", list); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
8
628
2
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var S = Console.ReadLine(); var K = long.Parse(Console.ReadLine()); long count = 0; for (int i = 0; i < S.Length; i++) { var num = S[i] - '0'; if (num == 1) { count++; if (count == K) { Console.WriteLine(1); return; } } else { Console.WriteLine(num); } } } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var S = Console.ReadLine(); var K = long.Parse(Console.ReadLine()); long count = 0; for (int i = 0; i < S.Length; i++) { var num = S[i] - '0'; if (num == 1) { count++; if (count == K) { Console.WriteLine(1); return; } } else { Console.WriteLine(num); return; } } } }
[["+", 8, 196, 0, 57, 75, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 75, 196, 0, 37, 0, 35]]
8
126
2
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() { string S = Console.ReadLine(); int K = int.Parse(Console.ReadLine()); // 2は、5000兆日後には2の5000兆乗の長さになる。 //つまり、2以上も、5000兆日後にはnの5000兆乗の長さになる。 // Kはせいぜい1以上10^18以下 //文字列中の、最初の1が連続する部分の長さ var xxx = S.TakeWhile(itm => itm == '1').Count(); // 1が連続する部分の次の文字 var yyy = S.SkipWhile(itm => itm == '1').Take(1); if (K <= xxx) { Console.WriteLine(1); } else { Console.WriteLine(yyy.Single()); } } } static class MathUtil { public static IEnumerable<IEnumerable<int>> GetPermutation(int n) { if (n == 0) { yield return Single(0); yield break; } for (int i = 0; i <= n; i++) { foreach (var x in GetPermutation(n - 1)) { yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1)); } } } private static IEnumerable<int> Single(int x) { yield return x; } public static IEnumerable<int> EnumeratePrimeNumbers() { List<int> primes = new List<int>() { 2 }; yield return 2; for (int i = 3; i < int.MaxValue; i++) { bool isPrime = true; int Sqrt = (int)Math.Sqrt(i) + 1; foreach (var prime in primes) { if (prime > Sqrt) { break; } if (i % prime == 0) { isPrime = false; break; } } if (isPrime) { primes.Add(i); yield return i; } } } }
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() { string S = Console.ReadLine(); long K = long.Parse(Console.ReadLine()); // 2は、5000兆日後には2の5000兆乗の長さになる。 //つまり、2以上も、5000兆日後にはnの5000兆乗の長さになる。 // Kはせいぜい1以上10^18以下 //文字列中の、最初の1が連続する部分の長さ var xxx = S.TakeWhile(itm => itm == '1').Count(); // 1が連続する部分の次の文字 var yyy = S.SkipWhile(itm => itm == '1').Take(1); if (K <= xxx) { Console.WriteLine(1); } else { Console.WriteLine(yyy.Single()); } } } static class MathUtil { public static IEnumerable<IEnumerable<int>> GetPermutation(int n) { if (n == 0) { yield return Single(0); yield break; } for (int i = 0; i <= n; i++) { foreach (var x in GetPermutation(n - 1)) { yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1)); } } } private static IEnumerable<int> Single(int x) { yield return x; } public static IEnumerable<int> EnumeratePrimeNumbers() { List<int> primes = new List<int>() { 2 }; yield return 2; for (int i = 3; i < int.MaxValue; i++) { bool isPrime = true; int Sqrt = (int)Math.Sqrt(i) + 1; foreach (var prime in primes) { if (prime > Sqrt) { break; } if (i % prime == 0) { isPrime = false; break; } } if (isPrime) { primes.Add(i); yield return i; } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
383
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var sc = new Scanner(); string s = sc.NextString(); long k = sc.NextLong(); // < 10 ^ 18 long c = 5000000000000000; // = 5 * 10^15 // 2^(10^15) vs 10^18 int i = 0; while (i < s.Length - 1 && s[i] == '1') i++; Console.WriteLine(i > k ? s[0] : s[i]); } } class Scanner { int index = -1; string[] buf; public Scanner() {} public int NextInt() { CheckNext(); return int.Parse(buf[index++]); } public long NextLong() { CheckNext(); return long.Parse(buf[index++]); } public double NextDouble() { CheckNext(); return double.Parse(buf[index++]); } public string NextString() { CheckNext(); return buf[index++]; } private void CheckNext() { if (index >= 0 && index < buf.Length) return; buf = Console.ReadLine().Split(' '); index = 0; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var sc = new Scanner(); string s = sc.NextString(); long k = sc.NextLong(); // < 10 ^ 18 long c = 5000000000000000; // = 5 * 10^15 // 2^(10^15) vs 10^18 int i = 0; while (i < s.Length - 1 && s[i] == '1') i++; Console.WriteLine(i >= k ? s[0] : s[i]); } } class Scanner { int index = -1; string[] buf; public Scanner() {} public int NextInt() { CheckNext(); return int.Parse(buf[index++]); } public long NextLong() { CheckNext(); return long.Parse(buf[index++]); } public double NextDouble() { CheckNext(); return double.Parse(buf[index++]); } public string NextString() { CheckNext(); return buf[index++]; } private void CheckNext() { if (index >= 0 && index < buf.Length) return; buf = Console.ReadLine().Split(' '); index = 0; } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20]]
8
270
2
using System; namespace To_Infinity { class Program { static void Main(string[] args) { var s = Console.ReadLine(); var k = long.Parse(Console.ReadLine()); var count = 0; for (int i = 0; i < s.Length; i++) { if (1 == int.Parse(s[i].ToString())) { count++; } else { break; } } if (count <= k) { Console.WriteLine(1); return; } if (1 == k) { Console.WriteLine(s[0]); return; } for (int i = 0; i < s.Length; i++) { if (1 != int.Parse(s[i].ToString())) { Console.WriteLine(s[i]); return; } } } } }
using System; namespace To_Infinity { class Program { static void Main(string[] args) { var s = Console.ReadLine(); var k = long.Parse(Console.ReadLine()); var count = 0; for (int i = 0; i < s.Length; i++) { if (1 == int.Parse(s[i].ToString())) { count++; } else { break; } } if (count >= k) { Console.WriteLine(1); return; } if (1 == k) { Console.WriteLine(s[0]); return; } for (int i = 0; i < s.Length; i++) { if (1 != int.Parse(s[i].ToString())) { Console.WriteLine(s[i]); return; } } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
183
2
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 void Solve() { Scan sc = new Scan(); write wr = new write(); string S = sc.str; long N = sc.longarr[0]; int i = 0; while (i + 1 <= S.Length && S[i] == '1') { i++; } if (N <= i + 1) { wr.wri(1); } else wr.wri(S[i]); } } 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 void Solve() { Scan sc = new Scan(); write wr = new write(); string S = sc.str; long N = sc.longarr[0]; int i = 0; while (i + 1 <= S.Length && S[i] == '1') { i++; } if (N < i + 1) { wr.wri(1); } else wr.wri(S[i]); } } 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); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
8
259
2
using System; namespace AtCoder { class Program { static void Main(string[] args) { MainStream(); } static void MainStream() { char[] s = Console.ReadLine().ToCharArray(); long k = int.Parse(Console.ReadLine()); if (s[0] != '1') { Console.WriteLine(s[0]); return; } for (long i = 0; i < k && i < s.Length; i++) { if (s[i] != '1') { Console.WriteLine(s[i]); return; } } Console.WriteLine("1"); return; } } }
using System; namespace AtCoder { class Program { static void Main(string[] args) { MainStream(); } static void MainStream() { char[] s = Console.ReadLine().ToCharArray(); long k = long.Parse(Console.ReadLine()); if (s[0] != '1') { Console.WriteLine(s[0]); return; } for (long i = 0; i < k && i < s.Length; i++) { if (s[i] != '1') { Console.WriteLine(s[i]); return; } } Console.WriteLine("1"); return; } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
145
2
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 static System.Math; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { string s = Console.ReadLine(); Console.WriteLine(s.TakeWhile(x => x == '1').Count() >= int.Parse(Console.ReadLine()) ? '1' : s.First(x => x != '1')); } }
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 static System.Math; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { string s = Console.ReadLine(); Console.WriteLine(s.TakeWhile(x => x == '1').Count() >= long.Parse(Console.ReadLine()) ? '1' : s.First(x => x != '1')); } }
[["-", 0, 41, 15, 16, 12, 213, 63, 214, 205, 199], ["+", 0, 41, 15, 16, 12, 213, 63, 214, 205, 199]]
8
153
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C044 { class C106 { static void Main(string[] args) { string S = Console.ReadLine(); long K = long.Parse(Console.ReadLine()); char ot = '1'; int counter = 0; foreach (char c in S) { if (counter > K) break; if (c != '1') { ot = c; break; } counter++; } Console.WriteLine(ot); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C044 { class C106 { static void Main(string[] args) { string S = Console.ReadLine(); long K = long.Parse(Console.ReadLine()); char ot = '1'; int counter = 1; foreach (char c in S) { if (counter > K) break; if (c != '1') { ot = c; break; } counter++; } Console.WriteLine(ot); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
124
2
using System; namespace ABC106C { class MainClass { public static void Main(string[] args) { // N M みたいな入力 string Sinput = Console.ReadLine(); char[] S = Sinput.ToCharArray(); // N M みたいな入力 string input2 = Console.ReadLine(); long K = long.Parse(input2); // 5000兆 long n = 5000000000000000; // ans int ans = 0; double p = 0; for (int i = 0; i < S.Length; i++) { p = Math.Pow(double.Parse(S[i].ToString()), n); if (p > K) { ans = int.Parse(S[i].ToString()); break; } else { K = K - (long)p; // Console.WriteLine(K); } } //出力 Console.WriteLine(ans); } } }
using System; namespace ABC106C { class MainClass { public static void Main(string[] args) { // N M みたいな入力 string Sinput = Console.ReadLine(); char[] S = Sinput.ToCharArray(); // N M みたいな入力 string input2 = Console.ReadLine(); long K = long.Parse(input2); // 5000兆 long n = 5000000000000000; // ans int ans = 0; double p = 0; for (int i = 0; i < S.Length; i++) { p = Math.Pow(double.Parse(S[i].ToString()), n); if (p >= K) { ans = int.Parse(S[i].ToString()); break; } else { K = K - (long)p; // Console.WriteLine(K); } } //出力 Console.WriteLine(ans); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
8
169
2
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static void Main(string[] args) { string S = Console.ReadLine(); string N = Console.ReadLine(); if (N.Length <= 3 && int.Parse(N) <= 100 && int.Parse(S[0].ToString()) == 1) { for (int i = 0; i < int.Parse(N); i++) { if (int.Parse(S[i].ToString()) != 1) { Console.WriteLine(S[i]); return; } if (i == int.Parse(N) - 1) { Console.WriteLine("1"); return; } } } else { for (int i = 0; i < int.Parse(N); i++) { if (int.Parse(S[i].ToString()) != 1) { Console.WriteLine(S[i]); return; } } } } } }
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static void Main(string[] args) { string S = Console.ReadLine(); string N = Console.ReadLine(); if (N.Length <= 3 && int.Parse(N) <= 100 && int.Parse(S[0].ToString()) == 1) { for (int i = 0; i < int.Parse(N); i++) { if (int.Parse(S[i].ToString()) != 1) { Console.WriteLine(S[i]); return; } if (i == int.Parse(N) - 1) { Console.WriteLine("1"); return; } } } else { for (int i = 0; i < S.Length; i++) { if (int.Parse(S[i].ToString()) != 1) { Console.WriteLine(S[i]); return; } } } } } }
[["-", 0, 7, 15, 16, 12, 213, 63, 214, 205, 199], ["+", 75, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 7, 15, 16, 12, 213, 3, 4, 0, 24], ["-", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25], ["+", 75, 196, 0, 7, 15, 16, 12, 214, 141, 22]]
8
222
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static Scanner cin = new Scanner(); static void Main() { string S = Console.ReadLine(); long K = cin.Long(); if (K > 100) { string not_one = ""; foreach (var x in S) { if (x != '1') { not_one = x.ToString(); break; } } Console.WriteLine(not_one == "" ? "1" : not_one); } else if (K == 1) Console.WriteLine(S[0].ToString()); else { string not_one = S[(int)K - 1].ToString(); for (int i = 0; i <= K - 2; i++) { if (S[i] != '1') { not_one = S[i].ToString(); break; } } Console.WriteLine(not_one == "" ? "1" : not_one); } Console.ReadLine(); } } class Scanner //標準入力 { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int Int() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static Scanner cin = new Scanner(); static void Main() { string S = Console.ReadLine(); long K = cin.Long(); if (K > S.Length) { string not_one = ""; foreach (var x in S) { if (x != '1') { not_one = x.ToString(); break; } } Console.WriteLine(not_one == "" ? "1" : not_one); } else if (K == 1) Console.WriteLine(S[0].ToString()); else { string not_one = S[(int)K - 1].ToString(); for (int i = 0; i <= K - 2; i++) { if (S[i] != '1') { not_one = S[i].ToString(); break; } } Console.WriteLine(not_one == "" ? "1" : not_one); } Console.ReadLine(); } } class Scanner //標準入力 { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int Int() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22]]
8
582
4
using System; using System.Linq; class P { static void Main() { string S = Console.ReadLine(); long K = long.Parse(Console.ReadLine()); int count1 = 0; for (int i = 1; i <= S.Length; i++) { if (S[i - 1] == '1') count1++; else break; } string ans = ""; if (count1 > 0) { if (K <= count1) ans = "1"; else ans = S[1].ToString(); } else { ans = S[0].ToString(); } Console.WriteLine(ans); } }
using System; using System.Linq; class P { static void Main() { string S = Console.ReadLine(); long K = long.Parse(Console.ReadLine()); int count1 = 0; for (int i = 1; i <= S.Length; i++) { if (S[i - 1] == '1') count1++; else break; } string ans = ""; if (count1 > 0) { if (K <= count1) ans = "1"; else ans = S[count1].ToString(); } else { ans = S[0].ToString(); } Console.WriteLine(ans); } }
[["-", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 22]]
8
143
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { //******Q4 To Infinity class 使用************** // Sは数値の文字列 1>= <=100 // Kは何文字目を表す数値 string s = Console.ReadLine(); int k = int.Parse(Console.ReadLine()); infinity Infinity = new infinity(); Console.WriteLine(Infinity.ans(s, k)); // Console.ReadLine(); //******Q3 105 class Divisor****************** // int a = int.Parse(Console.ReadLine()); // Divisor divisor = new Divisor(); // int ans = divisor.Q3(a); // Console.WriteLine(ans ); //******Q3 105 ここまで********************** } private static string Q1() { //練習問題 // a // b c(bとcの間はスペース) // s // という入力値(改行されている) abcは数値 sは文字列 //  これを a+b+c sの形で出力せよ //   a=3.b=12,c=20 s="miho" なら 出力は "35 miho" int a = int.Parse(Console.ReadLine()); string[] bc = Console.ReadLine().Split(' '); int b = int.Parse(bc[0]); int c = int.Parse(bc[1]); string s = Console.ReadLine(); return ((a + b + c) + " " + s); } private static int Q2() { // garden string[] ab = Console.ReadLine().Split(' '); int a = int.Parse(ab[0]); int b = int.Parse(ab[1]); return ((a - 1) * (b - 1)); } } class infinity { public char ans(string s, int k) { char[] chars = s.ToCharArray(); if (chars[0] != '1') return chars[0]; long a = leftcnt1(s); if (a >= k) { return '1'; } else { // a < k return chars[a]; } } private long leftcnt1(string s) { char[] chars = s.ToCharArray(); for (long i = 0; i < s.Length - 1; i++) { if (chars[i] != '1') return i; } return 0; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { //******Q4 To Infinity class 使用************** // Sは数値の文字列 1>= <=100 // Kは何文字目を表す数値 string s = Console.ReadLine(); long k = long.Parse(Console.ReadLine()); infinity Infinity = new infinity(); Console.WriteLine(Infinity.ans(s, k)); // Console.ReadLine(); //******Q3 105 class Divisor****************** // int a = int.Parse(Console.ReadLine()); // Divisor divisor = new Divisor(); // int ans = divisor.Q3(a); // Console.WriteLine(ans ); //******Q3 105 ここまで********************** } private static string Q1() { //練習問題 // a // b c(bとcの間はスペース) // s // という入力値(改行されている) abcは数値 sは文字列 //  これを a+b+c sの形で出力せよ //   a=3.b=12,c=20 s="miho" なら 出力は "35 miho" int a = int.Parse(Console.ReadLine()); string[] bc = Console.ReadLine().Split(' '); int b = int.Parse(bc[0]); int c = int.Parse(bc[1]); string s = Console.ReadLine(); return ((a + b + c) + " " + s); } private static int Q2() { // garden string[] ab = Console.ReadLine().Split(' '); int a = int.Parse(ab[0]); int b = int.Parse(ab[1]); return ((a - 1) * (b - 1)); } } class infinity { public char ans(string s, long k) { char[] chars = s.ToCharArray(); if (chars[0] != '1') return chars[0]; long a = leftcnt1(s); if (a >= k) { return '1'; } else { // a < k return chars[a]; } } private long leftcnt1(string s) { char[] chars = s.ToCharArray(); for (long i = 0; i < s.Length - 1; i++) { if (chars[i] != '1') return i; } return 0; } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199]]
8
400
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc106_c { class Program { static void Main(string[] args) { string s = Console.ReadLine(); long k = long.Parse(Console.ReadLine()); int p = 0; for (int i = 0; i < s.Length; ++i) { if (s[i] != '1') { p = i; break; } } if (k < p) { Console.WriteLine(1); } else { Console.WriteLine(s[p]); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc106_c { class Program { static void Main(string[] args) { string s = Console.ReadLine(); long k = long.Parse(Console.ReadLine()); int p = 0; for (int i = 0; i < s.Length; ++i) { if (s[i] != '1') { p = i; break; } } if (k - 1 < p) { Console.WriteLine(1); } else { Console.WriteLine(s[p]); } } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
139
2
using System; public class Hello { public static void Main() { var s = Console.ReadLine(); var k = long.Parse(Console.ReadLine()); for (var i = 0; i < s.Length; i++) { if (s[i] != '1') { Console.WriteLine(s[i]); return; } } Console.WriteLine('1'); } }
using System; public class Hello { public static void Main() { var s = Console.ReadLine(); var k = long.Parse(Console.ReadLine()); for (var i = 0; i < k; i++) { if (s[i] != '1') { Console.WriteLine(s[i]); return; } } Console.WriteLine('1'); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
91
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { var S = Console.ReadLine(); long K = long.Parse(Console.ReadLine()); int x; for (x = 0; S[x] == '1'; x++) ; if (K <= (long)x) { Console.WriteLine(1); } else { Console.WriteLine(S[x]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { var S = Console.ReadLine(); long K = long.Parse(Console.ReadLine()); int x; for (x = 0; x < S.Length && S[x] == '1'; x++) ; if (K <= (long)x) { Console.WriteLine(1); } else { Console.WriteLine(S[x]); } } }
[["+", 8, 196, 0, 7, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 18], ["+", 0, 7, 15, 16, 31, 16, 12, 214, 205, 22], ["+", 0, 7, 15, 16, 31, 16, 12, 214, 0, 131], ["+", 0, 7, 15, 16, 31, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 98]]
8
118
6
using System; using System.Collections.Generic; using System.Linq; class Program { public static int Main(string[] args) { string str = Console.ReadLine(); string s = str; List<int> s_list = new List<int>(); for (int i = 0; i < s.Length; i++) { s_list.Add(int.Parse(s[i].ToString())); } str = Console.ReadLine(); long k = long.Parse(str); long max = new List<long> { s.Length, k }.Max(); int answer = 1; for (int i = 0; i < max; i++) { if (s_list[i] > 1) { answer = s_list[i]; break; } } Console.WriteLine(answer); return 0; } }
using System; using System.Collections.Generic; using System.Linq; class Program { public static int Main(string[] args) { string str = Console.ReadLine(); string s = str; List<int> s_list = new List<int>(); for (int i = 0; i < s.Length; i++) { s_list.Add(int.Parse(s[i].ToString())); } str = Console.ReadLine(); long k = long.Parse(str); long min = new List<long> { s.Length, k }.Min(); int answer = 1; for (int i = 0; i < min; i++) { if (s_list[i] > 1) { answer = s_list[i]; break; } } Console.WriteLine(answer); return 0; } }
[["-", 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], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
185
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace test { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var K = long.Parse(Console.ReadLine()); var num = 0; var idx = 0; for (var i = 0; i < S.Length; i++) { var tmp = int.Parse(S.Substring(i, 1)); if (tmp != 1) { num = tmp; idx = i; break; } } Console.WriteLine(idx > K - 1 ? 1 : num); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace test { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var K = long.Parse(Console.ReadLine()); var num = 1; var idx = 0; for (var i = 0; i < S.Length; i++) { var tmp = int.Parse(S.Substring(i, 1)); if (tmp != 1) { num = tmp; idx = i; break; } } Console.WriteLine(idx > K - 1 ? 1 : num); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
147
2
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; /*Please dont change namespace, Dcoder and class must not be public*/ // Compiler version 4.0, .NET Framework 4.5 namespace Dcoder { public class Program { public static void Main(string[] args) { Method(args); } public static void Method(string[] args) { string s = Console.ReadLine(); long k = long.Parse(Console.ReadLine()); for (int i = 0; i < s.Length; i++) { if (s[i] != '1' || i == k) { Console.WriteLine(s[i]); return; } else { continue; } } Console.WriteLine(k); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; /*Please dont change namespace, Dcoder and class must not be public*/ // Compiler version 4.0, .NET Framework 4.5 namespace Dcoder { public class Program { public static void Main(string[] args) { Method(args); } public static void Method(string[] args) { string s = Console.ReadLine(); long k = long.Parse(Console.ReadLine()); for (int i = 0; i < s.Length; i++) { if (s[i] != '1' || i == k - 1) { Console.WriteLine(s[i]); return; } else { continue; } } Console.WriteLine(k); } } }
[["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203]]
8
144
2
using System; using System.Collections.Generic; class Program { public static int min(int x, int y) { if (x >= y) { return y; } else { return x; } } public static void Main() { int N, K; var NKL = Console.ReadLine().Split(' '); N = int.Parse(NKL[0]); K = int.Parse(NKL[1]); var A = new int[N]; var line = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { A[i] = int.Parse(line[i]); } int M = 2147483646; for (int k = 0; k < N - K + 1; k++) { if (A[k] * A[k + K - 1] < 0) { int s = min(A[k + K - 1] - 2 * A[k], 2 * A[k + K - 1] - A[k]); M = min(s, M); } else if (A[k] <= 0 && A[k + K - 1] <= 0) { M = min(-A[k], M); } else if (A[k] >= 0 && A[k + K - 1] >= 0) { M = min(A[k + K - 1], M); } } Console.WriteLine(M); } }
using System; using System.Collections.Generic; class Program { public static int min(int x, int y) { if (x >= y) { return y; } else { return x; } } public static void Main() { int N, K; var NKL = Console.ReadLine().Split(' '); N = int.Parse(NKL[0]); K = int.Parse(NKL[1]); var A = new int[N]; var line = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { A[i] = int.Parse(line[i]); } int M = 2147483646; for (int k = 0; k < N - K + 1; k++) { if (A[k] < 0 && A[k + K - 1] > 0) { int s = min(A[k + K - 1] - 2 * A[k], 2 * A[k + K - 1] - A[k]); M = min(s, M); } else if (A[k] <= 0 && A[k + K - 1] <= 0) { M = min(-A[k], M); } else if (A[k] >= 0 && A[k + K - 1] >= 0) { M = min(A[k + K - 1], M); } } Console.WriteLine(M); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47]]
8
327
6
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var K = sc.ReadInt(); var X = sc.ReadIntArray(N); var ans = int.MaxValue; for (int i = K - 1; i < N; i++) { var v1 = X[i - K + 1]; var v2 = X[i]; if (v1 * v2 >= 0) { ans = Math.Min(ans, Math.Max(Math.Abs(v1), Math.Abs(v2))); } else { var res1 = Math.Abs(v1) * 2 + Math.Abs(v2); var res2 = Math.Abs(v1) + Math.Abs(v2 * 2); ans = Math.Min(ans, Math.Min(res1, res2)); } } Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var K = sc.ReadInt(); var X = sc.ReadLongArray(N); var ans = long.MaxValue; for (int i = K - 1; i < N; i++) { var v1 = X[i - K + 1]; var v2 = X[i]; if (v1 * v2 >= 0) { ans = Math.Min(ans, Math.Max(Math.Abs(v1), Math.Abs(v2))); } else { var res1 = Math.Abs(v1) * 2 + Math.Abs(v2); var res2 = Math.Abs(v1) + Math.Abs(v2 * 2); ans = Math.Min(ans, Math.Min(res1, res2)); } } Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199]]
8
720
4
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { var cin = new Scanner(); int n = cin.Int(); int k = cin.Int(); var x = cin.ArrayLong(n); long ans = long.MaxValue; for (int i = 0; i < n - k; i++) { long l = x[i]; long r = x[i + k - 1]; long temp1 = Math.Abs(l) + Math.Abs(r - l); long temp2 = Math.Abs(r - l) + Math.Abs(r); ans = Math.Min(ans, temp1); ans = Math.Min(ans, temp2); } Console.WriteLine(ans); } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { var cin = new Scanner(); int n = cin.Int(); int k = cin.Int(); var x = cin.ArrayLong(n); long ans = long.MaxValue; for (int i = 0; i <= n - k; i++) { long l = x[i]; long r = x[i + k - 1]; long temp1 = Math.Abs(l) + Math.Abs(r - l); long temp2 = Math.Abs(r - l) + Math.Abs(r); ans = Math.Min(ans, temp1); ans = Math.Min(ans, temp2); } Console.WriteLine(ans); } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
560
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; //using static System.Globalization.CultureInfo; using System.Text; class Program { private static void chmin<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == 1 ? val : num; private static void chmax<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == -1 ? val : num; static void Main(string[] args) { var pr = new Program(); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); pr.Solve(); Console.Out.Flush(); } void Solve() { int num, k; Input.Make(out num, out k); var xs = Input.ar; var min = long.MaxValue; for(var i = 0; i < num - k+1; i++) { if (Sign(xs[i]) == Sign(xs[i + k-1])) chmin(ref min, Max(xs[i], xs[i + k-1])); else chmin(ref min, Min(2L * Abs(xs[i]) + xs[i + k-1], Abs(xs[i]) + 2L * xs[i + k-1])); } WriteLine(min); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static T[] create<T>(int n, Func<int, T> f) => Enumerable.Repeat(0, n).Select(f).ToArray(); public static char[][] gred(int h) => create(h, _ => read.ToCharArray()); public static int[] ar1D(int n) => create(n, _ => num); public static long[] arL1D(int n) => create(n, _ => numL); public static string[] strs(int n) => create(n, _ => read); public static int[][] ar2D(int n) => create(n, _ => ar); public static long[][] arL2D(int n) => create(n, _ => arL); public static List<T>[] edge<T>(int n) => create(n, _ => new List<T>()); public static T GetValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object)int.Parse(g); if (t == typeof(long)) return (T)(object)long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object)char.Parse(g); if (t == typeof(double)) return (T)(object)double.Parse(g); if (t == typeof(bool)) return (T)(object)bool.Parse(g); return default(T); } public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } private static Queue<string> sc; public static T Next<T>(){ sc = sc ?? new Queue<string>(); if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item);return GetValue<T>(sc.Dequeue()); } public static void Next<T>(ref T val) => val = Next<T>(); public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; //using static System.Globalization.CultureInfo; using System.Text; class Program { private static void chmin<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == 1 ? val : num; private static void chmax<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == -1 ? val : num; static void Main(string[] args) { var pr = new Program(); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); pr.Solve(); Console.Out.Flush(); } void Solve() { int num, k; Input.Make(out num, out k); var xs = Input.ar; var min = long.MaxValue; for (var i = 0; i < num - k + 1; i++) { if (Sign(xs[i]) == Sign(xs[i + k - 1])) chmin(ref min, Max(Abs(xs[i]), Abs(xs[i + k - 1]))); else chmin(ref min, Min(2L * Abs(xs[i]) + xs[i + k - 1], Abs(xs[i]) + 2L * xs[i + k - 1])); } WriteLine(min); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static T[] create<T>(int n, Func<int, T> f) => Enumerable.Repeat(0, n).Select(f).ToArray(); public static char[][] gred(int h) => create(h, _ => read.ToCharArray()); public static int[] ar1D(int n) => create(n, _ => num); public static long[] arL1D(int n) => create(n, _ => numL); public static string[] strs(int n) => create(n, _ => read); public static int[][] ar2D(int n) => create(n, _ => ar); public static long[][] arL2D(int n) => create(n, _ => arL); public static List<T>[] edge<T>(int n) => create(n, _ => new List<T>()); public static T GetValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object)int.Parse(g); if (t == typeof(long)) return (T)(object)long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object)char.Parse(g); if (t == typeof(double)) return (T)(object)double.Parse(g); if (t == typeof(bool)) return (T)(object)bool.Parse(g); return default(T); } public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } private static Queue<string> sc; public static T Next<T>(){ sc = sc ?? new Queue<string>(); if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item);return GetValue<T>(sc.Dequeue()); } public static void Next<T>(ref T val) => val = Next<T>(); public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
[["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
1,187
6
using System; using System.Collections.Generic; using System.Linq; namespace algorithm { class Program { static void Main(string[] args) { //全体/必要本数 var q = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); //座標 var d = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int k = q[1]; // 0から近い端を調べる int min = int.MaxValue; for (int i = 0; i < q[0] - k; i++) { min = Math.Min(Math.Min(min, d[i + k - 1] - d[i] + Math.Abs(d[i])), d[i + k - 1] - d[i] + Math.Abs(d[i + k - 1])); } //出力 Console.WriteLine(min); } } }
using System; using System.Collections.Generic; using System.Linq; namespace algorithm { class Program { static void Main(string[] args) { //全体/必要本数 var q = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); //座標 var d = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int k = q[1]; // 0から近い端を調べる int min = int.MaxValue; for (int i = 0; i + k - 1 < q[0]; i++) { min = Math.Min(Math.Min(min, d[i + k - 1] - d[i] + Math.Abs(d[i])), d[i + k - 1] - d[i] + Math.Abs(d[i + k - 1])); } //出力 Console.WriteLine(min); } } }
[["+", 0, 7, 15, 16, 31, 16, 31, 16, 17, 72], ["+", 0, 7, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22]]
8
191
6
using System; using System.Linq; namespace Candles { class Program { static void Main(string[] args) { var nk = GetArrayIntInput(); var inputs = GetArrayIntInput(); int result = int.MaxValue; for (int i = 0; i < nk[0] - nk[1]; i++) { var range = inputs[i + nk[1] - 1] - inputs[i]; var tmpResult = Math.Min(range + Math.Abs(inputs[i]), range + Math.Abs(inputs[i + nk[1] - 1])); result = Math.Min(result, tmpResult); } CWrite(result); } static string[] GetArrayCharInput() => Console.ReadLine().Split(); static int[] GetArrayIntInput() => Console.ReadLine().StringToIntArray(); static int GetIntInput() => Console.ReadLine().ToInt(); static void CWrite<T>(T str) => Console.WriteLine(str); } static class ExtentionsLibrary { public static int[] StringToIntArray(this string str) => str.Split().Select(int.Parse).ToArray(); public static int ToInt(this string str) => int.Parse(str); } }
using System; using System.Linq; namespace Candles { class Program { static void Main(string[] args) { var nk = GetArrayIntInput(); var inputs = GetArrayIntInput(); int result = int.MaxValue; for (int i = 0; i <= nk[0] - nk[1]; i++) { var range = inputs[i + nk[1] - 1] - inputs[i]; var tmpResult = Math.Min(range + Math.Abs(inputs[i]), range + Math.Abs(inputs[i + nk[1] - 1])); result = Math.Min(result, tmpResult); } CWrite(result); } static string[] GetArrayCharInput() => Console.ReadLine().Split(); static int[] GetArrayIntInput() => Console.ReadLine().StringToIntArray(); static int GetIntInput() => Console.ReadLine().ToInt(); static void CWrite<T>(T str) => Console.WriteLine(str); } static class ExtentionsLibrary { public static int[] StringToIntArray(this string str) => str.Split().Select(int.Parse).ToArray(); public static int ToInt(this string str) => int.Parse(str); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
268
2
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]C - Candles var line = ReadLine().ToList(); int n = line[0]; int k = line[1]; var x = ReadLine().ToList(); int min = int.MaxValue; for (int i = 0; i <= n - k; i++) { int firstX = x[i]; int lastX = x[i + k - 1]; int dist = GetDistance(firstX, lastX); if (dist < min) { min = dist; } } Console.WriteLine(min); } static int GetDistance(int firstX, int lastX) { if (lastX < 0) { return Math.Abs(firstX); } else if (firstX > 0) { return lastX; } else { //片方の座標がマイナスで、もう片方がプラスのケース //(最初にどちらの方向に行くかで2パターンが考えられる) int dist1 = Math.Abs(firstX) * 2 + lastX; int dist2 = lastX * 2 + Math.Abs(firstX); if (dist1 > dist2) { return dist1; } else { return dist2; } } } static IEnumerable<int> ReadLine() { var line = Console.ReadLine().TrimEnd(); var array = line.Split(' '); foreach (var s in array) { yield return int.Parse(s); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]C - Candles var line = ReadLine().ToList(); int n = line[0]; int k = line[1]; var x = ReadLine().ToList(); int min = int.MaxValue; for (int i = 0; i <= n - k; i++) { int firstX = x[i]; int lastX = x[i + k - 1]; int dist = GetDistance(firstX, lastX); if (dist < min) { min = dist; } } Console.WriteLine(min); } static int GetDistance(int firstX, int lastX) { if (lastX <= 0) { return Math.Abs(firstX); } else if (firstX >= 0) { return lastX; } else { //片方の座標がマイナスで、もう片方がプラスのケース //(最初にどちらの方向に行くかで2パターンが考えられる) int dist1 = Math.Abs(firstX) * 2 + lastX; int dist2 = lastX * 2 + Math.Abs(firstX); if (dist1 < dist2) { return dist1; } else { return dist2; } } } static IEnumerable<int> ReadLine() { var line = Console.ReadLine().TrimEnd(); var array = line.Split(' '); foreach (var s in array) { yield return int.Parse(s); } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 20], ["-", 75, 57, 75, 196, 0, 57, 15, 16, 17, 47], ["+", 75, 57, 75, 196, 0, 57, 15, 16, 17, 18]]
8
290
6
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { string[] s = Console.ReadLine().Split().ToArray(); int n = int.Parse(s[0]); int k = int.Parse(s[1]); int[] x = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); int ans = int.MaxValue; if (n == 1) { Console.WriteLine(x[0]); return; } for (int i = 0; i < x.Length - k; i++) { ans = Math.Min(ans, Math.Abs(x[i + k - 1]) + Math.Abs(x[i + k - 1] - x[i])); ans = Math.Min(ans, Math.Abs(x[i]) + Math.Abs(x[i + k - 1] - x[i])); } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { string[] s = Console.ReadLine().Split().ToArray(); int n = int.Parse(s[0]); int k = int.Parse(s[1]); int[] x = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); int ans = int.MaxValue; if (n == 1) { Console.WriteLine(x[0]); return; } for (int i = 0; i < x.Length - k + 1; i++) { ans = Math.Min(ans, Math.Abs(x[i + k - 1]) + Math.Abs(x[i + k - 1] - x[i])); ans = Math.Min(ans, Math.Abs(x[i]) + Math.Abs(x[i + k - 1] - x[i])); } Console.WriteLine(ans); } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
236
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; public class MyProgram { public static void Main() { int[] n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int N = n[0]; int K = n[1] - 1; n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int min = 99999999; int a = 0, b = 0, c = 0; for (int i = 0; i < N - K; i++) { a = Math.Abs(n[i]) + Math.Abs(n[i + K] - n[i]); b = Math.Abs(n[i + K]) + Math.Abs(n[i + K] - n[i]); c = Math.Min(a, b); min = Math.Min(min, c); } Console.WriteLine(min); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; public class MyProgram { public static void Main() { int[] n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int N = n[0]; int K = n[1] - 1; n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); long min = 999999999999; int a = 0, b = 0, c = 0; for (int i = 0; i < N - K; i++) { a = Math.Abs(n[i]) + Math.Abs(n[i + K] - n[i]); b = Math.Abs(n[i + K]) + Math.Abs(n[i + K] - n[i]); c = Math.Min(a, b); min = Math.Min(min, c); } Console.WriteLine(min); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
241
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace test { class Program { static void Main(string[] args) { string s = Console.ReadLine(); int N = int.Parse(s.Split(' ')[0]); int K = int.Parse(s.Split(' ')[1]); string[] arr = Console.ReadLine().Split(' '); long[] Pattern = new long[N - K + 1]; for (int i = 0; i < N - K + 1; i++) { long max = long.Parse(arr[K + i]); long min = long.Parse(arr[i]); if (max <= 0) { Pattern[i] = (-1) * min; continue; } else if (0 <= min) { Pattern[i] = max; continue; } if (Math.Abs(min) < max) { Pattern[i] = Math.Abs(min) * 2 + max; } else { Pattern[i] = Math.Abs(min) + max * 2; } } Console.WriteLine(Pattern.Min()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace test { class Program { static void Main(string[] args) { string s = Console.ReadLine(); int N = int.Parse(s.Split(' ')[0]); int K = int.Parse(s.Split(' ')[1]); string[] arr = Console.ReadLine().Split(' '); long[] Pattern = new long[N - K + 1]; for (int i = 0; i < N - K + 1; i++) { long max = long.Parse(arr[K + i - 1]); long min = long.Parse(arr[i]); if (max <= 0) { Pattern[i] = (-1) * min; continue; } else if (0 <= min) { Pattern[i] = max; continue; } if (Math.Abs(min) < max) { Pattern[i] = Math.Abs(min) * 2 + max; } else { Pattern[i] = Math.Abs(min) + max * 2; } } Console.WriteLine(Pattern.Min()); } } }
[["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
275
2
using System; using System.Collections.Generic; using System.Linq; namespace ABC107C { class Program { static void Main(string[] args) { var dg = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray(); var n = dg[0]; var k = dg[1] - 1; var x = Console.ReadLine().Split(' ').Select(v => double.Parse(v)).ToArray(); var min = double.MaxValue; for (int i = 0; i < (n - k); ++i) { var start = x[i]; var end = x[i + k]; // Console.WriteLine(start); // Console.WriteLine(target); double res = calc(start, end); if (res < min) { min = res; } if (start >= 0) { break; } } Console.WriteLine(min); } static double calc(double start, double end) { if (start < 0) { if (end < 0) { return Math.Abs(end); } return getMin(start, end); } return end; } static double getMin(double start, double end) { var a = Math.Abs(end) + Math.Abs(start) * 2; var b = Math.Abs(end * 2 + Math.Abs(start)); return a < b ? a : b; } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC107C { class Program { static void Main(string[] args) { var dg = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray(); var n = dg[0]; var k = dg[1] - 1; var x = Console.ReadLine().Split(' ').Select(v => double.Parse(v)).ToArray(); var min = double.MaxValue; for (int i = 0; i < (n - k); ++i) { var start = x[i]; var end = x[i + k]; // Console.Write(start); // Console.Write(" "); // Console.WriteLine(end); // Console.WriteLine("---"); double res = calc(start, end); if (res < min) { min = res; } if (start >= 0) { break; } } Console.WriteLine(min); } static double calc(double start, double end) { if (start < 0) { if (end < 0) { return Math.Abs(start); } return getMin(start, end); } return end; } static double getMin(double start, double end) { var a = Math.Abs(end) + Math.Abs(start) * 2; var b = Math.Abs(end) * 2 + Math.Abs(start); // Console.Write(a); // Console.Write(" "); // Console.WriteLine(b); // Console.WriteLine("---"); return a < b ? a : b; } } }
[["-", 0, 37, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 37, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25]]
8
308
4
// デバッグ実行:Ctrl+F5 using System; class Program { static void Main(string[] args) { String line; line = Console.ReadLine(); String[] words = line.Split(' '); int N, K; int[] rousoku; N = int.Parse(words[0]); K = int.Parse(words[1]); rousoku = new int[N]; line = Console.ReadLine(); words = line.Split(' '); for (int i = 0; i < N; i++) { rousoku[i] = int.Parse(words[i]); } int min = 300000000; int kouho = 0; int x1, x2; if (K == 1) { for (int i = 0; i < N; i++) { kouho = Math.Abs(rousoku[i]); if (min > kouho) { min = kouho; } } } else { for (int i = 0; i < N - K; i++) { x1 = Math.Abs(rousoku[i]); x2 = Math.Abs(rousoku[i + K - 1]); if (rousoku[i] < 0 && rousoku[i + K - 1] < 0) { kouho = x1; } else if (rousoku[i] >= 0 && rousoku[i + K - 1] >= 0) { kouho = x2; } else { if (x1 > x2) { kouho = x1 + x2 * 2; } else { kouho = x1 * 2 + x2; } } if (min > kouho) { min = kouho; } } } Console.WriteLine(min); } }
// デバッグ実行:Ctrl+F5 using System; class Program { static void Main(string[] args) { String line; line = Console.ReadLine(); String[] words = line.Split(' '); int N, K; int[] rousoku; N = int.Parse(words[0]); K = int.Parse(words[1]); rousoku = new int[N]; line = Console.ReadLine(); words = line.Split(' '); for (int i = 0; i < N; i++) { rousoku[i] = int.Parse(words[i]); } int min = 2000000000; int kouho = 0; int x1, x2; if (K == 1) { for (int i = 0; i < N; i++) { kouho = Math.Abs(rousoku[i]); if (min > kouho) { min = kouho; } } } else { for (int i = 0; i < N - K + 1; i++) { x1 = Math.Abs(rousoku[i]); x2 = Math.Abs(rousoku[i + K - 1]); if (rousoku[i] < 0 && rousoku[i + K - 1] < 0) { kouho = x1; } else if (rousoku[i] >= 0 && rousoku[i + K - 1] >= 0) { kouho = x2; } else { if (x1 > x2) { kouho = x1 + x2 * 2; } else { kouho = x1 * 2 + x2; } } if (min > kouho) { min = kouho; } } } Console.WriteLine(min); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 75, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 75, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
350
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { var N = sc.Int; var A = sc.ArrInt; int r = (int)1e9, l = 0; while (r - l > 1) { var m = (r + l) >> 1; var s = N + 10; var ct = 0L; var bit = new BIT(N * 2 + 100); bit.add(s, 1); for (var i = 0; i < N; i++) { if (A[i] >= m) s++; else s--; ct += bit[s]; bit.add(s, 1); } if ((N * (N + 1) / 2 + 1) / 2 <= ct) l = m; else r = m; } WriteLine(l); } } public class BIT { // 1-indexed long[] data; public BIT(int num) { data = new long[num + 1]; } public long this[int index] { get { var s = 0L; for (var i = index; i > 0; i -= i & -i) s += data[i]; return s; } } public void add(int index, long value) { for (var i = index; i < data.Length; i += i & -i) data[i] += value; } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { var N = sc.Int; var A = sc.ArrInt; int r = (int)1e9 + 1, l = 0; while (r - l > 1) { var m = (r + l) >> 1; var s = N + 10; var ct = 0L; var bit = new BIT(N * 2 + 100); bit.add(s, 1); for (var i = 0; i < N; i++) { if (A[i] >= m) s++; else s--; ct += bit[s]; bit.add(s, 1); } if ((N * (N + 1L) / 2 + 1) / 2 <= ct) l = m; else r = m; } WriteLine(l); } } public class BIT { // 1-indexed long[] data; public BIT(int num) { data = new long[num + 1]; } public long this[int index] { get { var s = 0L; for (var i = index; i > 0; i -= i & -i) s += data[i]; return s; } } public void add(int index, long value) { for (var i = index; i < data.Length; i += i & -i) data[i] += value; } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 31, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 12, 203]]
8
1,829
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC { class Program { static void Main(string[] args) { var split = Console.ReadLine().Split(' '); int N = int.Parse(split[0]); int K = int.Parse(split[1]); split = Console.ReadLine().Split(' '); long[] x = new long[N]; int first_notminus = -1; bool first_flag = false; for (int i = 0; i < N; i++) { x[i] = long.Parse(split[i]); } long output = long.MaxValue; for (int i = 0; i + K < N; i++) { long hidari = x[i]; long migi = x[i + K - 1]; long candidate = long.MaxValue; if (hidari * migi > 0) { if (Math.Max(Math.Abs(hidari), Math.Abs(migi)) < candidate) candidate = Math.Max(Math.Abs(hidari), Math.Abs(migi)); } else { if (Math.Abs(hidari) + migi + Math.Min(migi, Math.Abs(hidari)) < candidate) candidate = Math.Abs(hidari) + migi + Math.Min(migi, Math.Abs(hidari)); } if (output > candidate) output = candidate; } Console.WriteLine(output); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC { class Program { static void Main(string[] args) { var split = Console.ReadLine().Split(' '); int N = int.Parse(split[0]); int K = int.Parse(split[1]); split = Console.ReadLine().Split(' '); long[] x = new long[N]; int first_notminus = -1; bool first_flag = false; for (int i = 0; i < N; i++) { x[i] = long.Parse(split[i]); } long output = long.MaxValue; for (int i = 0; i + K < N + 1; i++) { long hidari = x[i]; long migi = x[i + K - 1]; long candidate = long.MaxValue; if (hidari * migi > 0) { if (Math.Max(Math.Abs(hidari), Math.Abs(migi)) < candidate) candidate = Math.Max(Math.Abs(hidari), Math.Abs(migi)); } else { if (Math.Abs(hidari) + migi + Math.Min(migi, Math.Abs(hidari)) < candidate) candidate = Math.Abs(hidari) + migi + Math.Min(migi, Math.Abs(hidari)); } if (output > candidate) output = candidate; } Console.WriteLine(output); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
334
2
using System; using System.Text; using System.Collections.Generic; using static System.Math; using System.Linq; using static System.Array; namespace AtcoderExpress { class Program { static void Main(string[] args) { var NMQ = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = NMQ[0]; var M = NMQ[1]; var Q = NMQ[2]; var Route = new long[N + 1, N + 1]; for (int i = 0; i < M; i++) { var LR = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var L = LR[0]; var R = LR[1]; Route[L, R]++; } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { Route[i, j] += Route[i, j - 1]; } } for (int i = 0; i < Q; i++) { var PQ = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var S = PQ[0]; var G = PQ[1]; var ans = 0L; for (int j = 1; j <= N; j++) { ans += Route[j, G] - Route[j, S - 1]; } Console.WriteLine(ans); } } } }
using System; using System.Text; using System.Collections.Generic; using static System.Math; using System.Linq; using static System.Array; namespace AtcoderExpress { class Program { static void Main(string[] args) { var NMQ = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = NMQ[0]; var M = NMQ[1]; var Q = NMQ[2]; var Route = new long[N + 1, N + 1]; for (int i = 0; i < M; i++) { var LR = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var L = LR[0]; var R = LR[1]; Route[L, R]++; } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { Route[i, j] += Route[i, j - 1]; } } for (int i = 0; i < Q; i++) { var PQ = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var S = PQ[0]; var G = PQ[1]; var ans = 0L; for (int j = S; j <= G; j++) { ans += Route[j, G] - Route[j, S - 1]; } Console.WriteLine(ans); } } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22]]
8
352
4
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static int[,] train; static int[,] c; static int N; static int Solve(int p, int q) { int rec = 0; for (int i = p; i <= q; i++) { rec += c[i, q] - c[i, p - 1]; } return rec; } static void CreateC() { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { c[i, j] = c[i, j - 1] + train[i, j]; //累積和を撮る } } } static void Main(string[] args) { //入力1(N, M, Q) int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); N = input[0]; int M = input[1]; int Q = input[2]; train = new int[N + 1, N + 1]; c = new int[N + 1, N + 1]; //入力2(train) for (int i = 0; i < M; i++) { input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int l = input[0]; int r = input[1]; train[l, r]++; } //累積和c生成 CreateC(); //入力3(各クエリを解く) for (int i = 0; i < Q; i++) { input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int p = input[0]; int q = input[1]; Console.WriteLine("ans:" + Solve(p, q)); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static int[,] train; static int[,] c; static int N; static int Solve(int p, int q) { int rec = 0; for (int i = p; i <= q; i++) { rec += c[i, q] - c[i, p - 1]; } return rec; } static void CreateC() { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { c[i, j] = c[i, j - 1] + train[i, j]; //累積和を撮る } } } static void Main(string[] args) { //入力1(N, M, Q) int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); N = input[0]; int M = input[1]; int Q = input[2]; train = new int[N + 1, N + 1]; c = new int[N + 1, N + 1]; //入力2(train) for (int i = 0; i < M; i++) { input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int l = input[0]; int r = input[1]; train[l, r]++; } //累積和c生成 CreateC(); //入力3(各クエリを解く) for (int i = 0; i < Q; i++) { input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int p = input[0]; int q = input[1]; Console.WriteLine(Solve(p, q)); } } } }
[["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 62], ["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
412
4
using System; using System.Collections.Generic; using System.Linq; namespace easy_Atcoder { class Program { static void Main(string[] args) { int[] NK = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Console.WriteLine(NK[0] % NK[1]); } // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse); // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // long N = NK[0]; // long K = NK[1]; // long K = long.Parse(Console.ReadLine()); // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // string S = Console.ReadLine(); // int x = int.Parse(Console.ReadLine()); // int b = int.Parse(Console.ReadLine()); // int N = int.Parse(Console.ReadLine()); // float N = float.Parse(Console.ReadLine()); // string c = Console.ReadLine(); // string B = Console.ReadLine(); // string[] s = Console.ReadLine().Split(); // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), // Console.ReadLine() }).Select(float.Parse); float[] a = // Array.ConvertAll(Console.ReadLine().Split(),float.Parse); var X = // Console.ReadLine(); int[,] abcd = new int[NMQ[2],4]; int[] A = new // int[NMQ[0]]; int[] A_num = new int[NMQ[0]]; long[] // s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); var hs=new // Dictionary<long,long>(); for(int i=0;i<s[0];i++){ // long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];} // else{hs.Add(q[0],q[1]);} // } // //最小公倍数 // static long Lcm(long a, long b) // { // return a/Gcd(a,b)*b; // } // //最大公約数 // static long Gcd(long m, long n) // { // if(n==0)return m; // return Gcd(n,m%n); // } } }
using System; using System.Collections.Generic; using System.Linq; namespace easy_Atcoder { class Program { static void Main(string[] args) { int[] NK = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Console.WriteLine(NK[0] % NK[1] == 0 ? 0 : 1); } // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse); // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // long N = NK[0]; // long K = NK[1]; // long K = long.Parse(Console.ReadLine()); // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // string S = Console.ReadLine(); // int x = int.Parse(Console.ReadLine()); // int b = int.Parse(Console.ReadLine()); // int N = int.Parse(Console.ReadLine()); // float N = float.Parse(Console.ReadLine()); // string c = Console.ReadLine(); // string B = Console.ReadLine(); // string[] s = Console.ReadLine().Split(); // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), // Console.ReadLine() }).Select(float.Parse); float[] a = // Array.ConvertAll(Console.ReadLine().Split(),float.Parse); var X = // Console.ReadLine(); int[,] abcd = new int[NMQ[2],4]; int[] A = new // int[NMQ[0]]; int[] A_num = new int[NMQ[0]]; long[] // s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); var hs=new // Dictionary<long,long>(); for(int i=0;i<s[0];i++){ // long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];} // else{hs.Add(q[0],q[1]);} // } // //最小公倍数 // static long Lcm(long a, long b) // { // return a/Gcd(a,b)*b; // } // //最大公約数 // static long Gcd(long m, long n) // { // if(n==0)return m; // return Gcd(n,m%n); // } } }
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
109
6
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var n = cin.nextInt(); var k = cin.nextInt(); Console.WriteLine(n % k); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var n = cin.nextInt(); var k = cin.nextInt(); Console.WriteLine(n % k == 0 ? 0 : 1); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
566
6
using System; namespace ABC105A { class Program { static void Main(string[] args) { int a, b; string[] ss = Console.ReadLine().Split(' '); a = int.Parse(ss[0]); b = int.Parse(ss[1]); if (a == b) Console.WriteLine("0"); else Console.WriteLine("1"); Console.ReadKey(); } } }
using System; namespace ABC105A { class Program { static void Main(string[] args) { int a, b; string[] ss = Console.ReadLine().Split(' '); a = int.Parse(ss[0]); b = int.Parse(ss[1]); if (a % b == 0) Console.WriteLine("0"); else Console.WriteLine("1"); Console.ReadKey(); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
100
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder { public class ABC { static readonly int mod = 1000000007; // 10^9+7 static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); // int n = int.Parse(Console.ReadLine()); // long n = long.Parse(Console.ReadLine()); // string s = Console.ReadLine(); int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray(); // long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray(); int n = vs[0]; int k = vs[1]; int ans = k % n == 0 ? 0 : 1; Console.WriteLine(ans); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder { public class ABC { static readonly int mod = 1000000007; // 10^9+7 static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); // int n = int.Parse(Console.ReadLine()); // long n = long.Parse(Console.ReadLine()); // string s = Console.ReadLine(); int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray(); // long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray(); int n = vs[0]; int k = vs[1]; int ans = n % k == 0 ? 0 : 1; Console.WriteLine(ans); Console.Out.Flush(); } } }
[["-", 0, 212, 0, 41, 15, 16, 31, 16, 31, 22], ["-", 0, 212, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 0, 212, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 0, 212, 0, 41, 15, 16, 31, 16, 12, 22]]
8
154
4
using System; namespace atcoderA { class MainClass { public static void Main(string[] args) { int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int N = line[0]; int K = line[1]; Console.WriteLine(N % K == 0 ? 0 : N % K); } } }
using System; namespace atcoderA { class MainClass { public static void Main(string[] args) { int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int N = line[0]; int K = line[1]; Console.WriteLine(N % K == 0 ? 0 : 1); } } }
[["-", 3, 4, 0, 28, 0, 41, 75, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 41, 75, 16, 17, 109], ["-", 3, 4, 0, 28, 0, 41, 75, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
83
4
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int K = int.Parse(s[1]); Console.WriteLine(N % K); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int K = int.Parse(s[1]); Console.WriteLine(N % K == 0 ? 0 : 1); } }
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
83
6
using System; using System.Collections.Generic; using System.Linq; namespace ziyuutyou { class Program { static void Main(string[] args) { var sen = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var mai = sen[0] / sen[1]; var aaa = sen[0] % sen[1]; if (aaa == 0) { Console.WriteLine(0); } else { Console.WriteLine(Math.Abs(aaa)); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace ziyuutyou { class Program { static void Main(string[] args) { var sen = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var mai = sen[0] / sen[1]; var aaa = sen[0] % sen[1]; if (aaa == 0) { Console.WriteLine(0); } else { Console.WriteLine(Math.Abs(1)); } } } }
[["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203]]
8
115
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; namespace AtCoder { class Program { static void Main() { var raw = ReadLine().Split().Select(int.Parse).ToArray(); var N = raw[0]; var K = raw[1]; WriteLine(N % K == 0 ? 1 : 0); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; namespace AtCoder { class Program { static void Main() { var raw = ReadLine().Split().Select(int.Parse).ToArray(); var N = raw[0]; var K = raw[1]; WriteLine(N % K == 0 ? 0 : 1); } } }
[["-", 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, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
87
4
using System; using System.Collections.Generic; using System.Linq; namespace ABC109C { static class MainClass { public static void Main(string[] args) { string[] input1 = Console.ReadLine().Split(' '); int N = int.Parse(input1[0]); int X = int.Parse(input1[1]); string[] input2 = Console.ReadLine().Split(' '); var x = new List<int>(); for (int i = 0; i < N; i++) { x.Add(int.Parse(input2[i])); } x.Sort(); for (int i = 0; i < N - 1; i++) { x[i + 1] = Gcd(Math.Abs(x[i] - X), Math.Abs(x[i + 1] - X)) + X; } Console.WriteLine(x[N - 1] - X); } public static int Gcd(int a, int b) { int tmp; // a<bにする if (a >= b) { tmp = a; a = b; b = tmp; } if (a == 0) { return b; } tmp = a; a = b % a; b = tmp; return Gcd(a, b); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC109C { static class MainClass { public static void Main(string[] args) { string[] input1 = Console.ReadLine().Split(' '); int N = int.Parse(input1[0]); int X = int.Parse(input1[1]); string[] input2 = Console.ReadLine().Split(' '); var x = new List<int>(); for (int i = 0; i < N; i++) { x.Add(int.Parse(input2[i])); } x.Sort(); for (int i = 0; i < N - 1; i++) { x[i + 1] = Gcd(Math.Abs(x[i] - X), Math.Abs(x[i + 1] - X)) + X; } Console.WriteLine(Math.Abs(x[N - 1] - X)); } public static int Gcd(int a, int b) { int tmp; // a<bにする if (a >= b) { tmp = a; a = b; b = tmp; } if (a == 0) { return b; } tmp = a; a = b % a; b = tmp; return Gcd(a, b); } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
286
5
using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string[] inputs1 = Console.ReadLine().Split(' '); int n = int.Parse(inputs1[0]); int x = int.Parse(inputs1[1]); string[] inputs2 = Console.ReadLine().Split(' '); int[] x_Rpos = new int[n]; for (int i = 0; i < inputs2.Length; i++) { x_Rpos[i] = int.Parse(inputs2[i]) - x; } Array.Sort(x_Rpos); int[] nums = new int[n - 1]; for (int i = 1; i < n; i++) { nums[i - 1] = G(x_Rpos[0], x_Rpos[i]); } Array.Sort(nums); Array.Reverse(nums); int result = 0; for (int i = 0; i < nums.Length; i++) { if (Judge(x_Rpos, nums[i])) { result = i; break; } } if (n == 1) Console.WriteLine(x_Rpos[0]); else Console.WriteLine(nums[result]); Console.ReadLine(); } static int G(int i1, int i2) { if (i2 % i1 != 0) return G(i2 % i1, i1); else return i1; } static bool Judge(int[] array, int d) { for (int i = 0; i < array.Length; i++) { if (array[i] % d != 0) return false; } return true; } } }
using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string[] inputs1 = Console.ReadLine().Split(' '); int n = int.Parse(inputs1[0]); int x = int.Parse(inputs1[1]); string[] inputs2 = Console.ReadLine().Split(' '); int[] x_Rpos = new int[n]; for (int i = 0; i < inputs2.Length; i++) { x_Rpos[i] = Math.Abs(int.Parse(inputs2[i]) - x); } Array.Sort(x_Rpos); int[] nums = new int[n - 1]; for (int i = 1; i < n; i++) { nums[i - 1] = G(x_Rpos[0], x_Rpos[i]); } Array.Sort(nums); Array.Reverse(nums); int result = 0; for (int i = 0; i < nums.Length; i++) { if (Judge(x_Rpos, nums[i])) { result = i; break; } } if (n == 1) Console.WriteLine(x_Rpos[0]); else Console.WriteLine(nums[result]); Console.ReadLine(); } static int G(int i1, int i2) { if (i2 % i1 != 0) return G(i2 % i1, i1); else return i1; } static bool Judge(int[] array, int d) { for (int i = 0; i < array.Length; i++) { if (array[i] % d != 0) return false; } return true; } } }
[["+", 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, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
359
5
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm {     class Program     {         static void Main(string[] args)         {             var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int H = l[0], W = l[1]; var a = new int [H][]; for (var i = 0; i < H; i++) { a[i] = Console.ReadLine().Split().Select(int.Parse).ToArray(); } var ans = new List<string>(); for (var i = 0; i < H; i++) { for (var j = 0; j < W; j++) { if (a[i][j] % 2 == 1) { if (j + 1 < W) { a[i][j]--; a[i][j + 1]++; ans.Add($"{i} {j} {i} {j+1}"); } else if (i + 1 < H) { a[i][j]--; a[i + 1][j]++; ans.Add($"{i} {j} {i+1} {j}"); } } } } Console.WriteLine(ans.Count); foreach (var an in ans) { Console.WriteLine(an); }         }     } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm {     class Program     {         static void Main(string[] args)         {             var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int H = l[0], W = l[1]; var a = new int [H][]; for (var i = 0; i < H; i++) { a[i] = Console.ReadLine().Split().Select(int.Parse).ToArray(); } var ans = new List<string>(); for (var i = 0; i < H; i++) { for (var j = 0; j < W; j++) { if (a[i][j] % 2 == 1) { if (j + 1 < W) { a[i][j]--; a[i][j + 1]++; ans.Add($"{i+1} {j+1} {i+1} {j+2}"); } else if (i + 1 < H) { a[i][j]--; a[i + 1][j]++; ans.Add($"{i+1} {j+1} {i+2} {j+1}"); } } } } Console.WriteLine(ans.Count); foreach (var an in ans) { Console.WriteLine(an); }         }     } }
[["+", 0, 28, 0, 283, 0, 284, 0, 16, 17, 72], ["+", 0, 28, 0, 283, 0, 284, 0, 16, 12, 203], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 12, 203]]
8
328
16
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } } class Program { static int h; static int w; static bool isOdd(int x) { return (x & 1) == 1; } static Tuple<int, int> nextPos(int hh, int ww) { int nh = 0, nw = 0; if (isOdd(hh)) { if (ww < w) { nh = hh; nw = ww + 1; } else { nh = hh + 1; nw = ww; } } else { if (ww > 1) { nh = hh; nw = ww - 1; } else { nh = hh + 1; nw = ww; } } return Tuple.Create(nh, nw); } public static void Main() { var tmp = ReadIntArray(); h = tmp[0]; w = tmp[1]; int[][] d = new int [h][]; for (int i = 0; i < h; i++) d[i] = ReadIntArray(); var ls = new List<Tuple<int, int, int, int>>(); int hh = 1, ww = 1; while (hh <= h) { var t = nextPos(hh, ww); int nh = t.Item1, nw = t.Item2; if (isOdd(d[hh - 1][ww - 1])) { ls.Add(Tuple.Create(hh, ww, nh, nw)); d[hh - 1][ww - 1]--; d[nh - 1][nw - 1]++; } hh = nh; ww = nw; } WriteLine(ls.Count()); foreach (var t in ls) { WriteLine($"{t.Item1} {t.Item2} {t.Item3} {t.Item4}"); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } } class Program { static int h; static int w; static bool isOdd(int x) { return (x & 1) == 1; } static Tuple<int, int> nextPos(int hh, int ww) { int nh = 0, nw = 0; if (isOdd(hh)) { if (ww < w) { nh = hh; nw = ww + 1; } else { nh = hh + 1; nw = ww; } } else { if (ww > 1) { nh = hh; nw = ww - 1; } else { nh = hh + 1; nw = ww; } } return Tuple.Create(nh, nw); } public static void Main() { var tmp = ReadIntArray(); h = tmp[0]; w = tmp[1]; int[][] d = new int [h][]; for (int i = 0; i < h; i++) d[i] = ReadIntArray(); var ls = new List<Tuple<int, int, int, int>>(); int hh = 1, ww = 1; while (hh <= h) { var t = nextPos(hh, ww); int nh = t.Item1, nw = t.Item2; if (nh <= h && isOdd(d[hh - 1][ww - 1])) { ls.Add(Tuple.Create(hh, ww, nh, nw)); d[hh - 1][ww - 1]--; d[nh - 1][nw - 1]++; } hh = nh; ww = nw; } WriteLine(ls.Count()); foreach (var t in ls) { WriteLine($"{t.Item1} {t.Item2} {t.Item3} {t.Item4}"); } } }
[["+", 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, 52, 8, 196, 0, 57, 15, 16, 17, 98]]
8
456
4
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 int h = int.Parse(input[0]); int w = int.Parse(input[1]); int[,] matrix = new int[h, w]; //行列 for (int i = 0; i < h; i++) { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); for (int j = 0; j < w; j++) matrix[i, j] = nums[j]; } int moveTime = 0; int pickUp = 0; //持っている時1 for (int i = 0; i < h; i++) //全部の行を調べる { if (i % 2 == 0) //偶数行の時 { for (int j = 0; j < w; j++) //全部の列を調べる { if (matrix[i, j] % 2 == 1) { if (pickUp == 1) pickUp = 0; else pickUp = 1; } if (pickUp == 1) { if (j + 1 < w) moveTime++; else if (i + 1 < h) moveTime++; } } } if (i % 2 == 1) //奇数行の時 { for (int j = w - 1; j >= 0; j--) //全部の列を調べる { if (matrix[i, j] % 2 == 1) { if (pickUp == 1) pickUp = 0; else pickUp = 1; } if (pickUp == 1) { if (j - 1 >= 0) moveTime++; else if (i + 1 < h) moveTime++; } } } } Console.WriteLine(moveTime); for (int i = 0; i < h; i++) //全部の行を再び調べる { if (i % 2 == 0) //偶数行の時 { for (int j = 0; j < w; j++) //全部の列を調べる { if (matrix[i, j] % 2 == 1) { if (pickUp == 1) pickUp = 0; else pickUp = 1; } if (pickUp == 1) { if (j + 1 < w) Console.WriteLine(((int)i + 1) + " " + ((int)j + 1) + " " + ((int)i + 1) + " " + ((int)j + 2)); else if (i + 1 < h) Console.WriteLine(((int)i + 1) + " " + ((int)j + 1) + " " + ((int)i + 2) + " " + ((int)j + 1)); } } } if (i % 2 == 1) //奇数行の時 { for (int j = w - 1; j >= 0; j--) //全部の列を調べる { if (matrix[i, j] % 2 == 1) { if (pickUp == 1) pickUp = 0; else pickUp = 1; } if (pickUp == 1) { if (j - 1 >= 0) Console.WriteLine(((int)i + 1) + " " + ((int)j + 1) + " " + ((int)i + 1) + " " + j); else if (i + 1 < h) Console.WriteLine(((int)i + 1) + " " + ((int)j + 1) + " " + ((int)i + 2) + " " + ((int)j + 1)); } } } } } }
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 int h = int.Parse(input[0]); int w = int.Parse(input[1]); int[,] matrix = new int[h, w]; //行列 for (int i = 0; i < h; i++) { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); for (int j = 0; j < w; j++) matrix[i, j] = nums[j]; } int moveTime = 0; int pickUp = 0; //持っている時1 for (int i = 0; i < h; i++) //全部の行を調べる { if (i % 2 == 0) //偶数行の時 { for (int j = 0; j < w; j++) //全部の列を調べる { if (matrix[i, j] % 2 == 1) { if (pickUp == 1) pickUp = 0; else pickUp = 1; } if (pickUp == 1) { if (j + 1 < w) moveTime++; else if (i + 1 < h) moveTime++; } } } if (i % 2 == 1) //奇数行の時 { for (int j = w - 1; j >= 0; j--) //全部の列を調べる { if (matrix[i, j] % 2 == 1) { if (pickUp == 1) pickUp = 0; else pickUp = 1; } if (pickUp == 1) { if (j - 1 >= 0) moveTime++; else if (i + 1 < h) moveTime++; } } } } Console.WriteLine(moveTime); pickUp = 0; for (int i = 0; i < h; i++) //全部の行を再び調べる { if (i % 2 == 0) //偶数行の時 { for (int j = 0; j < w; j++) //全部の列を調べる { if (matrix[i, j] % 2 == 1) { if (pickUp == 1) pickUp = 0; else pickUp = 1; } if (pickUp == 1) { if (j + 1 < w) Console.WriteLine(((int)i + 1) + " " + ((int)j + 1) + " " + ((int)i + 1) + " " + ((int)j + 2)); else if (i + 1 < h) Console.WriteLine(((int)i + 1) + " " + ((int)j + 1) + " " + ((int)i + 2) + " " + ((int)j + 1)); } } } if (i % 2 == 1) //奇数行の時 { for (int j = w - 1; j >= 0; j--) //全部の列を調べる { if (matrix[i, j] % 2 == 1) { if (pickUp == 1) pickUp = 0; else pickUp = 1; } if (pickUp == 1) { if (j - 1 >= 0) Console.WriteLine(((int)i + 1) + " " + ((int)j + 1) + " " + ((int)i + 1) + " " + j); else if (i + 1 < h) Console.WriteLine(((int)i + 1) + " " + ((int)j + 1) + " " + ((int)i + 2) + " " + ((int)j + 1)); } } } } } }
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
748
4
using System; using System.Linq; namespace Sample { class Sample { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); if (N % 2 == 0) { Console.WriteLine(Math.Pow(N / 2, 2)); } else { Console.WriteLine((N / 2) * (N / 2 - 1)); } } } }
using System; using System.Linq; namespace Sample { class Sample { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); if (N % 2 == 0) { Console.WriteLine(Math.Pow(N / 2, 2)); } else { Console.WriteLine((N / 2) * (N / 2 + 1)); } } } }
[["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72]]
8
89
2
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); // MyDebugger.Test(process, "../TextFile2.txt"); // MyDebugger.MakeTestCase("../TextFile2.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var n = int.Parse(input.ReadLine()); var odd = n / 2; var eve = n / 2; if (n % 2 == 0) odd--; return odd * eve; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); // MyDebugger.Test(process, "../TextFile2.txt"); // MyDebugger.MakeTestCase("../TextFile2.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var n = int.Parse(input.ReadLine()); var odd = n / 2; var eve = n / 2; if (n % 2 == 1) odd++; return odd * eve; } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 68], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29]]
8
163
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var waaaa = new waaaa(); waaaa.Solve(); } } public class waaaa { const int MOD = 1000000007; const long INF = 1 << 61; const int MOD2 = 998244353; Scaner cin = new Scaner(); write cout = new write(); Math2 mmath = new Math2(); public void Solve() { mmath.FactoricalModSet(1000000); //ここから var o = cin.IntM; int N = o[0]; cout.wri((N / 2) * (N + 1) / 2); } public static bool NextPermutation<T>(T[] array, int start, int length) where T : IComparable { int end = start + length - 1; // 範囲が狭すぎる if (end <= start) return false; int last = end; while (true) { int pos = last--; if (array[last].CompareTo(array[pos]) < 0) { int i; for (i = end + 1; array[last].CompareTo(array[--i]) >= 0;) { } T tmp = array[last]; array[last] = array[i]; array[i] = tmp; Array.Reverse(array, pos, end - pos + 1); return true; } if (last == start) // 最後の順列 { Array.Reverse(array, start, end - start); return false; } } // ここに来ることはない throw new Exception("NextPermutation: Fatal error"); } } // b-aで降順 // priority queue class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } public class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 // Nまでの階乗をセットしておく public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = pow(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } // nCr 引数:n r (mod) public long nCr(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } //階乗(O(logN)) 引数:底x n乗 (MOD) public long pow(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } //最大公約数 引数:整数x,y public long GCD(long x, long y) { while (y != 0) { var r = x % y; x = y; y = r; } return x; } //最小公倍数 引数:整数x,y public long LCM(long x, long y) { return x * y / GCD(x, y); } //素因数分解 引数:整数N public Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public List<long> PrimeFactorization2(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } } namespace CompLib.Algorithms { #region BinarySearch public static partial class Algorithm { static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) { var l = 0; var r = a.Count - 1; while (l <= r) { var m = (l + r) / 2; var res = cmp.Compare(a[m], v); if (res < 0 || (res == 0 && !islb)) l = m + 1; else r = m - 1; } return l; } /// <summary> /// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref /// name="v"/> 以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) { return binarySearch(a, v, Comparer<T>.Create(f), true); } /// <summary> /// デフォルトの比較関数に従って,<paramref name="a"/> ///の要素のうち,<paramref name="v"/> ///以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int LowerBound<T>(this IList<T> a, T v) { return binarySearch(a, v, Comparer<T>.Default, true); } /// <summary> /// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref /// name="v"/> 以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) { return binarySearch(a, v, Comparer<T>.Create(cmp), false); } /// <summary> /// デフォルトの比較関数に従って,<paramref name="a"/> ///の要素のうち,<paramref name="v"/> ///より真に大きい要素が現れる最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int UpperBound<T>(this IList<T> a, T v) { return binarySearch(a, v, Comparer<T>.Default, false); } } #endregion } class Scaner { public string Str => Console.ReadLine(); public string[] StrM => Str.Split(' '); public long[] LongM => StrM.Select(long.Parse).ToArray(); public int[] IntM => StrM.Select(int.Parse).ToArray(); public char[] CharM => Str.ToArray(); public long Long1 => LongM[0]; public int Int1 => IntM[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var waaaa = new waaaa(); waaaa.Solve(); } } public class waaaa { const int MOD = 1000000007; const long INF = 1 << 61; const int MOD2 = 998244353; Scaner cin = new Scaner(); write cout = new write(); Math2 mmath = new Math2(); public void Solve() { mmath.FactoricalModSet(1000000); //ここから var o = cin.IntM; int N = o[0]; cout.wri((N / 2) * (N + (N % 2)) / 2); } public static bool NextPermutation<T>(T[] array, int start, int length) where T : IComparable { int end = start + length - 1; // 範囲が狭すぎる if (end <= start) return false; int last = end; while (true) { int pos = last--; if (array[last].CompareTo(array[pos]) < 0) { int i; for (i = end + 1; array[last].CompareTo(array[--i]) >= 0;) { } T tmp = array[last]; array[last] = array[i]; array[i] = tmp; Array.Reverse(array, pos, end - pos + 1); return true; } if (last == start) // 最後の順列 { Array.Reverse(array, start, end - start); return false; } } // ここに来ることはない throw new Exception("NextPermutation: Fatal error"); } } // b-aで降順 // priority queue class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } public class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 // Nまでの階乗をセットしておく public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = pow(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } // nCr 引数:n r (mod) public long nCr(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } //階乗(O(logN)) 引数:底x n乗 (MOD) public long pow(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } //最大公約数 引数:整数x,y public long GCD(long x, long y) { while (y != 0) { var r = x % y; x = y; y = r; } return x; } //最小公倍数 引数:整数x,y public long LCM(long x, long y) { return x * y / GCD(x, y); } //素因数分解 引数:整数N public Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public List<long> PrimeFactorization2(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } } namespace CompLib.Algorithms { #region BinarySearch public static partial class Algorithm { static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) { var l = 0; var r = a.Count - 1; while (l <= r) { var m = (l + r) / 2; var res = cmp.Compare(a[m], v); if (res < 0 || (res == 0 && !islb)) l = m + 1; else r = m - 1; } return l; } /// <summary> /// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref /// name="v"/> 以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) { return binarySearch(a, v, Comparer<T>.Create(f), true); } /// <summary> /// デフォルトの比較関数に従って,<paramref name="a"/> ///の要素のうち,<paramref name="v"/> ///以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int LowerBound<T>(this IList<T> a, T v) { return binarySearch(a, v, Comparer<T>.Default, true); } /// <summary> /// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref /// name="v"/> 以上の要素であるような最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) { return binarySearch(a, v, Comparer<T>.Create(cmp), false); } /// <summary> /// デフォルトの比較関数に従って,<paramref name="a"/> ///の要素のうち,<paramref name="v"/> ///より真に大きい要素が現れる最小のインデックスを取得します. /// </summary> /// <typeparam name="T"><see cref="IList{T}"/> /// の要素の型を指定します.</typeparam> <param /// name="a">対象となるコレクション</param> <param /// name="v">対象となる要素</param> <param name="f"></param> /// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed /// でのインデックス.</returns> <remarks> <paramref name="a"/> /// は比較関数に対して昇順であることを仮定しています.この関数は O(log N) /// で実行されます.</remarks> public static int UpperBound<T>(this IList<T> a, T v) { return binarySearch(a, v, Comparer<T>.Default, false); } } #endregion } class Scaner { public string Str => Console.ReadLine(); public string[] StrM => Str.Split(' '); public long[] LongM => StrM.Select(long.Parse).ToArray(); public int[] IntM => StrM.Select(int.Parse).ToArray(); public char[] CharM => Str.ToArray(); public long Long1 => LongM[0]; public int Int1 => IntM[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
[["-", 0, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 31, 16, 12, 23, 0, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 12, 23, 0, 16, 12, 23, 0, 16, 17, 109], ["+", 12, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 31, 16, 12, 23, 0, 16, 12, 23, 0, 25]]
8
1,660
6
using System; using System.Collections.Generic; using System.Linq; namespace test { class Program { static void Main(string[] args) { string b = Console.ReadLine(); int A = int.Parse(b); int an; an = A / 2 * (A - A / 2) / 2; Console.Write(an); } } }
using System; using System.Collections.Generic; using System.Linq; namespace test { class Program { static void Main(string[] args) { string b = Console.ReadLine(); int A = int.Parse(b); int an; an = A / 2 * (A - A / 2); Console.Write(an); } } }
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
79
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; class Program { static void Main(string[] args) { new Program().Calc(); } Scanner cin; public Program() {} 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 Calc() { cin = new Scanner(); int K = cin.nextInt(); int odd = K / 2 * 2; int even = K - odd; Write(even * odd); } } public static class StringExtension { public static char GetChar1(this string str, int indexOneBase) { return str[indexOneBase - 1]; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; class Program { static void Main(string[] args) { new Program().Calc(); } Scanner cin; public Program() {} 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 Calc() { cin = new Scanner(); int K = cin.nextInt(); int odd = K / 2; int even = K - odd; Write(even * odd); } } public static class StringExtension { public static char GetChar1(this string str, int indexOneBase) { return str[indexOneBase - 1]; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
579
2