buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Practice {
class Program {
static void Main(string[] args) {
SolveA();
// SolveB();
// SolveC();
// SolveD();
}
private const long MOD = 1000000007;
static void SolveA() {
int n = ReadAndParseInt();
int[] ta = ReadAndParseIntArr();
int t = ta[0];
int a = ta[1];
int[] h = ReadAndParseIntArr();
int ans = 0;
int diff = int.MaxValue;
for (int i = 0; i < h.Length; ++i) {
int d = (int)Math.Abs(t - h[i] * 0.006f - a);
if (d < diff) {
diff = d;
ans = i;
}
}
Console.WriteLine(ans + 1);
}
#region よく使う便利関数
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); }
private static int[] ReadAndParseIntArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static long ReadAndParseLong() {
return long.Parse(Console.ReadLine());
}
private static long[] ReadAndParseLongArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Practice {
class Program {
static void Main(string[] args) {
SolveA();
// SolveB();
// SolveC();
// SolveD();
}
private const long MOD = 1000000007;
static void SolveA() {
int n = ReadAndParseInt();
int[] ta = ReadAndParseIntArr();
int t = ta[0];
int a = ta[1];
int[] h = ReadAndParseIntArr();
int ans = 0;
double diff = double.MaxValue;
for (int i = 0; i < h.Length; ++i) {
double d = Math.Abs(t - h[i] * 0.006 - a);
if (d < diff) {
diff = d;
ans = i;
}
}
Console.WriteLine(ans + 1);
}
#region よく使う便利関数
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); }
private static int[] ReadAndParseIntArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static long ReadAndParseLong() {
return long.Parse(Console.ReadLine());
}
private static long[] ReadAndParseLongArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
#endregion
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 0, 28, 0, 16, 31, 16, 12, 16, 12, 250], ["+", 0, 28, 0, 16, 31, 16, 12, 16, 12, 250]]
| 8
| 418
| 11
|
using System;
using System.Collections.Generic;
using System.Linq;
static class MainClass {
public struct City {
public long num;
public long year;
public int ID;
public City(long n, long y, int i) {
num = n;
year = y;
ID = i;
}
}
public static void Main(string[] args) {
var temp = Console.ReadLine().Split(' ').Select(long.Parse);
var N = temp.ElementAt(0);
var M = temp.ElementAt(1);
var CityList = new List<City>();
for (var i = 0; i < M; i++) {
var temp2 = Console.ReadLine().Split(' ').Select(long.Parse);
CityList.Add(new City(temp2.ElementAt(0), temp2.ElementAt(1), i));
}
var ans = new List<string>();
var sorted = CityList.OrderBy(x => x.year).ThenBy(x => x.num);
var count = 0;
var prev = sorted.First().num;
foreach (var c in sorted) {
count = prev == c.num ? count + 1 : 1;
ans.Add(String.Format("{0:000000}", c.num) +
String.Format("{0:000000}", count) +
String.Format("{0:000000}", c.ID));
}
ans = ans.OrderBy(x => int.Parse(x.Substring(12)))
.Select(s => s.Substring(0, 12))
.ToList();
ans.ForEach(Console.WriteLine);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
static class MainClass {
public struct City {
public long num;
public long year;
public int ID;
public City(long n, long y, int i) {
num = n;
year = y;
ID = i;
}
}
public static void Main(string[] args) {
var temp = Console.ReadLine().Split(' ').Select(long.Parse);
var N = temp.ElementAt(0);
var M = temp.ElementAt(1);
var CityList = new List<City>();
for (var i = 0; i < M; i++) {
var temp2 = Console.ReadLine().Split(' ').Select(long.Parse);
CityList.Add(new City(temp2.ElementAt(0), temp2.ElementAt(1), i));
}
var ans = new List<string>();
var sorted = CityList.OrderBy(x => x.num).ThenBy(x => x.year);
var count = 0;
var prev = sorted.First().num;
foreach (var c in sorted) {
count = prev == c.num ? count + 1 : 1;
ans.Add(String.Format("{0:000000}", c.num) +
String.Format("{0:000000}", count) +
String.Format("{0:000000}", c.ID));
prev = c.num;
}
ans = ans.OrderBy(x => int.Parse(x.Substring(12)))
.Select(s => s.Substring(0, 12))
.ToList();
ans.ForEach(Console.WriteLine);
}
}
|
[["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 141, 22]]
| 8
| 356
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharp_AtCoder {
class Program {
static void Main(string[] args) {
int[] NM =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int N = NM[0];
int M = NM[1];
Dictionary<int, int>[] prefs = new Dictionary<int, int>[N];
int[] city_to_pref = new int[M];
string[] id = new string[M];
for (int i = 0; i < N; i++)
prefs[i] = new Dictionary<int, int>();
for (int city_num = 0; city_num < M; city_num++) {
int[] PY =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int pref_num = PY[0] - 1;
int year = PY[1];
city_to_pref[city_num] = pref_num;
prefs[pref_num][city_num] = year;
}
for (int pref_num = 0; pref_num < N; pref_num++) {
// yearで昇順
int cnt = 1;
foreach (var city_to_year in prefs[pref_num].OrderBy(x => x.Value)) {
int city_num = city_to_year.Key;
int city_year = city_to_year.Value;
// city_numのidを求める
// pref_num(6) + cnt(6)
string left = (pref_num + 1).ToString();
for (int i = 0; i < 6 - left.Length; i++)
left = "0" + left;
string right = cnt.ToString();
for (int i = 0; i < 6 - right.Length; i++)
right = "0" + right;
id[city_num] = left + right;
cnt++;
}
}
Console.WriteLine(string.Join("\n", id));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharp_AtCoder {
class Program {
static void Main(string[] args) {
int[] NM =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int N = NM[0];
int M = NM[1];
Dictionary<int, int>[] prefs = new Dictionary<int, int>[N];
int[] city_to_pref = new int[M];
string[] id = new string[M];
for (int i = 0; i < N; i++)
prefs[i] = new Dictionary<int, int>();
for (int city_num = 0; city_num < M; city_num++) {
int[] PY =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int pref_num = PY[0] - 1;
int year = PY[1];
city_to_pref[city_num] = pref_num;
prefs[pref_num][city_num] = year;
}
for (int pref_num = 0; pref_num < N; pref_num++) {
// yearで昇順
int cnt = 1;
foreach (var city_to_year in prefs[pref_num].OrderBy(x => x.Value)) {
int city_num = city_to_year.Key;
int city_year = city_to_year.Value;
// city_numのidを求める
// pref_num(6) + cnt(6)
string left = (pref_num + 1).ToString();
int left_l = left.Length;
for (int i = 0; i < 6 - left_l; i++)
left = "0" + left;
string right = cnt.ToString();
int right_l = right.Length;
for (int i = 0; i < 6 - right_l; i++)
right = "0" + right;
id[city_num] = left + right;
cnt++;
}
}
Console.WriteLine(string.Join("\n", id));
}
}
}
|
[["+", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 15, 16, 12, 16, 12, 214, 205, 22], ["-", 0, 7, 15, 16, 12, 16, 12, 214, 0, 131], ["-", 0, 7, 15, 16, 12, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22]]
| 8
| 414
| 22
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace _0030 {
struct ID {
internal int ken;
internal int rank;
}
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int n = int.Parse(str[0]);
int m = int.Parse(str[1]);
var ans = new ID[m + 1];
var data = new Dictionary<long, int>[n + 1];
var sortdata = new Dictionary<long, int>[n + 1];
//インスタンスを作成
for (int i = 1; i <= n; i++) {
data[i] = new Dictionary<long, int>();
sortdata[i] = new Dictionary<long, int>();
}
int p;
long y;
// i市情報からデータを設定
for (int i = 1; i <= m; i++) {
str = Console.ReadLine().Split(' ');
p = int.Parse(str[0]);
y = long.Parse(str[1]);
data[p][y] = i;
}
//各県に対してkey(年数)を基準にソート
for (int i = 1; i <= n; i++) {
sortdata[i] =
data[i].OrderBy((x) => x.Key).ToDictionary(x => x.Key, x => x.Value);
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
cnt = 1;
foreach (var s in sortdata[i]) {
Console.WriteLine($"i = {i} {s.Key} {s.Value}");
ans[s.Value].ken = i;
ans[s.Value].rank = cnt;
cnt++;
}
}
for (int i = 1; i <= m; i++) {
Console.WriteLine(string.Format("{0:d6}{1:d6}", ans[i].ken, ans[i].rank));
}
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace _0030 {
struct ID {
internal int ken;
internal int rank;
}
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int n = int.Parse(str[0]);
int m = int.Parse(str[1]);
var ans = new ID[m + 1];
var data = new Dictionary<long, int>[n + 1];
var sortdata = new Dictionary<long, int>[n + 1];
//インスタンスを作成
for (int i = 1; i <= n; i++) {
data[i] = new Dictionary<long, int>();
sortdata[i] = new Dictionary<long, int>();
}
int p;
long y;
// i市情報からデータを設定
for (int i = 1; i <= m; i++) {
str = Console.ReadLine().Split(' ');
p = int.Parse(str[0]);
y = long.Parse(str[1]);
data[p][y] = i;
}
//各県に対してkey(年数)を基準にソート
for (int i = 1; i <= n; i++) {
sortdata[i] =
data[i].OrderBy((x) => x.Key).ToDictionary(x => x.Key, x => x.Value);
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
cnt = 1;
foreach (var s in sortdata[i]) {
// Console.WriteLine($"i = {i} {s.Key} {s.Value}");
ans[s.Value].ken = i;
ans[s.Value].rank = cnt;
cnt++;
}
}
for (int i = 1; i <= m; i++) {
Console.WriteLine(string.Format("{0:d6}{1:d6}", ans[i].ken, ans[i].rank));
}
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 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, 22], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 28, 0, 283, 0, 284, 0, 214, 205, 22], ["-", 0, 28, 0, 283, 0, 284, 0, 214, 0, 131], ["-", 0, 28, 0, 283, 0, 284, 0, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35]]
| 8
| 435
| 24
|
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) {
int[] nm = ReadLine().Split(' ').Select(int.Parse).ToArray();
int n = nm[0];
int m = nm[1];
var ls = new List<hoge>();
for (int i = 0; i < m; i++) {
long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray();
long p = s[0];
long y = s[1];
ls.Add(new hoge() { id = p, year = y, index = i });
}
ls = ls.OrderBy(x => x.id).ToList();
ls = ls.OrderBy(x => x.year).ToList();
var ans = new SortedDictionary<long, string>();
int cnt = 1;
long rem = ls[0].id;
for (int i = 0; i < m; i++) {
long p = ls[i].id;
long index = ls[i].index;
if (rem != p)
cnt = 1;
ans.Add(index, string.Format("{0:000000}{1:000000}", p, cnt));
cnt++;
}
foreach (var item in ans) {
WriteLine(item.Value);
}
}
}
class hoge {
public long id { get; set; }
public long year { get; set; }
public long index { get; set; }
}
}
|
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) {
long[] nm = ReadLine().Split(' ').Select(long.Parse).ToArray();
long n = nm[0];
long m = nm[1];
var ls = new List<hoge>();
for (long i = 0; i < m; i++) {
long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray();
long p = s[0];
long y = s[1];
ls.Add(new hoge() { id = p, year = y, index = i });
}
ls = ls.OrderBy(x => x.id).ThenBy(y => y.year).ToList();
var ans = new SortedDictionary<long, string>();
long cnt = 1;
long rem = ls[0].id;
for (int i = 0; i < m; i++) {
long p = ls[i].id;
long index = ls[i].index;
if (rem != p) {
cnt = 1;
rem = p;
}
ans.Add(index, string.Format("{0:000000}{1:000000}", p, cnt));
cnt++;
}
foreach (var item in ans) {
WriteLine(item.Value);
}
}
}
class hoge {
public long id { get; set; }
public long year { get; set; }
public long index { get; set; }
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 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], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 205, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 370
| 32
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;
class MyUtil {
public static int[] ReadIntArray() {
return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
}
class Bisect {
public static int BisectRight<T>(T[] a, T x)
where T : IComparable {
int lo = 0, hi = a.Length;
while (lo < hi) {
int mid = (lo + hi) / 2;
if (x.CompareTo(a[mid]) < 0) {
hi = mid;
} else {
lo = mid + 1;
}
}
return lo;
}
}
class Program {
public static void Main() {
var tmp = ReadIntArray();
int n = tmp[0], m = tmp[1];
int[] p = new int[m];
int[] y = new int[m];
List<int>[] dat = new List<int>[n];
WriteLine(-1);
for (int i = 0; i < n; i++) {
dat[i] = new List<int>();
}
WriteLine(0);
for (int i = 0; i < m; i++) {
tmp = ReadIntArray();
p[i] = tmp[0];
y[i] = tmp[1];
dat[p[i] - 1].Add(y[i]);
}
WriteLine(1);
int[][] dat2 = new int [n][];
for (int i = 0; i < n; i++) {
dat2[i] = dat[i].ToArray();
Array.Sort(dat2[i]);
}
WriteLine(2);
for (int i = 0; i < m; i++) {
int pn = p[i];
int yn = Bisect.BisectRight(dat2[pn - 1], y[i]);
Write(String.Format("{0:000000}", pn));
WriteLine(String.Format("{0:000000}", yn));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;
class MyUtil {
public static int[] ReadIntArray() {
return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
}
class Bisect {
public static int BisectRight<T>(T[] a, T x)
where T : IComparable {
int lo = 0, hi = a.Length;
while (lo < hi) {
int mid = (lo + hi) / 2;
if (x.CompareTo(a[mid]) < 0) {
hi = mid;
} else {
lo = mid + 1;
}
}
return lo;
}
}
class Program {
public static void Main() {
var tmp = ReadIntArray();
int n = tmp[0], m = tmp[1];
int[] p = new int[m];
int[] y = new int[m];
List<int>[] dat = new List<int>[n];
for (int i = 0; i < n; i++) {
dat[i] = new List<int>();
}
for (int i = 0; i < m; i++) {
tmp = ReadIntArray();
p[i] = tmp[0];
y[i] = tmp[1];
dat[p[i] - 1].Add(y[i]);
}
int[][] dat2 = new int [n][];
for (int i = 0; i < n; i++) {
dat2[i] = dat[i].ToArray();
Array.Sort(dat2[i]);
}
for (int i = 0; i < m; i++) {
int pn = p[i];
int yn = Bisect.BisectRight(dat2[pn - 1], y[i]);
Write(String.Format("{0:000000}", pn));
WriteLine(String.Format("{0:000000}", yn));
}
}
}
|
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 469
| 21
|
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
int n = input[0];
int m = input[1];
int[][] pyn = new int [m][];
for (var i = 0; i < m; i++) {
pyn[i] = new int[4]; // 4...id in same p
var pyin = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
pyn[i][0] = i + 1; // number
pyn[i][1] = pyin[0]; // p
pyn[i][2] = pyin[1]; // y
}
Array.Sort(pyn, (a, b) => a[2] - b[2]);
int[] cnt = new int[n];
for (var i = 0; i < m; i++) {
cnt[pyn[i][1] - 1]++;
pyn[i][3] = cnt[pyn[i][1] - 1];
}
for (var i = 0; i < m; i++) {
Console.WriteLine(string.Format("{ 0:d6}", pyn[i][1]) +
string.Format("{ 0:d6}", pyn[i][3]));
}
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
int n = input[0];
int m = input[1];
int[][] pyn = new int [m][];
for (var i = 0; i < m; i++) {
pyn[i] = new int[4]; // 4...id in same p
var pyin = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
pyn[i][0] = i + 1; // number
pyn[i][1] = pyin[0]; // p
pyn[i][2] = pyin[1]; // y
}
Array.Sort(pyn, (a, b) => a[2] - b[2]);
int[] cnt = new int[n];
for (var i = 0; i < m; i++) {
cnt[pyn[i][1] - 1]++;
pyn[i][3] = cnt[pyn[i][1] - 1];
}
Array.Sort(pyn, (a, b) => a[0] - b[0]);
for (var i = 0; i < m; i++) {
Console.WriteLine(String.Format("{0:D6}", pyn[i][1]) +
String.Format("{0:D6}", pyn[i][3]));
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 24], ["+", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 21], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 204, 205, 22], ["+", 0, 218, 8, 16, 31, 204, 206, 207, 0, 70], ["+", 8, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 218, 8, 16, 31, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 33], ["+", 0, 28, 0, 218, 8, 16, 12, 204, 205, 22], ["+", 0, 218, 8, 16, 12, 204, 206, 207, 0, 70], ["+", 8, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 218, 8, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 205, 22], ["-", 31, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 31, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["-", 12, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 12, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 345
| 31
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp {
class Program {
static void Main(string[] args) {
var str = Console.ReadLine();
var strs = str.Split(' ');
var N = int.Parse(strs[0]);
var M = int.Parse(strs[1]);
var PY = new List<List<int>>();
for (int i = 0; i < M; i++) {
str = Console.ReadLine();
strs = str.Split(' ');
var list = new List<int>();
list.Add(i);
list.Add(int.Parse(strs[0]));
list.Add(int.Parse(strs[1]));
list.Add(0);
PY.Add(list);
}
PY = PY.OrderBy(py => py[1]).ThenBy(py => py[2]).ToList();
var prevP = PY[0][1];
var no = 1;
for (int i = 0; i < PY.Count; i++) {
if (prevP != PY[i][1]) {
no = 1;
}
PY[i][3] = no++;
}
PY = PY.OrderBy(py => py[0]).ToList();
foreach (var item in PY) {
Console.WriteLine(item[1].ToString().PadLeft(6, '0') +
item[3].ToString().PadLeft(6, '0'));
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp {
class Program {
static void Main(string[] args) {
var str = Console.ReadLine();
var strs = str.Split(' ');
var N = int.Parse(strs[0]);
var M = int.Parse(strs[1]);
var PY = new List<List<int>>();
for (int i = 0; i < M; i++) {
str = Console.ReadLine();
strs = str.Split(' ');
var list = new List<int>();
list.Add(i);
list.Add(int.Parse(strs[0]));
list.Add(int.Parse(strs[1]));
list.Add(0);
PY.Add(list);
}
PY = PY.OrderBy(py => py[1]).ThenBy(py => py[2]).ToList();
var prevP = PY[0][1];
var no = 1;
for (int i = 0; i < PY.Count; i++) {
if (prevP != PY[i][1]) {
no = 1;
prevP = PY[i][1];
}
PY[i][3] = no++;
}
PY = PY.OrderBy(py => py[0]).ToList();
foreach (var item in PY) {
Console.WriteLine(item[1].ToString().PadLeft(6, '0') +
item[3].ToString().PadLeft(6, '0'));
}
}
}
}
|
[["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 204, 205, 204, 205, 22], ["+", 0, 11, 12, 204, 205, 204, 206, 207, 0, 70], ["+", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 351
| 10
|
using System;
class City {
public int i, p, y, b;
public City(int i, int p, int y) {
this.i = i;
this.p = p;
this.y = y;
}
}
class Program {
static void Main(string[] args) {
var nm = Console.ReadLine().Split(' ');
var n = int.Parse(nm[0]);
var m = int.Parse(nm[1]);
var cities = new City[m];
for (int i = 0; i < m; i++) {
var py = Console.ReadLine().Split(' ');
cities[i] = new City(i, int.Parse(py[0]), int.Parse(py[1]));
}
Array.Sort(cities, (a, b) => a.y - b.y);
Array.Sort(cities, (a, b) => a.p - b.p);
cities[0].b = 1;
for (int i = 1; i < m; i++) {
if (cities[i - 1].p == cities[i].p) {
cities[i].b = cities[i - 1].b + 1;
} else {
cities[i].b = 1;
}
}
Array.Sort(cities, (a, b) => a.i - b.i);
for (int i = 0; i < m; i++) {
Console.WriteLine("{0:D6}{1:D6}", cities[i].p, cities[i].b);
}
}
}
|
using System;
class City {
public int i, p, y, b;
public City(int i, int p, int y) {
this.i = i;
this.p = p;
this.y = y;
}
}
class Program {
static void Main(string[] args) {
var nm = Console.ReadLine().Split(' ');
var n = int.Parse(nm[0]);
var m = int.Parse(nm[1]);
var cities = new City[m];
for (int i = 0; i < m; i++) {
var py = Console.ReadLine().Split(' ');
cities[i] = new City(i, int.Parse(py[0]), int.Parse(py[1]));
}
Array.Sort(cities, (a, b) => a.p == b.p ? a.y - b.y : a.p - b.p);
cities[0].b = 1;
for (int i = 1; i < m; i++) {
if (cities[i - 1].p == cities[i].p) {
cities[i].b = cities[i - 1].b + 1;
} else {
cities[i].b = 1;
}
}
Array.Sort(cities, (a, b) => a.i - b.i);
for (int i = 0; i < m; i++) {
Console.WriteLine("{0:D6}{1:D6}", cities[i].p, cities[i].b);
}
}
}
|
[["+", 0, 218, 8, 41, 15, 16, 31, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 41, 15, 16, 17, 60], ["+", 0, 218, 8, 41, 15, 16, 12, 214, 205, 22], ["+", 0, 218, 8, 41, 15, 16, 12, 214, 0, 131], ["+", 0, 218, 8, 41, 15, 16, 12, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 41, 0, 101], ["+", 0, 218, 8, 41, 64, 16, 31, 214, 205, 22], ["+", 0, 218, 8, 41, 64, 16, 31, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 3, 4, 0, 28, 0, 218, 54, 55, 0, 24], ["-", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 54, 55, 0, 21], ["-", 3, 4, 0, 28, 0, 218, 54, 55, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 41, 0, 102]]
| 8
| 355
| 23
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC113C {
static class MainClass {
public static void Main(string[] args) {
string[] input1 = Console.ReadLine().Split(' ');
int N = int.Parse(input1[0]);
int M = int.Parse(input1[1]);
// 2 11
// 1 3
// 1 5
// 2 2
// 1 8
// 1 4
// 2 9
// 2 30
// 3 2
// 3 99
// 3 1
// 3 1
int[][] PY = new int [M][];
for (int i = 0; i < M; i++) {
string[] input2 = Console.ReadLine().Split(' ');
int[] pandy = new int[4];
pandy[0] = int.Parse(input2[0]); //県
pandy[1] = int.Parse(input2[1]); //年
pandy[2] = i; //もとのindex
pandy[3] = 0; //市の中の順番
PY[i] = pandy;
}
// PY.ToList().Sort((a, b) => a[0] - b[0]);//県でソート
List<int[]> dst = PY.ToList().OrderBy(a => a[0]).ThenBy(a => a[1]).ToList();
List<int> grp = dst.GroupBy(a => a[0]).Select(c => c.Count()).ToList();
int diff = 0;
for (int i = 0; i < M; i++) {
if (i != 0) {
if (dst[i][0] != dst[i - 1][0]) {
diff = diff + grp[0];
grp.RemoveAt(0);
}
}
dst[i][3] = int.Parse(string.Format("{0,10}", i - diff + 1));
}
foreach (int[] item in dst) {
Console.WriteLine(item[0] + " " + item[3]);
}
List<string> ans = dst.ToList()
.OrderBy(a => a[2])
.ToList()
.Select(a => string.Format("{0:D6}", a[0]) +
String.Format("{0:D6}", a[3]))
.ToList();
foreach (var items in ans) {
Console.WriteLine(items);
}
return;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC113C {
static class MainClass {
public static void Main(string[] args) {
string[] input1 = Console.ReadLine().Split(' ');
int N = int.Parse(input1[0]);
int M = int.Parse(input1[1]);
int[][] PY = new int [M][];
for (int i = 0; i < M; i++) {
string[] input2 = Console.ReadLine().Split(' ');
int[] pandy = new int[4];
pandy[0] = int.Parse(input2[0]); //県
pandy[1] = int.Parse(input2[1]); //年
pandy[2] = i; //もとのindex
pandy[3] = 0; //市の中の順番
PY[i] = pandy;
}
// PY.ToList().Sort((a, b) => a[0] - b[0]);//県でソート
List<int[]> dst = PY.ToList().OrderBy(a => a[0]).ThenBy(a => a[1]).ToList();
List<int> grp = dst.GroupBy(a => a[0]).Select(c => c.Count()).ToList();
int diff = 0;
for (int i = 0; i < M; i++) {
if (i != 0) {
if (dst[i][0] != dst[i - 1][0]) {
diff = diff + grp[0];
grp.RemoveAt(0);
}
}
dst[i][3] = int.Parse(string.Format("{0,10}", i - diff + 1));
}
List<string> ans = dst.ToList()
.OrderBy(a => a[2])
.ToList()
.Select(a => string.Format("{0:D6}", a[0]) +
String.Format("{0:D6}", a[3]))
.ToList();
foreach (var items in ans) {
Console.WriteLine(items);
}
return;
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 24], ["-", 0, 195, 8, 196, 0, 210, 39, 224, 39, 199], ["-", 8, 196, 0, 210, 39, 224, 225, 226, 0, 70], ["-", 8, 196, 0, 210, 39, 224, 225, 226, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 25], ["-", 0, 195, 8, 196, 0, 210, 8, 196, 0, 45], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 16, 31, 16, 31, 204, 205, 22], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46]]
| 8
| 485
| 30
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CS.Solve {
class Program {
static void Main(string[] args) {
var NM = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
List<int[]> x = new List<int[]>();
foreach (var i in Enumerable.Range(0, NM[1])) {
var tmp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
x.Add(new int[] { tmp[0], tmp[1], i, 0 });
}
var y = x.OrderBy(p => p[0]).OrderBy(p => p[1]).ToArray();
y[0][3] = 0;
var pi = y[0][0];
var junban = 0;
foreach (var tmp in y) {
if (tmp[0] == pi) {
tmp[3] = junban;
junban++;
} else {
junban = 0;
tmp[3] = 0;
}
}
foreach (var tmp in y.OrderBy(p => p[2])) {
Console.WriteLine("{0:000000}{1:000000}", tmp[0], tmp[3] + 1);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CS.Solve {
class Program {
static void Main(string[] args) {
var NM = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
List<int[]> x = new List<int[]>();
foreach (var i in Enumerable.Range(0, NM[1])) {
var tmp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
x.Add(new int[] { tmp[0], tmp[1], i, 0 });
}
var y = x.OrderBy(p => p[0]).ThenBy(p => p[1]).ToList();
y[0][3] = 0;
var pi = y[0][0];
var junban = 0;
foreach (var tmp in y.Skip(1)) {
if (tmp[0] == pi) {
junban++;
tmp[3] = junban;
} else {
junban = 0;
tmp[3] = 0;
pi = tmp[0];
}
}
foreach (var tmp in y.OrderBy(p => p[2])) {
Console.WriteLine("{0:000000}{1:000000}", tmp[0], tmp[3] + 1);
}
}
}
}
|
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 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], ["+", 0, 210, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 25], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
| 8
| 303
| 22
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// Submission #3535255 - AtCoder Beginner Contest 113 | AtCoder
// https://abc113.contest.atcoder.jp/submissions/3535255
public class Program_ABC113_C_kuuso1 {
public static void Main() {
int N, M;
int[] P, Y;
var d = ria();
N = d[0];
M = d[1];
P = new int[M];
Y = new int[M];
for (int i = 0; i < M; i++) {
d = ria();
P[i] = d[0];
Y[i] = d[1];
}
var di = new Dictionary<int, List<int[]>>();
for (int i = 0; i < M; i++) {
if (!di.ContainsKey(P[i])) {
di.Add(P[i], new List<int[]>());
}
di[P[i]].Add(new[] { i, Y[i] });
}
var ans = new String[M];
foreach (var pr in di.Keys) {
// var l = di[pr].ToList();
var l = di[pr];
// l.Sort((p, q) => p[1].CompareTo(q[1]));
l.Sort();
for (int i = 0; i < l.Count; i++) {
ans[l[i][0]] = String.Format("{0:D06}{1:D06}", pr, i + 1);
}
}
Console.WriteLine(String.Join("\r\n", ans));
} // main
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// Submission #3535255 - AtCoder Beginner Contest 113 | AtCoder
// https://abc113.contest.atcoder.jp/submissions/3535255
public class Program_ABC113_C_kuuso1 {
public static void Main() {
int N, M;
int[] P, Y;
var d = ria();
N = d[0];
M = d[1];
P = new int[M];
Y = new int[M];
for (int i = 0; i < M; i++) {
d = ria();
P[i] = d[0];
Y[i] = d[1];
}
var di = new Dictionary<int, List<int[]>>();
for (int i = 0; i < M; i++) {
if (!di.ContainsKey(P[i])) {
di.Add(P[i], new List<int[]>());
}
di[P[i]].Add(new[] { i, Y[i] });
}
var ans = new String[M];
foreach (var pr in di.Keys) {
// var l = di[pr].ToList();
var l = di[pr];
l.Sort((p, q) => p[1].CompareTo(q[1]));
for (int i = 0; i < l.Count; i++) {
ans[l[i][0]] = String.Format("{0:D06}{1:D06}", pr, i + 1);
}
}
Console.WriteLine(String.Join("\r\n", ans));
} // main
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
}
|
[["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 24], ["+", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 21], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 218, 8, 213, 63, 214, 205, 204, 205, 22], ["+", 8, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 8, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 24], ["+", 8, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
| 8
| 362
| 18
|
using System;
using System.Linq;
using System.Collections.Generic;
class MondaiC {
static void Main() {
var line =
Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
var N = line[0];
var M = line[1];
var index = new int[M];
var city = new long[M];
var pri = new int[M];
for (int i = 0; i < M; ++i) {
var l =
Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
pri[i] = l[0];
city[i] = l[1];
index[i] = i;
}
Array.Sort(city, index);
var ans = new string[M];
var priCount = new int[line[0] + 1];
for (int i = 0; i < M; ++i) {
priCount[pri[i]]++;
ans[index[i]] = string.Format("{0:D6}", pri[i]) +
string.Format("{0:D6}", priCount[pri[i]]);
}
foreach (var a in ans) {
Console.WriteLine(a);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class MondaiC {
static void Main() {
var line =
Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
var N = line[0];
var M = line[1];
var index = new int[M];
var city = new long[M];
var pri = new int[M];
for (int i = 0; i < M; ++i) {
var l =
Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
pri[i] = l[0];
city[i] = l[1];
index[i] = i;
}
Array.Sort(city, index);
var ans = new string[M];
var priCount = new int[line[0] + 1];
for (int i = 0; i < M; ++i) {
priCount[pri[index[i]]]++;
ans[index[i]] = string.Format("{0:D6}", pri[index[i]]) +
string.Format("{0:D6}", priCount[pri[index[i]]]);
}
foreach (var a in ans) {
Console.WriteLine(a);
}
}
}
|
[["+", 0, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73]]
| 8
| 288
| 9
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder.ABC113.B {
class Program {
static void Main() {
var sc = new Scanner();
var n = sc.Nextint();
var m = sc.Nextint();
var P = new int[m];
var Y = new long[m];
for (int i = 0; i < m; i++) {
P[i] = sc.Nextint();
Y[i] = sc.NextLong();
}
var identificationNumbers = new string[m];
var X = new int[m];
var sortedY = Y.Select((val, idx) => new { Year = val, Index = idx })
.OrderBy(elem => elem.Year)
.ToArray();
foreach (var item in sortedY) {
var idx = item.Index;
Console.Error.WriteLine($"{idx} : {item.Year}");
var idnum = string.Format("{0:D6}{1:D6}", P[idx], ++X[P[idx]]);
identificationNumbers[idx] = idnum;
}
foreach (var item in identificationNumbers) {
Console.WriteLine(item);
}
}
}
class Scanner {
string[] s;
long i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return Next();
i = 0;
return s[i++];
}
public int Nextint() { return int.Parse(Next()); }
public int[] Arrayint(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Nextint() + add;
}
return Array;
}
public long NextLong() { return long.Parse(Next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (long i = 0; i < N; i++) {
Array[i] = NextLong() + add;
}
return Array;
}
public double NextDouble() { return double.Parse(Next()); }
public double[] ArrayDouble(long N, double add = 0) {
double[] Array = new double[N];
for (long i = 0; i < N; i++) {
Array[i] = NextDouble() + add;
}
return Array;
}
public decimal NextDecimal() { return decimal.Parse(Next()); }
public decimal[] ArrayDecimal(long N, decimal add = 0) {
decimal[] Array = new decimal[N];
for (long i = 0; i < N; i++) {
Array[i] = NextDecimal();
}
return Array;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder.ABC113.C {
class Program {
static void Main() {
var sc = new Scanner();
var n = sc.Nextint();
var m = sc.Nextint();
var P = new int[m];
var Y = new long[m];
for (int i = 0; i < m; i++) {
P[i] = sc.Nextint();
Y[i] = sc.NextLong();
}
var identificationNumbers = new string[m];
var X = new int[P.Max() + 1];
var sortedY = Y.Select((val, idx) => new { Year = val, Index = idx })
.OrderBy(elem => elem.Year)
.ToArray();
foreach (var item in sortedY) {
var idx = item.Index;
Console.Error.WriteLine($"{idx} : {item.Year}");
var idnum = string.Format("{0:D6}{1:D6}", P[idx], ++X[P[idx]]);
identificationNumbers[idx] = idnum;
}
foreach (var item in identificationNumbers) {
Console.WriteLine(item);
}
}
}
class Scanner {
string[] s;
long i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return Next();
i = 0;
return s[i++];
}
public int Nextint() { return int.Parse(Next()); }
public int[] Arrayint(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Nextint() + add;
}
return Array;
}
public long NextLong() { return long.Parse(Next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (long i = 0; i < N; i++) {
Array[i] = NextLong() + add;
}
return Array;
}
public double NextDouble() { return double.Parse(Next()); }
public double[] ArrayDouble(long N, double add = 0) {
double[] Array = new double[N];
for (long i = 0; i < N; i++) {
Array[i] = NextDouble() + add;
}
return Array;
}
public decimal NextDecimal() { return decimal.Parse(Next()); }
public decimal[] ArrayDecimal(long N, decimal add = 0) {
decimal[] Array = new decimal[N];
for (long i = 0; i < N; i++) {
Array[i] = NextDecimal();
}
return Array;
}
}
}
|
[["-", 36, 36, 0, 208, 0, 209, 141, 232, 141, 22], ["+", 36, 36, 0, 208, 0, 209, 141, 232, 141, 22], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 225, 226, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 225, 226, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 225, 226, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 225, 226, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 225, 226, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203]]
| 8
| 700
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;
class MyUtil {
public static long[] ReadLongArray() {
return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
}
class Program {
static long[] sz;
static long[] p;
public static void Main() {
sz = new long[51];
p = new long[51];
sz[0] = p[0] = 1;
for (int i = 1; i <= 50; i++) {
sz[i] = sz[i - 1] * 2 + 3;
p[i] = p[i - 1] * 2 + 1;
}
var tmp = ReadLongArray();
int n = (int)tmp[0];
long x = tmp[1];
WriteLine(numPaties(n, x));
}
static long numPaties(int lv, long x) {
if (x == 1)
return 0;
else if (x < sz[lv - 1] + 2)
return numPaties(lv - 1, x - 1);
else if (x == sz[lv - 1] + 2)
return p[lv - 1] + 1;
else if (x < sz[lv]) {
return p[lv - 1] + 1 + numPaties(lv - 1, x - sz[lv - 1] - 2);
} else {
return p[lv - 1] * 2 + 1;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;
class MyUtil {
public static long[] ReadLongArray() {
return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
}
class Program {
static long[] a;
static long[] p;
public static void Main() {
a = new long[51];
p = new long[51];
a[0] = p[0] = 1;
for (int i = 1; i <= 50; i++) {
a[i] = a[i - 1] * 2 + 3;
p[i] = p[i - 1] * 2 + 1;
}
var tmp = ReadLongArray();
int n = (int)tmp[0];
long x = tmp[1];
WriteLine(f(n, x));
}
static long f(int lv, long x) {
if (lv == 0)
return 1;
if (x == 1)
return 0;
else if (x < a[lv - 1] + 2)
return f(lv - 1, x - 1);
else if (x == a[lv - 1] + 2)
return p[lv - 1] + 1;
else if (x < a[lv])
return p[lv - 1] + 1 + f(lv - 1, x - a[lv - 1] - 2);
else
return p[lv - 1] * 2 + 1;
}
}
|
[["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["+", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 11, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 204, 205, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 75, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 75, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["-", 0, 57, 75, 57, 64, 37, 0, 213, 63, 22], ["+", 0, 57, 75, 57, 64, 37, 0, 213, 63, 22], ["-", 75, 57, 75, 57, 15, 16, 12, 204, 205, 22], ["+", 75, 57, 75, 57, 15, 16, 12, 204, 205, 22], ["-", 75, 57, 75, 57, 75, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 37, 0, 16, 12, 213, 63, 22], ["+", 75, 57, 64, 37, 0, 16, 12, 213, 63, 22], ["-", 0, 28, 0, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 16, 12, 204, 205, 22], ["-", 75, 57, 75, 57, 75, 57, 64, 196, 0, 46], ["-", 75, 57, 75, 57, 75, 57, 75, 196, 0, 45], ["-", 75, 57, 75, 57, 75, 57, 75, 196, 0, 46]]
| 8
| 333
| 39
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;
class MyUtil {
public static long[] ReadLongArray() {
return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
}
class Program {
static long[] sz;
static long[] p;
public static void Main() {
sz = new long[51];
p = new long[51];
sz[0] = p[0] = 1;
for (int i = 1; i <= 50; i++) {
sz[i] = sz[i - 1] * 2 + 3;
p[i] = p[i - 1] * 2 + 1;
}
var tmp = ReadLongArray();
int n = (int)tmp[0];
long x = tmp[1];
WriteLine(numPaties(n, x));
}
static long numPaties(int lv, long x) {
if (x == 1) {
return 0;
} else if (x < sz[lv - 1] + 2) {
return numPaties(lv - 1, x - 1);
} else if (x == sz[lv - 1] + 2) {
return p[lv - 1] + 1;
} else if (x < sz[lv]) {
return p[lv - 1] + 1 + numPaties(lv - 1, x - sz[lv - 1] - 2);
} else {
return p[lv];
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;
class MyUtil {
public static long[] ReadLongArray() {
return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
}
class Program {
static long[] sz;
static long[] p;
public static void Main() {
sz = new long[51];
p = new long[51];
sz[0] = p[0] = 1;
for (int i = 1; i <= 50; i++) {
sz[i] = sz[i - 1] * 2 + 3;
p[i] = p[i - 1] * 2 + 1;
}
var tmp = ReadLongArray();
int n = (int)tmp[0];
long x = tmp[1];
WriteLine(numPaties(n, x));
}
static long numPaties(int lv, long x) {
if (lv == 0)
return 1;
if (x == 1)
return 0;
else if (x < sz[lv - 1] + 2)
return numPaties(lv - 1, x - 1);
else if (x == sz[lv - 1] + 2)
return p[lv - 1] + 1;
else if (x < sz[lv])
return p[lv - 1] + 1 + numPaties(lv - 1, x - sz[lv - 1] - 2);
else
return p[lv - 1] * 2 + 1;
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["-", 0, 57, 75, 57, 75, 57, 64, 196, 0, 45], ["-", 0, 57, 75, 57, 75, 57, 64, 196, 0, 46], ["-", 75, 57, 75, 57, 75, 57, 64, 196, 0, 45], ["-", 75, 57, 75, 57, 75, 57, 64, 196, 0, 46], ["-", 75, 57, 75, 57, 75, 57, 75, 196, 0, 45], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 75, 57, 75, 37, 0, 16, 31, 16, 17, 48], ["+", 75, 57, 75, 37, 0, 16, 31, 16, 12, 203], ["+", 75, 57, 75, 57, 75, 37, 0, 16, 17, 72], ["+", 75, 57, 75, 57, 75, 37, 0, 16, 12, 203], ["-", 75, 57, 75, 57, 75, 57, 75, 196, 0, 46]]
| 8
| 333
| 25
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Prog {
private const int INF = 1000000007;
private static long[] data;
private static long[] Pdata;
public struct Pair<T> {
public T x, y;
public Pair(T x, T y) {
this.x = x;
this.y = y;
}
}
public static void Solve() {
int N = NextInt();
long X = NextLong();
data = new long[60];
Pdata = new long[60];
data[0] = 1;
Pdata[0] = 1;
for (int i = 0; i <= 50; i++) {
data[i + 1] = data[i] * 2 + 3;
Pdata[i + 1] = Pdata[i] * 2 + 1;
}
Console.WriteLine(Christmas(N, X));
}
public static long Christmas(long n, long x) {
//レベル0バーガーはパティなので
if (n == 0)
return 1;
//前のレベルバーガーを計算
long h = data[n - 1];
// Bしか食べれない
if (x == 1)
return 0;
//前のレベルの半分も食べれない
else if (x <= h + 1)
return Christmas(n - 1, x - 1);
//ちょうど半分
else if (x == h + 2)
return Pdata[n - 1] + 1;
//半分以上食べれる
else if (x <= h * 2 + 2)
return Pdata[n - 1] + 1 + Christmas(n - 1, x - data[n - 1] - 2);
//全部食べる
else
return Pdata[n - 1] + 1;
}
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
}
public class Input {
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static char NextChar() {
Confirm();
return char.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Prog {
private const int INF = 1000000007;
private static long[] data;
private static long[] Pdata;
public struct Pair<T> {
public T x, y;
public Pair(T x, T y) {
this.x = x;
this.y = y;
}
}
public static void Solve() {
int N = NextInt();
long X = NextLong();
data = new long[60];
Pdata = new long[60];
data[0] = 1;
Pdata[0] = 1;
for (int i = 0; i <= 50; i++) {
data[i + 1] = data[i] * 2 + 3;
Pdata[i + 1] = Pdata[i] * 2 + 1;
}
Console.WriteLine(Christmas(N, X));
}
public static long Christmas(long n, long x) {
//レベル0バーガーはパティなので
if (n == 0)
return 1;
//前のレベルバーガーを計算
long h = data[n - 1];
long p = Pdata[n - 1];
// Bしか食べれない
if (x == 1)
return 0;
//前のレベルの半分も食べれない
else if (x <= h + 1)
return Christmas(n - 1, x - 1);
//ちょうど半分
else if (x == h + 2)
return p + 1;
//半分以上食べれる
else if (x <= h * 2 + 2)
return p + 1 + Christmas(n - 1, x - h - 2);
//全部食べる
else
return 2 * p + 1;
}
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
}
public class Input {
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static char NextChar() {
Confirm();
return char.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 75, 57, 64, 37, 0, 16, 31, 204, 205, 22], ["-", 64, 37, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 64, 37, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 75, 57, 75, 57, 64, 37, 0, 16, 31, 22], ["-", 64, 37, 0, 16, 31, 16, 31, 204, 205, 22], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 75, 57, 64, 37, 0, 16, 31, 16, 31, 22], ["-", 0, 28, 0, 16, 31, 16, 12, 204, 205, 22], ["-", 0, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 75, 57, 75, 37, 0, 16, 31, 204, 205, 22], ["-", 75, 37, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 75, 37, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 75, 57, 75, 37, 0, 16, 31, 16, 31, 203], ["+", 75, 57, 75, 37, 0, 16, 31, 16, 17, 48], ["+", 75, 57, 75, 37, 0, 16, 31, 16, 12, 22]]
| 8
| 691
| 40
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
static void Main(string[] args) {
var nx = Array.ConvertAll(ReadLine().Split(' '), long.Parse);
WriteLine(Get(nx[0], nx[1]));
}
private static long Get(long num, long x) {
if (num == 0)
return 0;
if (x == Pow(2, num + 1) - 1)
return (long)Pow(2, num);
else if (x > Pow(2, num + 1) - 1)
return (long)Pow(2, num) + Get(num - 1, x - (long)Pow(2, num + 1) + 1);
else
return Get(num - 1, x - 1);
}
private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
private const int MOD = 1000000007;
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
static void Main(string[] args) {
var nx = Array.ConvertAll(ReadLine().Split(' '), long.Parse);
// for (var i = 1; i <= 13; i++) WriteLine(Get(2, i));
WriteLine(Get(nx[0], nx[1]));
}
private static long Get(long num, long x) {
if (num == 0)
return x <= 0 ? 0 : 1;
if (x == (long)Pow(2, num + 1) - 1)
return (long)Pow(2, num);
else if (x > (long)Pow(2, num + 1) - 1)
return (long)Pow(2, num) + Get(num - 1, x - (long)Pow(2, num + 1) + 1);
else
return Get(num - 1, x - 1);
}
private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
private const int MOD = 1000000007;
}
|
[["+", 0, 57, 64, 37, 0, 41, 15, 16, 31, 22], ["+", 0, 57, 64, 37, 0, 41, 15, 16, 17, 19], ["+", 0, 57, 64, 37, 0, 41, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 37, 0, 41, 0, 101], ["+", 8, 196, 0, 57, 64, 37, 0, 41, 0, 102], ["+", 8, 196, 0, 57, 64, 37, 0, 41, 75, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 74, 0, 24], ["+", 0, 57, 15, 16, 12, 16, 31, 74, 39, 199], ["+", 0, 57, 15, 16, 12, 16, 31, 74, 0, 25], ["+", 75, 57, 15, 16, 12, 16, 31, 74, 0, 24], ["+", 75, 57, 15, 16, 12, 16, 31, 74, 39, 199], ["+", 75, 57, 15, 16, 12, 16, 31, 74, 0, 25]]
| 8
| 214
| 12
|
using System;
namespace ABC115_D___Christmas {
class Program {
static long[] burger;
static long[] patty;
static void Main(string[] args) {
var NX = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
var N = NX[0];
var X = NX[1];
burger = new long[N + 1];
burger[0] = 1;
for (int i = 1; i < N + 1; i++)
burger[i] = burger[i - 1] * 2 + 3;
patty = new long[N + 1];
patty[0] = 1;
for (int i = 1; i < N + 1; i++)
patty[i] = patty[i - 1] * 2 + 1;
Console.WriteLine(Eat(N, X));
}
static long Eat(long N, long X) {
if (N == 0)
return X == 1 ? 1 : 0;
if (X <= burger[N - 1] + 1)
return Eat(N - 1, X - 1);
return 1 + patty[N - 1] + Eat(N - 1, X - 2 - burger[N - 1]);
}
}
}
|
using System;
namespace ABC115_D___Christmas {
class Program {
static long[] burger;
static long[] patty;
static void Main(string[] args) {
var NX = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
var N = NX[0];
var X = NX[1];
burger = new long[N + 1];
burger[0] = 1;
for (int i = 1; i < N + 1; i++)
burger[i] = burger[i - 1] * 2 + 3;
patty = new long[N + 1];
patty[0] = 1;
for (int i = 1; i < N + 1; i++)
patty[i] = patty[i - 1] * 2 + 1;
Console.WriteLine(Eat(N, X));
}
static long Eat(long N, long X) {
if (N == 0)
return X == 1 ? 1 : 0;
if (X <= burger[N - 1] + 1)
return Eat(N - 1, X - 1);
if (X == burger[N])
return patty[N];
return 1 + patty[N - 1] + Eat(N - 1, X - 2 - burger[N - 1]);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 37, 0, 204, 205, 22], ["+", 0, 57, 64, 37, 0, 204, 206, 207, 0, 70], ["+", 64, 37, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 64, 37, 0, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38]]
| 8
| 265
| 15
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;
public class D {
public static void Main() {
int N = GetInt();
long X = GetLong();
long[] numP = new long[N + 1];
long[] numTotal = new long[N + 1];
numP[0] = 1L;
numTotal[0] = 1L;
for (int i = 1; i <= N; i++) {
numP[i] = 1L + 2L * numP[i - 1];
numTotal[i] = 3L + 2L * numTotal[i - 1];
}
Solver solver = new Solver(numP, numTotal);
Console.WriteLine(solver.eat(N, X));
}
}
public class Solver {
private long[] m_numP;
private long[] m_numTotal;
public Solver(long[] numP, long[] numTotal) {
m_numP = numP;
m_numTotal = numTotal;
}
public long eat(int level, long length) {
if (length == 1L) {
return 0L;
} else if (length < 1L + m_numTotal[level - 1]) {
return eat(level - 1, length - 1L);
} else if (length == 1L + m_numTotal[level - 1]) {
return m_numP[level - 1L];
} else if (length == 2L + m_numTotal[level - 1]) {
return m_numP[level - 1] + 1L;
} else if (length < 3L + 2 * m_numTotal[level - 1]) {
return m_numP[level - 1] + 1L +
eat(level - 1, length - 2L - m_numTotal[level - 1]);
} else {
return m_numP[level];
}
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() { return int.Parse(getArg()); }
public static long GetLong() { return long.Parse(getArg()); }
public static double GetDouble() { return double.Parse(getArg()); }
public static string GetString() { return getArg(); }
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;
public class D {
public static void Main() {
int N = GetInt();
long X = GetLong();
long[] numP = new long[N + 1];
long[] numTotal = new long[N + 1];
numP[0] = 1L;
numTotal[0] = 1L;
for (int i = 1; i <= N; i++) {
numP[i] = 1L + 2L * numP[i - 1];
numTotal[i] = 3L + 2L * numTotal[i - 1];
}
Solver solver = new Solver(numP, numTotal);
Console.WriteLine(solver.eat(N, X));
}
}
public class Solver {
private long[] m_numP;
private long[] m_numTotal;
public Solver(long[] numP, long[] numTotal) {
m_numP = numP;
m_numTotal = numTotal;
}
public long eat(int level, long length) {
if (length == 1L) {
return (level == 0) ? 1 : 0;
} else if (length < 1L + m_numTotal[level - 1]) {
return eat(level - 1, length - 1L);
} else if (length == 1L + m_numTotal[level - 1]) {
return m_numP[level - 1L];
} else if (length == 2L + m_numTotal[level - 1]) {
return m_numP[level - 1] + 1L;
} else if (length < 3L + 2 * m_numTotal[level - 1]) {
return m_numP[level - 1] + 1L +
eat(level - 1, length - 2L - m_numTotal[level - 1]);
} else {
return m_numP[level];
}
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() { return int.Parse(getArg()); }
public static long GetLong() { return long.Parse(getArg()); }
public static double GetDouble() { return double.Parse(getArg()); }
public static string GetString() { return getArg(); }
}
|
[["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 203], ["+", 64, 196, 0, 37, 0, 41, 15, 23, 0, 24], ["+", 0, 37, 0, 41, 15, 23, 0, 16, 31, 22], ["+", 0, 37, 0, 41, 15, 23, 0, 16, 17, 60], ["+", 0, 37, 0, 41, 15, 23, 0, 16, 12, 203], ["+", 64, 196, 0, 37, 0, 41, 15, 23, 0, 25], ["+", 0, 57, 64, 196, 0, 37, 0, 41, 0, 101], ["+", 0, 57, 64, 196, 0, 37, 0, 41, 64, 203], ["+", 0, 57, 64, 196, 0, 37, 0, 41, 0, 102], ["+", 0, 57, 64, 196, 0, 37, 0, 41, 75, 203]]
| 8
| 511
| 10
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
int N = int.Parse(str[0]);
long X = long.Parse(str[1]);
long[] P = new long[51];
long[] B = new long[51];
P[0] = 1;
B[0] = 0;
for (var i = 1; i <= 50; i++) {
P[i] = P[i - 1] * 2 + 1;
B[i] = B[i - 1] * 2 + 2;
}
long ans = fa(N, X, P, B);
Console.WriteLine(ans);
}
public static long fa(int n, long x, long[] P, long[] B) {
long ans = 0;
if (x <= 1) {
ans = 0;
} else if (x <= 1 + P[n - 1] + B[n - 1]) {
ans = fa(n - 1, x - 1, P, B);
} else if (x <= 1 + P[n - 1] + B[n - 1] + 1) {
ans = P[n - 1] + 1;
} else if (x <= 1 + P[n - 1] + B[n - 1] + 1 + P[n - 1] + B[n - 1]) {
ans = P[n - 1] + 1 + fa(n - 1, x - 1 - P[n - 1] - B[n - 1] - 1, P, B);
} else {
ans = P[n];
}
return ans;
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
int N = int.Parse(str[0]);
long X = long.Parse(str[1]);
long[] P = new long[51];
long[] B = new long[51];
P[0] = 1;
B[0] = 0;
for (var i = 1; i <= 50; i++) {
P[i] = P[i - 1] * 2 + 1;
B[i] = B[i - 1] * 2 + 2;
}
long ans = fa(N, X, P, B);
Console.WriteLine(ans);
}
public static long fa(int n, long x, long[] P, long[] B) {
long ans = 0;
if (n == 0) {
ans = 1;
} else if (x <= 1) {
ans = 0;
} else if (x <= 1 + P[n - 1] + B[n - 1]) {
ans = fa(n - 1, x - 1, P, B);
} else if (x <= 1 + P[n - 1] + B[n - 1] + 1) {
ans = P[n - 1] + 1;
} else if (x <= 1 + P[n - 1] + B[n - 1] + 1 + P[n - 1] + B[n - 1]) {
ans = P[n - 1] + 1 + fa(n - 1, x - 1 - P[n - 1] - B[n - 1] - 1, P, B);
} else {
ans = P[n];
}
return ans;
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24]]
| 8
| 381
| 13
|
using System;
using System.Collections.Generic;
using System.Text;
namespace AtTest.ABC_115 {
class D {
static void Main(string[] args) {
Method(args);
Console.ReadLine();
}
static void Method(string[] args) {
long[] nx = ReadLongs();
long n = nx[0];
long x = nx[1];
var pCnt = new long [n + 1][]; // all, p L= 0 ~ n
pCnt[0] = new long[2] { 1, 1 };
for (int i = 1; i <= n; i++) {
pCnt[i] =
new long[2] { pCnt[i - 1][0] * 2 + 3, pCnt[i - 1][1] * 2 + 1 };
}
long cnt = 0;
long nn = n;
long now = x - 1;
while (nn > 0) {
if (now == 0) {
Console.WriteLine(cnt);
return;
} else if (now < pCnt[nn][0] / 2) {
now--;
nn--;
} else if (now == pCnt[nn][0] / 2) {
Console.WriteLine(cnt + pCnt[nn - 1][1] + 1);
return;
} else if (now < pCnt[nn][0] - 1) {
now -= pCnt[nn - 1][0] + 2;
cnt += pCnt[nn - 1][1];
nn--;
} else if (now == pCnt[nn][0] - 1) {
Console.WriteLine(cnt + pCnt[nn][1]);
return;
}
}
Console.WriteLine(cnt + 1 + pCnt[n][0]);
}
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
namespace AtTest.ABC_115 {
class D {
static void Main(string[] args) {
Method(args);
Console.ReadLine();
}
static void Method(string[] args) {
long[] nx = ReadLongs();
long n = nx[0];
long x = nx[1];
var pCnt = new long [n + 1][]; // all, p L= 0 ~ n
pCnt[0] = new long[2] { 1, 1 };
for (int i = 1; i <= n; i++) {
pCnt[i] =
new long[2] { pCnt[i - 1][0] * 2 + 3, pCnt[i - 1][1] * 2 + 1 };
}
long cnt = 0;
long nn = n;
long now = x - 1;
while (nn > 0) {
if (now == 0) {
Console.WriteLine(cnt);
return;
} else if (now < pCnt[nn][0] / 2) {
now--;
nn--;
} else if (now == pCnt[nn][0] / 2) {
Console.WriteLine(cnt + pCnt[nn - 1][1] + 1);
return;
} else if (now < pCnt[nn][0] - 1) {
now -= pCnt[nn - 1][0] + 2;
cnt += pCnt[nn - 1][1] + 1;
nn--;
} else if (now == pCnt[nn][0] - 1) {
Console.WriteLine(cnt + pCnt[nn][1]);
return;
}
}
Console.WriteLine(cnt + 1);
}
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 28, 0, 16, 12, 204, 205, 204, 205, 22], ["-", 0, 16, 12, 204, 205, 204, 206, 207, 0, 70], ["-", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 16, 12, 204, 205, 204, 206, 207, 0, 73], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 522
| 10
|
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading;
using System.Xml.Schema;
namespace Contest {
class Scanner {
private string[] line = new string[0];
private int index = 0;
public string Next() {
if (line.Length <= index) {
line = Console.ReadLine().Split(' ');
index = 0;
}
var res = line[index];
index++;
return res;
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public ulong NextUlong() { return ulong.Parse(Next()); }
public string[] Array() {
line = Console.ReadLine().Split(' ');
index = line.Length;
return line;
}
public int[] IntArray() {
var array = Array();
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
public long[] LongArray() {
var array = Array();
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
}
class Program {
private int N;
private long X;
private long[] Size;
private long[] PP;
private void Scan() {
var sc = new Scanner();
N = sc.NextInt();
X = sc.NextLong();
}
public void Solve() {
Scan();
Size = new long[51];
PP = new long[51];
Size[0] = 1;
PP[0] = 1;
for (int i = 1; i <= 50; i++) {
Size[i] = Size[i - 1] * 2 + 3;
PP[i] = PP[i - 1] * 2 + 1;
}
Console.WriteLine(EatP(N, X));
}
private long EatP(int l, long n) {
if (l == 0) {
if (n == 1) {
return 1;
} else {
return 0;
}
}
long result = 0;
if (n <= 1) {
return 0;
}
if (n > 1 && n <= 1 + Size[l - 1]) {
return EatP(l - 1, n - 1);
}
if (n == Size[l - 1] + 2) {
return EatP(l - 1, n - 1) + 1;
}
if (n > Size[l - 1] + 2 && n <= Size[l - 1] * 2 + 2) {
return PP[l - 1] + 1 + EatP(l - 1, n - Size[l - 1] - 1);
}
return PP[l];
}
static void Main() => new Program().Solve();
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading;
using System.Xml.Schema;
namespace Contest {
class Scanner {
private string[] line = new string[0];
private int index = 0;
public string Next() {
if (line.Length <= index) {
line = Console.ReadLine().Split(' ');
index = 0;
}
var res = line[index];
index++;
return res;
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public ulong NextUlong() { return ulong.Parse(Next()); }
public string[] Array() {
line = Console.ReadLine().Split(' ');
index = line.Length;
return line;
}
public int[] IntArray() {
var array = Array();
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
public long[] LongArray() {
var array = Array();
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
}
class Program {
private int N;
private long X;
private long[] Size;
private long[] PP;
private void Scan() {
var sc = new Scanner();
N = sc.NextInt();
X = sc.NextLong();
}
public void Solve() {
Scan();
Size = new long[51];
PP = new long[51];
Size[0] = 1;
PP[0] = 1;
for (int i = 1; i <= 50; i++) {
Size[i] = Size[i - 1] * 2 + 3;
PP[i] = PP[i - 1] * 2 + 1;
}
Console.WriteLine(EatP(N, X));
}
private long EatP(int l, long n) {
if (l == 0) {
if (n == 1) {
return 1;
} else {
return 0;
}
}
long result = 0;
if (n <= 1) {
return 0;
}
if (n > 1 && n <= 1 + Size[l - 1]) {
return EatP(l - 1, n - 1);
}
if (n == Size[l - 1] + 2) {
return PP[l - 1] + 1;
}
if (n > Size[l - 1] + 2 && n <= Size[l - 1] * 2 + 2) {
return PP[l - 1] + 1 + EatP(l - 1, n - Size[l - 1] - 2);
}
return PP[l];
}
static void Main() => new Program().Solve();
}
}
|
[["-", 64, 196, 0, 37, 0, 16, 31, 213, 63, 22], ["-", 0, 37, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 64, 196, 0, 37, 0, 16, 31, 204, 205, 22], ["+", 0, 37, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 37, 0, 16, 31, 213, 3, 4, 0, 21], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 37, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 37, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 694
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC114A {
class Program {
static void Main(string[] args) {
int X;
string b;
var word = Console.ReadLine().Split(' ');
X = int.Parse(word[0]);
if (X == 3 || X == 5 || X == 7) {
b = "Yes";
} else {
b = "No";
}
Console.WriteLine(b);
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC114A {
class Program {
static void Main(string[] args) {
int X;
var word = Console.ReadLine().Split(' ');
X = int.Parse(word[0]);
if (X == 3 || X == 5 || X == 7) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
Console.ReadKey();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 75, 196, 0, 1, 0, 11, 12, 5, 0, 62], ["-", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 124
| 4
|
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;
class Program {
static void Main(string[] Args) {
int X = Int32.Parse(ReadLine());
if (X == 3 && X == 5 && X == 7) {
WriteLine("Yes");
return;
}
WriteLine("NO");
}
}
|
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;
class Program {
static void Main(string[] Args) {
var X = Int32.Parse(ReadLine());
if (X == 3 || X == 5 || X == 7) {
WriteLine("YES");
return;
}
WriteLine("NO");
ReadLine();
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
| 8
| 80
| 12
|
using System;
class Program {
static void Main(string[] args) {
int age = int.Parse(Console.ReadLine());
if (age % 3 == 0 || age % 5 == 0 || age % 7 == 0) {
Console.Write("YES");
} else {
Console.Write("NO");
}
}
}
|
using System;
class Program {
static void Main(string[] args) {
int age = int.Parse(Console.ReadLine());
if (age == 3 || age == 5 || age == 7) {
Console.Write("YES");
} else {
Console.Write("NO");
}
}
}
|
[["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 109], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 15, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["-", 15, 16, 31, 16, 12, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 75
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace A {
class Program {
static void Main(string[] args) {
int X = int.Parse(Console.ReadLine());
if (X == 3 || X == 5 || X == 7) {
Console.Write("Yes");
} else {
Console.Write("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace A {
class Program {
static void Main(string[] args) {
int X = int.Parse(Console.ReadLine());
if (X == 3 || X == 5 || X == 7) {
Console.Write("YES");
} else {
Console.Write("NO");
}
Console.ReadKey();
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 97
| 10
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program {
static void Main() {
//入力
// int[] input = Console.ReadLine().Split().Select(i =>
// int.Parse(i)).ToArray(); string input= Console.ReadLine(); int input
// =int.Parse(Console.ReadLine());
char[] str = Console.ReadLine().ToCharArray();
for (int a = 0; a < str.Length; a++) {
if (str[a] == '1') {
str[a] = '9';
} else {
str[a] = '1';
}
}
Console.WriteLine(str.ToString());
/*
//処理速度計測
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
//解法
//処理速度表示
sw.Stop();
TimeSpan ts = sw.Elapsed;
Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
*/
Console.ReadLine();
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program {
static void Main() {
//入力
// int[] input = Console.ReadLine().Split().Select(i =>
// int.Parse(i)).ToArray(); string input= Console.ReadLine(); int input
// =int.Parse(Console.ReadLine());
char[] str = Console.ReadLine().ToCharArray();
for (int a = 0; a < str.Length; a++) {
if (str[a] == '1') {
str[a] = '9';
} else {
str[a] = '1';
}
}
Console.WriteLine(string.Join("", str));
/*
//処理速度計測
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
//解法
//処理速度表示
sw.Stop();
TimeSpan ts = sw.Elapsed;
Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
*/
Console.ReadLine();
}
}
|
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 126
| 8
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace B {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var n = int.Parse(Console.ReadLine());
var answer = 0;
if (n == 999)
answer = 1111;
else
answer = 111 * ((n / 111) + (n % 111 > 0 ? 1 : 0));
Console.WriteLine(answer);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace B {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var n = int.Parse(Console.ReadLine());
var answer = 0;
answer = 111 * ((n / 111) + (n % 111 > 0 ? 1 : 0));
Console.WriteLine(answer);
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22]]
| 8
| 151
| 11
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC099 {
class Program {
static void Main(string[] args) {
List<string> list = new List<string>();
while (true) {
string line = Console.ReadLine();
if (line == null)
break;
list.Add(line);
}
int ans = int.Parse(list[0]);
var a = list[0].First();
if (list[0].First().Equals(list[0].Last()) &&
list[0].First().ToString().Equals(list[0].Substring(1, 1))) {
Console.WriteLine(list[0]);
} else if (ans < 222) {
Console.WriteLine("222");
} else if (ans < 333) {
Console.WriteLine("333");
} else if (ans < 444) {
Console.WriteLine("444");
} else if (ans < 555) {
Console.WriteLine("555");
} else if (ans < 666) {
Console.WriteLine("666");
} else if (ans < 777) {
Console.WriteLine("777");
} else if (ans < 888) {
Console.WriteLine("888");
} else if (ans < 999) {
Console.WriteLine("999");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC099 {
class Program {
static void Main(string[] args) {
List<string> list = new List<string>();
while (true) {
string line = Console.ReadLine();
if (line == null)
break;
list.Add(line);
}
int ans = int.Parse(list[0]);
var a = list[0].First();
if (list[0].First().Equals(list[0].Last()) &&
list[0].First().ToString().Equals(list[0].Substring(1, 1))) {
Console.WriteLine(list[0]);
} else if (ans < 111) {
Console.WriteLine("111");
} else if (ans < 222) {
Console.WriteLine("222");
} else if (ans < 333) {
Console.WriteLine("333");
} else if (ans < 444) {
Console.WriteLine("444");
} else if (ans < 555) {
Console.WriteLine("555");
} else if (ans < 666) {
Console.WriteLine("666");
} else if (ans < 777) {
Console.WriteLine("777");
} else if (ans < 888) {
Console.WriteLine("888");
} else if (ans < 999) {
Console.WriteLine("999");
}
}
}
}
|
[["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 18]]
| 8
| 310
| 18
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using static System.Console;
using static System.Math;
class AC {
void Solve() {
var abc = new int[] { 111, 222, 333, 444, 555, 666, 777, 888, 999, 1111 };
var N = io.Int;
for (var i = 0; i < abc.Length - 1; ++i) {
if (abc[i] == N) {
WriteLine(abc[i]);
break;
} else {
if (N < abc[i]) {
WriteLine(abc[i]);
break;
} else {
WriteLine(abc[i + 1]);
break;
}
}
}
}
IoTiny io = new IoTiny();
public static void Main(string[] args) => new AC().Stream();
private void Stream() {
// var exStdIn = new System.IO.StreamReader("stdin.txt");
// SetIn(exStdIn);
Solve();
io.Flush();
}
}
class IoTiny {
string[] _nextBuffer;
int _bufferCnt;
char[] cs = new char[] { ' ', '"', ',' };
StreamWriter sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
AutoFlush = true
#else
AutoFlush = false
#endif
};
public IoTiny() {
_nextBuffer = new string[0];
_bufferCnt = 0;
SetOut(sw);
}
string Next() {
if (_bufferCnt < _nextBuffer.Length)
return _nextBuffer[_bufferCnt++];
var st = ReadLine();
while (st == "")
st = ReadLine();
_nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
_bufferCnt = 0;
return _nextBuffer[_bufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public void Flush() => Out.Flush();
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using static System.Console;
using static System.Math;
class AC {
void Solve() {
var abc =
new int[] { 111, 222, 333, 444, 555, 666, 777, 888, 999, 1111, -1 };
var N = io.Int;
for (var i = 0; i < abc.Length - 1; ++i) {
if (N == abc[i]) {
WriteLine(abc[i]);
break;
} else {
if (N < abc[i]) {
WriteLine(abc[i]);
break;
}
}
}
}
IoTiny io = new IoTiny();
public static void Main(string[] args) => new AC().Stream();
private void Stream() {
// var exStdIn = new System.IO.StreamReader("stdin.txt");
// SetIn(exStdIn);
Solve();
io.Flush();
}
}
class IoTiny {
string[] _nextBuffer;
int _bufferCnt;
char[] cs = new char[] { ' ', '"', ',' };
StreamWriter sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
AutoFlush = true
#else
AutoFlush = false
#endif
};
public IoTiny() {
_nextBuffer = new string[0];
_bufferCnt = 0;
SetOut(sw);
}
string Next() {
if (_bufferCnt < _nextBuffer.Length)
return _nextBuffer[_bufferCnt++];
var st = ReadLine();
while (st == "")
st = ReadLine();
_nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
_bufferCnt = 0;
return _nextBuffer[_bufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public void Flush() => Out.Flush();
}
|
[["+", 0, 200, 0, 212, 0, 227, 0, 229, 0, 21], ["+", 0, 212, 0, 227, 0, 229, 0, 241, 0, 33], ["+", 0, 212, 0, 227, 0, 229, 0, 241, 0, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 75, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["-", 0, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 75, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 75, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 435
| 22
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var ans = -1;
for (int i = 1; i <= 8; i++) {
var low = i * 100 + i * 10 + i * 1;
var high = (i + 1) * 100 + (i + 1) * 10 + (i + 1) * 1;
if (low == N || high == N) {
ans = N;
break;
}
if (low < N && N < high) {
ans = high;
break;
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var ans = -1;
for (int i = 1; i <= 8; i++) {
var low = i * 100 + i * 10 + i * 1;
var high = (i + 1) * 100 + (i + 1) * 10 + (i + 1) * 1;
if (low == N || high == N) {
ans = N;
break;
}
if (N < low) {
ans = low;
break;
}
if (low < N && N < high) {
ans = high;
break;
}
}
Console.WriteLine(ans);
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24]]
| 8
| 151
| 14
|
using System;
public class Hello {
public static void Main() {
var n = int.Parse(Console.ReadLine());
var ans = (n / 111 + 1) * 111;
Console.WriteLine(ans);
}
}
|
using System;
public class Hello {
public static void Main() {
var n = int.Parse(Console.ReadLine());
var ans = (n % 111 == 0) ? n : (n / 111 + 1) * 111;
Console.WriteLine(ans);
}
}
|
[["+", 0, 41, 15, 23, 0, 16, 31, 16, 17, 109], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 12, 203], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 17, 60], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 41, 15, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 64, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 212, 0, 41, 75, 16, 31, 23, 0, 24], ["+", 75, 16, 31, 23, 0, 16, 31, 16, 31, 22]]
| 8
| 50
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
namespace AtCoder {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<long> Slist() {
return ReadLine().Split().Select(long.Parse).ToList();
}
static void Main(string[] args) {
var N = Sarray()[0];
var A = Sarray();
var o = new Dictionary<long, long>();
var e = new Dictionary<long, long>();
for (var i = 0; i < A.Length; ++i) {
if (i % 2 == 0) {
if (!o.ContainsKey(A[i]))
o[A[i]] = 1;
else
++o[A[i]];
} else {
if (!e.ContainsKey(A[i]))
e[A[i]] = 1;
else
++e[A[i]];
}
}
long rui = 0;
long maxvo1 = -1;
long maxvo2 = -1;
o[-1] = 0;
foreach (var kv in o) {
if (o[maxvo1] <= kv.Value) {
maxvo2 = maxvo1;
maxvo1 = kv.Key;
}
rui += kv.Value;
}
long maxve1 = -1;
long maxve2 = -1;
e[-1] = 0;
foreach (var kv in e) {
if (e[maxve1] <= kv.Value) {
maxve2 = maxve1;
maxve1 = kv.Key;
}
rui += kv.Value;
}
if (maxvo1 == maxve1) //最長が同じ文字
{
if (o[maxvo1] < e[maxve1])
rui -= e[maxve1] + o[maxvo2];
else if (e[maxve1] < o[maxvo1])
rui -= o[maxvo1] + e[maxve2];
else {
var max = Math.Max(o[maxvo2], e[maxve2]);
rui -= o[maxvo1] + max;
}
} else
rui -= e[maxve1] + o[maxvo1];
WriteLine(rui);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
namespace AtCoder {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<long> Slist() {
return ReadLine().Split().Select(long.Parse).ToList();
}
static void Main(string[] args) {
var N = Sarray()[0];
var A = Sarray();
var o = new Dictionary<long, long>();
var e = new Dictionary<long, long>();
for (var i = 0; i < A.Length; ++i) {
if (i % 2 == 0) {
if (!o.ContainsKey(A[i]))
o[A[i]] = 1;
else
++o[A[i]];
} else {
if (!e.ContainsKey(A[i]))
e[A[i]] = 1;
else
++e[A[i]];
}
}
long maxvo1 = -1;
long maxvo2 = -1;
o[-1] = 0;
foreach (var kv in o) {
if (o[maxvo1] <= kv.Value) {
maxvo2 = maxvo1;
maxvo1 = kv.Key;
} else if (o[maxvo2] <= kv.Value)
maxvo2 = kv.Key;
}
long maxve1 = -1;
long maxve2 = -1;
e[-1] = 0;
foreach (var kv in e) {
if (e[maxve1] <= kv.Value) {
maxve2 = maxve1;
maxve1 = kv.Key;
} else if (e[maxve2] <= kv.Value)
maxve2 = kv.Key;
}
if (maxvo1 == maxve1) //最長が同じ文字
{
if (o[maxvo1] < e[maxve1])
N -= e[maxve1] + o[maxvo2];
else if (e[maxve1] < o[maxvo1])
N -= o[maxvo1] + e[maxve2];
else {
var max = Math.Max(o[maxvo2], e[maxve2]);
N -= o[maxvo1] + max;
}
} else
N -= e[maxve1] + o[maxvo1];
WriteLine(N);
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 95], ["+", 0, 210, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 210, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 204, 205, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 19], ["+", 0, 210, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 57, 64, 1, 0, 11, 31, 22], ["+", 75, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 57, 64, 1, 0, 11, 12, 214, 205, 22], ["+", 75, 57, 64, 1, 0, 11, 12, 214, 0, 131], ["+", 75, 57, 64, 1, 0, 11, 12, 214, 141, 22], ["-", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 75, 57, 64, 1, 0, 11, 31, 22], ["-", 75, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 478
| 47
|
using System;
using System.Linq;
class C {
static void Main(string[] args) {
Console.ReadLine();
var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var odd = vals.Where((i, p) => i % 2 != 0)
.GroupBy(p => p)
.OrderBy(p => -p.Count())
.Take(2)
.ToArray();
var evn = vals.Where((i, p) => i % 2 == 0)
.GroupBy(p => p)
.OrderBy(p => -p.Count())
.Take(2)
.ToArray();
if (odd[0].Key != evn[0].Key)
Console.WriteLine(vals.Length - (odd[0].Count() + evn[0].Count()));
else
Console.WriteLine(
vals.Length -
Math.Max(odd[0].Count() + evn.Skip(1).FirstOrDefault()?.Count() ?? 0,
evn[0].Count() + odd.Skip(1).FirstOrDefault()?.Count()
?? 0));
}
}
|
using System;
using System.Linq;
class C {
static void Main(string[] args) {
Console.ReadLine();
var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var odd = vals.Where((p, i) => i % 2 != 0)
.GroupBy(p => p)
.OrderBy(p => -p.Count())
.ToArray();
var evn = vals.Where((p, i) => i % 2 == 0)
.GroupBy(p => p)
.OrderBy(p => -p.Count())
.ToArray();
if (odd[0].Key != evn[0].Key)
Console.WriteLine(vals.Length - (odd[0].Count() + evn[0].Count()));
else
Console.WriteLine(
vals.Length -
Math.Max(
odd[0].Count() + (evn.Skip(1).FirstOrDefault()?.Count() ?? 0),
evn[0].Count() + (odd.Skip(1).FirstOrDefault()?.Count() ?? 0)));
}
}
|
[["-", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 54, 55, 0, 21], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 21], ["+", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 218, 8, 241, 0, 213, 3, 4, 0, 25], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
| 8
| 267
| 22
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var v = new int[n];
var inputs = Console.ReadLine().Split(' ');
var oddCounts = new Dictionary<int, int>();
var evenCounts = new Dictionary<int, int>();
for (int i = 0; i < n; i++) {
v[i] = int.Parse(inputs[i]);
Dictionary<int, int> targetCounts = null;
if (i % 2 == 0) {
targetCounts = evenCounts;
} else {
targetCounts = oddCounts;
}
if (targetCounts.ContainsKey(v[i])) {
targetCounts[v[i]]++;
} else {
targetCounts.Add(v[i], 1);
}
}
var evenTop2 = evenCounts.OrderByDescending((pair) => pair.Value)
.Take(2)
.Select(pair => pair.Key)
.ToList();
var oddTop2 = oddCounts.OrderByDescending((pair) => pair.Value)
.Take(2)
.Select(pair => pair.Key)
.ToList();
if (oddTop2.Count == 1) {
oddTop2.Add(0);
}
var count = dfs(v, evenTop2, oddTop2);
Console.WriteLine(count);
}
static int dfs(int[] v, List<int> evenTop2, List<int> oddTop2) {
int min = 1000000;
foreach (var even in evenTop2) {
foreach (var odd in oddTop2) {
if (even == odd) {
break;
}
int evenOddCount = CalcCost(v, even, odd);
int oddEvenCount = CalcCost(v, odd, even);
min = Math.Min(min, evenOddCount);
min = Math.Min(min, oddEvenCount);
}
}
if (min == 1000000) {
return 2;
}
return min;
}
static int CalcCost(int[] v, int even, int odd) {
int count = 0;
for (int i = 0; i < v.Length; i++) {
if (i % 2 == 0) {
if (v[i] != even) {
count++;
}
} else {
if (v[i] != odd) {
count++;
}
}
}
return count;
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var v = new int[n];
var inputs = Console.ReadLine().Split(' ');
var oddCounts = new Dictionary<int, int>();
var evenCounts = new Dictionary<int, int>();
for (int i = 0; i < n; i++) {
v[i] = int.Parse(inputs[i]);
Dictionary<int, int> targetCounts = null;
if (i % 2 == 0) {
targetCounts = evenCounts;
} else {
targetCounts = oddCounts;
}
if (targetCounts.ContainsKey(v[i])) {
targetCounts[v[i]]++;
} else {
targetCounts.Add(v[i], 1);
}
}
var evenTop2 = evenCounts.OrderByDescending((pair) => pair.Value)
.Take(2)
.Select(pair => pair.Key)
.ToList();
var oddTop2 = oddCounts.OrderByDescending((pair) => pair.Value)
.Take(2)
.Select(pair => pair.Key)
.ToList();
if (oddTop2.Count == 1) {
oddTop2.Add(0);
}
var count = dfs(v, evenTop2, oddTop2);
Console.WriteLine(count);
}
static int dfs(int[] v, List<int> evenTop2, List<int> oddTop2) {
int min = 1000000;
foreach (var even in evenTop2) {
foreach (var odd in oddTop2) {
if (even == odd) {
continue;
}
int evenOddCount = CalcCost(v, even, odd);
int oddEvenCount = CalcCost(v, odd, even);
min = Math.Min(min, evenOddCount);
min = Math.Min(min, oddEvenCount);
}
}
return min;
}
static int CalcCost(int[] v, int even, int odd) {
int count = 0;
for (int i = 0; i < v.Length; i++) {
if (i % 2 == 0) {
if (v[i] != even) {
count++;
}
} else {
if (v[i] != odd) {
count++;
}
}
}
return count;
}
}
|
[["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["-", 0, 210, 8, 196, 0, 210, 8, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
| 8
| 499
| 13
|
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
int[] v = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
Dictionary<int, int> o = new Dictionary<int, int>();
Dictionary<int, int> e = new Dictionary<int, int>();
// インデックス0から始まるので、インデックスが偶数のものは奇数番目にある
for (int i = 0; i < n; i++) {
if (i % 2 == 1) {
// 偶数の場合
if (e.ContainsKey(v[i])) {
e[v[i]]++;
} else {
e.Add(v[i], 1);
}
} else {
// 奇数の場合
if (o.ContainsKey(v[i])) {
o[v[i]]++;
} else {
o.Add(v[i], 1);
}
}
}
// 出てくる個数でソート
var o_sorted = o.OrderByDescending(i => i.Value);
var e_sorted = e.OrderByDescending(i => i.Value);
// 奇数偶数に分割した結果、要素が1コしか無い場合があるのでElementAtOrDefault
var o_1st = o_sorted.First();
var o_2nd = o_sorted.ElementAtOrDefault(1);
var e_1st = e_sorted.First();
var e_2nd = e_sorted.ElementAtOrDefault(1);
// 偶奇で最頻値が同じかどうかで場合分け
if (e_1st.Key != o_1st.Key) {
Console.WriteLine(n - e_1st.Value - o_1st.Value);
} else {
Console.WriteLine(
Math.Min(e_2nd.Value - o_1st.Value, e_1st.Value - o_2nd.Value));
}
}
}
|
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
int[] v = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
Dictionary<int, int> o = new Dictionary<int, int>();
Dictionary<int, int> e = new Dictionary<int, int>();
// インデックス0から始まるので、インデックスが偶数のものは奇数番目にある
for (int i = 0; i < n; i++) {
if (i % 2 == 1) {
// 偶数の場合
if (e.ContainsKey(v[i])) {
e[v[i]]++;
} else {
e.Add(v[i], 1);
}
} else {
// 奇数の場合
if (o.ContainsKey(v[i])) {
o[v[i]]++;
} else {
o.Add(v[i], 1);
}
}
}
// 出てくる個数でソート
var o_sorted = o.OrderByDescending(i => i.Value);
var e_sorted = e.OrderByDescending(i => i.Value);
// 奇数偶数に分割した結果、要素が1コしか無い場合があるのでElementAtOrDefault
var o_1st = o_sorted.First();
var o_2nd = o_sorted.ElementAtOrDefault(1);
var e_1st = e_sorted.First();
var e_2nd = e_sorted.ElementAtOrDefault(1);
// 偶奇で最頻値が同じかどうかで場合分け
if (e_1st.Key != o_1st.Key) {
Console.WriteLine(n - e_1st.Value - o_1st.Value);
} else {
// 最頻値が同じ場合、片方は二番目に多い数で書き換え。少ないほうが答え。
Console.WriteLine(Math.Min(n - o_1st.Value - e_2nd.Value,
n - e_1st.Value - o_2nd.Value));
}
}
}
|
[["-", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 16, 12, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 16, 12, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 214, 205, 22]]
| 8
| 345
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
int n = int.Parse(System.Console.ReadLine().Trim());
int[] line = Array.ConvertAll(System.Console.ReadLine().Trim().Split(' '),
int.Parse);
Dictionary<int, int> s = new Dictionary<int, int>();
Dictionary<int, int> t = new Dictionary<int, int>();
Dictionary<int, int> tmp;
for (int i = 0; i < n; i++) {
tmp = (i % 2 == 0) ? s : t;
if (tmp.ContainsKey(line[i])) {
tmp[line[i]]++;
} else {
tmp.Add(line[i], 1);
}
}
if (s.Count == 1 && t.Count == 1 && s.First().Key != t.First().Key) {
//すでにVVV
System.Console.WriteLine("{0}", 0);
return;
} else if (s.Count == 1 && t.Count == 1) {
//全要素が同じ
System.Console.WriteLine("{0}", s.First().Value);
return;
}
int s1 = 0, s2 = 0, t1 = 0, t2 = 0;
s = s.OrderByDescending(x => x.Value)
.ToDictionary(x => x.Key, x => x.Value);
t = t.OrderByDescending(x => x.Value)
.ToDictionary(x => x.Key, x => x.Value);
s1 = s[s.Keys.ToList()[0]];
t1 = t[t.Keys.ToList()[0]];
if (s1 != t1) {
//最頻値が異なればsもtも最頻値で置換
System.Console.WriteLine("{0}", (n - s1 - t1));
} else {
//最頻値が同じならいずれかを2番目の頻度の値で置換
if (s.Count > 1)
s2 = s[s.Keys.ToList()[1]];
if (t.Count > 1)
t2 = t[t.Keys.ToList()[1]];
// sを最頻値で、tを二番目で書き換え
// tを最頻値で、sを二番目で書き換え
int sRlt = n - s1 - t2;
int tRlt = n - s2 - t1;
System.Console.WriteLine("{0}", Math.Min(sRlt, tRlt));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
int n = int.Parse(System.Console.ReadLine().Trim());
int[] line = Array.ConvertAll(System.Console.ReadLine().Trim().Split(' '),
int.Parse);
Dictionary<int, int> s = new Dictionary<int, int>();
Dictionary<int, int> t = new Dictionary<int, int>();
Dictionary<int, int> tmp;
for (int i = 0; i < n; i++) {
tmp = (i % 2 == 0) ? s : t;
if (tmp.ContainsKey(line[i])) {
tmp[line[i]]++;
} else {
tmp.Add(line[i], 1);
}
}
if (s.Count == 1 && t.Count == 1 && s.First().Key != t.First().Key) {
//すでにVVV
System.Console.WriteLine("{0}", 0);
return;
} else if (s.Count == 1 && t.Count == 1) {
//全要素が同じ
System.Console.WriteLine("{0}", s.First().Value);
return;
}
int s1 = 0, s2 = 0, t1 = 0, t2 = 0;
s = s.OrderByDescending(x => x.Value)
.ToDictionary(x => x.Key, x => x.Value);
t = t.OrderByDescending(x => x.Value)
.ToDictionary(x => x.Key, x => x.Value);
s1 = s[s.Keys.ToList()[0]];
t1 = t[t.Keys.ToList()[0]];
if (s.Keys.ToList()[0] != t.Keys.ToList()[0]) {
//最頻値が異なればsもtも最頻値で置換
System.Console.WriteLine("{0}", (n - s1 - t1));
} else {
//最頻値が同じならいずれかを2番目の頻度の値で置換
if (s.Count > 1)
s2 = s[s.Keys.ToList()[1]];
if (t.Count > 1)
t2 = t[t.Keys.ToList()[1]];
// sを最頻値で、tを二番目で書き換え
// tを最頻値で、sを二番目で書き換え
int sRlt = n - s1 - t2;
int tRlt = n - s2 - t1;
System.Console.WriteLine("{0}", Math.Min(sRlt, tRlt));
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 31, 204, 205, 213, 63, 214, 205, 214, 205, 22], ["+", 31, 204, 205, 213, 63, 214, 205, 214, 0, 131], ["+", 31, 204, 205, 213, 63, 214, 205, 214, 141, 22], ["+", 15, 16, 31, 204, 205, 213, 63, 214, 0, 131], ["+", 15, 16, 31, 204, 205, 213, 63, 214, 141, 22], ["+", 15, 16, 31, 204, 205, 213, 3, 4, 0, 24], ["+", 15, 16, 31, 204, 205, 213, 3, 4, 0, 25], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 12, 204, 205, 213, 63, 214, 205, 214, 205, 22], ["+", 12, 204, 205, 213, 63, 214, 205, 214, 0, 131], ["+", 12, 204, 205, 213, 63, 214, 205, 214, 141, 22], ["+", 15, 16, 12, 204, 205, 213, 63, 214, 0, 131], ["+", 15, 16, 12, 204, 205, 213, 63, 214, 141, 22], ["+", 15, 16, 12, 204, 205, 213, 3, 4, 0, 24], ["+", 15, 16, 12, 204, 205, 213, 3, 4, 0, 25], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 512
| 22
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoder_BeginerContest {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string str = Console.ReadLine();
var progression = str.Split(' ').Select(int.Parse);
var twoProgressions =
progression.Select((p, i) => new { Content = p, Index = i });
var evenProgression =
twoProgressions.Where(p => p.Index % 2 == 0).Select(p => p.Content);
var oddProgression =
twoProgressions.Where(p => p.Index % 2 == 1).Select(p => p.Content);
int modNumEvenProg = evenProgression.Mode();
int modNumOddProg = oddProgression.Mode();
if (modNumOddProg == modNumEvenProg) {
int count1, count2;
int secoundmodNumOddProg = oddProgression.SecoundMode();
int secoundmodNumEvenProg = evenProgression.SecoundMode();
count1 = oddProgression.Count(op => op != modNumOddProg);
count1 += evenProgression.Count(ep => ep != secoundmodNumEvenProg);
count2 = oddProgression.Count(op => op != secoundmodNumOddProg);
count2 += evenProgression.Count(ep => ep != modNumEvenProg);
Console.WriteLine(count1 > count2 ? count2 : count1);
return;
}
// 修正する箇所の数を計測
int count;
count = evenProgression.Count(ep => ep != modNumEvenProg);
count += oddProgression.Count(op => op != modNumOddProg);
Console.WriteLine(count);
}
}
public static class MyExtension {
public static int Mode(this IEnumerable<int> progression) {
var NumsOfElements = new Dictionary<int, int>();
progression.Distinct().ToList().ForEach(p => { NumsOfElements.Add(p, 0); });
progression.ToList().ForEach(p => { NumsOfElements[p]++; });
var elements = NumsOfElements.OrderByDescending(noe => noe.Value);
return elements.ElementAt(0).Key;
}
public static int SecoundMode(this IEnumerable<int> progression) {
var NumsOfElements = new Dictionary<int, int>();
progression.Distinct().ToList().ForEach(p => { NumsOfElements.Add(p, 0); });
progression.ToList().ForEach(p => { NumsOfElements[p]++; });
var elements = NumsOfElements.OrderByDescending(noe => noe.Value);
if (NumsOfElements.Count < 2) {
return elements.ElementAt(0).Key;
}
return elements.ElementAt(1).Key;
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoder_BeginerContest {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string str = Console.ReadLine();
var progression = str.Split(' ').Select(int.Parse);
var twoProgressions =
progression.Select((p, i) => new { Content = p, Index = i });
var evenProgression =
twoProgressions.Where(p => p.Index % 2 == 0).Select(p => p.Content);
var oddProgression =
twoProgressions.Where(p => p.Index % 2 == 1).Select(p => p.Content);
int modNumEvenProg = evenProgression.Mode();
int modNumOddProg = oddProgression.Mode();
if (modNumOddProg == modNumEvenProg) {
int count1, count2;
int secoundmodNumOddProg = oddProgression.SecoundMode();
int secoundmodNumEvenProg = evenProgression.SecoundMode();
if (secoundmodNumEvenProg == modNumEvenProg &&
secoundmodNumOddProg == modNumOddProg) {
Console.WriteLine(n / 2);
return;
}
count1 = oddProgression.Count(op => op != modNumOddProg);
count1 += evenProgression.Count(ep => ep != secoundmodNumEvenProg);
count2 = oddProgression.Count(op => op != secoundmodNumOddProg);
count2 += evenProgression.Count(ep => ep != modNumEvenProg);
Console.WriteLine(count1 > count2 ? count2 : count1);
return;
}
// 修正する箇所の数を計測
int count;
count = evenProgression.Count(ep => ep != modNumEvenProg);
count += oddProgression.Count(op => op != modNumOddProg);
Console.WriteLine(count);
}
}
public static class MyExtension {
public static int Mode(this IEnumerable<int> progression) {
var NumsOfElements = new Dictionary<int, int>();
progression.Distinct().ToList().ForEach(p => { NumsOfElements.Add(p, 0); });
progression.ToList().ForEach(p => { NumsOfElements[p]++; });
var elements = NumsOfElements.OrderByDescending(noe => noe.Value);
return elements.ElementAt(0).Key;
}
public static int SecoundMode(this IEnumerable<int> progression) {
var NumsOfElements = new Dictionary<int, int>();
progression.Distinct().ToList().ForEach(p => { NumsOfElements.Add(p, 0); });
progression.ToList().ForEach(p => { NumsOfElements[p]++; });
var elements = NumsOfElements.OrderByDescending(noe => noe.Value);
if (NumsOfElements.Count < 2) {
return elements.ElementAt(0).Key;
}
return elements.ElementAt(1).Key;
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 530
| 23
|
using System;
using System.Text;
public class Program {
public void Solve() {
var sc = new Scanner();
string s = sc.Next();
// 一辺取って片方がサイズiの木
// 残りはサイズN-iの木
// 絶対にサイズ1は作れなきゃいけない
// 絶対にサイズNは作れない
int n = s.Length;
var flag = new bool[n + 1];
for (int i = 0; i < n; i++) {
flag[i + 1] = s[i] == '1';
}
var sb = new StringBuilder();
int c = 1;
if (!flag[1]) {
Console.WriteLine(-1);
return;
}
for (int i = 1; i < n; i++) {
if (flag[i] != flag[n - i]) {
Console.WriteLine(-1);
return;
}
sb.AppendLine($"{c} {i + 1}");
if (flag[i]) {
c = i + 1;
}
}
Console.Write(sb.ToString());
}
public static void Main(string[] args) { new Program().Solve(); }
}
class Scanner {
public Scanner() {
_pos = 0;
_line = new string[0];
}
const char Separator = ' ';
private int _pos;
private string[] _line;
#region スペース区切りで取得
public string Next() {
if (_pos >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_pos = 0;
}
return _line[_pos++];
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public double NextDouble() { return double.Parse(Next()); }
#endregion
#region 型変換
private int[] ToIntArray(string[] array) {
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
private long[] ToLongArray(string[] array) {
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
private double[] ToDoubleArray(string[] array) {
var result = new double[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = double.Parse(array[i]);
}
return result;
}
#endregion
#region 配列取得
public string[] Array() {
if (_pos >= _line.Length)
_line = Console.ReadLine().Split(Separator);
_pos = _line.Length;
return _line;
}
public int[] IntArray() { return ToIntArray(Array()); }
public long[] LongArray() { return ToLongArray(Array()); }
public double[] DoubleArray() { return ToDoubleArray(Array()); }
#endregion
}
|
using System;
using System.Text;
public class Program {
public void Solve() {
var sc = new Scanner();
string s = sc.Next();
// 一辺取って片方がサイズiの木
// 残りはサイズN-iの木
// 絶対にサイズ1は作れなきゃいけない
// 絶対にサイズNは作れない
int n = s.Length;
var flag = new bool[n + 1];
for (int i = 0; i < n; i++) {
flag[i + 1] = s[i] == '1';
}
var sb = new StringBuilder();
int c = 1;
if (!flag[1]) {
Console.WriteLine(-1);
return;
}
if (flag[n]) {
Console.WriteLine(-1);
return;
}
for (int i = 1; i < n; i++) {
if (flag[i] != flag[n - i]) {
Console.WriteLine(-1);
return;
}
sb.AppendLine($"{c} {i + 1}");
if (flag[i]) {
c = i + 1;
}
}
Console.Write(sb.ToString());
}
public static void Main(string[] args) { new Program().Solve(); }
}
class Scanner {
public Scanner() {
_pos = 0;
_line = new string[0];
}
const char Separator = ' ';
private int _pos;
private string[] _line;
#region スペース区切りで取得
public string Next() {
if (_pos >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_pos = 0;
}
return _line[_pos++];
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public double NextDouble() { return double.Parse(Next()); }
#endregion
#region 型変換
private int[] ToIntArray(string[] array) {
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
private long[] ToLongArray(string[] array) {
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
private double[] ToDoubleArray(string[] array) {
var result = new double[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = double.Parse(array[i]);
}
return result;
}
#endregion
#region 配列取得
public string[] Array() {
if (_pos >= _line.Length)
_line = Console.ReadLine().Split(Separator);
_pos = _line.Length;
return _line;
}
public int[] IntArray() { return ToIntArray(Array()); }
public long[] LongArray() { return ToLongArray(Array()); }
public double[] DoubleArray() { return ToDoubleArray(Array()); }
#endregion
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 204, 206, 207, 0, 70], ["+", 0, 57, 15, 204, 206, 207, 0, 28, 0, 22], ["+", 8, 196, 0, 57, 15, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 647
| 19
|
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using Debug = System.Diagnostics.Debug;
using System.Runtime.CompilerServices;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
static class P {
static void Main() {
var hwk = Console.ReadLine().Split().Select(int.Parse).ToArray();
var h = hwk[0];
var w = hwk[1];
var k = hwk[2];
ModInt[] counts = new ModInt[w];
counts[0] = 1;
for (int row = 0; row < h; row++) {
ModInt[] newCounts = new ModInt[w];
for (int i = 0; i < 1 << (w - 1); i++) {
if (Enumerable.Range(0, w - 2).Any(
x => ((i >> x) & (i >> (x + 1)) & 1) == 1))
continue;
for (int j = 0; j < w; j++) {
if (((i >> j) & 1) == 1) {
newCounts[j] += counts[j + 1];
newCounts[j + 1] += counts[j];
j++;
} else {
newCounts[j] += counts[j];
}
}
}
counts = newCounts;
}
Console.WriteLine(counts[k - 1]);
}
}
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.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using Debug = System.Diagnostics.Debug;
using System.Runtime.CompilerServices;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
static class P {
static void Main() {
var hwk = Console.ReadLine().Split().Select(int.Parse).ToArray();
var h = hwk[0];
var w = hwk[1];
var k = hwk[2];
if (w == 1) {
Console.WriteLine(1);
return;
}
ModInt[] counts = new ModInt[w];
counts[0] = 1;
for (int row = 0; row < h; row++) {
ModInt[] newCounts = new ModInt[w];
for (int i = 0; i < 1 << (w - 1); i++) {
if (Enumerable.Range(0, w - 2).Any(
x => ((i >> x) & (i >> (x + 1)) & 1) == 1))
continue;
for (int j = 0; j < w; j++) {
if (((i >> j) & 1) == 1) {
newCounts[j] += counts[j + 1];
newCounts[j + 1] += counts[j];
j++;
} else {
newCounts[j] += counts[j];
}
}
}
counts = newCounts;
}
Console.WriteLine(counts[k - 1]);
}
}
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;
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 799
| 17
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;
class Solver {
public void Solve(Scanner sc) {
int H, W, K;
sc.Make(out H, out W, out K);
var dp = new ModInt[W];
var newdp = new ModInt[W];
dp[0] = 1;
K--;
var ct = new int[W - 1];
for (int i = 0; i < (1 << (W - 1)); i++) {
var l = 0;
for (var j = 0; j < W - 1; j++)
if ((1 & i >> j) == 1)
l = j + 1;
for (var j = 0; j < W - 2; j++)
if ((1 & i >> j) == 1 && (1 & i >> (j + 1)) == 1)
goto END;
for (var j = l; j < W - 1; j++)
ct[j]++;
END:;
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
newdp[j] = dp[j] * ct[Max(0, j - 1)] * ct[Max(0, W - 2 - j)];
if (j - 1 >= 0)
newdp[j] += dp[j - 1] * ct[Max(0, j - 2)] * ct[Max(0, W - 2 - j)];
if (j + 1 < W)
newdp[j] += dp[j + 1] * ct[Max(0, j - 1)] * ct[Max(0, W - 3 - j)];
}
swap(ref dp, ref newdp);
}
WriteLine(dp[K]);
}
}
public struct ModInt {
public const long MOD = (int)1e9 + 7;
// public const long MOD = 998244353;
public long Value { get; set; }
public ModInt(long n = 0) { Value = n; }
private static ModInt[] fac; //階乗
private static ModInt[] inv; //逆数
private static ModInt[] facinv; // 1/(i!)
public override string ToString() => Value.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt l, ModInt r) {
l.Value += r.Value;
if (l.Value >= MOD)
l.Value -= MOD;
return l;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt l, ModInt r) {
l.Value -= r.Value;
if (l.Value < 0)
l.Value += MOD;
return l;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt
operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt l) => l.Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long n) {
n %= MOD;
if (n < 0)
n += MOD;
return new ModInt(n);
}
public static ModInt Pow(ModInt m, long n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return Pow(m * m, n >> 1);
else
return Pow(m * m, n >> 1) * m;
}
public static void Build(int n) {
fac = new ModInt[n + 1];
facinv = new ModInt[n + 1];
inv = new ModInt[n + 1];
inv[1] = 1;
fac[0] = fac[1] = 1;
facinv[0] = facinv[1] = 1;
for (var i = 2; i <= n; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = MOD - inv[MOD % i] * (MOD / i);
facinv[i] = facinv[i - 1] * inv[i];
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Fac(ModInt n) => fac[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Inv(ModInt n) => inv[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt FacInv(ModInt n) => facinv[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Comb(ModInt n, ModInt r) {
if (n < r)
return 0;
if (n == r)
return 1;
var calc = fac[n];
calc = calc * facinv[r];
calc = calc * facinv[n - r];
return calc;
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve(new Scanner());
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(this IList<T> A, int i, int j) {
var t = A[i];
A[i] = A[j];
A[j] = t;
}
public static T[] Shuffle<T>(this IList<T> A) {
T[] rt = A.ToArray();
Random rnd = new Random();
for (int i = rt.Length - 1; i >= 1; i--)
swap(ref rt[i], ref rt[rnd.Next(i + 1)]);
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
public string Str => Console.ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
public int[] ArrInt1D(int n) => Create(n, () => Int);
public long[] ArrLong1D(int n) => Create(n, () => Long);
public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
// public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1,
// v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2,
// out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3,
// T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2,
// v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2> p) {
var c = Comparer<T1>.Default.Compare(v1, p.v1);
if (c == 0)
c = Comparer<T2>.Default.Compare(v2, p.v2);
return c;
}
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public void Deconstruct(out T1 a, out T2 b) {
a = v1;
b = v2;
}
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() {}
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2, T3> p) {
var c = base.CompareTo(p);
if (c == 0)
c = Comparer<T3>.Default.Compare(v3, p.v3);
return c;
}
public override string ToString() => $"{base.ToString()} {v3.ToString()}";
public void Deconstruct(out T1 a, out T2 b, out T3 c) {
Deconstruct(out a, out b);
c = v3;
}
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;
class Solver {
public void Solve(Scanner sc) {
int H, W, K;
sc.Make(out H, out W, out K);
if (W == 1)
Fail(1);
var dp = new ModInt[W];
var newdp = new ModInt[W];
dp[0] = 1;
K--;
var ct = new int[W - 1];
for (int i = 0; i < (1 << (W - 1)); i++) {
var l = 0;
for (var j = 0; j < W - 1; j++)
if ((1 & i >> j) == 1)
l = j + 1;
for (var j = 0; j < W - 2; j++)
if ((1 & i >> j) == 1 && (1 & i >> (j + 1)) == 1)
goto END;
for (var j = l; j < W - 1; j++)
ct[j]++;
END:;
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
newdp[j] = dp[j] * ct[Max(0, j - 1)] * ct[Max(0, W - 2 - j)];
if (j - 1 >= 0)
newdp[j] += dp[j - 1] * ct[Max(0, j - 2)] * ct[Max(0, W - 2 - j)];
if (j + 1 < W)
newdp[j] += dp[j + 1] * ct[Max(0, j - 1)] * ct[Max(0, W - 3 - j)];
}
swap(ref dp, ref newdp);
}
WriteLine(dp[K]);
}
}
public struct ModInt {
public const long MOD = (int)1e9 + 7;
// public const long MOD = 998244353;
public long Value { get; set; }
public ModInt(long n = 0) { Value = n; }
private static ModInt[] fac; //階乗
private static ModInt[] inv; //逆数
private static ModInt[] facinv; // 1/(i!)
public override string ToString() => Value.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt l, ModInt r) {
l.Value += r.Value;
if (l.Value >= MOD)
l.Value -= MOD;
return l;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt l, ModInt r) {
l.Value -= r.Value;
if (l.Value < 0)
l.Value += MOD;
return l;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt
operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt l) => l.Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long n) {
n %= MOD;
if (n < 0)
n += MOD;
return new ModInt(n);
}
public static ModInt Pow(ModInt m, long n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return Pow(m * m, n >> 1);
else
return Pow(m * m, n >> 1) * m;
}
public static void Build(int n) {
fac = new ModInt[n + 1];
facinv = new ModInt[n + 1];
inv = new ModInt[n + 1];
inv[1] = 1;
fac[0] = fac[1] = 1;
facinv[0] = facinv[1] = 1;
for (var i = 2; i <= n; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = MOD - inv[MOD % i] * (MOD / i);
facinv[i] = facinv[i - 1] * inv[i];
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Fac(ModInt n) => fac[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Inv(ModInt n) => inv[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt FacInv(ModInt n) => facinv[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Comb(ModInt n, ModInt r) {
if (n < r)
return 0;
if (n == r)
return 1;
var calc = fac[n];
calc = calc * facinv[r];
calc = calc * facinv[n - r];
return calc;
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve(new Scanner());
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(this IList<T> A, int i, int j) {
var t = A[i];
A[i] = A[j];
A[j] = t;
}
public static T[] Shuffle<T>(this IList<T> A) {
T[] rt = A.ToArray();
Random rnd = new Random();
for (int i = rt.Length - 1; i >= 1; i--)
swap(ref rt[i], ref rt[rnd.Next(i + 1)]);
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
public string Str => Console.ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
public int[] ArrInt1D(int n) => Create(n, () => Int);
public long[] ArrLong1D(int n) => Create(n, () => Long);
public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
// public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1,
// v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2,
// out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3,
// T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2,
// v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2> p) {
var c = Comparer<T1>.Default.Compare(v1, p.v1);
if (c == 0)
c = Comparer<T2>.Default.Compare(v2, p.v2);
return c;
}
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public void Deconstruct(out T1 a, out T2 b) {
a = v1;
b = v2;
}
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() {}
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2, T3> p) {
var c = base.CompareTo(p);
if (c == 0)
c = Comparer<T3>.Default.Compare(v3, p.v3);
return c;
}
public override string ToString() => $"{base.ToString()} {v3.ToString()}";
public void Deconstruct(out T1 a, out T2 b, out T3 c) {
Deconstruct(out a, out b);
c = v3;
}
}
#endregion
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 213, 63, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 2,555
| 11
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder {
public class ABC {
static int mod = 1000000007; // 10^9+7
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
// int n = int.Parse(Console.ReadLine());
// string s = Console.ReadLine();
int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
// long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
int h = vs[0];
int w = vs[1];
int k = vs[2];
int[,] c = new int[w, 3];
for (int i = 0; i < 1 << w - 1; i++) {
bool f = true;
int t = i;
for (int j = 0; j < w - 2; j++) {
if (t % 4 == 3) {
f = false;
break;
}
t >>= 1;
}
if (f) {
// System.Diagnostics.Debug.WriteLine($"{Convert.ToString(i,
// 2).PadLeft(w - 1, '0')}");
t = i << 1;
for (int j = 0; j < w; j++) {
int t2 = t % 4;
if (t2 == 1) {
c[j, 0]++; // c[x, 0] x-1 -> x
} else if (t2 == 0) {
c[j, 1]++; // c[x, 1] x -> x
} else if (t2 == 2) {
c[j, 2]++; // c[x, 2] x+1 -> x
}
t >>= 1;
}
}
}
long[,] dp = new long[w, h + 1];
dp[k - 1, 0] = 1;
for (int i = 1; i <= h; i++) {
for (int j = 0; j < w; j++) {
if (j > 0) {
dp[j, i] += dp[j - 1, i - 1] * c[j, 0] % mod;
}
dp[j, i] += dp[j, i - 1] * c[j, 1] % mod;
if (j < w - 1) {
dp[j, i] += dp[j + 1, i - 1] * c[j, 2] % mod;
}
}
}
// for (int i = 0; i <= h; i++) {
// for (int j = 0; j < w; j++) {
// System.Diagnostics.Debug.Write($"{dp[j, i]} ");
// }
// System.Diagnostics.Debug.WriteLine($"");
//}
Console.WriteLine(dp[0, h]);
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder {
public class ABC {
static int mod = 1000000007; // 10^9+7
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
// int n = int.Parse(Console.ReadLine());
// string s = Console.ReadLine();
int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
// long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
int h = vs[0];
int w = vs[1];
int k = vs[2];
int[,] c = new int[w, 3];
for (int i = 0; i < 1 << w - 1; i++) {
bool f = true;
int t = i;
for (int j = 0; j < w - 2; j++) {
if (t % 4 == 3) {
f = false;
break;
}
t >>= 1;
}
if (f) {
// System.Diagnostics.Debug.WriteLine($"{Convert.ToString(i,
// 2).PadLeft(w - 1, '0')}");
t = i << 1;
for (int j = 0; j < w; j++) {
int t2 = t % 4;
if (t2 == 1) {
c[j, 0]++; // c[x, 0] x-1 -> x
} else if (t2 == 0) {
c[j, 1]++; // c[x, 1] x -> x
} else if (t2 == 2) {
c[j, 2]++; // c[x, 2] x+1 -> x
}
t >>= 1;
}
}
}
long[,] dp = new long[w, h + 1];
dp[k - 1, 0] = 1;
for (int i = 1; i <= h; i++) {
for (int j = 0; j < w; j++) {
if (j > 0) {
dp[j, i] += dp[j - 1, i - 1] * c[j, 0] % mod;
}
dp[j, i] += dp[j, i - 1] * c[j, 1] % mod;
if (j < w - 1) {
dp[j, i] += dp[j + 1, i - 1] * c[j, 2] % mod;
}
dp[j, i] %= mod;
}
}
// for (int i = 0; i <= h; i++) {
// for (int j = 0; j < w; j++) {
// System.Diagnostics.Debug.Write($"{dp[j, i]} ");
// }
// System.Diagnostics.Debug.WriteLine($"");
//}
Console.WriteLine(dp[0, h]);
Console.Out.Flush();
}
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 490
| 9
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
long mod = 1000000007;
string[] input = Console.ReadLine().Split(' ');
int h = int.Parse(input[0]);
int w = int.Parse(input[1]);
int k = int.Parse(input[2]);
long[,] dp = new long[h + 1, w]; //見た行数と何列目にいるか
dp[0, 0] = 1;
if (w > 1) {
for (int i = 1; i <= h; i++) {
for (int j = 0; j < w; j++) {
for (int x = 0; x < Math.Pow(2, w - 1); x++) {
List<int> rowMemo = BinaryToNum(w - 1, x);
bool rowContinue = false;
for (int y = 1; y < w - 1; y++) {
if (rowMemo[y - 1] + rowMemo[y] == 2)
rowContinue = true;
}
if (rowContinue)
continue;
if (j == 0) {
if (rowMemo[j] == 1)
dp[i, j] += dp[i - 1, j + 1];
else
dp[i, j] += dp[i - 1, j];
} else if (j == w - 1) {
if (rowMemo[j - 1] == 1)
dp[i, j] += dp[i - 1, j - 1];
else
dp[i, j] += dp[i - 1, j];
} else {
if (rowMemo[j] == 1)
dp[i, j] += dp[i - 1, j + 1];
else if (rowMemo[j - 1] == 1)
dp[i, j] += dp[i - 1, j - 1];
else
dp[i, j] += dp[i - 1, j];
}
}
// Console.WriteLine(i+" "+j+" "+dp[i,j]);
}
}
Console.WriteLine(dp[h, k - 1]);
} else
Console.WriteLine(1);
}
static List<int>
FactorialToNum(int n, int num) { // n個の数を並べ替えた方法をリストに直す。
// n=1でnum=0なら{0}。 n=2でnum=0なら{0,1}、num=1なら{1,0}
List<int> answersNum = new List<int>();
List<int> answers = new List<int>();
List<int> answersRest = new List<int>();
int rest = 1;
for (int i = 2; i < n; i++) {
rest *= i;
}
for (int i = n - 1; i > 0; i--) {
answersNum.Add(num / rest);
num %= rest;
rest /= i;
}
answersNum.Add(0);
for (int i = 0; i < n; i++) {
answersRest.Add(i);
}
for (int i = 0; i < n; i++) {
answers.Add(answersRest[answersNum[i]]);
answersRest.RemoveAt(answersNum[i]);
}
return answers;
}
static List<int> BinaryToNum(int n,
int num) { // 2進数でn桁の数numをリストに直す。
// n=2でnum=0なら{0,0}、num=1なら{0,1}、num=2なら{1,0}。
List<int> answers = new List<int>();
int rest = 1;
for (int i = 0; i < n - 1; i++) {
rest *= 2;
}
for (int i = 0; i < n; i++) {
answers.Add(num / rest);
num %= rest;
rest /= 2;
}
return answers;
}
}
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
long mod = 1000000007;
string[] input = Console.ReadLine().Split(' ');
int h = int.Parse(input[0]);
int w = int.Parse(input[1]);
int k = int.Parse(input[2]);
long[,] dp = new long[h + 1, w]; //見た行数と何列目にいるか
dp[0, 0] = 1;
if (w > 1) {
for (int i = 1; i <= h; i++) {
for (int j = 0; j < w; j++) {
for (int x = 0; x < Math.Pow(2, w - 1); x++) {
List<int> rowMemo = BinaryToNum(w - 1, x);
bool rowContinue = false;
for (int y = 1; y < w - 1; y++) {
if (rowMemo[y - 1] + rowMemo[y] == 2)
rowContinue = true;
}
if (rowContinue)
continue;
if (j == 0) {
if (rowMemo[j] == 1)
dp[i, j] += dp[i - 1, j + 1];
else
dp[i, j] += dp[i - 1, j];
} else if (j == w - 1) {
if (rowMemo[j - 1] == 1)
dp[i, j] += dp[i - 1, j - 1];
else
dp[i, j] += dp[i - 1, j];
} else {
if (rowMemo[j] == 1)
dp[i, j] += dp[i - 1, j + 1];
else if (rowMemo[j - 1] == 1)
dp[i, j] += dp[i - 1, j - 1];
else
dp[i, j] += dp[i - 1, j];
}
dp[i, j] %= mod;
}
// Console.WriteLine(i+" "+j+" "+dp[i,j]);
}
}
Console.WriteLine(dp[h, k - 1]);
} else
Console.WriteLine(1);
}
static List<int>
FactorialToNum(int n, int num) { // n個の数を並べ替えた方法をリストに直す。
// n=1でnum=0なら{0}。 n=2でnum=0なら{0,1}、num=1なら{1,0}
List<int> answersNum = new List<int>();
List<int> answers = new List<int>();
List<int> answersRest = new List<int>();
int rest = 1;
for (int i = 2; i < n; i++) {
rest *= i;
}
for (int i = n - 1; i > 0; i--) {
answersNum.Add(num / rest);
num %= rest;
rest /= i;
}
answersNum.Add(0);
for (int i = 0; i < n; i++) {
answersRest.Add(i);
}
for (int i = 0; i < n; i++) {
answers.Add(answersRest[answersNum[i]]);
answersRest.RemoveAt(answersNum[i]);
}
return answers;
}
static List<int> BinaryToNum(int n,
int num) { // 2進数でn桁の数numをリストに直す。
// n=2でnum=0なら{0,0}、num=1なら{0,1}、num=2なら{1,0}。
List<int> answers = new List<int>();
int rest = 1;
for (int i = 0; i < n - 1; i++) {
rest *= 2;
}
for (int i = 0; i < n; i++) {
answers.Add(num / rest);
num %= rest;
rest /= 2;
}
return answers;
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 744
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
public class Program {
static int mod = 1000000007;
public static void Main(string[] args) {
var line = Scanner.StringList;
int H = line[0].Int();
int W = line[1].Int();
int K = line[2].Int();
var dp = new int[H + 1, W];
dp[0, 0] = 1;
// 隣あってないbit
var status = Enumerable.Range(0, 1 << (W - 1))
.Where(i => !i.NeighboringBit(W - 1))
.ToArray();
// どこの列
foreach (int i in Enumerable.Range(0, H)) {
// その列におけるスタート地点
foreach (int j in Enumerable.Range(0, W)) {
// その列における棒があるかないかbit
foreach (int k in status) {
// 一番左でない、かつ、左側のbitが存在すれば移動する
if (j >= 1 && (k.GetBit(j - 1))) {
dp[i + 1, j - 1] += dp[i, j];
dp[i + 1, j - 1] %= mod;
}
// 一番右でない、かつ、右側のbitが存在すれば移動する
else if (j <= W - 2 && k.GetBit(j)) {
dp[i + 1, j + 1] += dp[i, j];
dp[i + 1, j + 1] %= mod;
}
// 素通り
else {
dp[i + 1, j] += dp[i, j];
dp[i + 1, j] %= mod;
}
}
}
}
Console.WriteLine(dp[H, K - 1]);
Console.ReadLine();
}
}
/// <summary>
/// スキャナ
/// </summary>
public class Scanner {
public static long Long {
get { return Console.ReadLine().Long(); }
}
public static int Int {
get { return Console.ReadLine().Int(); }
}
public static string String {
get { return Console.ReadLine(); }
}
public static string[] StringList {
get { return Console.ReadLine().Split(); }
}
public static IEnumerable<int> IntList {
get { return StringList.Select(int.Parse); }
}
public static IEnumerable<long> LongList {
get { return StringList.Select(long.Parse); }
}
public static IEnumerable<double> DoubleList {
get { return StringList.Select(double.Parse); }
}
}
/// <summary>
/// Linq拡張
/// </summary>
public static class LinqExtension {
/// <summary>
/// 二分探索
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="self"></param>
/// <param name="solve"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <returns></returns>
public static T LeftBinarySearch<T>(this IEnumerable<T> self,
Func<T, bool> solve, T min, T max) {
int index = self.LeftBinarySearchIndex(solve);
return self.Get(index, min, max);
}
/// <summary>
/// 二分探索
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="self"></param>
/// <param name="solve"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <returns></returns>
public static T RightBinarySearch<T>(this IEnumerable<T> self,
Func<T, bool> solve, T min, T max) {
int index = self.RightBinarySearchIndex(solve);
return self.Get(index, min, max);
}
/// <summary>
/// OutOfRange対応
/// </summary>
/// <typeparam name="T">型T</typeparam>
/// <param name="self">IEnumerable</param>
/// <param name="index">対象のインデックス</param>
/// <param name="min">0未満のインデックスの時</param>
/// <param name="max">配列のサイズ以上の時</param>
/// <returns>型Tの値</returns>
public static T Get<T>(this IEnumerable<T> self, int index, T min, T max) {
if (index < 0)
return min;
if (index >= self.Count())
return max;
return self.ElementAt(index);
}
/// <summary>
/// <para>二分探索</para>
/// <para>渡されたラムダ式の条件を満たすものの中で、一番左側のもの(インデックスが小さい)</para>
/// </summary>
/// <typeparam name="T">IEnumerable</typeparam>
/// <param name="solve"></param>
/// <returns>一番左側のインデックス</returns>
public static int LeftBinarySearchIndex<T>(this IEnumerable<T> self,
Func<T, bool> solve) {
int ng = -1;
int ok = self.Count();
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (solve(self.ElementAt(mid))) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
/// <summary>
/// <para>二分探索</para>
/// <para>渡されたラムダ式の条件を満たすものの中で、一番右側のもの(インデックスが大きい)</para>
/// </summary>
/// <typeparam name="T">IEnumerable</typeparam>
/// <param name="solve"></param>
/// <returns>一番右側のインデックス</returns>
public static int RightBinarySearchIndex<T>(this IEnumerable<T> self,
Func<T, bool> solve) {
int ng = self.Count();
int ok = -1;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (solve(self.ElementAt(mid))) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
/// <summary>
/// リストを埋める
/// </summary>
/// <typeparam name="T">型T</typeparam>
/// <param name="self">リスト</param>
/// <param name="func">(index) => T</param>
/// <returns>リストの参照</returns>
public static IList<T> Fill<T>(this IList<T> self, Func<int, T> func) {
for (int i = 0; i < self.Count; i++) {
self[i] = func(i);
}
return self;
}
/// <summary>
/// リストを埋める
/// </summary>
/// <typeparam name="T">型T</typeparam>
/// <param name="self">リスト</param>
/// <param name="value">型Tの値</param>
/// <returns>リストの参照</returns>
public static IList<T> Fill<T>(this IList<T> self, T value) {
for (int i = 0; i < self.Count; i++) {
self[i] = value;
}
return self;
}
}
/// <summary>
/// Int拡張
/// </summary>
public static class IntExtensiton {
/// <summary>
/// 階上
/// </summary>
/// <param name="self"></param>
/// <returns></returns>
public static long Factorial(this int self) {
if (self == 1)
return 1L;
return self * self.Factorial();
}
/// <summary>
/// 階上
/// </summary>
/// <param name="self"></param>
/// <returns></returns>
public static long Factorial(this int self, int c) {
if (c == 0 || self == 1)
return 1L;
return self * Factorial(self - 1, c - 1);
}
public static int BitCount(this int bit, int digit = 32) {
int count = 0;
for (int i = (digit - 1); i >= 0; i--) {
if (bit.GetBit(i))
count++;
}
return count;
}
public static bool GetBit(this int bit, int digit) {
int mask = (1 << digit);
return (bit & mask) == mask;
}
public static int SetBit(this int bit, int digit) {
return (bit | (1 << digit));
}
public static string BitToString(this int bit, int digit = 32) {
StringBuilder sb = new StringBuilder();
for (int i = (digit - 1); i >= 0; i--) {
sb.Append(bit.GetBit(i) ? "1" : "0");
}
return sb.ToString();
}
public static bool IsDivisor(this int self, int target) {
return self % target == 0;
}
public static bool NeighboringBit(this int self, int digit = 32) {
if (digit == 1)
return true;
return Enumerable.Range(0, digit - 1)
.Where(j => self.GetBit(j) && self.GetBit(j + 1))
.Any();
}
}
/// <summary>
/// Long拡張
/// </summary>
public static class LongExtensition {
public static long BitCount(this long bit, int digit = 64) {
long count = 0;
for (int i = (digit - 1); i >= 0; i--) {
if (bit.GetBit(i))
count++;
}
return count;
}
public static bool GetBit(this long bit, int digit) {
long mask = (1L << digit);
return (bit & mask) == mask;
}
public static long SetBit(this long bit, int digit) {
return bit | (1L << digit);
}
public static string BitToString(this long bit, int digit = 64) {
StringBuilder sb = new StringBuilder();
for (int i = (digit - 1); i >= 0; i--) {
sb.Append(bit.GetBit(i) ? "1" : "0");
}
return sb.ToString();
}
public static bool IsDivisor(this long self, int target) {
return self % target == 0;
}
}
/// <summary>
/// String拡張
/// </summary>
public static class StringExtensiton {
public static int Int(this string str) { return int.Parse(str); }
public static long Long(this string str) { return long.Parse(str); }
public static double Double(this string str) { return double.Parse(str); }
}
/// <summary>
/// 便利関数
/// </summary>
public static class F {
public static void ChMax<T>(ref T x, T y)
where T : IComparable {
if (x.CompareTo(y) < 0) {
x = y;
}
}
public static void ChMin<T>(ref T x, T y)
where T : IComparable {
if (x.CompareTo(y) > 0) {
x = y;
}
}
public static void Swap<T>(ref T x, ref T y) {
T tmp = x;
x = y;
y = tmp;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
public class Program {
static int mod = 1000000007;
public static void Main(string[] args) {
var line = Scanner.StringList;
int H = line[0].Int();
int W = line[1].Int();
int K = line[2].Int();
var dp = new int[H + 1, W];
dp[0, 0] = 1;
// 隣あってないbit
var status = Enumerable.Range(0, 1 << (W - 1))
.Where(i => !i.NeighboringBit(W - 1))
.ToArray();
// どこの列
foreach (int i in Enumerable.Range(0, H)) {
// その列におけるスタート地点
foreach (int j in Enumerable.Range(0, W)) {
// その列における棒があるかないかbit
foreach (int k in status) {
// 一番左でない、かつ、左側のbitが存在すれば移動する
if (j > 0 && (k.GetBit(j - 1))) {
dp[i + 1, j - 1] += dp[i, j];
dp[i + 1, j - 1] %= mod;
}
// 一番右でない、かつ、右側のbitが存在すれば移動する
else if (j < W - 1 && k.GetBit(j)) {
dp[i + 1, j + 1] += dp[i, j];
dp[i + 1, j + 1] %= mod;
}
// 素通り
else {
dp[i + 1, j] += dp[i, j];
dp[i + 1, j] %= mod;
}
}
}
}
Console.WriteLine(dp[H, K - 1]);
Console.ReadLine();
}
}
/// <summary>
/// スキャナ
/// </summary>
public class Scanner {
public static long Long {
get { return Console.ReadLine().Long(); }
}
public static int Int {
get { return Console.ReadLine().Int(); }
}
public static string String {
get { return Console.ReadLine(); }
}
public static string[] StringList {
get { return Console.ReadLine().Split(); }
}
public static IEnumerable<int> IntList {
get { return StringList.Select(int.Parse); }
}
public static IEnumerable<long> LongList {
get { return StringList.Select(long.Parse); }
}
public static IEnumerable<double> DoubleList {
get { return StringList.Select(double.Parse); }
}
}
/// <summary>
/// Linq拡張
/// </summary>
public static class LinqExtension {
/// <summary>
/// 二分探索
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="self"></param>
/// <param name="solve"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <returns></returns>
public static T LeftBinarySearch<T>(this IEnumerable<T> self,
Func<T, bool> solve, T min, T max) {
int index = self.LeftBinarySearchIndex(solve);
return self.Get(index, min, max);
}
/// <summary>
/// 二分探索
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="self"></param>
/// <param name="solve"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <returns></returns>
public static T RightBinarySearch<T>(this IEnumerable<T> self,
Func<T, bool> solve, T min, T max) {
int index = self.RightBinarySearchIndex(solve);
return self.Get(index, min, max);
}
/// <summary>
/// OutOfRange対応
/// </summary>
/// <typeparam name="T">型T</typeparam>
/// <param name="self">IEnumerable</param>
/// <param name="index">対象のインデックス</param>
/// <param name="min">0未満のインデックスの時</param>
/// <param name="max">配列のサイズ以上の時</param>
/// <returns>型Tの値</returns>
public static T Get<T>(this IEnumerable<T> self, int index, T min, T max) {
if (index < 0)
return min;
if (index >= self.Count())
return max;
return self.ElementAt(index);
}
/// <summary>
/// <para>二分探索</para>
/// <para>渡されたラムダ式の条件を満たすものの中で、一番左側のもの(インデックスが小さい)</para>
/// </summary>
/// <typeparam name="T">IEnumerable</typeparam>
/// <param name="solve"></param>
/// <returns>一番左側のインデックス</returns>
public static int LeftBinarySearchIndex<T>(this IEnumerable<T> self,
Func<T, bool> solve) {
int ng = -1;
int ok = self.Count();
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (solve(self.ElementAt(mid))) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
/// <summary>
/// <para>二分探索</para>
/// <para>渡されたラムダ式の条件を満たすものの中で、一番右側のもの(インデックスが大きい)</para>
/// </summary>
/// <typeparam name="T">IEnumerable</typeparam>
/// <param name="solve"></param>
/// <returns>一番右側のインデックス</returns>
public static int RightBinarySearchIndex<T>(this IEnumerable<T> self,
Func<T, bool> solve) {
int ng = self.Count();
int ok = -1;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (solve(self.ElementAt(mid))) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
/// <summary>
/// リストを埋める
/// </summary>
/// <typeparam name="T">型T</typeparam>
/// <param name="self">リスト</param>
/// <param name="func">(index) => T</param>
/// <returns>リストの参照</returns>
public static IList<T> Fill<T>(this IList<T> self, Func<int, T> func) {
for (int i = 0; i < self.Count; i++) {
self[i] = func(i);
}
return self;
}
/// <summary>
/// リストを埋める
/// </summary>
/// <typeparam name="T">型T</typeparam>
/// <param name="self">リスト</param>
/// <param name="value">型Tの値</param>
/// <returns>リストの参照</returns>
public static IList<T> Fill<T>(this IList<T> self, T value) {
for (int i = 0; i < self.Count; i++) {
self[i] = value;
}
return self;
}
}
/// <summary>
/// Int拡張
/// </summary>
public static class IntExtensiton {
/// <summary>
/// 階上
/// </summary>
/// <param name="self"></param>
/// <returns></returns>
public static long Factorial(this int self) {
if (self == 1)
return 1L;
return self * self.Factorial();
}
/// <summary>
/// 階上
/// </summary>
/// <param name="self"></param>
/// <returns></returns>
public static long Factorial(this int self, int c) {
if (c == 0 || self == 1)
return 1L;
return self * Factorial(self - 1, c - 1);
}
public static int BitCount(this int bit, int digit = 32) {
int count = 0;
for (int i = (digit - 1); i >= 0; i--) {
if (bit.GetBit(i))
count++;
}
return count;
}
public static bool GetBit(this int bit, int digit) {
int mask = (1 << digit);
return (bit & mask) == mask;
}
public static int SetBit(this int bit, int digit) {
return (bit | (1 << digit));
}
public static string BitToString(this int bit, int digit = 32) {
StringBuilder sb = new StringBuilder();
for (int i = (digit - 1); i >= 0; i--) {
sb.Append(bit.GetBit(i) ? "1" : "0");
}
return sb.ToString();
}
public static bool IsDivisor(this int self, int target) {
return self % target == 0;
}
public static bool NeighboringBit(this int self, int digit = 32) {
if (digit < 2)
return false;
return Enumerable.Range(0, digit - 1)
.Where(j => self.GetBit(j) && self.GetBit(j + 1))
.Any();
}
}
/// <summary>
/// Long拡張
/// </summary>
public static class LongExtensition {
public static long BitCount(this long bit, int digit = 64) {
long count = 0;
for (int i = (digit - 1); i >= 0; i--) {
if (bit.GetBit(i))
count++;
}
return count;
}
public static bool GetBit(this long bit, int digit) {
long mask = (1L << digit);
return (bit & mask) == mask;
}
public static long SetBit(this long bit, int digit) {
return bit | (1L << digit);
}
public static string BitToString(this long bit, int digit = 64) {
StringBuilder sb = new StringBuilder();
for (int i = (digit - 1); i >= 0; i--) {
sb.Append(bit.GetBit(i) ? "1" : "0");
}
return sb.ToString();
}
public static bool IsDivisor(this long self, int target) {
return self % target == 0;
}
}
/// <summary>
/// String拡張
/// </summary>
public static class StringExtensiton {
public static int Int(this string str) { return int.Parse(str); }
public static long Long(this string str) { return long.Parse(str); }
public static double Double(this string str) { return double.Parse(str); }
}
/// <summary>
/// 便利関数
/// </summary>
public static class F {
public static void ChMax<T>(ref T x, T y)
where T : IComparable {
if (x.CompareTo(y) < 0) {
x = y;
}
}
public static void ChMin<T>(ref T x, T y)
where T : IComparable {
if (x.CompareTo(y) > 0) {
x = y;
}
}
public static void Swap<T>(ref T x, ref T y) {
T tmp = x;
x = y;
y = tmp;
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 19], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 18], ["-", 75, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 75, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 37, 0, 211, 0, 146], ["+", 8, 196, 0, 57, 64, 37, 0, 211, 0, 147]]
| 8
| 1,780
| 14
|
using System;
using System.Linq;
using System.Collections.Generic;
class Bmondai {
static void Main() {
var line =
Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
for (int i = 0; i < line[2]; ++i) {
if (line[0] % 2 != 0)
line[0]--;
line[0] /= 2;
line[1] += line[0];
if (line[1] % 2 != 0)
line[1]--;
line[1] /= 2;
;
line[0] += line[1];
}
Console.WriteLine($"{line[0]} {line[1]}");
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Bmondai {
static void Main() {
var line =
Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
for (int i = 1; i <= line[2]; ++i) {
if (i % 2 == 1) {
if (line[0] % 2 != 0)
line[0]--;
line[0] /= 2;
line[1] += line[0];
} else {
if (line[1] % 2 != 0)
line[1]--;
line[1] /= 2;
;
line[0] += line[1];
}
}
Console.WriteLine($"{line[0]} {line[1]}");
}
}
|
[["-", 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, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 167
| 17
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static _20200219.Cin;
using static _20200219.Util;
using Pair = _20200219.VTuple<long, long>;
using Graph =
System.Collections.Generic.List<System.Collections.Generic.List<long>>;
using System.Text;
namespace _20200219 {
public class Program {
public static void Main(string[] args) {
// ARC033_B(); 17min
// Nikkei2019_2_B();
Tenka1_2018_C();
}
public static void Tenka1_2018_C() {
long N = rl;
long[] A = new long[N];
for (int i = 0; i < N; i++) {
A[i] = rl;
}
Sort(A);
long leftVal = A[0];
long rightVal = A[N - 1];
long ans = Abs(leftVal - rightVal);
long l = 1;
long r = N - 2;
while (l <= r) {
long ll = Abs(leftVal - l);
long lr = Abs(rightVal - l);
long maxL = Max(ll, lr);
long _rl = Abs(leftVal - r);
long rr = Abs(rightVal = r);
long maxR = Max(_rl, rr);
if (maxL > maxR) {
ans += maxL;
if (ll > lr)
leftVal = A[l];
else
rightVal = A[l];
l++;
} else {
ans += maxR;
if (_rl > rr)
leftVal = A[r];
else
rightVal = A[r];
r--;
}
}
Console.WriteLine(ans);
}
public static void Nikkei2019_2_B() {
long N = rl;
long[] A = rla;
if (A[0] != 0) {
Console.WriteLine(0);
return;
}
Sort(A);
HashMap<long, long> hs = new HashMap<long, long>();
hs[0]++;
long prev = 0;
for (int i = 1; i < N; i++) {
if (A[i] == prev) {
hs[A[i]]++;
} else if (A[i] == prev + 1) {
prev = A[i];
hs[A[i]]++;
} else {
Console.WriteLine(0);
return;
}
}
var kosuAry = hs.Keys.OrderBy(n => n).Select(n => hs[n]).ToArray();
if (kosuAry[0] != 1) {
Console.WriteLine(0);
return;
}
long ans = 1;
for (int i = 1; i < kosuAry.Length; i++) {
for (int j = 0; j < kosuAry[i]; j++) {
ans = (ans * kosuAry[i - 1]) % 998244353;
}
}
Console.WriteLine(ans);
}
public static void ARC033_B() {
long NA = rl;
long NB = rl;
long[] A = rla;
long[] B = rla;
HashSet<long> hsA = new HashSet<long>();
foreach (var a in A)
hsA.Add(a);
long bunsi = 0;
foreach (var b in B) {
if (hsA.Contains(b))
bunsi++;
}
foreach (var b in B) {
hsA.Add(b);
}
long bunbo = hsA.Count;
Console.WriteLine(bunsi / (double)bunbo);
}
}
public class HashMap<K, V> : Dictionary<K, V> {
V i;
static Func<V> j =
System.Linq.Expressions.Expression
.Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V)))
.Compile();
public HashMap() {}
public HashMap(V a) { i = a; }
new public V this[K a] { get { V b;
if (TryGetValue(a, out b))
return b;
else
return base[a] = i != null ? i : j();
}
set { base[a] = value; }
}
}
public static class Util {
public static readonly long INF = (long)1e17;
public readonly static long MOD = (long)1e9 + 7;
public static void DontAutoFlush() {
var a = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(a);
}
public static void Flush() { Console.Out.Flush(); }
public static T[] Sort<T>(T[] a) {
Array.Sort<T>(a);
return a;
}
public static T[] SortDecend<T>(T[] a) {
Array.Sort<T>(a);
Array.Reverse(a);
return a;
}
public static void Swap<T>(ref T a, ref T b) {
T c = a;
a = b;
b = c;
}
public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); }
public static void ChMax(ref long a, long b) {
if (a < b)
a = b;
}
public static void ChMin(ref long a, long b) {
if (a > b)
a = b;
}
public static long ModAdd(long a, long b) {
long c = a + b;
if (c >= MOD)
return c % MOD;
return c;
}
public static long ModMul(long a, long b) {
long c = a * b;
if (c >= MOD)
return c % MOD;
return c;
}
public static void ChModAdd(ref long a, long b) {
a += b;
if (a >= MOD)
a %= MOD;
}
public static void ChModMul(ref long a, long b) {
a *= b;
if (a >= MOD)
a %= MOD;
}
public static void FillArray<T>(T[] a, T b) {
int c = a.Length;
for (int d = 0; d < c; d++)
a[d] = b;
}
public static void FillArray<T>(T[,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
for (int e = 0; e < c; e++)
for (int f = 0; f < d; f++) {
a[e, f] = b;
}
}
public static void FillArray<T>(T[,,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
int e = a.GetLength(2);
for (int f = 0; f < c; f++)
for (int g = 0; g < d; g++) {
for (int h = 0; h < e; h++) {
a[f, g, h] = b;
}
}
}
public static long[] Accumulate(long[] a) {
long[] b = new long[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
public static double[] Accumulate(double[] a) {
double[] b = new double[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
}
public static class Cin {
public static long rl {
get { return ReadLong(); }
}
public static long[] rla {
get { return ReadLongArray(); }
}
public static double rd {
get { return ReadDouble(); }
}
public static double[] rda {
get { return ReadDoubleArray(); }
}
public static string rs {
get { return ReadString(); }
}
public static int ReadInt() { return int.Parse(k()); }
public static long ReadLong() { return long.Parse(k()); }
public static double ReadDouble() { return double.Parse(k()); }
public static string ReadString() { return k(); }
public static int[] ReadIntArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
public static long[] ReadLongArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
public static double[] ReadDoubleArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
}
public static void ReadCols(out long[] a, out long[] b, long c) {
a = new long[c];
b = new long[c];
for (int d = 0; d < c; d++) {
a[d] = ReadLong();
b[d] = ReadLong();
}
}
public static void ReadCols(out long[] a, out long[] b, out long[] c,
long d) {
a = new long[d];
b = new long[d];
c = new long[d];
for (int e = 0; e < d; e++) {
a[e] = ReadLong();
b[e] = ReadLong();
c[e] = ReadLong();
}
}
public static int[][] ReadIntTable(int a) {
i = null;
int[][] b = new int [a][];
for (int c = 0; c < a; c++)
b[c] = ReadIntArray();
return b;
}
public static long[][] ReadLongTable(long a) {
i = null;
long[][] b = new long [a][];
for (long c = 0; c < a; c++)
b[c] = ReadLongArray();
return b;
}
static string[] i { get; set; }
static int j { get; set; }
static string k() {
if (i == null || i.Length <= j) {
i = Console.ReadLine().Split(' ');
j = 0;
}
return i[j++];
}
}
public struct VTuple<T1, T2> : IComparable<VTuple<T1, T2>>,
IEquatable<VTuple<T1, T2>> {
public T1 First;
public T2 Second;
public VTuple(T1 a, T2 b) {
First = a;
Second = b;
}
public int CompareTo(VTuple<T1, T2> a) {
int b = Comparer<T1>.Default.Compare(First, a.First);
if (b != 0)
return b;
return Comparer<T2>.Default.Compare(Second, a.Second);
}
public override bool Equals(object a) {
return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a);
}
public bool Equals(VTuple<T1, T2> a) {
return EqualityComparer<T1>.Default.Equals(First, a.First) &&
EqualityComparer<T2>.Default.Equals(Second, a.Second);
}
public override int GetHashCode() {
int a = First != null ? First.GetHashCode() : 0;
int b = Second != null ? Second.GetHashCode() : 0;
uint c = ((uint)a << 5) | ((uint)a >> 27);
return ((int)c + a) ^ b;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static _20200219.Cin;
using static _20200219.Util;
using Pair = _20200219.VTuple<long, long>;
using Graph =
System.Collections.Generic.List<System.Collections.Generic.List<long>>;
using System.Text;
namespace _20200219 {
public class Program {
public static void Main(string[] args) {
// ARC033_B(); 17min
// Nikkei2019_2_B();
Tenka1_2018_C();
}
public static void Tenka1_2018_C() {
long N = rl;
long[] A = new long[N];
for (int i = 0; i < N; i++) {
A[i] = rl;
}
Sort(A);
long leftVal = A[0];
long rightVal = A[N - 1];
long ans = Abs(leftVal - rightVal);
long l = 1;
long r = N - 2;
while (l <= r) {
long ll = Abs(leftVal - A[l]);
long lr = Abs(rightVal - A[l]);
long maxL = Max(ll, lr);
long _rl = Abs(leftVal - A[r]);
long rr = Abs(rightVal - A[r]);
long maxR = Max(_rl, rr);
if (maxL > maxR) {
ans += maxL;
if (ll > lr) {
leftVal = A[l];
} else {
rightVal = A[l];
}
l++;
} else {
ans += maxR;
if (_rl > rr) {
leftVal = A[r];
} else {
rightVal = A[r];
}
r--;
}
// Console.WriteLine(s);
}
Console.WriteLine(ans);
}
public static void Nikkei2019_2_B() {
long N = rl;
long[] A = rla;
if (A[0] != 0) {
Console.WriteLine(0);
return;
}
Sort(A);
HashMap<long, long> hs = new HashMap<long, long>();
hs[0]++;
long prev = 0;
for (int i = 1; i < N; i++) {
if (A[i] == prev) {
hs[A[i]]++;
} else if (A[i] == prev + 1) {
prev = A[i];
hs[A[i]]++;
} else {
Console.WriteLine(0);
return;
}
}
var kosuAry = hs.Keys.OrderBy(n => n).Select(n => hs[n]).ToArray();
if (kosuAry[0] != 1) {
Console.WriteLine(0);
return;
}
long ans = 1;
for (int i = 1; i < kosuAry.Length; i++) {
for (int j = 0; j < kosuAry[i]; j++) {
ans = (ans * kosuAry[i - 1]) % 998244353;
}
}
Console.WriteLine(ans);
}
public static void ARC033_B() {
long NA = rl;
long NB = rl;
long[] A = rla;
long[] B = rla;
HashSet<long> hsA = new HashSet<long>();
foreach (var a in A)
hsA.Add(a);
long bunsi = 0;
foreach (var b in B) {
if (hsA.Contains(b))
bunsi++;
}
foreach (var b in B) {
hsA.Add(b);
}
long bunbo = hsA.Count;
Console.WriteLine(bunsi / (double)bunbo);
}
}
public class HashMap<K, V> : Dictionary<K, V> {
V i;
static Func<V> j =
System.Linq.Expressions.Expression
.Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V)))
.Compile();
public HashMap() {}
public HashMap(V a) { i = a; }
new public V this[K a] { get { V b;
if (TryGetValue(a, out b))
return b;
else
return base[a] = i != null ? i : j();
}
set { base[a] = value; }
}
}
public static class Util {
public static readonly long INF = (long)1e17;
public readonly static long MOD = (long)1e9 + 7;
public static void DontAutoFlush() {
var a = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(a);
}
public static void Flush() { Console.Out.Flush(); }
public static T[] Sort<T>(T[] a) {
Array.Sort<T>(a);
return a;
}
public static T[] SortDecend<T>(T[] a) {
Array.Sort<T>(a);
Array.Reverse(a);
return a;
}
public static void Swap<T>(ref T a, ref T b) {
T c = a;
a = b;
b = c;
}
public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); }
public static void ChMax(ref long a, long b) {
if (a < b)
a = b;
}
public static void ChMin(ref long a, long b) {
if (a > b)
a = b;
}
public static long ModAdd(long a, long b) {
long c = a + b;
if (c >= MOD)
return c % MOD;
return c;
}
public static long ModMul(long a, long b) {
long c = a * b;
if (c >= MOD)
return c % MOD;
return c;
}
public static void ChModAdd(ref long a, long b) {
a += b;
if (a >= MOD)
a %= MOD;
}
public static void ChModMul(ref long a, long b) {
a *= b;
if (a >= MOD)
a %= MOD;
}
public static void FillArray<T>(T[] a, T b) {
int c = a.Length;
for (int d = 0; d < c; d++)
a[d] = b;
}
public static void FillArray<T>(T[,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
for (int e = 0; e < c; e++)
for (int f = 0; f < d; f++) {
a[e, f] = b;
}
}
public static void FillArray<T>(T[,,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
int e = a.GetLength(2);
for (int f = 0; f < c; f++)
for (int g = 0; g < d; g++) {
for (int h = 0; h < e; h++) {
a[f, g, h] = b;
}
}
}
public static long[] Accumulate(long[] a) {
long[] b = new long[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
public static double[] Accumulate(double[] a) {
double[] b = new double[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
}
public static class Cin {
public static long rl {
get { return ReadLong(); }
}
public static long[] rla {
get { return ReadLongArray(); }
}
public static double rd {
get { return ReadDouble(); }
}
public static double[] rda {
get { return ReadDoubleArray(); }
}
public static string rs {
get { return ReadString(); }
}
public static int ReadInt() { return int.Parse(k()); }
public static long ReadLong() { return long.Parse(k()); }
public static double ReadDouble() { return double.Parse(k()); }
public static string ReadString() { return k(); }
public static int[] ReadIntArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
public static long[] ReadLongArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
public static double[] ReadDoubleArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
}
public static void ReadCols(out long[] a, out long[] b, long c) {
a = new long[c];
b = new long[c];
for (int d = 0; d < c; d++) {
a[d] = ReadLong();
b[d] = ReadLong();
}
}
public static void ReadCols(out long[] a, out long[] b, out long[] c,
long d) {
a = new long[d];
b = new long[d];
c = new long[d];
for (int e = 0; e < d; e++) {
a[e] = ReadLong();
b[e] = ReadLong();
c[e] = ReadLong();
}
}
public static int[][] ReadIntTable(int a) {
i = null;
int[][] b = new int [a][];
for (int c = 0; c < a; c++)
b[c] = ReadIntArray();
return b;
}
public static long[][] ReadLongTable(long a) {
i = null;
long[][] b = new long [a][];
for (long c = 0; c < a; c++)
b[c] = ReadLongArray();
return b;
}
static string[] i { get; set; }
static int j { get; set; }
static string k() {
if (i == null || i.Length <= j) {
i = Console.ReadLine().Split(' ');
j = 0;
}
return i[j++];
}
}
public struct VTuple<T1, T2> : IComparable<VTuple<T1, T2>>,
IEquatable<VTuple<T1, T2>> {
public T1 First;
public T2 Second;
public VTuple(T1 a, T2 b) {
First = a;
Second = b;
}
public int CompareTo(VTuple<T1, T2> a) {
int b = Comparer<T1>.Default.Compare(First, a.First);
if (b != 0)
return b;
return Comparer<T2>.Default.Compare(Second, a.Second);
}
public override bool Equals(object a) {
return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a);
}
public bool Equals(VTuple<T1, T2> a) {
return EqualityComparer<T1>.Default.Equals(First, a.First) &&
EqualityComparer<T2>.Default.Equals(Second, a.Second);
}
public override int GetHashCode() {
int a = First != null ? First.GetHashCode() : 0;
int b = Second != null ? Second.GetHashCode() : 0;
uint c = ((uint)a << 5) | ((uint)a >> 27);
return ((int)c + a) ^ b;
}
}
}
|
[["+", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73], ["-", 3, 4, 0, 28, 0, 11, 0, 202, 0, 32], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 2,479
| 22
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<long> Slist() {
return ReadLine().Split().Select(long.Parse).ToList();
}
static long Mod = (long)1e9 + 7;
static void Main(string[] args) {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
var N = Sarray()[0];
var k = 0L;
for (k = 0; k <= N; ++k) {
if (2 * N == k * (k + 1))
break;
}
if (2 * N != k * (k + 1)) {
WriteLine("No");
return;
}
var ans =
Enumerable.Range(0, (int)k + 1).Select(_ => new long[k + 1]).ToArray();
var s = 1L;
for (var i = 0; i <= k; ++i)
ans[i][0] = k;
for (var i = 0; i < k; ++i) {
for (var j = i + 1; j <= k; ++j)
ans[j][i + 1] = s + j - (i + 1);
for (var j = i; j < k; ++j)
ans[i][j + 1] = s++;
}
for (var i = 0; i <= k; ++i)
WriteLine(string.Join(" ", ans[i]));
// Out.Flush();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<long> Slist() {
return ReadLine().Split().Select(long.Parse).ToList();
}
static long Mod = (long)1e9 + 7;
static void Main(string[] args) {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
var N = Sarray()[0];
var k = 0L;
for (k = 0; k <= N; ++k) {
if (2 * N == k * (k + 1))
break;
}
if (2 * N != k * (k + 1)) {
WriteLine("No");
return;
}
var ans =
Enumerable.Range(0, (int)k + 1).Select(_ => new long[k + 1]).ToArray();
var s = 1L;
for (var i = 0; i <= k; ++i)
ans[i][0] = k;
for (var i = 0; i < k; ++i) {
for (var j = i + 1; j <= k; ++j)
ans[j][i + 1] = s + j - (i + 1);
for (var j = i; j < k; ++j)
ans[i][j + 1] = s++;
}
WriteLine("Yes");
WriteLine(k + 1);
for (var i = 0; i <= k; ++i)
WriteLine(string.Join(" ", ans[i]));
// Out.Flush();
}
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 374
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder {
class AC {
const int MOD = 1000000007;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
const double EPS = 1e-8;
static readonly int[] dx = { 0, 1, 0, -1 };
static readonly int[] dy = { 1, 0, -1, 0 };
// static List<List<int>> G = new List<List<int>>();
// static List<List<Edge>>G = new List<List<Edge>>();
// static List<Edge> E = new List<Edge>();
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var cin = new Scanner();
int N = int.Parse(Console.ReadLine());
long K = -1;
for (var k = 1; k * (k - 1) <= 2 * N; k++) {
if (k * (k - 1) == 2 * N) {
K = k;
break;
}
}
if (K == -1) {
Console.WriteLine("No");
return;
}
var ans = new List<List<int>>();
for (var i = 0; i < K; i++)
ans.Add(new List<int>());
int cur = 1;
for (var i = 0; i < K - 1; i++) {
for (var j = i + 1; j < K; j++) {
ans[i].Add(cur);
ans[j].Add(cur);
cur++;
}
}
Console.WriteLine("Yes");
Console.WriteLine(K);
for (var i = 0; i < K; i++) {
Console.Write($"{K - 1} ");
Console.WriteLine(string.Join(" ", ans[i]));
}
Console.Out.Flush();
}
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;
}
}
struct Pair<T, U> : IComparable<Pair<T, U>>
where T : IComparable<T>
where U : IComparable<U> {
public T first;
public U second;
private readonly bool CompWithFirst;
public Pair(T f, U s, int comp) {
first = f;
second = s;
CompWithFirst = comp == 1;
}
public Pair(T f, U s) {
first = f;
second = s;
CompWithFirst = true;
}
public int CompareTo(Pair<T, U> other) {
return CompWithFirst ? first.CompareTo(other.first)
: second.CompareTo(other.second);
}
}
}
public class PriorityQueue<T>
where T : IComparable<T> {
public readonly List<T> Q;
private readonly int r;
public PriorityQueue(bool ascending) {
if (ascending) {
r = 1;
} else {
r = -1;
}
Q = new List<T>();
}
private void PushHeap(List<T> list, T item) {
int n = list.Count();
list.Add(item);
while (n != 0) {
int pIndex = (n - 1) / 2;
if (list[n].CompareTo(list[pIndex]) * r > 0) {
Swap(Q, n, pIndex);
} else {
break;
}
n = pIndex;
}
}
private void PopHeap(List<T> list) {
int n = list.Count() - 1;
list[0] = list[n];
list.RemoveAt(n);
int cur = 0;
int comp;
while (2 * cur + 1 <= n - 1) {
int c1 = 2 * cur + 1;
int c2 = 2 * (cur + 1);
if (c1 == n - 1) {
comp = c1;
} else {
comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2;
}
if (list[cur].CompareTo(list[comp]) * r < 0) {
Swap(Q, cur, comp);
} else {
break;
}
cur = comp;
}
}
private void Swap(List<T> list, int a, int b) {
T keep = list[a];
list[a] = list[b];
list[b] = keep;
}
public void Enqueue(T value) { PushHeap(Q, value); }
public T Dequeue() {
T ret = Q[0];
PopHeap(Q);
return ret;
}
public T Peek() { return Q[0]; }
public int Count() { return Q.Count(); }
public bool Contains(T obj) { return Q.Contains(obj); }
}
public class Scanner {
public int[] ReadSplit() {
int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
return array;
}
public long[] ReadSplitL() {
long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
return array;
}
public double[] ReadSplitD() {
double[] array = Console.ReadLine().Split().Select(double.Parse).ToArray();
return array;
}
public void ReadTwo_Int(out int n, out int m) {
var input = ReadSplit();
n = input[0];
m = input[1];
}
public void ReadTwo_long(out long n, out long m) {
var input = ReadSplitL();
n = input[0];
m = input[1];
}
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
for (var i = 0; i < array.Length; i++) {
array[i] = initialvalue;
}
}
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Display<T>(T[,] array2d, int n, int m) {
for (var i = 0; i < n; i++) {
for (var j = 0; j < m; j++) {
Console.Write($"{array2d[i, j]} ");
}
Console.WriteLine();
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder {
class AC {
const int MOD = 1000000007;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
const double EPS = 1e-8;
static readonly int[] dx = { 0, 1, 0, -1 };
static readonly int[] dy = { 1, 0, -1, 0 };
// static List<List<int>> G = new List<List<int>>();
// static List<List<Edge>>G = new List<List<Edge>>();
// static List<Edge> E = new List<Edge>();
static void Main(string[] args) {
// var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
// false }; Console.SetOut(sw);
var cin = new Scanner();
int N = int.Parse(Console.ReadLine());
long K = -1;
for (var k = 1; k * (k - 1) <= 2 * N; k++) {
if (k * (k - 1) == 2 * N) {
K = k;
break;
}
}
if (K == -1) {
Console.WriteLine("No");
return;
}
var ans = new List<List<int>>();
for (var i = 0; i < K; i++)
ans.Add(new List<int>());
int cur = 1;
for (var i = 0; i < K - 1; i++) {
for (var j = i + 1; j < K; j++) {
ans[i].Add(cur);
ans[j].Add(cur);
cur++;
}
}
Console.WriteLine("Yes");
Console.WriteLine(K);
for (var i = 0; i < K; i++) {
Console.Write($"{K - 1} ");
Console.WriteLine(string.Join(" ", ans[i]));
}
// Console.Out.Flush();
}
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;
}
}
struct Pair<T, U> : IComparable<Pair<T, U>>
where T : IComparable<T>
where U : IComparable<U> {
public T first;
public U second;
private readonly bool CompWithFirst;
public Pair(T f, U s, int comp) {
first = f;
second = s;
CompWithFirst = comp == 1;
}
public Pair(T f, U s) {
first = f;
second = s;
CompWithFirst = true;
}
public int CompareTo(Pair<T, U> other) {
return CompWithFirst ? first.CompareTo(other.first)
: second.CompareTo(other.second);
}
}
}
public class PriorityQueue<T>
where T : IComparable<T> {
public readonly List<T> Q;
private readonly int r;
public PriorityQueue(bool ascending) {
if (ascending) {
r = 1;
} else {
r = -1;
}
Q = new List<T>();
}
private void PushHeap(List<T> list, T item) {
int n = list.Count();
list.Add(item);
while (n != 0) {
int pIndex = (n - 1) / 2;
if (list[n].CompareTo(list[pIndex]) * r > 0) {
Swap(Q, n, pIndex);
} else {
break;
}
n = pIndex;
}
}
private void PopHeap(List<T> list) {
int n = list.Count() - 1;
list[0] = list[n];
list.RemoveAt(n);
int cur = 0;
int comp;
while (2 * cur + 1 <= n - 1) {
int c1 = 2 * cur + 1;
int c2 = 2 * (cur + 1);
if (c1 == n - 1) {
comp = c1;
} else {
comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2;
}
if (list[cur].CompareTo(list[comp]) * r < 0) {
Swap(Q, cur, comp);
} else {
break;
}
cur = comp;
}
}
private void Swap(List<T> list, int a, int b) {
T keep = list[a];
list[a] = list[b];
list[b] = keep;
}
public void Enqueue(T value) { PushHeap(Q, value); }
public T Dequeue() {
T ret = Q[0];
PopHeap(Q);
return ret;
}
public T Peek() { return Q[0]; }
public int Count() { return Q.Count(); }
public bool Contains(T obj) { return Q.Contains(obj); }
}
public class Scanner {
public int[] ReadSplit() {
int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
return array;
}
public long[] ReadSplitL() {
long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
return array;
}
public double[] ReadSplitD() {
double[] array = Console.ReadLine().Split().Select(double.Parse).ToArray();
return array;
}
public void ReadTwo_Int(out int n, out int m) {
var input = ReadSplit();
n = input[0];
m = input[1];
}
public void ReadTwo_long(out long n, out long m) {
var input = ReadSplitL();
n = input[0];
m = input[1];
}
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
for (var i = 0; i < array.Length; i++) {
array[i] = initialvalue;
}
}
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Display<T>(T[,] array2d, int n, int m) {
for (var i = 0; i < n; i++) {
for (var j = 0; j < m; j++) {
Console.Write($"{array2d[i, j]} ");
}
Console.WriteLine();
}
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["-", 0, 198, 0, 200, 0, 212, 0, 230, 39, 22], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 230, 10, 229, 0, 45], ["-", 0, 212, 0, 230, 10, 229, 0, 11, 31, 22], ["-", 0, 230, 10, 229, 0, 11, 0, 202, 0, 32], ["-", 0, 230, 10, 229, 0, 11, 12, 211, 0, 147], ["-", 0, 200, 0, 212, 0, 230, 10, 229, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22]]
| 8
| 1,415
| 33
|
using System;
using System.Collections.Generic;
using System.Text;
public class Program {
private int N;
public void Solve() {
var sc = new Scanner();
N = sc.NextInt();
int r;
for (r = 1; (r + 1) * r / 2 < N; r++)
;
if ((r + 1) * r / 2 != N) {
Console.WriteLine("No");
return;
}
Console.WriteLine("Yes");
List<int>[] ans = new List<int>[r + 1];
for (int i = 0; i <= r; i++) {
ans[i] = new List<int>();
}
int n = 1;
for (int i = 0; i < r; i++) {
int t = ans[i].Count;
for (int j = 0; j < r - t; j++) {
ans[i].Add(n);
ans[i + j + 1].Add(n);
n++;
}
}
var sb = new StringBuilder();
foreach (List<int> list in ans) {
sb.AppendLine($"{list.Count} {string.Join(" ", list)}");
}
Console.Write(sb.ToString());
}
public static void Main(string[] args) { new Program().Solve(); }
}
class Scanner {
public Scanner() {
_pos = 0;
_line = new string[0];
}
const char Separator = ' ';
private int _pos;
private string[] _line;
#region スペース区切りで取得
public string Next() {
if (_pos >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_pos = 0;
}
return _line[_pos++];
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public double NextDouble() { return double.Parse(Next()); }
#endregion
#region 型変換
private int[] ToIntArray(string[] array) {
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
private long[] ToLongArray(string[] array) {
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
private double[] ToDoubleArray(string[] array) {
var result = new double[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = double.Parse(array[i]);
}
return result;
}
#endregion
#region 配列取得
public string[] Array() {
if (_pos >= _line.Length)
_line = Console.ReadLine().Split(Separator);
_pos = _line.Length;
return _line;
}
public int[] IntArray() { return ToIntArray(Array()); }
public long[] LongArray() { return ToLongArray(Array()); }
public double[] DoubleArray() { return ToDoubleArray(Array()); }
#endregion
}
|
using System;
using System.Collections.Generic;
using System.Text;
public class Program {
private int N;
public void Solve() {
var sc = new Scanner();
N = sc.NextInt();
int r;
for (r = 1; (r + 1) * r / 2 < N; r++)
;
if ((r + 1) * r / 2 != N) {
Console.WriteLine("No");
return;
}
List<int>[] ans = new List<int>[r + 1];
for (int i = 0; i <= r; i++) {
ans[i] = new List<int>();
}
int n = 1;
for (int i = 0; i < r; i++) {
int t = ans[i].Count;
for (int j = 0; j < r - t; j++) {
ans[i].Add(n);
ans[i + j + 1].Add(n);
n++;
}
}
var sb = new StringBuilder();
sb.AppendLine("Yes");
sb.AppendLine((r + 1).ToString());
foreach (List<int> list in ans) {
sb.AppendLine($"{list.Count} {string.Join(" ", list)}");
}
Console.Write(sb.ToString());
}
public static void Main(string[] args) { new Program().Solve(); }
}
class Scanner {
public Scanner() {
_pos = 0;
_line = new string[0];
}
const char Separator = ' ';
private int _pos;
private string[] _line;
#region スペース区切りで取得
public string Next() {
if (_pos >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_pos = 0;
}
return _line[_pos++];
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public double NextDouble() { return double.Parse(Next()); }
#endregion
#region 型変換
private int[] ToIntArray(string[] array) {
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
private long[] ToLongArray(string[] array) {
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
private double[] ToDoubleArray(string[] array) {
var result = new double[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = double.Parse(array[i]);
}
return result;
}
#endregion
#region 配列取得
public string[] Array() {
if (_pos >= _line.Length)
_line = Console.ReadLine().Split(Separator);
_pos = _line.Length;
return _line;
}
public int[] IntArray() { return ToIntArray(Array()); }
public long[] LongArray() { return ToLongArray(Array()); }
public double[] DoubleArray() { return ToDoubleArray(Array()); }
#endregion
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 28, 0, 213, 63, 214, 205, 23, 0, 24], ["+", 0, 213, 63, 214, 205, 23, 0, 16, 31, 22], ["+", 0, 213, 63, 214, 205, 23, 0, 16, 17, 72], ["+", 0, 213, 63, 214, 205, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 213, 63, 214, 205, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 727
| 33
|
// デバッグ実行:Ctrl+F5
using System;
class Program {
static void Main(string[] args) {
String line;
line = Console.ReadLine();
String[] words = line.Split(' ');
int N = int.Parse(line);
int limit = (int)Math.Sqrt(N * 2) + 1;
int number = 0;
for (int i = 1; i < limit; i++) {
if (i * (i + 1) == N * 2) {
// 成功
number = i;
break;
}
}
if (number == 0) {
Console.WriteLine("No");
} else {
Console.WriteLine("Yes");
int[] syuugou = new int[number * (number + 1)];
int now = 1;
for (int j = 0; j < number + 1; j++) {
for (int i = j; i < number; i++) {
syuugou[i + j * number] = now;
syuugou[j + (i + 1) * number] = now;
now++;
}
}
for (int j = 0; j < number + 1; j++) {
Console.Write(number + " " + syuugou[j * number]);
for (int i = 1; i < number; i++) {
Console.Write(" " + syuugou[i + j * number]);
}
Console.WriteLine();
}
}
}
}
|
// デバッグ実行:Ctrl+F5
using System;
class Program {
static void Main(string[] args) {
String line;
line = Console.ReadLine();
String[] words = line.Split(' ');
int N = int.Parse(line);
int limit = (int)Math.Sqrt(N * 2) + 1;
int number = 0;
for (int i = 1; i < limit; i++) {
if (i * (i + 1) == N * 2) {
// 成功
number = i;
break;
}
}
if (number == 0) {
Console.WriteLine("No");
} else {
Console.WriteLine("Yes");
Console.WriteLine(number + 1);
int[] syuugou = new int[number * (number + 1)];
int now = 1;
for (int j = 0; j < number + 1; j++) {
for (int i = j; i < number; i++) {
syuugou[i + j * number] = now;
syuugou[j + (i + 1) * number] = now;
now++;
}
}
for (int j = 0; j < number + 1; j++) {
Console.Write(number + " " + syuugou[j * number]);
for (int i = 1; i < number; i++) {
Console.Write(" " + syuugou[i + j * number]);
}
Console.WriteLine();
}
}
}
}
|
[["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 305
| 9
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(ReadLine()); }
public static long[] Reads() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
public static long gcd(long x, long y) {
if (x < y)
gcd(y, x);
while (y != 0) {
var z = x;
x = y;
y = z % y;
}
return x;
}
public static long lcm(long x, long y) { return x * y / gcd(x, y); }
public static long C(long n, long k) {
long x = 1;
for (long i = 1; i <= k; i++) {
x *= n - i + 1;
x /= i;
}
return x;
}
static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var q = Reads();
var n = q[0];
var m = q[1];
var s = ReadLine().ToArray();
var t = ReadLine().ToArray();
var l = lcm(n, m);
var x = l / n;
var y = l / m;
var f = true;
for (int i = 0; i < Math.Min(n, m); i++) {
if (i % x == 0 && i % y == 0) {
if (s[i / x] != t[i / y])
f = false;
}
}
WriteLine(f ? l : -1);
Console.Out.Flush();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(ReadLine()); }
public static long[] Reads() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
public static long gcd(long x, long y) {
if (x < y)
gcd(y, x);
while (y != 0) {
var z = x;
x = y;
y = z % y;
}
return x;
}
public static long lcm(long x, long y) { return x * y / gcd(x, y); }
public static long C(long n, long k) {
long x = 1;
for (long i = 1; i <= k; i++) {
x *= n - i + 1;
x /= i;
}
return x;
}
static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var q = Reads();
var n = q[0];
var m = q[1];
var s = ReadLine().ToArray();
var t = ReadLine().ToArray();
var l = lcm(n, m);
var x = l / n;
var y = l / m;
var r = x * y;
var f = true;
for (long i = 0; i / x < n && i / y < m; i += r) {
if (s[i / x] != t[i / y])
f = false;
}
WriteLine(f ? l : -1);
Console.Out.Flush();
}
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 7, 15, 16, 31, 16, 31, 16, 17, 85], ["+", 0, 7, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 7, 15, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 7, 15, 16, 12, 213, 3, 4, 0, 21], ["-", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 109], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 17, 85], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 31, 22], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 393
| 41
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long n = sc.NextInt();
long m = sc.NextInt();
string s = sc.Next();
string t = sc.Next();
long answer = Lcm(n, m);
long stepN = answer / n;
long stepM = answer / m;
for (long i = 0; i < n; i++) {
long index = stepN * 1;
if (index % stepM == 0) {
int indexS = (int)(index / stepN);
int indexT = (int)(index / stepM);
if (indexS >= n || indexT >= m) {
continue;
}
char schar = s[(int)(index / stepN)];
char tchar = t[(int)(index / stepM)];
if (schar != tchar) {
Console.WriteLine(-1);
return;
}
}
}
Console.WriteLine(answer);
}
// 最大公約数(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;
}
// 最小公倍数(long)
private static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long n = sc.NextInt();
long m = sc.NextInt();
string s = sc.Next();
string t = sc.Next();
long answer = Lcm(n, m);
long stepN = answer / n;
long stepM = answer / m;
for (long i = 0; i < n; i++) {
long index = stepN * i;
if (index % stepM == 0) {
int indexS = (int)(index / stepN);
int indexT = (int)(index / stepM);
if (indexS >= n || indexT >= m) {
continue;
}
char schar = s[indexS];
char tchar = t[indexT];
if (schar != tchar) {
Console.WriteLine(-1);
return;
}
}
}
Console.WriteLine(answer);
}
// 最大公約数(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;
}
// 最小公倍数(long)
private static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
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, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 0, 204, 206, 207, 0, 28, 0, 74, 0, 24], ["-", 0, 204, 206, 207, 0, 28, 0, 74, 39, 199], ["-", 0, 204, 206, 207, 0, 28, 0, 74, 0, 25], ["-", 206, 207, 0, 28, 0, 74, 51, 23, 0, 24], ["-", 0, 28, 0, 74, 51, 23, 0, 16, 31, 22], ["-", 0, 28, 0, 74, 51, 23, 0, 16, 17, 85], ["-", 0, 28, 0, 74, 51, 23, 0, 16, 12, 22], ["-", 206, 207, 0, 28, 0, 74, 51, 23, 0, 25], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 602
| 20
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
int n = nm[0];
int m = nm[1];
var s = Console.ReadLine();
var t = Console.ReadLine();
long ans = 0;
var ok = true;
long lcm = Lcm(n, m);
long gcd = Gcd(n, m);
for (int i = 0; i < gcd; ++i) {
if (i == 0) {
if (s[i] != t[i]) {
ok = false;
break;
}
} else if (s[i * n - 1] != t[i * m - 1]) {
ok = false;
break;
}
}
if (ok) {
ans = lcm;
} else {
ans = -1;
}
// 出力
Console.WriteLine(ans);
}
// 最小公倍数
public static long Lcm(long a, long b) { return a * b / Gcd(a, b); }
// ユークリッドの互除法
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
int n = nm[0];
int m = nm[1];
var s = Console.ReadLine();
var t = Console.ReadLine();
long ans = 0;
var ok = true;
long lcm = Lcm(n, m);
long gcd = Gcd(n, m);
for (int i = 0; i < gcd; ++i) {
if (i == 0) {
if (s[i] != t[i]) {
ok = false;
break;
}
} else if (s[i * n / (int)gcd] != t[i * m / (int)gcd]) {
ok = false;
break;
}
}
if (ok) {
ans = lcm;
} else {
ans = -1;
}
// 出力
Console.WriteLine(ans);
}
// 最小公倍数
public static long Lcm(long a, long b) { return a * b / Gcd(a, b); }
// ユークリッドの互除法
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
}
|
[["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 85], ["+", 206, 207, 0, 28, 0, 16, 12, 74, 0, 24], ["+", 206, 207, 0, 28, 0, 16, 12, 74, 39, 199], ["+", 206, 207, 0, 28, 0, 16, 12, 74, 0, 25], ["+", 206, 207, 0, 28, 0, 16, 12, 74, 51, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 85]]
| 8
| 311
| 14
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int[,] A = new int[N, 2];
int[][] B = new int [N * 2][];
for (var i = 0; i < N; i++) {
string[] str = Console.ReadLine().Split();
A[i, 0] = int.Parse(str[0]);
A[i, 1] = int.Parse(str[1]);
B[i * 2] = new int[3];
B[i * 2][0] = A[i, 0];
B[i * 2][1] = i;
B[i * 2][2] = 0;
B[i * 2 + 1] = new int[3];
B[i * 2 + 1][0] = A[i, 1];
B[i * 2 + 1][1] = i;
B[i * 2 + 1][2] = 1;
}
Array.Sort(B, (x, y) => x[0] - y[0]);
int[,] C = new int[N, 2];
int cta = 0;
int ctb = 0;
long ct = 0;
for (var i = 0; i < N; i++) {
ct += B[i][0];
C[B[i][1], B[i][2]] += 1;
if (B[i][2] == 0) {
cta += 1;
} else {
ctb += 1;
}
}
if (cta < N && ctb < N) {
int fct = 0;
for (var i = 0; i < N; i++) {
if (C[i, 0] == 1 && C[i, 1] == 1) {
fct += 1;
}
}
if (fct == 0) {
ct -= B[N][0];
ct += B[N + 1][0];
if (B[N][1] == B[N + 1][1]) {
long ct1 = ct;
ct1 -= B[N + 1][0];
ct1 += B[N + 2][0];
long ct2 = ct;
ct2 -= B[N - 1][0];
ct2 += B[N][0];
ct = Math.Min(ct1, ct2);
}
}
}
Console.WriteLine(ct);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int[,] A = new int[N, 2];
int[][] B = new int [N * 2][];
for (var i = 0; i < N; i++) {
string[] str = Console.ReadLine().Split();
A[i, 0] = int.Parse(str[0]);
A[i, 1] = int.Parse(str[1]);
B[i * 2] = new int[3];
B[i * 2][0] = A[i, 0];
B[i * 2][1] = i;
B[i * 2][2] = 0;
B[i * 2 + 1] = new int[3];
B[i * 2 + 1][0] = A[i, 1];
B[i * 2 + 1][1] = i;
B[i * 2 + 1][2] = 1;
}
Array.Sort(B, (x, y) => x[0] - y[0]);
int[,] C = new int[N, 2];
int cta = 0;
int ctb = 0;
long ct = 0;
for (var i = 0; i < N; i++) {
ct += B[i][0];
C[B[i][1], B[i][2]] += 1;
if (B[i][2] == 0) {
cta += 1;
} else {
ctb += 1;
}
}
if (cta < N && ctb < N) {
int fct = 0;
for (var i = 0; i < N; i++) {
if (C[i, 0] == 1 && C[i, 1] == 1) {
fct += 1;
}
}
if (fct == 0) {
ct -= B[N - 1][0];
ct += B[N][0];
if (B[N - 1][1] == B[N][1]) {
long ct1 = ct;
ct1 -= B[N][0];
ct1 += B[N + 1][0];
long ct2 = ct;
ct2 -= B[N - 2][0];
ct2 += B[N - 1][0];
ct = Math.Min(ct1, ct2);
}
}
}
Console.WriteLine(ct);
}
}
|
[["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 560
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class Program {
static void Main() {
IO io = new IO();
//ここから
int[] str = io.ReadLineToIntArray();
int n = str[0];
int x = str[1];
int[] a = io.ReadLineToIntArray();
int ans = 0;
a = a.OrderBy(A => A).ToArray();
for (int i = 0; i < n; i++) {
if (x >= a[i]) {
x -= a[i];
ans++;
} else {
break;
}
}
if (x > 0 && ans > 0) {
ans--;
}
//ここまで
Console.Write(ans);
Console.ReadKey();
}
}
//関数
public class Func {
public void Swap<T>(ref T a, ref T b) {
T temp;
temp = a;
a = b;
b = temp;
}
}
// IOを担う関数群
public class IO {
// stringの入力
public string ReadLineToString() { return Console.ReadLine(); }
// intの入力
public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
//空白区切りの複数の文字列の入力をstring[]にして返す
public string[] ReadLineToStringArray() {
return Console.ReadLine().Split(' ').ToArray();
}
//空白区切りの複数の整数の入力をint[]にして返す
public int[] ReadLineToIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
//空白区切りの複数の文字列の入力をList<string>で受け取る
public List<string> ReadLineToStringList() {
return Console.ReadLine().Split(' ').ToList();
}
//空白区切りの複数の整数の入力をList<int>で受け取る
public List<int> ReadLineToIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class Program {
static void Main() {
IO io = new IO();
//ここから
int[] str = io.ReadLineToIntArray();
int n = str[0];
int x = str[1];
int[] a = io.ReadLineToIntArray();
int ans = 0;
a = a.OrderBy(A => A).ToArray();
for (int i = 0; i < n; i++) {
if (x >= a[i]) {
x -= a[i];
ans++;
} else {
x -= a[i];
break;
}
}
if (x > 0 && ans > 0) {
ans--;
}
//ここまで
Console.Write(ans);
Console.ReadKey();
}
}
//関数
public class Func {
public void Swap<T>(ref T a, ref T b) {
T temp;
temp = a;
a = b;
b = temp;
}
}
// IOを担う関数群
public class IO {
// stringの入力
public string ReadLineToString() { return Console.ReadLine(); }
// intの入力
public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
//空白区切りの複数の文字列の入力をstring[]にして返す
public string[] ReadLineToStringArray() {
return Console.ReadLine().Split(' ').ToArray();
}
//空白区切りの複数の整数の入力をint[]にして返す
public int[] ReadLineToIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
//空白区切りの複数の文字列の入力をList<string>で受け取る
public List<string> ReadLineToStringList() {
return Console.ReadLine().Split(' ').ToList();
}
//空白区切りの複数の整数の入力をList<int>で受け取る
public List<int> ReadLineToIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
}
}
|
[["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 75, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 387
| 7
|
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;
class Program {
static void Main(string[] Args) {
var Nx = new List<string>(ReadLine().Split(' '))
.Select(ele => Int32.Parse(ele))
.ToList();
var a = new List<string>(ReadLine().Split(' '))
.Select(ele => Int32.Parse(ele))
.ToList();
int Result = 0;
while (true) {
int min = a.Min();
if (min <= Nx[1]) {
Result++;
a.Remove(min);
} else {
break;
}
if (a.Count() == 0)
break;
}
WriteLine(Result);
ReadLine();
}
}
|
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;
class Program {
static void Main(string[] Args) {
var Nx = new List<string>(ReadLine().Split(' '))
.Select(ele => Int32.Parse(ele))
.ToList();
var a = new List<string>(ReadLine().Split(' '))
.Select(ele => Int32.Parse(ele))
.ToList();
int Result = 0;
while (true) {
int min = a.Min();
if (min <= Nx[1]) {
a.Remove(min);
Nx[1] -= min;
Result++;
} else
break;
if (a.Count() == 0) {
if (Nx[1] != 0)
Result--;
break;
}
}
WriteLine(Result);
ReadLine();
}
}
|
[["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 0, 52, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 64, 196, 0, 57, 64, 1, 0, 223, 0, 68], ["+", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 177
| 29
|
using System;
using System.Collections.Generic;
using System.Linq;
using console = System.Console;
namespace AtCoderTemplate {
public class App {
public static void Main(string[] args) {
var p = int.Parse(console.ReadLine().Split()[1]);
var q = console.ReadLine()
.Split()
.Select(i => int.Parse(i))
.OrderBy(i => i)
.Select(i => {
p -= i;
return p;
})
.Count(i => i >= 0);
console.WriteLine(q - (p > 0 ? 1 : 0));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using console = System.Console;
namespace AtCoderTemplate {
public class App {
public static void Main(string[] args) {
var p = long.Parse(console.ReadLine().Split()[1]);
console.WriteLine(console.ReadLine()
.Split()
.Select(i => long.Parse(i))
.OrderBy(i => i)
.Select(i => {
p -= i;
return p;
})
.Count(i => i >= 0) -
(p > 0 ? 1 : 0));
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
| 8
| 137
| 17
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(' ');
string N = s[0];
int x = int.Parse(s[1]);
int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int temp = 0;
Array.Sort(a);
if (a.Sum() < x) {
Console.WriteLine(a.Length - 1);
return;
}
for (int i = 0; i < a.Length; i++) {
x -= a[i];
temp = i;
if (x < 0) {
break;
}
temp++;
}
Console.WriteLine(temp);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(' ');
string N = s[0];
long x = long.Parse(s[1]);
long[] a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
long temp = 0;
Array.Sort(a);
if (a.Sum() < x) {
Console.WriteLine(a.Length - 1);
return;
}
for (long i = 0; i < a.Length; i++) {
x -= a[i];
// temp = i;
if (x < 0) {
break;
}
temp++;
}
Console.WriteLine(temp);
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 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, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 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, 32], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22]]
| 8
| 196
| 16
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Solver {
Scanner sc = new Scanner();
public void Solve() {
var N = sc.nextInt();
var x = sc.nextInt();
var a = sc.ArrayInt(N);
a = a.OrderBy(i => i).ToArray();
var ans = 0;
for (int i = 0; i < N; i++) {
if (x >= a[i]) {
ans++;
x -= a[i];
}
}
WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] args) {
Solver s = new Solver();
s.Solve();
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Solver {
Scanner sc = new Scanner();
public void Solve() {
var N = sc.nextInt();
var x = sc.nextInt();
var a = sc.ArrayInt(N);
a = a.OrderBy(i => i).ToArray();
var ans = 0;
for (int i = 0; i < N; i++) {
if (x >= a[i]) {
x -= a[i];
if (i == N - 1) {
if (x == 0) {
ans++;
}
} else {
ans++;
}
}
}
WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] args) {
Solver s = new Solver();
s.Solve();
}
}
|
[["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 509
| 30
|
using System;
using static System.Console;
using static System.Math;
public class Hello {
public static void Main() {
string[] input = ReadLine().Split(' ');
int kazu = int.Parse(input[0]);
string[] suji = ReadLine().Split(' ');
// int max = int.Parse(input[1]);
int[] suuji = new int[kazu];
for (int i = 0; i < kazu; i++) {
suuji[i] = int.Parse(suji[i]);
}
for (int i = 0; i < kazu * 2; i++) {
for (int j = 0; j < kazu - 1; j++) {
if (suuji[j] > suuji[j + 1]) {
int temp = suuji[j];
suuji[j] = suuji[j + 1];
suuji[j + 1] = temp;
}
}
}
int a = int.Parse(input[1]);
int ans = 0;
for (int i = 0; i < kazu; i++) {
if (suuji[i] < a) {
a -= suuji[i];
ans++;
}
}
WriteLine(ans);
}
}
|
using System;
using static System.Console;
using static System.Math;
public class Hello {
public static void Main() {
string[] input = ReadLine().Split(' ');
int kazu = int.Parse(input[0]);
string[] suji = ReadLine().Split(' ');
// int max = int.Parse(input[1]);
int[] suuji = new int[kazu];
for (int i = 0; i < kazu; i++) {
suuji[i] = int.Parse(suji[i]);
}
for (int i = 0; i < kazu * 10; i++) {
for (int j = 0; j < kazu - 1; j++) {
if (suuji[j] > suuji[j + 1]) {
int temp = suuji[j];
suuji[j] = suuji[j + 1];
suuji[j + 1] = temp;
}
}
}
/* for(int i=0;i<kazu;i++){
WriteLine(suuji[i]);
}*/
int a = int.Parse(input[1]);
int ans = 0;
for (int i = 0; i < kazu; i++) {
// WriteLine("a{0}",a);
if (suuji[i] <= a) {
a -= suuji[i];
ans++;
}
}
// WriteLine("aa{0}",a);
if (ans == kazu && a > 0) {
ans--;
// WriteLine("ddd");
}
WriteLine(ans);
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 68], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 257
| 19
|
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
class Program {
const long mod = 1000000007;
// public static int[] max;
struct Point {
public int x;
public int y;
public Point(int b, int c) {
x = b;
y = c;
}
}
static void Main(string[] args) {
char[] cs = new char[] { ' ', ',' };
// int val = int.Parse(Console.ReadLine());
// int[] vals = parseAry(Console.ReadLine().Split(cs));
// string str = Console.ReadLine();
// string[] strs = Console.ReadLine().Split(cs);
// string res="";
// int res = 0; ;
// int t = int.Parse(Console.ReadLine());
// string str = Console.ReadLine();
/// int[] vals = parseAry(Console.ReadLine().Split(cs));
// int n = int.Parse(Console.ReadLine());
// int num = vals[0];
int[] vals = parseAry(Console.ReadLine().Split(cs));
int[] chil = parseAry(Console.ReadLine().Split(cs));
int res = 0;
Array.Sort(chil);
for (int i = 0; i < vals[0]; i++) {
if (vals[1] >= chil[i]) {
vals[1] -= chil[i];
res++;
}
}
if (vals[1] > 0) {
res--;
}
if (res < 0) {
res = 0;
}
Console.WriteLine(res);
return;
}
// String[] -----> int[]
static int[] parseAry(string[] str) {
int[] nums = new int[str.Length];
for (int i = 0; i < str.Length; i++) {
nums[i] = int.Parse(str[i]);
}
return nums;
}
// String[] -----> long[]
static long[] parseAryL(string[] str) {
long[] nums = new long[str.Length];
for (int i = 0; i < str.Length; i++) {
nums[i] = long.Parse(str[i]);
}
return nums;
}
//文字列を1文字ずつString[]に入れる
static string[] strAry(String str) {
string[] re = new string[str.Length];
for (int i = 0; i < str.Length; i++) {
re[i] = str[i].ToString();
}
return re;
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
class Program {
const long mod = 1000000007;
// public static int[] max;
struct Point {
public int x;
public int y;
public Point(int b, int c) {
x = b;
y = c;
}
}
static void Main(string[] args) {
char[] cs = new char[] { ' ', ',' };
// int val = int.Parse(Console.ReadLine());
// int[] vals = parseAry(Console.ReadLine().Split(cs));
// string str = Console.ReadLine();
// string[] strs = Console.ReadLine().Split(cs);
// string res="";
// int res = 0; ;
// int t = int.Parse(Console.ReadLine());
// string str = Console.ReadLine();
/// int[] vals = parseAry(Console.ReadLine().Split(cs));
// int n = int.Parse(Console.ReadLine());
// int num = vals[0];
int[] vals = parseAry(Console.ReadLine().Split(cs));
int[] chil = parseAry(Console.ReadLine().Split(cs));
int res = 0;
Array.Sort(chil);
for (int i = 0; i < vals[0]; i++) {
if (vals[1] >= chil[i]) {
vals[1] -= chil[i];
res++;
}
}
if (res == vals[0] && vals[1] > 0) {
res--;
}
if (res < 0) {
res = 0;
}
Console.WriteLine(res);
return;
}
// String[] -----> int[]
static int[] parseAry(string[] str) {
int[] nums = new int[str.Length];
for (int i = 0; i < str.Length; i++) {
nums[i] = int.Parse(str[i]);
}
return nums;
}
// String[] -----> long[]
static long[] parseAryL(string[] str) {
long[] nums = new long[str.Length];
for (int i = 0; i < str.Length; i++) {
nums[i] = long.Parse(str[i]);
}
return nums;
}
//文字列を1文字ずつString[]に入れる
static string[] strAry(String str) {
string[] re = new string[str.Length];
for (int i = 0; i < str.Length; i++) {
re[i] = str[i].ToString();
}
return re;
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22]]
| 8
| 420
| 7
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Atcoder {
class Program {
public static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int x = int.Parse(input[1]);
string[] childs = Console.ReadLine().Split(' ');
int[] childsInt = new int[childs.Length];
for (int i = 0; i < childs.Length; i++) {
childsInt[i] = int.Parse(childs[i]);
}
Array.Sort(childsInt);
int num = 0;
for (int i = 0; i < N; i++) {
if (childsInt[i] <= x) {
num++;
x = x - childsInt[i];
} else {
Console.WriteLine(num);
return;
}
}
Console.WriteLine(num - 1);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Atcoder {
class Program {
public static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int x = int.Parse(input[1]);
string[] childs = Console.ReadLine().Split(' ');
int[] childsInt = new int[childs.Length];
for (int i = 0; i < childs.Length; i++) {
childsInt[i] = int.Parse(childs[i]);
}
Array.Sort(childsInt);
int num = 0;
for (int i = 0; i < N; i++) {
if (childsInt[i] <= x) {
num++;
x = x - childsInt[i];
} else {
Console.WriteLine(num);
return;
}
}
if (x != 0) {
Console.WriteLine(num - 1);
} else {
Console.WriteLine(num);
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 215
| 18
|
using System;
using System.Linq;
namespace AGC027_A {
class Program {
static void Main(string[] args) {
var Nx = Console.ReadLine().Split().Select(int.Parse).ToArray();
var N = Nx[0];
var x = Nx[1];
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(a);
var c = 0;
foreach (var ai in a) {
if (x - ai >= 0) {
c++;
x -= ai;
}
}
Console.WriteLine(c);
}
}
}
|
using System;
using System.Linq;
namespace AGC027_A {
class Program {
static void Main(string[] args) {
var Nx = Console.ReadLine().Split().Select(int.Parse).ToArray();
var N = Nx[0];
var x = Nx[1];
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(a);
var c = 0;
foreach (var ai in a) {
if (x - ai >= 0) {
c++;
x -= ai;
}
}
if (c == N && x > 0) {
c--;
}
Console.WriteLine(c);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 68], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 136
| 15
|
using System;
using System.Linq;
namespace agc027_a {
class Program {
static void Main(string[] args) {
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(a);
int ret = 0;
for (int i = 0; i < x[0] && x[1] >= a[i]; i++) {
x[1] -= a[i];
ret++;
}
Console.WriteLine(ret);
}
}
}
|
using System;
using System.Linq;
namespace agc027_a {
class Program {
static void Main(string[] args) {
long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
Array.Sort(a);
int ret = 0;
for (int i = 0; i < x[0] && x[1] >= a[i]; i++) {
x[1] -= a[i];
ret++;
}
if (ret == x[0] && x[1] > 0)
ret--;
Console.WriteLine(ret);
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 68], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 140
| 27
|
using System;
namespace ABC109A {
class Program {
static void Main(string[] args) {
int a, b;
string[] ss = Console.ReadLine().Split(' ');
a = int.Parse(ss[0]);
b = int.Parse(ss[1]);
if (a * b % 2 == 0)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
Console.ReadKey();
}
}
}
|
using System;
namespace ABC109A {
class Program {
static void Main(string[] args) {
int a, b;
string[] ss = Console.ReadLine().Split(' ');
a = int.Parse(ss[0]);
b = int.Parse(ss[1]);
if (a * b % 2 == 0)
Console.WriteLine("No");
else
Console.WriteLine("Yes");
Console.ReadKey();
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 104
| 4
|
using System;
namespace ABC026A {
class Program {
static void Main(string[] args) {
int a, b;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
// c = int.Parse(word[2]);
if (a * b % 2 == 0 || a * b == 9)
Console.WriteLine("No");
else
Console.WriteLine("Yes");
Console.ReadKey();
}
}
}
|
using System;
namespace ABC026A {
class Program {
static void Main(string[] args) {
int a, b, c;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
// c = int.Parse(word[2]);
if (a % 2 != 0 && b % 2 != 0)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
Console.ReadKey();
}
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 48], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 48], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 109
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
var n = int.Parse(Console.ReadLine());
var ans = true;
var old = new HashSet<string>();
var lastWord = Console.ReadLine();
for (var i = 1; i < n && ans; ++i) {
var newyork = Console.ReadLine();
if (old.Contains(newyork) || newyork.First() != lastWord.Last()) {
ans = false;
} else {
old.Add(newyork);
lastWord = newyork;
}
}
Console.WriteLine(ans ? "Yes" : "No");
//デバッグ実行での確認用。そのまま提出しても問題なし
Console.ReadKey();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
var n = int.Parse(Console.ReadLine());
var ans = true;
var lastWord = Console.ReadLine();
var old = new HashSet<string>();
old.Add(lastWord);
for (var i = 1; i < n && ans; ++i) {
var newyork = Console.ReadLine();
if (old.Contains(newyork) || newyork.First() != lastWord.Last()) {
ans = false;
} else {
old.Add(newyork);
lastWord = newyork;
}
}
Console.WriteLine(ans ? "Yes" : "No");
//デバッグ実行での確認用。そのまま提出しても問題なし
Console.ReadKey();
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 155
| 17
|
using System;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
bool Ans = true;
var N = int.Parse(System.Console.ReadLine());
var Word = new string[N + 1];
var Wordlength = new int[N + 1];
var WordF = new string[N + 1];
var WordE = new string[N + 1];
for (int h = 1; h <= N; h++) {
Word[h] = Console.ReadLine();
Wordlength[h] = Word[h].Length;
WordF[h] = Word[h].Substring(0, 1);
WordE[h] = Word[h].Substring(Wordlength[h] - 1);
if (h >= 2) {
if (WordE[h - 1] != WordF[h]) {
Ans = false;
}
}
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (i != j) {
if (Word[i] == Word[j]) {
Ans = false;
Console.WriteLine("Hey1");
}
}
}
}
if (Ans == true) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
bool Ans = true;
var N = int.Parse(System.Console.ReadLine());
var Word = new string[N + 1];
var Wordlength = new int[N + 1];
var WordF = new string[N + 1];
var WordE = new string[N + 1];
for (int h = 1; h <= N; h++) {
Word[h] = Console.ReadLine();
Wordlength[h] = Word[h].Length;
WordF[h] = Word[h].Substring(0, 1);
WordE[h] = Word[h].Substring(Wordlength[h] - 1);
if (h >= 2) {
if (WordE[h - 1] != WordF[h]) {
Ans = false;
}
}
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (i != j) {
if (Word[i] == Word[j]) {
Ans = false;
}
}
}
}
if (Ans == true) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 287
| 9
|
using System;
using System.Linq;
class Program {
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] w = new string[n];
w[0] = Console.ReadLine();
for (int i = 1; i < n; i++) {
w[i] = Console.ReadLine();
if (w.Where(x => x == w[i]).Count() != 1 &&
w[i].Substring(0, 1) == w[i - 1].Substring(w[i - 1].Count() - 1, 1)) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
|
using System;
using System.Linq;
class Program {
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] w = new string[n];
w[0] = Console.ReadLine();
for (int i = 1; i < n; i++) {
w[i] = Console.ReadLine();
if (w.Where(x => x == w[i]).Count() != 1 ||
w[i - 1].Substring(w[i - 1].Length - 1, 1) != w[i].Substring(0, 1)) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 12, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["-", 15, 16, 12, 16, 31, 213, 3, 4, 0, 21], ["-", 15, 16, 12, 16, 31, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 15, 16, 12, 16, 12, 213, 63, 214, 141, 22], ["-", 15, 16, 12, 16, 12, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 15, 16, 12, 16, 31, 213, 3, 4, 0, 21], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 15, 16, 12, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 12, 16, 12, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 168
| 26
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder.ABC109.B {
class Program {
static void Main() {
var sc = new Scanner();
var n = sc.Nextint();
var w = Enumerable.Range(0, n).Select(i => sc.Next()).ToArray();
var set = new HashSet<string>();
for (int i = 0; i < n - 1; i++) {
if (set.Contains(w[i]) || w[i].Last() != w[i + 1].First()) {
Console.WriteLine("No");
return;
}
set.Add(w[i]);
}
Console.WriteLine("Yes");
}
}
class Scanner {
string[] s;
long i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return Next();
i = 0;
return s[i++];
}
public int Nextint() { return int.Parse(Next()); }
public int[] Arrayint(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Nextint() + add;
}
return Array;
}
public long NextLong() { return long.Parse(Next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (long i = 0; i < N; i++) {
Array[i] = NextLong() + add;
}
return Array;
}
public double NextDouble() { return double.Parse(Next()); }
public double[] ArrayDouble(long N, double add = 0) {
double[] Array = new double[N];
for (long i = 0; i < N; i++) {
Array[i] = NextDouble() + add;
}
return Array;
}
public decimal NextDecimal() { return decimal.Parse(Next()); }
public decimal[] ArrayDecimal(long N, decimal add = 0) {
decimal[] Array = new decimal[N];
for (long i = 0; i < N; i++) {
Array[i] = NextDecimal();
}
return Array;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder.ABC109.B {
class Program {
static void Main() {
var sc = new Scanner();
var n = sc.Nextint();
var w = Enumerable.Range(0, n).Select(i => sc.Next()).ToArray();
var usedSet = new HashSet<string>();
usedSet.Add(w[0]);
for (int i = 1; i < n; i++) {
if (usedSet.Contains(w[i]) || w[i - 1].Last() != w[i].First()) {
Console.WriteLine("No");
return;
}
usedSet.Add(w[i]);
}
Console.WriteLine("Yes");
}
}
class Scanner {
string[] s;
long i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return Next();
i = 0;
return s[i++];
}
public int Nextint() { return int.Parse(Next()); }
public int[] Arrayint(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Nextint() + add;
}
return Array;
}
public long NextLong() { return long.Parse(Next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (long i = 0; i < N; i++) {
Array[i] = NextLong() + add;
}
return Array;
}
public double NextDouble() { return double.Parse(Next()); }
public double[] ArrayDouble(long N, double add = 0) {
double[] Array = new double[N];
for (long i = 0; i < N; i++) {
Array[i] = NextDouble() + add;
}
return Array;
}
public decimal NextDecimal() { return decimal.Parse(Next()); }
public decimal[] ArrayDecimal(long N, decimal add = 0) {
decimal[] Array = new decimal[N];
for (long i = 0; i < N; i++) {
Array[i] = NextDecimal();
}
return Array;
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22]]
| 8
| 615
| 24
|
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;
var words = cin.ReadStrArray(n);
var already = new HashSet<string>();
for (var i = 1; i < words.Length; i++) {
var current = words[i];
var previous = words[i - 1];
if (!already.Add(current) || current.First() != previous.Last()) {
WriteLine("No");
return;
}
}
WriteLine("Yes");
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var n = cin.ReadInt;
var words = cin.ReadStrArray(n);
for (var i = 1; i < words.Length; i++) {
var current = words[i];
var previous = words[i - 1];
if (words.Take(i - 1).Contains(current) ||
current.First() != previous.Last()) {
WriteLine("No");
return;
}
}
WriteLine("Yes");
}
}
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;
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["-", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 18], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 57, 15, 16, 31, 241, 0, 111], ["-", 15, 16, 31, 241, 0, 213, 63, 214, 205, 22], ["+", 31, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 15, 16, 31, 241, 0, 213, 63, 214, 141, 22], ["+", 31, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 31, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 205, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 31, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22]]
| 8
| 528
| 23
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Atcoder {
public class Program {
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
var words = new List<string>();
for (int i = 0; i < n; i++) {
words.Add(Console.ReadLine());
if (i != 0) {
string last = words[i - 1].Substring(words[i - 1].Length - 1);
string top = words[i].Substring(0, 1);
if (words.IndexOf(words[i]) != -1 || last != top) {
Console.WriteLine("No");
return;
}
}
}
Console.WriteLine("Yes");
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Atcoder {
public class Program {
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
var words = new List<string>();
for (int i = 0; i < n; i++) {
words.Add(Console.ReadLine());
if (i != 0) {
string last = words[i - 1].Substring(words[i - 1].Length - 1, 1);
string top = words[i].Substring(0, 1);
for (int j = 0; j < words.Count - 1; j++) {
if (words[j] == words[i] || last != top) {
Console.WriteLine("No");
return;
}
}
}
}
Console.WriteLine("Yes");
}
}
}
|
[["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 88], ["+", 0, 57, 64, 196, 0, 7, 10, 198, 39, 199], ["+", 64, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 35], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 18], ["-", 15, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 7, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 64, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 64, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 25], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 45], ["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["-", 0, 57, 15, 16, 31, 16, 12, 241, 0, 33], ["-", 0, 57, 15, 16, 31, 16, 12, 241, 0, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 176
| 31
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var words = new HashSet<string>();
string previousWord = null;
var output = "Yes";
for (int i = 0; i < n; i++) {
var word = Console.ReadLine();
if (!words.Add(word)) {
output = "No";
}
if (previousWord == null) {
continue;
}
if (previousWord.Last() != word.First()) {
output = "No";
}
previousWord = word;
}
Console.WriteLine(output);
return;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var words = new HashSet<string>();
string previousWord = null;
var output = "Yes";
for (int i = 0; i < n; i++) {
var word = Console.ReadLine();
if (!words.Add(word)) {
output = "No";
}
if (previousWord != null && previousWord.Last() != word.First()) {
output = "No";
}
previousWord = word;
}
Console.WriteLine(output);
return;
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 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, 17, 98]]
| 8
| 159
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
class Program {
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
private static void Yes() { print("Yes"); }
private static void No() { print("No"); }
private static void print(object obj) { Console.WriteLine(obj); }
static void Main(string[] args) {
int a = ReadInt();
char s, g;
List<string> list = new List<string>();
bool yes = true;
string befo = Read();
for (int i = 1; i < a; i++) {
string core = Read();
if (core[0] != befo[befo.Length - 1] || list.Contains(core)) {
yes = false;
}
list.Add(core);
befo = core;
}
if (yes) {
Yes();
} else {
No();
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
class Program {
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
private static void Yes() { print("Yes"); }
private static void No() { print("No"); }
private static void print(object obj) { Console.WriteLine(obj); }
static void Main(string[] args) {
int a = ReadInt();
char s, g;
List<string> list = new List<string>();
bool yes = true;
string befo = Read();
list.Add(befo);
for (int i = 1; i < a; i++) {
string core = Read();
if (core[0] != befo[befo.Length - 1] || list.Contains(core)) {
yes = false;
}
list.Add(core);
befo = core;
}
if (yes) {
Yes();
} else {
No();
}
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 364
| 7
|
using System;
using System.Collections.Generic;
namespace abc109_b {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
List<string> list = new List<string>();
string s = Console.ReadLine();
list.Add(s);
bool ret = true;
for (int i = 1; i < n; i++) {
string x = Console.ReadLine();
if (s[s.Length - 1] != x[0])
ret = false;
if (list.Contains(x))
ret = false;
s = x;
}
Console.WriteLine(ret ? "Yes" : "No");
}
}
}
|
using System;
using System.Collections.Generic;
namespace abc109_b {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
List<string> list = new List<string>();
string s = Console.ReadLine();
list.Add(s);
bool ret = true;
for (int i = 1; i < n; i++) {
string x = Console.ReadLine();
if (s[s.Length - 1] != x[0])
ret = false;
if (list.Contains(x))
ret = false;
s = x;
list.Add(x);
}
Console.WriteLine(ret ? "Yes" : "No");
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 155
| 7
|
#pragma warning disable
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;
static class MainClass {
public static void Main() {
var n = Console.ReadLine().ToInt32();
var before = "";
var isOk = true;
var ls = new List<string>();
for (int i = 0; i < n; i++) {
var str = Console.ReadLine();
if (str.First() != before.Last() || ls.Contains(str)) {
isOk = false;
}
ls.Add(str);
before = str;
}
Console.WriteLine(isOk ? "Yes" : "No");
}
#region ライブラリ
#region 二分探索
public static int LowerBound<T>(this IEnumerable<T> ar, int start, int end,
T value, IComparer<T> comparer) {
var arr = ar.ToArray();
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
public static int LowerBound<T>(this IEnumerable<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count(), value, Comparer<T>.Default);
}
public static int UpperBound<T>(this IEnumerable<T> ar, int start, int end,
T value, IComparer<T> comparer) {
var arr = ar.ToArray();
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
public static int UpperBound<T>(this IEnumerable<T> arr, T value) {
return UpperBound(arr, 0, arr.Count(), value, Comparer<T>.Default);
}
#endregion
#region bit全探索
/// <summary>
/// Bit全探索用のライブラリ
/// </summary>
/// <param name="len">作る配列の長さ(lenが0以下だと(ry)</param>
/// <returns>できた配列</returns>
public static List<List<bool>> CreateBits(int len) {
return CreateBitsPri(new List<List<bool>>(), len, 0);
}
private static List<List<bool>> CreateBitsPri(List<List<bool>> bits, int len,
int count) {
if (count == 0) {
var lss = new List<bool>();
lss.Add(true);
bits.Add(lss);
var lx = new List<bool>();
lx.Add(false);
bits.Add(lx);
count++;
return CreateBitsPri(bits, len, count);
}
if (len - count == 0)
return bits;
count++;
var ls = new List<List<bool>>();
foreach (var item in bits) {
var x = item.ToList();
x.Add(true);
item.Add(false);
ls.Add(item);
ls.Add(x);
}
return CreateBitsPri(ls, len, count);
}
#endregion
#region 文字列処理
public static int ToInt32(this string str) { return int.Parse(str); }
public static List<string> SplittedStringToList(this string str) {
return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
.ToList();
}
public static List<int> SplittedStringToInt32List(this string str) {
return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => int.Parse(x))
.ToList();
}
#endregion
#region エラトステネスの篩
/**
* MIT License
Copyright (c) 2018 gushwell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
**/
public class BoundedBoolArray {
private BitArray _array;
private int _lower;
public BoundedBoolArray(int lower, int upper) {
_array = new BitArray(upper - lower + 1);
_lower = lower;
}
public bool this[int index] {
get { return _array[index - _lower]; }
set { _array[index - _lower] = value; }
}
}
public static IEnumerable<int> GeneratePrimes() {
var primes = new List<int>() { 2, 3 };
foreach (var p in primes)
yield return p;
int ix = 0;
while (true) {
int prime1st = primes[ix];
int prime2nd = primes[++ix];
var lower = prime1st * prime1st;
var upper = prime2nd * prime2nd - 1;
var sieve = new BoundedBoolArray(lower, upper);
foreach (var prime in primes.Take(ix)) {
var start = (int)Math.Ceiling((double)lower / prime) * prime;
for (int index = start; index <= upper; index += prime)
sieve[index] = true;
}
for (int i = lower; i <= upper; i++) {
if (sieve[i] == false) {
primes.Add(i);
yield return i;
}
}
}
}
#endregion
#region DeepClone
public static T DeepClone<T>(this T src) {
using (var memoryStream = new MemoryStream()) {
var binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(memoryStream, src);
memoryStream.Seek(0, SeekOrigin.Begin);
return (T)binaryFormatter.Deserialize(memoryStream);
}
}
#endregion
#region 順列を作るやつ
public static List<List<int>> GeneratePermutations(int n) {
if (n > 14)
throw new ArgumentOutOfRangeException();
var ls = new List<List<int>>();
ls.Add(new List<int>() { 1 });
for (int i = 0; i < n - 1; i++) {
var newls = new List<List<int>>();
ls.ForEach(x => {
var len = x.Count;
for (int j = 0; j <= len; j++) {
var item = x.DeepClone();
item.Insert(j, i + 2);
newls.Add(item);
}
});
ls = newls;
}
return ls;
}
#endregion
#endregion
}
|
#pragma warning disable
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;
static class MainClass {
public static void Main() {
var n = Console.ReadLine().ToInt32();
var before = "";
var isOk = true;
var ls = new List<string>();
for (int i = 0; i < n; i++) {
var str = Console.ReadLine();
if (before != "")
if (str.First() != before.Last() || ls.Contains(str)) {
isOk = false;
}
ls.Add(str);
before = str;
}
Console.WriteLine(isOk ? "Yes" : "No");
}
#region ライブラリ
#region 二分探索
public static int LowerBound<T>(this IEnumerable<T> ar, int start, int end,
T value, IComparer<T> comparer) {
var arr = ar.ToArray();
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
public static int LowerBound<T>(this IEnumerable<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count(), value, Comparer<T>.Default);
}
public static int UpperBound<T>(this IEnumerable<T> ar, int start, int end,
T value, IComparer<T> comparer) {
var arr = ar.ToArray();
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
public static int UpperBound<T>(this IEnumerable<T> arr, T value) {
return UpperBound(arr, 0, arr.Count(), value, Comparer<T>.Default);
}
#endregion
#region bit全探索
/// <summary>
/// Bit全探索用のライブラリ
/// </summary>
/// <param name="len">作る配列の長さ(lenが0以下だと(ry)</param>
/// <returns>できた配列</returns>
public static List<List<bool>> CreateBits(int len) {
return CreateBitsPri(new List<List<bool>>(), len, 0);
}
private static List<List<bool>> CreateBitsPri(List<List<bool>> bits, int len,
int count) {
if (count == 0) {
var lss = new List<bool>();
lss.Add(true);
bits.Add(lss);
var lx = new List<bool>();
lx.Add(false);
bits.Add(lx);
count++;
return CreateBitsPri(bits, len, count);
}
if (len - count == 0)
return bits;
count++;
var ls = new List<List<bool>>();
foreach (var item in bits) {
var x = item.ToList();
x.Add(true);
item.Add(false);
ls.Add(item);
ls.Add(x);
}
return CreateBitsPri(ls, len, count);
}
#endregion
#region 文字列処理
public static int ToInt32(this string str) { return int.Parse(str); }
public static List<string> SplittedStringToList(this string str) {
return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
.ToList();
}
public static List<int> SplittedStringToInt32List(this string str) {
return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => int.Parse(x))
.ToList();
}
#endregion
#region エラトステネスの篩
/**
* MIT License
Copyright (c) 2018 gushwell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
**/
public class BoundedBoolArray {
private BitArray _array;
private int _lower;
public BoundedBoolArray(int lower, int upper) {
_array = new BitArray(upper - lower + 1);
_lower = lower;
}
public bool this[int index] {
get { return _array[index - _lower]; }
set { _array[index - _lower] = value; }
}
}
public static IEnumerable<int> GeneratePrimes() {
var primes = new List<int>() { 2, 3 };
foreach (var p in primes)
yield return p;
int ix = 0;
while (true) {
int prime1st = primes[ix];
int prime2nd = primes[++ix];
var lower = prime1st * prime1st;
var upper = prime2nd * prime2nd - 1;
var sieve = new BoundedBoolArray(lower, upper);
foreach (var prime in primes.Take(ix)) {
var start = (int)Math.Ceiling((double)lower / prime) * prime;
for (int index = start; index <= upper; index += prime)
sieve[index] = true;
}
for (int i = lower; i <= upper; i++) {
if (sieve[i] == false) {
primes.Add(i);
yield return i;
}
}
}
}
#endregion
#region DeepClone
public static T DeepClone<T>(this T src) {
using (var memoryStream = new MemoryStream()) {
var binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(memoryStream, src);
memoryStream.Seek(0, SeekOrigin.Begin);
return (T)binaryFormatter.Deserialize(memoryStream);
}
}
#endregion
#region 順列を作るやつ
public static List<List<int>> GeneratePermutations(int n) {
if (n > 14)
throw new ArgumentOutOfRangeException();
var ls = new List<List<int>>();
ls.Add(new List<int>() { 1 });
for (int i = 0; i < n - 1; i++) {
var newls = new List<List<int>>();
ls.ForEach(x => {
var len = x.Count;
for (int j = 0; j <= len; j++) {
var item = x.DeepClone();
item.Insert(j, i + 2);
newls.Add(item);
}
});
ls = newls;
}
return ls;
}
#endregion
#endregion
}
|
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 5, 0, 62], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 57, 64, 57, 0, 24]]
| 8
| 1,333
| 7
|
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace debug {
class main {
static void Main(string[] args) {
//問題クラスを展開
ProgramC a = new ProgramC();
a.main(); //実行する
}
}
class ProgramA {
public void main() {
//数値入力する
string[] s = Console.ReadLine().Split(' ');
//それぞれの文字列で答えを出す
if ((int.Parse(s[0]) * int.Parse(s[1])) % 2 == 1)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
class ProgramB {
public void main() {
//入力
string input = Console.ReadLine();
int n = int.Parse(input);
string[] num = new string[n];
// char型で読み込み、int型に変換。そこから数を足して、char型に戻す
for (int i = 0; i < n; i++) {
string s = Console.ReadLine();
if (num.Contains(s) == true) {
Console.WriteLine("No");
return;
}
if (i == 0) {
num[0] = s;
} else {
if (num[i - 1][num[i - 1].Length - 1] != s[0]) {
Console.WriteLine("No");
return;
}
num[i] = s;
}
}
Console.WriteLine("Yes");
}
}
class ProgramC {
public void main() {
//入力
string[] input = Console.ReadLine().Split();
long n = long.Parse(input[0]);
long x = long.Parse(input[1]);
string[] s = Console.ReadLine().Split();
long[] a = new long[n];
//
for (int i = 0; i < n; i++)
a[i] = Math.Abs(long.Parse(s[i]) - x);
long ans = gcd(a[0], a[1]);
for (int i = 2; i < n; i++)
ans = gcd(ans, a[i]);
//答え出力
Console.WriteLine(ans);
}
/*最大公約数を求める関数*/
static long gcd(long p, long q) {
if (p < q) {
long temp = p;
p = q;
q = temp;
}
long r = 1;
while (r != 0) {
r = p % q;
p = q;
q = r;
}
return p;
}
}
class ProgramD {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
//後端と辺番号を記録
List<Hen>[] tree = new List<Hen>[n];
for (int i = 0; i < n; i++)
tree[i] = new List<Hen>();
for (int i = 0; i < n - 1; i++) {
string[] s = Console.ReadLine().Split();
tree[int.Parse(s[0]) - 1].Add(new Hen(int.Parse(s[1]) - 1, i));
}
int[] ans = new int[n]; //辺i番目の色
int[] memo = new int[n]; //後端をiとしたときについている辺の番号
int K = 0;
Queue<int> q = new Queue<int>();
q.Enqueue(0);
// BFSを行う
while (q.Count != 0) {
int num = q.Count;
for (int i = 0; i < num; i++) {
int temp = q.Dequeue();
int count = 1;
//前の辺の番号を気にしながら辺番号を決める
foreach (var t in tree[temp]) {
//もし前の辺がすでに使っている番号なら飛ばす
if (memo[temp] == count)
count++;
ans[t.b] = count; //答に入れる
memo[t.a] = count; //辺の関係を記録しておく
q.Enqueue(t.a); //下に伝播する
count++;
}
K = Math.Max(K, count - 1); //必要な色の最大値を求める
}
}
//答え出力
Console.WriteLine(K);
for (int i = 0; i < n - 1; i++)
Console.WriteLine(ans[i]);
}
}
class Hen {
public int a;
public int b;
public Hen(int a, int b) {
this.a = a;
this.b = b;
}
}
}
|
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace debug {
class main {
static void Main(string[] args) {
//問題クラスを展開
ProgramC a = new ProgramC();
a.main(); //実行する
}
}
class ProgramA {
public void main() {
//数値入力する
string[] s = Console.ReadLine().Split(' ');
//それぞれの文字列で答えを出す
if ((int.Parse(s[0]) * int.Parse(s[1])) % 2 == 1)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
class ProgramB {
public void main() {
//入力
string input = Console.ReadLine();
int n = int.Parse(input);
string[] num = new string[n];
// char型で読み込み、int型に変換。そこから数を足して、char型に戻す
for (int i = 0; i < n; i++) {
string s = Console.ReadLine();
if (num.Contains(s) == true) {
Console.WriteLine("No");
return;
}
if (i == 0) {
num[0] = s;
} else {
if (num[i - 1][num[i - 1].Length - 1] != s[0]) {
Console.WriteLine("No");
return;
}
num[i] = s;
}
}
Console.WriteLine("Yes");
}
}
class ProgramC {
public void main() {
//入力
string[] input = Console.ReadLine().Split();
long n = long.Parse(input[0]);
long x = long.Parse(input[1]);
string[] s = Console.ReadLine().Split();
long[] a = new long[n];
//
for (int i = 0; i < n; i++)
a[i] = Math.Abs(long.Parse(s[i]) - x);
if (n == 1) {
Console.WriteLine(a[0]);
return;
}
long ans = gcd(a[0], a[1]);
for (int i = 2; i < n; i++)
ans = gcd(ans, a[i]);
//答え出力
Console.WriteLine(ans);
}
/*最大公約数を求める関数*/
static long gcd(long p, long q) {
if (p < q) {
long temp = p;
p = q;
q = temp;
}
long r = 1;
while (r != 0) {
r = p % q;
p = q;
q = r;
}
return p;
}
}
class ProgramD {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
//後端と辺番号を記録
List<Hen>[] tree = new List<Hen>[n];
for (int i = 0; i < n; i++)
tree[i] = new List<Hen>();
for (int i = 0; i < n - 1; i++) {
string[] s = Console.ReadLine().Split();
tree[int.Parse(s[0]) - 1].Add(new Hen(int.Parse(s[1]) - 1, i));
}
int[] ans = new int[n]; //辺i番目の色
int[] memo = new int[n]; //後端をiとしたときについている辺の番号
int K = 0;
Queue<int> q = new Queue<int>();
q.Enqueue(0);
// BFSを行う
while (q.Count != 0) {
int num = q.Count;
for (int i = 0; i < num; i++) {
int temp = q.Dequeue();
int count = 1;
//前の辺の番号を気にしながら辺番号を決める
foreach (var t in tree[temp]) {
//もし前の辺がすでに使っている番号なら飛ばす
if (memo[temp] == count)
count++;
ans[t.b] = count; //答に入れる
memo[t.a] = count; //辺の関係を記録しておく
q.Enqueue(t.a); //下に伝播する
count++;
}
K = Math.Max(K, count - 1); //必要な色の最大値を求める
}
}
//答え出力
Console.WriteLine(K);
for (int i = 0; i < n - 1; i++)
Console.WriteLine(ans[i]);
}
}
class Hen {
public int a;
public int b;
public Hen(int a, int b) {
this.a = a;
this.b = b;
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 918
| 20
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class ACCEPTED {
public void Solve() {
var o = Longm;
var N = (int)o[0];
var X = o[1];
var x = Longm;
Array.Sort(x);
var b = Enumerable.Range(0, N - 1).Select(i => x[i + 1] - x[i]).ToArray();
var g = -1L;
for (int i = 0; i < N - 1; ++i) {
g = GCD(g, b[i]);
}
for (int i = 0; i < N; ++i) {
if (X <= x[i]) {
g = GCD(g, x[i] - X);
if (i != 0)
g = GCD(g, X - x[i - 1]);
}
}
Write(g);
}
}
public static class Graph {}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const int MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Pow(long i, long N, long MOD = 1000000007) {
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
N >>= 1;
}
return res;
}
public static long GCD(long i, long N) {
if (i > N)
Swap(ref i, ref N);
if (i == -1)
return N;
while (N != 0) {
var r = i % N;
i = N;
N = r;
}
return i;
}
public static long LCM(long i, long N) => i * N / GCD(i, N);
public static long Comb(long N, long R, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = N; i >= N - R + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long N, long R) {
long Nume = 1;
long Deno = 1;
if (R > N - R)
Swap(ref N, ref R);
for (long i = 1; i <= R; ++i) {
Deno *= i;
Nume *= N - i + 1;
}
return Deno / Nume;
}
public static Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public static List<long> DivisorEnumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var ACCEPTED = new ACCEPTED();
ACCEPTED.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strm => Str.Split(' ');
public static long[] Longm => Strm.Select(long.Parse).ToArray();
public static int[] Intm => Strm.Select(int.Parse).ToArray();
public static char[] Charm => Str.ToArray();
public static double[] Doublem => Strm.Select(double.Parse).ToArray();
public static long Long1 => Longm[0];
public static int Int1 => Intm[0];
public static char Char1 => Charm[0];
public static double Double1 => Doublem[0];
public static long[] HorizontalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Horizontalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class ACCEPTED {
public void Solve() {
var o = Longm;
var N = (int)o[0];
var X = o[1];
var x = Longm;
Array.Sort(x);
var b = Enumerable.Range(0, N - 1).Select(i => x[i + 1] - x[i]).ToArray();
var g = -1L;
for (int i = 0; i < N - 1; ++i) {
g = GCD(g, b[i]);
}
for (int i = 0; i < N; ++i) {
if (X <= x[i]) {
g = GCD(g, x[i] - X);
if (i != 0)
g = GCD(g, X - x[i - 1]);
}
}
if (N == 1)
g = (Abs(X - x[0]));
Write(g);
}
}
public static class Graph {}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const int MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Pow(long i, long N, long MOD = 1000000007) {
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
N >>= 1;
}
return res;
}
public static long GCD(long i, long N) {
if (i > N)
Swap(ref i, ref N);
if (i == -1)
return N;
while (N != 0) {
var r = i % N;
i = N;
N = r;
}
return i;
}
public static long LCM(long i, long N) => i * N / GCD(i, N);
public static long Comb(long N, long R, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = N; i >= N - R + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long N, long R) {
long Nume = 1;
long Deno = 1;
if (R > N - R)
Swap(ref N, ref R);
for (long i = 1; i <= R; ++i) {
Deno *= i;
Nume *= N - i + 1;
}
return Deno / Nume;
}
public static Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public static List<long> DivisorEnumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var ACCEPTED = new ACCEPTED();
ACCEPTED.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strm => Str.Split(' ');
public static long[] Longm => Strm.Select(long.Parse).ToArray();
public static int[] Intm => Strm.Select(int.Parse).ToArray();
public static char[] Charm => Str.ToArray();
public static double[] Doublem => Strm.Select(double.Parse).ToArray();
public static long Long1 => Longm[0];
public static int Int1 => Intm[0];
public static char Char1 => Charm[0];
public static double Double1 => Doublem[0];
public static long[] HorizontalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Horizontalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 23, 0, 24], ["+", 64, 1, 0, 11, 12, 23, 0, 213, 63, 22], ["+", 0, 11, 12, 23, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 11, 12, 23, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 64, 1, 0, 11, 12, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 1,209
| 20
|
using System;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program {
static string S;
static void Main(string[] args) {
//入力を受け取る
var NX = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
var N = NX[0];
var X = NX[1];
var y = Console.ReadLine()
.Split(' ')
.Select(x => Math.Abs(long.Parse(x) - X))
.ToArray();
long res = gcd(y[0], y[1]);
for (int i = 2; i < N; i++) {
res = gcd(res, y[i]);
}
Console.WriteLine(res);
}
static long gcd(long a, long b) {
long res = 1;
if (a < b) {
return gcd(b, a);
}
while (b != 0) {
res = b;
b = a % b;
a = res;
}
return res;
}
}
|
using System;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program {
static void Main(string[] args) {
//入力を受け取る
var NX = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
var N = NX[0];
var X = NX[1];
var y = Console.ReadLine()
.Split(' ')
.Select(x => Math.Abs(long.Parse(x) - X))
.ToArray();
long res = y[0];
for (long i = 1; i < N; i++) {
res = gcd(res, y[i]);
}
Console.WriteLine(res);
}
static long gcd(long a, long b) {
long res = 1;
if (a < b) {
return gcd(b, a);
}
while (b != 0) {
res = b;
b = a % b;
a = res;
}
return res;
}
}
|
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 0, 208, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 235, 8, 201, 0, 195, 0, 251, 0, 115], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 241
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) { A(); }
static void A() {
var NX = ReadSplitInt();
var N = NX[0];
var X = NX[1];
var x = ReadSplitInt();
if (X == 1) {
Println(Abs(X - x[0]));
return;
}
var a = new int[N];
for (int i = 0; i < N; i++) {
a[i] = Abs(X - x[i]);
}
var ans = Gcd(a[0], a[1]);
for (int i = 2; i < N; i++) {
ans = Gcd(a[i], ans);
}
Println(ans);
}
static IEnumerable<int> Range(int start, int stop) {
if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
return new List<int>();
return Enumerable.Range(start, stop - start);
}
static bool IsDigit(string str) {
var i = 0;
return int.TryParse(str, out i);
}
static int DigitsSum(long num) {
return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
}
static int[] ToIntArray(string str) {
return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
}
static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);
static bool IsPrime(int x) {
if (x <= 1 || (x != 2 && x % 2 == 0))
return false;
if (x == 2)
return true;
for (int i = 3; i < x; i += 2)
if (x % i == 0)
return false;
return true;
}
static string Read() => Console.ReadLine();
static int ReadInt() => int.Parse(Read());
static long ReadLong() => long.Parse(Read());
static List<string> ReadSplit() => Read().Split().ToList();
static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
static List<long>
ReadSplitLong() => Read().Split().Select(long.Parse).ToList();
static void Print(object value) => Console.Write(value.ToString());
static void Println(object value) => Console.WriteLine(value.ToString());
static string Join<T>(IEnumerable<T> list) => string.Join("", list);
}
public static class MyExtensions {
public static string Slice(this string str, int start = 0, int stop = 0) {
if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
return "";
if (stop == 0)
stop = str.Length;
return str.Substring(start, stop - start);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) { A(); }
static void A() {
var NX = ReadSplitInt();
var N = NX[0];
var X = NX[1];
var x = ReadSplitInt();
var a = new int[N];
for (int i = 0; i < N; i++) {
a[i] = Abs(X - x[i]);
}
var ans = a[0];
for (int i = 1; i < N; i++) {
ans = Gcd(ans, a[i]);
}
Println(ans);
}
static IEnumerable<int> Range(int start, int stop) {
if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
return new List<int>();
return Enumerable.Range(start, stop - start);
}
static bool IsDigit(string str) {
var i = 0;
return int.TryParse(str, out i);
}
static int DigitsSum(long num) {
return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
}
static int[] ToIntArray(string str) {
return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
}
static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);
static bool IsPrime(int x) {
if (x <= 1 || (x != 2 && x % 2 == 0))
return false;
if (x == 2)
return true;
for (int i = 3; i < x; i += 2)
if (x % i == 0)
return false;
return true;
}
static string Read() => Console.ReadLine();
static int ReadInt() => int.Parse(Read());
static long ReadLong() => long.Parse(Read());
static List<string> ReadSplit() => Read().Split().ToList();
static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
static List<long>
ReadSplitLong() => Read().Split().Select(long.Parse).ToList();
static void Print(object value) => Console.Write(value.ToString());
static void Println(object value) => Console.WriteLine(value.ToString());
static string Join<T>(IEnumerable<T> list) => string.Join("", list);
}
public static class MyExtensions {
public static string Slice(this string str, int start = 0, int stop = 0) {
if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
return "";
if (stop == 0)
stop = str.Length;
return str.Substring(start, stop - start);
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 700
| 37
|
using System;
class Program {
static void Main(string[] args) {
var t = Read(2);
var n = t[0];
var f = t[1];
var x = Read(n);
for (int i = 0; i < n; i++) {
x[i] -= f;
}
Write(gcd(x));
}
static void Write(string s) {
Console.WriteLine(s);
return;
}
static void Write(long n) {
Console.WriteLine(n.ToString());
return;
}
static string ReadStr() { return Console.ReadLine(); }
static string[] ReadStrs() { return Console.ReadLine().Split(' '); }
static long Read() { return long.Parse(Console.ReadLine()); }
static long[] Read(long n) {
long[] p = new long[n];
string[] t = Console.ReadLine().Split(' ');
for (long i = 0; i < n; i++) {
p[i] = long.Parse(t[i]);
}
return p;
}
static long abs(long n) { return (n > 0) ? n : -n; }
static long gcd(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = gcd(p, n[i]);
}
return p;
}
static long gcd(long a, long b) { return (a == 0) ? b : gcd(b % a, a); }
static long lcm(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = lcm(p, n[i]);
}
return p;
}
static long lcm(long a, long b) { return a * b / gcd(a, b); }
static long max(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = (p > n[i]) ? p : n[i];
}
return p;
}
static long min(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = (p < n[i]) ? p : n[i];
}
return p;
}
static void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
static void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
static void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
static string clip(string s, int start, int count) {
if (start + count < s.Length) {
s = s.Remove(start + count);
}
if (start > 0) {
s = s.Remove(0, start);
}
return s;
}
static long ConvToLong(string n, int b) {
long m = 0;
long t = 1;
for (int i = n.Length - 1; i >= 0; i--) {
int k = int.Parse(n[i].ToString());
m += t * k;
t *= b;
}
return m;
}
}
|
using System;
class Program {
static void Main(string[] args) {
var t = Read(2);
var n = t[0];
var f = t[1];
var x = Read(n);
for (int i = 0; i < n; i++) {
x[i] = abs(x[i] - f);
}
Write(gcd(x));
}
static void Write(string s) {
Console.WriteLine(s);
return;
}
static void Write(long n) {
Console.WriteLine(n.ToString());
return;
}
static string ReadStr() { return Console.ReadLine(); }
static string[] ReadStrs() { return Console.ReadLine().Split(' '); }
static long Read() { return long.Parse(Console.ReadLine()); }
static long[] Read(long n) {
long[] p = new long[n];
string[] t = Console.ReadLine().Split(' ');
for (long i = 0; i < n; i++) {
p[i] = long.Parse(t[i]);
}
return p;
}
static long abs(long n) { return (n > 0) ? n : -n; }
static long gcd(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = gcd(p, n[i]);
}
return p;
}
static long gcd(long a, long b) { return (a == 0) ? b : gcd(b % a, a); }
static long lcm(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = lcm(p, n[i]);
}
return p;
}
static long lcm(long a, long b) { return a * b / gcd(a, b); }
static long max(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = (p > n[i]) ? p : n[i];
}
return p;
}
static long min(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = (p < n[i]) ? p : n[i];
}
return p;
}
static void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
static void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
static void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
static string clip(string s, int start, int count) {
if (start + count < s.Length) {
s = s.Remove(start + count);
}
if (start > 0) {
s = s.Remove(0, start);
}
return s;
}
static long ConvToLong(string n, int b) {
long m = 0;
long t = 1;
for (int i = n.Length - 1; i >= 0; i--) {
int k = int.Parse(n[i].ToString());
m += t * k;
t *= b;
}
return m;
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
| 8
| 754
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
// using System.Numerics;
using static System.Math;
using static System.Console;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var a = ri;
var b = ri;
if (n == 1)
Console.WriteLine("Hello World");
else
Console.WriteLine(a + b);
}
const long INF = 1L << 60;
static int[] dx = { -1, 0, 1, 0 };
static int[] dy = { 0, 1, 0, -1 };
int ri {
get { return sc.Integer(); }
}
long rl {
get { return sc.Long(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public IO.StreamScanner sc =
new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f(i);
return a;
}
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
}
}
#region main
static class Ex {
static public string AsString(this IEnumerable<char> ie) {
return new string(ie.ToArray());
}
static public string AsJoinedString<T>(this IEnumerable<T> ie,
string st = " ") {
return string.Join(st, ie);
}
static public void Main() {
Console.SetOut(new Program.IO.Printer(
Console.OpenStandardOutput()) { AutoFlush = false });
var solver = new Program.Solver();
solver.Solve();
Console.Out.Flush();
}
}
#endregion
#region Ex
namespace Program.IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return 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;
public bool IsEndOfStream {
get { return isEof; }
}
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);
}
}
}
#endregion
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
// using System.Numerics;
using static System.Math;
using static System.Console;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
if (n == 1)
Console.WriteLine("Hello World");
else {
var a = ri;
var b = ri;
Console.WriteLine(a + b);
}
}
const long INF = 1L << 60;
static int[] dx = { -1, 0, 1, 0 };
static int[] dy = { 0, 1, 0, -1 };
int ri {
get { return sc.Integer(); }
}
long rl {
get { return sc.Long(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public IO.StreamScanner sc =
new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f(i);
return a;
}
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
}
}
#region main
static class Ex {
static public string AsString(this IEnumerable<char> ie) {
return new string(ie.ToArray());
}
static public string AsJoinedString<T>(this IEnumerable<T> ie,
string st = " ") {
return string.Join(st, ie);
}
static public void Main() {
Console.SetOut(new Program.IO.Printer(
Console.OpenStandardOutput()) { AutoFlush = false });
var solver = new Program.Solver();
solver.Solve();
Console.Out.Flush();
}
}
#endregion
#region Ex
namespace Program.IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return 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;
public bool IsEndOfStream {
get { return isEof; }
}
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);
}
}
}
#endregion
|
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 866
| 22
|
using System;
using System.IO;
class MainClass {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
string output = "";
string line;
while ((line = Console.ReadLine()) != null) {
string[] tokens = line.Split(' ');
int a = int.Parse(tokens[0]);
switch (a) {
case 1:
output = "Hello World";
break;
case 2:
int outputInt = int.Parse(tokens[1]) + int.Parse(tokens[2]);
output = outputInt.ToString();
break;
}
Console.WriteLine(output);
}
Console.Out.Flush();
}
}
|
using System;
using System.IO;
class MainClass {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
string output = "";
string line;
while ((line = Console.ReadLine()) != null) {
string[] tokens = line.Split(' ');
int a = int.Parse(tokens[0]);
switch (a) {
case 1:
output = "Hello World";
break;
case 2:
int outputInt =
int.Parse(Console.ReadLine()) + int.Parse(Console.ReadLine());
output = outputInt.ToString();
break;
}
Console.WriteLine(output);
}
Console.Out.Flush();
}
}
|
[["-", 31, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 212, 0, 16, 12, 213, 3, 4, 0, 24], ["-", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22]]
| 8
| 159
| 18
|
using System;
namespace _112_1 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int A = int.Parse(Console.ReadLine());
int B = int.Parse(Console.ReadLine());
if (N == 2) {
Console.WriteLine(A + B);
} else {
Console.WriteLine("Hello World");
}
}
}
}
|
using System;
namespace _112_1 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
if (N == 2) {
int A = int.Parse(Console.ReadLine());
int B = int.Parse(Console.ReadLine());
Console.WriteLine(A + B);
} else {
Console.WriteLine("Hello World");
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45]]
| 8
| 93
| 14
|
// A Dynamic Programming based
// C# program to find minimum
// number operations to
// convert str1 to str2
using System;
using System.Collections.Generic;
using System.Linq;
class GFG {
static Dictionary<int, int> ans = new Dictionary<int, int>();
public static void Main() {
var input1 = Console.ReadLine().Split(' ');
var n = int.Parse(input1[0]);
var t = int.Parse(input1[1]);
while (n > 0) {
var input2 = Console.ReadLine().Split(' ');
var c1 = int.Parse(input2[0]);
var t2 = int.Parse(input2[1]);
if (!ans.ContainsKey(c1))
ans.Add(c1, t2);
n--;
}
var minCost = ans.Where(x => x.Value <= t);
if (minCost.Count() == 0)
Console.Write("TLE");
else {
int min = int.MaxValue;
foreach (var p in minCost) {
if (p.Key < min)
min = p.Key;
}
Console.Write(min);
}
}
}
|
// A Dynamic Programming based
// C# program to find minimum
// number operations to
// convert str1 to str2
using System;
using System.Collections.Generic;
using System.Linq;
class GFG {
static Dictionary<int, int> ans = new Dictionary<int, int>();
public static void Main() {
var input1 = Console.ReadLine().Split(' ');
var n = int.Parse(input1[0]);
var t = int.Parse(input1[1]);
while (n > 0) {
var input2 = Console.ReadLine().Split(' ');
var c1 = int.Parse(input2[0]);
var t2 = int.Parse(input2[1]);
if (!ans.ContainsKey(c1))
ans.Add(c1, t2);
else {
var tt = ans[c1];
ans[c1] = Math.Min(tt, t2);
}
n--;
}
var minCost = ans.Where(x => x.Value <= t);
if (minCost.Count() == 0)
Console.Write("TLE");
else {
int min = int.MaxValue;
foreach (var p in minCost) {
if (p.Key < min)
min = p.Key;
}
Console.Write(min);
}
}
}
|
[["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 95], ["+", 0, 52, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["+", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 239
| 25
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class ACCEPTED {
public void Solve() {
var o = Ints;
var N = o[0];
var T = o[1];
int ans = INF;
for (int i = 0; i < N; ++i) {
var x = Ints;
if (x[1] <= T)
ans = Min(ans, x[0]);
}
Write(ans);
}
}
public static class Graph {}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const int MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Pow(long i, long N, long MOD = 1000000007) {
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
N >>= 1;
}
return res;
}
public static long GCD(long i, long N) {
if (i > N)
Swap(ref i, ref N);
if (i == 0)
return N;
while (N != 0) {
var r = i % N;
i = N;
N = r;
}
return i;
}
public static long LCM(long i, long N) => i * N / GCD(i, N);
public static long Comb(long N, long R, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = N; i >= N - R + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long N, long R) {
long Nume = 1;
long Deno = 1;
if (R > N - R)
Swap(ref N, ref R);
for (long i = 1; i <= R; ++i) {
Deno *= i;
Nume *= N - i + 1;
}
return Deno / Nume;
}
public static Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public static List<long> DivisorEnumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var ACCEPTED = new ACCEPTED();
ACCEPTED.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] HorizontalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Horizontalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class ACCEPTED {
public void Solve() {
var o = Ints;
var N = o[0];
var T = o[1];
int ans = INF;
for (int i = 0; i < N; ++i) {
var x = Ints;
if (x[1] <= T)
ans = Min(ans, x[0]);
}
Write(ans == INF ? "TLE" : ans.ToString());
}
}
public static class Graph {}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const int MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Pow(long i, long N, long MOD = 1000000007) {
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
N >>= 1;
}
return res;
}
public static long GCD(long i, long N) {
if (i > N)
Swap(ref i, ref N);
if (i == 0)
return N;
while (N != 0) {
var r = i % N;
i = N;
N = r;
}
return i;
}
public static long LCM(long i, long N) => i * N / GCD(i, N);
public static long Comb(long N, long R, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = N; i >= N - R + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long N, long R) {
long Nume = 1;
long Deno = 1;
if (R > N - R)
Swap(ref N, ref R);
for (long i = 1; i <= R; ++i) {
Deno *= i;
Nume *= N - i + 1;
}
return Deno / Nume;
}
public static Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public static List<long> DivisorEnumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var ACCEPTED = new ACCEPTED();
ACCEPTED.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] HorizontalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Horizontalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 28, 0, 41, 75, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 41, 75, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 41, 75, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 41, 75, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 41, 75, 213, 3, 4, 0, 25]]
| 8
| 1,106
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var firstLine = Console.ReadLine().Split(' ');
var N = int.Parse(firstLine[0]);
var T = int.Parse(firstLine[1]);
Dictionary<int, int> tmpList = new Dictionary<int, int>();
for (int i = 0; i < N; i++) {
var tmp = Console.ReadLine().Split(' ');
var ci = int.Parse(tmp[0]);
var ti = int.Parse(tmp[1]);
if (ti <= T) {
tmpList.Add(ci, ti);
}
}
if (!tmpList.Any()) {
Console.Write("TLE");
} else {
Console.Write(tmpList.Min(x => x.Key));
}
// var result = tmpList.Min(x => x.Value);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var firstLine = Console.ReadLine().Split(' ');
var N = int.Parse(firstLine[0]);
var T = int.Parse(firstLine[1]);
List<int> tmpList = new List<int>();
for (int i = 0; i < N; i++) {
var tmp = Console.ReadLine().Split(' ');
var ci = int.Parse(tmp[0]);
var ti = int.Parse(tmp[1]);
if (ti <= T) {
tmpList.Add(ci);
}
}
if (!tmpList.Any()) {
Console.Write("TLE");
} else {
Console.Write(tmpList.Min());
}
// var result = tmpList.Min(x => x.Value);
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 236, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 236, 141, 22], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 21], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 21], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22]]
| 8
| 221
| 15
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program {
public static Scanner input;
static void Main() {
input = new Scanner();
int[] nt = input.splitInt();
var ct = input.jaggedArrayInt(nt[0]);
var arr = ct.OrderBy(i => i[0]).ToArray();
for (int a = 0; a < nt[0]; a++) {
if (arr[a][1] <= nt[1]) {
WriteLine(arr[a][0]);
break;
}
}
}
static int countChar(string s, string key) {
return s.Length - s.Replace(key, "").Length;
}
}
class Scanner {
public Scanner() {}
public void skip() {
ReadLine();
return;
}
public string String() { return ReadLine(); }
public string[] splitString() { return ReadLine().Split(); }
public string[] linesString(int len) {
var arr = new string[len];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine();
}
return arr;
}
public string[][] jaggedArrayString(int len) {
var arr = new string[len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split();
}
return arr;
}
public int Int() { return int.Parse(ReadLine()); }
public int[] splitInt() {
return ReadLine().Split().Select(i => int.Parse(i)).ToArray();
}
public int[] linesInt(int len) {
var arr = new int[len];
for (int a = 0; a < len; a++) {
arr[a] = int.Parse(ReadLine());
}
return arr;
}
public int[][] jaggedArrayInt(int len) {
var arr = new int [len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split().Select(i => int.Parse(i)).ToArray();
}
return arr;
}
public long Long() { return long.Parse(ReadLine()); }
public long[] splitLong() {
return ReadLine().Split().Select(i => long.Parse(i)).ToArray();
}
public long[] linesLong(int len) {
var arr = new long[len];
for (int a = 0; a < len; a++) {
arr[a] = long.Parse(ReadLine());
}
return arr;
}
public long[][] jaggedArrayLong(int len) {
var arr = new long [len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split().Select(i => long.Parse(i)).ToArray();
}
return arr;
}
public double Double() { return double.Parse(ReadLine()); }
public double[] splitDouble() {
return ReadLine().Split().Select(i => double.Parse(i)).ToArray();
}
public double[] linesDouble(int len) {
var arr = new double[len];
for (int a = 0; a < len; a++) {
arr[a] = double.Parse(ReadLine());
}
return arr;
}
public double[][] jaggedArrayDouble(int len) {
var arr = new double [len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split().Select(i => double.Parse(i)).ToArray();
}
return arr;
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program {
public static Scanner input;
static void Main() {
input = new Scanner();
int[] nt = input.splitInt();
var ct = input.jaggedArrayInt(nt[0]);
var arr = ct.OrderBy(i => i[0]).ToArray();
for (int a = 0; a < nt[0]; a++) {
if (arr[a][1] <= nt[1]) {
WriteLine(arr[a][0]);
return;
}
}
WriteLine("TLE");
}
static int countChar(string s, string key) {
return s.Length - s.Replace(key, "").Length;
}
}
class Scanner {
public Scanner() {}
public void skip() {
ReadLine();
return;
}
public string String() { return ReadLine(); }
public string[] splitString() { return ReadLine().Split(); }
public string[] linesString(int len) {
var arr = new string[len];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine();
}
return arr;
}
public string[][] jaggedArrayString(int len) {
var arr = new string[len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split();
}
return arr;
}
public int Int() { return int.Parse(ReadLine()); }
public int[] splitInt() {
return ReadLine().Split().Select(i => int.Parse(i)).ToArray();
}
public int[] linesInt(int len) {
var arr = new int[len];
for (int a = 0; a < len; a++) {
arr[a] = int.Parse(ReadLine());
}
return arr;
}
public int[][] jaggedArrayInt(int len) {
var arr = new int [len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split().Select(i => int.Parse(i)).ToArray();
}
return arr;
}
public long Long() { return long.Parse(ReadLine()); }
public long[] splitLong() {
return ReadLine().Split().Select(i => long.Parse(i)).ToArray();
}
public long[] linesLong(int len) {
var arr = new long[len];
for (int a = 0; a < len; a++) {
arr[a] = long.Parse(ReadLine());
}
return arr;
}
public long[][] jaggedArrayLong(int len) {
var arr = new long [len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split().Select(i => long.Parse(i)).ToArray();
}
return arr;
}
public double Double() { return double.Parse(ReadLine()); }
public double[] splitDouble() {
return ReadLine().Split().Select(i => double.Parse(i)).ToArray();
}
public double[] linesDouble(int len) {
var arr = new double[len];
for (int a = 0; a < len; a++) {
arr[a] = double.Parse(ReadLine());
}
return arr;
}
public double[][] jaggedArrayDouble(int len) {
var arr = new double [len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split().Select(i => double.Parse(i)).ToArray();
}
return arr;
}
}
|
[["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 877
| 9
|
using System;
using System.Collections.Generic;
// using System.Linq;
class Program {
static void Main(string[] args) {
// 入力フェーズ
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int T = int.Parse(input[1]);
int min = 1001;
for (int i = 0; i < N; i++) {
input = Console.ReadLine().Split(' ');
int cost = int.Parse(input[0]);
int time = int.Parse(input[1]);
if (time <= T) {
if (cost < min)
min = cost;
}
}
Console.WriteLine(min);
}
}
|
using System;
using System.Collections.Generic;
// using System.Linq;
class Program {
static void Main(string[] args) {
// 入力フェーズ
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int T = int.Parse(input[1]);
int min = 1001;
for (int i = 0; i < N; i++) {
input = Console.ReadLine().Split(' ');
int cost = int.Parse(input[0]);
int time = int.Parse(input[1]);
if (time <= T) {
if (cost < min)
min = cost;
}
}
if (min == 1001)
Console.WriteLine("TLE");
else
Console.WriteLine(min);
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
| 8
| 158
| 16
|
using System;
public class timeLimit {
public static void Main() {
string[] hoge = Console.ReadLine().Split(' ');
var n = int.Parse(hoge[0]);
var t = int.Parse(hoge[1]);
var min = 100000000000; // minimum cost
for (int i = 0; i < n; i++) {
string[] fuga = Console.ReadLine().Split(' ');
if (int.Parse(fuga[1]) <= t) {
if (int.Parse(fuga[0]) < min) {
min = int.Parse(fuga[0]);
}
} else {
return;
}
}
if (min != 100000000000) {
Console.WriteLine(min);
} else {
Console.WriteLine("TLE");
}
}
}
|
using System;
public class timeLimit {
public static void Main() {
string[] hoge = Console.ReadLine().Split(' ');
var n = int.Parse(hoge[0]);
var t = int.Parse(hoge[1]);
var min = int.MaxValue; // minimum cost
for (int i = 0; i < n; i++) {
string[] fuga = Console.ReadLine().Split(' ');
if (int.Parse(fuga[1]) <= t && int.Parse(fuga[0]) < min) {
min = int.Parse(fuga[0]);
}
}
if (min < int.MaxValue) {
Console.WriteLine(min);
} else {
Console.WriteLine("TLE");
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 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], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 8, 196, 0, 57, 75, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 75, 196, 0, 37, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 205, 199], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22]]
| 8
| 176
| 21
|
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var n = int.Parse(line[0]);
var t = int.Parse(line[1]);
line = Console.ReadLine().Trim().Split(' ');
var ansno = int.Parse(line[0]);
var anst = int.Parse(line[1]);
for (int i = 1; i < n; i++) {
line = Console.ReadLine().Trim().Split(' ');
var a = int.Parse(line[0]);
var b = int.Parse(line[1]);
if (b <= t && b < anst) {
ansno = a;
}
}
if (anst > t)
Console.WriteLine("TLE");
else
Console.WriteLine(ansno);
}
}
|
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var n = int.Parse(line[0]);
var t = int.Parse(line[1]);
line = Console.ReadLine().Trim().Split(' ');
var anscost = 99999999;
var wcost = int.Parse(line[0]);
var wt = int.Parse(line[1]);
if (wt <= t)
anscost = wcost;
for (int i = 1; i < n; i++) {
line = Console.ReadLine().Trim().Split(' ');
var a = int.Parse(line[0]);
var b = int.Parse(line[1]);
if (b <= t && a < anscost) {
anscost = a;
}
}
if (anscost == 99999999)
Console.WriteLine("TLE");
else
Console.WriteLine(anscost);
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 75, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 209
| 33
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ACprac {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int n = int.Parse(str[0]);
int t = int.Parse(str[1]);
int cost = 1000;
string rslt = "TLE";
for (int i = 0; i < n; i++) {
string[] tmp_s = Console.ReadLine().Split(' ');
int tmp_t = int.Parse(tmp_s[1]);
int tmp_c = int.Parse(tmp_s[0]);
if (tmp_t <= t) {
if (cost > tmp_c) {
cost = tmp_c;
rslt = cost.ToString();
}
}
}
Console.WriteLine(rslt);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ACprac {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int n = int.Parse(str[0]);
int t = int.Parse(str[1]);
int cost = 1000;
string rslt = "TLE";
for (int i = 0; i < n; i++) {
string[] tmp_s = Console.ReadLine().Split(' ');
int tmp_t = int.Parse(tmp_s[1]);
int tmp_c = int.Parse(tmp_s[0]);
if (tmp_t <= t) {
rslt = cost.ToString();
if (cost > tmp_c) {
cost = tmp_c;
rslt = cost.ToString();
}
}
}
Console.WriteLine(rslt);
}
}
}
|
[["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 197
| 8
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace LinqTest {
class MainClass {
public static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
var N = int.Parse(input[0]);
var T = int.Parse(input[1]);
var list = new List<int>();
for (int i = 0; i < N; i++) {
var input2 = Console.ReadLine().Split(' ');
var c = int.Parse(input2[0]);
var t = int.Parse(input2[1]);
if (t <= T) {
list.Add(c);
} else {
// list.Add(0);
}
}
if (list == null) {
Console.WriteLine("TLE");
} else {
Console.WriteLine(list.Min());
}
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace LinqTest {
class MainClass {
public static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
var N = int.Parse(input[0]);
var T = int.Parse(input[1]);
var list = new List<int>();
for (int i = 0; i < N; i++) {
var input2 = Console.ReadLine().Split(' ');
var c = int.Parse(input2[0]);
var t = int.Parse(input2[1]);
if (t <= T) {
list.Add(c);
}
}
if (list.Count() == 0) {
Console.WriteLine("TLE");
} else {
Console.WriteLine(list.Min());
}
}
}
}
|
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 215], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 196
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
class B {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int T = int.Parse(input[1]);
int minCost = 1000; // 1000のままだったら場合帰宅できない
for (int i = 1; i <= N; i++) {
string[] forInput = Console.ReadLine().Split(' ');
int ci = int.Parse(forInput[0]);
int ti = int.Parse(forInput[1]);
//時間条件クリア時
if (ti <= T) {
//コストがminCostよりも小さければ代入してやる。
if (ci < minCost) {
minCost = ci;
}
}
}
if (minCost != 1000) {
Console.WriteLine(minCost);
} else {
Console.WriteLine("TLE");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
class B {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int T = int.Parse(input[1]);
int minCost = 1001; // 1001のままだったら場合帰宅できない
for (int i = 1; i <= N; i++) {
string[] forInput = Console.ReadLine().Split(' ');
int ci = int.Parse(forInput[0]);
int ti = int.Parse(forInput[1]);
//時間条件クリア時
if (ti <= T) {
//コストがminCostよりも小さければ代入してやる。
if (ci < minCost) {
minCost = ci;
}
}
}
if (minCost != 1001) {
Console.WriteLine(minCost);
} else if (minCost == 1001) {
Console.WriteLine("TLE");
}
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25]]
| 8
| 205
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long n = sc.NextLong();
List<Tuple<long, long, long>> list = new List<Tuple<long, long, long>>();
long maxH = 0;
long maxX = 0;
long maxY = 0;
for (int i = 0; i < n; i++) {
long x = sc.NextLong();
long y = sc.NextLong();
long h = sc.NextLong();
if (h >= maxH) {
maxH = h;
maxX = x;
maxY = y;
}
list.Add(Tuple.Create(x, y, h));
}
for (long x = 0; x <= 100; x++) {
for (long y = 0; y <= 100; y++) {
long h = maxH + Math.Abs(x - maxX) + +Math.Abs(y - maxY);
bool ok = true;
foreach (var item in list) {
if (item.Item3 !=
h - Math.Abs(x - item.Item1) - Math.Abs(y - item.Item2)) {
ok = false;
break;
}
}
if (ok) {
Console.WriteLine(x + " " + y + " " + h);
return;
}
}
}
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long n = sc.NextLong();
List<Tuple<long, long, long>> list = new List<Tuple<long, long, long>>();
long maxH = 0;
long maxX = 0;
long maxY = 0;
for (int i = 0; i < n; i++) {
long x = sc.NextLong();
long y = sc.NextLong();
long h = sc.NextLong();
if (h >= maxH) {
maxH = h;
maxX = x;
maxY = y;
}
list.Add(Tuple.Create(x, y, h));
}
for (long x = 0; x <= 100; x++) {
for (long y = 0; y <= 100; y++) {
long h = maxH + Math.Abs(x - maxX) + +Math.Abs(y - maxY);
bool ok = true;
foreach (var item in list) {
if (item.Item3 !=
Math.Max(h - Math.Abs(x - item.Item1) - Math.Abs(y - item.Item2),
0)) {
ok = false;
break;
}
}
if (ok) {
Console.WriteLine(x + " " + y + " " + h);
return;
}
}
}
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["+", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 21], ["+", 15, 16, 12, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 600
| 7
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
static void Main(string[] args) {
var n = Read().Int();
var xl = new int[n];
var yl = new int[n];
var hl = new long[n];
for (int i = 0; i < n; i++) {
var r = ReadSplit();
xl[i] = r[0].Int();
yl[i] = r[1].Int();
hl[i] = r[2].Long();
}
var ansH = 0L;
var ansX = 0L;
var ansY = 0L;
for (int x = 0; x <= 100; x++) {
for (int y = 0; y <= 100; y++) {
var h = -1L;
var isOk = true;
for (int i = 0; i < n; i++) {
var tmp = hl[i] + Math.Abs(xl[i] - x) + Math.Abs(yl[i] - y);
if (hl[i] == 0) {
continue;
}
if (h == -1) {
h = tmp;
}
if (h != tmp) {
isOk = false;
break;
}
}
for (int i = 0; i < n; i++) {
if (isOk) {
var tmp = h - Math.Abs(xl[i] - x) - Math.Abs(yl[i] - y);
if (hl[i] - tmp != 0) {
isOk = false;
break;
}
}
}
if (isOk) {
ansH = h;
ansX = x;
ansY = y;
WriteRead(ansX.ToString() + " " + ansY.ToString() + " " +
ansH.ToString());
return;
}
}
}
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
static void Main(string[] args) {
var n = Read().Int();
var xl = new int[n];
var yl = new int[n];
var hl = new long[n];
for (int i = 0; i < n; i++) {
var r = ReadSplit();
xl[i] = r[0].Int();
yl[i] = r[1].Int();
hl[i] = r[2].Long();
}
var ansH = 0L;
var ansX = 0L;
var ansY = 0L;
for (int x = 0; x <= 100; x++) {
for (int y = 0; y <= 100; y++) {
var h = -1L;
var isOk = true;
for (int i = 0; i < n; i++) {
var tmp = hl[i] + Math.Abs(xl[i] - x) + Math.Abs(yl[i] - y);
if (tmp != 0 && hl[i] == 0) {
continue;
}
if (h == -1) {
h = tmp;
}
if (h != tmp) {
isOk = false;
break;
}
}
for (int i = 0; i < n; i++) {
if (isOk) {
var tmp =
Math.Max(h - Math.Abs(xl[i] - x) - Math.Abs(yl[i] - y), 0);
if (hl[i] - tmp != 0) {
isOk = false;
break;
}
}
}
if (isOk) {
ansH = h;
ansX = x;
ansY = y;
WriteRead(ansX.ToString() + " " + ansY.ToString() + " " +
ansH.ToString());
return;
}
}
}
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
[["+", 8, 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], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 744
| 11
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC112C {
class Program {
static void Main(string[] args) {
var N = ReadInt;
long[] x = new long[N];
long[] y = new long[N];
long[] h = new long[N];
for (int i = 0; i < N; i++) {
x[i] = ReadInt;
y[i] = ReadInt;
h[i] = ReadInt;
}
for (int cx = 0; cx < 101; cx++) {
for (int cy = 0; cy < 101; cy++) {
//一個目を使ってHを作成
long H = Math.Abs(x[0] - cx) + Math.Abs(y[0] - cy) + h[0];
bool ok = true;
for (int i = 1; i < N; i++) {
long height =
Math.Max(H - Math.Abs(x[i] - cx) - Math.Abs(y[i] - cy), 0);
if (h[i] != height)
ok = false;
}
if (ok) {
Console.WriteLine(cx + " " + cy + " " + H);
}
}
}
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String ReadNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int ReadInt => int.Parse(ReadNext());
public static long ReadLong => long.Parse(ReadNext());
public static int[] ReadInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] ReadLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
}
static class Debug {
static public void Draw2D(int[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
int[,] map2 = new int[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0;
else if (i == 0)
map2[i, j] = j - 1;
else if (j == 0)
map2[i, j] = i - 1;
else
map2[i, j] = map[i - 1, j - 1];
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j] % 10);
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
public static void Draw1D(int[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
}
}
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC112C {
class Program {
static void Main(string[] args) {
var N = ReadInt;
long[] x = new long[N];
long[] y = new long[N];
long[] h = new long[N];
for (int i = 0; i < N; i++) {
x[i] = ReadInt;
y[i] = ReadInt;
h[i] = ReadInt;
}
for (int cx = 0; cx < 101; cx++) {
for (int cy = 0; cy < 101; cy++) {
//一個目を使ってHを作成
long H = 0;
for (int i = 0; i < N; i++) {
if (h[i] == 0)
continue;
H = Math.Abs(x[i] - cx) + Math.Abs(y[i] - cy) + h[i];
}
bool ok = true;
for (int i = 0; i < N; i++) {
long height =
Math.Max(H - Math.Abs(x[i] - cx) - Math.Abs(y[i] - cy), 0);
if (h[i] != height)
ok = false;
}
if (ok) {
Console.WriteLine(cx + " " + cy + " " + H);
return;
}
}
}
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String ReadNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int ReadInt => int.Parse(ReadNext());
public static long ReadLong => long.Parse(ReadNext());
public static int[] ReadInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] ReadLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
}
static class Debug {
static public void Draw2D(int[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
int[,] map2 = new int[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0;
else if (i == 0)
map2[i, j] = j - 1;
else if (j == 0)
map2[i, j] = i - 1;
else
map2[i, j] = map[i - 1, j - 1];
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j] % 10);
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
public static void Draw1D(int[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
}
}
|
[["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 24], ["+", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 25], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
| 8
| 739
| 41
|
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace debug {
class main {
static void Main(string[] args) {
//問題クラスを展開
ProgramC a = new ProgramC();
a.main(); //実行する
}
}
class ProgramA {
public void main() {
//数値入力する
string[] s = Console.ReadLine().Split(' ');
//それぞれの文字列で答えを出す
if ((int.Parse(s[0]) * int.Parse(s[1])) % 2 == 1)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
class ProgramB {
public void main() {
//入力
string input = Console.ReadLine();
int n = int.Parse(input);
string[] num = new string[n];
// char型で読み込み、int型に変換。そこから数を足して、char型に戻す
for (int i = 0; i < n; i++) {
string s = Console.ReadLine();
if (num.Contains(s) == true) {
Console.WriteLine("No");
return;
}
if (i == 0) {
num[0] = s;
} else {
if (num[i - 1][num[i - 1].Length - 1] != s[0]) {
Console.WriteLine("No");
return;
}
num[i] = s;
}
}
Console.WriteLine("Yes");
}
}
class ProgramC {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
//情報を記録
List<Pos> info = new List<Pos>();
//とりあえず情報を記録する
for (int i = 0; i < n; i++) {
string[] s = Console.ReadLine().Split();
info.Add(new Pos(int.Parse(s[0]), int.Parse(s[1]), long.Parse(s[2])));
}
var info2 = info.OrderByDescending(x => x.c);
//この座標が答として高さを仮定する
for (int i = 0; i <= 100; i++)
for (int j = 0; j <= 100; j++) {
long h = 0;
int x = 0;
int count = 1;
foreach (var f in info2) {
if (x == 0)
h = f.c + Math.Abs(f.a - i) + Math.Abs(f.b - j);
else {
long h2 = h - Math.Abs(f.a - i) - Math.Abs(f.b - j);
if (h2 == f.c)
count++;
}
x++;
}
if (count == n) {
Console.WriteLine(i + " " + j + " " + h);
return;
}
}
}
}
class Pos {
public int a;
public int b;
public long c;
public Pos(int a, int b, long c) {
this.a = a;
this.b = b;
this.c = c;
}
}
class ProgramD {
public void main() {
//入力
string[] input = Console.ReadLine().Split();
long n = long.Parse(input[0]);
long m = long.Parse(input[1]);
long ans = 1;
// 2変数に分離
for (int i = 1; i <= Math.Sqrt(m); i++) {
if (m % i == 0) {
if (m / i >= n) {
ans = Math.Max(ans, i);
if (i >= n)
ans = Math.Max(ans, m / i);
}
}
}
//答え出力
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace debug {
class main {
static void Main(string[] args) {
//問題クラスを展開
ProgramC a = new ProgramC();
a.main(); //実行する
}
}
class ProgramA {
public void main() {
//数値入力する
string[] s = Console.ReadLine().Split(' ');
//それぞれの文字列で答えを出す
if ((int.Parse(s[0]) * int.Parse(s[1])) % 2 == 1)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
class ProgramB {
public void main() {
//入力
string input = Console.ReadLine();
int n = int.Parse(input);
string[] num = new string[n];
// char型で読み込み、int型に変換。そこから数を足して、char型に戻す
for (int i = 0; i < n; i++) {
string s = Console.ReadLine();
if (num.Contains(s) == true) {
Console.WriteLine("No");
return;
}
if (i == 0) {
num[0] = s;
} else {
if (num[i - 1][num[i - 1].Length - 1] != s[0]) {
Console.WriteLine("No");
return;
}
num[i] = s;
}
}
Console.WriteLine("Yes");
}
}
class ProgramC {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
//情報を記録
List<Pos> info = new List<Pos>();
//とりあえず情報を記録する
for (int i = 0; i < n; i++) {
string[] s = Console.ReadLine().Split();
info.Add(new Pos(int.Parse(s[0]), int.Parse(s[1]), long.Parse(s[2])));
}
var info2 = info.OrderByDescending(x => x.c);
//この座標が答として高さを仮定する
for (int i = 0; i <= 100; i++)
for (int j = 0; j <= 100; j++) {
long h = 0;
int x = 0;
int count = 1;
foreach (var f in info2) {
if (x == 0)
h = f.c + Math.Abs(f.a - i) + Math.Abs(f.b - j);
else {
long h2 = h - Math.Abs(f.a - i) - Math.Abs(f.b - j);
if (h2 < 0)
h2 = 0;
if (h2 == f.c)
count++;
}
x++;
}
if (count == n) {
Console.WriteLine(i + " " + j + " " + h);
// return;
}
}
}
}
class Pos {
public int a;
public int b;
public long c;
public Pos(int a, int b, long c) {
this.a = a;
this.b = b;
this.c = c;
}
}
class ProgramD {
public void main() {
//入力
string[] input = Console.ReadLine().Split();
long n = long.Parse(input[0]);
long m = long.Parse(input[1]);
long ans = 1;
// 2変数に分離
for (int i = 1; i <= Math.Sqrt(m); i++) {
if (m % i == 0) {
if (m / i >= n) {
ans = Math.Max(ans, i);
if (i >= n)
ans = Math.Max(ans, m / i);
}
}
}
//答え出力
Console.WriteLine(ans);
}
}
}
|
[["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 75, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
| 8
| 782
| 12
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace C {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var n = int.Parse(Console.ReadLine());
var points = new Point[n];
for (var i = 0; i < points.Length; i++) {
var xyh =
Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
points[i] = new Point { X = xyh[0], Y = xyh[1], H = xyh[2] };
}
for (var cx = 0; cx <= 100; cx++) {
for (var cy = 0; cy <= 100; cy++) {
var h = Math.Abs(points[0].X - cx) + Math.Abs(points[0].Y - cy) +
points[0].H;
var isValid = true;
for (var k = 0; k < points.Length; k++) {
var tmpH = Math.Max(
h - Math.Abs(points[k].X - cx) - Math.Abs(points[k].Y - cy), 0L);
if (points[k].H != tmpH) {
isValid = false;
break;
}
}
if (isValid) {
Console.WriteLine($"{cx} {cy} {h}");
return;
}
}
}
}
public struct Point {
public long X { get; set; }
public long Y { get; set; }
public long H { get; set; }
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace C {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var n = int.Parse(Console.ReadLine());
var points = new Point[n];
var index = 0;
for (var i = 0; i < points.Length; i++) {
var xyh =
Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
points[i] = new Point { X = xyh[0], Y = xyh[1], H = xyh[2] };
if (xyh[2] > 0)
index = i;
}
for (var cx = 0; cx <= 100; cx++) {
for (var cy = 0; cy <= 100; cy++) {
var h = Math.Abs(points[index].X - cx) +
Math.Abs(points[index].Y - cy) + points[index].H;
var isValid = true;
for (var i = 0; i < points.Length; i++) {
var tmpH = Math.Max(
h - Math.Abs(points[i].X - cx) - Math.Abs(points[i].Y - cy), 0L);
if (points[i].H != tmpH) {
isValid = false;
break;
}
}
if (isValid) {
Console.WriteLine($"{cx} {cy} {h}");
return;
}
}
}
}
public struct Point {
public long X { get; set; }
public long Y { get; set; }
public long H { get; set; }
}
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["-", 31, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 31, 214, 205, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 403
| 36
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.