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; namespace ConsoleApp7 { class Program { static void Main(string[] args) { int[] at = new int[4]; int n = int.Parse(System.Console.ReadLine()); for (int i = 0; i < n; i++) { string a = System.Console.ReadLine(); switch (a) { case "AC": at[0] += 1; break; case "TLE": at[1] += 1; break; case "WA": at[2] += 1; break; case "RE": at[3] += 1; break; } } string p = "AC x" + at[0]; System.Console.WriteLine(p); p = "WA x" + at[2]; System.Console.WriteLine(p); p = "TLE x" + at[1]; System.Console.WriteLine(p); p = "RE x" + at[3]; System.Console.WriteLine(p); } } }
using System; namespace ConsoleApp7 { class Program { static void Main(string[] args) { int[] at = new int[4]; int n = int.Parse(System.Console.ReadLine()); for (int i = 0; i < n; i++) { string a = System.Console.ReadLine(); switch (a) { case "AC": at[0] += 1; break; case "TLE": at[1] += 1; break; case "WA": at[2] += 1; break; case "RE": at[3] += 1; break; } } string p = "AC x " + at[0]; System.Console.WriteLine(p); p = "WA x " + at[2]; System.Console.WriteLine(p); p = "TLE x " + at[1]; System.Console.WriteLine(p); p = "RE x " + at[3]; System.Console.WriteLine(p); } } }
[["-", 0, 200, 0, 212, 0, 16, 31, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 16, 31, 5, 0, 222], ["-", 0, 1, 0, 11, 12, 16, 31, 5, 0, 222], ["+", 0, 1, 0, 11, 12, 16, 31, 5, 0, 222]]
8
219
8
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class Util { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int N = ri(); List<string> ss = new List<string>(); for (int i = 0; i < N; i++) ss.Add(rs()); // int ACcnt = 0; // int WAcnt = 0; // int TLEcnt = 0; // int REcnt = 0; Dictionary<string, int> dic = new Dictionary<string, int>() { { "AC", 0 }, { "WA", 0 }, { "TLE", 0 }, { "RE", 0 }, }; foreach (string s in ss) dic[s]++; string ans = ""; foreach (string key in dic.Keys) ans += key + "x" + dic[key] + "\r\n"; Console.WriteLine(ans); Console.ReadLine(); } 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 Util { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int N = ri(); List<string> ss = new List<string>(); for (int i = 0; i < N; i++) ss.Add(rs()); // int ACcnt = 0; // int WAcnt = 0; // int TLEcnt = 0; // int REcnt = 0; Dictionary<string, int> dic = new Dictionary<string, int>() { { "AC", 0 }, { "WA", 0 }, { "TLE", 0 }, { "RE", 0 }, }; foreach (string s in ss) dic[s]++; string ans = ""; foreach (string key in dic.Keys) ans += key + " x " + dic[key] + "\r\n"; Console.WriteLine(ans); Console.ReadLine(); } 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)); } }
[["-", 12, 16, 31, 16, 31, 16, 12, 5, 0, 222], ["+", 12, 16, 31, 16, 31, 16, 12, 5, 0, 222]]
8
441
2
using System; namespace Atcoder001 { class Program { static void Main(string[] args) { int amount = int.Parse(Console.ReadLine()); string[] answers = new string[amount]; for (int i = 0; i < amount; i++) { answers[i] = Console.ReadLine(); } int[] count = new int[4]; foreach (string answer in answers) { if (answer.Equals("AC")) { count[0] += 1; } else if (answer.Equals("WA")) { count[1] += 1; } else if (answer.Equals("TLE")) { count[2] += 1; } else if (answer.Equals("RE")) { count[3] += 1; } } Console.WriteLine("AC x " + count[0]); Console.WriteLine("WA x " + count[1]); Console.WriteLine("TLE x " + count[2]); Console.WriteLine("WA x " + count[3]); } } }
using System; namespace Atcoder001 { class Program { static void Main(string[] args) { int amount = int.Parse(Console.ReadLine()); string[] answers = new string[amount]; for (int i = 0; i < amount; i++) { answers[i] = Console.ReadLine(); } int[] count = new int[4]; foreach (string answer in answers) { if (answer.Equals("AC")) { count[0] += 1; } else if (answer.Equals("WA")) { count[1] += 1; } else if (answer.Equals("TLE")) { count[2] += 1; } else if (answer.Equals("RE")) { count[3] += 1; } } Console.WriteLine("AC x " + count[0]); Console.WriteLine("WA x " + count[1]); Console.WriteLine("TLE x " + count[2]); Console.WriteLine("RE x " + count[3]); } } }
[["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222]]
8
233
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp5 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int ac = 0; int wa = 0; int tle = 0; int re = 0; for (int i = 0; i < N; i++) { String S = Console.ReadLine(); if (S.Equals("AC")) { ac++; } else if (S.Equals("WA")) { wa++; } else if (S.Equals("TLE")) { tle++; } else if (S.Equals("re")) { re++; } } Console.WriteLine("AC x " + ac); Console.WriteLine("WA x " + wa); Console.WriteLine("TLE x " + tle); Console.WriteLine("RE x " + re); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp5 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int ac = 0; int wa = 0; int tle = 0; int re = 0; for (int i = 0; i < N; i++) { String S = Console.ReadLine(); if (S.Equals("AC")) { ac++; } else if (S.Equals("WA")) { wa++; } else if (S.Equals("TLE")) { tle++; } else if (S.Equals("RE")) { re++; } } Console.WriteLine("AC x " + ac); Console.WriteLine("WA x " + wa); Console.WriteLine("TLE x " + tle); Console.WriteLine("RE x " + re); } } }
[["-", 15, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 15, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
216
2
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder.Abc { class QuestionB { public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int AC = 0, WA = 0, TLE = 0, RE = 0; for (int i = 0; i < N; i++) { string S = Console.ReadLine(); if (S == "AC") { AC++; } if (S == "WA") { WA++; } if (S == "TLE") { TLE++; } if (S == "RE") { RE++; } } Console.WriteLine("AC × " + AC); Console.WriteLine("WA × " + WA); Console.WriteLine("TLE × " + TLE); Console.WriteLine("RE × " + RE); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder.Abc { class QuestionB { public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int AC = 0, WA = 0, TLE = 0, RE = 0; for (int i = 0; i < N; i++) { string S = Console.ReadLine(); if (S == "AC") { AC++; } if (S == "WA") { WA++; } if (S == "TLE") { TLE++; } if (S == "RE") { RE++; } } Console.WriteLine("AC x " + AC); Console.WriteLine("WA x " + WA); Console.WriteLine("TLE x " + TLE); Console.WriteLine("RE x " + RE); } } }
[["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222]]
8
189
8
using System; using System.Linq; namespace AtCoderMake.ABC173 { class ABC173B { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); int ac = 0; int wa = 0; int lte = 0; int re = 0; for (int i = 0; i < n; i++) { string s = Console.ReadLine(); if (s == "AC") { ac++; } else if (s == "WA") { wa++; } else if (s == "LTE") { lte++; } else { re++; } } Console.WriteLine("AC x " + ac); Console.WriteLine("WA x " + wa); Console.WriteLine("LTE x " + lte); Console.WriteLine("RE x " + re); } } }
using System; using System.Linq; namespace AtCoderMake.ABC173 { class ABC173B { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); int ac = 0; int wa = 0; int lte = 0; int re = 0; for (int i = 0; i < n; i++) { string s = Console.ReadLine(); if (s == "AC") { ac++; } else if (s == "WA") { wa++; } else if (s == "TLE") { lte++; } else { re++; } } Console.WriteLine("AC x " + ac); Console.WriteLine("WA x " + wa); Console.WriteLine("TLE x " + lte); Console.WriteLine("RE x " + re); } } }
[["-", 75, 57, 75, 57, 15, 16, 12, 5, 0, 222], ["+", 75, 57, 75, 57, 15, 16, 12, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222]]
8
179
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var N = GetLongNum(); var list = new List<string>(); for (int i = 0; i < N; i++) { list.Add(GetString()); } var AC = list.Count(x => x == "AC"); var WA = list.Count(x => x == "WA"); var TLE = list.Count(x => x == "TLE"); var RE = list.Count(x => x == "RE"); Console.WriteLine("AC × " + AC); Console.WriteLine("WA × " + WA); Console.WriteLine("TLE × " + +TLE); Console.WriteLine("RE × " + RE); } private static long[] GetLongNumArray() { var input = Console.ReadLine().Split(' '); return input.Select(x => long.Parse(x)).ToArray(); } private static long GetLongNum() { return long.Parse(Console.ReadLine()); } private static string[] GetStringArray() { return Console.ReadLine().Split(' '); } private static string GetString() { return Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var N = GetLongNum(); var list = new List<string>(); for (int i = 0; i < N; i++) { list.Add(GetString()); } var AC = list.Count(x => x == "AC"); var WA = list.Count(x => x == "WA"); var TLE = list.Count(x => x == "TLE"); var RE = list.Count(x => x == "RE"); Console.WriteLine("AC x " + AC); Console.WriteLine("WA x " + WA); Console.WriteLine("TLE x " + +TLE); Console.WriteLine("RE x " + RE); } private static long[] GetLongNumArray() { var input = Console.ReadLine().Split(' '); return input.Select(x => long.Parse(x)).ToArray(); } private static long GetLongNum() { return long.Parse(Console.ReadLine()); } private static string[] GetStringArray() { return Console.ReadLine().Split(' '); } private static string GetString() { return Console.ReadLine(); } } }
[["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222]]
8
302
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int line = int.Parse(Console.ReadLine()); int AC = 0; int WA = 0; int TLE = 0; int RE = 0; for (int i = 0; i < line; i++) { string line2 = Console.ReadLine(); if (line2 == "AC") { AC++; } else if (line2 == "WA") { WA++; } else if (line2 == "TLE") { TLE++; } else if (line2 == "RE") { RE++; } } Console.WriteLine("AC × " + AC); Console.WriteLine("WA × " + WA); Console.WriteLine("TLE × " + TLE); Console.WriteLine("RE × " + RE); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int line = int.Parse(Console.ReadLine()); int AC = 0; int WA = 0; int TLE = 0; int RE = 0; for (int i = 0; i < line; i++) { string line2 = Console.ReadLine(); if (line2 == "AC") { AC++; } else if (line2 == "WA") { WA++; } else if (line2 == "TLE") { TLE++; } else if (line2 == "RE") { RE++; } } Console.WriteLine("AC x " + AC); Console.WriteLine("WA x " + WA); Console.WriteLine("TLE x " + TLE); Console.WriteLine("RE x " + RE); } }
[["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222]]
8
200
8
using System; namespace ABC173 { class Program { static void Main(string[] args) { b(); } public static void b() { int n = int.Parse(Console.ReadLine()); int ac = 0; int wa = 0; int tle = 0; int re = 0; for (int i = 0; i < n; i++) { string s = Console.ReadLine(); if (s == "AC") ac++; else if (s == "WA") wa++; else if (s == "TLE") tle++; else re++; } Console.WriteLine("AC * {0}", ac); Console.WriteLine("WA * {0}", wa); Console.WriteLine("TLE * {0}", tle); Console.WriteLine("RE * {0}", re); } } }
using System; namespace ABC173 { class Program { static void Main(string[] args) { b(); } public static void b() { int n = int.Parse(Console.ReadLine()); int ac = 0; int wa = 0; int tle = 0; int re = 0; for (int i = 0; i < n; i++) { string s = Console.ReadLine(); if (s == "AC") ac++; else if (s == "WA") wa++; else if (s == "TLE") tle++; else re++; } Console.WriteLine("AC x {0}", ac); Console.WriteLine("WA x {0}", wa); Console.WriteLine("TLE x {0}", tle); Console.WriteLine("RE x {0}", re); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
176
8
using System; class Program { static void Main(string[] args) { int ac = 0, wa = 0, tle = 0, re = 0; for (int i = 0, n = int.Parse(Console.ReadLine()); i < n; i++) { switch (Console.ReadLine()) { case "AC": ac++; break; case "WA": wa++; break; case "TLE": tle++; break; case "RE": re++; break; } } Console.WriteLine("AC x " + ac); Console.WriteLine("WA x " + wa); Console.WriteLine("TLE x" + tle); Console.WriteLine("RE x " + re); } }
using System; class Program { static void Main(string[] args) { int ac = 0, wa = 0, tle = 0, re = 0; for (int i = 0, n = int.Parse(Console.ReadLine()); i < n; i++) { switch (Console.ReadLine()) { case "AC": ac++; break; case "WA": wa++; break; case "TLE": tle++; break; case "RE": re++; break; } } Console.WriteLine("AC x " + ac); Console.WriteLine("WA x " + wa); Console.WriteLine("TLE x " + tle); Console.WriteLine("RE x " + re); } }
[["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222]]
8
158
2
using System; using System.Collections.Generic; using System.Linq; namespace atcoder173 { class Program { static void Main(string[] args) { var list = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var H = list[0]; // 行数 var W = list[1]; // 列数 var K = list[2]; // 期待する黒の個数 string[,] field = new string[H, W]; for (int i = 0; i < H; i++) { var buf = Console.ReadLine(); for (int j = 0; j < W; j++) field[i, j] = buf[j].ToString(); } int ans = 0; // rowBitCounter // どの行を選ぶか全ての組み合わせ数を定義する // 行を選ぶ選ばない含め全種類を試すため(1 << H)通り // 例えばHが2ならどの行も選ばない、0行を選ぶ、1行を選ぶ、0と1行を選ぶで4通り for (int rowBitCounter = 0; rowBitCounter < 1 << H; rowBitCounter++) { var selectedRowBitNums = new List<int>(); // どの行を赤く塗りつぶすかを決めて、塗りつぶす行をselectedRowBitNumsに追加する // (1 << i)がBitでの行を表している // 例えばHが2なら(1 << // i)が01,10の2通りでこれは0列目,1列目を表す(iがちょうど列番号になる) // rowBitCounterはどの行を選ぶかが決まるためrowBitCounterが0の時は下1桁は0でどの行も選ばない // rowBitCounterが1の時は下1桁が1なので、下1桁が1である01(0列目)が選ばれ、0列目(i)がselectedRowBitNumsに格納される for (int i = 0; i < H; i++) { if ((rowBitCounter & (1 << i)) != 0) { selectedRowBitNums.Add(i); } } // columnBitCounter // どの列を選ぶか全ての組み合わせ数を定義する // 列を選ぶ選ばない含め全種類を試すため(1 << W)通り for (int columnBitCounter = 0; columnBitCounter < 1 << W; columnBitCounter++) { var selectedColumnBitNums = new List<int>(); // どの列を赤く塗りつぶすかを決めて、塗りつぶす列をselectedRowBitNumsに追加する // (1 << i)がBitでの列を表している for (int i = 0; i < W; i++) { if ((columnBitCounter & (1 << i)) != 0) { selectedColumnBitNums.Add(i); } } var fieldForCalculation = (string[,])field.Clone(); // 選択した行番号は赤で塗りつぶすためrで置き換える foreach (var v in selectedRowBitNums) { for (int i = 0; i < W; i++) { fieldForCalculation[v, i] = "r"; } } foreach (var v in selectedColumnBitNums) { for (int i = 0; i < H; i++) { fieldForCalculation[i, v] = "r"; } } int blackNum = 0; for (int i = 0; i < field.GetLength(0); i++) { for (int j = 0; j < field.GetLength(1); j++) { if (field[i, j] == "#") blackNum++; } } if (blackNum == K) ans++; } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace atcoder173 { class Program { static void Main(string[] args) { var list = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var H = list[0]; // 行数 var W = list[1]; // 列数 var K = list[2]; // 期待する黒の個数 string[,] field = new string[H, W]; for (int i = 0; i < H; i++) { var buf = Console.ReadLine(); for (int j = 0; j < W; j++) { field[i, j] = buf[j].ToString(); } } int ans = 0; // rowBitCounter // どの行を選ぶか全ての組み合わせ数を定義する // 行を選ぶ選ばない含め全種類を試すため(1 << H)通り // 例えばHが2ならどの行も選ばない、0行を選ぶ、1行を選ぶ、0と1行を選ぶで4通り for (int rowBitCounter = 0; rowBitCounter < 1 << H; rowBitCounter++) { var selectedRowBitNums = new List<int>(); // どの行を赤く塗りつぶすかを決めて、塗りつぶす行をselectedRowBitNumsに追加する // (1 << i)がBitでの行を表している // 例えばHが2なら(1 << // i)が01,10の2通りでこれは0列目,1列目を表す(iがちょうど列番号になる) // rowBitCounterはどの行を選ぶかが決まるためrowBitCounterが0の時は下1桁は0でどの行も選ばない // rowBitCounterが1の時は下1桁が1なので、下1桁が1である01(0列目)が選ばれ、0列目(i)がselectedRowBitNumsに格納される for (int i = 0; i < H; i++) { if ((rowBitCounter & (1 << i)) != 0) { selectedRowBitNums.Add(i); } } // columnBitCounter // どの列を選ぶか全ての組み合わせ数を定義する // 列を選ぶ選ばない含め全種類を試すため(1 << W)通り for (int columnBitCounter = 0; columnBitCounter < 1 << W; columnBitCounter++) { var selectedColumnBitNums = new List<int>(); // どの列を赤く塗りつぶすかを決めて、塗りつぶす列をselectedRowBitNumsに追加する // (1 << i)がBitでの列を表している for (int i = 0; i < W; i++) { if ((columnBitCounter & (1 << i)) != 0) { selectedColumnBitNums.Add(i); } } var fieldForCalculation = (string[,])field.Clone(); // 選択した行番号は赤で塗りつぶすためrで置き換える foreach (var v in selectedRowBitNums) { for (int i = 0; i < W; i++) { fieldForCalculation[v, i] = "r"; } } foreach (var v in selectedColumnBitNums) { for (int i = 0; i < H; i++) { fieldForCalculation[i, v] = "r"; } } int blackNum = 0; for (int i = 0; i < fieldForCalculation.GetLength(0); i++) { for (int j = 0; j < fieldForCalculation.GetLength(1); j++) { if (fieldForCalculation[i, j] == "#") blackNum++; } } if (blackNum == K) ans++; } } Console.WriteLine(ans); } } }
[["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22]]
8
485
8
using System; class program { static void Main() { var vals = Console.ReadLine().Split(' '); var H = int.Parse(vals[0]); var W = int.Parse(vals[1]); var K = int.Parse(vals[2]); var grid = new char [H][]; for (int y = 0; y < H; y++) { grid[y] = Console.ReadLine().ToCharArray(); } int ans = 0, count; for (int i = 0; i < (1 << H); i++) { for (int j = 0; j < (1 << W); j++) { count = 0; for (int x = 0; x < W; x++) { for (int y = 0; y < H; y++) { if (((i >> x) & 1) == 0 && ((j >> y) & 1) == 0 && grid[x][y] == '#') count++; } } if (count == K) ans++; } } Console.WriteLine(ans); } }
using System; class program { static void Main() { var vals = Console.ReadLine().Split(' '); var H = int.Parse(vals[0]); var W = int.Parse(vals[1]); var K = int.Parse(vals[2]); var grid = new char [H][]; for (int i = 0; i < H; i++) { grid[i] = Console.ReadLine().ToCharArray(); } int ans = 0, count; for (int i = 0; i < (1 << H); i++) { for (int j = 0; j < (1 << W); j++) { count = 0; for (int x = 0; x < H; x++) { for (int y = 0; y < W; y++) { if (((i >> x) & 1) == 0 && ((j >> y) & 1) == 0 && grid[x][y] == '#') count++; } } if (count == K) ans++; } } Console.WriteLine(ans); } }
[["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22]]
8
251
12
using System; using System.Collections.Generic; namespace abc173_c { class Program { static void Main(string[] args) { var H = CIn.ReadInt(); var W = CIn.ReadInt(); var K = CIn.ReadInt(); var c = CIn.ReadStringArray(W); var ans = 0; for (int bit = 0; bit < Math.Pow(2, H); bit++) { for (int bit2 = 0; bit2 < Math.Pow(2, W); bit2++) { var x = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if ((bit >> i & 1) == 0 && (bit2 >> j & 1) == 0 && c[i][j] == '#') { x += 1; } } } if (x == K) { ans += 1; } } } Console.WriteLine(ans); } } class CIn { private static readonly Queue<string> fieldBuffer = new Queue<string>(); public static string Read() { if (fieldBuffer.Count == 0) { foreach (var field in Console.ReadLine().Split()) { fieldBuffer.Enqueue(field); } } return fieldBuffer.Dequeue(); } public static int ReadInt() => int.Parse(Read()); public static long ReadLong() => long.Parse(Read()); public static double ReadDouble() => double.Parse(Read()); public static string[] ReadStringArray(long n) { var array = new string[n]; for (var i = 0; i < n; i++) { array[i] = Read(); } return array; } public static int[] ReadIntArray(long n) { var array = new int[n]; for (var i = 0; i < n; i++) { array[i] = ReadInt(); } return array; } public static long[] ReadLongArray(long n) { var array = new long[n]; for (var i = 0; i < n; i++) { array[i] = ReadLong(); } return array; } public static double[] ReadDoubleArray(long n) { var array = new double[n]; for (var i = 0; i < n; i++) { array[i] = ReadDouble(); } return array; } } }
using System; using System.Collections.Generic; namespace abc173_c { class Program { static void Main(string[] args) { var H = CIn.ReadInt(); var W = CIn.ReadInt(); var K = CIn.ReadInt(); var c = CIn.ReadStringArray(H); var ans = 0; for (int bit = 0; bit < Math.Pow(2, H); bit++) { for (int bit2 = 0; bit2 < Math.Pow(2, W); bit2++) { var x = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if ((bit >> i & 1) == 0 && (bit2 >> j & 1) == 0 && c[i][j] == '#') { x += 1; } } } if (x == K) { ans += 1; } } } Console.WriteLine(ans); } } class CIn { private static readonly Queue<string> fieldBuffer = new Queue<string>(); public static string Read() { if (fieldBuffer.Count == 0) { foreach (var field in Console.ReadLine().Split()) { fieldBuffer.Enqueue(field); } } return fieldBuffer.Dequeue(); } public static int ReadInt() => int.Parse(Read()); public static long ReadLong() => long.Parse(Read()); public static double ReadDouble() => double.Parse(Read()); public static string[] ReadStringArray(long n) { var array = new string[n]; for (var i = 0; i < n; i++) { array[i] = Read(); } return array; } public static int[] ReadIntArray(long n) { var array = new int[n]; for (var i = 0; i < n; i++) { array[i] = ReadInt(); } return array; } public static long[] ReadLongArray(long n) { var array = new long[n]; for (var i = 0; i < n; i++) { array[i] = ReadLong(); } return array; } public static double[] ReadDoubleArray(long n) { var array = new double[n]; for (var i = 0; i < n; i++) { array[i] = ReadDouble(); } return array; } } }
[["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22]]
8
527
2
using System; using CompLib.Util; public class Program { public void Solve() { var sc = new Scanner(); int h = sc.NextInt(); int w = sc.NextInt(); int k = sc.NextInt(); string[] c = new string[h]; for (int i = 0; i < h; i++) { c[i] = sc.Next(); } int lR = 1 << h; int lC = 1 << w; int ans = 0; for (int i = 0; i < lR; i++) { for (int j = 0; j < lC; j++) { int cnt = 0; for (int l = 0; l < h; l++) { for (int m = 0; m < w; m++) { if (c[l][m] == '#' && (i & (1 << l)) == 0 && (j & (1 << l)) == 0) { cnt++; } } } if (cnt == k) ans++; } } Console.WriteLine(ans); } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { if (_index >= _line.Length) { string s; do { s = Console.ReadLine(); } while (s.Length == 0); _line = s.Split(Separator); _index = 0; } return _line[_index++]; } public string ReadLine() { _index = _line.Length; return Console.ReadLine(); } 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() { string s = Console.ReadLine(); _line = s.Length == 0 ? new string[0] : s.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 CompLib.Util; public class Program { public void Solve() { var sc = new Scanner(); int h = sc.NextInt(); int w = sc.NextInt(); int k = sc.NextInt(); string[] c = new string[h]; for (int i = 0; i < h; i++) { c[i] = sc.Next(); } int lR = 1 << h; int lC = 1 << w; int ans = 0; for (int i = 0; i < lR; i++) { for (int j = 0; j < lC; j++) { int cnt = 0; for (int l = 0; l < h; l++) { for (int m = 0; m < w; m++) { if (c[l][m] == '#' && (i & (1 << l)) == 0 && (j & (1 << m)) == 0) { cnt++; } } } if (cnt == k) ans++; } } Console.WriteLine(ans); } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { if (_index >= _line.Length) { string s; do { s = Console.ReadLine(); } while (s.Length == 0); _line = s.Split(Separator); _index = 0; } return _line[_index++]; } public string ReadLine() { _index = _line.Length; return Console.ReadLine(); } 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() { string s = Console.ReadLine(); _line = s.Length == 0 ? new string[0] : s.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(); } }
[["-", 31, 23, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 12, 22]]
8
624
2
using System; using System.Linq; namespace abc173c { class Program { static void Main(string[] args) { var ln1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var H = ln1[0]; var W = ln1[1]; var K = ln1[2]; var cells = Enumerable.Repeat(0, H).Select(x => Console.ReadLine()).ToArray(); var ans = 0; // マスクパターン for (var mr = 0; mr < (1 << H); ++mr) { for (var mc = 0; mc < (1 << 3); ++mc) { int black = 0; // マスクの全要素を探索 for (var r = 0; r < H; ++r) { for (var c = 0; c < W; ++c) { // マスクがかかっているセルはスキップ if (((mr >> r) & 1) == 1) continue; if (((mc >> c) & 1) == 1) continue; // 空いてるマスが#ならカウントアップ if (cells[r][c] != '#') continue; ++black; } } if (black == K) { ++ans; // Console.WriteLine("[ {0} {1} ]", Convert.ToString(mr, // 2).PadLeft(H,'0'), Convert.ToString(mc, 2).PadLeft(W,'0')); } } } Console.WriteLine(ans); } } }
using System; using System.Linq; namespace abc173c { class Program { static void Main(string[] args) { var ln1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var H = ln1[0]; var W = ln1[1]; var K = ln1[2]; var cells = Enumerable.Repeat(0, H).Select(x => Console.ReadLine()).ToArray(); var ans = 0; // マスクパターン for (var mr = 0; mr < (1 << H); ++mr) { for (var mc = 0; mc < (1 << W); ++mc) { int black = 0; // マスクの全要素を探索 for (var r = 0; r < H; ++r) { for (var c = 0; c < W; ++c) { // マスクがかかっているセルはスキップ if (((mr >> r) & 1) == 1) continue; if (((mc >> c) & 1) == 1) continue; // 空いてるマスが#ならカウントアップ if (cells[r][c] != '#') continue; ++black; } } // Console.WriteLine("[ {0} {1} ] {2}", Convert.ToString(mr, // 2).PadLeft(H,'0'), Convert.ToString(mc, 2).PadLeft(W,'0'),black); if (black == K) { ++ans; } } } Console.WriteLine(ans); } } }
[["-", 0, 7, 15, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 7, 15, 16, 12, 23, 0, 16, 12, 22]]
8
267
2
using System; using System.Collections.Generic; using System.Linq; class Class1 { static void Main(string[] args) { List<int> HKW = Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToList(); int H = HKW[0]; int W = HKW[1]; int K = HKW[2]; var ct = new char [H][]; for (int i = 0; i < H; i++) { ct[i] = Console.ReadLine().ToCharArray(); } int result = 0; // 最大は2^(6+6) = 2^12で 4096通りなので計算量は大したことない for (int i = 0; i < (1 << H); i++) { for (int j = 0; j < (1 << W); j++) { // Console.WriteLine($"START: i={i},j={j}"); int blakcs = 0; for (int x = 0; x < H; x++) { if ((i >> x & 1) == 1) { // Console.WriteLine($"SKIP_X: x={x}"); continue; } for (int y = 0; y < W; y++) { // Console.WriteLine($"LOOP: x={x},y={y}"); if ((j >> y & 1) == 1) { // Console.WriteLine($"SKIP_Y: y={y}"); continue; } if (ct[x][y] == '#') { blakcs++; } } } if (blakcs == K) { // Console.WriteLine($"i={i},j={j}, result++"); result++; } } } Console.WriteLine($"result: {result}"); } }
using System; using System.Collections.Generic; using System.Linq; class Class1 { static void Main(string[] args) { List<int> HKW = Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToList(); int H = HKW[0]; int W = HKW[1]; int K = HKW[2]; var ct = new char [H][]; for (int i = 0; i < H; i++) { ct[i] = Console.ReadLine().ToCharArray(); } int result = 0; // 最大は2^(6+6) = 2^12で 4096通りなので計算量は大したことない for (int i = 0; i < (1 << H); i++) { for (int j = 0; j < (1 << W); j++) { // Console.WriteLine($"START: i={i},j={j}"); int blakcs = 0; for (int x = 0; x < H; x++) { if ((i >> x & 1) == 1) { // Console.WriteLine($"SKIP_X: x={x}"); continue; } for (int y = 0; y < W; y++) { // Console.WriteLine($"LOOP: x={x},y={y}"); if ((j >> y & 1) == 1) { // Console.WriteLine($"SKIP_Y: y={y}"); continue; } if (ct[x][y] == '#') { blakcs++; } } } if (blakcs == K) { // Console.WriteLine($"i={i},j={j}, result++"); result++; } } } Console.WriteLine(result); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62]]
8
293
5
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var h = input[0]; var w = input[1]; var k = input[2]; var grid = new string[6, 6]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) grid[i, j] = ""; for (int i = 0; i < h; i++) { var input1 = Console.ReadLine(); for (int j = 0; j < w; j++) grid[i, j] = input1[j].ToString(); } var c1 = new List<string> { "", "1", "2", "3", "4", "5", "6" }; var c2 = new List<string> { "12", "13", "14", "15", "16", "23", "24", "25", "26", "34", "35", "36", "45", "46", "56" }; var c3 = new List<string> { "123", "124", "125", "126", "134", "135", "136", "145", "146", "156", "234", "235", "236", "245", "246", "256", "345", "346", "456" }; var c4 = new List<string> { "1234", "1235", "1236", "1245", "1246", "1256", "1345", "1346", "1356", "1456", "2345", "2346", "2356", "2456", "3456" }; var c5 = new List<string> { "12345", "12346", "23456", "12356", "12456", "13456" }; var c6 = new List<string> { "123456" }; int res = 0; var totalh = new List<string> {}; totalh.AddRange(c1); if (h > 1) totalh.AddRange(c2); if (h > 2) totalh.AddRange(c3); if (h > 3) totalh.AddRange(c4); if (h > 4) totalh.AddRange(c5); if (h > 5) totalh.AddRange(c6); var totalw = new List<string> {}; totalw.AddRange(c1); if (w > 1) totalw.AddRange(c2); if (w > 2) totalw.AddRange(c3); if (w > 3) totalw.AddRange(c4); if (w > 4) totalw.AddRange(c5); if (w > 5) totalw.AddRange(c6); for (int i = 0; i < totalh.Count(); i++) { for (int j = 0; j < totalw.Count(); j++) { var sweeph = totalh[i]; var sweepw = totalw[j]; bool check = true; for (int l = 0; l < sweeph.Length; l++) { int thish = int.Parse(sweeph[l].ToString()) - 1; if (thish >= h) check = false; } for (int l = 0; l < sweepw.Length; l++) { int thisw = int.Parse(sweepw[l].ToString()) - 1; if (thisw >= w) check = false; } if (!check) continue; var thisgrid = new string[6, 6]; for (int l = 0; l < h; l++) for (int q = 0; q < w; q++) thisgrid[l, q] = grid[l, q]; for (int l = 0; l < sweeph.Length; l++) { // if (sweeph[i].ToString() == "") continue; int thish = int.Parse(sweeph[l].ToString()) - 1; for (int q = 0; q < w; q++) thisgrid[thish, q] = ""; } for (int l = 0; l < sweepw.Length; l++) { // if (sweepw[i].ToString() == "") continue; int thisw = int.Parse(sweepw[l].ToString()) - 1; for (int q = 0; q < h; q++) thisgrid[q, thisw] = ""; } int cnt = 0; for (int l = 0; l < h; l++) for (int q = 0; q < w; q++) if (thisgrid[l, q] == "#") cnt++; if (k == cnt) res++; } } Console.WriteLine(res); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var h = input[0]; var w = input[1]; var k = input[2]; var grid = new string[6, 6]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) grid[i, j] = ""; for (int i = 0; i < h; i++) { var input1 = Console.ReadLine(); for (int j = 0; j < w; j++) grid[i, j] = input1[j].ToString(); } var c1 = new List<string> { "", "1", "2", "3", "4", "5", "6" }; var c2 = new List<string> { "12", "13", "14", "15", "16", "23", "24", "25", "26", "34", "35", "36", "45", "46", "56" }; var c3 = new List<string> { "123", "124", "125", "126", "134", "135", "136", "145", "146", "156", "234", "235", "236", "245", "246", "256", "345", "346", "356", "456" }; var c4 = new List<string> { "1234", "1235", "1236", "1245", "1246", "1256", "1345", "1346", "1356", "1456", "2345", "2346", "2356", "2456", "3456" }; var c5 = new List<string> { "12345", "12346", "23456", "12356", "12456", "13456" }; var c6 = new List<string> { "123456" }; int res = 0; var totalh = new List<string> {}; totalh.AddRange(c1); if (h > 1) totalh.AddRange(c2); if (h > 2) totalh.AddRange(c3); if (h > 3) totalh.AddRange(c4); if (h > 4) totalh.AddRange(c5); if (h > 5) totalh.AddRange(c6); var totalw = new List<string> {}; totalw.AddRange(c1); if (w > 1) totalw.AddRange(c2); if (w > 2) totalw.AddRange(c3); if (w > 3) totalw.AddRange(c4); if (w > 4) totalw.AddRange(c5); if (w > 5) totalw.AddRange(c6); for (int i = 0; i < totalh.Count(); i++) { for (int j = 0; j < totalw.Count(); j++) { var sweeph = totalh[i]; var sweepw = totalw[j]; bool check = true; for (int l = 0; l < sweeph.Length; l++) { int thish = int.Parse(sweeph[l].ToString()) - 1; if (thish >= h) check = false; } for (int l = 0; l < sweepw.Length; l++) { int thisw = int.Parse(sweepw[l].ToString()) - 1; if (thisw >= w) check = false; } if (!check) continue; var thisgrid = new string[6, 6]; for (int l = 0; l < h; l++) for (int q = 0; q < w; q++) thisgrid[l, q] = grid[l, q]; for (int l = 0; l < sweeph.Length; l++) { // if (sweeph[i].ToString() == "") continue; int thish = int.Parse(sweeph[l].ToString()) - 1; for (int q = 0; q < w; q++) thisgrid[thish, q] = ""; } for (int l = 0; l < sweepw.Length; l++) { // if (sweepw[i].ToString() == "") continue; int thisw = int.Parse(sweepw[l].ToString()) - 1; for (int q = 0; q < h; q++) thisgrid[q, thisw] = ""; } int cnt = 0; for (int l = 0; l < h; l++) for (int q = 0; q < w; q++) if (thisgrid[l, q] == "#") cnt++; if (k == cnt) res++; } } Console.WriteLine(res); } } }
[["+", 0, 212, 0, 230, 10, 229, 0, 5, 0, 222], ["+", 0, 212, 0, 230, 10, 229, 0, 5, 0, 62], ["+", 0, 200, 0, 212, 0, 230, 10, 229, 0, 21]]
8
1,072
4
using System; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { string[] input = Read(); int h = int.Parse(input[0]); int w = int.Parse(input[1]); int k = int.Parse(input[2]); char[][] color = new char [h][]; for (int i = 0; i < h; i++) { color[i] = Read() [0].ToCharArray(); } int max = 1 << (h + w); int count = 0; for (int i = 1; i < max; i++) { bool[] act = new bool[h + w]; int black = 0; for (int j = 0; j < h + w; j++) { act[j] = (i & (1 << j)) != 0; } for (int row = 0; row < h; row++) { for (int col = 0; col < w; col++) { if (color[row][col] == '#' && !act[row] && !act[h + col]) black++; } } if (black == k) count++; } Write(count); } static string[] Read() { return Console.ReadLine().Split(' '); } static void Write(object o) { Console.WriteLine(o.ToString()); } }
using System; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { string[] input = Read(); int h = int.Parse(input[0]); int w = int.Parse(input[1]); int k = int.Parse(input[2]); char[][] color = new char [h][]; for (int i = 0; i < h; i++) { color[i] = Read() [0].ToCharArray(); } int max = 1 << (h + w); int count = 0; for (int i = 0; i < max; i++) { bool[] act = new bool[h + w]; int black = 0; for (int j = 0; j < h + w; j++) { act[j] = (i & (1 << j)) != 0; } for (int row = 0; row < h; row++) { for (int col = 0; col < w; col++) { if (color[row][col] == '#' && !act[row] && !act[h + col]) black++; } } if (black == k) count++; } Write(count); } static string[] Read() { return Console.ReadLine().Split(' '); } static void Write(object o) { Console.WriteLine(o.ToString()); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
330
2
using System; namespace B { class Program { static void Main(string[] args) { string s = Console.ReadLine(); string t = Console.ReadLine(); int nCorrMax = 0; for (int i = 0; i < s.Length - t.Length; i++) { var nCorrTmp = 0; var j = 0; foreach (var c in t) { if (c == s[i + j]) { nCorrTmp += 1; } j++; } nCorrMax = Math.Max(nCorrMax, nCorrTmp); } Console.WriteLine(t.Length - nCorrMax); } } }
using System; namespace B { class Program { static void Main(string[] args) { string s = Console.ReadLine(); string t = Console.ReadLine(); int nCorrMax = 0; for (int i = 0; i < s.Length - t.Length + 1; i++) { var nCorrTmp = 0; var j = 0; foreach (var c in t) { if (c == s[i + j]) { nCorrTmp += 1; } j++; } nCorrMax = Math.Max(nCorrMax, nCorrTmp); } Console.WriteLine(t.Length - nCorrMax); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
128
2
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Runtime.ExceptionServices; using System.Security.Cryptography.X509Certificates; using System.Text; using static System.Console; using static System.Math; namespace AtCoder { class Program { static void Main(string[] args) { var S = Read(); var T = Read(); var Ans = int.MaxValue; for (int i = 0; i < S.Length - T.Length; i++) { var st = S.Substring(i, T.Length); var needchange = 0; for (int j = 0; j < T.Length; j++) { if (st[j] != T[j]) { needchange++; } } Ans = Min(Ans, needchange); } WriteLine(Ans); } private static string Read() { return ReadLine(); } private static string[] Reads() { return (Read().Split()); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Runtime.ExceptionServices; using System.Security.Cryptography.X509Certificates; using System.Text; using static System.Console; using static System.Math; namespace AtCoder { class Program { static void Main(string[] args) { var S = Read(); var T = Read(); var Ans = int.MaxValue; for (int i = 0; i <= S.Length - T.Length; i++) { var st = S.Substring(i, T.Length); var needchange = 0; for (int j = 0; j < T.Length; j++) { if (st[j] != T[j]) { needchange++; } } Ans = Min(Ans, needchange); } WriteLine(Ans); } private static string Read() { return ReadLine(); } private static string[] Reads() { return (Read().Split()); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
355
2
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); string input2 = Console.ReadLine(); int ans = input.Length; for (int length = 0; length < input.Length - input2.Length; length++) { int diff = 0; for (int pos = 0; pos < input2.Length; pos++) { if (input2[pos] != input[length]) { diff++; } } ans = ans > diff ? diff : ans; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); string input2 = Console.ReadLine(); int ans = input.Length; for (int length = 0; length <= input.Length - input2.Length; length++) { int diff = 0; for (int pos = 0; pos < input2.Length; pos++) { if (input2[pos] != input[pos + length]) { diff++; } } ans = ans > diff ? diff : ans; } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72]]
8
157
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; using System.Collections; namespace CompetitiveProgramming { public class CPair<T, U> : IComparable where T : IComparable<T> { public readonly T Item1; public readonly U Item2; public int CompareTo(object obj) { CPair<T, U> castedObj = (CPair<T, U>)obj; return this.Item1.CompareTo(castedObj.Item1); } public CPair(T t, U u) { Item1 = t; Item2 = u; } } class Pair : IComparable { public long x; public long a; public long b; public long c; public Pair(long X, long Y, long Z, long D) { x = X; a = Y; b = Z; c = D; } public Pair(long a, long x) { this.a = a; this.x = x; } public Pair(long a, long b, long c) { this.a = a; this.b = b; this.c = c; } public int CompareTo(object obj) { Pair kore = (Pair)obj; return x.CompareTo(kore.x); } public static bool operator <=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x <= p2.x; } else { return p1.a <= p2.a; } } public static bool operator >=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x >= p2.x; } else { return p1.a >= p2.a; } } } class Zettiti : IComparable { public long num; public Zettiti(long num) { this.num = num; } public int CompareTo(object obj) { Zettiti kore = (Zettiti)obj; long knum = Math.Abs(kore.num); long mynum = Math.Abs(num); return mynum.CompareTo(knum); } } class Program { static void Main(string[] args) { // Utils.BinarySearch.Search StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); string s = scan.Scan(); string t = scan.Scan(); long ans = long.MaxValue; for (int i = 0; i < s.Length - t.Length; i++) { long buf = 0; for (int j = 0; j < t.Length; j++) { if (s[i + j] != t[j]) { buf++; } } ans = Math.Min(buf, ans); } Console.WriteLine(ans); } static bool isOK(long mid, long[] a, long[] f, long k) { long count = 0; for (long i = 0; i < a.Length; i++) { long togo = mid / f[i]; ; count += Math.Max(0, a[i] - togo); } return (count <= k); } static void Output<T>(List<T> list, string kugiri = "\n") { for (int i = 0; i < list.Count; i++) { Console.Write(list[i]); if (i != list.Count - 1) { Console.Write(kugiri); } } } static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isok(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int binary_search(int key, int[] moto) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int[] Togo; static bool CheckBipartite(int now, int prev, List<int>[] g, int c = 0) // 0,-1が想定 { if (Togo == null) Togo = Enumerable.Repeat(-1, g.Length).ToArray(); foreach (var next in g[now]) { if (next == prev) continue; var nextc = Togo[next]; if (nextc >= 0 && nextc == c) return false; if (nextc >= 0) continue; Togo[next] = (c + 1) % 2; var res = CheckBipartite(next, now, g, (c + 1) % 2); if (res == false) return false; } return true; } static bool isOK(int index, int key, int[] moto) { return moto[index] > key; } public static int bitCount(int k) { uint i = (uint)k; i = i - ((i >> 1) & 0x55555555); i = (i & 0x33333333) + ((i >> 2) & 0x33333333); i = (i + (i >> 4)) & 0x0f0f0f0f; i = i + (i >> 8); i = i + (i >> 16); return (int)i & 0x3f; } static int check(long moto, long tai) { if (tai % moto != 0) { return 0; } while (tai > 1) { if (tai % moto == 0) { tai /= moto; } else if (tai > moto) { tai %= moto; } else { tai -= moto; } } if (tai == 1) { return 1; } else { return 0; } } static bool NextPermutation(int[] array) { var size = array.Length; var ok = false; // array[i]<array[i+1]を満たす最大のiを求める int i = size - 2; for (; 0 <= i; i--) { if (array[i] < array[i + 1]) { ok = true; break; } } //全ての要素が降順の場合、NextPermutationは存在しない if (ok == false) return false; // array[i]<array[j]を満たす最大のjを求める int j = size - 1; for (;; j--) { if (array[i] < array[j]) break; } // iとjの要素をswapする var tmp = array[i]; array[i] = array[j]; array[j] = tmp; // i以降の要素を反転させる Array.Reverse(array, i + 1, size - (i + 1)); return true; } static List<int[]> GetAllPermutation(int N) { var res = new List<int[]>(); var array = Enumerable.Range(0, N).ToArray(); do { var copy = new int[N]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static List<int[]> GetAllPermutation(int[] array) { var size = array.Length; var res = new List<int[]>(); do { var copy = new int[size]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static long Syakutori( int[] a, long k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上 { long sum = 0; int right = 0; long ans = 0; for (int left = 0; left < a.Length; left++) { while (right < a.Length && sum < k) { sum += a[right]; right++; } if (k <= sum) { ans += a.Length - right + 1; } if (left == right) { right++; } else { sum -= a[left]; } } return ans; } static int[] zalgo(String s) { int n = s.Length; int[] ret = new int[n]; ret[0] = n; int i = 1, j = 0; while (i < n) { while (i + j < n && s[j] == s[i + j]) ++j; ret[i] = j; if (j == 0) { ++i; continue; } int k = 1; while (i + k < n && k + ret[k] < j) { ret[i + k] = ret[k]; ++k; } i += k; j -= k; } return ret; } static int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } static long gcd(long a, long b) { if (a % b == 0) { return b; } return gcd(b, a % b); } public static List<long> factorialMemo = new List<long>() { 1 }; static long Fact(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } static int[] yousogotoplus(int[] a, int[] b) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[i]; } return c; } static int[] yousogotoplus(int[] a, int[,] b, int l) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[l, i]; } return c; } static int[] yousogotoplus(int[,] a, int l) { int[] c = new int[a.GetLength(1)]; for (int i = 0; i < a.GetLength(1); i++) { c[i] = a[l, i]; } return c; } public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[LowerBound(dp, a[i])] = a[i]; } return LowerBound(dp, long.MaxValue - 1); } static long DivideWith(long m, long n, List<long> primes) { while (m % n == 0) { primes.Add(n); m = m / n; } return m; } static List<CPair<long, long>> SoinsuBunkai(long num) { List<CPair<long, long>> primes = new List<CPair<long, long>>(); List<long> yakusu = new List<long>(); List<long> yakusu2 = new List<long>(); for (int i = 2; i * i <= num; i++) { if (num % i != 0) { continue; } yakusu.Add(i); if (i * i != num) { yakusu2.Add(num / i); } } for (int i = 0; i < yakusu.Count; i++) { if (num % yakusu[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu[i] == 0; j++) { num /= yakusu[i]; } primes.Add(new CPair<long, long>(yakusu[i], j)); } for (int i = yakusu2.Count - 1; i > 0; i--) { if (num % yakusu2[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu2[i] == 0; j++) { num /= yakusu2[i]; } primes.Add(new CPair<long, long>(yakusu2[i], j)); } return primes; } static IEnumerable<int> Primes(int maxnum) { // var sieve = new BitArray(maxnum + 1, true); bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray(); int squareroot = (int)Math.Sqrt(maxnum); for (int i = 2; i <= squareroot; i++) { if (sieve[i] == false) continue; for (int n = i * 2; n <= maxnum; n += i) sieve[n] = false; } for (int i = 2; i <= maxnum; i++) if (sieve[i] == true) yield return i; } /* static long[] SoinsuBunkai(long num) { if (num == 1) return new long[] { 1 }; List<long> primes = new List<long>(); long n = DivideWith(num, 2, primes); n = DivideWith(n, 3, primes); n = DivideWith(n, 5, primes); long i = 0; while (n > 1) { int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 }; foreach (var p in ps) { // 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break; } i += 30; } return primes.ToArray(); }*/ public static int h; public static int w; public static int BFS(int height, int width, char[,] map) { int[] dx = new int[] { -1, 0, 0, 1 }; int[] dy = new int[] { 0, 1, -1, 0 }; bool[,] visited = new bool[h, w]; int[,] len = new int[h, w]; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(new Tuple<int, int>(height, width)); int max = 0; visited[height, width] = true; while (queue.Count > 0) { var now = queue.Dequeue(); for (int i = 0; i < 4; i++) { int ny = now.Item1 + dy[i]; int nx = now.Item2 + dx[i]; if (ny >= h || ny < 0 || nx >= w || nx < 0) continue; if (visited[ny, nx] || map[ny, nx] == '#') continue; visited[ny, nx] = true; len[ny, nx] = len[now.Item1, now.Item2] + 1; max = Math.Max(max, len[ny, nx]); queue.Enqueue(new Tuple<int, int>(ny, nx)); } } return max; } static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Initialize<T>(ref T[] array, T initialvalue) { array = Array.ConvertAll(array, x => initialvalue); } static int[] Manacher(string S) { int i = 0, j = 0; int[] R = new int[S.Length]; while (i < S.Length) { while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j]) ++j; R[i] = j; int k = 1; while (i - k >= 0 && k + R[i - k] < j) { R[i + k] = R[i - k]; ++k; } i += k; j -= k; } return R; } /* static Pair[] a; static int SaikiZentansaku(List<int>now,int count,int last,int n,int m) { List<int> next = new List<int>(); for (int i = 0; i < now.Count; i++) { next.Add(now[i]); } next.Add(last); var kore = next.ToArray(); int ans = 0; if(count==n) { for (int i = 0; i < a.Length; i++) { int A = a[i].a; int b = a[i].b; int c = a[i].c; int d = a[i].x; if (kore[b] - kore[A] == c) { ans += d; } } return ans; } for (int i = last; i <= m; i++) { ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m)); } return ans; }*/ } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private long len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public char[] Char(long n) { char[] kore = new char[n]; for (long i = 0; i < n; i++) { kore[i] = Char(); } return kore; } public char[,] Char(long n, long m) { char[,] kore = new char[n, m]; for (long i = 0; i < n; i++) { for (int j = 0; j < m; j++) { kore[i, j] = Char(); } } return kore; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public long[] Long(long n) { long[] kore = new long[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public Mlong[] MLong(long n) { Mlong[] kore = new Mlong[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public long[,] Long(long h, long w) { long[,] kore = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = Long(); } } return kore; } public int Integer() { return (int)Long(); } public Mint[] MInteger(long n) { Mint[] kore = new Mint[n]; for (int i = 0; i < n; i++) { kore[i] = Integer(); } return kore; } public int[] Integer(long n) { int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = (int)Long(); } return kore; } public int[,] Integer(long h, long w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = (int)Long(); } } return kore; } public int[] StringToInt(int n) { char[] s = Scan().ToCharArray(); int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = s[i] - '0'; } return kore; } public int[,] StringToInt(int h, int w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { char[] s = Scan().ToCharArray(); for (int j = 0; j < w; j++) { kore[i, j] = s[j] - '0'; } } return kore; } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } public class Mlong : IComparable { private static long mod = 1000000007; public long num; public Mlong(long num) { if (num < 0) { num += mod; } this.num = num % mod; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mlong operator +(Mlong x, Mlong y) { return new Mlong((x.num + y.num) % mod); } public static Mlong operator -(Mlong x, Mlong y) { return new Mlong((x.num - y.num + mod) % mod); } public static Mlong operator *(Mlong x, Mlong y) { return new Mlong((long)(((1L * x.num) * y.num) % mod)); } public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); } static long GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; } public static implicit operator Mlong(long x) { return new Mlong(x); } public static Mlong operator %(Mlong x, Mlong y) { return new Mlong(x.num % y.num); } public static explicit operator long(Mlong x) { return x.num; } public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; } public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; } public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; } public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; } public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; } public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; } public Mlong Pow(Mlong n) { Mlong pow = this; Mlong res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n = n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); } public static List<Mlong> factorialMemo = new List<Mlong>() { 1 }; static Mlong Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mlong Comb(Mlong n, Mlong a) { Mlong buf1 = 1; Mlong buf2 = 1; for (long i = 0; i < a.num; i++) { buf1 *= n - i; buf2 *= (i + 1); } return buf1.modjyo(buf2); } public static Mlong Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mlong x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mlong kore = (Mlong)obj; return num.CompareTo(kore.num); } } public class Mint : IComparable { public static int mod = 1000000007; public int num; public Mint(int Num) { num = Num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mint operator +(Mint x, Mint y) { return new Mint((x.num + y.num) % mod); } public static Mint operator -(Mint x, Mint y) { return new Mint((x.num - y.num + mod) % mod); } public static Mint operator *(Mint x, Mint y) { return new Mint((int)(((1L * x.num) * y.num) % mod)); } public Mint hutujyo(Mint x) { return new Mint(num / x.num); } static int GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return (int)(x2 + mod); div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return (int)(x1 + mod); div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; } /* public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }*/ public static implicit operator Mint(int x) { return new Mint(x); } public static Mint[] Toarray(int[] x) { Mint[] buf = new Mint[x.Length]; for (int i = 0; i < x.Length; i++) { buf[i] = x[i]; } return buf; } public static explicit operator int(Mint x) { return x.num; } public static Mint operator %(Mint x, Mint y) { return new Mint(x.num % y.num); } public static bool operator ==(Mint x, Mint y) { return x.num == y.num; } public static bool operator !=(Mint x, Mint y) { return x.num != y.num; } public static bool operator<(Mint x, Mint y) { return x.num < y.num; } public static bool operator>(Mint x, Mint y) { return x.num > y.num; } public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; } public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; } public Mint Pow(Mint n) { Mint pow = this; Mint res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mint Pow(Mint a, Mint n) { return a.Pow(n); } public static List<Mint> factorialMemo = new List<Mint>() { 1 }; static Mint Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mint Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mint x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mint kore = (Mint)obj; return num.CompareTo(kore.num); } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } public class Tree { public Node[] Nodes; public List<int[]> hen; public class Node { public int? parent = null; public List<int[]> children = new List<int[]>(); public int parentcolor = -1; } public Tree(int kosu) { Nodes = new Node[kosu]; for (int i = 0; i < Nodes.Length; i++) { Nodes[i] = new Node(); } hen = new List<int[]>(); } public void Connect(int oya, int ko, int id) { hen.Add(new int[] { oya, ko, 0 }); Nodes[oya].children.Add(new int[] { ko, id }); Nodes[ko].parent = oya; } } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } // return ret; return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public bool Any() { return _root != null; } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public T max() { SB_BinarySearchTree<T>.Node ima = _root; while (ima.RChild != null) { ima = ima.RChild; } return ima.Value; } public T min() { SB_BinarySearchTree<T>.Node ima = _root; while (ima.LChild != null) { ima = ima.LChild; } return ima.Value; } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public class RollingHashSlow { public const long B = (long)1e5 + 7; public const long MOD = (long)1e9 + 7; public string S { get; set; } public int N { get; set; } public long[] Power { get; set; } public long[] Hash { get; set; } public RollingHashSlow(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new long[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = (this.Power[i] * B) % MOD; } // ハッシュを前計算する this.Hash = new long[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD; } } // S[l, r) のハッシュ値を求める public long Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD); if (hash < 0) hash += MOD; return hash; } } class RollingHashFast { public const ulong B = (ulong)1e9 + 7; public string S { get; set; } public int N { get; set; } public ulong[] Power { get; set; } public ulong[] Hash { get; set; } public RollingHashFast(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new ulong[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = this.Power[i] * B; } // ハッシュを前計算する this.Hash = new ulong[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = this.Hash[i] * B + S[i]; } } // [l, r) のハッシュ値を求める public ulong Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]); return hash; } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } // [s, t) public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class WarshallFloyd { public int V { get; set; } public long[,] DP { get; set; } public long INF = long.MaxValue; public bool[] Negative; public WarshallFloyd(int v) { this.V = v; this.DP = new long[V, V]; for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { this.DP[i, j] = INF; } this.DP[i, i] = 0; } } public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; } public long[,] CalcMinCost() { this.Negative = new bool[V]; for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]); } } } for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; if (DP[i, j] > DP[i, k] + DP[k, j]) { this.Negative[i] = true; this.Negative[j] = true; this.Negative[k] = true; } } } } return DP; } public long GetMinCost(int a, int b) { return DP[a, b]; } public bool IsINF(int a, int b) { return DP[a, b] >= INF; } public bool IsNegative(params int[] vs) { if (vs.Length == 0) vs = Enumerable.Range(0, V).ToArray(); foreach (var v in vs) { if (Negative[v]) return true; } return false; } } /// <summary> /// Get min cost between two points /// </summary> public class Dijkstra { private int maxIndex = -1; private const int INF = Int32.MaxValue; private int[,] _edgeArray; /// <summary> /// Dijkstra, get min cost between two points /// should not contain negatie cost path /// </summary> /// <param name="size">max index of vertices</param> public Dijkstra(int size) { maxIndex = size + 1; _edgeArray = new int[maxIndex, maxIndex]; for (int i = 0; i < _edgeArray.GetLength(0); i++) { for (int j = 0; j < _edgeArray.GetLength(1); j++) { _edgeArray[i, j] = INF; if (i == j) _edgeArray[i, j] = 0; } } } // Add a path(no direction) with its cost public void AddPath(int s, int t, int cost) { _edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost); _edgeArray[t, s] = _edgeArray[s, t]; } // Get the min cost between s and t // return Int32.MaxValue if no path public int GetMinCost(int s, int t) { int[] cost = new int[maxIndex]; for (int i = 0; i < cost.Length; i++) cost[i] = INF; cost[s] = 0; var priorityQueue = new PriorityQueue<CPair<int, int>>(); priorityQueue.Enqueue(new CPair<int, int>(0, s)); while (priorityQueue.Count() > 0) { var costDestinationPair = priorityQueue.Dequeue(); if (cost[costDestinationPair.Item2] < costDestinationPair.Item1) continue; for (int i = 0; i < maxIndex; i++) { int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF ? INF : costDestinationPair.Item1 + _edgeArray[costDestinationPair.Item2, i]; if (newCostToi < cost[i]) { cost[i] = newCostToi; priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i)); } } } return cost[t]; } } class Deque<T> : IEnumerable<T> { public T this[int i] { get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; } set { if (i < 0) throw new ArgumentOutOfRangeException(); this.Buffer[(this.FirstIndex + i) % this.Capacity] = value; } } private T[] Buffer; private int Capacity; private int FirstIndex; private int LastIndex { get { return (this.FirstIndex + this.Length) % this.Capacity; } } public int Length; public Deque(int capacity = 16) { this.Capacity = capacity; this.Buffer = new T[this.Capacity]; this.FirstIndex = 0; } public void PushBack(T data) { if (this.Length == this.Capacity) this.Resize(); this.Buffer[this.LastIndex] = data; this.Length++; } public void PushFront(T data) { if (this.Length == this.Capacity) this.Resize(); var index = this.FirstIndex - 1; if (index < 0) index = this.Capacity - 1; this.Buffer[index] = data; this.Length++; this.FirstIndex = index; } public T PopBack() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[this.Length - 1]; this.Length--; return data; } public T PopFront() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[0]; this.FirstIndex++; this.FirstIndex %= this.Capacity; this.Length--; return data; } private void Resize() { var newArray = new T[this.Capacity * 2]; for (int i = 0; i < this.Length; i++) { newArray[i] = this[i]; } this.FirstIndex = 0; this.Capacity *= 2; this.Buffer = newArray; } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } public class PotentializedUnionFind { int _count; int[] par, sizes, rank; long[] weight; public PotentializedUnionFind(int N) { _count = N; par = new int[N]; sizes = new int[N]; rank = new int[N]; weight = new long[N]; for (int i = 0; i < N; ++i) { par[i] = i; sizes[i] = 1; rank[i] = 0; } } int Root(int X) { if (par[X] == X) { return X; } else { int r = Root(par[X]); weight[X] += weight[par[X]]; return (par[X] = r); } } public bool Merge(int X, int Y, long W) { W += GetWeight(X); W -= GetWeight(Y); X = Root(X); Y = Root(Y); if (X == Y) return false; --_count; if (rank[X] < rank[Y]) { par[X] = Y; sizes[Y] += sizes[X]; weight[X] = -W; } else { par[Y] = X; sizes[X] += sizes[Y]; if (rank[X] == rank[Y]) ++rank[X]; weight[Y] = W; } return true; } public bool IsSame(int X, int Y) => Root(X) == Root(Y); public int Count => _count; public bool IsParent(int X) => X == Root(X); public int GetParent(int X) => Root(X); public int Size(int X) => sizes[Root(X)]; public long GetWeight(int X) { Root(X); return weight[X]; } public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X); } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } public class SortedMultiSet<T> : IEnumerable<T> { private SortedDictionary<T, int> _dict; public SortedMultiSet() { _dict = new SortedDictionary<T, int>(); } public SortedMultiSet(IEnumerable<T> items) : this() { Add(items); } public bool Contains(T item) { return _dict.ContainsKey(item); } public void Add(T item) { if (_dict.ContainsKey(item)) _dict[item]++; else _dict[item] = 1; } public void Add(IEnumerable<T> items) { foreach (var item in items) Add(item); } public void Remove(T item) { if (!_dict.ContainsKey(item)) throw new ArgumentException(); if (--_dict[item] == 0) _dict.Remove(item); } // Return the last value in the multiset public T Peek() { if (!_dict.Any()) throw new NullReferenceException(); return _dict.Last().Key; } // Return the last value in the multiset and remove it. public T Pop() { T item = Peek(); Remove(item); return item; } public IEnumerator<T> GetEnumerator() { foreach (var kvp in _dict) for (int i = 0; i < kvp.Value; i++) yield return kvp.Key; } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } class Treap<T> : IEnumerable<T> where T : IComparable { public int Length { get { return this.Root == null ? 0 : this.NodeCount(this.Root); } } public T this[int i] { get { if (this.Root.Count < i - 1) throw new IndexOutOfRangeException(); return this.Root.Get(i); } } public Node Root; private IComparer<T> Cmp = Comparer<T>.Default; public Treap(IComparer<T> cmp = null) { if (cmp != null) this.Cmp = cmp; } public Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if (l.Priority > r.Priority) { l.R = this.Merge(l.R, r); return this.Update(l); } else { r.L = this.Merge(l, r.L); return this.Update(r); } } // 左にk個、右に残り(n-k)個に分割する public (Node, Node) Split(int k) { return this.Split(this.Root, k); } public (Node, Node) Split(Node t, int k) { if (t == null) return (null, null); if (k <= this.NodeCount(t.L)) { var s = this.Split(t.L, k); t.L = s.Item2; return (s.Item1, this.Update(t)); } else { var s = this.Split(t.R, k - this.NodeCount(t.L) - 1); t.R = s.Item1; return (this.Update(t), s.Item2); } } public int NodeCount(Node node) { return node == null ? 0 : node.Count; } public int LowerBouond(T value) { return this.LowerBouond(this.Root, value); } public int LowerBouond(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) <= 0) return this.LowerBouond(node.L, value); else return this.NodeCount(node.L) + 1 + this.LowerBouond(node.R, value); } public int UpperBound(T value) { return this.UpperBound(this.Root, value); } public int UpperBound(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) >= 0) return this.NodeCount(node.L) + 1 + this.UpperBound(node.R, value); else return this.UpperBound(node.L, value); } public int ValueCount(T value) { return this.UpperBound(value) - this.LowerBouond(value); } public void Insert(T value) { var sub = this.Split(this.Root, this.LowerBouond(value)); var newNode = new Node(value); var merged = this.Merge(sub.Item1, newNode); this.Root = this.Merge(merged, sub.Item2); } public void Erase(T value) { if (this.ValueCount(value) == 0) return; var sub = this.Split(this.Root, this.LowerBouond(value)); this.Root = this.Merge(sub.Item1, this.Split(sub.Item2, 1).Item2); } public void InsertAt(Node node, int k) { var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public void InsertAt(T value, int k) { var node = new Node(value); var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public Node EraseAt(int k) { var sub = this.Split(this.Root, k); var sub2 = this.Split(sub.Item2, 1); var res = sub2.Item1; this.Root = this.Merge(sub.Item1, sub2.Item2); return res; } public Node Update(Node node) { node.Count = this.NodeCount(node.L) + this.NodeCount(node.R) + 1; return node; } public class Node { private static Random Rand = new Random(); public T Value; public Node L = null; public Node R = null; public int Count; public double Priority; public Node(T value, double priority) { this.Value = value; this.Priority = priority; this.Count = 1; } public Node(T value) : this(value, Rand.NextDouble()) {} public T Get(int i) { return this.GetNode(i).Value; } public Node GetNode(int i) { var lcount = 0; if (this.L != null) lcount = this.L.Count; if (lcount == i) return this; else if (lcount < i) return this.R.GetNode(i - lcount - 1); else return this.L.GetNode(i); } } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) yield return this.Root.Get(i); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } public static class ObjectExtension { // ディープコピーの複製を作る拡張メソッド public static T DeepClone<T>(this T src) { using (var memoryStream = new System.IO.MemoryStream()) { var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); binaryFormatter.Serialize(memoryStream, src); // シリアライズ memoryStream.Seek(0, System.IO.SeekOrigin.Begin); return (T)binaryFormatter.Deserialize(memoryStream); // デシリアライズ } } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; using System.Collections; namespace CompetitiveProgramming { public class CPair<T, U> : IComparable where T : IComparable<T> { public readonly T Item1; public readonly U Item2; public int CompareTo(object obj) { CPair<T, U> castedObj = (CPair<T, U>)obj; return this.Item1.CompareTo(castedObj.Item1); } public CPair(T t, U u) { Item1 = t; Item2 = u; } } class Pair : IComparable { public long x; public long a; public long b; public long c; public Pair(long X, long Y, long Z, long D) { x = X; a = Y; b = Z; c = D; } public Pair(long a, long x) { this.a = a; this.x = x; } public Pair(long a, long b, long c) { this.a = a; this.b = b; this.c = c; } public int CompareTo(object obj) { Pair kore = (Pair)obj; return x.CompareTo(kore.x); } public static bool operator <=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x <= p2.x; } else { return p1.a <= p2.a; } } public static bool operator >=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x >= p2.x; } else { return p1.a >= p2.a; } } } class Zettiti : IComparable { public long num; public Zettiti(long num) { this.num = num; } public int CompareTo(object obj) { Zettiti kore = (Zettiti)obj; long knum = Math.Abs(kore.num); long mynum = Math.Abs(num); return mynum.CompareTo(knum); } } class Program { static void Main(string[] args) { // Utils.BinarySearch.Search StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); string s = scan.Scan(); string t = scan.Scan(); long ans = long.MaxValue; for (int i = 0; i <= s.Length - t.Length; i++) { long buf = 0; for (int j = 0; j < t.Length; j++) { if (s[i + j] != t[j]) { buf++; } } ans = Math.Min(buf, ans); } Console.WriteLine(ans); } static bool isOK(long mid, long[] a, long[] f, long k) { long count = 0; for (long i = 0; i < a.Length; i++) { long togo = mid / f[i]; ; count += Math.Max(0, a[i] - togo); } return (count <= k); } static void Output<T>(List<T> list, string kugiri = "\n") { for (int i = 0; i < list.Count; i++) { Console.Write(list[i]); if (i != list.Count - 1) { Console.Write(kugiri); } } } static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isok(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int binary_search(int key, int[] moto) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int[] Togo; static bool CheckBipartite(int now, int prev, List<int>[] g, int c = 0) // 0,-1が想定 { if (Togo == null) Togo = Enumerable.Repeat(-1, g.Length).ToArray(); foreach (var next in g[now]) { if (next == prev) continue; var nextc = Togo[next]; if (nextc >= 0 && nextc == c) return false; if (nextc >= 0) continue; Togo[next] = (c + 1) % 2; var res = CheckBipartite(next, now, g, (c + 1) % 2); if (res == false) return false; } return true; } static bool isOK(int index, int key, int[] moto) { return moto[index] > key; } public static int bitCount(int k) { uint i = (uint)k; i = i - ((i >> 1) & 0x55555555); i = (i & 0x33333333) + ((i >> 2) & 0x33333333); i = (i + (i >> 4)) & 0x0f0f0f0f; i = i + (i >> 8); i = i + (i >> 16); return (int)i & 0x3f; } static int check(long moto, long tai) { if (tai % moto != 0) { return 0; } while (tai > 1) { if (tai % moto == 0) { tai /= moto; } else if (tai > moto) { tai %= moto; } else { tai -= moto; } } if (tai == 1) { return 1; } else { return 0; } } static bool NextPermutation(int[] array) { var size = array.Length; var ok = false; // array[i]<array[i+1]を満たす最大のiを求める int i = size - 2; for (; 0 <= i; i--) { if (array[i] < array[i + 1]) { ok = true; break; } } //全ての要素が降順の場合、NextPermutationは存在しない if (ok == false) return false; // array[i]<array[j]を満たす最大のjを求める int j = size - 1; for (;; j--) { if (array[i] < array[j]) break; } // iとjの要素をswapする var tmp = array[i]; array[i] = array[j]; array[j] = tmp; // i以降の要素を反転させる Array.Reverse(array, i + 1, size - (i + 1)); return true; } static List<int[]> GetAllPermutation(int N) { var res = new List<int[]>(); var array = Enumerable.Range(0, N).ToArray(); do { var copy = new int[N]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static List<int[]> GetAllPermutation(int[] array) { var size = array.Length; var res = new List<int[]>(); do { var copy = new int[size]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static long Syakutori( int[] a, long k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上 { long sum = 0; int right = 0; long ans = 0; for (int left = 0; left < a.Length; left++) { while (right < a.Length && sum < k) { sum += a[right]; right++; } if (k <= sum) { ans += a.Length - right + 1; } if (left == right) { right++; } else { sum -= a[left]; } } return ans; } static int[] zalgo(String s) { int n = s.Length; int[] ret = new int[n]; ret[0] = n; int i = 1, j = 0; while (i < n) { while (i + j < n && s[j] == s[i + j]) ++j; ret[i] = j; if (j == 0) { ++i; continue; } int k = 1; while (i + k < n && k + ret[k] < j) { ret[i + k] = ret[k]; ++k; } i += k; j -= k; } return ret; } static int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } static long gcd(long a, long b) { if (a % b == 0) { return b; } return gcd(b, a % b); } public static List<long> factorialMemo = new List<long>() { 1 }; static long Fact(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } static int[] yousogotoplus(int[] a, int[] b) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[i]; } return c; } static int[] yousogotoplus(int[] a, int[,] b, int l) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[l, i]; } return c; } static int[] yousogotoplus(int[,] a, int l) { int[] c = new int[a.GetLength(1)]; for (int i = 0; i < a.GetLength(1); i++) { c[i] = a[l, i]; } return c; } public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[LowerBound(dp, a[i])] = a[i]; } return LowerBound(dp, long.MaxValue - 1); } static long DivideWith(long m, long n, List<long> primes) { while (m % n == 0) { primes.Add(n); m = m / n; } return m; } static List<CPair<long, long>> SoinsuBunkai(long num) { List<CPair<long, long>> primes = new List<CPair<long, long>>(); List<long> yakusu = new List<long>(); List<long> yakusu2 = new List<long>(); for (int i = 2; i * i <= num; i++) { if (num % i != 0) { continue; } yakusu.Add(i); if (i * i != num) { yakusu2.Add(num / i); } } for (int i = 0; i < yakusu.Count; i++) { if (num % yakusu[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu[i] == 0; j++) { num /= yakusu[i]; } primes.Add(new CPair<long, long>(yakusu[i], j)); } for (int i = yakusu2.Count - 1; i > 0; i--) { if (num % yakusu2[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu2[i] == 0; j++) { num /= yakusu2[i]; } primes.Add(new CPair<long, long>(yakusu2[i], j)); } return primes; } static IEnumerable<int> Primes(int maxnum) { // var sieve = new BitArray(maxnum + 1, true); bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray(); int squareroot = (int)Math.Sqrt(maxnum); for (int i = 2; i <= squareroot; i++) { if (sieve[i] == false) continue; for (int n = i * 2; n <= maxnum; n += i) sieve[n] = false; } for (int i = 2; i <= maxnum; i++) if (sieve[i] == true) yield return i; } /* static long[] SoinsuBunkai(long num) { if (num == 1) return new long[] { 1 }; List<long> primes = new List<long>(); long n = DivideWith(num, 2, primes); n = DivideWith(n, 3, primes); n = DivideWith(n, 5, primes); long i = 0; while (n > 1) { int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 }; foreach (var p in ps) { // 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break; } i += 30; } return primes.ToArray(); }*/ public static int h; public static int w; public static int BFS(int height, int width, char[,] map) { int[] dx = new int[] { -1, 0, 0, 1 }; int[] dy = new int[] { 0, 1, -1, 0 }; bool[,] visited = new bool[h, w]; int[,] len = new int[h, w]; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(new Tuple<int, int>(height, width)); int max = 0; visited[height, width] = true; while (queue.Count > 0) { var now = queue.Dequeue(); for (int i = 0; i < 4; i++) { int ny = now.Item1 + dy[i]; int nx = now.Item2 + dx[i]; if (ny >= h || ny < 0 || nx >= w || nx < 0) continue; if (visited[ny, nx] || map[ny, nx] == '#') continue; visited[ny, nx] = true; len[ny, nx] = len[now.Item1, now.Item2] + 1; max = Math.Max(max, len[ny, nx]); queue.Enqueue(new Tuple<int, int>(ny, nx)); } } return max; } static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Initialize<T>(ref T[] array, T initialvalue) { array = Array.ConvertAll(array, x => initialvalue); } static int[] Manacher(string S) { int i = 0, j = 0; int[] R = new int[S.Length]; while (i < S.Length) { while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j]) ++j; R[i] = j; int k = 1; while (i - k >= 0 && k + R[i - k] < j) { R[i + k] = R[i - k]; ++k; } i += k; j -= k; } return R; } /* static Pair[] a; static int SaikiZentansaku(List<int>now,int count,int last,int n,int m) { List<int> next = new List<int>(); for (int i = 0; i < now.Count; i++) { next.Add(now[i]); } next.Add(last); var kore = next.ToArray(); int ans = 0; if(count==n) { for (int i = 0; i < a.Length; i++) { int A = a[i].a; int b = a[i].b; int c = a[i].c; int d = a[i].x; if (kore[b] - kore[A] == c) { ans += d; } } return ans; } for (int i = last; i <= m; i++) { ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m)); } return ans; }*/ } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private long len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public char[] Char(long n) { char[] kore = new char[n]; for (long i = 0; i < n; i++) { kore[i] = Char(); } return kore; } public char[,] Char(long n, long m) { char[,] kore = new char[n, m]; for (long i = 0; i < n; i++) { for (int j = 0; j < m; j++) { kore[i, j] = Char(); } } return kore; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public long[] Long(long n) { long[] kore = new long[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public Mlong[] MLong(long n) { Mlong[] kore = new Mlong[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public long[,] Long(long h, long w) { long[,] kore = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = Long(); } } return kore; } public int Integer() { return (int)Long(); } public Mint[] MInteger(long n) { Mint[] kore = new Mint[n]; for (int i = 0; i < n; i++) { kore[i] = Integer(); } return kore; } public int[] Integer(long n) { int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = (int)Long(); } return kore; } public int[,] Integer(long h, long w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = (int)Long(); } } return kore; } public int[] StringToInt(int n) { char[] s = Scan().ToCharArray(); int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = s[i] - '0'; } return kore; } public int[,] StringToInt(int h, int w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { char[] s = Scan().ToCharArray(); for (int j = 0; j < w; j++) { kore[i, j] = s[j] - '0'; } } return kore; } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } public class Mlong : IComparable { private static long mod = 1000000007; public long num; public Mlong(long num) { if (num < 0) { num += mod; } this.num = num % mod; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mlong operator +(Mlong x, Mlong y) { return new Mlong((x.num + y.num) % mod); } public static Mlong operator -(Mlong x, Mlong y) { return new Mlong((x.num - y.num + mod) % mod); } public static Mlong operator *(Mlong x, Mlong y) { return new Mlong((long)(((1L * x.num) * y.num) % mod)); } public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); } static long GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; } public static implicit operator Mlong(long x) { return new Mlong(x); } public static Mlong operator %(Mlong x, Mlong y) { return new Mlong(x.num % y.num); } public static explicit operator long(Mlong x) { return x.num; } public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; } public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; } public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; } public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; } public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; } public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; } public Mlong Pow(Mlong n) { Mlong pow = this; Mlong res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n = n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); } public static List<Mlong> factorialMemo = new List<Mlong>() { 1 }; static Mlong Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mlong Comb(Mlong n, Mlong a) { Mlong buf1 = 1; Mlong buf2 = 1; for (long i = 0; i < a.num; i++) { buf1 *= n - i; buf2 *= (i + 1); } return buf1.modjyo(buf2); } public static Mlong Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mlong x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mlong kore = (Mlong)obj; return num.CompareTo(kore.num); } } public class Mint : IComparable { public static int mod = 1000000007; public int num; public Mint(int Num) { num = Num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mint operator +(Mint x, Mint y) { return new Mint((x.num + y.num) % mod); } public static Mint operator -(Mint x, Mint y) { return new Mint((x.num - y.num + mod) % mod); } public static Mint operator *(Mint x, Mint y) { return new Mint((int)(((1L * x.num) * y.num) % mod)); } public Mint hutujyo(Mint x) { return new Mint(num / x.num); } static int GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return (int)(x2 + mod); div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return (int)(x1 + mod); div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; } /* public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }*/ public static implicit operator Mint(int x) { return new Mint(x); } public static Mint[] Toarray(int[] x) { Mint[] buf = new Mint[x.Length]; for (int i = 0; i < x.Length; i++) { buf[i] = x[i]; } return buf; } public static explicit operator int(Mint x) { return x.num; } public static Mint operator %(Mint x, Mint y) { return new Mint(x.num % y.num); } public static bool operator ==(Mint x, Mint y) { return x.num == y.num; } public static bool operator !=(Mint x, Mint y) { return x.num != y.num; } public static bool operator<(Mint x, Mint y) { return x.num < y.num; } public static bool operator>(Mint x, Mint y) { return x.num > y.num; } public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; } public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; } public Mint Pow(Mint n) { Mint pow = this; Mint res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mint Pow(Mint a, Mint n) { return a.Pow(n); } public static List<Mint> factorialMemo = new List<Mint>() { 1 }; static Mint Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mint Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mint x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mint kore = (Mint)obj; return num.CompareTo(kore.num); } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } public class Tree { public Node[] Nodes; public List<int[]> hen; public class Node { public int? parent = null; public List<int[]> children = new List<int[]>(); public int parentcolor = -1; } public Tree(int kosu) { Nodes = new Node[kosu]; for (int i = 0; i < Nodes.Length; i++) { Nodes[i] = new Node(); } hen = new List<int[]>(); } public void Connect(int oya, int ko, int id) { hen.Add(new int[] { oya, ko, 0 }); Nodes[oya].children.Add(new int[] { ko, id }); Nodes[ko].parent = oya; } } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } // return ret; return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public bool Any() { return _root != null; } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public T max() { SB_BinarySearchTree<T>.Node ima = _root; while (ima.RChild != null) { ima = ima.RChild; } return ima.Value; } public T min() { SB_BinarySearchTree<T>.Node ima = _root; while (ima.LChild != null) { ima = ima.LChild; } return ima.Value; } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public class RollingHashSlow { public const long B = (long)1e5 + 7; public const long MOD = (long)1e9 + 7; public string S { get; set; } public int N { get; set; } public long[] Power { get; set; } public long[] Hash { get; set; } public RollingHashSlow(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new long[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = (this.Power[i] * B) % MOD; } // ハッシュを前計算する this.Hash = new long[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD; } } // S[l, r) のハッシュ値を求める public long Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD); if (hash < 0) hash += MOD; return hash; } } class RollingHashFast { public const ulong B = (ulong)1e9 + 7; public string S { get; set; } public int N { get; set; } public ulong[] Power { get; set; } public ulong[] Hash { get; set; } public RollingHashFast(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new ulong[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = this.Power[i] * B; } // ハッシュを前計算する this.Hash = new ulong[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = this.Hash[i] * B + S[i]; } } // [l, r) のハッシュ値を求める public ulong Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]); return hash; } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } // [s, t) public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class WarshallFloyd { public int V { get; set; } public long[,] DP { get; set; } public long INF = long.MaxValue; public bool[] Negative; public WarshallFloyd(int v) { this.V = v; this.DP = new long[V, V]; for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { this.DP[i, j] = INF; } this.DP[i, i] = 0; } } public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; } public long[,] CalcMinCost() { this.Negative = new bool[V]; for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]); } } } for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; if (DP[i, j] > DP[i, k] + DP[k, j]) { this.Negative[i] = true; this.Negative[j] = true; this.Negative[k] = true; } } } } return DP; } public long GetMinCost(int a, int b) { return DP[a, b]; } public bool IsINF(int a, int b) { return DP[a, b] >= INF; } public bool IsNegative(params int[] vs) { if (vs.Length == 0) vs = Enumerable.Range(0, V).ToArray(); foreach (var v in vs) { if (Negative[v]) return true; } return false; } } /// <summary> /// Get min cost between two points /// </summary> public class Dijkstra { private int maxIndex = -1; private const int INF = Int32.MaxValue; private int[,] _edgeArray; /// <summary> /// Dijkstra, get min cost between two points /// should not contain negatie cost path /// </summary> /// <param name="size">max index of vertices</param> public Dijkstra(int size) { maxIndex = size + 1; _edgeArray = new int[maxIndex, maxIndex]; for (int i = 0; i < _edgeArray.GetLength(0); i++) { for (int j = 0; j < _edgeArray.GetLength(1); j++) { _edgeArray[i, j] = INF; if (i == j) _edgeArray[i, j] = 0; } } } // Add a path(no direction) with its cost public void AddPath(int s, int t, int cost) { _edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost); _edgeArray[t, s] = _edgeArray[s, t]; } // Get the min cost between s and t // return Int32.MaxValue if no path public int GetMinCost(int s, int t) { int[] cost = new int[maxIndex]; for (int i = 0; i < cost.Length; i++) cost[i] = INF; cost[s] = 0; var priorityQueue = new PriorityQueue<CPair<int, int>>(); priorityQueue.Enqueue(new CPair<int, int>(0, s)); while (priorityQueue.Count() > 0) { var costDestinationPair = priorityQueue.Dequeue(); if (cost[costDestinationPair.Item2] < costDestinationPair.Item1) continue; for (int i = 0; i < maxIndex; i++) { int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF ? INF : costDestinationPair.Item1 + _edgeArray[costDestinationPair.Item2, i]; if (newCostToi < cost[i]) { cost[i] = newCostToi; priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i)); } } } return cost[t]; } } class Deque<T> : IEnumerable<T> { public T this[int i] { get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; } set { if (i < 0) throw new ArgumentOutOfRangeException(); this.Buffer[(this.FirstIndex + i) % this.Capacity] = value; } } private T[] Buffer; private int Capacity; private int FirstIndex; private int LastIndex { get { return (this.FirstIndex + this.Length) % this.Capacity; } } public int Length; public Deque(int capacity = 16) { this.Capacity = capacity; this.Buffer = new T[this.Capacity]; this.FirstIndex = 0; } public void PushBack(T data) { if (this.Length == this.Capacity) this.Resize(); this.Buffer[this.LastIndex] = data; this.Length++; } public void PushFront(T data) { if (this.Length == this.Capacity) this.Resize(); var index = this.FirstIndex - 1; if (index < 0) index = this.Capacity - 1; this.Buffer[index] = data; this.Length++; this.FirstIndex = index; } public T PopBack() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[this.Length - 1]; this.Length--; return data; } public T PopFront() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[0]; this.FirstIndex++; this.FirstIndex %= this.Capacity; this.Length--; return data; } private void Resize() { var newArray = new T[this.Capacity * 2]; for (int i = 0; i < this.Length; i++) { newArray[i] = this[i]; } this.FirstIndex = 0; this.Capacity *= 2; this.Buffer = newArray; } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } public class PotentializedUnionFind { int _count; int[] par, sizes, rank; long[] weight; public PotentializedUnionFind(int N) { _count = N; par = new int[N]; sizes = new int[N]; rank = new int[N]; weight = new long[N]; for (int i = 0; i < N; ++i) { par[i] = i; sizes[i] = 1; rank[i] = 0; } } int Root(int X) { if (par[X] == X) { return X; } else { int r = Root(par[X]); weight[X] += weight[par[X]]; return (par[X] = r); } } public bool Merge(int X, int Y, long W) { W += GetWeight(X); W -= GetWeight(Y); X = Root(X); Y = Root(Y); if (X == Y) return false; --_count; if (rank[X] < rank[Y]) { par[X] = Y; sizes[Y] += sizes[X]; weight[X] = -W; } else { par[Y] = X; sizes[X] += sizes[Y]; if (rank[X] == rank[Y]) ++rank[X]; weight[Y] = W; } return true; } public bool IsSame(int X, int Y) => Root(X) == Root(Y); public int Count => _count; public bool IsParent(int X) => X == Root(X); public int GetParent(int X) => Root(X); public int Size(int X) => sizes[Root(X)]; public long GetWeight(int X) { Root(X); return weight[X]; } public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X); } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } public class SortedMultiSet<T> : IEnumerable<T> { private SortedDictionary<T, int> _dict; public SortedMultiSet() { _dict = new SortedDictionary<T, int>(); } public SortedMultiSet(IEnumerable<T> items) : this() { Add(items); } public bool Contains(T item) { return _dict.ContainsKey(item); } public void Add(T item) { if (_dict.ContainsKey(item)) _dict[item]++; else _dict[item] = 1; } public void Add(IEnumerable<T> items) { foreach (var item in items) Add(item); } public void Remove(T item) { if (!_dict.ContainsKey(item)) throw new ArgumentException(); if (--_dict[item] == 0) _dict.Remove(item); } // Return the last value in the multiset public T Peek() { if (!_dict.Any()) throw new NullReferenceException(); return _dict.Last().Key; } // Return the last value in the multiset and remove it. public T Pop() { T item = Peek(); Remove(item); return item; } public IEnumerator<T> GetEnumerator() { foreach (var kvp in _dict) for (int i = 0; i < kvp.Value; i++) yield return kvp.Key; } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } class Treap<T> : IEnumerable<T> where T : IComparable { public int Length { get { return this.Root == null ? 0 : this.NodeCount(this.Root); } } public T this[int i] { get { if (this.Root.Count < i - 1) throw new IndexOutOfRangeException(); return this.Root.Get(i); } } public Node Root; private IComparer<T> Cmp = Comparer<T>.Default; public Treap(IComparer<T> cmp = null) { if (cmp != null) this.Cmp = cmp; } public Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if (l.Priority > r.Priority) { l.R = this.Merge(l.R, r); return this.Update(l); } else { r.L = this.Merge(l, r.L); return this.Update(r); } } // 左にk個、右に残り(n-k)個に分割する public (Node, Node) Split(int k) { return this.Split(this.Root, k); } public (Node, Node) Split(Node t, int k) { if (t == null) return (null, null); if (k <= this.NodeCount(t.L)) { var s = this.Split(t.L, k); t.L = s.Item2; return (s.Item1, this.Update(t)); } else { var s = this.Split(t.R, k - this.NodeCount(t.L) - 1); t.R = s.Item1; return (this.Update(t), s.Item2); } } public int NodeCount(Node node) { return node == null ? 0 : node.Count; } public int LowerBouond(T value) { return this.LowerBouond(this.Root, value); } public int LowerBouond(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) <= 0) return this.LowerBouond(node.L, value); else return this.NodeCount(node.L) + 1 + this.LowerBouond(node.R, value); } public int UpperBound(T value) { return this.UpperBound(this.Root, value); } public int UpperBound(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) >= 0) return this.NodeCount(node.L) + 1 + this.UpperBound(node.R, value); else return this.UpperBound(node.L, value); } public int ValueCount(T value) { return this.UpperBound(value) - this.LowerBouond(value); } public void Insert(T value) { var sub = this.Split(this.Root, this.LowerBouond(value)); var newNode = new Node(value); var merged = this.Merge(sub.Item1, newNode); this.Root = this.Merge(merged, sub.Item2); } public void Erase(T value) { if (this.ValueCount(value) == 0) return; var sub = this.Split(this.Root, this.LowerBouond(value)); this.Root = this.Merge(sub.Item1, this.Split(sub.Item2, 1).Item2); } public void InsertAt(Node node, int k) { var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public void InsertAt(T value, int k) { var node = new Node(value); var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public Node EraseAt(int k) { var sub = this.Split(this.Root, k); var sub2 = this.Split(sub.Item2, 1); var res = sub2.Item1; this.Root = this.Merge(sub.Item1, sub2.Item2); return res; } public Node Update(Node node) { node.Count = this.NodeCount(node.L) + this.NodeCount(node.R) + 1; return node; } public class Node { private static Random Rand = new Random(); public T Value; public Node L = null; public Node R = null; public int Count; public double Priority; public Node(T value, double priority) { this.Value = value; this.Priority = priority; this.Count = 1; } public Node(T value) : this(value, Rand.NextDouble()) {} public T Get(int i) { return this.GetNode(i).Value; } public Node GetNode(int i) { var lcount = 0; if (this.L != null) lcount = this.L.Count; if (lcount == i) return this; else if (lcount < i) return this.R.GetNode(i - lcount - 1); else return this.L.GetNode(i); } } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) yield return this.Root.Get(i); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } public static class ObjectExtension { // ディープコピーの複製を作る拡張メソッド public static T DeepClone<T>(this T src) { using (var memoryStream = new System.IO.MemoryStream()) { var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); binaryFormatter.Serialize(memoryStream, src); // シリアライズ memoryStream.Seek(0, System.IO.SeekOrigin.Begin); return (T)binaryFormatter.Deserialize(memoryStream); // デシリアライズ } } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
13,483
2
using System; namespace Example03 { class Program { static void Main(string[] args) { char[] s = Console.ReadLine().ToCharArray(); char[] t = Console.ReadLine().ToCharArray(); int dif = t.Length; for (int i = 0; i < s.Length - t.Length; i++) { int score = 0; for (int j = 0; j < t.Length; j++) { if (!s[i + j].Equals(t[j])) score++; } if (dif > score) dif = score; } Console.WriteLine(dif); } } }
using System; namespace Example03 { class Program { static void Main(string[] args) { char[] s = Console.ReadLine().ToCharArray(); char[] t = Console.ReadLine().ToCharArray(); int dif = t.Length; for (int i = 0; i <= s.Length - t.Length; i++) { int score = 0; for (int j = 0; j < t.Length; j++) { if (!s[i + j].Equals(t[j])) score++; } if (dif > score) dif = score; } Console.WriteLine(dif); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
142
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { string s = Console.ReadLine(); string t = Console.ReadLine(); List<uint> compared = new List<uint>(); for (int i = 0; i < s.Length - t.Length; i++) { compared.Add(CompareStrings(i, s, t)); } Console.WriteLine(compared.Min()); return; } static uint CompareStrings(int startIdx, string s, string t) { uint ret = 0; for (int i = 0; i < t.Length; i++) { if (s[startIdx + i] != t[i]) { ret++; } } return ret; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { string s = Console.ReadLine(); string t = Console.ReadLine(); List<uint> compared = new List<uint>(); // Must <= for (int i = 0; i <= s.Length - t.Length; i++) { compared.Add(CompareStrings(i, s, t)); } Console.WriteLine(compared.Min()); return; } static uint CompareStrings(int startIdx, string s, string t) { uint ret = 0; for (int i = 0; i < t.Length; i++) { if (s[startIdx + i] != t[i]) { ret++; } } return ret; } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
171
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 CP { class Atria { static void Main(string[] args) { string s = ReadLine(); string t = ReadLine(); int ans = 0; for (int i = 0; i < s.Length - t.Length + 1; i++) { int tmp = 0; for (int j = 0; j < t.Length; j++) { if (s[i + j] == t[j]) tmp++; } ans = Max(tmp, ans); } WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace CP { class Atria { static void Main(string[] args) { string s = ReadLine(); string t = ReadLine(); int ans = 0; for (int i = 0; i < s.Length - t.Length + 1; i++) { int tmp = 0; for (int j = 0; j < t.Length; j++) { if (s[i + j] == t[j]) tmp++; } ans = Max(tmp, ans); } WriteLine(t.Length - ans); } } }
[["+", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
153
4
using System; class B { static void Main() { string S = Console.ReadLine(); string A = Console.ReadLine(); int ans = 1999, f = 0; for (int i = 0; i < S.Length - A.Length; i++) { f = 0; for (int j = 0; j < A.Length; j++) { if (S.Substring(i + j, 1) != A.Substring(j, 1)) f++; } ans = Math.Min(ans, f); } Console.WriteLine(ans); } }
using System; class B { static void Main() { string S = Console.ReadLine(); string A = Console.ReadLine(); int ans = 1000, f = 0; for (int i = 0; i <= S.Length - A.Length; i++) { f = 0; for (int j = 0; j < A.Length; j++) { if (S.Substring(i + j, 1) != A.Substring(j, 1)) f++; } ans = Math.Min(ans, f); } Console.WriteLine(ans); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
128
4
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Reflection.Metadata; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading; namespace AtCoder { public class Program { static void Main() { var cin = new Scanner(); string s = cin.Next(); string t = cin.Next(); int sn = s.Length; int tn = t.Length; int ans = int.MaxValue; for (int i = 0; i < sn - tn; i++) { int temp = 0; for (int j = 0; j < tn; j++) { if (s[i + j] != t[j]) { ++temp; } } ans = Math.Min(ans, temp); } Console.WriteLine(ans); } } public class HashMap<TKey, TValue> : Dictionary<TKey, TValue> { private readonly Func<TKey, TValue> initialzier_; public HashMap(Func<TKey, TValue> initialzier) : base() { initialzier_ = initialzier; } public HashMap(Func<TKey, TValue> initialzier, int capacity) : base(capacity) { initialzier_ = initialzier; } new public TValue this[TKey key] { get { if (ContainsKey(key) == false) { base[key] = initialzier_(key); } return base[key]; } set { base[key] = value; } } } public struct ModInt { public const long P = 1000000007; //public const long P = 998244353; public static ModInt Inverse(ModInt value) => Pow(value, P - 2); public static ModInt Pow(ModInt value, long k) => Pow(value.value_, k); public static ModInt Pow(long value, long k) { long ret = 1; for (k %= P - 1; k > 0; k >>= 1, value = value * value % P) { if ((k & 1) == 1) { ret = ret * value % P; } } return new ModInt(ret); } private long value_; public ModInt(long value) => value_ = value; public ModInt(long value, bool mods) { if (mods) { value %= P; if (value < 0) { value += P; } } value_ = value; } public static ModInt operator +(ModInt lhs, ModInt rhs) { lhs.value_ = (lhs.value_ + rhs.value_) % P; return lhs; } public static ModInt operator +(long lhs, ModInt rhs) { rhs.value_ = (lhs + rhs.value_) % P; return rhs; } public static ModInt operator +(ModInt lhs, long rhs) { lhs.value_ = (lhs.value_ + rhs) % P; return lhs; } public static ModInt operator -(ModInt lhs, ModInt rhs) { lhs.value_ = (P + lhs.value_ - rhs.value_) % P; return lhs; } public static ModInt operator -(long lhs, ModInt rhs) { rhs.value_ = (P + lhs - rhs.value_) % P; return rhs; } public static ModInt operator -(ModInt lhs, long rhs) { lhs.value_ = (P + lhs.value_ - rhs) % P; return lhs; } public static ModInt operator *(ModInt lhs, ModInt rhs) { lhs.value_ = lhs.value_ * rhs.value_ % P; return lhs; } public static ModInt operator *(long lhs, ModInt rhs) { rhs.value_ = lhs * rhs.value_ % P; return rhs; } public static ModInt operator *(ModInt lhs, long rhs) { lhs.value_ = lhs.value_ * rhs % P; return lhs; } public static ModInt operator /(ModInt lhs, ModInt rhs) { long exp = P - 2; while (exp > 0) { if (exp % 2 > 0) { lhs *= rhs; } rhs *= rhs; exp /= 2; } return lhs; } public static implicit operator ModInt(long n) => new ModInt(n, true); public long ToLong() => value_; public override string ToString() => value_.ToString(); } public static class Helper { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UpdateMin<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) > 0 ? value : target; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UpdateMin<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) > 0) { target = value; onUpdated(value); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UpdateMax<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) < 0 ? value : target; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UpdateMax<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) < 0) { target = value; onUpdated(value); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Array<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<T> List<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[,] Array2<T>(int n, int m, T init) where T : struct { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = init; } } return array; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[,] Array2<T>(int n, int m, Func<int, int, T> initializer) { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = initializer(i, j); } } return array; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[,,] Array3<T>(int n1, int n2, int n3, T init) where T : struct { var array = new T[n1, n2, n3]; for (int i1 = 0; i1 < n1; i1++) { for (int i2 = 0; i2 < n2; i2++) { for (int i3 = 0; i3 < n3; i3++) { array[i1, i2, i3] = init; } } } return array; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[,,,] Array4<T>(int n1, int n2, int n3, int n4, T init) where T : struct { var array = new T[n1, n2, n3, n4]; for (int i1 = 0; i1 < n1; i1++) { for (int i2 = 0; i2 < n2; i2++) { for (int i3 = 0; i3 < n3; i3++) { for (int i4 = 0; i4 < n4; i4++) { array[i1, i2, i3, i4] = init; } } } } return array; } private static readonly int[] delta4_ = { 1, 0, -1, 0, 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void DoAt4(int i, int j, int imax, int jmax, Action<int, int> action) { for (int dn = 0; dn < 4; dn++) { int d4i = i + delta4_[dn]; int d4j = j + delta4_[dn + 1]; if ((uint)d4i < (uint)imax && (uint)d4j < (uint)jmax) { action(d4i, d4j); } } } private static readonly int[] delta8_ = { 1, 0, -1, 0, 1, 1, -1, -1, 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void DoAt8(int i, int j, int imax, int jmax, Action<int, int> action) { for (int dn = 0; dn < 8; dn++) { int d8i = i + delta8_[dn]; int d8j = j + delta8_[dn + 1]; if ((uint)d8i < (uint)imax && (uint)d8j < (uint)jmax) { action(d8i, d8j); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void ForEachSubBit(int bit, Action<int> action) { for (int sub = bit; sub >= 0; sub--) { sub &= bit; action(sub); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Reverse(string src) { var chars = src.ToCharArray(); for (int i = 0, j = chars.Length - 1; i < j; i++, j--) { var tmp = chars[i]; chars[i] = chars[j]; chars[j] = tmp; } return new string(chars); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Join<T>(this IEnumerable<T> values, string separator = "") => string.Join(separator, values); } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private readonly Func<string> reader_; private string[] buf_; private int index_; public Scanner(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public string NextLine() => reader_(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Int() => int.Parse(Next()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Int(int offset) => int.Parse(Next()) + offset; [MethodImpl(MethodImplOptions.AggressiveInlining)] public (int, int) Int2(int offset = 0) => (Int(offset), Int(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public (int, int, int) Int3(int offset = 0) => (Int(offset), Int(offset), Int(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public (int, int, int, int) Int4(int offset = 0) => (Int(offset), Int(offset), Int(offset), Int(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int[] ArrayInt(int length, int offset = 0) { int[] Array = new int[length]; for (int i = 0; i < length; i++) { Array[i] = Int(offset); } return Array; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Long() => long.Parse(Next()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Long(long offset) => long.Parse(Next()) + offset; [MethodImpl(MethodImplOptions.AggressiveInlining)] public (long, long) Long2(long offset = 0) => (Long(offset), Long(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public (long, long, long) Long3(long offset = 0) => (Long(offset), Long(offset), Long(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public (long, long, long, long) Long4(long offset = 0) => (Long(offset), Long(offset), Long(offset), Long(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long[] ArrayLong(int length, long offset = 0) { long[] Array = new long[length]; for (int i = 0; i < length; i++) { Array[i] = Long(offset); } return Array; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public double Double() => double.Parse(Next()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public double Double(double offset) => double.Parse(Next()) + offset; [MethodImpl(MethodImplOptions.AggressiveInlining)] public (double, double) Double2(double offset = 0) => (Double(offset), Double(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public (double, double, double) Double3(double offset = 0) => (Double(offset), Double(offset), Double(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public (double, double, double, double) Double4(double offset = 0) => (Double(offset), Double(offset), Double(offset), Double(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public double[] ArrayDouble(int length, double offset = 0) { double[] Array = new double[length]; for (int i = 0; i < length; i++) { Array[i] = Double(offset); } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Reflection.Metadata; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading; namespace AtCoder { public class Program { static void Main() { var cin = new Scanner(); string s = cin.Next(); string t = cin.Next(); int sn = s.Length; int tn = t.Length; int ans = int.MaxValue; for (int i = 0; i <= sn - tn; i++) { int temp = 0; for (int j = 0; j < tn; j++) { if (s[i + j] != t[j]) { ++temp; } } ans = Math.Min(ans, temp); } Console.WriteLine(ans); } } public class HashMap<TKey, TValue> : Dictionary<TKey, TValue> { private readonly Func<TKey, TValue> initialzier_; public HashMap(Func<TKey, TValue> initialzier) : base() { initialzier_ = initialzier; } public HashMap(Func<TKey, TValue> initialzier, int capacity) : base(capacity) { initialzier_ = initialzier; } new public TValue this[TKey key] { get { if (ContainsKey(key) == false) { base[key] = initialzier_(key); } return base[key]; } set { base[key] = value; } } } public struct ModInt { public const long P = 1000000007; //public const long P = 998244353; public static ModInt Inverse(ModInt value) => Pow(value, P - 2); public static ModInt Pow(ModInt value, long k) => Pow(value.value_, k); public static ModInt Pow(long value, long k) { long ret = 1; for (k %= P - 1; k > 0; k >>= 1, value = value * value % P) { if ((k & 1) == 1) { ret = ret * value % P; } } return new ModInt(ret); } private long value_; public ModInt(long value) => value_ = value; public ModInt(long value, bool mods) { if (mods) { value %= P; if (value < 0) { value += P; } } value_ = value; } public static ModInt operator +(ModInt lhs, ModInt rhs) { lhs.value_ = (lhs.value_ + rhs.value_) % P; return lhs; } public static ModInt operator +(long lhs, ModInt rhs) { rhs.value_ = (lhs + rhs.value_) % P; return rhs; } public static ModInt operator +(ModInt lhs, long rhs) { lhs.value_ = (lhs.value_ + rhs) % P; return lhs; } public static ModInt operator -(ModInt lhs, ModInt rhs) { lhs.value_ = (P + lhs.value_ - rhs.value_) % P; return lhs; } public static ModInt operator -(long lhs, ModInt rhs) { rhs.value_ = (P + lhs - rhs.value_) % P; return rhs; } public static ModInt operator -(ModInt lhs, long rhs) { lhs.value_ = (P + lhs.value_ - rhs) % P; return lhs; } public static ModInt operator *(ModInt lhs, ModInt rhs) { lhs.value_ = lhs.value_ * rhs.value_ % P; return lhs; } public static ModInt operator *(long lhs, ModInt rhs) { rhs.value_ = lhs * rhs.value_ % P; return rhs; } public static ModInt operator *(ModInt lhs, long rhs) { lhs.value_ = lhs.value_ * rhs % P; return lhs; } public static ModInt operator /(ModInt lhs, ModInt rhs) { long exp = P - 2; while (exp > 0) { if (exp % 2 > 0) { lhs *= rhs; } rhs *= rhs; exp /= 2; } return lhs; } public static implicit operator ModInt(long n) => new ModInt(n, true); public long ToLong() => value_; public override string ToString() => value_.ToString(); } public static class Helper { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UpdateMin<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) > 0 ? value : target; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UpdateMin<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) > 0) { target = value; onUpdated(value); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UpdateMax<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) < 0 ? value : target; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UpdateMax<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) < 0) { target = value; onUpdated(value); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Array<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<T> List<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[,] Array2<T>(int n, int m, T init) where T : struct { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = init; } } return array; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[,] Array2<T>(int n, int m, Func<int, int, T> initializer) { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = initializer(i, j); } } return array; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[,,] Array3<T>(int n1, int n2, int n3, T init) where T : struct { var array = new T[n1, n2, n3]; for (int i1 = 0; i1 < n1; i1++) { for (int i2 = 0; i2 < n2; i2++) { for (int i3 = 0; i3 < n3; i3++) { array[i1, i2, i3] = init; } } } return array; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[,,,] Array4<T>(int n1, int n2, int n3, int n4, T init) where T : struct { var array = new T[n1, n2, n3, n4]; for (int i1 = 0; i1 < n1; i1++) { for (int i2 = 0; i2 < n2; i2++) { for (int i3 = 0; i3 < n3; i3++) { for (int i4 = 0; i4 < n4; i4++) { array[i1, i2, i3, i4] = init; } } } } return array; } private static readonly int[] delta4_ = { 1, 0, -1, 0, 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void DoAt4(int i, int j, int imax, int jmax, Action<int, int> action) { for (int dn = 0; dn < 4; dn++) { int d4i = i + delta4_[dn]; int d4j = j + delta4_[dn + 1]; if ((uint)d4i < (uint)imax && (uint)d4j < (uint)jmax) { action(d4i, d4j); } } } private static readonly int[] delta8_ = { 1, 0, -1, 0, 1, 1, -1, -1, 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void DoAt8(int i, int j, int imax, int jmax, Action<int, int> action) { for (int dn = 0; dn < 8; dn++) { int d8i = i + delta8_[dn]; int d8j = j + delta8_[dn + 1]; if ((uint)d8i < (uint)imax && (uint)d8j < (uint)jmax) { action(d8i, d8j); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void ForEachSubBit(int bit, Action<int> action) { for (int sub = bit; sub >= 0; sub--) { sub &= bit; action(sub); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Reverse(string src) { var chars = src.ToCharArray(); for (int i = 0, j = chars.Length - 1; i < j; i++, j--) { var tmp = chars[i]; chars[i] = chars[j]; chars[j] = tmp; } return new string(chars); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Join<T>(this IEnumerable<T> values, string separator = "") => string.Join(separator, values); } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private readonly Func<string> reader_; private string[] buf_; private int index_; public Scanner(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public string NextLine() => reader_(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Int() => int.Parse(Next()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Int(int offset) => int.Parse(Next()) + offset; [MethodImpl(MethodImplOptions.AggressiveInlining)] public (int, int) Int2(int offset = 0) => (Int(offset), Int(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public (int, int, int) Int3(int offset = 0) => (Int(offset), Int(offset), Int(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public (int, int, int, int) Int4(int offset = 0) => (Int(offset), Int(offset), Int(offset), Int(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int[] ArrayInt(int length, int offset = 0) { int[] Array = new int[length]; for (int i = 0; i < length; i++) { Array[i] = Int(offset); } return Array; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Long() => long.Parse(Next()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Long(long offset) => long.Parse(Next()) + offset; [MethodImpl(MethodImplOptions.AggressiveInlining)] public (long, long) Long2(long offset = 0) => (Long(offset), Long(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public (long, long, long) Long3(long offset = 0) => (Long(offset), Long(offset), Long(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public (long, long, long, long) Long4(long offset = 0) => (Long(offset), Long(offset), Long(offset), Long(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long[] ArrayLong(int length, long offset = 0) { long[] Array = new long[length]; for (int i = 0; i < length; i++) { Array[i] = Long(offset); } return Array; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public double Double() => double.Parse(Next()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public double Double(double offset) => double.Parse(Next()) + offset; [MethodImpl(MethodImplOptions.AggressiveInlining)] public (double, double) Double2(double offset = 0) => (Double(offset), Double(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public (double, double, double) Double3(double offset = 0) => (Double(offset), Double(offset), Double(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public (double, double, double, double) Double4(double offset = 0) => (Double(offset), Double(offset), Double(offset), Double(offset)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public double[] ArrayDouble(int length, double offset = 0) { double[] Array = new double[length]; for (int i = 0; i < length; i++) { Array[i] = Double(offset); } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
3,047
2
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; namespace AtCoderBeginnerContest177 { class Program { static void Main(string[] args) { // 課題B:Substring(2020/8/29) string reStr = Console.ReadLine(); string str = Console.ReadLine(); if (reStr.Contains(str)) { Console.Write(0); return; } int minCnt = str.Length; for (int i = 0; i < reStr.Length - str.Length; i++) { int cnt = 0; for (int j = 0; j < str.Length; j++) { if (!reStr[i + j].Equals(str[j])) cnt++; } if (minCnt > cnt) minCnt = cnt; } Console.Write(minCnt); } } }
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; namespace AtCoderBeginnerContest177 { class Program { static void Main(string[] args) { // 課題B:Substring(2020/8/29) string reStr = Console.ReadLine(); string str = Console.ReadLine(); if (reStr.Contains(str)) { Console.Write(0); return; } int minCnt = str.Length; for (int i = 0; i < reStr.Length - str.Length + 1; i++) { int cnt = 0; for (int j = 0; j < str.Length; j++) { if (!reStr[i + j].Equals(str[j])) cnt++; } if (minCnt > cnt) minCnt = cnt; } Console.Write(minCnt); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
170
2
using System; using System.Collections.Generic; namespace Sample { // 拡張クラス static class Sample { static void Main() { string s = Console.ReadLine(); string t = Console.ReadLine(); string[] sarr = s.MySplit(1); string[] tarr = t.MySplit(1); int score = tarr.Length; for (int i = 0; i < (sarr.Length - tarr.Length); i++) { int subcount = 0; for (int j = 0; j < tarr.Length; j++) { if (!sarr[i + j].Equals(tarr[j])) { subcount++; } } if (subcount < score) { score = subcount; } } Console.WriteLine(Convert.ToString(score)); } // 拡張メソッド static string[] MySplit(this string str, int count) { var list = new List<string>(); int length = (int)Math.Ceiling((double)str.Length / count); for (int i = 0; i < length; i++) { int start = count * i; if (str.Length <= start) { break; } if (str.Length < start + count) { list.Add(str.Substring(start)); } else { list.Add(str.Substring(start, count)); } } return list.ToArray(); } } }
using System; using System.Collections.Generic; namespace Sample { // 拡張クラス static class Sample { static void Main() { string s = Console.ReadLine(); string t = Console.ReadLine(); string[] sarr = s.MySplit(1); string[] tarr = t.MySplit(1); int score = tarr.Length; for (int i = 0; i <= (sarr.Length - tarr.Length); i++) { int subcount = 0; for (int j = 0; j < tarr.Length; j++) { if (!sarr[i + j].Equals(tarr[j])) { subcount++; } } if (subcount < score) { score = subcount; } } Console.WriteLine(Convert.ToString(score)); } // 拡張メソッド static string[] MySplit(this string str, int count) { var list = new List<string>(); int length = (int)Math.Ceiling((double)str.Length / count); for (int i = 0; i < length; i++) { int start = count * i; if (str.Length <= start) { break; } if (str.Length < start + count) { list.Add(str.Substring(start)); } else { list.Add(str.Substring(start, count)); } } return list.ToArray(); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
300
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace atcoder151 { public class MainClass { public static void Main(string[] args) { new MainClass().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { string s = cin.Read; string t = cin.Read; List<int> list = new List<int>(); // for (int i =0; i < t.Length;i++) { list.Add(0); //} bool one = false; if (s.Length == 1 && t.Length == 1) { one = true; } int num; for (int i = 0; i < s.Length - t.Length + 1; i++) { num = 0; int change = i; for (int j = 0; j < t.Length; j++) { // WriteLine(s[i]); // WriteLine(t[j]); if (s[change] == t[j]) { num++; // WriteLine(num); } // WriteLine("change is " + change); change++; } change = 0; // WriteLine("-----------------"); list.Add(num); } int ans; if (list.Max() == 0 && !one) { ans = 0; WriteLine(ans); } else if (one) { if (s != t) { WriteLine(1); } else { WriteLine(0); } } // WriteLine(list.Max()); else { ans = t.Length - list.Max(); WriteLine(ans); } // int i = t.Length; // int p = 0; // while (i < s.Length) //{ // // パターン末尾に位置を合わせる // p = t.Length - 1; // while (p >= 0 && i < s.Length) // { // if (s[i] == t[p]) // { // i--; p--; // } // else // { // break; // } // } //} ////string[] array = Console.ReadLine().Split(' ').ToArray(); // int n = int.Parse(Console.ReadLine()); ////Console.WriteLine(n); // int[] num_array = cin.ReadIntArray(n); // List<int> list = new List<int>(); // int min = num_array[0]; ////WriteLine(min); // for (int i =0; i< n; i++) { // if (num_array[i] == min) { // list.Add(0); // } // else if (num_array[i] > min) { // //list.Add(0); // min = num_array[i]; // list.Add(0); // } else if (num_array[i] < min) { // list.Add(min - num_array[i]); // } //} // WriteLine(list.Sum()); } public class ConsoleInput { // string[] arr; // int x; // int y; // for (int i = 0; i<n; i++) // { // arr = Console.ReadLine().Split(' ').ToArray(); // x = int.Parse(arr[0]); // y = int.Parse(arr[1]); // var power = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)); // if (power <= d) // { // counter++; // } // } private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace atcoder151 { public class MainClass { public static void Main(string[] args) { new MainClass().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { string s = cin.Read; string t = cin.Read; List<int> list = new List<int>(); // for (int i =0; i < t.Length;i++) { list.Add(0); //} bool one = false; if (s.Length == 1 && t.Length == 1) { one = true; } int num; for (int i = 0; i < s.Length - t.Length + 1; i++) { num = 0; int change = i; for (int j = 0; j < t.Length; j++) { // WriteLine(s[i]); // WriteLine(t[j]); if (s[change] == t[j]) { num++; // WriteLine(num); } // WriteLine("change is " + change); change++; } change = 0; // WriteLine("-----------------"); list.Add(num); } int ans; if (list.Max() == 0 && !one) { ans = t.Length; WriteLine(ans); } else if (one) { if (s != t) { WriteLine(1); } else { WriteLine(0); } } // WriteLine(list.Max()); // else if (list.Max() == 0) //{ // ans = //} else { ans = t.Length - list.Max(); WriteLine(ans); } // int i = t.Length; // int p = 0; // while (i < s.Length) //{ // // パターン末尾に位置を合わせる // p = t.Length - 1; // while (p >= 0 && i < s.Length) // { // if (s[i] == t[p]) // { // i--; p--; // } // else // { // break; // } // } //} ////string[] array = Console.ReadLine().Split(' ').ToArray(); // int n = int.Parse(Console.ReadLine()); ////Console.WriteLine(n); // int[] num_array = cin.ReadIntArray(n); // List<int> list = new List<int>(); // int min = num_array[0]; ////WriteLine(min); // for (int i =0; i< n; i++) { // if (num_array[i] == min) { // list.Add(0); // } // else if (num_array[i] > min) { // //list.Add(0); // min = num_array[i]; // list.Add(0); // } else if (num_array[i] < min) { // list.Add(min - num_array[i]); // } //} // WriteLine(list.Sum()); } public class ConsoleInput { // string[] arr; // int x; // int y; // for (int i = 0; i<n; i++) // { // arr = Console.ReadLine().Split(' ').ToArray(); // x = int.Parse(arr[0]); // y = int.Parse(arr[1]); // var power = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)); // if (power <= d) // { // counter++; // } // } private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 141, 22]]
8
704
4
using System; class Program { static void Main(string[] args) {    string S = Console.ReadLine(); //標準入力    string T = Console.ReadLine(); //標準入力 int S_length = S.Length; int T_length = T.Length; int maxlength = 0; for (int i = 0; i < S_length - T_length; i++) { int count = 0; for (int j = 0; j < T_length; j++) { if (S.Substring(i + j, 1) == T.Substring(j, 1)) { count++; } } if (maxlength < count) { maxlength = count; } } Console.WriteLine("{0}", T_length - maxlength); } }
using System; class Program { static void Main(string[] args) {    string S = Console.ReadLine(); //標準入力    string T = Console.ReadLine(); //標準入力 int S_length = S.Length; int T_length = T.Length; int maxlength = 0; for (int i = 0; i < S_length - T_length + 1; i++) { int count = 0; for (int j = 0; j < T_length; j++) { if (S.Substring(i + j, 1) == T.Substring(j, 1)) { count++; } } if (maxlength < count) { maxlength = count; } } Console.WriteLine("{0}", T_length - maxlength); } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
150
2
// // ABC177B // URL : // using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; namespace AtCoder.Template.ABC177B { class Solver { public static readonly long MOD_CONST = 1000000007; //(long)Math.Pow(10, 9) + 7; public static void Main(string[] args) { //出力高速化 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } public void Solve() { string S = Console.ReadLine(); string T = Console.ReadLine(); int longestMatchCnt = 0; for (int i = 0; i < S.Length - T.Length; ++i) { int matchCnt = 0; // S[i]からの部分文字列とTを比較 for (int it = 0; it < T.Length; ++it) { if (S[i + it] == T[it]) { //マッチ数をカウント matchCnt++; } } if (matchCnt > longestMatchCnt) { longestMatchCnt = matchCnt; } } //最大マッチ数がわかったので答えを出す Console.WriteLine(Math.Max(T.Length - longestMatchCnt, 0)); } //--------------------------------------------------------------------------------- #region MyLib /// <summary> /// string -> List<char>に分解する。1文字がListの1要素 /// </summary> /// <param name="a"></param> /// <returns></returns> public static List<char> separeteToList(string a) { var l = new List<char>(a.Length); foreach (char x in a) { l.Add(x); } return l; } /// <summary> /// List<char> -> stringに合成する /// </summary> /// <param name="l"></param> /// <returns></returns> public static string combineCharList(List<char> l) { var ans = new StringBuilder(); foreach (char x in l) { ans.Append(x); } return ans.ToString(); } /// <summary> /// Aの文字をなるべくCorrectに合うように並びかえる。当然Correctにしかない文字もあるので、その場合はAの適当な文字で置き換える /// 例) /// A = abcde, eppstein /// Corrent = acfbe, pipeline /// ans = acdbe, pspetine /// </summary> /// <param name="A"></param> /// <param name="Correct"></param> public static List<char> FillChar(List<char> A, List<char> Correct) { char Empty = ' '; var ARemain = new List<char>(A); var ans = new List<char>(A.Count); for (int i = 0; i < Correct.Count; ++i) { // Aの文字をなるべくCorrectに合うように、ansの文字を決める int foundPos = ARemain.FindIndex(x => x == Correct[i]); if (foundPos != -1) //文字がCorrectの中で見つかったら { char found = ARemain[foundPos]; ans.Add(found); ARemain.Remove(found); //使った文字は除外 } else // Aにない文字もある。後で使わなかったAの適当な文字で埋める { ans.Add(Empty); } } // Aにない文字がCorrectにあったら、Aの残りの文字で適当に埋める for (int i = 0; i < A.Count; ++i) { if (ans[i] == Empty) { ans[i] = ARemain.First(); ARemain.RemoveAt(0); } } return ans; } /// <summary> /// リストから、重複したものを除外したリストを新規に作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="src"></param> /// <param name="dst"></param> public static void getDistinctList<T>(List<T> src, out List<T> dst) { var iter = src.Distinct(); dst = new List<T>(); foreach (var item in iter) { dst.Add(item); } } /// <summary> /// グラフ系 /// </summary> public class Node { public Node(long val) { this.Value = val; this.Children = new List<Node>(); } public Node(long val, List<Node> children) { this.Value = val; this.Children = children; } public long Value { get; set; } public List<Node> Children { get; set; } } /// <summary> /// Clamping /// </summary> /// <typeparam name="T">比較型</typeparam> /// <param name="x">clampしたい値</param> /// <param name="min">最小値</param> /// <param name="max">最大値</param> /// <returns>clamp済みの値</returns> public static T Clamp<T>(T x, T min, T max) where T : IComparable<T> { if (x.CompareTo(min) < 0) { return min; } else if (x.CompareTo(max) > 0) { return max; } else return x; // return Math.Max(Math.Min(x, max), min); } /// <summary> /// 指定された底log_baseでの, 対数を計算 /// </summary> /// <param name="x"></param> /// <param name="log_base">指定の底</param> /// <returns></returns> public static double LogBase(double x, double log_base) { // log_b(N) = log_a(N) / log_a(B)より return Math.Log(x) / Math.Log(log_base); } /// <summary> /// 初項a, 公差d, 項数nの数列の和 /// </summary> /// <param name="n">求めたいところ</param> /// <returns>初項からxまで足した値</returns> static long SumSeries(long a, long d, long n) { return (2 * a + (n - 1) * d) * n / 2; } /// <summary> /// 累積和の配列を計算する /// Sum[ a[0], a[i] )がs[i+1]に入っている /// s[0] : 0 //一切和を取らない場合 /// s[1] : ls[0] //a[0] + s[0] = a[0] /// s[2] : ls[1] + s[1] //a[1] + a[0] /// ... /// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0] /// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0] /// /// 例: [1, 7)の和(a[1] + ... + a[6]) /// s[1] = a[0] //[0, 1) /// s[7] = a[0] + a[1] + ... + a[6] //[0, 7) /// よってs[7] - s[1]); /// </summary> /// <param name="ls">計算したい配列</param> /// <returns>累積和配列</returns> static List<long> AggregateSumList(List<long> a) { var s = new List<long>(a.Count + 1); if (a.Count == 0) { return s; } s.Add(0); // s[0] = 0 for (int i = 0; i < a.Count; ++i) { s.Add(a[i] + s[i]); } return s; } /// <summary> /// 与えられた数が素数かどうかを計算する /// </summary> /// <param name="num">対象数</param> /// <returns>true:素数, false:素数ではない(合成数)</returns> public static bool isPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } /// <summary> /// 素因数分解 /// </summary> /// <param name="n"></param> /// <returns>keyが素数、valueがその素数の登場回数</returns> public static Dictionary<long, long> PrimeFactorization(long n) { var result = new Dictionary<long, long>(); //初めの素数2から割っていく for (long p = 2; p * p <= n; p++) { //割り切れないなら、素因数に含まれてない if (n % p != 0) continue; long count = 0; // 割り続ける while (n % p == 0) { count++; n /= p; } result[p] = count; } // 素数が残っている場合 if (n != 1) result[n] = 1; return result; } /// <summary> /// 順列mPnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Permutation(long m, long n) { long ret = 1; for (var i = 0; i < n; ++i) { ret *= m - i; } return ret; } /// <summary> /// 組み合わせmCnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Combination(long m, long n) { if (m == n || n == 0) { return 1; } long ans = 1; for (var i = 1; i <= n; ++i) { ans = ans * (m - i + 1) / i; } return ans; } static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } static long Lcm(long m, long n) { var gcd = Gcd(m, n); // return (m * n) / gcd; return m / gcd * n; //桁あふれ対策 } #endregion MyLib } }
// // ABC177B // URL : // using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; namespace AtCoder.Template.ABC177B { class Solver { public static readonly long MOD_CONST = 1000000007; //(long)Math.Pow(10, 9) + 7; public static void Main(string[] args) { //出力高速化 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } public void Solve() { string S = Console.ReadLine(); string T = Console.ReadLine(); int longestMatchCnt = 0; for (int i = 0; i < S.Length - T.Length + 1; ++i) { int matchCnt = 0; // S[i]からの部分文字列とTを比較 for (int it = 0; it < T.Length; ++it) { if (S[i + it] == T[it]) { //マッチ数をカウント matchCnt++; } } if (matchCnt > longestMatchCnt) { longestMatchCnt = matchCnt; } } //最大マッチ数がわかったので答えを出す Console.WriteLine(Math.Max(T.Length - longestMatchCnt, 0)); } //--------------------------------------------------------------------------------- #region MyLib /// <summary> /// string -> List<char>に分解する。1文字がListの1要素 /// </summary> /// <param name="a"></param> /// <returns></returns> public static List<char> separeteToList(string a) { var l = new List<char>(a.Length); foreach (char x in a) { l.Add(x); } return l; } /// <summary> /// List<char> -> stringに合成する /// </summary> /// <param name="l"></param> /// <returns></returns> public static string combineCharList(List<char> l) { var ans = new StringBuilder(); foreach (char x in l) { ans.Append(x); } return ans.ToString(); } /// <summary> /// Aの文字をなるべくCorrectに合うように並びかえる。当然Correctにしかない文字もあるので、その場合はAの適当な文字で置き換える /// 例) /// A = abcde, eppstein /// Corrent = acfbe, pipeline /// ans = acdbe, pspetine /// </summary> /// <param name="A"></param> /// <param name="Correct"></param> public static List<char> FillChar(List<char> A, List<char> Correct) { char Empty = ' '; var ARemain = new List<char>(A); var ans = new List<char>(A.Count); for (int i = 0; i < Correct.Count; ++i) { // Aの文字をなるべくCorrectに合うように、ansの文字を決める int foundPos = ARemain.FindIndex(x => x == Correct[i]); if (foundPos != -1) //文字がCorrectの中で見つかったら { char found = ARemain[foundPos]; ans.Add(found); ARemain.Remove(found); //使った文字は除外 } else // Aにない文字もある。後で使わなかったAの適当な文字で埋める { ans.Add(Empty); } } // Aにない文字がCorrectにあったら、Aの残りの文字で適当に埋める for (int i = 0; i < A.Count; ++i) { if (ans[i] == Empty) { ans[i] = ARemain.First(); ARemain.RemoveAt(0); } } return ans; } /// <summary> /// リストから、重複したものを除外したリストを新規に作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="src"></param> /// <param name="dst"></param> public static void getDistinctList<T>(List<T> src, out List<T> dst) { var iter = src.Distinct(); dst = new List<T>(); foreach (var item in iter) { dst.Add(item); } } /// <summary> /// グラフ系 /// </summary> public class Node { public Node(long val) { this.Value = val; this.Children = new List<Node>(); } public Node(long val, List<Node> children) { this.Value = val; this.Children = children; } public long Value { get; set; } public List<Node> Children { get; set; } } /// <summary> /// Clamping /// </summary> /// <typeparam name="T">比較型</typeparam> /// <param name="x">clampしたい値</param> /// <param name="min">最小値</param> /// <param name="max">最大値</param> /// <returns>clamp済みの値</returns> public static T Clamp<T>(T x, T min, T max) where T : IComparable<T> { if (x.CompareTo(min) < 0) { return min; } else if (x.CompareTo(max) > 0) { return max; } else return x; // return Math.Max(Math.Min(x, max), min); } /// <summary> /// 指定された底log_baseでの, 対数を計算 /// </summary> /// <param name="x"></param> /// <param name="log_base">指定の底</param> /// <returns></returns> public static double LogBase(double x, double log_base) { // log_b(N) = log_a(N) / log_a(B)より return Math.Log(x) / Math.Log(log_base); } /// <summary> /// 初項a, 公差d, 項数nの数列の和 /// </summary> /// <param name="n">求めたいところ</param> /// <returns>初項からxまで足した値</returns> static long SumSeries(long a, long d, long n) { return (2 * a + (n - 1) * d) * n / 2; } /// <summary> /// 累積和の配列を計算する /// Sum[ a[0], a[i] )がs[i+1]に入っている /// s[0] : 0 //一切和を取らない場合 /// s[1] : ls[0] //a[0] + s[0] = a[0] /// s[2] : ls[1] + s[1] //a[1] + a[0] /// ... /// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0] /// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0] /// /// 例: [1, 7)の和(a[1] + ... + a[6]) /// s[1] = a[0] //[0, 1) /// s[7] = a[0] + a[1] + ... + a[6] //[0, 7) /// よってs[7] - s[1]); /// </summary> /// <param name="ls">計算したい配列</param> /// <returns>累積和配列</returns> static List<long> AggregateSumList(List<long> a) { var s = new List<long>(a.Count + 1); if (a.Count == 0) { return s; } s.Add(0); // s[0] = 0 for (int i = 0; i < a.Count; ++i) { s.Add(a[i] + s[i]); } return s; } /// <summary> /// 与えられた数が素数かどうかを計算する /// </summary> /// <param name="num">対象数</param> /// <returns>true:素数, false:素数ではない(合成数)</returns> public static bool isPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } /// <summary> /// 素因数分解 /// </summary> /// <param name="n"></param> /// <returns>keyが素数、valueがその素数の登場回数</returns> public static Dictionary<long, long> PrimeFactorization(long n) { var result = new Dictionary<long, long>(); //初めの素数2から割っていく for (long p = 2; p * p <= n; p++) { //割り切れないなら、素因数に含まれてない if (n % p != 0) continue; long count = 0; // 割り続ける while (n % p == 0) { count++; n /= p; } result[p] = count; } // 素数が残っている場合 if (n != 1) result[n] = 1; return result; } /// <summary> /// 順列mPnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Permutation(long m, long n) { long ret = 1; for (var i = 0; i < n; ++i) { ret *= m - i; } return ret; } /// <summary> /// 組み合わせmCnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Combination(long m, long n) { if (m == n || n == 0) { return 1; } long ans = 1; for (var i = 1; i <= n; ++i) { ans = ans * (m - i + 1) / i; } return ans; } static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } static long Lcm(long m, long n) { var gcd = Gcd(m, n); // return (m * n) / gcd; return m / gcd * n; //桁あふれ対策 } #endregion MyLib } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
1,317
2
using System; public class Program { public static void Main(string[] args) { string s = Console.ReadLine(); string t = Console.ReadLine(); var sLength = s.Length; var tLength = t.Length; var ans = tLength; var pos = 0; while (pos + tLength < sLength) { var current = s.Substring(pos, tLength); var match = 0; for (int i = 0; i < tLength; i++) { if (current[i].Equals(t[i])) match++; } if (ans > tLength - match) ans = tLength - match; pos++; } Console.WriteLine(ans); } }
using System; public class Program { public static void Main(string[] args) { string s = Console.ReadLine(); string t = Console.ReadLine(); var sLength = s.Length; var tLength = t.Length; var ans = tLength; var pos = 0; while (pos + tLength <= sLength) { var current = s.Substring(pos, tLength); var match = 0; for (int i = 0; i < tLength; i++) { if (current[i].Equals(t[i])) match++; } if (ans > tLength - match) ans = tLength - match; pos++; } Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
8
147
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; namespace AtCoder { static class Program_D { class Solver { int ri => sc.Integer(); long rl => sc.Long(); double rd => sc.Double(); string rs => sc.Scan(); public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); public void Solve() { var s = rs; var t = rs; int maxSame = 0; for (int i = 0; i < s.Length - t.Length; ++i) { maxSame = Math.Max(maxSame, SameChar(s, t, i)); } Wl(t.Length - maxSame); } int SameChar(string s, string t, int index) { int count = 0; for (int i = 0; i < t.Length; ++i) { if (s[index + i] == t[i]) count++; } return count; } // ---------------------------------------------------------------------------- static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } string Rl() { return Console.ReadLine(); } void Wl(UInt64 val) { Console.WriteLine(val); } void Wl(Int64 val) { Console.WriteLine(val); } void Wl(uint val) { Console.WriteLine(val); } void Wl(int val) { Console.WriteLine(val); } void Wl(double val) { Console.WriteLine(val); } void Wl(string mes) { Console.WriteLine(mes); } public int Int() { return int.Parse(Console.ReadLine()); } public int[] Ints(int subtract) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) - subtract) .ToArray(); } public Int64[] Int64s(Int64 subtract) { return Console.ReadLine() .Split(' ') .Select(s => Int64.Parse(s) - subtract) .ToArray(); } public UInt64[] UInt64s(UInt64 subtract) { return Console.ReadLine() .Split(' ') .Select(s => UInt64.Parse(s) - subtract) .ToArray(); } } static void Main(string[] args) { Console.SetOut( new Printer(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(); Console.Out.Flush(); } } public class Printer : StreamWriter { public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture; public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } struct ModInt { const int MOD = 1000000007; long Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt modInt) => modInt.Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long val) => new ModInt(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) { long res = a.Data + b.Data; return new ModInt() { Data = res >= MOD ? res - MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, long b) => a.Data + b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, long b) => a.Data - b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => Data.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GetInverse(long a) { long div; long p = MOD; long x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; namespace AtCoder { static class Program_D { class Solver { int ri => sc.Integer(); long rl => sc.Long(); double rd => sc.Double(); string rs => sc.Scan(); public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); public void Solve() { var s = rs; var t = rs; int maxSame = 0; for (int i = 0; i <= s.Length - t.Length; ++i) { // Wl(i); maxSame = Math.Max(maxSame, SameChar(s, t, i)); } Wl(t.Length - maxSame); } int SameChar(string s, string t, int index) { int count = 0; for (int i = 0; i < t.Length; ++i) { if (s[index + i] == t[i]) count++; } return count; } // ---------------------------------------------------------------------------- static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } string Rl() { return Console.ReadLine(); } void Wl(UInt64 val) { Console.WriteLine(val); } void Wl(Int64 val) { Console.WriteLine(val); } void Wl(uint val) { Console.WriteLine(val); } void Wl(int val) { Console.WriteLine(val); } void Wl(double val) { Console.WriteLine(val); } void Wl(string mes) { Console.WriteLine(mes); } public int Int() { return int.Parse(Console.ReadLine()); } public int[] Ints(int subtract) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) - subtract) .ToArray(); } public Int64[] Int64s(Int64 subtract) { return Console.ReadLine() .Split(' ') .Select(s => Int64.Parse(s) - subtract) .ToArray(); } public UInt64[] UInt64s(UInt64 subtract) { return Console.ReadLine() .Split(' ') .Select(s => UInt64.Parse(s) - subtract) .ToArray(); } } static void Main(string[] args) { Console.SetOut( new Printer(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(); Console.Out.Flush(); } } public class Printer : StreamWriter { public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture; public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } struct ModInt { const int MOD = 1000000007; long Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt modInt) => modInt.Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long val) => new ModInt(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) { long res = a.Data + b.Data; return new ModInt() { Data = res >= MOD ? res - MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, long b) => a.Data + b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, long b) => a.Data - b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => Data.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GetInverse(long a) { long div; long p = MOD; long x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
1,392
2
using System; using System.Linq; namespace AtCoderTutorial { public class AtCoder176 { public static void Main(string[] args) { // long[] HW = Console.ReadLine().Split(' ').Select(_ => // long.Parse(_)).ToArray(); long[] C = // Console.ReadLine().Split(' ').Select(_ => // long.Parse(_)).ToArray(); long[] D = // Console.ReadLine().Split(' ').Select(_ => // long.Parse(_)).ToArray(); string S = Console.ReadLine(); string T = Console.ReadLine(); int maxMatchNum = 0; if (S.Contains(T)) { maxMatchNum = T.Length; } for (int i = 0; i < S.Length - T.Length; i++) { int matchNum = 0; char[] subS = S.Substring(i, T.Length).ToCharArray(); char[] charT = T.ToCharArray(); for (int j = 0; j < subS.Length; j++) { if (subS[j] == charT[j]) { matchNum++; } } if (matchNum > maxMatchNum) { maxMatchNum = matchNum; } } Console.WriteLine(T.Length - maxMatchNum); } } }
using System; using System.Linq; namespace AtCoderTutorial { public class AtCoder176 { public static void Main(string[] args) { // long[] HW = Console.ReadLine().Split(' ').Select(_ => // long.Parse(_)).ToArray(); long[] C = // Console.ReadLine().Split(' ').Select(_ => // long.Parse(_)).ToArray(); long[] D = // Console.ReadLine().Split(' ').Select(_ => // long.Parse(_)).ToArray(); string S = Console.ReadLine(); string T = Console.ReadLine(); int maxMatchNum = 0; if (S.Contains(T)) { maxMatchNum = T.Length; } for (int i = 0; i <= S.Length - T.Length; i++) { int matchNum = 0; char[] subS = S.Substring(i, T.Length).ToCharArray(); char[] charT = T.ToCharArray(); for (int j = 0; j < subS.Length; j++) { if (subS[j] == charT[j]) { matchNum++; } } if (matchNum > maxMatchNum) { maxMatchNum = matchNum; } } Console.WriteLine(T.Length - maxMatchNum); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
191
2
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.IO; using System.Text; using N = System.Int32; static class Program { static public void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } } public class Solver { public void Solve() { string s = rs, t = rs; N x = 0, m = 0; for (int i = 0; i < s.Length - t.Length; i++) { x = 0; for (int j = 0; j < t.Length; j++) { if (s[i + j] == t[j]) x++; } if (x > m) m = x; } Write(t.Length - m); } N rn { get { return sc.Integer(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); void Write<T>(T t) { Console.WriteLine(t.ToString()); } void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public N Integer() { N ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public double Double() { return double.Parse(Scan()); } }
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.IO; using System.Text; using N = System.Int32; static class Program { static public void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } } public class Solver { public void Solve() { string s = rs, t = rs; N x = 0, m = 0; for (int i = 0; i <= s.Length - t.Length; i++) { x = 0; for (int j = 0; j < t.Length; j++) { if (s[i + j] == t[j]) x++; } if (x > m) m = x; } Write(t.Length - m); } N rn { get { return sc.Integer(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); void Write<T>(T t) { Console.WriteLine(t.ToString()); } void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public N Integer() { N ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public double Double() { return double.Parse(Scan()); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
703
2
using System; using System.Linq; namespace AtCoder.Abcdef { public class QuestionB { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // Input string string s = Console.ReadLine(); string t = Console.ReadLine(); var ans = int.MaxValue; var diff = s.Length - t.Length; for (int i = 0; i < diff; i++) { var flags = new bool[t.Length]; for (int j = 0; j < t.Length; j++) { if (s[j + i] != t[j]) flags[j] = true; } ans = Math.Min(ans, flags.Where(item => item).Count()); } Console.WriteLine(ans); Console.Out.Flush(); } } }
using System; using System.Linq; namespace AtCoder.Abcdef { public class QuestionB { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // Input string string s = Console.ReadLine(); string t = Console.ReadLine(); var ans = int.MaxValue; var diff = s.Length - t.Length; for (int i = 0; i <= diff; i++) { var flags = new bool[t.Length]; for (int j = 0; j < t.Length; j++) { if (s[j + i] != t[j]) flags[j] = true; } ans = Math.Min(ans, flags.Where(item => item).Count()); } Console.WriteLine(ans); Console.Out.Flush(); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
200
2
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; namespace abc177 { class Program { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); if (File.Exists("input.txt")) { Console.SetIn(new StreamReader("input.txt")); } solve_abc177B(); Console.Out.Flush(); } public static void solve_abc177B() { string s = Console.ReadLine(); string t = Console.ReadLine(); int min = int.MaxValue; for (int i = 0; i < s.Length - t.Length; i++) { int cnt = 0; int j = 0; while (j < t.Length) { if (s[i + j] != t[j]) { cnt++; } j++; } min = Math.Min(min, cnt); } Console.WriteLine(min); } public static void solve_abc177A() { int[] dts = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int d = dts[0]; int t = dts[1]; int s = dts[2]; double taken = (double)d / s; Console.WriteLine(taken > t ? "No" : "Yes"); } public static int binSerachLeft(int[] a, int x) { int l = -1; int r = a.Length; while (r > l + 1) { int m = (l + r) / 2; if (a[m] <= x) { l = m; } else { r = m; } } return l; } } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; namespace abc177 { class Program { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); if (File.Exists("input.txt")) { Console.SetIn(new StreamReader("input.txt")); } solve_abc177B(); Console.Out.Flush(); } public static void solve_abc177B() { string s = Console.ReadLine(); string t = Console.ReadLine(); int min = 10001; for (int i = 0; i < s.Length - t.Length + 1; i++) { int cnt = 0; int j = 0; while (j < t.Length) { if (s[i + j] != t[j]) { cnt++; } j++; } min = Math.Min(min, cnt); } Console.WriteLine(min); } public static void solve_abc177A() { int[] dts = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int d = dts[0]; int t = dts[1]; int s = dts[2]; double taken = (double)d / s; Console.WriteLine(taken > t ? "No" : "Yes"); } public static int binSerachLeft(int[] a, int x) { int l = -1; int r = a.Length; while (r > l + 1) { int m = (l + r) / 2; if (a[m] <= x) { l = m; } else { r = m; } } return l; } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
379
6
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Numerics; class Util { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { string S = rs(); string T = rs(); int ans = T.Length; for (int i = 0; i < S.Length - T.Length; i++) { int diffCnt = 0; for (int j = 0; j < T.Length; j++) { if (S[i + j] != T[j]) diffCnt++; } ans = Math.Min(ans, diffCnt); } Console.WriteLine(ans); Console.ReadLine(); } 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)); } static int[] generateNums(int num, int N) { return Enumerable.Repeat(num, N).ToArray(); } static int[] generateSuretsu(int N) { return Enumerable.Range(0, N).ToArray(); } } public static class Combination { //使い方:int[][] Is = Combination.Enumerate(nums, k, //withRepetition:false).ToArray(); public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition) { if (k == 1) { foreach (var item in items) yield return new T[] { item }; yield break; } foreach (var item in items) { var leftside = new T[] { item }; // item よりも前のものを除く (順列と組み合わせの違い) // 重複を許さないので、unusedから item そのものも取り除く var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList(); foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) { yield return leftside.Concat(rightside).ToArray(); } } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Numerics; class Util { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { string S = rs(); string T = rs(); int ans = T.Length; for (int i = 0; i < S.Length - T.Length + 1; i++) { int diffCnt = 0; for (int j = 0; j < T.Length; j++) { if (S[i + j] != T[j]) diffCnt++; } ans = Math.Min(ans, diffCnt); } Console.WriteLine(ans); Console.ReadLine(); } 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)); } static int[] generateNums(int num, int N) { return Enumerable.Repeat(num, N).ToArray(); } static int[] generateSuretsu(int N) { return Enumerable.Range(0, N).ToArray(); } } public static class Combination { //使い方:int[][] Is = Combination.Enumerate(nums, k, //withRepetition:false).ToArray(); public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition) { if (k == 1) { foreach (var item in items) yield return new T[] { item }; yield break; } foreach (var item in items) { var leftside = new T[] { item }; // item よりも前のものを除く (順列と組み合わせの違い) // 重複を許さないので、unusedから item そのものも取り除く var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList(); foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) { yield return leftside.Concat(rightside).ToArray(); } } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
594
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.B { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var S = ReadText().ToCharArray(); var T = ReadText().ToCharArray(); var tcount = T.Length; var max = 0; for (var i = 0; i < S.Length - tcount; i++) { max = Math.Max(max, SameCount(S, T, i)); } return tcount - max; } private static int SameCount(char[] s, char[] t, int i) { var count = 0; for (var j = 0; j < t.Length; j++) { if (t[j] == s[i + j]) { count++; } } return count; } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.B { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var S = ReadText().ToCharArray(); var T = ReadText().ToCharArray(); var tcount = T.Length; var max = 0; for (var i = 0; i <= S.Length - tcount; i++) { max = Math.Max(max, SameCount(S, T, i)); } return tcount - max; } private static int SameCount(char[] s, char[] t, int i) { var count = 0; for (var j = 0; j < t.Length; j++) { if (t[j] == s[i + j]) { count++; } } return count; } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
490
2
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; namespace contest_Csharp { class Program { public static (long m, long s)[,] dp; static void Main(string[] args) { // checked { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); /*var vals = Console.ReadLine().Split(' '). Select(x => int.Parse(x)).ToList(); var D = vals[0]; var T = vals[1]; var S = vals[2];*/ var S = Console.ReadLine(); var D = Console.ReadLine(); var ans = D.Length; for (int i = 0; i < S.Length - D.Length; i++) { var na = 0; var sb = S.Substring(i, D.Length); for (int k = 0; k < D.Length; k++) { if (sb[k] != D[k]) na++; } ans = Math.Min(na, ans); } Console.WriteLine(ans); Console.Out.Flush(); } } } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; namespace contest_Csharp { class Program { public static (long m, long s)[,] dp; static void Main(string[] args) { checked { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); /*var vals = Console.ReadLine().Split(' '). Select(x => int.Parse(x)).ToList(); var D = vals[0]; var T = vals[1]; var S = vals[2];*/ var S = Console.ReadLine(); var D = Console.ReadLine(); var ans = D.Length; for (int i = 0; i < S.Length - D.Length + 1; i++) { var na = 0; var sb = S.Substring(i, D.Length); for (int k = 0; k < D.Length; k++) { if (sb[k] != D[k]) na++; } ans = Math.Min(na, ans); } Console.WriteLine(ans); Console.Out.Flush(); } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 287, 0, 292], ["+", 0, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 0, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
216
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { char[] s = Console.ReadLine().ToCharArray(); char[] t = Console.ReadLine().ToCharArray(); int cntMax = 0; for (int i = 0; i < s.Length - t.Length; i++) { int cnt = 0; for (int j = 0; j < t.Length; j++) { if (s[i + j].Equals(t[j])) { cnt++; } } if (cnt > cntMax) cntMax = cnt; } Console.WriteLine(t.Length - cntMax); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { char[] s = Console.ReadLine().ToCharArray(); char[] t = Console.ReadLine().ToCharArray(); int cntMax = 0; for (int i = 0; i <= s.Length - t.Length; i++) { int cnt = 0; for (int j = 0; j < t.Length; j++) { if (s[i + j].Equals(t[j])) { cnt++; } } if (cnt > cntMax) cntMax = cnt; } Console.WriteLine(t.Length - cntMax); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
162
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace atcoder { public class Program { public static void Main(string[] args) { var S = Console.ReadLine(); var T = Console.ReadLine(); var ans = int.MaxValue; for (int i = 0; i < S.Length - T.Length; i++) { var cnt = 0; for (int j = 0; j < T.Length; j++) { if (S[i + j] != T[j]) cnt++; } if (cnt < ans) ans = cnt; } Console.WriteLine(ans == int.MaxValue ? 0 : ans); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace atcoder { public class Program { public static void Main(string[] args) { var S = Console.ReadLine(); var T = Console.ReadLine(); var ans = int.MaxValue; for (int i = 0; i < S.Length - T.Length + 1; i++) { var cnt = 0; for (int j = 0; j < T.Length; j++) { if (S[i + j] != T[j]) cnt++; } if (cnt < ans) ans = cnt; } Console.WriteLine(ans == int.MaxValue ? 0 : ans); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
153
2
using System; using System.Linq; class Program { static void Main(string[] args) { var s = Console.ReadLine().ToCharArray(); var t = Console.ReadLine().ToCharArray(); int ans = 0; for (int i = 0; i < s.Length - t.Length; i++) { int count = 0; for (int j = 0; j < t.Length; j++) { if (s[i + j] == t[j]) count++; } ans = Math.Max(ans, count); } Console.WriteLine(t.Length - ans); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static string[] ReadStringArray() { return Console.ReadLine().Split(' '); } static int[] ReadIntArray() { return ReadStringArray().Select(i => int.Parse(i)).ToArray(); } }
using System; using System.Linq; class Program { static void Main(string[] args) { var s = Console.ReadLine().ToCharArray(); var t = Console.ReadLine().ToCharArray(); int ans = 0; for (int i = 0; i <= s.Length - t.Length; i++) { int count = 0; for (int j = 0; j < t.Length; j++) { if (s[i + j] == t[j]) count++; } ans = Math.Max(ans, count); } Console.WriteLine(t.Length - ans); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static string[] ReadStringArray() { return Console.ReadLine().Split(' '); } static int[] ReadIntArray() { return ReadStringArray().Select(i => int.Parse(i)).ToArray(); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
210
2
using System; namespace B { class Program { static void Main(string[] args) { var s = Console.ReadLine(); var t = Console.ReadLine(); int max = t.Length; for (var i = 0; i < s.Length - t.Length; i++) { int val = 0; for (var j = 0; j < t.Length; j++) { if (s[i + j] == t[j]) val++; } if (t.Length - val < max) max = t.Length - val; } Console.WriteLine(max); } } }
using System; namespace B { class Program { static void Main(string[] args) { var s = Console.ReadLine(); var t = Console.ReadLine(); int max = t.Length; for (var i = 0; i <= s.Length - t.Length; i++) { int val = 0; for (var j = 0; j < t.Length; j++) { if (s[i + j] == t[j]) val++; } if (t.Length - val < max) max = t.Length - val; } Console.WriteLine(max); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
134
2
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 s = cin.next(); var t = cin.next(); var ans = long.MaxValue; for (int i = 0; i < s.Length - t.Length; i++) { var count = 0L; for (int j = 0; j < t.Length; j++) { if (s[i + j] != t[j]) count++; } ans = Math.Min(ans, count); } Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var s = cin.next(); var t = cin.next(); var ans = long.MaxValue; for (int i = 0; i <= s.Length - t.Length; i++) { var count = 0L; for (int j = 0; j < t.Length; j++) { if (s[i + j] != t[j]) count++; } ans = Math.Min(ans, count); } Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
644
2
using System.Linq; using System.Text; using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Diagnostics; using System.Threading; using System.Runtime.CompilerServices; using System.IO.Pipes; namespace AtCoder { class Program { struct Point { public int x; public int y; public Point(int x, int y) { this.x = x; this.y = y; } } const int BiggestMod = 1000000007; public static void Main() { var str = Console.ReadLine(); var compare = Console.ReadLine(); var difference = compare.Length - str.Length + 1; var ans = int.MaxValue; var l = compare.Length; for (int i = 0; i < difference; ++i) { int count = 0; for (int j = i, k = 0; k < l; ++k, ++j) if (str[j] != compare[k]) count++; ans = Math.Min(ans, count); } Console.WriteLine(ans); } } }
using System.Linq; using System.Text; using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Diagnostics; using System.Threading; using System.Runtime.CompilerServices; using System.IO.Pipes; namespace AtCoder { class Program { struct Point { public int x; public int y; public Point(int x, int y) { this.x = x; this.y = y; } } const int BiggestMod = 1000000007; public static void Main() { var str = Console.ReadLine(); var compare = Console.ReadLine(); var difference = Math.Abs(compare.Length - str.Length) + 1; var ans = int.MaxValue; var l = compare.Length; for (int i = 0; i < difference; ++i) { int count = 0; for (int j = i, k = 0; k < l; ++k, ++j) if (str[j] != compare[k]) count++; ans = Math.Min(ans, count); } Console.WriteLine(ans); } } }
[["+", 0, 212, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 16, 31, 213, 3, 4, 0, 25]]
8
236
5
using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; class Program { static void Main(string[] args) { var s = Console.ReadLine().ToCharArray(); var t = Console.ReadLine().ToCharArray(); int min = t.Length; for (int i = 0; i < s.Length - t.Length; i++) { int diff = 0; for (int j = 0; j < t.Length; j++) { if (s[i + j] != t[j]) diff++; } min = Math.Min(min, diff); } Console.WriteLine(min); } }
using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; class Program { static void Main(string[] args) { var s = Console.ReadLine().ToCharArray(); var t = Console.ReadLine().ToCharArray(); int min = t.Length; for (int i = 0; i < s.Length - t.Length + 1; i++) { int diff = 0; for (int j = 0; j < t.Length; j++) { if (s[i + j] != t[j]) diff++; } min = Math.Min(min, diff); } Console.WriteLine(min); } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
150
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; namespace AtCoder.ABC { class QuestionB { public static void Main(string[] args) { var scanner = new Scanner(); var s = scanner.NextLine(); var t = scanner.NextLine(); var max = int.MaxValue; for (int i = 0; i < s.Length - t.Length; i++) { var tmp = 0; for (int j = 0; j < t.Length; j++) { var sIndex = i + j; if (s[sIndex] != t[j]) { tmp++; } } max = Math.Min(max, tmp); } Console.WriteLine(max); } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private readonly Func<string> reader_; private string[] buf_; private int index_; public Scanner(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string NextLine() => reader_(); public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } 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; } public (int, int) Int2(int add = 0) { var array = ArrayInt(2, add); return (array[0], array[1]); } public (int, int, int) Int3(int add = 0) { var array = ArrayInt(3, add); return (array[0], array[1], array[2]); } public (long, long) Long2(int add = 0) { var array = ArrayLong(2, add); return (array[0], array[1]); } public (long, long, long) Long3(int add = 0) { var array = ArrayLong(3, add); return (array[0], array[1], array[2]); } public (double, double) Double2(int add = 0) { var array = ArrayDouble(2, add); return (array[0], array[1]); } public (double, double, double) Double3(int add = 0) { var array = ArrayDouble(3, add); return (array[0], array[1], array[2]); } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; namespace AtCoder.ABC { class QuestionB { public static void Main(string[] args) { var scanner = new Scanner(); var s = scanner.NextLine(); var t = scanner.NextLine(); var max = int.MaxValue; for (int i = 0; i <= s.Length - t.Length; i++) { var tmp = 0; for (int j = 0; j < t.Length; j++) { var sIndex = i + j; if (s[sIndex] != t[j]) { tmp++; } } max = Math.Min(max, tmp); } Console.WriteLine(max); } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private readonly Func<string> reader_; private string[] buf_; private int index_; public Scanner(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string NextLine() => reader_(); public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } 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; } public (int, int) Int2(int add = 0) { var array = ArrayInt(2, add); return (array[0], array[1]); } public (int, int, int) Int3(int add = 0) { var array = ArrayInt(3, add); return (array[0], array[1], array[2]); } public (long, long) Long2(int add = 0) { var array = ArrayLong(2, add); return (array[0], array[1]); } public (long, long, long) Long3(int add = 0) { var array = ArrayLong(3, add); return (array[0], array[1], array[2]); } public (double, double) Double2(int add = 0) { var array = ArrayDouble(2, add); return (array[0], array[1]); } public (double, double, double) Double3(int add = 0) { var array = ArrayDouble(3, add); return (array[0], array[1], array[2]); } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
881
2
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Linq.Expressions; using System.Diagnostics.Tracing; namespace Main { class Program { static void Main(string[] args) { //ここから // int n=ReadInt(); // string[] str = Console.ReadLine().Split(' '); string s = Console.ReadLine(); string t = Console.ReadLine(); int sl = s.Length; int tl = t.Length; int ans = tl; for (int i = 0; i < sl - tl; i++) { int tmp = 0; for (int j = 0; j < tl; j++) { if (s[i + j] != t[j]) tmp++; } if (tmp < ans) ans = tmp; } Cout(ans); //ここまで } static void Cout(string s) { Console.WriteLine(s); return; } static void Cout(int n) { Console.WriteLine(n); return; } static void Cout(long n) { Console.WriteLine(n); return; } static int ReadInt() { return int.Parse(Console.ReadLine()); } static int[] ReadArray(int n) { string[] str = Console.ReadLine().Split(' '); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(str[i]); } return a; } static long[] ReadArray(long n) { string[] str = Console.ReadLine().Split(' '); long[] a = new long[n]; for (long i = 0; i < n; i++) { a[i] = long.Parse(str[i]); } return a; } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int Min(int a, int b) { if (a < b) return a; return b; } static int Max(int a, int b) { if (a > b) return a; return b; } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Linq.Expressions; using System.Diagnostics.Tracing; namespace Main { class Program { static void Main(string[] args) { //ここから // int n=ReadInt(); // string[] str = Console.ReadLine().Split(' '); string s = Console.ReadLine(); string t = Console.ReadLine(); int sl = s.Length; int tl = t.Length; int ans = tl; for (int i = 0; i < sl - tl + 1; i++) { int tmp = 0; for (int j = 0; j < tl; j++) { if (s[i + j] != t[j]) tmp++; } if (tmp < ans) ans = tmp; } Cout(ans); //ここまで } static void Cout(string s) { Console.WriteLine(s); return; } static void Cout(int n) { Console.WriteLine(n); return; } static void Cout(long n) { Console.WriteLine(n); return; } static int ReadInt() { return int.Parse(Console.ReadLine()); } static int[] ReadArray(int n) { string[] str = Console.ReadLine().Split(' '); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(str[i]); } return a; } static long[] ReadArray(long n) { string[] str = Console.ReadLine().Split(' '); long[] a = new long[n]; for (long i = 0; i < n; i++) { a[i] = long.Parse(str[i]); } return a; } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int Min(int a, int b) { if (a < b) return a; return b; } static int Max(int a, int b) { if (a > b) return a; return b; } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
453
2
using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System; class Program { #region Reader static string ReadStr => Console.ReadLine(); static string[] ReadStrs => Console.ReadLine().Split(' '); static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim()); static int[] ReadInts => Console.ReadLine() .Trim() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim()); static long[] ReadLongs => Console.ReadLine() .Trim() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); #endregion #region Method const int mod = 1000000007; public static int Mod(int a, int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; } public static long Mod(long a, long mod = mod) { return a % mod >= 0 ? a % mod : a % mod + mod; } #endregion static void Main() { string S = ReadStr; string T = ReadStr; int ans = 1000000; for (int s = 0; s < S.Length - T.Length; s++) { int count = 0; for (int t = 0; t < T.Length; t++) { if (S[s + t] != T[t]) count++; } ans = Min(ans, count); } WriteLine(ans); } }
using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System; class Program { #region Reader static string ReadStr => Console.ReadLine(); static string[] ReadStrs => Console.ReadLine().Split(' '); static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim()); static int[] ReadInts => Console.ReadLine() .Trim() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim()); static long[] ReadLongs => Console.ReadLine() .Trim() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); #endregion #region Method const int mod = 1000000007; public static int Mod(int a, int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; } public static long Mod(long a, long mod = mod) { return a % mod >= 0 ? a % mod : a % mod + mod; } #endregion static void Main() { string S = ReadStr; string T = ReadStr; int ans = 1000000; for (int s = 0; s < S.Length - T.Length + 1; s++) { int count = 0; for (int t = 0; t < T.Length; t++) { if (S[s + t] != T[t]) count++; } ans = Min(ans, count); } WriteLine(ans); } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
352
2
using System; using System.Linq; using CompLib.Util; public class Program { public void Solve() { var sc = new Scanner(); string s = sc.Next(); string t = sc.Next(); int ans = int.MaxValue; for (int b = 0; b + t.Length < s.Length; b++) { int cnt = 0; for (int i = 0; i < t.Length; i++) { if (t[i] != s[b + i]) { cnt++; continue; } } ans = Math.Min(ans, cnt); } Console.WriteLine(ans); } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { if (_index >= _line.Length) { string s; do { s = Console.ReadLine(); } while (s.Length == 0); _line = s.Split(Separator); _index = 0; } return _line[_index++]; } public string ReadLine() { _index = _line.Length; return Console.ReadLine(); } 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() { string s = Console.ReadLine(); _line = s.Length == 0 ? new string[0] : s.Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Linq; using CompLib.Util; public class Program { public void Solve() { var sc = new Scanner(); string s = sc.Next(); string t = sc.Next(); int ans = int.MaxValue; for (int b = 0; b + t.Length <= s.Length; b++) { int cnt = 0; for (int i = 0; i < t.Length; i++) { if (t[i] != s[b + i]) { cnt++; continue; } } ans = Math.Min(ans, cnt); } Console.WriteLine(ans); } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { if (_index >= _line.Length) { string s; do { s = Console.ReadLine(); } while (s.Length == 0); _line = s.Split(Separator); _index = 0; } return _line[_index++]; } public string ReadLine() { _index = _line.Length; return Console.ReadLine(); } 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() { string s = Console.ReadLine(); _line = s.Length == 0 ? new string[0] : s.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, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
526
2
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace Tasks { public class B { 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 = Scanner.Scan<string>(); var T = Scanner.Scan<string>(); var answer = T.Length; for (var i = 0; i < S.Length - T.Length; i++) { var tmp = 0; for (var j = 0; j < T.Length; j++) { if (S[i + j] != T[j]) tmp++; } answer = Math.Min(answer, tmp); } Console.WriteLine(answer); } public static class Scanner { private static Queue<string> queue = new Queue<string>(); public static T Next<T>() { if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item); return (T)Convert.ChangeType(queue.Dequeue(), typeof(T)); } public static T Scan<T>() => Next<T>(); public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>()); public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>()); public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>()); public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>()); public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select( x => (T)Convert.ChangeType(x, typeof(T))); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace Tasks { public class B { 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 = Scanner.Scan<string>(); var T = Scanner.Scan<string>(); var answer = T.Length; for (var i = 0; i < S.Length - T.Length + 1; i++) { var tmp = 0; for (var j = 0; j < T.Length; j++) { if (S[i + j] != T[j]) tmp++; } answer = Math.Min(answer, tmp); } Console.WriteLine(answer); } public static class Scanner { private static Queue<string> queue = new Queue<string>(); public static T Next<T>() { if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item); return (T)Convert.ChangeType(queue.Dequeue(), typeof(T)); } public static T Scan<T>() => Next<T>(); public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>()); public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>()); public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>()); public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>()); public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select( x => (T)Convert.ChangeType(x, typeof(T))); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
553
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ProblemB { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var S = NS; var T = NS; var ans = long.MaxValue; for (var i = 0; i < S.Length; i++) { if (i + T.Length >= S.Length) break; var cnt = 0L; for (var j = 0; j < T.Length; j++) { if (S[i + j] != T[j]) ++cnt; } ans = Min(ans, cnt); } Console.WriteLine(ans); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return isEof; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_FastIODebug() {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string Scan() => NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override long Long() => long.Parse(NextString()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override double Double() => double.Parse(NextString()); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ProblemB { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var S = NS; var T = NS; var ans = long.MaxValue; for (var i = 0; i < S.Length; i++) { if (i + T.Length > S.Length) break; var cnt = 0L; for (var j = 0; j < T.Length; j++) { if (S[i + j] != T[j]) ++cnt; } ans = Min(ans, cnt); } Console.WriteLine(ans); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return isEof; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_FastIODebug() {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string Scan() => NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override long Long() => long.Parse(NextString()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override double Double() => double.Parse(NextString()); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47]]
8
1,634
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static int N; static long[] A; static void INPUT() { N = NextInt(); A = LineLong(); } static void OUT() { var s = new long[N]; s[N - 1] = A[N - 1]; for (int i = N - 2; i >= 0; i--) { s[i] = A[i] + s[i + 1]; } var ans = 0L; for (int i = 0; i < N - 1; i++) { ans += (A[i] * s[i + 1]) % MOD; ans %= MOD; } Console.WriteLine(ans); } static void Main(string[] args) { #if DEBUG // TESTINPUT(); INPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() {} } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static int N; static long[] A; static void INPUT() { N = NextInt(); A = LineLong(); } static void OUT() { var s = new long[N]; s[N - 1] = A[N - 1]; for (int i = N - 2; i >= 0; i--) { s[i] = A[i] + s[i + 1] % MOD; } var ans = 0L; for (int i = 0; i < N - 1; i++) { ans += (A[i] * s[i + 1]) % MOD; ans %= MOD; } Console.WriteLine(ans); } static void Main(string[] args) { #if DEBUG // TESTINPUT(); INPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() {} } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
[["+", 0, 1, 0, 11, 12, 16, 12, 16, 17, 109], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 22]]
8
532
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { #region library static int n = 0; static int m = 0; static int r = 0; static int c = 0; static int x = 0; static int y = 0; static string s = ""; static string[] ss; static long sum = 0; static long cnt = 0; static long max = -1; static long min = 2147483647; static bool flg = false; static bool flg2 = false; static string alpha = "abcdefghijklmnopqrstuvwxyz"; static long mod = 1000000007; static long[] arr; static char[,] map; static long[,] imap; public class Input { static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } public bool Any() { return queue.Any() || Read(); } bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); } public int[] NextInt(int n, int offset = 0) { return NextT(n, offset, int.Parse, (x, y) => x + y); } public long[] NextLong(int n, long offset = 0) { return NextT(n, offset, long.Parse, (x, y) => x + y); } public double[] NextDouble(int n, double offset = 0.0) { return NextT(n, offset, double.Parse, (x, y) => x + y); } } static Input input; static int Int() { return input.NextInt(); } static long Long() { return input.NextLong(); } static double Double() { return input.NextDouble(); } static string Text() { return input.Next(); } static void wl(object obj = null) { Console.WriteLine(obj); } static void w(object obj) { Console.Write(obj); } static void Yes() { wl("YES"); } static void No() { wl("NO"); } static void Sum() { wl(sum); } static void Cnt() { wl(cnt); } static void SetArray(long num = -1) { if (n == 0) { n = Int(); } arr = new long[n]; for (int i = 0; i < n; i++) { if (num == -1) arr[i] = Int(); else arr[i] = num; } } static void ShowArray() { for (int i = 0; i < arr.Length; i++) { if (i > 0) w(" "); w(arr[i]); } wl(); } static void SetMap(char def = '@') { if (r == 0 && c == 0) { r = Int(); c = Int(); } map = new char[r, c]; for (int i = 0; i < r; i++) { if (def == '@') s = Text(); for (int j = 0; j < c; j++) { map[i, j] = (def == '@') ? s[j] : def; } } } static void SetIMap(long def = -1) { if (r == 0 && c == 0) { r = Int(); c = Int(); } imap = new long[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { imap[i, j] = (def == -1) ? Int() : def; } } } static void ShowMap() { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { w(map[i, j]); } wl(); } } static void ShowIMap() { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { w(imap[i, j]); } wl(); } } #endregion #region main static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); input = new Input(); Solve(); Console.Out.Flush(); } public static void Solve() { SetArray(); //掛け算の右辺 long right = 0; for (int i = n - 1; i > 0; --i) { right += arr[i]; sum += (arr[i - 1] % mod * right % mod); sum %= mod; } Sum(); } #endregion }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { #region library static int n = 0; static int m = 0; static int r = 0; static int c = 0; static int x = 0; static int y = 0; static string s = ""; static string[] ss; static long sum = 0; static long cnt = 0; static long max = -1; static long min = 2147483647; static bool flg = false; static bool flg2 = false; static string alpha = "abcdefghijklmnopqrstuvwxyz"; static long mod = 1000000007; static long[] arr; static char[,] map; static long[,] imap; public class Input { static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } public bool Any() { return queue.Any() || Read(); } bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); } public int[] NextInt(int n, int offset = 0) { return NextT(n, offset, int.Parse, (x, y) => x + y); } public long[] NextLong(int n, long offset = 0) { return NextT(n, offset, long.Parse, (x, y) => x + y); } public double[] NextDouble(int n, double offset = 0.0) { return NextT(n, offset, double.Parse, (x, y) => x + y); } } static Input input; static int Int() { return input.NextInt(); } static long Long() { return input.NextLong(); } static double Double() { return input.NextDouble(); } static string Text() { return input.Next(); } static void wl(object obj = null) { Console.WriteLine(obj); } static void w(object obj) { Console.Write(obj); } static void Yes() { wl("YES"); } static void No() { wl("NO"); } static void Sum() { wl(sum); } static void Cnt() { wl(cnt); } static void SetArray(long num = -1) { if (n == 0) { n = Int(); } arr = new long[n]; for (int i = 0; i < n; i++) { if (num == -1) arr[i] = Int(); else arr[i] = num; } } static void ShowArray() { for (int i = 0; i < arr.Length; i++) { if (i > 0) w(" "); w(arr[i]); } wl(); } static void SetMap(char def = '@') { if (r == 0 && c == 0) { r = Int(); c = Int(); } map = new char[r, c]; for (int i = 0; i < r; i++) { if (def == '@') s = Text(); for (int j = 0; j < c; j++) { map[i, j] = (def == '@') ? s[j] : def; } } } static void SetIMap(long def = -1) { if (r == 0 && c == 0) { r = Int(); c = Int(); } imap = new long[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { imap[i, j] = (def == -1) ? Int() : def; } } } static void ShowMap() { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { w(map[i, j]); } wl(); } } static void ShowIMap() { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { w(imap[i, j]); } wl(); } } #endregion #region main static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); input = new Input(); Solve(); Console.Out.Flush(); } public static void Solve() { SetArray(); //掛け算の右辺 long right = 0; for (int i = n - 1; i > 0; --i) { right += arr[i]; sum += (arr[i - 1] % mod) * (right % mod); sum %= mod; } Sum(); } #endregion }
[["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24]]
8
1,448
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static readonly long Mod = 1000000007; static void Main() { int N = RInt(); var a = RLongs(); var d = new long[N + 1]; for (int i = 0; i < N; i++) { d[i + 1] = d[i] + a[i]; } long ans = 0; for (int i = 0; i < N - 1; i++) { ans += a[i] * (d[N] - d[i + 1]); ans %= Mod; } WriteLine(ans); } } class Scanner { public static string RString() => Console.ReadLine(); public static int RInt() => ReadTuple<int>(); public static long RLong() => ReadTuple<long>(); public static double RDouble() => ReadTuple<double>(); public static string[] RStrings() => Console.ReadLine().Split(); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadTuple<T1>() { var r = RString(); var r1 = (T1)Convert.ChangeType(r, typeof(T1)); return r1; } public static (T1, T2) ReadTuple<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadTuple<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static readonly long Mod = 1000000007; static void Main() { int N = RInt(); var a = RLongs(); var d = new long[N + 1]; for (int i = 0; i < N; i++) { d[i + 1] = d[i] + a[i]; } long ans = 0; for (int i = 0; i < N - 1; i++) { ans += a[i] * ((d[N] - d[i + 1]) % Mod); ans %= Mod; } WriteLine(ans); } } class Scanner { public static string RString() => Console.ReadLine(); public static int RInt() => ReadTuple<int>(); public static long RLong() => ReadTuple<long>(); public static double RDouble() => ReadTuple<double>(); public static string[] RStrings() => Console.ReadLine().Split(); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadTuple<T1>() { var r = RString(); var r1 = (T1)Convert.ChangeType(r, typeof(T1)); return r1; } public static (T1, T2) ReadTuple<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadTuple<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
[["+", 12, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 12, 16, 12, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 109], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22]]
8
766
4
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; using static System.Array; class MainClass : Scanner { static void Main() { int N = RInt(); var A = RLongs(); var d = new long[N + 1]; for (int i = 0; i < N; i++) { d[i + 1] = d[i] + A[i]; } Modular ans = 0; for (int i = 0; i < N - 1; i++) { ans += A[i] * (d[N] - d[i + 1]); } WriteLine((int)ans); } } class Modular { private const int M = 1000000007; private long value; public Modular(long value = 0) { this.value = value; } public static implicit operator Modular(long a) { var m = a % M; return new Modular((m < 0) ? m + M : m); } public static Modular operator +(Modular a, Modular b) => a.value + b.value; public static Modular operator -(Modular a, Modular b) => a.value - b.value; public static Modular operator *(Modular a, Modular b) => a.value * b.value; public static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, M - 2); } private static readonly List<int> facs = new List<int> { 1 }; public static Modular Fac(int n) //階乗 { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % M)); } return facs[n]; } public static Modular Fac(int r, int n) { int temp = 1; for (int i = r; i <= n; i++) { temp = (int)(Math.BigMul(temp, i) % M); } return temp; } public static Modular Ncr(int n, int r) // nCr { return (n < r) ? 0 : (n == r) ? 1 : (n < 1000000) ? Fac(n) / (Fac(r) * Fac(n - r)) : Fac(n - r + 1, n) / Fac(r); } public static explicit operator int(Modular a) { return (int)a.value; } } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; using static System.Array; class MainClass : Scanner { static void Main() { int N = RInt(); var A = RLongs(); var d = new long[N + 1]; for (int i = 0; i < N; i++) { d[i + 1] = d[i] + A[i]; } Modular ans = 0; for (int i = 0; i < N - 1; i++) { ans += A[i] * (Modular)(d[N] - d[i + 1]); } WriteLine((int)ans); } } class Modular { private const int M = 1000000007; private long value; public Modular(long value = 0) { this.value = value; } public static implicit operator Modular(long a) { var m = a % M; return new Modular((m < 0) ? m + M : m); } public static Modular operator +(Modular a, Modular b) => a.value + b.value; public static Modular operator -(Modular a, Modular b) => a.value - b.value; public static Modular operator *(Modular a, Modular b) => a.value * b.value; public static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, M - 2); } private static readonly List<int> facs = new List<int> { 1 }; public static Modular Fac(int n) //階乗 { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % M)); } return facs[n]; } public static Modular Fac(int r, int n) { int temp = 1; for (int i = r; i <= n; i++) { temp = (int)(Math.BigMul(temp, i) % M); } return temp; } public static Modular Ncr(int n, int r) // nCr { return (n < r) ? 0 : (n == r) ? 1 : (n < 1000000) ? Fac(n) / (Fac(r) * Fac(n - r)) : Fac(n - r + 1, n) / Fac(r); } public static explicit operator int(Modular a) { return (int)a.value; } } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
[["+", 0, 1, 0, 11, 12, 16, 12, 74, 39, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 0, 25], ["+", 0, 11, 12, 16, 12, 74, 51, 23, 0, 24]]
8
1,217
3
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.IO.Compression; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using System.Text; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { private const long COMDIV = 1000000007; static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var As = Console.ReadLine().Split().Select(long.Parse).ToArray(); long sumAs = As.Sum(); long ret = 0; for (int i = 0; i < N - 1; i++) { if (i == N - 2) { ret = (ret + As[i] * As[i + 1] % COMDIV) % COMDIV; break; } sumAs -= As[i]; ret = (ret + As[i] * sumAs % COMDIV) % COMDIV; } Console.WriteLine(ret); } } }
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.IO.Compression; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using System.Text; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { private const long COMDIV = 1000000007; static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var As = Console.ReadLine().Split().Select(decimal.Parse).ToArray(); decimal sumAs = As.Sum(); decimal ret = 0; for (int i = 0; i < N - 1; i++) { if (i == N - 2) { ret = (ret + As[i] * As[i + 1] % COMDIV) % COMDIV; break; } sumAs -= As[i]; ret = (ret + As[i] * sumAs % COMDIV) % COMDIV; } Console.WriteLine(ret); } } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
231
6
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var N = sc.ReadInt(); var A = sc.ReadIntArray(N); var sum = new long[N + 1]; for (int i = 0; i < N; i++) { sum[i + 1] += sum[i] + A[i]; } ModInt ans = 0; for (int i = 0; i < N; i++) { var x = sum[N] - sum[i + 1]; ans += x * A[i]; } Console.WriteLine(ans); } static Scanner sc = new Scanner(); } public struct ModInt { public const long Mod = (int)1e9 + 7; public long num; public ModInt(long n) { num = n; while (num < 0) num += Mod; } public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static ModInt operator /(ModInt l, ModInt r) { return l * Inverse(r); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } public static ModInt Pow(long v, long k) { v = new ModInt(v).num; long res = 1; while (k > 0) { if ((k & 1) == 1) res = res * v % Mod; v = v * v % Mod; k >>= 1; } return new ModInt(res); } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } private static List<ModInt> Facs = new List<ModInt> { 1 }; private static List<ModInt> iFacs = new List<ModInt> { 1 }; public static ModInt Fac(int n) { for (int i = Facs.Count; i <= n; i++) { Facs.Add(i * Facs[i - 1]); iFacs.Add(Inverse(Facs[i])); } return Facs[n]; } public static ModInt iFac(int n) { Fac(n); return iFacs[n]; } public static ModInt nCr(int n, int r, bool loop = false) { if (n < r || n < 0 || r < 0) return 0; if (n == r) return 1; if (loop && n > (int)1e6) return nCrLoop(n, r); return Fac(n) * iFac(r) * iFac(n - r); } public static ModInt nCrLoop(long n, long r) { ModInt num = 1; for (long i = 1; i <= r; i++) { num = num * (n - i + 1) / i; } return num; } public static ModInt nHr(int n, int r) { return nCr(n + r - 1, r); } } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var N = sc.ReadInt(); var A = sc.ReadLongArray(N); var sum = new long[N + 1]; for (int i = 0; i < N; i++) { sum[i + 1] += sum[i] + A[i]; } ModInt ans = 0; for (int i = 0; i < N; i++) { ModInt x = sum[N] - sum[i + 1]; ans += x * A[i]; } Console.WriteLine(ans); } static Scanner sc = new Scanner(); } public struct ModInt { public const long Mod = (int)1e9 + 7; public long num; public ModInt(long n) { num = n; while (num < 0) num += Mod; } public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static ModInt operator /(ModInt l, ModInt r) { return l * Inverse(r); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } public static ModInt Pow(long v, long k) { v = new ModInt(v).num; long res = 1; while (k > 0) { if ((k & 1) == 1) res = res * v % Mod; v = v * v % Mod; k >>= 1; } return new ModInt(res); } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } private static List<ModInt> Facs = new List<ModInt> { 1 }; private static List<ModInt> iFacs = new List<ModInt> { 1 }; public static ModInt Fac(int n) { for (int i = Facs.Count; i <= n; i++) { Facs.Add(i * Facs[i - 1]); iFacs.Add(Inverse(Facs[i])); } return Facs[n]; } public static ModInt iFac(int n) { Fac(n); return iFacs[n]; } public static ModInt nCr(int n, int r, bool loop = false) { if (n < r || n < 0 || r < 0) return 0; if (n == r) return 1; if (loop && n > (int)1e6) return nCrLoop(n, r); return Fac(n) * iFac(r) * iFac(n - r); } public static ModInt nCrLoop(long n, long r) { ModInt num = 1; for (long i = 1; i <= r; i++) { num = num * (n - i + 1) / i; } return num; } public static ModInt nHr(int n, int r) { return nCr(n + r - 1, r); } } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 22]]
8
1,778
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder177 { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); long[] A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long wa = 0; long[] was = new long[N]; long ans = 0; foreach (long a in A) { wa += a; } wa -= A[0]; long mod = 1000000007; for (long i = 0; i < N - 1; i++) { if (i == 0) { was[i] = wa; continue; } was[i] = (was[i - 1] - A[i]); } for (long i = 0; i < N - 1; i++) { ans += (A[i] * was[i]) % mod; ans %= mod; } Console.WriteLine(ans % mod); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder177 { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); long[] A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long wa = 0; long[] was = new long[N]; long ans = 0; foreach (long a in A) { wa += a; } wa -= A[0]; long mod = 1000000007; for (long i = 0; i < N - 1; i++) { if (i == 0) { was[i] = wa; continue; } was[i] = (was[i - 1] - A[i]); } for (long i = 0; i < N - 1; i++) { ans += (A[i] * (was[i] % mod)) % mod; ans %= mod; } Console.WriteLine(ans % mod); } } }
[["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 17, 109], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
8
241
4
using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; namespace C { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); ulong[] a = new ulong[N]; #region 自作 /*for (int i = 0; i < N; i++) { a[i] = long.Parse(s[i]); } long ans = 0; for (int i = 0; i < N - 1; i++) { for (int j = i+1; j < N; j++) { ans += a[i] * a[j]; } }*/ #endregion #region 解説より ulong sum = 0; ulong ans = 0; ulong mod = 1000000007; for (int i = 0; i < N; i++) { a[i] = ulong.Parse(s[i]); sum += a[i]; sum %= mod; } for (int i = 0; i < N - 1; i++) { sum -= a[i]; if (sum < 0) sum += mod; ans += a[i] * sum; ans %= mod; } #endregion Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; namespace C { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); long[] a = new long[N]; #region 自作 /*for (int i = 0; i < N; i++) { a[i] = long.Parse(s[i]); } long ans = 0; for (int i = 0; i < N - 1; i++) { for (int j = i+1; j < N; j++) { ans += a[i] * a[j]; } }*/ #endregion #region 解説より long sum = 0; long ans = 0; long mod = 1000000007; for (int i = 0; i < N; i++) { a[i] = long.Parse(s[i]); sum += a[i]; sum %= mod; } for (int i = 0; i < N - 1; i++) { sum -= a[i]; if (sum < 0) sum += mod; ans += a[i] * sum; ans %= mod; } #endregion Console.WriteLine(ans); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199]]
8
207
12
using System.Linq; using System.Text; using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Diagnostics; using System.Threading; using System.Runtime.CompilerServices; using System.IO.Pipes; namespace AtCoder { class Program { struct Point { public int x; public int y; public Point(int x, int y) { this.x = x; this.y = y; } } const int BiggestMod = 1000000007; public static void Main() { int num = int.Parse(Console.ReadLine()); long ans = 0; long[] args = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long[] data = new long[num - 1]; data[num - 2] = args[num - 1]; for (int i = num - 2; 0 < i; --i) data[i - 1] = args[i] + data[i]; for (int i = 0; i < num - 1; ++i) { ans += args[i] * data[i]; ans %= BiggestMod; } Console.WriteLine(ans); } } }
using System.Linq; using System.Text; using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Diagnostics; using System.Threading; using System.Runtime.CompilerServices; using System.IO.Pipes; namespace AtCoder { class Program { struct Point { public int x; public int y; public Point(int x, int y) { this.x = x; this.y = y; } } const int BiggestMod = 1000000007; public static void Main() { int num = int.Parse(Console.ReadLine()); long ans = 0; long[] args = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long[] data = new long[num - 1]; data[num - 2] = args[num - 1]; for (int i = num - 2; 0 < i; --i) data[i - 1] = (args[i] + data[i]) % BiggestMod; for (int i = 0; i < num - 1; ++i) { ans += args[i] * data[i]; ans %= BiggestMod; } Console.WriteLine(ans); /* int num = int.Parse(Console.ReadLine()); int GetGcd(int a, int b) => Gcd(Math.Max(a, b), Math.Min(a, b)); int Gcd(int a, int b) => (a % b == 0 ? b : Gcd(b, a % b)); var args = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var buf = args[0]; for (int i = 1; i < num; ++i) { buf = GetGcd(buf, args[i]); if (buf == 1) { goto skip; } } Console.WriteLine("not coprime"); return; skip: Array.Sort(args); for (int i = 0; i + 1< num; ++i) for (int j = i + 1; j < num; ++j) if (Gcd(args[j], args[i]) != 1) { Console.WriteLine("setwise coprime"); return; } Console.WriteLine("pairwise coprime"); return; */ } } }
[["+", 8, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 8, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 0, 7, 8, 1, 0, 11, 12, 16, 17, 109], ["+", 0, 7, 8, 1, 0, 11, 12, 16, 12, 22]]
8
270
4
using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Text; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] sA = Console.ReadLine().Split(' '); long[] A = new long[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(sA[i]); } long ans = 0; int modNum = 1000000007; // for(int i = 0;i < N - 1; i++) //{ // for (int j = i + 1; j < N; j++) // { // ans += (A[i] * A[j]) % modNum; // ans %= modNum; // } //} long sumNum = 0; for (int i = 0; i < N - 1; i++) { sumNum += A[i]; ans += sumNum * A[i + 1]; ans %= modNum; } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Text; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] sA = Console.ReadLine().Split(' '); long[] A = new long[N]; for (int i = 0; i < N; i++) { A[i] = long.Parse(sA[i]); } long ans = 0; long modNum = 1000000007; // for(int i = 0;i < N - 1; i++) //{ // for (int j = i + 1; j < N; j++) // { // ans += (A[i] * A[j]) % modNum; // ans %= modNum; // } //} long sumNum = 0; for (int i = 0; i < N - 1; i++) { sumNum += A[i]; sumNum %= modNum; ans += sumNum * A[i + 1]; ans %= modNum; } Console.WriteLine(ans); } }
[["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22]]
8
189
8
using System; using static System.Console; using static System.Math; using System.Numerics; using System.Collections.Generic; using System.Linq; namespace AtCoder { public class Program { public static void Main(string[] args) { long mod = 1000000007; long ans = 0; var n = myRead.readInt(); var s = myRead.readLongArray(); long sum = 0; for (int i = 0; i < n; i++) { sum += s[i]; } for (int i = 0; i < n - 1; i++) { sum -= s[i]; ans += (sum * (s[i] % mod)) % mod; ans %= mod; } WriteLine(ans); } } public static class myRead { public static int readInt() { return int.Parse(ReadLine()); } public static long readLong() { return long.Parse(ReadLine()); } public static string readStr() { return ReadLine(); } public static int[] readIntArray() { return ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] readLongArray() { return ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] readStrArray() { return ReadLine().Split(' '); } } public static class MyMath { public static long Factorical(long n) { return n <= 1 ? 1L : n * Factorical(n - 1); } public static long Permutation(long n, long m) { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); } public static long Combination(long n, long m) { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); } public static long Gcd(long n, long m) { return n % m == 0 ? m : Gcd(m, n % m); } public static long Lcm(long n, long m) { return n * m / Gcd(n, m); } public static long Pow(long n, long m) { return m == 0 ? 1L : m == 1 ? n : n * Pow(n, m - 1); } } }
using System; using static System.Console; using static System.Math; using System.Numerics; using System.Collections.Generic; using System.Linq; namespace AtCoder { public class Program { public static void Main(string[] args) { long mod = 1000000007; long ans = 0; var n = myRead.readInt(); var s = myRead.readLongArray(); long sum = 0; for (int i = 0; i < n; i++) { sum += s[i]; } for (int i = 0; i < n - 1; i++) { sum -= s[i]; ans += (s[i] * (sum % mod)) % mod; ans %= mod; } WriteLine(ans); } } public static class myRead { public static int readInt() { return int.Parse(ReadLine()); } public static long readLong() { return long.Parse(ReadLine()); } public static string readStr() { return ReadLine(); } public static int[] readIntArray() { return ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] readLongArray() { return ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] readStrArray() { return ReadLine().Split(' '); } } public static class MyMath { public static long Factorical(long n) { return n <= 1 ? 1L : n * Factorical(n - 1); } public static long Permutation(long n, long m) { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); } public static long Combination(long n, long m) { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); } public static long Gcd(long n, long m) { return n % m == 0 ? m : Gcd(m, n % m); } public static long Lcm(long n, long m) { return n * m / Gcd(n, m); } public static long Pow(long n, long m) { return m == 0 ? 1L : m == 1 ? n : n * Pow(n, m - 1); } } }
[["-", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 48], ["-", 12, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 48], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 31, 22]]
8
524
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Numerics; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var n = Console.ReadLine().ToInt(); var a = Input().Select(long.Parse).ToArray(); var sw = new long[n + 1]; for (int i = 1; i < n; i++) { sw[i] = (sw[i - 1] + a[i]) % Giri; } long wa = 0; for (int i = 0; i < n; i++) { // Console.WriteLine(sw[n-1] - sw[i]); wa += (a[i] * (sw[n - 1] - sw[i])) % Giri; wa %= Giri; /* Console.WriteLine(a[i]); for(int j = i+1; j < n; j++) { wa += (a[i] * a[j])%Giri; wa %= Giri; } */ } Console.WriteLine(wa); } static int CntReplace(string a, string b) { int wa = 0; for (int i = 0; i < a.Length; i++) { if (a[i] != b[i]) wa++; } return wa; } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Numerics; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var n = Console.ReadLine().ToInt(); var a = Input().Select(long.Parse).ToArray(); var sw = new long[n + 1]; for (int i = 1; i < n; i++) { sw[i] = (sw[i - 1] + a[i]) % Giri; } long wa = 0; for (int i = 0; i < n; i++) { // Console.WriteLine(sw[n-1] - sw[i]); wa += (a[i] * (Giri + sw[n - 1] - sw[i])) % Giri; wa %= Giri; /* Console.WriteLine(a[i]); for(int j = i+1; j < n; j++) { wa += (a[i] * a[j])%Giri; wa %= Giri; } */ } Console.WriteLine(wa); } static int CntReplace(string a, string b) { int wa = 0; for (int i = 0; i < a.Length; i++) { if (a[i] != b[i]) wa++; } return wa; } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
[["+", 0, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 17, 72]]
8
441
2
using System; using System.Linq; using System.Collections.Generic; using System.Numerics; namespace ABC177 { class Program { static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var A = Console.ReadLine().Split().Select(long.Parse).ToArray(); var sum = 0L; var ans = 0L; for (int i = 0; i < N - 1; i++) { sum += A[i]; ans += (sum * A[i + 1]) % 1000000007; } Console.WriteLine(ans % 1000000007); } } }
using System; using System.Linq; using System.Collections.Generic; using System.Numerics; namespace ABC177 { class Program { static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var A = Console.ReadLine().Split().Select(long.Parse).ToArray(); var sum = 0L; var ans = 0L; for (int i = 0; i < N - 1; i++) { sum += A[i]; ans += (sum % 1000000007 * A[i + 1] % 1000000007); } Console.WriteLine(ans % 1000000007); } } }
[["+", 12, 23, 0, 16, 31, 16, 31, 16, 17, 109], ["+", 12, 23, 0, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 25]]
8
136
4
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace Tasks { public class C { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var N = Scanner.Scan<int>(); var A = Scanner.ScanEnumerable<long>().ToArray(); var p = (int)1e9 + 7; var agg = CumulativeItems(A, p).ToArray(); var sum = agg[N]; var answer = 0L; for (var i = 1; i < N; i++) { answer += (A[i - 1] * (sum - agg[i])) % p; // Console.WriteLine((A[i - 1] % p * (sum - agg[i]) % p) % p); answer %= p; } Console.WriteLine(answer % p); } public static IEnumerable<long> CumulativeItems(IEnumerable<long> items, int mod) { var arr = items.ToArray(); var ret = new long[arr.Length + 1]; for (var i = 0; i < arr.Length; i++) ret[i + 1] = (arr[i] + ret[i]) % mod; return ret; } public static class Scanner { private static Queue<string> queue = new Queue<string>(); public static T Next<T>() { if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item); return (T)Convert.ChangeType(queue.Dequeue(), typeof(T)); } public static T Scan<T>() => Next<T>(); public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>()); public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>()); public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>()); public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>()); public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select( x => (T)Convert.ChangeType(x, typeof(T))); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace Tasks { public class C { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var N = Scanner.Scan<int>(); var A = Scanner.ScanEnumerable<long>().ToArray(); var p = (int)1e9 + 7; var agg = CumulativeItems(A, p).ToArray(); var sum = agg[N]; var answer = 0L; for (var i = 1; i < N; i++) { answer += (A[i - 1] * (sum - agg[i] + p) % p) % p; // Console.WriteLine((A[i - 1] % p * (sum - agg[i]) % p) % p); answer %= p; } Console.WriteLine(answer % p); } public static IEnumerable<long> CumulativeItems(IEnumerable<long> items, int mod) { var arr = items.ToArray(); var ret = new long[arr.Length + 1]; for (var i = 0; i < arr.Length; i++) ret[i + 1] = (arr[i] + ret[i]) % mod; return ret; } public static class Scanner { private static Queue<string> queue = new Queue<string>(); public static T Next<T>() { if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item); return (T)Convert.ChangeType(queue.Dequeue(), typeof(T)); } public static T Scan<T>() => Next<T>(); public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>()); public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>()); public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>()); public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>()); public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select( x => (T)Convert.ChangeType(x, typeof(T))); } } }
[["+", 0, 16, 31, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 109], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22]]
8
640
4
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; namespace FertiLib.Contest.C { static class Program { public static void Solve(Scanner cin) { int n = cin.ReadInt(); var a = cin.ReadLongArray(n); ModInt ans = a.Sum() * a.Sum(); for (int i = 0; i < n; i++) { ans -= a[i] * a[i]; } ans /= 2; 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; } } public struct ModInt : IComparable<ModInt>, IEquatable<ModInt> { public static long MOD = 1000000007; public static bool isModPrime { get; set; } private readonly long num; public ModInt(long n) { num = n; isModPrime = true; } public override string ToString() => num.ToString(); public static ModInt operator +(ModInt l, ModInt r) { long x = l.num + r.num; if (x >= MOD) x -= MOD; return new ModInt(x); } public static ModInt operator -(ModInt l, ModInt r) { long x = l.num - r.num; if (x < 0) x += MOD; return new ModInt(x); } public static ModInt operator *(ModInt l, ModInt r) => new ModInt((l.num * r.num) % MOD); public static ModInt operator /(ModInt l, ModInt r) => l * r.Inverse(); public static ModInt operator ++(ModInt x) { var tmp = x + new ModInt(1); return tmp; } public static ModInt operator --(ModInt x) { var tmp = x - new ModInt(1); return tmp; } public static bool operator>(ModInt l, ModInt r) => l.CompareTo(r) > 0; public static bool operator<(ModInt l, ModInt r) => l.CompareTo(r) < 0; public static bool operator >=(ModInt l, ModInt r) => l.CompareTo(r) >= 0; public static bool operator <=(ModInt l, ModInt r) => l.CompareTo(r) <= 0; public static bool operator ==(ModInt l, ModInt r) => l.Equals(r); public static bool operator !=(ModInt l, ModInt r) => !l.Equals(r); public static implicit operator long(ModInt x) => x.num; public static implicit operator ModInt(long n) { n %= MOD; if (n < 0) n += MOD; return new ModInt(n); } public ModInt Inverse() => Inverse(this, MOD); public static ModInt Inverse(ModInt x) => Inverse(x.num, MOD); public static long Inverse(long x, long m) { if (x % m == 0) throw new DivideByZeroException(); long a = x, b = m, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; long p = a; a = b; b = p; // swap(a, b); u -= t * v; p = u; u = v; v = p; // swap(u, v); } u %= m; if (u < 0) u += m; return u; } public static ModInt Pow(long x, long n) { long now = 1; if (isModPrime) n %= MOD - 1; for (; n > 0; n /= 2, x = x * x % MOD) { if (n % 2 == 1) now = now * x % MOD; } return new ModInt(now); } public int CompareTo(ModInt x) { if (num == x.num) return 0; if (num > x.num) return 1; return -1; } public bool Equals(ModInt x) => num == x.num; public override bool Equals(object obj) => obj is ModInt m && num == m.num; public override int GetHashCode() { return HashCode.Combine(num); } } static class Extention { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); public static int UpperBound<T>(this IList<T> list, T value) => list.BinarySearch(value, true, 0, list.Count, Comparer<T>.Default); public static int LowerBound<T>(this IList<T> list, T value) => list.BinarySearch(value, false, 0, list.Count, Comparer<T>.Default); public static int BinarySearch<T>(this IList<T> list, T value, bool isUpperBound, int index, int length, Comparer<T> comparer) { var ng = index - 1; var ok = index + length; while (ok - ng > 1) { var mid = ng + (ok - ng) / 2; var res = comparer.Compare(list[mid], value); if (res < 0 || (isUpperBound && res == 0)) ng = mid; else ok = mid; } return ok; } } 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; using System.Runtime.CompilerServices; namespace FertiLib.Contest.C { static class Program { public static void Solve(Scanner cin) { int n = cin.ReadInt(); var a = cin.ReadLongArray(n); ModInt ans = a.Sum(); ans *= a.Sum(); for (int i = 0; i < n; i++) { ans -= a[i] * a[i]; } ans /= 2; 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; } } public struct ModInt : IComparable<ModInt>, IEquatable<ModInt> { public static long MOD = 1000000007; public static bool isModPrime { get; set; } private readonly long num; public ModInt(long n) { num = n; isModPrime = true; } public override string ToString() => num.ToString(); public static ModInt operator +(ModInt l, ModInt r) { long x = l.num + r.num; if (x >= MOD) x -= MOD; return new ModInt(x); } public static ModInt operator -(ModInt l, ModInt r) { long x = l.num - r.num; if (x < 0) x += MOD; return new ModInt(x); } public static ModInt operator *(ModInt l, ModInt r) => new ModInt((l.num * r.num) % MOD); public static ModInt operator /(ModInt l, ModInt r) => l * r.Inverse(); public static ModInt operator ++(ModInt x) { var tmp = x + new ModInt(1); return tmp; } public static ModInt operator --(ModInt x) { var tmp = x - new ModInt(1); return tmp; } public static bool operator>(ModInt l, ModInt r) => l.CompareTo(r) > 0; public static bool operator<(ModInt l, ModInt r) => l.CompareTo(r) < 0; public static bool operator >=(ModInt l, ModInt r) => l.CompareTo(r) >= 0; public static bool operator <=(ModInt l, ModInt r) => l.CompareTo(r) <= 0; public static bool operator ==(ModInt l, ModInt r) => l.Equals(r); public static bool operator !=(ModInt l, ModInt r) => !l.Equals(r); public static implicit operator long(ModInt x) => x.num; public static implicit operator ModInt(long n) { n %= MOD; if (n < 0) n += MOD; return new ModInt(n); } public ModInt Inverse() => Inverse(this, MOD); public static ModInt Inverse(ModInt x) => Inverse(x.num, MOD); public static long Inverse(long x, long m) { if (x % m == 0) throw new DivideByZeroException(); long a = x, b = m, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; long p = a; a = b; b = p; // swap(a, b); u -= t * v; p = u; u = v; v = p; // swap(u, v); } u %= m; if (u < 0) u += m; return u; } public static ModInt Pow(long x, long n) { long now = 1; if (isModPrime) n %= MOD - 1; for (; n > 0; n /= 2, x = x * x % MOD) { if (n % 2 == 1) now = now * x % MOD; } return new ModInt(now); } public int CompareTo(ModInt x) { if (num == x.num) return 0; if (num > x.num) return 1; return -1; } public bool Equals(ModInt x) => num == x.num; public override bool Equals(object obj) => obj is ModInt m && num == m.num; public override int GetHashCode() { return HashCode.Combine(num); } } static class Extention { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); public static int UpperBound<T>(this IList<T> list, T value) => list.BinarySearch(value, true, 0, list.Count, Comparer<T>.Default); public static int LowerBound<T>(this IList<T> list, T value) => list.BinarySearch(value, false, 0, list.Count, Comparer<T>.Default); public static int BinarySearch<T>(this IList<T> list, T value, bool isUpperBound, int index, int length, Comparer<T> comparer) { var ng = index - 1; var ok = index + length; while (ok - ng > 1) { var mid = ng + (ok - ng) / 2; var res = comparer.Compare(list[mid], value); if (res < 0 || (isUpperBound && res == 0)) ng = mid; else ok = mid; } return ok; } } 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); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108]]
8
3,621
4
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { int N = RInt(); var A = RInts(); int num = A[0]; for (int i = 1; i < N; i++) { num = (int)GCD(num, A[i]); } if (num != 1) { WriteLine("not coprime"); return; } bool frag = true; const int Amax = 1000000; bool[] used = new bool[Amax + 1]; int[] count = new int[Amax + 1]; for (int i = 0; i < N; i++) { count[A[i]]++; } for (int i = 2; i <= Amax; i++) { if (used[i]) continue; int cnt = 0; for (int k = i; k <= Amax; k += i) { used[k] = true; cnt += count[A[i]]; } if (cnt >= 2) { frag = false; } } WriteLine(frag ? "pairwise coprime" : "setwise coprime"); } public static long GCD(long a, long b) => a == 0 ? b : GCD(b % a, a); } class Scanner { public static string RString() => Console.ReadLine(); public static int RInt() => ReadTuple<int>(); public static long RLong() => ReadTuple<long>(); public static double RDouble() => ReadTuple<double>(); public static string[] RStrings() => Console.ReadLine().Split(); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadTuple<T1>() { var r = RString(); var r1 = (T1)Convert.ChangeType(r, typeof(T1)); return r1; } public static (T1, T2) ReadTuple<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadTuple<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { int N = RInt(); var A = RInts(); int num = A[0]; for (int i = 1; i < N; i++) { num = (int)GCD(num, A[i]); } if (num != 1) { WriteLine("not coprime"); return; } bool frag = true; const int Amax = 1000000; bool[] used = new bool[Amax + 1]; int[] count = new int[Amax + 1]; for (int i = 0; i < N; i++) { count[A[i]]++; } for (int i = 2; i <= Amax; i++) { if (used[i]) continue; int cnt = 0; for (int k = i; k <= Amax; k += i) { used[k] = true; cnt += count[k]; } if (cnt >= 2) { frag = false; } } WriteLine(frag ? "pairwise coprime" : "setwise coprime"); } public static long GCD(long a, long b) => a == 0 ? b : GCD(b % a, a); } class Scanner { public static string RString() => Console.ReadLine(); public static int RInt() => ReadTuple<int>(); public static long RLong() => ReadTuple<long>(); public static double RDouble() => ReadTuple<double>(); public static string[] RStrings() => Console.ReadLine().Split(); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadTuple<T1>() { var r = RString(); var r1 = (T1)Convert.ChangeType(r, typeof(T1)); return r1; } public static (T1, T2) ReadTuple<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadTuple<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
[["-", 12, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22]]
8
896
5
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ProblemE { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var AList = NNList(N); var hurui = new long[1000001]; foreach (var item in AList) { hurui[item]++; } var pairwise = true; var setwise = true; var done = new bool[N]; for (var i = 2; i <= 1000000; i++) { if (done[i]) continue; var cnt = 0L; for (var j = i; j <= 1000000; j += i) { done[j] = true; cnt += hurui[j]; } if (cnt > 1) pairwise = false; if (cnt == N) setwise = false; } if (pairwise) { Console.WriteLine("pairwise coprime"); return; } if (setwise) { Console.WriteLine("setwise coprime"); return; } Console.WriteLine("not coprime"); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return isEof; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_FastIODebug() {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string Scan() => NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override long Long() => long.Parse(NextString()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override double Double() => double.Parse(NextString()); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ProblemE { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var AList = NNList(N); var hurui = new long[1000001]; foreach (var item in AList) { hurui[item]++; } var pairwise = true; var setwise = true; var done = new bool[1000001]; for (var i = 2; i <= 1000000; i++) { if (done[i]) continue; var cnt = 0L; for (var j = i; j <= 1000000; j += i) { done[j] = true; cnt += hurui[j]; } if (cnt > 1) pairwise = false; if (cnt == N) setwise = false; } if (pairwise) { Console.WriteLine("pairwise coprime"); return; } if (setwise) { Console.WriteLine("setwise coprime"); return; } Console.WriteLine("not coprime"); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return isEof; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_FastIODebug() {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string Scan() => NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override long Long() => long.Parse(NextString()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override double Double() => double.Parse(NextString()); } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203]]
8
1,709
2
using System; using System.Collections.Generic; using System.Linq; namespace E { class Program { static List<int> min_factor = new List<int>(); static void Main(string[] args) { var n = Int32.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(" ").Select(s => Int32.Parse(s)).ToList(); min_factor = new List<int>(); for (var i = 0; i <= 1000000; i++) { min_factor.Add(i); } for (int i = 2; i * i <= 1000000; i++) { if (min_factor[i] < i) continue; for (int j = i * i; j <= 1000000; j += i) { if (min_factor[j] == j) min_factor[j] = i; } } var values = new Dictionary<int, int>(); foreach (var val in a) { var facts = PrimeFactors(val); foreach (var hoge in facts) { if (!values.ContainsKey(hoge)) values[hoge] = 0; values[hoge]++; } } bool flag1 = true; var f2 = true; foreach (var v in values) { if (v.Key == 1) continue; if (v.Value > 1) { flag1 = false; } if (v.Value >= n) { f2 = false; } } if (flag1) { Console.WriteLine("pairwise coprime"); return; } else if (f2) { Console.WriteLine("setwise coprime"); return; } Console.WriteLine("not coprime"); } public static IEnumerable<int> PrimeFactors(int n) { int tmp = n; while (tmp > 1) { yield return min_factor[tmp]; tmp = tmp / min_factor[tmp]; } yield return 1; } } }
using System; using System.Collections.Generic; using System.Linq; namespace E { class Program { static List<int> min_factor = new List<int>(); static void Main(string[] args) { var n = Int32.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(" ").Select(s => Int32.Parse(s)).ToList(); min_factor = new List<int>(); for (var i = 0; i <= 1000000; i++) { min_factor.Add(i); } for (int i = 2; i * i <= 1000000; i++) { if (min_factor[i] < i) continue; for (int j = i * i; j <= 1000000; j += i) { if (min_factor[j] == j) min_factor[j] = i; } } var values = new Dictionary<int, int>(); foreach (var val in a) { var facts = PrimeFactors(val); foreach (var hoge in facts.Distinct()) { if (!values.ContainsKey(hoge)) values[hoge] = 0; values[hoge]++; } } bool flag1 = true; var f2 = true; foreach (var v in values) { if (v.Key == 1) continue; if (v.Value > 1) { flag1 = false; } if (v.Value >= n) { f2 = false; } } if (flag1) { Console.WriteLine("pairwise coprime"); return; } else if (f2) { Console.WriteLine("setwise coprime"); return; } Console.WriteLine("not coprime"); } public static IEnumerable<int> PrimeFactors(int n) { int tmp = n; while (tmp > 1) { yield return min_factor[tmp]; tmp = tmp / min_factor[tmp]; } yield return 1; } } }
[["+", 8, 196, 0, 210, 12, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 210, 12, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 210, 8, 196, 0, 210, 0, 25]]
8
401
4
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Linq.Expressions; using System.Diagnostics.Tracing; namespace Main { class Program { static void Main(string[] args) { //ここから // int n=ReadInt(); // string[] str = Console.ReadLine().Split(' '); int n = ReadInt(); int[] a = ReadArray(n); bool isP = true; int max = a.Max(); // zentai gcd int Gcd = gcd(a[0], a[1]); for (int i = 2; i < n; i++) { Gcd = gcd(Gcd, a[i]); if (Gcd == 1) break; } if (Gcd != 1) { Cout("not coprime"); return; } bool[] insu = new bool[max + 1]; for (int i = 0; i < max + 1; i++) { insu[i] = false; } for (int i = 0; i < n; i++) { int k = a[i]; int j = 2; while (j * j <= a[i]) { if (k % j == 0) { while (k % j == 0) { k /= j; } if (insu[j]) { Cout("setwise coprime"); return; } insu[j] = true; } j++; } if (insu[k]) { Cout("setwise coprime"); return; } insu[k] = true; } if (isP) Cout("pairwise coprime"); else Cout("setwise coprime"); //ここまで } static int gcd(int a, int b) { if (a > b) { int temp = a; a = b; b = temp; } while (true) { int amari = b % a; if (amari == 0) { return a; } b = a; a = amari; } } static void Cout(string s) { Console.WriteLine(s); return; } static void Cout(int n) { Console.WriteLine(n); return; } static void Cout(long n) { Console.WriteLine(n); return; } static int ReadInt() { return int.Parse(Console.ReadLine()); } static int[] ReadArray(int n) { string[] str = Console.ReadLine().Split(' '); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(str[i]); } return a; } static long[] ReadArray(long n) { string[] str = Console.ReadLine().Split(' '); long[] a = new long[n]; for (long i = 0; i < n; i++) { a[i] = long.Parse(str[i]); } return a; } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int Min(int a, int b) { if (a < b) return a; return b; } static int Max(int a, int b) { if (a > b) return a; return b; } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Linq.Expressions; using System.Diagnostics.Tracing; namespace Main { class Program { static void Main(string[] args) { //ここから // int n=ReadInt(); // string[] str = Console.ReadLine().Split(' '); int n = ReadInt(); int[] a = ReadArray(n); bool isP = true; int max = a.Max(); // zentai gcd int Gcd = gcd(a[0], a[1]); for (int i = 2; i < n; i++) { Gcd = gcd(Gcd, a[i]); if (Gcd == 1) break; } if (Gcd != 1) { Cout("not coprime"); return; } bool[] insu = new bool[max + 1]; for (int i = 0; i < max + 1; i++) { insu[i] = false; } for (int i = 0; i < n; i++) { int k = a[i]; int j = 2; while (j * j <= a[i]) { if (k % j == 0) { while (k % j == 0) { k /= j; } if (insu[j]) { Cout("setwise coprime"); return; } insu[j] = true; } j++; } if (k != 1 && insu[k]) { Cout("setwise coprime"); return; } insu[k] = true; } if (isP) Cout("pairwise coprime"); else Cout("setwise coprime"); //ここまで } static int gcd(int a, int b) { if (a > b) { int temp = a; a = b; b = temp; } while (true) { int amari = b % a; if (amari == 0) { return a; } b = a; a = amari; } } static void Cout(string s) { Console.WriteLine(s); return; } static void Cout(int n) { Console.WriteLine(n); return; } static void Cout(long n) { Console.WriteLine(n); return; } static int ReadInt() { return int.Parse(Console.ReadLine()); } static int[] ReadArray(int n) { string[] str = Console.ReadLine().Split(' '); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(str[i]); } return a; } static long[] ReadArray(long n) { string[] str = Console.ReadLine().Split(' '); long[] a = new long[n]; for (long i = 0; i < n; i++) { a[i] = long.Parse(str[i]); } return a; } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int Min(int a, int b) { if (a < b) return a; return b; } static int Max(int a, int b) { if (a > b) return a; return b; } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
8
687
4
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(); int[] aa = sc.IntArray(); long allGcd = Gcd(aa[0], aa[1]); for (int i = 2; i < n; i++) { allGcd = Gcd(allGcd, aa[i]); } if (allGcd > 1) { Console.WriteLine("not coprime"); return; } aa = aa.OrderBy(num => num).ToArray(); if (aa.Max() == 1) { Console.WriteLine("pairwise coprime"); return; } SortedSet<int> set = new SortedSet<int>(); for (int i = 0; i < n; i++) { var num = aa[i]; if (num == 1) { continue; } SortedSet<int> primes = new SortedSet<int>(); for (int j = 2; j * j <= aa[i]; j++) { if (num % j == 0) { primes.Add(j); num /= j; } j++; } if (num != 1) { primes.Add(num); } foreach (var p in primes) { if (set.Contains(p)) { Console.WriteLine("setwise coprime"); return; } else { set.Add(p); } } } Console.WriteLine("pairwise coprime"); } // 最大公約数(long) private static long Gcd(long a, long b) { if (a < b) { return Gcd(b, a); } while (b != 0) { long r = a % b; a = b; b = r; } return a; } 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(); int[] aa = sc.IntArray(); long allGcd = Gcd(aa[0], aa[1]); for (int i = 2; i < n; i++) { allGcd = Gcd(allGcd, aa[i]); } if (allGcd > 1) { Console.WriteLine("not coprime"); return; } aa = aa.OrderBy(num => num).ToArray(); if (aa.Max() == 1) { Console.WriteLine("pairwise coprime"); return; } SortedSet<int> set = new SortedSet<int>(); for (int i = 0; i < n; i++) { var num = aa[i]; if (num == 1) { continue; } SortedSet<int> primes = new SortedSet<int>(); for (int j = 2; j * j <= aa[i]; j++) { if (num % j == 0) { primes.Add(j); num /= j; j--; } } if (num != 1) { primes.Add(num); } foreach (var p in primes) { if (set.Contains(p)) { Console.WriteLine("setwise coprime"); return; } else { set.Add(p); } } } Console.WriteLine("pairwise coprime"); } // 最大公約数(long) private static long Gcd(long a, long b) { if (a < b) { return Gcd(b, a); } while (b != 0) { long r = a % b; a = b; b = r; } return a; } 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, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 68], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
683
4
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC177E { class Program { static void Main(string[] args) { var N = RInt; var A = RInts; var ps = PrimeNumbers(1000 + 1); int[] count = new int[1000010]; for (int i = 0; i < N; i++) { int num = A[i]; for (int j = 0; j < ps.Length; j++) { if (ps[j] > num) break; if (num % ps[j] == 0) { num /= ps[j]; count[ps[j]]++; while (num % ps[j] == 0) { num /= ps[j]; } } } count[num]++; } bool ansPair = true; bool ansSet = true; for (int i = 0; i < count.Length; i++) { if (count[i] > 1) ansPair = false; if (count[i] == N) ansSet = false; } if (ansPair) Console.WriteLine("pairwise coprime"); else if (ansSet) Console.WriteLine("setwise coprime"); else Console.WriteLine("not coprime"); } public static int[] PrimeNumbers(int n) { int max = n; var searchList = Enumerable.Range(2, max).ToList(); var pList = new List<int>(); while (searchList.Count > 0) { int cand = searchList.First(); pList.Add(cand); searchList.RemoveAll(x => x % cand == 0); } return pList.ToArray(); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String RNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int RInt => int.Parse(RNext()); public static long RLong => long.Parse(RNext()); public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); public static string RString => RNext(); //以下未テスト public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray(); public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray(); public static char[][] RMap(int h) => Enumerable.Repeat(0, h) .Select(x => Console.ReadLine().ToCharArray()) .ToArray(); } public struct Mlong { long _v; const long mod = 1000000007; public Mlong(long n = 0) : this() { _v = n >= mod || n < 0 ? (n % mod + mod) % mod : n; } public static implicit operator Mlong(long _x) => new Mlong(_x); public static implicit operator long(Mlong _x) => _x._v; public static Mlong operator +(Mlong m1, Mlong m2) { long m = m1._v + m2._v; return m >= mod ? m - mod : m; } public static Mlong operator -(Mlong m1, Mlong m2) { long m = m1._v - m2._v; return m >= 0 ? m : m + mod; } public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod; public static Mlong operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod; public static long ModPow(long a, long n) { if (n == 0) return 1; else if (n % 2 == 1) return a * ModPow(a, n - 1) % mod; else return ModPow(a * a % mod, n / 2); } static Mlong[] fac, finv, inv; public static void nCkInit(int max) { fac = new Mlong[max]; finv = new Mlong[max]; inv = new Mlong[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = fac[i - 1] * i; inv[i] = mod - inv[mod % i] * (mod / i); finv[i] = finv[i - 1] * inv[i]; } } public static Mlong nCk(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } } static class Debug { public static void Draw<T>(T[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } static public void Draw<T>(T[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); string[,] map2 = new string[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.ToString(); else if (i == 0) map2[i, j] = (j - 1).ToString(); else if (j == 0) map2[i, j] = (i - 1).ToString(); else map2[i, j] = map[i - 1, j - 1].ToString(); } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j].Last()); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } } }
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC177E { class Program { static void Main(string[] args) { var N = RInt; var A = RInts; var ps = PrimeNumbers(1000 + 1); int[] count = new int[1000010]; for (int i = 0; i < N; i++) { int num = A[i]; for (int j = 0; j < ps.Length; j++) { if (ps[j] > num) break; if (num % ps[j] == 0) { num /= ps[j]; count[ps[j]]++; while (num % ps[j] == 0) { num /= ps[j]; } } } if (num != 1) count[num]++; } bool ansPair = true; bool ansSet = true; for (int i = 0; i < count.Length; i++) { if (count[i] > 1) ansPair = false; if (count[i] == N) ansSet = false; } if (ansPair) Console.WriteLine("pairwise coprime"); else if (ansSet) Console.WriteLine("setwise coprime"); else Console.WriteLine("not coprime"); } public static int[] PrimeNumbers(int n) { int max = n; var searchList = Enumerable.Range(2, max).ToList(); var pList = new List<int>(); while (searchList.Count > 0) { int cand = searchList.First(); pList.Add(cand); searchList.RemoveAll(x => x % cand == 0); } return pList.ToArray(); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String RNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int RInt => int.Parse(RNext()); public static long RLong => long.Parse(RNext()); public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); public static string RString => RNext(); //以下未テスト public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray(); public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray(); public static char[][] RMap(int h) => Enumerable.Repeat(0, h) .Select(x => Console.ReadLine().ToCharArray()) .ToArray(); } public struct Mlong { long _v; const long mod = 1000000007; public Mlong(long n = 0) : this() { _v = n >= mod || n < 0 ? (n % mod + mod) % mod : n; } public static implicit operator Mlong(long _x) => new Mlong(_x); public static implicit operator long(Mlong _x) => _x._v; public static Mlong operator +(Mlong m1, Mlong m2) { long m = m1._v + m2._v; return m >= mod ? m - mod : m; } public static Mlong operator -(Mlong m1, Mlong m2) { long m = m1._v - m2._v; return m >= 0 ? m : m + mod; } public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod; public static Mlong operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod; public static long ModPow(long a, long n) { if (n == 0) return 1; else if (n % 2 == 1) return a * ModPow(a, n - 1) % mod; else return ModPow(a * a % mod, n / 2); } static Mlong[] fac, finv, inv; public static void nCkInit(int max) { fac = new Mlong[max]; finv = new Mlong[max]; inv = new Mlong[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = fac[i - 1] * i; inv[i] = mod - inv[mod % i] * (mod / i); finv[i] = finv[i - 1] * inv[i]; } } public static Mlong nCk(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } } static class Debug { public static void Draw<T>(T[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } static public void Draw<T>(T[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); string[,] map2 = new string[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.ToString(); else if (i == 0) map2[i, j] = (j - 1).ToString(); else if (j == 0) map2[i, j] = (i - 1).ToString(); else map2[i, j] = map[i - 1, j - 1].ToString(); } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j].Last()); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25]]
8
1,439
6
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 ST = new SegTree(W + 1); for (int i = 0; i < H; i++) ST.Update(i, 0); int[] ans = new int[H]; for (int i = 0; i < H; i++) { while (true) { var idx = ST.QueryMinIdx(A[i], B[i] + 1); var val = ST.At(idx); if (val == ST.Inf) break; int hor = B[i] + 1 - idx; if (ST.At(B[i] + 1) > val + hor) ST.Update(B[i] + 1, val + hor); ST.ClearAt(idx); } var minhor = ST.QueryMin(0, W); ans[i] = minhor == ST.Inf ? -1 : (minhor + i + 1); } Console.WriteLine(String.Join("\n", ans)); } int H, W; int[] A, B; public Sol() { var d = ria(); H = d[0]; W = d[1]; A = new int[H]; B = new int[H]; for (int i = 0; i < H; i++) { d = ria(); A[i] = d[0] - 1; B[i] = d[1] - 1; } } 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)); } } class SegTree { // segment Tree // 0-origin public int[] Data; public int[] Idx; public int Inf; public int N; // size public int n; // size (power of 2); // constructor public SegTree(int n_, int inf_) { N = n_; Inf = inf_; n = 1; while (n < n_) n *= 2; Data = new int[2 * n - 1]; Idx = new int[2 * n - 1]; for (int i = 0; i < 2 * n - 1; i++) Data[i] = Inf; } public SegTree(int n_) { N = n_; Inf = (int)1e9; n = 1; while (n < n_) n *= 2; Data = new int[2 * n - 1]; Idx = new int[2 * n - 1]; for (int i = 0; i < 2 * n - 1; i++) Data[i] = Inf; } // 0 // 1 2 // 3 4 5 6 public void Update(int k, int a) { k += n - 1; Data[k] = a; Idx[k] = k - (n - 1); while (k > 0) { k = (k - 1) / 2; Data[k] = Math.Min(Data[k * 2 + 1], Data[k * 2 + 2]); Idx[k] = Data[k * 2 + 1] < Data[k * 2 + 2] ? Idx[k * 2 + 1] : Idx[k * 2 + 2]; } } // RMQ; // [a,b) // call: Query(a,b,0,0,n) public int QueryMin(int a, int b) { return Query(a, b, 0, 0, n); } public int QueryMinIdx(int a, int b) { return QueryIdx(a, b, 0, 0, n); } public int At(int idx) { return Data[idx + n - 1]; } public void ClearAt(int idx) { Update(idx, Inf); } public int Query(int a, int b, int k, int l, int r) { // [a,b) not overwraps [l,r) => return Inf if (r <= a || b <= l) return Inf; // [a,b) include [l,r) => return Data[k]; if (a <= l && r <= b) return Data[k]; // or return min(left,right) var vl = Query(a, b, k * 2 + 1, l, (l + r) / 2); var vr = Query(a, b, k * 2 + 2, (l + r) / 2, r); return Math.Min(vl, vr); } public int QueryIdx(int a, int b, int k, int l, int r) { // [a,b) not overwraps [l,r) => return Inf if (r <= a || b <= l) return -1; // [a,b) include [l,r) => return Data[k]; if (a <= l && r <= b) return Idx[k]; // or return min(left,right) var vlidx = QueryIdx(a, b, k * 2 + 1, l, (l + r) / 2); var vridx = QueryIdx(a, b, k * 2 + 2, (l + r) / 2, r); var vl = Data[vlidx + n - 1]; var vr = Data[vridx + n - 1]; return vl < vr ? vlidx : vridx; } public int Min { get { return Data[0]; } } public int MinIdx { get { return Idx[0]; } } public void UniqInit(int val) { for (int i = 0 + n - 1; i < N + n - 1; i++) Data[i] = val; int l = n - 1; int r = N + n - 1 - 1; while (l > 0) { l = (l - 1) / 2; r = (r - 1) / 2; for (int i = l; i <= r; i++) Data[i] = val; } } public void UniqInit(int[] vs) { for (int i = 0 + n - 1; i < N + n - 1; i++) { Data[i] = vs[i - (n - 1)]; Idx[i] = i - (n - 1); } for (int i = n - 2; i >= 0; i--) { Data[i] = Math.Min(Data[2 * i + 1], Data[2 * i + 2]); Idx[i] = Data[2 * i + 1] < Data[2 * i + 2] ? Idx[2 * i + 1] : Idx[2 * i + 2]; } } public void Dump() { Console.WriteLine(); int h = 0; int cnt = 0; for (int i = 0; i < Data.Length; i++) { Console.Write("{0} ", Data[i]); cnt++; if (cnt == 1 << h) { cnt = 0; h++; Console.WriteLine(); } } } }
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 ST = new SegTree(W + 1); for (int i = 0; i < W; i++) ST.Update(i, 0); int[] ans = new int[H]; for (int i = 0; i < H; i++) { while (true) { var idx = ST.QueryMinIdx(A[i], B[i] + 1); var val = ST.At(idx); if (val == ST.Inf) break; int hor = B[i] + 1 - idx; if (ST.At(B[i] + 1) > val + hor) ST.Update(B[i] + 1, val + hor); ST.ClearAt(idx); } var minhor = ST.QueryMin(0, W); ans[i] = minhor == ST.Inf ? -1 : (minhor + i + 1); } Console.WriteLine(String.Join("\n", ans)); } int H, W; int[] A, B; public Sol() { var d = ria(); H = d[0]; W = d[1]; A = new int[H]; B = new int[H]; for (int i = 0; i < H; i++) { d = ria(); A[i] = d[0] - 1; B[i] = d[1] - 1; } } 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)); } } class SegTree { // segment Tree // 0-origin public int[] Data; public int[] Idx; public int Inf; public int N; // size public int n; // size (power of 2); // constructor public SegTree(int n_, int inf_) { N = n_; Inf = inf_; n = 1; while (n < n_) n *= 2; Data = new int[2 * n - 1]; Idx = new int[2 * n - 1]; for (int i = 0; i < 2 * n - 1; i++) Data[i] = Inf; } public SegTree(int n_) { N = n_; Inf = (int)1e9; n = 1; while (n < n_) n *= 2; Data = new int[2 * n - 1]; Idx = new int[2 * n - 1]; for (int i = 0; i < 2 * n - 1; i++) Data[i] = Inf; } // 0 // 1 2 // 3 4 5 6 public void Update(int k, int a) { k += n - 1; Data[k] = a; Idx[k] = k - (n - 1); while (k > 0) { k = (k - 1) / 2; Data[k] = Math.Min(Data[k * 2 + 1], Data[k * 2 + 2]); Idx[k] = Data[k * 2 + 1] < Data[k * 2 + 2] ? Idx[k * 2 + 1] : Idx[k * 2 + 2]; } } // RMQ; // [a,b) // call: Query(a,b,0,0,n) public int QueryMin(int a, int b) { return Query(a, b, 0, 0, n); } public int QueryMinIdx(int a, int b) { return QueryIdx(a, b, 0, 0, n); } public int At(int idx) { return Data[idx + n - 1]; } public void ClearAt(int idx) { Update(idx, Inf); } public int Query(int a, int b, int k, int l, int r) { // [a,b) not overwraps [l,r) => return Inf if (r <= a || b <= l) return Inf; // [a,b) include [l,r) => return Data[k]; if (a <= l && r <= b) return Data[k]; // or return min(left,right) var vl = Query(a, b, k * 2 + 1, l, (l + r) / 2); var vr = Query(a, b, k * 2 + 2, (l + r) / 2, r); return Math.Min(vl, vr); } public int QueryIdx(int a, int b, int k, int l, int r) { // [a,b) not overwraps [l,r) => return Inf if (r <= a || b <= l) return -1; // [a,b) include [l,r) => return Data[k]; if (a <= l && r <= b) return Idx[k]; // or return min(left,right) var vlidx = QueryIdx(a, b, k * 2 + 1, l, (l + r) / 2); var vridx = QueryIdx(a, b, k * 2 + 2, (l + r) / 2, r); var vl = Data[vlidx + n - 1]; var vr = Data[vridx + n - 1]; return vl < vr ? vlidx : vridx; } public int Min { get { return Data[0]; } } public int MinIdx { get { return Idx[0]; } } public void UniqInit(int val) { for (int i = 0 + n - 1; i < N + n - 1; i++) Data[i] = val; int l = n - 1; int r = N + n - 1 - 1; while (l > 0) { l = (l - 1) / 2; r = (r - 1) / 2; for (int i = l; i <= r; i++) Data[i] = val; } } public void UniqInit(int[] vs) { for (int i = 0 + n - 1; i < N + n - 1; i++) { Data[i] = vs[i - (n - 1)]; Idx[i] = i - (n - 1); } for (int i = n - 2; i >= 0; i--) { Data[i] = Math.Min(Data[2 * i + 1], Data[2 * i + 2]); Idx[i] = Data[2 * i + 1] < Data[2 * i + 2] ? Idx[2 * i + 1] : Idx[2 * i + 2]; } } public void Dump() { Console.WriteLine(); int h = 0; int cnt = 0; for (int i = 0; i < Data.Length; i++) { Console.Write("{0} ", Data[i]); cnt++; if (cnt == 1 << h) { cnt = 0; h++; Console.WriteLine(); } } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
1,627
2
using System; class TEST { public static void Main() { string[] value = Console.ReadLine().Split( new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); int AllNum = int.Parse(value[0]); int MakeMax = int.Parse(value[1]); int MaxTime = int.Parse(value[2]); int time = 0; int temp = AllNum; while (temp >= 0) { temp -= MakeMax; time += MaxTime; } Console.WriteLine(time); } }
using System; class TEST { public static void Main() { string[] value = Console.ReadLine().Split( new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); // if (AllNum <= 0) int AllNum = int.Parse(value[0]); int MakeMax = int.Parse(value[1]); int MaxTime = int.Parse(value[2]); int time = 0; int temp = AllNum; while (temp > 0) { temp -= MakeMax; time += MaxTime; } Console.WriteLine(time); // Console.ReadKey(); } }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47]]
8
115
2
using System; using System.Linq; class Program { static void Main() { int N = int.Parse(Console.ReadLine()); var list = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int count = 0; for (int i = 0; i < N; i++) { if (i % 2 != 0 && list[i] % 2 != 0) { count++; } } Console.WriteLine(count); } }
using System; using System.Linq; class Program { static void Main() { int N = int.Parse(Console.ReadLine()); var list = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int count = 0; for (int i = 0; i < N; i++) { if (i % 2 == 0 && list[i] % 2 != 0) { count++; } } Console.WriteLine(count); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60]]
8
115
2
using System; using System.Linq; class Program { static void Main() { var N = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); var result = 0; for (int i = 0; i < N; i++) { if (i % 2 == 1 && a[i] % 2 == 1) { result++; } } Console.WriteLine(result); } }
using System; using System.Linq; class Program { static void Main() { var N = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); var result = 0; for (int i = 0; i < N; i++) { if ((i + 1) % 2 == 1 && a[i] % 2 == 1) { result++; } } Console.WriteLine(result); } }
[["+", 15, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 16, 31, 23, 0, 25]]
8
107
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using static System.Math; namespace CSharpSpiral { class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = #if DEBUG true #else false #endif }; Console.SetOut(sw); new Program().Solve(new ConsoleInput( #if DEBUG new StreamReader("../../../inputData.txt") #else Console.In #endif , ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var A = cin.ReadLongArray(N); Console.WriteLine(A.Where((x, i) => x % 2 != 0 && i % 2 != 0).Count()); } } static class ExtendClass { public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X); } class ConsoleInput { private readonly TextReader _stream; private readonly char _separator = ' '; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } public bool isEOF { get { return _stream.Peek() == -1; } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using static System.Math; namespace CSharpSpiral { class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = #if DEBUG true #else false #endif }; Console.SetOut(sw); new Program().Solve(new ConsoleInput( #if DEBUG new StreamReader("../../../inputData.txt") #else Console.In #endif , ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var A = cin.ReadLongArray(N); Console.WriteLine(A.Where((x, i) => x % 2 != 0 && i % 2 == 0).Count()); } } static class ExtendClass { public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X); } class ConsoleInput { private readonly TextReader _stream; private readonly char _separator = ' '; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } public bool isEOF { get { return _stream.Peek() == -1; } } } }
[["-", 0, 28, 0, 218, 8, 16, 12, 16, 17, 79], ["+", 0, 28, 0, 218, 8, 16, 12, 16, 17, 60]]
8
613
2
using System; using System.Linq; class name { static void Main() { int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] d = Console.ReadLine().Split().Select(int.Parse).ToArray(); int sum = 0; for (int i = 0; i < s[0]; i++) { if (i % 2 == 1 && d[i] % 2 == 1) { sum++; } } Console.WriteLine(sum); } }
using System; using System.Linq; class name { static void Main() { int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] d = Console.ReadLine().Split().Select(int.Parse).ToArray(); int sum = 0; for (int i = 0; i < s[0]; i++) { if (i % 2 == 0 && d[i] % 2 == 1) { sum++; } } Console.WriteLine(sum); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
124
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { public class EijB { public static void Main(string[] args) { var c = new ConsoleInput(Console.In); int N = c.ReadInt; int count = 0; for (int i = 0; i < N; i++) { int a = c.ReadInt; if (i % 2 == 0) continue; if (a % 2 == 0) continue; count++; } Console.WriteLine(count); } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { public class EijB { public static void Main(string[] args) { var c = new ConsoleInput(Console.In); int N = c.ReadInt; int count = 0; for (int i = 1; i <= N; i++) { int a = c.ReadInt; if (i % 2 == 0) continue; if (a % 2 == 0) continue; count++; } Console.WriteLine(count); } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
463
4
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; int count = 0; for (int i = 1; i <= N; i++) { var num = cin.ReadInt; if (i % 2 != 0) continue; if (num % 2 != 0) { count++; } } WriteLine(count); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; i++) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } public static class TestCheck { public static void Display(int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0}", txt); } public static void Display(int index, int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0} : {1}", index, txt); } public static void Display(List<int>[] list) { for (int i = 0; i < list.Length; i++) { Display(i, list[i].ToArray()); } } public static void Display(List<int[]> list) { for (int i = 0; i < list.Count; i++) { Display(i, list[i].ToArray()); } } public static void Display(int index, List<int[]> list) { for (int i = 0; i < list.Count; i++) { Display(index, list[i].ToArray()); } } public static void DisplayLine(string text) { WriteLine("----------" + text + "----------"); } public static void DisplayLine() { DisplayLine(""); } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; int count = 0; for (int i = 1; i <= N; i++) { var num = cin.ReadInt; if (i % 2 == 0) continue; if (num % 2 != 0) { count++; } } WriteLine(count); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; i++) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } public static class TestCheck { public static void Display(int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0}", txt); } public static void Display(int index, int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0} : {1}", index, txt); } public static void Display(List<int>[] list) { for (int i = 0; i < list.Length; i++) { Display(i, list[i].ToArray()); } } public static void Display(List<int[]> list) { for (int i = 0; i < list.Count; i++) { Display(i, list[i].ToArray()); } } public static void Display(int index, List<int[]> list) { for (int i = 0; i < list.Count; i++) { Display(index, list[i].ToArray()); } } public static void DisplayLine(string text) { WriteLine("----------" + text + "----------"); } public static void DisplayLine() { DisplayLine(""); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60]]
8
775
2
using System; using System.Collections.Generic; class Program { static void Main() { string N = Console.ReadLine(); int n = int.Parse(N); string[] a = Console.ReadLine().Split(' '); int j = 0; int count = 0; for (int i = 0; i < n; i++) { j = int.Parse(a[i]); if (i % 2 == 1 && j % 2 == 1) { count++; } } Console.WriteLine(count); } }
using System; using System.Collections.Generic; class Program { static void Main() { string N = Console.ReadLine(); int n = int.Parse(N); string[] a = Console.ReadLine().Split(' '); int j = 0; int count = 0; for (int i = 1; i <= n; i++) { j = int.Parse(a[i - 1]); if (i % 2 == 1 && j % 2 == 1) { count++; } } Console.WriteLine(count); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
122
6
using System; using System.Linq; using System.Collections.Generic; using E = System.Linq.Enumerable; public class Program { public static void Main() { var n = int.Parse(Console.ReadLine()); var seqA = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var k = seqA.Select((x, i) => i * x % 2).Sum(); Console.WriteLine(k); } }
using System; using System.Linq; using System.Collections.Generic; using E = System.Linq.Enumerable; public class Program { public static void Main() { var n = int.Parse(Console.ReadLine()); var seqA = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var k = seqA.Select((x, i) => (i + 1) * x % 2).Sum(); Console.WriteLine(k); } }
[["+", 0, 218, 8, 16, 31, 16, 31, 23, 0, 24], ["+", 8, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 8, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 218, 8, 16, 31, 16, 31, 23, 0, 25]]
8
111
4
using System; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var ans = a.Where((e, i) => i % 2 == 1 && e % 2 == 1).Count(); Console.WriteLine(ans); } }
using System; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var ans = a.Where((e, i) => (i + 1) % 2 == 1 && e % 2 == 1).Count(); Console.WriteLine(ans); } }
[["+", 8, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 8, 16, 31, 16, 31, 16, 31, 23, 0, 25]]
8
106
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static int N; static int[] a; static void INPUT() { N = NextInt(); a = LineInt(); } static void OUT() { var c = 0; for (int i = 0; i < N; i++) { if (i % 2 == 1 && a[i] % 2 == 1) c++; } Console.WriteLine(c); } static void Main(string[] args) { #if DEBUG // TESTINPUT(); INPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() {} } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static int N; static int[] a; static void INPUT() { N = NextInt(); a = LineInt(); } static void OUT() { var c = 0; for (int i = 0; i < N; i++) { if (i % 2 == 0 && a[i] % 2 == 1) c++; } Console.WriteLine(c); } static void Main(string[] args) { #if DEBUG // TESTINPUT(); INPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() {} } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
470
2
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramB { static void Main(string[] args) { var a = long.Parse(Console.ReadLine()); var list = Console.ReadLine().Split(" ").Select(x => long.Parse(x)).ToList(); var result = 0; for (var i = 1; i < a; i += 2) { if (list[i] % 2 == 1) { result++; } } Console.WriteLine(result); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramB { static void Main(string[] args) { var a = long.Parse(Console.ReadLine()); var list = Console.ReadLine().Split(" ").Select(x => long.Parse(x)).ToList(); var result = 0; for (var i = 0; i < a; i += 2) { if (list[i] % 2 == 1) { result++; } } Console.WriteLine(result); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
125
2
using System; using System.Collections.Generic; // using System.Linq; // using System.Numerics; class Program { static void Main(string[] args) { var input = INP(); int N = TOI(input[0]); var input2 = INP(); int[] a = new int[N]; for (int i = 0; i < N; i++) { a[i] = TOI(input2[i]); } int cnt = 0; for (int i = 0; i < N; i++) { if (i % 2 == 1) { if (a[i] % 2 == 1) { cnt++; } } } CWL(cnt); } public static List<int> PrimeFactors(int n) { var tmpList = new List<int>(); int i = 2; int tmp = n; while (i * i <= n) { if (tmp % i == 0) { tmp /= i; tmpList.Add(i); } else { i++; } } if (tmp != 1) tmpList.Add(tmp); return tmpList; } static string[] INP() { return Console.ReadLine().Split(' '); } static void CWL(string value) { Console.WriteLine(value); } static void CWL(int value) { Console.WriteLine(value); } static void CWL(long value) { Console.WriteLine(value); } static void CWL(float value) { Console.WriteLine(value); } static void CWL(double value) { Console.WriteLine(value); } static int TOI(string str) { return int.Parse(str); } static long TOL(string str) { return long.Parse(str); } static float TOF(string str) { return float.Parse(str); } static double TOD(string str) { return double.Parse(str); } /*static void Main (string[] args) { var input = INP(); var input2 = INP(); var input3 = INP(); CWL("dummy"); }*/ }
using System; using System.Collections.Generic; // using System.Linq; // using System.Numerics; class Program { static void Main(string[] args) { var input = INP(); int N = TOI(input[0]); var input2 = INP(); int[] a = new int[N]; for (int i = 0; i < N; i++) { a[i] = TOI(input2[i]); } int cnt = 0; for (int i = 0; i < N; i++) { if ((i + 1) % 2 == 1) { if (a[i] % 2 == 1) { cnt++; } } } CWL(cnt); } public static List<int> PrimeFactors(int n) { var tmpList = new List<int>(); int i = 2; int tmp = n; while (i * i <= n) { if (tmp % i == 0) { tmp /= i; tmpList.Add(i); } else { i++; } } if (tmp != 1) tmpList.Add(tmp); return tmpList; } static string[] INP() { return Console.ReadLine().Split(' '); } static void CWL(string value) { Console.WriteLine(value); } static void CWL(int value) { Console.WriteLine(value); } static void CWL(long value) { Console.WriteLine(value); } static void CWL(float value) { Console.WriteLine(value); } static void CWL(double value) { Console.WriteLine(value); } static int TOI(string str) { return int.Parse(str); } static long TOL(string str) { return long.Parse(str); } static float TOF(string str) { return float.Parse(str); } static double TOD(string str) { return double.Parse(str); } /*static void Main (string[] args) { var input = INP(); var input2 = INP(); var input3 = INP(); CWL("dummy"); }*/ }
[["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 25]]
8
403
4
using System; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { string[] input = Read(); int n = int.Parse(input[0]); input = Read(); int cnt = 0; for (int i = 1; i <= n; i++) { int a = int.Parse(input[i]); if (i % 2 != 0 && a % 2 != 0) cnt++; } Write(cnt); } static string[] Read() { return Console.ReadLine().Split(' '); } static void Write(object o) { Console.WriteLine(o.ToString()); } }
using System; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { string[] input = Read(); int n = int.Parse(input[0]); input = Read(); int cnt = 0; for (int i = 0; i < n; i++) { int a = int.Parse(input[i]); if (i % 2 == 0 && a % 2 != 0) cnt++; } Write(cnt); } static string[] Read() { return Console.ReadLine().Split(' '); } static void Write(object o) { Console.WriteLine(o.ToString()); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60]]
8
157
6
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var N = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray(); var answer = 0; foreach (var i in Enumerable.Range(0, N)) { if (i % 2 == 1 && a[i] % 2 == 1) { answer++; } } Console.WriteLine(answer); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var N = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray(); var answer = 0; foreach (var i in Enumerable.Range(0, N)) { if ((i + 1) % 2 == 1 && a[i] % 2 == 1) { answer++; } } Console.WriteLine(answer); } } }
[["+", 15, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 16, 31, 23, 0, 25]]
8
213
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var N = IO.RInt; var a = IO.RSInt; var ans = 0; for (int i = 0; i < N; i++) { if (i % 2 == 0) continue; else { if (a[i] % 2 == 1) ans++; } } WriteLine(ans); } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var N = IO.RInt; var a = IO.RSInt; var ans = 0; for (int i = 0; i < N; i++) { if (i % 2 == 1) continue; else { if (a[i] % 2 == 1) ans++; } } WriteLine(ans); } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203]]
8
531
2
using System; using System.Collections.Generic; using System.Linq; using static Scanner; class Program { static void Main() => new Program().Solve(); public void Solve() { int n = ReadInt(); Console.WriteLine( ReadInt(n).Where((x, i) => x % 2 == 1 && i % 2 == 1).Count()); } } static class Scanner { static Queue<string> que = new Queue<string>(); public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); } public static int ReadInt() => int.Parse(Read()); public static long ReadLong() => long.Parse(Read()); public static double ReadDouble() => double.Parse(Read()); public static decimal ReadDecimal() => decimal.Parse(Read()); public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); } public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse); public static IEnumerable<long> ReadLong(long n) => Read(n).Select(long.Parse); public static IEnumerable<double> ReadDouble(long n) => Read(n).Select(double.Parse); public static IEnumerable<decimal> ReadDecimal(long n) => Read(n).Select(decimal.Parse); }
using System; using System.Collections.Generic; using System.Linq; using static Scanner; class Program { static void Main() => new Program().Solve(); public void Solve() { int n = ReadInt(); Console.WriteLine( ReadInt(n).Where((x, i) => x % 2 == 1 && i % 2 == 0).Count()); } } static class Scanner { static Queue<string> que = new Queue<string>(); public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); } public static int ReadInt() => int.Parse(Read()); public static long ReadLong() => long.Parse(Read()); public static double ReadDouble() => double.Parse(Read()); public static decimal ReadDecimal() => decimal.Parse(Read()); public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); } public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse); public static IEnumerable<long> ReadLong(long n) => Read(n).Select(long.Parse); public static IEnumerable<double> ReadDouble(long n) => Read(n).Select(double.Parse); public static IEnumerable<decimal> ReadDecimal(long n) => Read(n).Select(decimal.Parse); }
[["-", 0, 28, 0, 218, 8, 16, 12, 16, 12, 203], ["+", 0, 28, 0, 218, 8, 16, 12, 16, 12, 203]]
8
346
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.B { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var N = ReadLong(); var a = ReadLongs(); var count = 0L; for (int i = 0; i < N; i++) { if (i % 2 == 1 && a[i] % 2 == 1) { count++; } } return count; } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.B { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var N = ReadLong(); var a = ReadLongs(); var count = 0L; for (int i = 0; i < N; i++) { if (i % 2 == 0 && a[i] % 2 == 1) { count++; } } return count; } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
408
2
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; public static class P { public static void Main() { int n = int.Parse(Console.ReadLine()); Console.WriteLine(Console.ReadLine() .Split() .Select(int.Parse) .Where((x, y) => x % 2 == 1 && y % 2 == 1) .Count()); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; public static class P { public static void Main() { int n = int.Parse(Console.ReadLine()); Console.WriteLine(Console.ReadLine() .Split() .Select(int.Parse) .Where((x, y) => x % 2 == 1 && y % 2 == 0) .Count()); } }
[["-", 0, 28, 0, 218, 8, 16, 12, 16, 12, 203], ["+", 0, 28, 0, 218, 8, 16, 12, 16, 12, 203]]
8
135
2
using System; using System.Collections.Generic; using System.IO.Pipes; using System.Linq; using static System.Math; namespace AtcoderSolve { class Program { static void Main(string[] args) { A(); } static void A() { var N = ReadInt(); var list = new int[100000]; for (int x = 1; x < Sqrt(N); x++) { for (int y = 1; y < Sqrt(N); y++) { for (int z = 1; z < Sqrt(N); z++) { var value = (int)(Pow(x, 2) + Pow(y, 2) + Pow(z, 2) + (x * y) + (y * z) + (z * x)); if (value <= 100000) list[value]++; } } } for (int i = 1; i < N; i++) Println(list[i]); } static List<long> ReadLines(long n) { var l = new List<long>(); for (long i = 0; i < n; i++) { l.Add(ReadLong()); } return l; } static void YESOrNO(bool e) => Println(e ? "YES" : "NO"); static void YesOrNo(bool e) => Println(e ? "Yes" : "No"); 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 SumDigits(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 long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b); static long Lcm(long a, long b) => a / Gcd(a, b) * 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.IO.Pipes; using System.Linq; using static System.Math; namespace AtcoderSolve { class Program { static void Main(string[] args) { A(); } static void A() { var N = ReadInt(); var list = new int[100000]; for (int x = 1; x < Sqrt(N); x++) { for (int y = 1; y < Sqrt(N); y++) { for (int z = 1; z < Sqrt(N); z++) { var value = (int)(Pow(x, 2) + Pow(y, 2) + Pow(z, 2) + (x * y) + (y * z) + (z * x)); if (value <= 100000) list[value]++; } } } for (int i = 1; i <= N; i++) Println(list[i]); } static List<long> ReadLines(long n) { var l = new List<long>(); for (long i = 0; i < n; i++) { l.Add(ReadLong()); } return l; } static void YESOrNO(bool e) => Println(e ? "YES" : "NO"); static void YesOrNo(bool e) => Println(e ? "Yes" : "No"); 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 SumDigits(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 long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b); static long Lcm(long a, long b) => a / Gcd(a, b) * 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); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
834
2
using System; using System.Linq; class name { static void Main() { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); int d = a[0]; int[] ans = new int[a[0] + 5]; for (int i = 0; i * i <= d; i++) { for (int s = 0; s * s <= d; s++) { for (int t = 0; t * t <= d; t++) { int dem = i * i + s * s + t * t + i * s + s * t + t * i; if (dem < d) { ans[dem]++; } } } } for (int f = 1; f < d + 1; f++) { Console.WriteLine(ans[f]); } } }
using System; using System.Linq; class name { static void Main() { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); int d = a[0]; int[] ans = new int[a[0] + 5]; for (int i = 1; i * i <= d; i++) { for (int s = 1; s * s <= d; s++) { for (int t = 1; t * t <= d; t++) { int dem = i * i + s * s + t * t + i * s + s * t + t * i; if (dem <= d) { ans[dem]++; } } } } for (int f = 1; f < d + 1; f++) { Console.WriteLine(ans[f]); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
192
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionC { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 long n = long.Parse(Console.ReadLine()); var ans = new long[n]; foreach (var x in Enumerable.Range(1, 100)) { foreach (var y in Enumerable.Range(1, 100)) { foreach (var z in Enumerable.Range(1, 100)) { var tmp = x * x + y * y + z * z + x * y + y * z + z * x; if (tmp < n) { ans[tmp - 1]++; } } } } for (int i = 0; i < n; i++) { Console.WriteLine(ans[i]); } Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionC { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 long n = long.Parse(Console.ReadLine()); var ans = new long[n]; foreach (var x in Enumerable.Range(1, 100)) { foreach (var y in Enumerable.Range(1, 100)) { foreach (var z in Enumerable.Range(1, 100)) { var tmp = x * x + y * y + z * z + x * y + y * z + z * x; if (tmp <= n) { ans[tmp - 1]++; } } } } for (int i = 0; i < n; i++) { Console.WriteLine(ans[i]); } Console.Out.Flush(); } } }
[["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 19]]
8
227
2
using System; namespace AtCoderSnippet { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var arr = new int[N]; for (long x = 1; x <= 100; x++) { for (long y = 1; y <= 100; y++) { for (long z = 1; z <= 100; z++) { long num = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x); if (num < N) arr[num - 1] += 1; } } } for (int i = 0; i < N; i++) { Console.WriteLine(arr[i]); } } } }
using System; namespace AtCoderSnippet { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var arr = new int[N]; for (long x = 1; x <= 100; x++) { for (long y = 1; y <= 100; y++) { for (long z = 1; z <= 100; z++) { long num = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x); if (num <= N) arr[num - 1] += 1; } } } for (int i = 0; i < N; i++) { Console.WriteLine(arr[i]); } } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
173
2
using System; using System.Linq; namespace AtCoder0711 { class MainClass { public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); // int[] a = Console.ReadLine().Split(' ').Select(x => // int.Parse(x)).ToArray(); long[] ans = new long[N]; for (var x = 1; x < 100; x++) { for (var y = 1; y < 100; y++) { for (var z = 1; z < 100; z++) { long n = x * x + y * y + z * z + x * y + y * z + z * x; if (n < N) ans[n - 1] += 1; } } } for (var i = 0; i < N; i++) { Console.WriteLine(ans[i]); } } } }
using System; using System.Linq; namespace AtCoder0711 { class MainClass { public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); // int[] a = Console.ReadLine().Split(' ').Select(x => // int.Parse(x)).ToArray(); long[] ans = new long[N]; for (var x = 1; x < 100; x++) { for (var y = 1; y < 100; y++) { for (var z = 1; z < 100; z++) { long n = x * x + y * y + z * z + x * y + y * z + z * x; if (n <= N) ans[n - 1] += 1; } } } for (var i = 0; i < N; i++) { Console.WriteLine(ans[i]); } } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
171
2