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.Linq;
namespace agc030_a {
class Program {
static void Main(string[] args) {
var text = Console.ReadLine();
var list = text.Split(' ').ToList();
var a = int.Parse(list[0]);
var b = int.Parse(list[1]);
if (b <= 5) {
Console.WriteLine("0");
} else if (b >= 6 && b <= 12) {
Console.WriteLine((a / 2).ToString());
} else {
Console.WriteLine(a);
}
}
}
}
|
using System;
using System.Linq;
namespace agc030_a {
class Program {
static void Main(string[] args) {
var text = Console.ReadLine();
var list = text.Split(' ').ToList();
var b = int.Parse(list[0]);
var a = int.Parse(list[1]);
if (b <= 5) {
Console.WriteLine("0");
} else if (b >= 6 && b <= 12) {
Console.WriteLine((a / 2).ToString());
} else {
Console.WriteLine(a);
}
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22]]
| 8
| 133
| 4
|
using System;
using System.Text;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int r = int.Parse(input[0]);
int D = int.Parse(input[1]);
int xo = int.Parse(input[2]);
int[] xn = new int[11];
xn[0] = xo;
for (int i = 0; i < 11; i++) {
xn[i + 1] = r * xn[i] - D;
}
for (int j = 1; j < 12; j++) {
Console.WriteLine(xn[j]);
}
}
}
|
using System;
using System.Text;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int r = int.Parse(input[0]);
int D = int.Parse(input[1]);
int xo = int.Parse(input[2]);
int[] xn = new int[11];
xn[0] = xo;
for (int i = 0; i < 10; i++) {
xn[i + 1] = r * xn[i] - D;
}
for (int j = 1; j < 11; j++) {
Console.WriteLine(xn[j]);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
| 8
| 156
| 4
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
// var N = long.Parse(Console.ReadLine());
Solve();
}
static string S;
static string T;
static int H;
static int W;
static int N;
static int SH;
static int SW;
static void Solve() {
var HWN = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
H = HWN[0];
W = HWN[1];
N = HWN[2];
var SP = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
SH = SP[0];
SW = SP[1];
S = Console.ReadLine();
T = Console.ReadLine();
var ans = false;
if (IsOkWide() && IsOkHeight()) {
ans = true;
}
Console.WriteLine(ans ? "YES" : "NO");
}
static bool IsOkWide() {
var min = 1;
var max = W;
for (int i = (int)N - 1; i >= 0; i--) {
if (T[i] == 'L') {
max = Min(max + 1, W);
} else if (T[i] == 'R') {
min = Max(min - 1, 1);
}
if (S[i] == 'L') {
min++;
} else if (S[i] == 'R') {
max--;
}
if (min > max) {
return false;
}
}
return (min <= SW) && (SW <= max);
}
static bool IsOkHeight() {
var min = 1;
var max = H;
for (int i = (int)N - 1; i >= 0; i--) {
if (T[i] == 'U') {
max = Min(max + 1, W);
} else if (T[i] == 'D') {
min = Max(min - 1, 1);
}
if (S[i] == 'U') {
min++;
} else if (S[i] == 'D') {
max--;
}
if (min > max) {
return false;
}
}
return (min <= SH) && (SH <= max);
}
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
// var N = long.Parse(Console.ReadLine());
Solve();
}
static string S;
static string T;
static int H;
static int W;
static int N;
static int SH;
static int SW;
static void Solve() {
var HWN = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
H = HWN[0];
W = HWN[1];
N = HWN[2];
var SP = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
SH = SP[0];
SW = SP[1];
S = Console.ReadLine();
T = Console.ReadLine();
var ans = false;
if (IsOkWide() && IsOkHeight()) {
ans = true;
}
Console.WriteLine(ans ? "YES" : "NO");
}
static bool IsOkWide() {
var min = 1;
var max = W;
for (int i = (int)N - 1; i >= 0; i--) {
if (T[i] == 'L') {
max = Min(max + 1, W);
} else if (T[i] == 'R') {
min = Max(min - 1, 1);
}
if (S[i] == 'L') {
min++;
} else if (S[i] == 'R') {
max--;
}
if (min > max) {
return false;
}
}
return (min <= SW) && (SW <= max);
}
static bool IsOkHeight() {
var min = 1;
var max = H;
for (int i = (int)N - 1; i >= 0; i--) {
if (T[i] == 'U') {
max = Min(max + 1, H);
} else if (T[i] == 'D') {
min = Max(min - 1, 1);
}
if (S[i] == 'U') {
min++;
} else if (S[i] == 'D') {
max--;
}
if (min > max) {
return false;
}
}
return (min <= SH) && (SH <= max);
}
}
}
|
[["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 535
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using static Math2;
using static Output;
using static Utils;
public class CP {
Input sc;
public void Solve() {
sc = new Input();
var t = 1;
// var sw = new Stopwatch();
// sw.Start();
while (t-- > 0) {
case1();
}
// sw.Stop();
// Put(sw.ElapsedMilliseconds + "ms");
}
public void case1() {
var H = sc.cin<int>();
var W = sc.cin<int>();
var N = sc.cin<int>();
var Sr = sc.cin<int>();
var Sc = sc.cin<int>();
var S = sc.cin<string>();
var T = sc.cin<string>();
var l = 1;
var r = W;
for (int i = N - 1; i >= 0; --i) {
if (i != N - 1 && T[i] == 'L')
r = Min(r + 1, W);
if (i != N - 1 && T[i] == 'R')
l = Max(l - 1, 1);
if (S[i] == 'L')
l++;
if (S[i] == 'R')
r--;
if (l > r) {
Put("NO");
return;
}
if (Sc < l || Sc > r) {
Put("NO");
return;
}
}
l = 1;
r = H;
for (int i = N - 1; i >= 0; --i) {
if (i != N - 1 && T[i] == 'U')
r = Min(r + 1, H);
if (i != N - 1 && T[i] == 'D')
l = Max(l - 1, 1);
if (S[i] == 'U')
l++;
if (S[i] == 'D')
r--;
if (l > r) {
Put("NO");
return;
}
if (Sr < l || Sr > r) {
Put("NO");
return;
}
}
Put("YES");
return;
}
}
public class BinarySearch {
public static int Lower_Bound<T>(IList<T> Array, T Target) {
return Lower_Bound<T>(Array, Target, Comparer<T>.Default.Compare);
}
public static int Lower_Bound<T>(IList<T> Array, T Target,
Comparison<T> Comp) {
var cmp = Comparer<T>.Create(Comp);
var l = -1; // always ng
var r = Array.Count(); // always ok
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(Array[mid], Target);
if (res >= 0)
r = mid;
else
l = mid;
}
return r;
}
public static int Upper_Bound<T>(IList<T> Array, T Target) {
return Upper_Bound<T>(Array, Target, Comparer<T>.Default.Compare);
}
public static int Upper_Bound<T>(IList<T> Array, T Target,
Comparison<T> Comp) {
var cmp = Comparer<T>.Create(Comp);
var l = -1;
var r = Array.Count;
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(Array[mid], Target);
if (res > 0)
r = mid;
else
l = mid;
}
return r;
}
public static bool Contains<T>(IList<T> Arr, T Target) {
return Contains<T>(Arr, Target, Comparer<T>.Default.Compare);
}
public static bool Contains<T>(IList<T> Arr, T Target, Comparison<T> Comp) {
return (Upper_Bound(Arr, Target, Comp) - Lower_Bound(Arr, Target, Comp) >
0);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const long MOD2 = 998244353;
public static long Power(long a, long b, long MOD = 1000000007) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
public static long Power2(long a, long b) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
public static long GCD(long a, long b) {
if (a == 0)
return b;
while (b > 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static long LCM(long a, long b) => (b / GCD(a, b)) * a;
public static long Comb(long n, long r, int MOD = 1000000007) {
if (r > n - r)
r = n - r;
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno = (Deno * i) % MOD;
Nume = Nume * (n - i + 1) % MOD;
}
return (Nume * inv(Deno)) % MOD;
}
public static long Comb2(long n, long r) {
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno *= i;
Nume *= n - i + 1;
}
return Nume / Deno;
}
public static long inv(long x, int MOD = 1000000007) {
return Power(x, MOD - 2, MOD);
}
}
public static class Utils {
public static int popcnt(long a) {
int cnt = 0;
while (a > 0) {
if ((a & 1) == 1)
++cnt;
a >>= 1;
}
return cnt;
}
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(string N) {
int ret = 0;
for (int i = 0; i < N.Length; ++i)
ret += N[i] - '0';
return ret;
}
public static string ConvertBase(long N, int K) {
StringBuilder ret = new StringBuilder();
while (N > 0) {
var r = N % K;
N /= K;
ret.Append(r);
}
return new string(ret.ToString().ToCharArray().Reverse().ToArray());
}
public static bool NextPermutation<T>(IList<T> lis, Comparison<T> cmp) {
int n = lis.Count;
int i = n - 1;
while (i - 1 >= 0) {
if (cmp(lis[i - 1], lis[i]) < 0)
break;
--i;
}
if (i == 0)
return false;
int j = i;
while (j + 1 < n) {
if (cmp(lis[i - 1], lis[j + 1]) > 0)
break;
++j;
}
var _q = lis[j];
lis[j] = lis[i - 1];
lis[i - 1] = _q;
int k = i;
int l = n - 1;
while (k < l) {
var _p = lis[k];
lis[k] = lis[l];
lis[l] = _p;
++k;
--l;
}
return true;
}
public static bool NextPermutation<T>(IList<T> lis) =>
NextPermutation(lis, Comparer<T>.Default.Compare);
}
public class PriorityQueue<T> {
List<T> _item;
public int Count {
get { return _item.Count; }
}
bool _isascend { get; set; }
public T Peek {
get { return _item[0]; }
}
Comparison<T> Comp;
public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null)
: this(Comparer<T>.Default.Compare, IsAscend, list) {}
public PriorityQueue(Comparison<T> cmp, bool IsAscend = true,
IEnumerable<T> list = null) {
_item = new List<T>();
_isascend = IsAscend;
this.Comp = cmp;
if (list != null) {
_item.AddRange(list);
Build();
}
}
private int Compare(int i, int j) => (_isascend ? -1 : 1) *
Comp(_item[i], _item[j]);
private void Swap(int i, int j) {
var t = _item[i];
_item[i] = _item[j];
_item[j] = t;
}
private int Parent(int i) => (i - 1) >> 1;
private int Left(int i) => (i << 1) + 1;
public T Enqueue(T val) {
int i = _item.Count;
_item.Add(val);
while (i > 0) {
int p = Parent(i);
if (Compare(i, p) > 0)
Swap(i, p);
i = p;
}
return val;
}
private void Heapify(int index) {
for (int i = index, j; (j = Left(i)) < _item.Count; i = j) {
if (j != _item.Count - 1 && Compare(j, j + 1) < 0)
j++;
if (Compare(i, j) < 0)
Swap(i, j);
}
}
public T Dequeue() {
T val = _item[0];
_item[0] = _item[_item.Count - 1];
_item.RemoveAt(_item.Count - 1);
Heapify(0);
return val;
}
private void Build() {
for (var i = (_item.Count >> 1) - 1; i >= 0; i--)
Heapify(i);
}
public bool Any() => Count > 0;
}
class Program {
static void Main(string[] args) {
var CP = new CP();
CP.Solve();
}
}
public static class Output {
public static void Put(string a) => Console.WriteLine(a);
public static void Put(params object[] i) => Put(string.Join(" ", i));
public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a));
public static void PutV<T>(IEnumerable<T> a) {
foreach (var z in a)
Put(z);
}
public static void YN(bool i) {
if (i)
Put("Yes");
else
Put("No");
}
}
public class Input {
public static string Str => Console.ReadLine();
public static bool IsTypeEqual<T, U>() => typeof(T).Equals(typeof(U));
public static T ConvertType<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
public static T Cast<T>(string s) {
if (IsTypeEqual<T, int>())
return ConvertType<T, int>(int.Parse(s));
else if (IsTypeEqual<T, long>())
return ConvertType<T, long>(long.Parse(s));
else if (IsTypeEqual<T, double>())
return ConvertType<T, double>(double.Parse(s));
else if (IsTypeEqual<T, char>())
return ConvertType<T, char>(char.Parse(s));
else
return ConvertType<T, string>(s);
}
public static T[] Castarr<T>(string[] s) {
var ret = new T[s.Length];
int i = 0;
if (IsTypeEqual<T, char>()) {
var list = new List<T>();
foreach (var t in s) {
foreach (var u in t) {
list.Add(ConvertType<T, char>(char.Parse(u.ToString())));
}
}
return list.ToArray();
}
foreach (var t in s) {
if (IsTypeEqual<T, int>())
ret[i++] = ConvertType<T, int>(int.Parse(t));
else if (IsTypeEqual<T, long>())
ret[i++] = ConvertType<T, long>(long.Parse(t));
else if (IsTypeEqual<T, double>())
ret[i++] = ConvertType<T, double>(double.Parse(t));
else
ret[i++] = ConvertType<T, string>(t);
}
return ret;
}
Queue<string> q = new Queue<string>();
void next() {
var ss = Str.Split(' ');
foreach (var item in ss)
q.Enqueue(item);
}
public T cin<T>() {
if (!q.Any())
next();
return Cast<T>(q.Dequeue());
}
public void mul<T>(out T t) { t = cin<T>(); }
public void mul<T, U>(out T t, out U u) {
t = cin<T>();
u = cin<U>();
}
public void mul<T, U, V>(out T t, out U u, out V v) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
}
public void mul<T, U, V, W>(out T t, out U u, out V v, out W w) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
}
public void mul<T, U, V, W, X>(out T t, out U u, out V v, out W w, out X x) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
x = cin<X>();
}
public void mul<T, U, V, W, X, Y>(out T t, out U u, out V v, out W w, out X x,
out Y y) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
x = cin<X>();
y = cin<Y>();
}
public void mul<T, U, V, W, X, Y, Z>(out T t, out U u, out V v, out W w,
out X x, out Y y, out Z z) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
x = cin<X>();
y = cin<Y>();
z = cin<Z>();
}
public T[] cinarr<T>() { return Castarr<T>(Str.Split(' ')); }
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using static Math2;
using static Output;
using static Utils;
public class CP {
Input sc;
public void Solve() {
sc = new Input();
var t = 1;
// var sw = new Stopwatch();
// sw.Start();
while (t-- > 0) {
case1();
}
// sw.Stop();
// Put(sw.ElapsedMilliseconds + "ms");
}
public void case1() {
var H = sc.cin<int>();
var W = sc.cin<int>();
var N = sc.cin<int>();
var Sr = sc.cin<int>();
var Sc = sc.cin<int>();
var S = sc.cin<string>();
var T = sc.cin<string>();
var l = 1;
var r = W;
for (int i = N - 1; i >= 0; --i) {
if (i != N - 1 && T[i] == 'L')
r = Min(r + 1, W);
if (i != N - 1 && T[i] == 'R')
l = Max(l - 1, 1);
if (S[i] == 'L')
l++;
if (S[i] == 'R')
r--;
if (l > r) {
Put("NO");
return;
}
}
if (Sc < l || Sc > r) {
Put("NO");
return;
}
l = 1;
r = H;
for (int i = N - 1; i >= 0; --i) {
if (i != N - 1 && T[i] == 'U')
r = Min(r + 1, H);
if (i != N - 1 && T[i] == 'D')
l = Max(l - 1, 1);
if (S[i] == 'U')
l++;
if (S[i] == 'D')
r--;
if (l > r) {
Put("NO");
return;
}
}
if (Sr < l || Sr > r) {
Put("NO");
return;
}
Put("YES");
}
}
public class BinarySearch {
public static int Lower_Bound<T>(IList<T> Array, T Target) {
return Lower_Bound<T>(Array, Target, Comparer<T>.Default.Compare);
}
public static int Lower_Bound<T>(IList<T> Array, T Target,
Comparison<T> Comp) {
var cmp = Comparer<T>.Create(Comp);
var l = -1; // always ng
var r = Array.Count(); // always ok
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(Array[mid], Target);
if (res >= 0)
r = mid;
else
l = mid;
}
return r;
}
public static int Upper_Bound<T>(IList<T> Array, T Target) {
return Upper_Bound<T>(Array, Target, Comparer<T>.Default.Compare);
}
public static int Upper_Bound<T>(IList<T> Array, T Target,
Comparison<T> Comp) {
var cmp = Comparer<T>.Create(Comp);
var l = -1;
var r = Array.Count;
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(Array[mid], Target);
if (res > 0)
r = mid;
else
l = mid;
}
return r;
}
public static bool Contains<T>(IList<T> Arr, T Target) {
return Contains<T>(Arr, Target, Comparer<T>.Default.Compare);
}
public static bool Contains<T>(IList<T> Arr, T Target, Comparison<T> Comp) {
return (Upper_Bound(Arr, Target, Comp) - Lower_Bound(Arr, Target, Comp) >
0);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const long MOD2 = 998244353;
public static long Power(long a, long b, long MOD = 1000000007) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
public static long Power2(long a, long b) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
public static long GCD(long a, long b) {
if (a == 0)
return b;
while (b > 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static long LCM(long a, long b) => (b / GCD(a, b)) * a;
public static long Comb(long n, long r, int MOD = 1000000007) {
if (r > n - r)
r = n - r;
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno = (Deno * i) % MOD;
Nume = Nume * (n - i + 1) % MOD;
}
return (Nume * inv(Deno)) % MOD;
}
public static long Comb2(long n, long r) {
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno *= i;
Nume *= n - i + 1;
}
return Nume / Deno;
}
public static long inv(long x, int MOD = 1000000007) {
return Power(x, MOD - 2, MOD);
}
}
public static class Utils {
public static int popcnt(long a) {
int cnt = 0;
while (a > 0) {
if ((a & 1) == 1)
++cnt;
a >>= 1;
}
return cnt;
}
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(string N) {
int ret = 0;
for (int i = 0; i < N.Length; ++i)
ret += N[i] - '0';
return ret;
}
public static string ConvertBase(long N, int K) {
StringBuilder ret = new StringBuilder();
while (N > 0) {
var r = N % K;
N /= K;
ret.Append(r);
}
return new string(ret.ToString().ToCharArray().Reverse().ToArray());
}
public static bool NextPermutation<T>(IList<T> lis, Comparison<T> cmp) {
int n = lis.Count;
int i = n - 1;
while (i - 1 >= 0) {
if (cmp(lis[i - 1], lis[i]) < 0)
break;
--i;
}
if (i == 0)
return false;
int j = i;
while (j + 1 < n) {
if (cmp(lis[i - 1], lis[j + 1]) > 0)
break;
++j;
}
var _q = lis[j];
lis[j] = lis[i - 1];
lis[i - 1] = _q;
int k = i;
int l = n - 1;
while (k < l) {
var _p = lis[k];
lis[k] = lis[l];
lis[l] = _p;
++k;
--l;
}
return true;
}
public static bool NextPermutation<T>(IList<T> lis) =>
NextPermutation(lis, Comparer<T>.Default.Compare);
}
public class PriorityQueue<T> {
List<T> _item;
public int Count {
get { return _item.Count; }
}
bool _isascend { get; set; }
public T Peek {
get { return _item[0]; }
}
Comparison<T> Comp;
public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null)
: this(Comparer<T>.Default.Compare, IsAscend, list) {}
public PriorityQueue(Comparison<T> cmp, bool IsAscend = true,
IEnumerable<T> list = null) {
_item = new List<T>();
_isascend = IsAscend;
this.Comp = cmp;
if (list != null) {
_item.AddRange(list);
Build();
}
}
private int Compare(int i, int j) => (_isascend ? -1 : 1) *
Comp(_item[i], _item[j]);
private void Swap(int i, int j) {
var t = _item[i];
_item[i] = _item[j];
_item[j] = t;
}
private int Parent(int i) => (i - 1) >> 1;
private int Left(int i) => (i << 1) + 1;
public T Enqueue(T val) {
int i = _item.Count;
_item.Add(val);
while (i > 0) {
int p = Parent(i);
if (Compare(i, p) > 0)
Swap(i, p);
i = p;
}
return val;
}
private void Heapify(int index) {
for (int i = index, j; (j = Left(i)) < _item.Count; i = j) {
if (j != _item.Count - 1 && Compare(j, j + 1) < 0)
j++;
if (Compare(i, j) < 0)
Swap(i, j);
}
}
public T Dequeue() {
T val = _item[0];
_item[0] = _item[_item.Count - 1];
_item.RemoveAt(_item.Count - 1);
Heapify(0);
return val;
}
private void Build() {
for (var i = (_item.Count >> 1) - 1; i >= 0; i--)
Heapify(i);
}
public bool Any() => Count > 0;
}
class Program {
static void Main(string[] args) {
var CP = new CP();
CP.Solve();
}
}
public static class Output {
public static void Put(string a) => Console.WriteLine(a);
public static void Put(params object[] i) => Put(string.Join(" ", i));
public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a));
public static void PutV<T>(IEnumerable<T> a) {
foreach (var z in a)
Put(z);
}
public static void YN(bool i) {
if (i)
Put("Yes");
else
Put("No");
}
}
public class Input {
public static string Str => Console.ReadLine();
public static bool IsTypeEqual<T, U>() => typeof(T).Equals(typeof(U));
public static T ConvertType<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
public static T Cast<T>(string s) {
if (IsTypeEqual<T, int>())
return ConvertType<T, int>(int.Parse(s));
else if (IsTypeEqual<T, long>())
return ConvertType<T, long>(long.Parse(s));
else if (IsTypeEqual<T, double>())
return ConvertType<T, double>(double.Parse(s));
else if (IsTypeEqual<T, char>())
return ConvertType<T, char>(char.Parse(s));
else
return ConvertType<T, string>(s);
}
public static T[] Castarr<T>(string[] s) {
var ret = new T[s.Length];
int i = 0;
if (IsTypeEqual<T, char>()) {
var list = new List<T>();
foreach (var t in s) {
foreach (var u in t) {
list.Add(ConvertType<T, char>(char.Parse(u.ToString())));
}
}
return list.ToArray();
}
foreach (var t in s) {
if (IsTypeEqual<T, int>())
ret[i++] = ConvertType<T, int>(int.Parse(t));
else if (IsTypeEqual<T, long>())
ret[i++] = ConvertType<T, long>(long.Parse(t));
else if (IsTypeEqual<T, double>())
ret[i++] = ConvertType<T, double>(double.Parse(t));
else
ret[i++] = ConvertType<T, string>(t);
}
return ret;
}
Queue<string> q = new Queue<string>();
void next() {
var ss = Str.Split(' ');
foreach (var item in ss)
q.Enqueue(item);
}
public T cin<T>() {
if (!q.Any())
next();
return Cast<T>(q.Dequeue());
}
public void mul<T>(out T t) { t = cin<T>(); }
public void mul<T, U>(out T t, out U u) {
t = cin<T>();
u = cin<U>();
}
public void mul<T, U, V>(out T t, out U u, out V v) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
}
public void mul<T, U, V, W>(out T t, out U u, out V v, out W w) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
}
public void mul<T, U, V, W, X>(out T t, out U u, out V v, out W w, out X x) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
x = cin<X>();
}
public void mul<T, U, V, W, X, Y>(out T t, out U u, out V v, out W w, out X x,
out Y y) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
x = cin<X>();
y = cin<Y>();
}
public void mul<T, U, V, W, X, Y, Z>(out T t, out U u, out V v, out W w,
out X x, out Y y, out Z z) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
x = cin<X>();
y = cin<Y>();
z = cin<Z>();
}
public T[] cinarr<T>() { return Castarr<T>(Str.Split(' ')); }
}
|
[["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38]]
| 8
| 3,443
| 6
|
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, N;
sc.Make(out H, out W, out N);
int str, stc;
sc.Make(out str, out stc);
str--;
stc--;
var S = Create(2, () => sc.Str);
var lr = new List<Pi>();
var ud = new List<Pi>();
for (int i = 0; i < N; i++) {
for (int k = 0; k < 2; k++) {
switch (S[k][i]) {
case 'L':
lr.Add(new Pi(0, k));
break;
case 'R':
lr.Add(new Pi(1, k));
break;
case 'U':
ud.Add(new Pi(0, k));
break;
case 'D':
ud.Add(new Pi(1, k));
break;
}
}
}
lr.Reverse();
ud.Reverse();
int l = 0, r = W - 1;
foreach (var p in lr) {
if (p.v2 == 0) {
if (p.v1 == 0)
l++;
else
r--;
} else {
if (p.v1 == 1)
l = Max(0, l - 1);
else
r = Min(W - 1, r + 1);
}
if (r < l)
Fail("NO");
}
if (stc < l || r < stc)
Fail("NO");
int u = 0, d = H - 1;
foreach (var p in ud) {
if (p.v2 == 0) {
if (p.v1 == 0)
u++;
else
d--;
} else {
if (p.v1 == 1)
u = Max(0, u - 1);
else
d = Min(W - 1, d + 1);
}
if (d < u)
Fail("NO");
}
if (str < u || d < str)
Fail("NO");
Console.WriteLine("YES");
}
}
#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) > 0) {
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) < 0) {
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[] 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;
}
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 IEnumerable<T>
Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
for (var i = 0; i < Min(A.Length, B.Length); i++) {
int c = cmp(A[i], B[i]);
if (c > 0)
return 1;
else if (c < 0)
return -1;
}
if (A.Length == B.Length)
return 0;
if (A.Length > B.Length)
return 1;
else
return -1;
}
public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
T max = A[0];
int rt = 0;
for (int i = 1; i < A.Count; i++)
if (cmp(max, A[i]) < 0) {
max = A[i];
rt = i;
}
return rt;
}
public static T PopBack<T>(this List<T> A) {
var v = A[A.Count - 1];
A.RemoveAt(A.Count - 1);
return v;
}
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 void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6,
out T7 v7) {
Make(out v1, out v2, out v3, out v4, out v5, out v6);
v7 = Next<T7>();
}
// 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, N;
sc.Make(out H, out W, out N);
int str, stc;
sc.Make(out str, out stc);
str--;
stc--;
var S = Create(2, () => sc.Str);
var lr = new List<Pi>();
var ud = new List<Pi>();
for (int i = 0; i < N; i++) {
for (int k = 0; k < 2; k++) {
switch (S[k][i]) {
case 'L':
lr.Add(new Pi(0, k));
break;
case 'R':
lr.Add(new Pi(1, k));
break;
case 'U':
ud.Add(new Pi(0, k));
break;
case 'D':
ud.Add(new Pi(1, k));
break;
}
}
}
lr.Reverse();
ud.Reverse();
int l = 0, r = W - 1;
foreach (var p in lr) {
if (p.v2 == 0) {
if (p.v1 == 0)
l++;
else
r--;
} else {
if (p.v1 == 1)
l = Max(0, l - 1);
else
r = Min(W - 1, r + 1);
}
if (r < l)
Fail("NO");
}
if (stc < l || r < stc)
Fail("NO");
int u = 0, d = H - 1;
foreach (var p in ud) {
if (p.v2 == 0) {
if (p.v1 == 0)
u++;
else
d--;
} else {
if (p.v1 == 1)
u = Max(0, u - 1);
else
d = Min(H - 1, d + 1);
}
if (d < u)
Fail("NO");
}
if (str < u || d < str)
Fail("NO");
Console.WriteLine("YES");
}
}
#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) > 0) {
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) < 0) {
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[] 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;
}
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 IEnumerable<T>
Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
for (var i = 0; i < Min(A.Length, B.Length); i++) {
int c = cmp(A[i], B[i]);
if (c > 0)
return 1;
else if (c < 0)
return -1;
}
if (A.Length == B.Length)
return 0;
if (A.Length > B.Length)
return 1;
else
return -1;
}
public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
T max = A[0];
int rt = 0;
for (int i = 1; i < A.Count; i++)
if (cmp(max, A[i]) < 0) {
max = A[i];
rt = i;
}
return rt;
}
public static T PopBack<T>(this List<T> A) {
var v = A[A.Count - 1];
A.RemoveAt(A.Count - 1);
return v;
}
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 void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6,
out T7 v7) {
Make(out v1, out v2, out v3, out v4, out v5, out v6);
v7 = Next<T7>();
}
// 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
|
[["-", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
| 8
| 2,287
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
class Program {
static void Main() {
int[] hwn =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int H = hwn[0];
int W = hwn[1];
int N = hwn[2];
int[] rc =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int sr = rc[0];
int sc = rc[1];
string S = Console.ReadLine();
string T = Console.ReadLine();
bool isRemain = true;
//横方向判定
{
int rangeSt = 1;
int rangeEd = W;
for (int i = S.Length - 1; i >= 0; i--) {
char chT = T[i];
char chS = S[i];
//後手の補正
if (chT == 'R') {
//この後手を指す直前に居ても大丈夫な範囲が左側に1増える
rangeSt = Math.Max(rangeSt - 1, 1);
} else if (chT == 'L') {
//この後手を指す直前に居ても大丈夫な範囲が右側に1増える
rangeEd = Math.Min(rangeEd + 1, W);
}
//後手が始まる前にいても良い範囲がない時点で後手の負けは確定
if (rangeEd > rangeSt) {
isRemain = false;
}
//先手の補正
if (chS == 'R') {
//この先手を指す直前に居ても大丈夫な範囲が右側から1縮む
rangeEd--;
} else if (chS == 'L') {
//この先手を指す直前にいても大丈夫な範囲が左側から1縮む
rangeSt++;
}
//先手が始まる前にいても良い範囲がない時点で後手の負けは確定
if (rangeEd > rangeSt) {
isRemain = false;
}
}
//更に初期座標が居ても良い範囲に含まれていない場合、後手の負けが確定
if (rangeSt > sc || sc > rangeEd) {
isRemain = false;
}
}
//縦方向判定
{
int rangeSt = 1;
int rangeEd = H;
for (int i = S.Length - 1; i >= 0; i--) {
char chT = T[i];
char chS = S[i];
//後手の補正
if (chT == 'D') {
//この後手を指す直前に居ても大丈夫な範囲が上側に1増える
rangeSt = Math.Max(rangeSt - 1, 1);
} else if (chT == 'U') {
//この後手を指す直前に居ても大丈夫な範囲が下側に1増える
rangeEd = Math.Min(rangeEd + 1, H);
}
//後手が始まる前にいても良い範囲がない時点で後手の負けは確定
if (rangeEd > rangeSt) {
isRemain = false;
}
//先手の補正
if (chS == 'D') {
//この先手を指す直前に居ても大丈夫な範囲が下側から1縮む
rangeEd--;
} else if (chS == 'U') {
//この先手を指す直前にいても大丈夫な範囲が上側から1縮む
rangeSt++;
}
//先手が始まる前にいても良い範囲がない時点で後手の負けは確定
if (rangeEd > rangeSt) {
isRemain = false;
}
}
//更に初期座標が居ても良い範囲に含まれていない場合、後手の負けが確定
if (rangeSt > sr || sr > rangeEd) {
isRemain = false;
}
}
Console.WriteLine(isRemain ? "YES" : "NO");
}
}
static class MathUtil {
public static IEnumerable<IEnumerable<int>> GetPermutation(int n) {
if (n == 0) {
yield return Single(0);
yield break;
}
for (int i = 0; i <= n; i++) {
foreach (var x in GetPermutation(n - 1)) {
yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
}
}
}
private static IEnumerable<int> Single(int x) { yield return x; }
public static IEnumerable<int> EnumeratePrimeNumbers() {
List<int> primes = new List<int>() { 2 };
yield return 2;
for (int i = 3; i < int.MaxValue; i++) {
bool isPrime = true;
int Sqrt = (int)Math.Sqrt(i) + 1;
foreach (var prime in primes) {
if (prime > Sqrt) {
break;
}
if (i % prime == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.Add(i);
yield return i;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
class Program {
static void Main() {
int[] hwn =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int H = hwn[0];
int W = hwn[1];
int N = hwn[2];
int[] rc =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int sr = rc[0];
int sc = rc[1];
string S = Console.ReadLine();
string T = Console.ReadLine();
bool isRemain = true;
//横方向判定
{
int rangeSt = 1;
int rangeEd = W;
for (int i = S.Length - 1; i >= 0; i--) {
char chT = T[i];
char chS = S[i];
//後手の補正
if (chT == 'R') {
//この後手を指す直前に居ても大丈夫な範囲が左側に1増える
rangeSt = Math.Max(rangeSt - 1, 1);
} else if (chT == 'L') {
//この後手を指す直前に居ても大丈夫な範囲が右側に1増える
rangeEd = Math.Min(rangeEd + 1, W);
}
//後手が始まる前にいても良い範囲がない時点で後手の負けは確定
if (rangeEd < rangeSt) {
isRemain = false;
}
//先手の補正
if (chS == 'R') {
//この先手を指す直前に居ても大丈夫な範囲が右側から1縮む
rangeEd--;
} else if (chS == 'L') {
//この先手を指す直前にいても大丈夫な範囲が左側から1縮む
rangeSt++;
}
//先手が始まる前にいても良い範囲がない時点で後手の負けは確定
if (rangeEd < rangeSt) {
isRemain = false;
}
}
//更に初期座標が居ても良い範囲に含まれていない場合、後手の負けが確定
if (rangeSt > sc || sc > rangeEd) {
isRemain = false;
}
}
//縦方向判定
{
int rangeSt = 1;
int rangeEd = H;
for (int i = S.Length - 1; i >= 0; i--) {
char chT = T[i];
char chS = S[i];
//後手の補正
if (chT == 'D') {
//この後手を指す直前に居ても大丈夫な範囲が上側に1増える
rangeSt = Math.Max(rangeSt - 1, 1);
} else if (chT == 'U') {
//この後手を指す直前に居ても大丈夫な範囲が下側に1増える
rangeEd = Math.Min(rangeEd + 1, H);
}
//後手が始まる前にいても良い範囲がない時点で後手の負けは確定
if (rangeEd < rangeSt) {
isRemain = false;
}
//先手の補正
if (chS == 'D') {
//この先手を指す直前に居ても大丈夫な範囲が下側から1縮む
rangeEd--;
} else if (chS == 'U') {
//この先手を指す直前にいても大丈夫な範囲が上側から1縮む
rangeSt++;
}
//先手が始まる前にいても良い範囲がない時点で後手の負けは確定
if (rangeEd < rangeSt) {
isRemain = false;
}
}
//更に初期座標が居ても良い範囲に含まれていない場合、後手の負けが確定
if (rangeSt > sr || sr > rangeEd) {
isRemain = false;
}
}
Console.WriteLine(isRemain ? "YES" : "NO");
}
}
static class MathUtil {
public static IEnumerable<IEnumerable<int>> GetPermutation(int n) {
if (n == 0) {
yield return Single(0);
yield break;
}
for (int i = 0; i <= n; i++) {
foreach (var x in GetPermutation(n - 1)) {
yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
}
}
}
private static IEnumerable<int> Single(int x) { yield return x; }
public static IEnumerable<int> EnumeratePrimeNumbers() {
List<int> primes = new List<int>() { 2 };
yield return 2;
for (int i = 3; i < int.MaxValue; i++) {
bool isPrime = true;
int Sqrt = (int)Math.Sqrt(i) + 1;
foreach (var prime in primes) {
if (prime > Sqrt) {
break;
}
if (i % prime == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.Add(i);
yield return i;
}
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 775
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.AGC_033 {
class B {
static void Main(string[] args) { Method(args); }
static void Method(string[] args) {
int[] hwn = ReadInts();
int h = hwn[0];
int w = hwn[1];
int n = hwn[2];
int[] spos = ReadInts();
string s = Read();
string t = Read();
int x = spos[0];
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
x++;
if (x > w) {
WriteLine("NO");
return;
}
if (x > 1 && t[i] == 'L')
x--;
}
x = spos[0];
for (int i = 0; i < n; i++) {
if (s[i] == 'L')
x--;
if (x < 1) {
WriteLine("NO");
return;
}
if (x < h && t[i] == 'R')
x++;
}
int y = spos[1];
for (int i = 0; i < n; i++) {
if (s[i] == 'D')
y++;
if (y > h) {
WriteLine("NO");
return;
}
if (y > 1 && t[i] == 'U')
y--;
}
y = spos[1];
for (int i = 0; i < n; i++) {
if (s[i] == 'U')
y--;
if (y < 1) {
WriteLine("NO");
return;
}
if (y < h && t[i] == 'D')
y++;
}
WriteLine("YES");
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.AGC_033 {
class B {
static void Main(string[] args) { Method(args); }
static void Method(string[] args) {
int[] hwn = ReadInts();
int h = hwn[0];
int w = hwn[1];
int n = hwn[2];
int[] spos = ReadInts();
string s = Read();
string t = Read();
int x = spos[1];
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
x++;
if (x > w) {
WriteLine("NO");
return;
}
if (x > 1 && t[i] == 'L')
x--;
}
x = spos[1];
for (int i = 0; i < n; i++) {
if (s[i] == 'L')
x--;
if (x < 1) {
WriteLine("NO");
return;
}
if (x < h && t[i] == 'R')
x++;
}
int y = spos[0];
for (int i = 0; i < n; i++) {
if (s[i] == 'D')
y++;
if (y > h) {
WriteLine("NO");
return;
}
if (y > 1 && t[i] == 'U')
y--;
}
y = spos[0];
for (int i = 0; i < n; i++) {
if (s[i] == 'U')
y--;
if (y < 1) {
WriteLine("NO");
return;
}
if (y < h && t[i] == 'D')
y++;
}
WriteLine("YES");
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 604
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Hayadoki20200309A {
class Input {
/// <summary>
/// 1行の入力を取得する
/// </summary>
/// <returns>文字列</returns>
public void String(out string s) { s = Console.ReadLine(); }
/// <summary>
/// 複数行の入力を取得
/// </summary>
/// <returns>文字列の配列</returns>
public void String(long rowNumber, out string[] s) {
s = new String[rowNumber];
for (long i = 0; i < rowNumber; i++) {
String(out s[i]);
}
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>int型の値</returns>
public void Int(out int i) {
string s;
String(out s);
i = int.Parse(s);
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <param name="a"></param>
public void Long(out long a) {
string s;
String(out s);
a = long.Parse(s);
}
/// <summary>
/// 2つの整数が1行に書かれている入力を、2つのlongで受け取る
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public void Long(out long a, out long b) {
long[] lArr;
Long(out lArr);
a = lArr[0];
b = lArr[1];
}
/// <summary>
/// 3つの整数が1行に書かれている入力を、3つのlongで受け取る
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
public void Long(out long a, out long b, out long c) {
long[] lArr;
Long(out lArr);
a = lArr[0];
b = lArr[1];
c = lArr[2];
}
/// <summary>
/// 4つの整数が1行に書かれている入力を、4つのlongで受け取る
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
/// <param name="d"></param>
public void Long(out long a, out long b, out long c, out long d) {
long[] lArr;
Long(out lArr);
a = lArr[0];
b = lArr[1];
c = lArr[2];
d = lArr[3];
}
public void Long(out long[] lArr) {
lArr = Split().Select(long.Parse).ToArray();
}
public void Long(long rowNumber, out long[] lArr) {
lArr = new long[rowNumber];
for (long i = 0; i < rowNumber; i++) {
Long(out lArr[i]);
}
}
/// <summary>
/// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="a"></param>
/// <param name="b"></param>
public void Long(long rowNumber, out long[] a, out long[] b) {
a = new long[rowNumber];
b = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
Long(out a[i], out b[i]);
}
}
/// <summary>
/// 3つの整数が複数行に書かれている入力を、3つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
public void Long(long rowNumber, out long[] a, out long[] b, out long[] c) {
a = new long[rowNumber];
b = new long[rowNumber];
c = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
Long(out a[i], out b[i], out c[i]);
}
}
/// <summary>
/// 4つの整数が複数行に書かれている入力を、4つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
/// <param name="d"></param>
public void Long(long rowNumber, out long[] a, out long[] b, out long[] c,
out long[] d) {
a = new long[rowNumber];
b = new long[rowNumber];
c = new long[rowNumber];
d = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
Long(out a[i], out b[i], out c[i], out d[i]);
}
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の値</returns>
public void Double(out double d) {
string s;
String(out s);
d = double.Parse(s);
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の配列</returns>
public void Double(out double[] dArr) {
dArr = Split().Select(double.Parse).ToArray();
}
private IEnumerable<string> Split() {
string s;
String(out s);
return s.Split(' ');
}
}
class Program {
static void Main(string[] args) {
Solver solver = new Solver();
solver.Solve();
}
}
class Solver {
private Input input = new Input();
private long A;
private long B;
private long T;
public Solver() { input.Long(out A, out B, out T); }
public void Solve() {
long ans = 0;
for (long i = 1; i < T; i++) {
if (i % A == 0) {
ans += B;
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Hayadoki20200309A {
class Input {
/// <summary>
/// 1行の入力を取得する
/// </summary>
/// <returns>文字列</returns>
public void String(out string s) { s = Console.ReadLine(); }
/// <summary>
/// 複数行の入力を取得
/// </summary>
/// <returns>文字列の配列</returns>
public void String(long rowNumber, out string[] s) {
s = new String[rowNumber];
for (long i = 0; i < rowNumber; i++) {
String(out s[i]);
}
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>int型の値</returns>
public void Int(out int i) {
string s;
String(out s);
i = int.Parse(s);
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <param name="a"></param>
public void Long(out long a) {
string s;
String(out s);
a = long.Parse(s);
}
/// <summary>
/// 2つの整数が1行に書かれている入力を、2つのlongで受け取る
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public void Long(out long a, out long b) {
long[] lArr;
Long(out lArr);
a = lArr[0];
b = lArr[1];
}
/// <summary>
/// 3つの整数が1行に書かれている入力を、3つのlongで受け取る
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
public void Long(out long a, out long b, out long c) {
long[] lArr;
Long(out lArr);
a = lArr[0];
b = lArr[1];
c = lArr[2];
}
/// <summary>
/// 4つの整数が1行に書かれている入力を、4つのlongで受け取る
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
/// <param name="d"></param>
public void Long(out long a, out long b, out long c, out long d) {
long[] lArr;
Long(out lArr);
a = lArr[0];
b = lArr[1];
c = lArr[2];
d = lArr[3];
}
public void Long(out long[] lArr) {
lArr = Split().Select(long.Parse).ToArray();
}
public void Long(long rowNumber, out long[] lArr) {
lArr = new long[rowNumber];
for (long i = 0; i < rowNumber; i++) {
Long(out lArr[i]);
}
}
/// <summary>
/// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="a"></param>
/// <param name="b"></param>
public void Long(long rowNumber, out long[] a, out long[] b) {
a = new long[rowNumber];
b = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
Long(out a[i], out b[i]);
}
}
/// <summary>
/// 3つの整数が複数行に書かれている入力を、3つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
public void Long(long rowNumber, out long[] a, out long[] b, out long[] c) {
a = new long[rowNumber];
b = new long[rowNumber];
c = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
Long(out a[i], out b[i], out c[i]);
}
}
/// <summary>
/// 4つの整数が複数行に書かれている入力を、4つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
/// <param name="d"></param>
public void Long(long rowNumber, out long[] a, out long[] b, out long[] c,
out long[] d) {
a = new long[rowNumber];
b = new long[rowNumber];
c = new long[rowNumber];
d = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
Long(out a[i], out b[i], out c[i], out d[i]);
}
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の値</returns>
public void Double(out double d) {
string s;
String(out s);
d = double.Parse(s);
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の配列</returns>
public void Double(out double[] dArr) {
dArr = Split().Select(double.Parse).ToArray();
}
private IEnumerable<string> Split() {
string s;
String(out s);
return s.Split(' ');
}
}
class Program {
static void Main(string[] args) {
Solver solver = new Solver();
solver.Solve();
}
}
class Solver {
private Input input = new Input();
private long A;
private long B;
private long T;
public Solver() { input.Long(out A, out B, out T); }
public void Solve() {
long ans = 0;
for (long i = 1; i <= T; i++) {
if (i % A == 0) {
ans += B;
}
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 908
| 2
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
int T = int.Parse(input[2]);
int count = 0;
for (int time = 1; time < T; time++) {
if (time % A == 0) {
count += B;
}
}
Console.WriteLine(count);
}
}
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
int T = int.Parse(input[2]);
int count = 0;
for (int time = 1; time <= T; time++) {
if (time % A == 0) {
count += B;
}
}
Console.WriteLine(count);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 117
| 2
|
using System;
using System.Linq;
public class Test {
public static void Main() {
// your code goes here
var c = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
int a = c[0];
int b = c[1];
int t = c[2];
int counter = 0;
for (int i = 1; i < t; i++) {
if (i % a == 0) {
counter = counter + b;
}
}
Console.WriteLine(counter);
}
}
|
using System;
using System.Linq;
public class Test {
public static void Main() {
// your code goes here
var c = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
int a = c[0];
int b = c[1];
int t = c[2];
int counter = 0;
for (int i = 1; i <= t; i++) {
if (i % a == 0) {
counter = counter + b;
}
}
Console.WriteLine(counter);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 119
| 2
|
using System;
class Program {
static void Main(string[] args) {
var inputValues = Console.ReadLine().Split(' ');
var A = int.Parse(inputValues[0]);
var B = int.Parse(inputValues[1]);
var T = int.Parse(inputValues[2]);
var biscuit = 0;
var sec = 1;
while (A * sec < T) {
biscuit += B;
sec++;
}
Console.WriteLine(biscuit);
}
}
|
using System;
class Program {
static void Main(string[] args) {
var inputValues = Console.ReadLine().Split(' ');
var A = int.Parse(inputValues[0]);
var B = int.Parse(inputValues[1]);
var T = int.Parse(inputValues[2]);
var biscuit = 0;
var sec = 1;
while (A * sec <= T) {
biscuit += B;
sec++;
}
Console.WriteLine(biscuit);
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
| 8
| 107
| 2
|
using System;
using System.Threading.Tasks;
static class Program {
static void Main() {
string[] inputs = Console.ReadLine().Split(' ');
int A = int.Parse(inputs[0]);
int B = int.Parse(inputs[1]);
int T = int.Parse(inputs[2]);
if (A > T)
Console.WriteLine("0");
int sum = 0;
for (int i = 1; i <= T; i++) {
if (i % A == 0)
sum += B;
}
Console.WriteLine(sum);
}
}
|
using System;
using System.Threading.Tasks;
static class Program {
static void Main() {
string[] inputs = Console.ReadLine().Split(' ');
int A = int.Parse(inputs[0]);
int B = int.Parse(inputs[1]);
int T = int.Parse(inputs[2]);
if (A > T)
Console.WriteLine("0");
else {
int sum = 0;
for (int i = 1; i <= T; i++) {
if (i % A == 0)
sum += B;
}
Console.WriteLine(sum);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 134
| 3
|
using System;
class Program {
public static void Main(string[] args) {
string[] sta = Console.ReadLine().Split(' ');
int a = int.Parse(sta[0]);
int b = int.Parse(sta[1]);
int c = int.Parse(sta[2]);
double d = c + 1.5;
int e = (int)d / a;
int ans = e * b;
if (a > c) {
ans = 0;
}
Console.WriteLine(ans);
}
}
|
using System;
class Program {
public static void Main(string[] args) {
string[] sta = Console.ReadLine().Split(' ');
int a = int.Parse(sta[0]);
int b = int.Parse(sta[1]);
int c = int.Parse(sta[2]);
double d = c + 0.5;
int e = (int)d / a;
int ans = e * b;
if (a > c) {
ans = 0;
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 250], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 250]]
| 8
| 119
| 2
|
using System;
namespace AtCoder {
class Program {
static void Main(string[] args) {
string[] abt = Console.ReadLine().Split();
var a = int.Parse(abt[0]);
var b = int.Parse(abt[1]);
var t = int.Parse(abt[2]);
var ret = 0;
for (var i = a; i < t; i += a)
ret += b;
Console.WriteLine(ret);
}
}
}
|
using System;
namespace AtCoder {
class Program {
static void Main(string[] args) {
string[] abt = Console.ReadLine().Split();
var a = int.Parse(abt[0]);
var b = int.Parse(abt[1]);
var t = int.Parse(abt[2]);
var ret = 0;
for (var i = a; i <= t; i += a)
ret += b;
Console.WriteLine(ret);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 107
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtC {
class Program {
static void Main(string[] args) {
var abt = ReadIntArray();
int A = abt[0], B = abt[1], T = abt[2];
Out((int)((T + .5) / A * B));
}
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static string ReadString() { return Console.ReadLine(); }
static void Out(object o) { Console.WriteLine(o); }
}
static class EnumerableExtension {
public delegate void Function<in T>(T val);
public static void ForEach<T>(this IEnumerable<T> enumerable,
Function<T> function) {
foreach (var x in enumerable) {
function(x);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtC {
class Program {
static void Main(string[] args) {
var abt = ReadIntArray();
int A = abt[0], B = abt[1], T = abt[2];
Out((int)((int)((T + .5) / A) * B));
}
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static string ReadString() { return Console.ReadLine(); }
static void Out(object o) { Console.WriteLine(o); }
}
static class EnumerableExtension {
public delegate void Function<in T>(T val);
public static void ForEach<T>(this IEnumerable<T> enumerable,
Function<T> function) {
foreach (var x in enumerable) {
function(x);
}
}
}
}
|
[["+", 0, 74, 51, 23, 0, 16, 31, 74, 39, 199], ["+", 0, 74, 51, 23, 0, 16, 31, 74, 0, 25], ["+", 51, 23, 0, 16, 31, 74, 51, 23, 0, 24], ["+", 31, 74, 51, 23, 0, 16, 31, 23, 0, 24], ["+", 51, 23, 0, 16, 31, 74, 51, 23, 0, 25]]
| 8
| 272
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoderCore {
public class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] vs =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int[] cs =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int ans = 0;
for (int i = 0; i < n; i++) {
if (vs[i] - cs[i] > 0) {
ans += vs[i];
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoderCore {
public class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] vs =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int[] cs =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int ans = 0;
for (int i = 0; i < n; i++) {
if (vs[i] - cs[i] > 0) {
ans += vs[i] - cs[i];
}
}
Console.WriteLine(ans);
}
}
}
|
[["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 168
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
// 整数の入力
int a = int.Parse(Console.ReadLine());
// スペース区切りの整数の入力
string[] inputv = Console.ReadLine().Split(' ');
string[] inputc = Console.ReadLine().Split(' ');
int z = 0, sum = 0;
for (int i = 0; i < a; i++) {
int v = int.Parse(inputv[i]);
int c = int.Parse(inputc[i]);
if ((v - c) >= 0)
sum += (v - c);
}
//出力
Console.WriteLine((z));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
// 整数の入力
int a = int.Parse(Console.ReadLine());
// スペース区切りの整数の入力
string[] inputv = Console.ReadLine().Split(' ');
string[] inputc = Console.ReadLine().Split(' ');
int z = 0, sum = 0;
for (int i = 0; i < a; i++) {
int v = int.Parse(inputv[i]);
int c = int.Parse(inputc[i]);
if ((v - c) >= 0)
sum += (v - c);
}
//出力
Console.WriteLine((sum));
}
}
|
[["-", 0, 198, 0, 200, 0, 289, 0, 289, 141, 22], ["+", 0, 198, 0, 200, 0, 289, 0, 289, 141, 22]]
| 8
| 173
| 2
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace atcoder {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int res = 0;
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
for (int i = k; i <= n; i++) {
res++;
}
Console.WriteLine();
}
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace atcoder {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int res = 0;
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
for (int i = k; i <= n; i++) {
res++;
}
Console.WriteLine(res);
}
}
}
|
[["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 113
| 1
|
namespace diverta2019.A {
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
public class Program {
public static void Main(string[] args) {
var l = ReadLineAsInts().ToList();
var n = l[0];
var k = l[0];
WriteLine(Solve(n, k));
}
public static IEnumerable<int>
ReadLineAsInts() => ReadLine().Split(' ').Select(x => int.Parse(x));
public static int Solve(int n, int k) => n - k + 1;
}
}
|
namespace diverta2019.A {
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
public class Program {
public static void Main(string[] args) {
var l = ReadLineAsInts().ToList();
var n = l[0];
var k = l[1];
WriteLine(Solve(n, k));
}
public static IEnumerable<int>
ReadLineAsInts() => ReadLine().Split(' ').Select(x => int.Parse(x));
public static int Solve(int n, int k) => n - k + 1;
}
}
|
[["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 132
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public static void Main() {
var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var n = vals[0];
var k = vals[1];
Console.WriteLine(k - n + 1);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public static void Main() {
var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var n = vals[0];
var k = vals[1];
Console.WriteLine(n - k + 1);
}
}
|
[["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22]]
| 8
| 82
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Diverta2019_A {
class Program {
static void Main(string[] args) {
string[] strs = Console.ReadLine().Split();
int n = int.Parse(strs[0]);
int k = int.Parse(strs[0]);
Console.WriteLine("{0}", n - k + 1);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Diverta2019_A {
class Program {
static void Main(string[] args) {
string[] strs = Console.ReadLine().Split();
int n = int.Parse(strs[0]);
int k = int.Parse(strs[1]);
Console.WriteLine("{0}", n - k + 1);
}
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 102
| 2
|
using System;
using System.Linq;
namespace diverta2019_b {
class Program {
static void Main(string[] args) {
var RGBN =
(Console.ReadLine().Split(' ').Select(x => int.Parse(x))).ToList();
var R = RGBN[0];
var G = RGBN[1];
var B = RGBN[2];
var N = RGBN[3];
var r = 0;
for (int i = 0; i <= N; i += R) {
for (int j = 0; j <= N; j += G) {
if (i + j > N)
break;
//残りがBで割り切れる
if ((N - i + j) % B == 0)
r++;
}
}
Console.WriteLine(r);
}
}
}
|
using System;
using System.Linq;
namespace diverta2019_b {
class Program {
static void Main(string[] args) {
var RGBN =
(Console.ReadLine().Split(' ').Select(x => int.Parse(x))).ToList();
var R = RGBN[0];
var G = RGBN[1];
var B = RGBN[2];
var N = RGBN[3];
var r = 0;
for (int i = 0; i <= N; i += R) {
for (int j = 0; j <= N; j += G) {
if (i + j > N)
break;
//残りがBで割り切れる
if ((N - (i + j)) % B == 0)
r++;
}
}
Console.WriteLine(r);
}
}
}
|
[["+", 31, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 31, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
| 8
| 167
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder2 {
class Program {
static void Main(string[] args) {
//出力の都度更新をやめる
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Ans();
//更新する
Console.Out.Flush();
}
public static void Ans() {
var inputArray = retreiveLongArray();
var inputCount = 1;
// 不正な入力は処理しない
if (inputArray.Length != inputCount) {
Console.WriteLine("invalid input");
return;
}
long N = inputArray[0];
var stringS = new List<string>();
for (int i = 0; i < N; i++) {
var input = retreiveStringArray()[0];
stringS.Add(input);
}
var p = 0;
var a = 0;
var b = 0;
var ab = 0;
for (int i = 0; i < N; i++) {
var s = stringS[i];
ab += CountOf(s, "AB");
if (s[0] == 'B' && s[s.Length - 1] == 'A') {
p++;
continue;
}
if (s[0] == 'B') {
b++;
}
if (s[s.Length - 1] == 'A') {
a++;
}
}
if (a == 0 && b == 0) {
Console.WriteLine(ab + p -
1); // aもbもない時、組み合わせできないB**Aが発生
return;
}
//答えの出力
var ans = ab + p + Math.Min(a, b);
Console.WriteLine(ans);
}
/// <summary>
/// 指定した文字列がいくつあるか
/// </summary>
private static int CountOf(string target, string str) {
int count = 0;
int index = target.IndexOf(str, 0);
while (index != -1) {
count++;
index = target.IndexOf(str, index + str.Length);
}
return count;
}
/// <summary>
/// スペースで区切られた文字列配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static string[] retreiveStringArray() {
var inputArray = Console.ReadLine().Split(' ');
return inputArray;
}
/// <summary>
/// スペースで区切られた整数配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static long[] retreiveLongArray() {
var inputArray = Console.ReadLine().Split(' ');
var longArray = inputArray.Select(s => long.Parse(s));
return longArray.ToArray();
}
/// <summary>
/// 2組みずつの入力データ(数値)からTuppleListを作成する
/// </summary>
/// <param name="N"></param>
/// <returns></returns>
private static List<Tuple<long, long>> createLongTuppleList(long N) {
var inpList = new List<Tuple<long, long>>();
for (int i = 0; i < N; i++) {
var inp = retreiveLongArray();
var item1 = inp[0];
var item2 = inp[1];
inpList.Add(new Tuple<long, long>(item1, item2));
}
return inpList;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder2 {
class Program {
static void Main(string[] args) {
//出力の都度更新をやめる
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Ans();
//更新する
Console.Out.Flush();
}
public static void Ans() {
var inputArray = retreiveLongArray();
var inputCount = 1;
// 不正な入力は処理しない
if (inputArray.Length != inputCount) {
Console.WriteLine("invalid input");
return;
}
long N = inputArray[0];
var stringS = new List<string>();
for (int i = 0; i < N; i++) {
var input = retreiveStringArray()[0];
stringS.Add(input);
}
var p = 0;
var a = 0;
var b = 0;
var ab = 0;
for (int i = 0; i < N; i++) {
var s = stringS[i];
ab += CountOf(s, "AB");
if (s[0] == 'B' && s[s.Length - 1] == 'A') {
p++;
continue;
}
if (s[0] == 'B') {
b++;
}
if (s[s.Length - 1] == 'A') {
a++;
}
}
if (a == 0 && b == 0 && p > 0) {
Console.WriteLine(ab + p -
1); // aもbもない時、組み合わせできないB**Aが発生
return;
}
//答えの出力
var ans = ab + p + Math.Min(a, b);
Console.WriteLine(ans);
}
/// <summary>
/// 指定した文字列がいくつあるか
/// </summary>
private static int CountOf(string target, string str) {
int count = 0;
int index = target.IndexOf(str, 0);
while (index != -1) {
count++;
index = target.IndexOf(str, index + str.Length);
}
return count;
}
/// <summary>
/// スペースで区切られた文字列配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static string[] retreiveStringArray() {
var inputArray = Console.ReadLine().Split(' ');
return inputArray;
}
/// <summary>
/// スペースで区切られた整数配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static long[] retreiveLongArray() {
var inputArray = Console.ReadLine().Split(' ');
var longArray = inputArray.Select(s => long.Parse(s));
return longArray.ToArray();
}
/// <summary>
/// 2組みずつの入力データ(数値)からTuppleListを作成する
/// </summary>
/// <param name="N"></param>
/// <returns></returns>
private static List<Tuple<long, long>> createLongTuppleList(long N) {
var inpList = new List<Tuple<long, long>>();
for (int i = 0; i < N; i++) {
var inp = retreiveLongArray();
var item1 = inp[0];
var item2 = inp[1];
inpList.Add(new Tuple<long, long>(item1, item2));
}
return inpList;
}
}
}
|
[["+", 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
| 610
| 4
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
// var s = Console.ReadLine();
long n = long.Parse(Console.ReadLine());
string[] s = new string[n];
for (long i = 0; i < n; i++) {
s[i] = Console.ReadLine();
}
long ans = 0;
for (long i = 0; i < n; i++) {
var tmp = s[i].Replace("AB", "");
if (tmp.Length < s[i].Length)
ans += (s[i].Length - tmp.Length) / 2;
}
long a = 0;
long b = 0;
long x = 0;
for (long i = 0; i < n; i++) {
if (s[i][s[i].Length - 1] == 'A')
a++;
if (s[i][0] == 'B')
b++;
if (s[i][s[i].Length - 1] == 'A' && s[i][0] == 'B')
x++;
}
if (a == b && b == x)
ans += a - 1;
else
ans += Math.Min(a, b);
// 出力
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
// var s = Console.ReadLine();
long n = long.Parse(Console.ReadLine());
string[] s = new string[n];
for (long i = 0; i < n; i++) {
s[i] = Console.ReadLine();
}
long ans = 0;
for (long i = 0; i < n; i++) {
var tmp = s[i].Replace("AB", "");
if (tmp.Length < s[i].Length)
ans += (s[i].Length - tmp.Length) / 2;
}
long a = 0;
long b = 0;
long x = 0;
for (long i = 0; i < n; i++) {
if (s[i][s[i].Length - 1] == 'A')
a++;
if (s[i][0] == 'B')
b++;
if (s[i][s[i].Length - 1] == 'A' && s[i][0] == 'B')
x++;
}
if (a != 0 && a == b && b == x)
ans += a - 1;
else
ans += Math.Min(a, b);
// 出力
Console.WriteLine(ans);
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 79], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22]]
| 8
| 307
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Hello {
static public int mod = 1000000007;
public static void Main() {
// 方針
//
int n = rint();
int a = 0;
int b = 0;
int ab = 0;
int axb = 0;
for (int i = 0; i < n; i++) {
string t = rstr();
int tl = t.Length;
string temp = t.Replace("AB", "");
ab += (tl - temp.Length) / 2;
if (t[0] == 'B')
a++;
if (t[tl - 1] == 'A')
b++;
if (t[0] == 'B' && t[tl - 1] == 'A')
axb++;
}
if (a == b && a == axb) {
WriteLine(axb - 1 + ab);
} else {
WriteLine(Min(a, b) + ab);
}
}
static int binarysearchd(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] >= b) {
return 0;
} else if (a[leng - 1] < b) {
return leng;
} else {
if (a[max] < b) {
return max + 1;
}
return min + 1;
}
}
static int binarysearchu(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] > b) {
return leng;
} else if (a[leng - 1] <= b) {
return 0;
} else {
if (a[max] <= b) {
return leng - (max + 1);
}
return leng - (min + 1);
}
}
// 1からaまでの数字並べ替え全通り返すやつ
static List<string> permutation(int a) {
var list = new List<string>();
if (a == 1) {
list.Add("1");
return list;
} else {
foreach (var k in permutation(a - 1)) {
var ch = k.ToCharArray();
for (int i = 0; i <= ch.Length; i++) {
string intemp = "";
if (i == 0) {
intemp += a.ToString();
}
for (int j = 0; j < ch.Length; j++) {
intemp += ch[j].ToString();
if (i == j + 1) {
intemp += a.ToString();
}
}
list.Add(intemp);
}
}
}
return list;
}
static void swap(ref int a, ref int b) {
var temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
// static int square2(long a,long b,long m){var list = new List<int>();int
// temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp <
// b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b >
// 0){if(temp <= b){b -= temp;ret =
// ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Hello {
static public int mod = 1000000007;
public static void Main() {
// 方針
//
int n = rint();
int a = 0;
int b = 0;
int ab = 0;
int axb = 0;
for (int i = 0; i < n; i++) {
string t = rstr();
int tl = t.Length;
string temp = t.Replace("AB", "");
ab += (tl - temp.Length) / 2;
if (t[0] == 'B')
a++;
if (t[tl - 1] == 'A')
b++;
if (t[0] == 'B' && t[tl - 1] == 'A')
axb++;
}
if (a == b && a == axb && axb > 0) {
WriteLine(axb - 1 + ab);
} else {
WriteLine(Min(a, b) + ab);
}
}
static int binarysearchd(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] >= b) {
return 0;
} else if (a[leng - 1] < b) {
return leng;
} else {
if (a[max] < b) {
return max + 1;
}
return min + 1;
}
}
static int binarysearchu(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] > b) {
return leng;
} else if (a[leng - 1] <= b) {
return 0;
} else {
if (a[max] <= b) {
return leng - (max + 1);
}
return leng - (min + 1);
}
}
// 1からaまでの数字並べ替え全通り返すやつ
static List<string> permutation(int a) {
var list = new List<string>();
if (a == 1) {
list.Add("1");
return list;
} else {
foreach (var k in permutation(a - 1)) {
var ch = k.ToCharArray();
for (int i = 0; i <= ch.Length; i++) {
string intemp = "";
if (i == 0) {
intemp += a.ToString();
}
for (int j = 0; j < ch.Length; j++) {
intemp += ch[j].ToString();
if (i == j + 1) {
intemp += a.ToString();
}
}
list.Add(intemp);
}
}
}
return list;
}
static void swap(ref int a, ref int b) {
var temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
// static int square2(long a,long b,long m){var list = new List<int>();int
// temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp <
// b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b >
// 0){if(temp <= b){b -= temp;ret =
// ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
|
[["+", 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
| 1,473
| 4
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections;
using System.Linq;
class Program {
static List<int> s = new List<int>();
static List<string> a = new List<string>();
static decimal result;
static StringBuilder sb = new StringBuilder();
static int N, M, K;
static void Main() {
Read1();
Read5();
//中のABを集計
for (int i = 0; i < N; i++) {
for (int j = 0; j < a[i].Length - 1; j++) {
if (a[i][j] == 'A' && a[i][j + 1] == 'B') {
result++;
}
}
}
int count, count2, count3;
count = 0;
count2 = 0;
count3 = 0;
// A末尾Bスタートを集計
for (int i = 0; i < N; i++) {
if (a[i][a[i].Length - 1] == 'A') {
count++;
}
if (a[i][0] == 'B') {
count2++;
}
if (a[i][a[i].Length - 1] == 'A' && a[i][0] == 'B') {
count3++;
}
}
if (count3 == count && count3 == count2) {
result += count3 - 1;
} else if (count2 >= count) {
result += count;
} else {
result += count2;
}
Console.WriteLine(result.ToString());
}
static void Read1() // 1項
{
string tmp = Console.ReadLine();
N = int.Parse(tmp);
}
static void Read2() //複数項(項目数N)
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read3() // 1行複数項
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < tmp.Length; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read4() // NK1行
{
string[] tmp = Console.ReadLine().Split(' ');
N = int.Parse(tmp[0]);
K = int.Parse(tmp[1]);
}
static void Read5() // N行K項
{
for (int i = 0; i < N; i++) {
a.Add(Console.ReadLine());
}
}
}
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections;
using System.Linq;
class Program {
static List<int> s = new List<int>();
static List<string> a = new List<string>();
static decimal result;
static StringBuilder sb = new StringBuilder();
static int N, M, K;
static void Main() {
Read1();
Read5();
//中のABを集計
for (int i = 0; i < N; i++) {
for (int j = 0; j < a[i].Length - 1; j++) {
if (a[i][j] == 'A' && a[i][j + 1] == 'B') {
result++;
}
}
}
int count, count2, count3;
count = 0;
count2 = 0;
count3 = 0;
// A末尾Bスタートを集計
for (int i = 0; i < N; i++) {
if (a[i][a[i].Length - 1] == 'A') {
count++;
}
if (a[i][0] == 'B') {
count2++;
}
if (a[i][a[i].Length - 1] == 'A' && a[i][0] == 'B') {
count3++;
}
}
if (count3 == count && count3 == count2 && count3 > 0) {
result += count3 - 1;
} else if (count2 >= count) {
result += count;
} else {
result += count2;
}
Console.WriteLine(result.ToString());
}
static void Read1() // 1項
{
string tmp = Console.ReadLine();
N = int.Parse(tmp);
}
static void Read2() //複数項(項目数N)
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read3() // 1行複数項
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < tmp.Length; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read4() // NK1行
{
string[] tmp = Console.ReadLine().Split(' ');
N = int.Parse(tmp[0]);
K = int.Parse(tmp[1]);
}
static void Read5() // N行K項
{
for (int i = 0; i < N; i++) {
a.Add(Console.ReadLine());
}
}
}
|
[["+", 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
| 565
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
int N = cin.nextInt();
string[] s = new string[N];
int ans = 0;
int Aend = 0;
int Bstart = 0;
int BA = 0;
for (int i = 0; i < N; i++) {
s[i] = cin.next();
int n = s[i].Length;
if (s[i][0] == 'B' && s[i][n - 1] == 'A')
BA++;
else if (s[i][0] == 'B')
Bstart++;
else if (s[i][n - 1] == 'A')
Aend++;
for (int j = 0; j < n - 1; j++) {
if (s[i][j] == 'A' && s[i][j + 1] == 'B')
ans++;
}
}
if (Aend + Bstart == 0)
ans += (BA - 1);
else
ans += BA + Math.Min(Aend, Bstart);
Console.WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
public long GCDLong(long a, long b) {
while (a != 0) {
long t = a;
a = b % a;
b = t;
}
return b;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
int N = cin.nextInt();
string[] s = new string[N];
int ans = 0;
int Aend = 0;
int Bstart = 0;
int BA = 0;
for (int i = 0; i < N; i++) {
s[i] = cin.next();
int n = s[i].Length;
if (s[i][0] == 'B' && s[i][n - 1] == 'A')
BA++;
else if (s[i][0] == 'B')
Bstart++;
else if (s[i][n - 1] == 'A')
Aend++;
for (int j = 0; j < n - 1; j++) {
if (s[i][j] == 'A' && s[i][j + 1] == 'B')
ans++;
}
}
if (Aend + Bstart == 0 && BA > 0)
ans += (BA - 1);
else
ans += BA + Math.Min(Aend, Bstart);
Console.WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
public long GCDLong(long a, long b) {
while (a != 0) {
long t = a;
a = b % a;
b = t;
}
return b;
}
}
|
[["+", 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
| 703
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
namespace AtCodeeeer {
class AtCOOOOOOOOOOOder {
static void Main(string[] args) {
int N = int.Parse(ReadLine());
int BほにゃA = 0;
int BほにゃnotA = 0;
int notBほにゃA = 0;
int ans = 0;
for (int i = 0; i < N; i++) {
string s = ReadLine();
if (s.StartsWith("B") && s.EndsWith("A")) {
BほにゃA++;
}
if (s.StartsWith("B") && !s.EndsWith("A")) {
BほにゃnotA++;
}
if (!s.StartsWith("B") && s.EndsWith("A")) {
notBほにゃA++;
}
for (int j = 0; j < s.Length - 1; j++) {
if (s.Substring(j, 2) == "AB") {
ans++;
}
}
}
if (BほにゃA == 0) {
WriteLine(ans + Min(BほにゃnotA, notBほにゃA));
} else if (BほにゃnotA + notBほにゃA == 0) {
WriteLine(ans + Min(BほにゃnotA, notBほにゃA) - 1);
} else {
WriteLine(ans + BほにゃA + Min(BほにゃnotA, notBほにゃA));
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
namespace AtCodeeeer {
class AtCOOOOOOOOOOOder {
static void Main(string[] args) {
int N = int.Parse(ReadLine());
int BほにゃA = 0;
int BほにゃnotA = 0;
int notBほにゃA = 0;
int ans = 0;
for (int i = 0; i < N; i++) {
string s = ReadLine();
if (s.StartsWith("B") && s.EndsWith("A")) {
BほにゃA++;
}
if (s.StartsWith("B") && !s.EndsWith("A")) {
BほにゃnotA++;
}
if (!s.StartsWith("B") && s.EndsWith("A")) {
notBほにゃA++;
}
for (int j = 0; j < s.Length - 1; j++) {
if (s.Substring(j, 2) == "AB") {
ans++;
}
}
}
if (BほにゃA == 0) {
WriteLine(ans + Min(BほにゃnotA, notBほにゃA));
} else if (BほにゃnotA + notBほにゃA == 0) {
WriteLine(ans + BほにゃA - 1);
} else {
WriteLine(ans + BほにゃA + Min(BほにゃnotA, notBほにゃA));
}
}
}
}
|
[["-", 0, 28, 0, 16, 31, 16, 12, 213, 63, 22], ["-", 0, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["-", 31, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 16, 31, 16, 12, 213, 3, 4, 0, 21], ["-", 0, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22]]
| 8
| 285
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace diverta_B {
class Program {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
string[] s = new string[n];
var count = 0;
var aback = 0;
var bfront = 0;
var both = 0;
var checkboth = 0;
for (int i = 0; i < n; i++) {
s[i] = Console.ReadLine();
for (int j = 0; j < s[i].Length - 1; j++) {
if (s[i].Substring(j, 2) == "AB") {
count++;
}
}
if (s[i].Substring(0, 1) == "B") {
bfront++;
both++;
}
if (s[i].Substring(s[i].Length - 1, 1) == "A") {
aback++;
both++;
}
if (both == 2) {
checkboth++;
}
both = 0;
}
if (bfront > aback) {
count = count + aback;
} else {
count = count + bfront;
}
if (aback == checkboth & bfront == checkboth) {
count = count - 1;
}
Console.WriteLine(Convert.ToString(count));
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace diverta_B {
class Program {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
string[] s = new string[n];
var count = 0;
var aback = 0;
var bfront = 0;
var both = 0;
var checkboth = 0;
for (int i = 0; i < n; i++) {
s[i] = Console.ReadLine();
for (int j = 0; j < s[i].Length - 1; j++) {
if (s[i].Substring(j, 2) == "AB") {
count++;
}
}
if (s[i].Substring(0, 1) == "B") {
bfront++;
both++;
}
if (s[i].Substring(s[i].Length - 1, 1) == "A") {
aback++;
both++;
}
if (both == 2) {
checkboth++;
}
both = 0;
}
if (bfront > aback) {
count = count + aback;
} else {
count = count + bfront;
}
if (aback == checkboth & bfront == checkboth & checkboth != 0) {
count = count - 1;
}
Console.WriteLine(Convert.ToString(count));
Console.ReadLine();
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 67], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 302
| 4
|
namespace inonoa {
class Ino {
static void Main() {
int n = int.Parse(System.Console.ReadLine());
int ans = 0;
int a = 0;
int b = 0;
int ab = 0;
for (int i = 0; i < n; i++) {
char[] si = System.Console.ReadLine().ToCharArray();
if (si[0] == 'B') {
b++;
}
if (si[si.Length - 1] == 'A') {
a++;
}
if (si[0] == 'B' && si[si.Length - 1] == 'A') {
ab++;
}
for (int j = 0; j < si.Length - 1; j++) {
if (si[j] == 'A' && si[j + 1] == 'B') {
ans++;
}
}
}
if (ab == a && ab == b) {
a--;
b--;
}
if (a == n) {
a--;
}
if (b == n) {
b--;
}
if (a > b) {
ans += b;
} else {
ans += a;
}
System.Console.WriteLine(ans);
}
}
}
|
namespace inonoa {
class Ino {
static void Main() {
int n = int.Parse(System.Console.ReadLine());
int ans = 0;
int a = 0;
int b = 0;
int ab = 0;
for (int i = 0; i < n; i++) {
char[] si = System.Console.ReadLine().ToCharArray();
if (si[0] == 'B') {
b++;
}
if (si[si.Length - 1] == 'A') {
a++;
}
if (si[0] == 'B' && si[si.Length - 1] == 'A') {
ab++;
}
for (int j = 0; j < si.Length - 1; j++) {
if (si[j] == 'A' && si[j + 1] == 'B') {
ans++;
}
}
}
if (ab == a && ab == b && ab != 0) {
a--;
b--;
}
if (a == n) {
a--;
}
if (b == n) {
b--;
}
if (a > b) {
ans += b;
} else {
ans += a;
}
System.Console.WriteLine(ans);
}
}
}
|
[["+", 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, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 264
| 4
|
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main() {
int count = int.Parse(ReadLine());
stringData[] stringDatas = new stringData[count];
for (int i = 0; i < count; i++) {
var input = ReadLine();
stringDatas[i] = new stringData(input);
}
int a_and_b = stringDatas.Count(sd => sd.IsEndWithA && sd.IsStartWithB);
int a = stringDatas.Count(sd => sd.IsEndWithA) - a_and_b;
int b = stringDatas.Count(sd => sd.IsStartWithB) - a_and_b;
int min = new[] { a, b }.Min();
if (a == 0 && b == 0)
min -= 1;
int Ab = stringDatas.Sum(sd => sd.ABCount);
WriteLine(Ab + min + a_and_b);
ReadKey();
}
}
public struct stringData {
public bool IsStartWithB;
public bool IsEndWithA;
public int ABCount;
public stringData(string s) {
ABCount = 0;
IsStartWithB = s[0] == 'B';
bool isA = false;
for (int i = 0; i < s.Length; i++) {
if (s[i] == 'A')
isA = true;
else if (s[i] == 'B' && isA) {
ABCount++;
isA = false;
} else {
isA = false;
}
}
IsEndWithA = s[s.Length - 1] == 'A';
}
}
static class MyUtil {
public static long[] ReadlongArray() {
return ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
}
/// <summary>
/// <see
/// cref="IEnumerable{T}"/>の各要素を並べてコンソールに出力します。各要素の間には半角スペースが一つ入ります。
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="ts"></param>
public static void WriteToConsole<T>(this IEnumerable<T> ts) {
StringBuilder stringBuilder = new StringBuilder();
foreach (T t in ts) {
stringBuilder.Append(t.ToString());
stringBuilder.Append(" ");
}
stringBuilder.Remove(stringBuilder.Length - 1, 1);
Console.WriteLine(stringBuilder.ToString());
}
}
|
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main() {
int count = int.Parse(ReadLine());
stringData[] stringDatas = new stringData[count];
for (int i = 0; i < count; i++) {
var input = ReadLine();
stringDatas[i] = new stringData(input);
}
int a_and_b = stringDatas.Count(sd => sd.IsEndWithA && sd.IsStartWithB);
int a = stringDatas.Count(sd => sd.IsEndWithA) - a_and_b;
int b = stringDatas.Count(sd => sd.IsStartWithB) - a_and_b;
int min = new[] { a, b }.Min();
if (a == 0 && b == 0 && a_and_b != 0)
min -= 1;
int Ab = stringDatas.Sum(sd => sd.ABCount);
WriteLine(Ab + min + a_and_b);
ReadKey();
}
}
public struct stringData {
public bool IsStartWithB;
public bool IsEndWithA;
public int ABCount;
public stringData(string s) {
ABCount = 0;
IsStartWithB = s[0] == 'B';
bool isA = false;
for (int i = 0; i < s.Length; i++) {
if (s[i] == 'A')
isA = true;
else if (s[i] == 'B' && isA) {
ABCount++;
isA = false;
} else {
isA = false;
}
}
IsEndWithA = s[s.Length - 1] == 'A';
}
}
static class MyUtil {
public static long[] ReadlongArray() {
return ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
}
/// <summary>
/// <see
/// cref="IEnumerable{T}"/>の各要素を並べてコンソールに出力します。各要素の間には半角スペースが一つ入ります。
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="ts"></param>
public static void WriteToConsole<T>(this IEnumerable<T> ts) {
StringBuilder stringBuilder = new StringBuilder();
foreach (T t in ts) {
stringBuilder.Append(t.ToString());
stringBuilder.Append(" ");
}
stringBuilder.Remove(stringBuilder.Length - 1, 1);
Console.WriteLine(stringBuilder.ToString());
}
}
|
[["+", 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, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 458
| 4
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using static System.Math;
namespace _20190511 {
class Program {
public static void Main(string[] args) {
using (var sc = new SetConsole()) {
int count = 0;
int n = GetString().ToInt();
var list = new List<string>();
var a = new Stack<string>();
var b = new Stack<string>();
var ab = new List<string>();
for (int i = 0; i < n; i++) {
var str = GetString();
if ('A' == str[str.Length - 1] && 'B' == str[0]) {
ab.Add(str);
} else if ('A' == str[str.Length - 1]) {
a.Push(str);
} else if ('B' == str[0]) {
b.Push(str);
}
for (int j = 0; j < str.Length - 1; j++) {
if ('A' == str[j] && 'B' == str[j + 1]) {
count++;
}
}
}
int abCount = ab.Count - 1 > 0 ? ab.Count - 1 : 0;
count += abCount;
if (abCount > 0) {
if (a.Any()) {
a.Pop();
count++;
}
if (b.Any()) {
b.Pop();
count++;
}
}
count += Min(a.Count, b.Count);
CWrite(count);
}
}
static void CWrite<T>(T str) => Console.WriteLine(str);
static string GetString() => Console.ReadLine();
static T[] GetArray<T>() {
var t = typeof(T);
var str = Console.ReadLine();
if (t == typeof(string)) {
return (T[])(object)str.Split();
}
if (t == typeof(int)) {
return (T[])(object)str.ToNumArray<T>();
}
if (t == typeof(long)) {
return (T[])(object)str.ToNumArray<T>();
}
if (t == typeof(double)) {
return (T[])(object)str.ToNumArray<T>();
}
throw new NotSupportedException($"{t} is not supported.");
}
}
class SetConsole : IDisposable {
readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
public SetConsole() {
sw.AutoFlush = false;
Console.SetOut(sw);
}
public void Dispose() {
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
}
static class ExtentionsLibrary {
public static T[] ToNumArray<T>(this string str) {
var t = typeof(T);
if (t == typeof(int)) {
return (T[])(object)str.Split().Select(int.Parse).ToArray();
}
if (t == typeof(long)) {
return (T[])(object)str.Split().Select(long.Parse).ToArray();
}
if (t == typeof(double)) {
return (T[])(object)str.Split().Select(double.Parse).ToArray();
}
throw new NotSupportedException();
}
public static int ToInt(this string str) => int.Parse(str);
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using static System.Math;
namespace _20190511 {
class Program {
public static void Main(string[] args) {
using (var sc = new SetConsole()) {
int count = 0;
int n = GetString().ToInt();
var list = new List<string>();
var a = new Stack<string>();
var b = new Stack<string>();
var ab = new List<string>();
for (int i = 0; i < n; i++) {
var str = GetString();
if ('A' == str[str.Length - 1] && 'B' == str[0]) {
ab.Add(str);
} else if ('A' == str[str.Length - 1]) {
a.Push(str);
} else if ('B' == str[0]) {
b.Push(str);
}
for (int j = 0; j < str.Length - 1; j++) {
if ('A' == str[j] && 'B' == str[j + 1]) {
count++;
}
}
}
int abCount = ab.Count - 1 > 0 ? ab.Count - 1 : 0;
count += abCount;
if (ab.Any()) {
if (a.Any()) {
a.Pop();
count++;
}
if (b.Any()) {
b.Pop();
count++;
}
}
count += Min(a.Count, b.Count);
CWrite(count);
}
}
static void CWrite<T>(T str) => Console.WriteLine(str);
static string GetString() => Console.ReadLine();
static T[] GetArray<T>() {
var t = typeof(T);
var str = Console.ReadLine();
if (t == typeof(string)) {
return (T[])(object)str.Split();
}
if (t == typeof(int)) {
return (T[])(object)str.ToNumArray<T>();
}
if (t == typeof(long)) {
return (T[])(object)str.ToNumArray<T>();
}
if (t == typeof(double)) {
return (T[])(object)str.ToNumArray<T>();
}
throw new NotSupportedException($"{t} is not supported.");
}
}
class SetConsole : IDisposable {
readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
public SetConsole() {
sw.AutoFlush = false;
Console.SetOut(sw);
}
public void Dispose() {
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
}
static class ExtentionsLibrary {
public static T[] ToNumArray<T>(this string str) {
var t = typeof(T);
if (t == typeof(int)) {
return (T[])(object)str.Split().Select(int.Parse).ToArray();
}
if (t == typeof(long)) {
return (T[])(object)str.Split().Select(long.Parse).ToArray();
}
if (t == typeof(double)) {
return (T[])(object)str.Split().Select(double.Parse).ToArray();
}
throw new NotSupportedException();
}
public static int ToInt(this string str) => int.Parse(str);
}
}
|
[["-", 0, 311, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 311, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 311, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25]]
| 8
| 773
| 8
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
static class Program {
const int mod = (int)1e9 + 7;
static void Main() {
Sc sc = new Sc();
int n = sc.I;
long ans = 0, a = 0, b = 0, c = 0;
for (int i = 0; i < n; i++) {
string s = sc.S;
for (int j = 0; j < s.Length - 1; j++) {
if (s[j] == 'A' && s[j + 1] == 'B') {
ans++;
}
}
if (s[s.Length - 1] == 'A') {
a++;
}
if (s[0] == 'B') {
b++;
}
if (s[s.Length - 1] == 'A' && s[0] == 'B') {
c++;
}
}
if (b == c && a == c) {
ans--;
}
Console.WriteLine("{0}", ans + Math.Min(a, b));
}
}
public class Sc {
private string[] a;
private int n = -1, m = 0;
public int I {
get {
if (n == -1 || n == a.Length - 1) {
n = -1;
a = Console.ReadLine().Split();
}
n++;
return int.Parse(a[n]);
}
}
public long L {
get {
if (n == -1 || n == a.Length - 1) {
n = -1;
a = Console.ReadLine().Split();
}
n++;
return long.Parse(a[n]);
}
}
public double D {
get {
if (n == -1 || n == a.Length - 1) {
n = -1;
a = Console.ReadLine().Split();
}
n++;
return double.Parse(a[n]);
}
}
public string S {
get {
if (n == -1 || n == a.Length - 1) {
n = -1;
a = Console.ReadLine().Split();
}
n++;
return a[n];
}
}
public int[] Ia {
get {
if (n != -1 && n != a.Length - 1) {
m = n;
n = -1;
return Array.ConvertAll(a.Skip(m + 1).ToArray(), int.Parse);
}
return Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
}
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse);
}
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
}
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
static class Program {
const int mod = (int)1e9 + 7;
static void Main() {
Sc sc = new Sc();
int n = sc.I;
long ans = 0, a = 0, b = 0, c = 0;
for (int i = 0; i < n; i++) {
string s = sc.S;
for (int j = 0; j < s.Length - 1; j++) {
if (s[j] == 'A' && s[j + 1] == 'B') {
ans++;
}
}
if (s[s.Length - 1] == 'A') {
a++;
}
if (s[0] == 'B') {
b++;
}
if (s[s.Length - 1] == 'A' && s[0] == 'B') {
c++;
}
}
if (b == c && a == c && c != 0) {
ans--;
}
Console.WriteLine("{0}", ans + Math.Min(a, b));
}
}
public class Sc {
private string[] a;
private int n = -1, m = 0;
public int I {
get {
if (n == -1 || n == a.Length - 1) {
n = -1;
a = Console.ReadLine().Split();
}
n++;
return int.Parse(a[n]);
}
}
public long L {
get {
if (n == -1 || n == a.Length - 1) {
n = -1;
a = Console.ReadLine().Split();
}
n++;
return long.Parse(a[n]);
}
}
public double D {
get {
if (n == -1 || n == a.Length - 1) {
n = -1;
a = Console.ReadLine().Split();
}
n++;
return double.Parse(a[n]);
}
}
public string S {
get {
if (n == -1 || n == a.Length - 1) {
n = -1;
a = Console.ReadLine().Split();
}
n++;
return a[n];
}
}
public int[] Ia {
get {
if (n != -1 && n != a.Length - 1) {
m = n;
n = -1;
return Array.ConvertAll(a.Skip(m + 1).ToArray(), int.Parse);
}
return Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
}
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse);
}
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 739
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
var n = int.Parse(Console.ReadLine());
var ss = new string[n];
for (int i = 0; i < ss.Length; ++i)
ss[i] = Console.ReadLine();
int count = 0;
int b = 0;
int a = 0;
int ba = 0;
for (int i = 0; i < ss.Length; ++i) {
var s = ss[i];
var prev = ' ';
var isB = false;
for (int j = 0, length = s.Length; j < length; ++j) {
var c = s[j];
switch (c) {
case 'B':
switch (prev) {
case 'A':
++count;
break;
case ' ':
isB = true;
break;
}
break;
}
prev = c;
}
if (prev == 'A') {
if (isB)
++ba;
else
++a;
} else if (isB)
++b;
}
if (b > a) {
var tmp = b;
b = a;
a = tmp;
}
var adder = b + ba;
if (a == 0)
--adder;
Console.WriteLine(count + adder);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
var n = int.Parse(Console.ReadLine());
var ss = new string[n];
for (int i = 0; i < ss.Length; ++i)
ss[i] = Console.ReadLine();
int count = 0;
int b = 0;
int a = 0;
int ba = 0;
for (int i = 0; i < ss.Length; ++i) {
var s = ss[i];
var prev = ' ';
var isB = false;
for (int j = 0, length = s.Length; j < length; ++j) {
var c = s[j];
switch (c) {
case 'B':
switch (prev) {
case 'A':
++count;
break;
case ' ':
isB = true;
break;
}
break;
}
prev = c;
}
if (prev == 'A') {
if (isB)
++ba;
else
++a;
} else if (isB)
++b;
}
if (b > a) {
var tmp = b;
b = a;
a = tmp;
}
var adder = b + ba;
if (a == 0 && ba > 0)
--adder;
Console.WriteLine(count + adder);
}
}
|
[["+", 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
| 285
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DIVERTA2019C {
class Program {
static int includeOf(string src, string target) {
int count = 0;
int index = src.IndexOf(target, 0);
while (index >= 0) {
count++;
index = src.IndexOf(target, index + target.Length);
}
return count;
}
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var input = Enumerable.Range(0, n).Select(_ => Console.ReadLine()).ToList();
var includeCount = 0;
var endCount = 0;
var startCount = 0;
var bothCount = 0;
foreach (var s in input) {
// 文字列中のAB数
includeCount += includeOf(s, "AB");
// 末尾がA
var lastChar = s.Last();
if (lastChar == 'A') {
endCount++;
}
// 先頭がB
var startChar = s.First();
if (startChar == 'B') {
startCount++;
}
// 先頭がBで末尾がA
if (startChar == 'B' && lastChar == 'A') {
bothCount++;
}
}
var unionCount = Math.Min(startCount, endCount);
var output = includeCount + unionCount;
// 単純に数えるだけだと、「B***A」みたいな単語でおかしくなるので調整
if (output > 0 && (bothCount == Math.Max(startCount, endCount))) {
output--;
}
Console.WriteLine(output);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DIVERTA2019C {
class Program {
static int includeOf(string src, string target) {
int count = 0;
int index = src.IndexOf(target, 0);
while (index >= 0) {
count++;
index = src.IndexOf(target, index + target.Length);
}
return count;
}
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var input = Enumerable.Range(0, n).Select(_ => Console.ReadLine()).ToList();
var includeCount = 0;
var endCount = 0;
var startCount = 0;
var bothCount = 0;
foreach (var s in input) {
// 文字列中のAB数
includeCount += includeOf(s, "AB");
// 末尾がA
var lastChar = s.Last();
if (lastChar == 'A') {
endCount++;
}
// 先頭がB
var startChar = s.First();
if (startChar == 'B') {
startCount++;
}
// 先頭がBで末尾がA
if (startChar == 'B' && lastChar == 'A') {
bothCount++;
}
}
var unionCount = Math.Min(startCount, endCount);
var output = includeCount + unionCount;
// Console.WriteLine($"{output}, {includeCount}, {unionCount},
// {bothCount}");
// 単純に数えるだけだと、「B***A」みたいな単語でおかしくなるので調整
if (output > 0 && unionCount > 0 &&
(bothCount == Math.Max(startCount, endCount))) {
output--;
}
Console.WriteLine(output);
}
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
| 8
| 303
| 4
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections;
using System.Linq;
class Program {
static List<int> s = new List<int>();
static List<string> a = new List<string>();
static decimal result;
static StringBuilder sb = new StringBuilder();
static decimal N, M, K;
static void Main() {
Read1();
//(m+1)x=N
// m>0
// Nの約数で見ていく
for (int x = 1; (double)x < Math.Sqrt((double)N); x++) {
if (N % x == 0 && x * (x - 1) < N) {
result += N / x - 1;
}
}
Console.WriteLine(result.ToString());
}
static void Read1() // 1項
{
string tmp = Console.ReadLine();
N = decimal.Parse(tmp);
}
static void Read2() //複数項(項目数N)
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read3() // 1行複数項
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < tmp.Length; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read4() // NK1行
{
string[] tmp = Console.ReadLine().Split(' ');
N = int.Parse(tmp[0]);
K = int.Parse(tmp[1]);
}
static void Read5() // N行K項
{
for (int i = 0; i < N; i++) {
a.Add(Console.ReadLine());
}
}
}
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections;
using System.Linq;
class Program {
static List<int> s = new List<int>();
static List<string> a = new List<string>();
static decimal result;
static StringBuilder sb = new StringBuilder();
static decimal N, M, K;
static void Main() {
Read1();
//(m+1)x=N
// m>0
// Nの約数で見ていく
for (int x = 1; (double)x < Math.Sqrt((double)N); x++) {
if (N % x == 0 && x * (x + 1) < N) {
result += N / x - 1;
}
}
Console.WriteLine(result.ToString());
}
static void Read1() // 1項
{
string tmp = Console.ReadLine();
N = decimal.Parse(tmp);
}
static void Read2() //複数項(項目数N)
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read3() // 1行複数項
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < tmp.Length; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read4() // NK1行
{
string[] tmp = Console.ReadLine().Split(' ');
N = int.Parse(tmp[0]);
K = int.Parse(tmp[1]);
}
static void Read5() // N行K項
{
for (int i = 0; i < N; i++) {
a.Add(Console.ReadLine());
}
}
}
|
[["-", 12, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 17, 72]]
| 8
| 389
| 2
|
using System;
using System.Collections.Generic;
namespace diverta2019_D {
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
var L = new Dictionary<long, int>();
var sqrt = (int)Math.Ceiling(Math.Sqrt(N));
long ans = N - 1;
for (long i = 2; i <= sqrt; i++) {
if (N % i == 0) {
var t = N / i;
var n = t - 1;
if (n > 0 && N % n == N / n)
ans += n;
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
namespace diverta2019_D {
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
var L = new Dictionary<long, int>();
var sqrt = (int)Math.Ceiling(Math.Sqrt(N));
long ans = 0;
for (long i = 1; i <= sqrt; i++) {
if (N % i == 0) {
var t = N / i;
var n = t - 1;
if (n > 0 && N % n == N / n)
ans += n;
}
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 146
| 6
|
using System;
class Diverta_2019_D {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long sum = 0;
long sqrt = (int)Math.Sqrt(N);
for (long i = 1; i < sqrt; i++) {
long a = (N - i) / i;
if ((N - i) % i == 0)
sum += a;
}
Console.WriteLine(sum);
}
}
|
using System;
class Diverta_2019_D {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long sum = 0;
long sqrt = (int)Math.Sqrt(N);
for (long i = 1; i < sqrt + 1; i++) {
long a = (N - i) / i;
if ((N - i) % i == 0 && i < a)
sum += a;
}
Console.WriteLine(sum);
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 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, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 100
| 6
|
using System;
namespace ConsoleApp23 {
class Program {
static void Main(string[] args) {
long x = long.Parse(Console.ReadLine());
long N = (long)System.Math.Sqrt(x);
long Ans = 0;
// Console.WriteLine(N);
for (int n = 1; n <= N; ++n) {
if (x % n == 0 && x / n != n) {
Ans += x / n - 1;
// Console.WriteLine(n-1);
}
}
Console.WriteLine(Ans);
}
}
}
|
using System;
namespace ConsoleApp23 {
class Program {
static void Main(string[] args) {
long x = long.Parse(Console.ReadLine());
long N = (long)System.Math.Sqrt(x);
long Ans = 0;
// Console.WriteLine(N);
for (int n = 1; n <= N; ++n) {
if (x % n == 0 && x / n - 1 >= N + 1) {
Ans += x / n - 1;
// Console.WriteLine(n-1);
}
}
Console.WriteLine(Ans);
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203]]
| 8
| 105
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace D {
class Program {
static void Main(string[] args) {
long n = RLong();
int rootN = (int)Math.Sqrt(n);
long cnt = 0;
for (int r = 1; r <= rootN + 1; r++) {
long pq = n - r;
long p = pq / r;
if (n == r * (p + 1) && n % r == 0 && pq % r == 0 && p >= rootN) {
cnt += p;
}
}
Console.WriteLine(cnt);
}
static string RSt() { return Console.ReadLine(); }
static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
static double RDouble() { return double.Parse(Console.ReadLine()); }
static string[] RArSt(char sep = ' ') {
return Console.ReadLine().Trim().Split(sep);
}
static int[] RArInt(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => int.Parse(e));
}
static long[] RArLong(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => long.Parse(e));
}
static double[] RArDouble(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => double.Parse(e));
}
static string WAr<T>(IEnumerable<T> array, string sep = " ") {
return string.Join(sep, array.Select(x => x.ToString()).ToArray());
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace D {
class Program {
static void Main(string[] args) {
long n = RLong();
int rootN = (int)Math.Sqrt(n);
long cnt = 0;
for (int r = 1; r <= rootN + 1; r++) {
long pq = n - r;
long p = pq / r;
if (n == r * (p + 1) && n % r == 0 && pq % r == 0 && p > r) {
cnt += p;
}
}
Console.WriteLine(cnt);
}
static string RSt() { return Console.ReadLine(); }
static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
static double RDouble() { return double.Parse(Console.ReadLine()); }
static string[] RArSt(char sep = ' ') {
return Console.ReadLine().Trim().Split(sep);
}
static int[] RArInt(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => int.Parse(e));
}
static long[] RArLong(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => long.Parse(e));
}
static double[] RArDouble(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => double.Parse(e));
}
static string WAr<T>(IEnumerable<T> array, string sep = " ") {
return string.Join(sep, array.Select(x => x.ToString()).ToArray());
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 429
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static long N;
public static void Main(string[] args) {
N = Input.NextLong();
long ans = 0;
for (int i = 1; i < N; i++) {
long a = (N - i) / i;
if (i > a)
break;
long a_mod = (N - i) % i;
if (a_mod == 0) {
ans += a;
}
}
Console.WriteLine(ans);
}
}
public static 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 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;
class Program {
static long N;
public static void Main(string[] args) {
N = Input.NextLong();
long ans = 0;
for (int i = 1; i < N; i++) {
long a = (N - i) / i;
if (i >= a)
break;
long a_mod = (N - i) % i;
if (a_mod == 0) {
ans += a;
}
}
Console.WriteLine(ans);
}
}
public static 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 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, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 400
| 2
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
;
long n = long.Parse(Console.ReadLine());
long ans = 0;
for (long i = 1;; i++) {
if (n / i < i)
break;
if (n % i == 0)
ans += n / i - 1;
}
Console.WriteLine(ans);
}
}
// mcs Main.cs
// mono Main.exe
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
;
long n = long.Parse(Console.ReadLine());
long ans = 0;
for (long i = 1;; i++) {
if (n / i - 1 < i + 1)
break;
if (n % i == 0)
ans += n / i - 1;
}
Console.WriteLine(ans);
}
}
// mcs Main.cs
// mono Main.exe
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 93
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.diverta2019 {
class D {
static void Main(string[] args) { Method(args); }
static void Method(string[] args) {
long n = ReadLong();
long res = 0;
for (long i = 1; i <= n / i; i++) {
if (n % i > 0)
continue;
long m = n / i - 1;
if (m < i)
continue;
res += m;
}
WriteLine(res);
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.diverta2019 {
class D {
static void Main(string[] args) { Method(args); }
static void Method(string[] args) {
long n = ReadLong();
long res = 0;
for (long i = 1; i <= n / i; i++) {
if (n % i > 0)
continue;
long m = n / i - 1;
if (i < m)
res += m;
}
WriteLine(res);
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35]]
| 8
| 317
| 6
|
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;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var a = new int[n + 1];
for (int i = 0; i < n; i++)
a[i + 1] = a[i] ^ ri;
var dp = new ModInt[1 << 20, 2];
var zero = new int[1 << 20];
for (int x = 0; x < 1 << 20; x++) {
dp[x, 0] = 1;
zero[x] = 10000000;
}
var z = 0;
for (int i = 1; i <= n; i++) {
var x = a[i];
if (a[i] == 0)
z++;
else {
dp[x, 0] += dp[x, 1] * Max(0, z - zero[x]);
dp[x, 1] += dp[x, 0];
zero[x] = z;
}
}
if (a.Last() == 0) {
ModInt ans = 0;
ans += ModInt.Pow(2, z - 1);
Debug.WriteLine(ans);
for (int x = 1; x < 1 << 20; x++)
ans += dp[x, 1];
Console.WriteLine(ans);
} else {
Console.WriteLine(dp[a.Last(), 1]);
}
}
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 < a.Length; ++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 void Main() {
Console.SetOut(new Program.IO.Printer(
Console.OpenStandardOutput()) { AutoFlush = true });
var solver = new Program.Solver();
var t = new System.Threading.Thread(solver.Solve, 50000000);
t.Start();
t.Join();
// 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
#region ModInt
/// <summary>
/// [0,<see cref="Mod"/>) までの値を取るような数
/// </summary>
public struct ModInt {
/// <summary>
/// 剰余を取る値.
/// </summary>
public const long Mod = (int)1e9 + 7;
/// <summary>
/// 実際の数値.
/// </summary>
public long num;
/// <summary>
/// 値が <paramref name="n"/> であるようなインスタンスを構築します.
/// </summary>
/// <param name="n">インスタンスが持つ値</param>
/// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref
/// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/>
/// を渡してください.このコンストラクタは O(1) で実行されます.</remarks>
public ModInt(long n) { num = n; }
/// <summary>
/// このインスタンスの数値を文字列に変換します.
/// </summary>
/// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10
/// 進表記したもの.</returns>
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
/// <summary>
/// 与えられた 2 つの数値からべき剰余を計算します.
/// </summary>
/// <param name="v">べき乗の底</param>
/// <param name="k">べき指数</param>
/// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns>
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
/// <summary>
/// 与えられた 2 つの数値からべき剰余を計算します.
/// </summary>
/// <param name="v">べき乗の底</param>
/// <param name="k">べき指数</param>
/// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns>
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
/// <summary>
/// 与えられた数の逆元を計算します.
/// </summary>
/// <param name="v">逆元を取る対象となる数</param>
/// <returns>逆元となるような値</returns>
/// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を
/// O(log N) で計算します.</remarks>
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#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;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var a = new int[n + 1];
for (int i = 0; i < n; i++)
a[i + 1] = a[i] ^ ri;
var dp = new ModInt[1 << 20, 2];
var zero = new int[1 << 20];
for (int x = 0; x < 1 << 20; x++) {
dp[x, 0] = 1;
zero[x] = 10000000;
}
var z = 0;
for (int i = 1; i <= n; i++) {
var x = a[i];
if (a[i] == 0)
z++;
else {
dp[x, 0] += dp[x, 1] * Max(0, z - zero[x]);
dp[x, 1] += dp[x, 0];
zero[x] = z;
}
}
if (a.Last() == 0) {
ModInt ans = 0;
ans += ModInt.Pow(2, z - 1);
Debug.WriteLine(ans);
for (int x = 1; x < 1 << 20; x++)
ans += dp[x, 1];
Console.WriteLine(ans);
} else {
Console.WriteLine(dp[a.Last(), 0]);
}
}
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 < a.Length; ++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 void Main() {
Console.SetOut(new Program.IO.Printer(
Console.OpenStandardOutput()) { AutoFlush = true });
var solver = new Program.Solver();
var t = new System.Threading.Thread(solver.Solve, 50000000);
t.Start();
t.Join();
// 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
#region ModInt
/// <summary>
/// [0,<see cref="Mod"/>) までの値を取るような数
/// </summary>
public struct ModInt {
/// <summary>
/// 剰余を取る値.
/// </summary>
public const long Mod = (int)1e9 + 7;
/// <summary>
/// 実際の数値.
/// </summary>
public long num;
/// <summary>
/// 値が <paramref name="n"/> であるようなインスタンスを構築します.
/// </summary>
/// <param name="n">インスタンスが持つ値</param>
/// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref
/// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/>
/// を渡してください.このコンストラクタは O(1) で実行されます.</remarks>
public ModInt(long n) { num = n; }
/// <summary>
/// このインスタンスの数値を文字列に変換します.
/// </summary>
/// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10
/// 進表記したもの.</returns>
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
/// <summary>
/// 与えられた 2 つの数値からべき剰余を計算します.
/// </summary>
/// <param name="v">べき乗の底</param>
/// <param name="k">べき指数</param>
/// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns>
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
/// <summary>
/// 与えられた 2 つの数値からべき剰余を計算します.
/// </summary>
/// <param name="v">べき乗の底</param>
/// <param name="k">べき指数</param>
/// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns>
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
/// <summary>
/// 与えられた数の逆元を計算します.
/// </summary>
/// <param name="v">逆元を取る対象となる数</param>
/// <returns>逆元となるような値</returns>
/// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を
/// O(log N) で計算します.</remarks>
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 1,414
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Z {
static void Main() => new K();
}
class K {
int[] G => ReadLine().Split().Select(int.Parse).ToArray();
static T[] MakeArray<T>(int n, Func<int, T> f) {
var a = new T[n];
for (var i = 0; i < n; i++)
a[i] = f(i);
return a;
}
static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) {
var a = new T[n];
a[0] = a0;
for (var i = 1; i < n; i++)
a[i] = f(i, a[i - 1]);
return a;
}
static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) {
var s = new T[a.Count + 1];
s[0] = zero;
for (var i = 0; i < a.Count; i++)
s[i + 1] = f(s[i], a[i]);
return s;
}
static int[] Accumulate(IList<int> a) {
var s = new int[a.Count + 1];
for (var i = 0; i < a.Count; i++)
s[i + 1] = s[i] + a[i];
return s;
}
const int MOD = 1000000007;
public K() {
var N = G[0];
var A = G;
var sum = Accumulate(A, 0, (a, b) => a ^ b);
var zero = Accumulate(sum.Select(t => t == 0 ? 1 : 0).ToList());
Func<IList<int>, int[]> getZero = l =>
MakeArray(l.Count - 1, i => zero[l[i + 1]] - zero[l[i]]);
var dic = Indexes(sum);
if (sum[N] != 0)
WriteLine(DP(getZero(dic[-1])).Last());
else {
var ans = Pow(2, zero[N + 1] - 2, MOD);
foreach (var t in dic)
if (t.Key != 0)
ans = (ans + DP(getZero(t.Value)).Sum()) % MOD;
WriteLine(ans % MOD);
}
}
static Dictionary<int, List<int>> Indexes(IList<int> x) {
var dic = new Dictionary<int, List<int>>();
for (var i = 0; i < x.Count; i++) {
if (!dic.ContainsKey(x[i]))
dic[x[i]] = new List<int>();
dic[x[i]].Add(i);
}
return dic;
}
static long[] DP(IList<int> zs) {
var L = zs.Count;
var dp = new long[L + 1];
dp[0] = 1;
var sum = 1L;
for (var j = 0; j < L; j++) {
dp[j + 1] = (dp[j] + zs[j] * sum % MOD) % MOD;
sum = (sum + dp[j + 1]) % MOD;
}
return dp;
}
public static long Pow(long a, long b, long mod) {
long p = 1L, x = a;
while (b > 0) {
if ((b & 1L) == 1L)
p = p * x % mod;
b >>= 1;
x = x * x % mod;
}
return p;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Z {
static void Main() => new K();
}
class K {
int[] G => ReadLine().Split().Select(int.Parse).ToArray();
static T[] MakeArray<T>(int n, Func<int, T> f) {
var a = new T[n];
for (var i = 0; i < n; i++)
a[i] = f(i);
return a;
}
static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) {
var a = new T[n];
a[0] = a0;
for (var i = 1; i < n; i++)
a[i] = f(i, a[i - 1]);
return a;
}
static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) {
var s = new T[a.Count + 1];
s[0] = zero;
for (var i = 0; i < a.Count; i++)
s[i + 1] = f(s[i], a[i]);
return s;
}
static int[] Accumulate(IList<int> a) {
var s = new int[a.Count + 1];
for (var i = 0; i < a.Count; i++)
s[i + 1] = s[i] + a[i];
return s;
}
const int MOD = 1000000007;
public K() {
var N = G[0];
var A = G;
var sum = Accumulate(A, 0, (a, b) => a ^ b);
var zero = Accumulate(sum.Select(t => t == 0 ? 1 : 0).ToList());
Func<IList<int>, int[]> getZero = l =>
MakeArray(l.Count - 1, i => zero[l[i + 1]] - zero[l[i]]);
var dic = Indexes(sum);
if (sum[N] != 0)
WriteLine(DP(getZero(dic[sum[N]])).Last());
else {
var ans = Pow(2, zero[N + 1] - 2, MOD);
foreach (var t in dic)
if (t.Key != 0)
ans = (ans + DP(getZero(t.Value)).Sum()) % MOD;
WriteLine(ans % MOD);
}
}
static Dictionary<int, List<int>> Indexes(IList<int> x) {
var dic = new Dictionary<int, List<int>>();
for (var i = 0; i < x.Count; i++) {
if (!dic.ContainsKey(x[i]))
dic[x[i]] = new List<int>();
dic[x[i]].Add(i);
}
return dic;
}
static long[] DP(IList<int> zs) {
var L = zs.Count;
var dp = new long[L + 1];
dp[0] = 1;
var sum = 1L;
for (var j = 0; j < L; j++) {
dp[j + 1] = (dp[j] + zs[j] * sum % MOD) % MOD;
sum = (sum + dp[j + 1]) % MOD;
}
return dp;
}
public static long Pow(long a, long b, long mod) {
long p = 1L, x = a;
while (b > 0) {
if ((b & 1L) == 1L)
p = p * x % mod;
b >>= 1;
x = x * x % mod;
}
return p;
}
}
|
[["-", 0, 204, 206, 207, 0, 28, 0, 241, 0, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 241, 0, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73]]
| 8
| 835
| 6
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Contest {
class Program {
private int H, W;
private char[][] A;
private int[] nextY = new int[] { 1, 0, -1, 0 };
private int[] nextX = new int[] { 0, 1, 0, -1 };
public void Solve() {
var sc = new Scanner();
H = sc.NextInt();
W = sc.NextInt();
A = new char [H][];
for (int i = 0; i < H; i++) {
A[i] = sc.Next().ToArray();
}
var hq = new Queue<int>();
var wq = new Queue<int>();
var cnt = new int[H, W];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cnt[i, j] = -1;
if (A[i][j] == '#') {
cnt[i, j] = 0;
hq.Enqueue(i);
wq.Enqueue(j);
}
}
}
while (hq.Count > 0) {
int h = hq.Dequeue();
int w = wq.Dequeue();
for (int i = 0; i < 4; i++) {
int nY = h + nextY[i];
int nX = w + nextX[i];
if (nY < 0 || nY >= H)
continue;
if (nX < 0 || nX >= H)
continue;
if (cnt[nY, nX] != -1)
continue;
cnt[nY, nX] = cnt[h, w] + 1;
hq.Enqueue(nY);
wq.Enqueue(nX);
}
}
int ans = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
ans = Math.Max(ans, cnt[i, j]);
}
}
Console.WriteLine(ans);
}
static void Main() => new Program().Solve();
}
}
class Scanner {
public Scanner() {
_stream = new StreamReader(Console.OpenStandardInput());
_pos = 0;
_line = new string[0];
_separator = ' ';
}
private char _separator;
private StreamReader _stream;
private int _pos;
private string[] _line;
#region get a element
public string Next() {
if (_pos >= _line.Length) {
_line = _stream.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 convert array
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 get array
public string[] Array() {
if (_pos >= _line.Length)
_line = _stream.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;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Contest {
class Program {
private int H, W;
private char[][] A;
private int[] nextY = new int[] { 1, 0, -1, 0 };
private int[] nextX = new int[] { 0, 1, 0, -1 };
public void Solve() {
var sc = new Scanner();
H = sc.NextInt();
W = sc.NextInt();
A = new char [H][];
for (int i = 0; i < H; i++) {
A[i] = sc.Next().ToArray();
}
var hq = new Queue<int>();
var wq = new Queue<int>();
var cnt = new int[H, W];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cnt[i, j] = -1;
if (A[i][j] == '#') {
cnt[i, j] = 0;
hq.Enqueue(i);
wq.Enqueue(j);
}
}
}
while (hq.Count > 0) {
int h = hq.Dequeue();
int w = wq.Dequeue();
for (int i = 0; i < 4; i++) {
int nY = h + nextY[i];
int nX = w + nextX[i];
if (nY < 0 || nY >= H)
continue;
if (nX < 0 || nX >= W)
continue;
if (cnt[nY, nX] != -1)
continue;
cnt[nY, nX] = cnt[h, w] + 1;
hq.Enqueue(nY);
wq.Enqueue(nX);
}
}
int ans = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
ans = Math.Max(ans, cnt[i, j]);
}
}
Console.WriteLine(ans);
}
static void Main() => new Program().Solve();
}
}
class Scanner {
public Scanner() {
_stream = new StreamReader(Console.OpenStandardInput());
_pos = 0;
_line = new string[0];
_separator = ' ';
}
private char _separator;
private StreamReader _stream;
private int _pos;
private string[] _line;
#region get a element
public string Next() {
if (_pos >= _line.Length) {
_line = _stream.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 convert array
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 get array
public string[] Array() {
if (_pos >= _line.Length)
_line = _stream.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, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 917
| 2
|
using System;
using static System.Console;
using System.Text;
using System.Linq;
using static System.Math;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program {
public static cp alg;
public static int h;
public static int w;
public static string[] A;
public static List<int[]> V;
static void Main(string[] args) {
alg = new cp();
var hw = alg.inputSplitInt();
h = hw[0];
w = hw[1];
A = alg.inputLinesString(h);
var cost = new int[h, w];
for (int a = 0; a < h; a++) {
for (int b = 0; b < w; b++) {
cost[a, b] = -1;
}
}
var que = new Queue<int[]>();
//最初の#をキューに入れる
int count = 0;
for (int a = 0; a < h; a++) {
for (int b = 0; b < w; b++) {
if (A[a][b] == '#') {
que.Enqueue(new int[2] { b, a });
cost[a, b] = 0;
}
}
}
while (que.Count > 0) {
var now = que.Dequeue();
var x = now[0];
var y = now[1];
var dx = new int[] { -1, 0, 1, 0 };
var dy = new int[] { 0, -1, 0, 1 };
for (int a = 0; a < 4; a++) {
if (x + dx[a] < 0 || x + dx[a] >= w || y + dy[a] < 0 ||
y + dy[a] >= h || cost[y + dy[a], x + dx[a]] == -1)
continue;
que.Enqueue(new int[] { x + dx[a], y + dy[a] });
cost[y + dy[a], x + dx[a]] = cost[y, x] + 1;
count = Math.Max(count, cost[y, x] + 1);
}
}
WriteLine(count);
}
}
class cp {
public cp() {}
public int GCD(int a, int b) { return a % b == 0 ? b : GCD(b, a % b); }
public int LCM(int a, int b) { return a * b / GCD(a, b); }
public int countChar(string s, string key) {
return s.Length - s.Replace(key, "").Length;
}
public string Yn(bool f) {
if (f) {
return "Yes";
} else {
return "No";
}
}
public string YN(bool f) {
if (f) {
return "YES";
} else {
return "NO";
}
}
public string yn(bool f) {
if (f) {
return "yes";
} else {
return "no";
}
}
public void inputSkip() {
ReadLine();
return;
}
public string inputString() { return ReadLine(); }
public string[] inputSplitString() { return ReadLine().Split(); }
public string[] inputLinesString(int len) {
var arr = new string[len];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine();
}
return arr;
}
public string[][] inputJaggedArrayString(int len) {
var arr = new string[len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split();
}
return arr;
}
public int inputInt() { return int.Parse(ReadLine()); }
public int[] inputSplitInt() {
return ReadLine().Split().Select(i => int.Parse(i)).ToArray();
}
public int[] inputLinesInt(int len) {
var arr = new int[len];
for (int a = 0; a < len; a++) {
arr[a] = int.Parse(ReadLine());
}
return arr;
}
public int[][] inputJaggedArrayInt(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 inputLong() { return long.Parse(ReadLine()); }
public long[] inputSplitLong() {
return ReadLine().Split().Select(i => long.Parse(i)).ToArray();
}
public long[] inputLinesLong(int len) {
var arr = new long[len];
for (int a = 0; a < len; a++) {
arr[a] = long.Parse(ReadLine());
}
return arr;
}
public long[][] inputJaggedArrayLong(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 inputDouble() { return double.Parse(ReadLine()); }
public double[] inputSplitDouble() {
return ReadLine().Split().Select(i => double.Parse(i)).ToArray();
}
public double[] inputLinesDouble(int len) {
var arr = new double[len];
for (int a = 0; a < len; a++) {
arr[a] = double.Parse(ReadLine());
}
return arr;
}
public double[][] inputJaggedArrayDouble(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 static System.Console;
using System.Text;
using System.Linq;
using static System.Math;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program {
public static cp alg;
public static int h;
public static int w;
public static string[] A;
public static List<int[]> V;
static void Main(string[] args) {
alg = new cp();
var hw = alg.inputSplitInt();
h = hw[0];
w = hw[1];
A = alg.inputLinesString(h);
var cost = new int[h, w];
for (int a = 0; a < h; a++) {
for (int b = 0; b < w; b++) {
cost[a, b] = -1;
}
}
var que = new Queue<int[]>();
//最初の#をキューに入れる
int count = 0;
for (int a = 0; a < h; a++) {
for (int b = 0; b < w; b++) {
if (A[a][b] == '#') {
que.Enqueue(new int[2] { b, a });
cost[a, b] = 0;
}
}
}
while (que.Count > 0) {
var now = que.Dequeue();
var x = now[0];
var y = now[1];
var dx = new int[] { -1, 0, 1, 0 };
var dy = new int[] { 0, -1, 0, 1 };
for (int a = 0; a < 4; a++) {
if (x + dx[a] < 0 || x + dx[a] >= w || y + dy[a] < 0 ||
y + dy[a] >= h || cost[y + dy[a], x + dx[a]] > -1)
continue;
que.Enqueue(new int[] { x + dx[a], y + dy[a] });
cost[y + dy[a], x + dx[a]] = cost[y, x] + 1;
count = Math.Max(count, cost[y, x] + 1);
}
}
WriteLine(count);
}
}
class cp {
public cp() {}
public int GCD(int a, int b) { return a % b == 0 ? b : GCD(b, a % b); }
public int LCM(int a, int b) { return a * b / GCD(a, b); }
public int countChar(string s, string key) {
return s.Length - s.Replace(key, "").Length;
}
public string Yn(bool f) {
if (f) {
return "Yes";
} else {
return "No";
}
}
public string YN(bool f) {
if (f) {
return "YES";
} else {
return "NO";
}
}
public string yn(bool f) {
if (f) {
return "yes";
} else {
return "no";
}
}
public void inputSkip() {
ReadLine();
return;
}
public string inputString() { return ReadLine(); }
public string[] inputSplitString() { return ReadLine().Split(); }
public string[] inputLinesString(int len) {
var arr = new string[len];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine();
}
return arr;
}
public string[][] inputJaggedArrayString(int len) {
var arr = new string[len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split();
}
return arr;
}
public int inputInt() { return int.Parse(ReadLine()); }
public int[] inputSplitInt() {
return ReadLine().Split().Select(i => int.Parse(i)).ToArray();
}
public int[] inputLinesInt(int len) {
var arr = new int[len];
for (int a = 0; a < len; a++) {
arr[a] = int.Parse(ReadLine());
}
return arr;
}
public int[][] inputJaggedArrayInt(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 inputLong() { return long.Parse(ReadLine()); }
public long[] inputSplitLong() {
return ReadLine().Split().Select(i => long.Parse(i)).ToArray();
}
public long[] inputLinesLong(int len) {
var arr = new long[len];
for (int a = 0; a < len; a++) {
arr[a] = long.Parse(ReadLine());
}
return arr;
}
public long[][] inputJaggedArrayLong(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 inputDouble() { return double.Parse(ReadLine()); }
public double[] inputSplitDouble() {
return ReadLine().Split().Select(i => double.Parse(i)).ToArray();
}
public double[] inputLinesDouble(int len) {
var arr = new double[len];
for (int a = 0; a < len; a++) {
arr[a] = double.Parse(ReadLine());
}
return arr;
}
public double[][] inputJaggedArrayDouble(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, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47]]
| 8
| 1,353
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
class Program {
static void Main() {
int[] HW =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int H = HW[0];
int W = HW[1];
char[] A = new char[H * W];
for (int i = 0; i < H; i++) {
var line = Console.ReadLine().ToArray();
line.CopyTo(A, i * W);
}
var Blacks = A.Select((c, i) => new { c, i })
.Where(itm => itm.c == '#')
.Select(itm => itm.i)
.ToArray();
int[] MAP = new int[H * W];
for (int i = 0; i < MAP.Length; i++)
MAP[i] = -1;
Queue<int> q = new Queue<int>();
foreach (var black in Blacks) {
MAP[black] = 0;
q.Enqueue(black);
}
while (q.Any()) {
var pt = q.Dequeue();
var x = pt % W;
var y = pt / W;
if (x + 1 < W && MAP[W * y + (x + 1)] == -1) {
MAP[W * y + (x + 1)] = MAP[pt] + 1;
q.Enqueue(W * y + (x + 1));
}
if (x - 1 > 0 && MAP[W * y + (x - 1)] == -1) {
MAP[W * y + (x - 1)] = MAP[pt] + 1;
q.Enqueue(W * y + (x - 1));
}
if (y + 1 < H && MAP[W * (y + 1) + x] == -1) {
MAP[W * (y + 1) + x] = MAP[pt] + 1;
q.Enqueue(W * (y + 1) + x);
}
if (y - 1 > 0 && MAP[W * (y - 1) + x] == -1) {
MAP[W * (y - 1) + x] = MAP[pt] + 1;
q.Enqueue(W * (y - 1) + x);
}
}
Console.WriteLine(MAP.Max());
}
}
static class MathUtil {
public static IEnumerable<IEnumerable<int>> GetPermutation(int n) {
if (n == 0) {
yield return Single(0);
yield break;
}
for (int i = 0; i <= n; i++) {
foreach (var x in GetPermutation(n - 1)) {
yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
}
}
}
private static IEnumerable<int> Single(int x) { yield return x; }
public static IEnumerable<int> EnumeratePrimeNumbers() {
List<int> primes = new List<int>() { 2 };
yield return 2;
for (int i = 3; i < int.MaxValue; i++) {
bool isPrime = true;
int Sqrt = (int)Math.Sqrt(i) + 1;
foreach (var prime in primes) {
if (prime > Sqrt) {
break;
}
if (i % prime == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.Add(i);
yield return i;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
class Program {
static void Main() {
int[] HW =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int H = HW[0];
int W = HW[1];
char[] A = new char[H * W];
for (int i = 0; i < H; i++) {
var line = Console.ReadLine().ToArray();
line.CopyTo(A, i * W);
}
var Blacks = A.Select((c, i) => new { c, i })
.Where(itm => itm.c == '#')
.Select(itm => itm.i)
.ToArray();
int[] MAP = new int[H * W];
for (int i = 0; i < MAP.Length; i++)
MAP[i] = -1;
Queue<int> q = new Queue<int>();
foreach (var black in Blacks) {
MAP[black] = 0;
q.Enqueue(black);
}
while (q.Any()) {
var pt = q.Dequeue();
var x = pt % W;
var y = pt / W;
if (x + 1 < W && MAP[W * y + (x + 1)] == -1) {
MAP[W * y + (x + 1)] = MAP[pt] + 1;
q.Enqueue(W * y + (x + 1));
}
if (x - 1 >= 0 && MAP[W * y + (x - 1)] == -1) {
MAP[W * y + (x - 1)] = MAP[pt] + 1;
q.Enqueue(W * y + (x - 1));
}
if (y + 1 < H && MAP[W * (y + 1) + x] == -1) {
MAP[W * (y + 1) + x] = MAP[pt] + 1;
q.Enqueue(W * (y + 1) + x);
}
if (y - 1 >= 0 && MAP[W * (y - 1) + x] == -1) {
MAP[W * (y - 1) + x] = MAP[pt] + 1;
q.Enqueue(W * (y - 1) + x);
}
}
Console.WriteLine(MAP.Max());
}
}
static class MathUtil {
public static IEnumerable<IEnumerable<int>> GetPermutation(int n) {
if (n == 0) {
yield return Single(0);
yield break;
}
for (int i = 0; i <= n; i++) {
foreach (var x in GetPermutation(n - 1)) {
yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
}
}
}
private static IEnumerable<int> Single(int x) { yield return x; }
public static IEnumerable<int> EnumeratePrimeNumbers() {
List<int> primes = new List<int>() { 2 };
yield return 2;
for (int i = 3; i < int.MaxValue; i++) {
bool isPrime = true;
int Sqrt = (int)Math.Sqrt(i) + 1;
foreach (var prime in primes) {
if (prime > Sqrt) {
break;
}
if (i % prime == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.Add(i);
yield return i;
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20]]
| 8
| 792
| 4
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program {
static long mod = 998244353;
static void Main(string[] args) {
char[] cs = new char[] { ' ' };
// 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());
// string res="";
long res = 0;
// int n = int.Parse(Console.ReadLine());
int[] vals = parseAry(Console.ReadLine().Split(cs));
int x = vals[0];
int y = vals[1];
List<int[]> now = new List<int[]>();
List<int[]> next = new List<int[]>();
string strs = "";
int[,] map = new int[y, x];
for (int i = 0; i < y; i++) {
strs = Console.ReadLine();
for (int k = 0; k < strs.Length; k++) {
if (strs[k] == '#') {
map[i, k] = '#';
now.Add(new int[] { i, k });
} else {
map[i, k] = '.';
}
}
}
int[,] nextmap = (int[,])map.Clone();
;
int[] DX = new int[4] { -1, 1, 0, 0 };
int[] DY = new int[4] { 0, 0, -1, 1 };
while (true) {
for (int i = 0; i < now.Count; i++) {
for (int d = 0; d < DX.Length; d++) {
int xx = now[i][1] + DX[d];
int yy = now[i][0] + DY[d];
if (0 <= yy && yy < y && 0 <= xx && xx < x) {
if (map[yy, xx] == '.') {
map[yy, xx] = '#';
next.Add(new int[2] { yy, xx });
}
}
}
}
res++;
if (next.Count == 0) {
break;
}
now = new List<int[]>();
for (int i = 0; i < next.Count; i++) {
now.Add((int[])next[i].Clone());
}
next = new List<int[]>();
}
res--;
Console.WriteLine(res);
return;
}
// 文字列strをindex番目からdで上書き
static string strOverWrite(string str, int i, string s) {
return str.Remove(i, s.Length).Insert(i, s);
}
// 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;
using System.Collections.Generic;
class Program {
static long mod = 998244353;
static void Main(string[] args) {
char[] cs = new char[] { ' ' };
// 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());
// string res="";
long res = 0;
// int n = int.Parse(Console.ReadLine());
int[] vals = parseAry(Console.ReadLine().Split(cs));
int y = vals[0];
int x = vals[1];
List<int[]> now = new List<int[]>();
List<int[]> next = new List<int[]>();
string strs = "";
int[,] map = new int[y, x];
for (int i = 0; i < y; i++) {
strs = Console.ReadLine();
for (int k = 0; k < strs.Length; k++) {
if (strs[k] == '#') {
map[i, k] = '#';
now.Add(new int[] { i, k });
} else {
map[i, k] = '.';
}
}
}
int[,] nextmap = (int[,])map.Clone();
;
int[] DX = new int[4] { -1, 1, 0, 0 };
int[] DY = new int[4] { 0, 0, -1, 1 };
while (true) {
for (int i = 0; i < now.Count; i++) {
for (int d = 0; d < DX.Length; d++) {
int xx = now[i][1] + DX[d];
int yy = now[i][0] + DY[d];
if (0 <= yy && yy < y && 0 <= xx && xx < x) {
if (map[yy, xx] == '.') {
map[yy, xx] = '#';
next.Add(new int[2] { yy, xx });
}
}
}
}
res++;
if (next.Count == 0) {
break;
}
now = new List<int[]>();
for (int i = 0; i < next.Count; i++) {
now.Add((int[])next[i].Clone());
}
next = new List<int[]>();
}
res--;
Console.WriteLine(res);
return;
}
// 文字列strをindex番目からdで上書き
static string strOverWrite(string str, int i, string s) {
return str.Remove(i, s.Length).Insert(i, s);
}
// 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, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22]]
| 8
| 771
| 4
|
using System;
using System.Linq;
class B {
static void Main() {
Console.ReadLine();
var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
var t = h[0];
Console.WriteLine(h.Skip(1).Count(x => {
var b = x >= t;
t = Math.Max(t, x);
return b;
}));
}
}
|
using System;
using System.Linq;
class B {
static void Main() {
Console.ReadLine();
var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
var t = h[0];
Console.WriteLine(1 + h.Skip(1).Count(x => {
var b = x >= t;
t = Math.Max(t, x);
return b;
}));
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
| 8
| 98
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;
namespace AtCoder_1 {
class Program {
static void Main(string[] args) {
var n = CinT();
var ab = CinTAr();
int m = 0;
int c = 0;
for (int i = 0; i < n; i++) {
if (m < ab[i]) {
m = ab[i];
c++;
}
}
Cout(c);
Cin();
}
static int GCD(int a, int b) {
if (a < b) {
swap(ref a, ref b);
}
if (a % b == 0) {
return b;
} else {
return GCD(b, a % b);
}
}
static void swap<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static readonly int MOD1E9 = 10000007;
static bool isInt(double d) { return (int)d == d; }
static string Cin() { return ReadLine(); }
static string[] CinAr() { return ReadLine().Split(' '); }
static int CinT() { return S2i(Cin()); }
static int[] CinTAr() {
return CinAr().Select((x, i) => { return S2i(x); }).ToArray();
}
static long CinL() { return S2L(Cin()); }
static long[] CinLAr() {
return CinAr().Select((x, i) => { return S2L(x); }).ToArray();
}
static double CinD() { return S2D(Cin()); }
static double[] CinDAr() {
return CinAr().Select((x, i) => { return S2D(x); }).ToArray();
}
static int S2i(string s) { return int.Parse(s); }
static long S2L(string s) { return long.Parse(s); }
static double S2D(string s) { return double.Parse(s); }
static void Cout(object s) { WriteLine(s); }
static int[] yakusuu(int n) {
if (n == 1) {
return new int[] { 1 };
}
HashSet<int> res = new HashSet<int>();
for (int i = 1; i < Math.Ceiling(n / 2.0); i++) {
if (n % i == 0) {
res.Add(i);
res.Add(n / i);
}
}
return res.ToArray();
}
/// <summary>
/// Debug時のみの使用を推奨
/// </summary>
/// <typeparam name="Type"></typeparam>
/// <param name="types"></param>
static void CoutAr<Type>(IEnumerable<Type> types) {
string text = "";
foreach (var i in types) {
text += " " + i;
}
WriteLine(text.Substring(1));
}
public static long nCr(int n, int r) {
// naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
return nPr(n, r) / Factorial(r);
}
public static long nPr(int n, int r) {
// naive: return Factorial(n) / Factorial(n - r);
return FactorialDivision(n, n - r);
}
private static long FactorialDivision(int topFactorial,
int divisorFactorial) {
long result = 1;
for (int i = topFactorial; i > divisorFactorial; i--)
result *= i;
return result;
}
private static long Factorial(int i) {
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;
namespace AtCoder_1 {
class Program {
static void Main(string[] args) {
var n = CinT();
var ab = CinTAr();
int m = 0;
int c = 0;
for (int i = 0; i < n; i++) {
if (m <= ab[i]) {
m = ab[i];
c++;
}
}
Cout(c);
Cin();
}
static int GCD(int a, int b) {
if (a < b) {
swap(ref a, ref b);
}
if (a % b == 0) {
return b;
} else {
return GCD(b, a % b);
}
}
static void swap<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static readonly int MOD1E9 = 10000007;
static bool isInt(double d) { return (int)d == d; }
static string Cin() { return ReadLine(); }
static string[] CinAr() { return ReadLine().Split(' '); }
static int CinT() { return S2i(Cin()); }
static int[] CinTAr() {
return CinAr().Select((x, i) => { return S2i(x); }).ToArray();
}
static long CinL() { return S2L(Cin()); }
static long[] CinLAr() {
return CinAr().Select((x, i) => { return S2L(x); }).ToArray();
}
static double CinD() { return S2D(Cin()); }
static double[] CinDAr() {
return CinAr().Select((x, i) => { return S2D(x); }).ToArray();
}
static int S2i(string s) { return int.Parse(s); }
static long S2L(string s) { return long.Parse(s); }
static double S2D(string s) { return double.Parse(s); }
static void Cout(object s) { WriteLine(s); }
static int[] yakusuu(int n) {
if (n == 1) {
return new int[] { 1 };
}
HashSet<int> res = new HashSet<int>();
for (int i = 1; i < Math.Ceiling(n / 2.0); i++) {
if (n % i == 0) {
res.Add(i);
res.Add(n / i);
}
}
return res.ToArray();
}
/// <summary>
/// Debug時のみの使用を推奨
/// </summary>
/// <typeparam name="Type"></typeparam>
/// <param name="types"></param>
static void CoutAr<Type>(IEnumerable<Type> types) {
string text = "";
foreach (var i in types) {
text += " " + i;
}
WriteLine(text.Substring(1));
}
public static long nCr(int n, int r) {
// naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
return nPr(n, r) / Factorial(r);
}
public static long nPr(int n, int r) {
// naive: return Factorial(n) / Factorial(n - r);
return FactorialDivision(n, n - r);
}
private static long FactorialDivision(int topFactorial,
int divisorFactorial) {
long result = 1;
for (int i = topFactorial; i > divisorFactorial; i--)
result *= i;
return result;
}
private static long Factorial(int i) {
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 759
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC124_B_Great_Ocean_View {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] height =
Console.ReadLine().Split(' ').Select((s) => int.Parse(s)).ToArray();
int peak = height[0];
int count = 1;
for (int i = 1; i < n; i++) {
if (peak >= height[i]) {
continue;
} else {
peak = height[i];
count++;
}
}
Console.WriteLine(count);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC124_B_Great_Ocean_View {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] height =
Console.ReadLine().Split(' ').Select((s) => int.Parse(s)).ToArray();
int peak = height[0];
int count = 1;
for (int i = 1; i < n; i++) {
if (peak > height[i]) {
continue;
} else {
peak = height[i];
count++;
}
}
Console.WriteLine(count);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47]]
| 8
| 158
| 2
|
using System;
namespace ABC124 {
class Program {
static int Main(string[] args) {
Program.ProblemB();
return 0;
}
static void ProblemB() {
string n = Console.ReadLine();
string[] input = Console.ReadLine().Split(' ');
int max = 0;
int count = 0;
for (int i = 0; i < int.Parse(n); i++) {
if (int.Parse(input[i]) >= max) {
count += 1;
}
max = int.Parse(input[i]);
}
Console.WriteLine(count);
}
}
}
|
using System;
namespace ABC124 {
class Program {
static int Main(string[] args) {
Program.ProblemB();
return 0;
}
static void ProblemB() {
string n = Console.ReadLine();
string[] input = Console.ReadLine().Split(' ');
int max = 0;
int count = 0;
for (int i = 0; i < int.Parse(n); i++) {
if (int.Parse(input[i]) >= max) {
count += 1;
max = int.Parse(input[i]);
}
}
Console.WriteLine(count);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 135
| 2
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class Problem {
static void Main() {
//--------------------------------input--------------------------------//
int n = Convert.ToInt32(Console.ReadLine());
var a = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);
//--------------------------------solve--------------------------------//
int min = a[0];
int kq = 0;
for (int i = 0; i < n; i++)
if (a[i] >= a[0]) {
kq++;
min = a[i];
}
Console.WriteLine(kq);
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class Problem {
static void Main() {
//--------------------------------input--------------------------------//
int n = Convert.ToInt32(Console.ReadLine());
var a = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);
//--------------------------------solve--------------------------------//
int min = a[0];
int kq = 0;
for (int i = 0; i < n; i++)
if (a[i] >= min) {
kq++;
min = a[i];
}
Console.WriteLine(kq);
}
}
|
[["-", 0, 7, 8, 57, 15, 16, 12, 204, 205, 22], ["-", 8, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 8, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 57, 15, 16, 12, 22]]
| 8
| 132
| 5
|
using System;
namespace Test {
class Program {
static void Main(string[] args) {
var res = 0;
var N = int.Parse(Console.ReadLine());
var H = new int[N];
var H_s = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
H[i] = int.Parse(H_s[i]);
}
for (int i = 0; i < N; i++) {
bool abelSee = true;
for (int j = 0; j < i; j++) {
if (H[j] > H[j]) {
abelSee = false;
}
}
if (abelSee) {
res++;
}
}
Console.WriteLine(res);
}
}
}
|
using System;
namespace Test {
class Program {
static void Main(string[] args) {
var res = 0;
var N = int.Parse(Console.ReadLine());
var H = new int[N];
var H_s = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
H[i] = int.Parse(H_s[i]);
}
for (int i = 0; i < N; i++) {
bool abelSee = true;
for (int j = 0; j < i; j++) {
if (H[j] > H[i]) {
abelSee = false;
}
}
if (abelSee) {
res++;
}
}
Console.WriteLine(res);
}
}
}
|
[["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 168
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static System.Math;
class Program {
public static void Main(string[] args) {
Console.ReadLine();
var v = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var count = 1;
var hOld = v[0];
foreach (var h in v.Skip(1)) {
if (h >= hOld) {
count++;
}
}
Console.WriteLine(count);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static System.Math;
class Program {
public static void Main(string[] args) {
Console.ReadLine();
var v = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var count = 1;
var hMax = v[0];
foreach (var h in v.Skip(1)) {
if (h >= hMax) {
hMax = h;
count++;
}
}
Console.WriteLine(count);
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 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
| 127
| 8
|
using System;
using static System.Console;
public class A {
static void Main() {
var s = Array.ConvertAll(ReadLine().Split(), int.Parse);
var ans = 0;
for (int i = 0; i < s.Length; i++) {
for (int j = 0; j <= i; j++) {
if (i == j) {
ans++;
break;
}
if (s[i] < s[j])
break;
}
}
WriteLine(ans);
}
}
|
using System;
using static System.Console;
public class B {
static void Main() {
ReadLine();
var s = Array.ConvertAll(ReadLine().Split(), int.Parse);
var ans = 0;
for (int i = 0; i < s.Length; i++) {
for (int j = 0; j <= i; j++) {
if (i == j) {
ans++;
break;
}
if (s[i] < s[j])
break;
}
}
WriteLine(ans);
}
}
|
[["-", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 112
| 6
|
using System;
using System.IO;
using System.Linq;
class Program {
static void Solve() {
var N = ReadInt();
var H = ReadInts();
var max = H[0];
var ans = 0;
for (var i = 0; i < N - 1; i++) {
if (H[i] >= max) {
ans++;
max = H[i];
}
}
Console.WriteLine(ans);
}
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static string Read() { return Console.ReadLine(); }
public static int ReadInt() { return int.Parse(Read()); }
public static long ReadLong() { return long.Parse(Read()); }
public static double ReadDouble() { return double.Parse(Read()); }
public static string[] Reads() { return Console.ReadLine().Split(' '); }
public static int[] ReadInts() {
return Reads().Select(_ => int.Parse(_)).ToArray();
}
public static long[] ReadLongs() {
return Reads().Select(_ => long.Parse(_)).ToArray();
}
public static double[] ReadDoubles() {
return Reads().Select(_ => double.Parse(_)).ToArray();
}
}
|
using System;
using System.IO;
using System.Linq;
class Program {
static void Solve() {
var N = ReadInt();
var H = ReadInts();
var max = H[0];
var ans = 0;
for (var i = 0; i < N; i++) {
if (H[i] >= max) {
ans++;
max = H[i];
}
}
Console.WriteLine(ans);
}
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static string Read() { return Console.ReadLine(); }
public static int ReadInt() { return int.Parse(Read()); }
public static long ReadLong() { return long.Parse(Read()); }
public static double ReadDouble() { return double.Parse(Read()); }
public static string[] Reads() { return Console.ReadLine().Split(' '); }
public static int[] ReadInts() {
return Reads().Select(_ => int.Parse(_)).ToArray();
}
public static long[] ReadLongs() {
return Reads().Select(_ => long.Parse(_)).ToArray();
}
public static double[] ReadDoubles() {
return Reads().Select(_ => double.Parse(_)).ToArray();
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 331
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static string InputPattern = "Input1";
static List<string> GetInputList() {
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("4");
WillReturn.Add("6 5 6 8");
// 3
} else if (InputPattern == "Input2") {
WillReturn.Add("5");
WillReturn.Add("4 5 3 5 4");
// 3
} else if (InputPattern == "Input3") {
WillReturn.Add("5");
WillReturn.Add("9 5 6 8 4");
// 1
} else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null)
WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main() {
List<string> InputList = GetInputList();
int[] HArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();
int CurrMax = int.MinValue;
int Answer = 0;
foreach (int EachInt in HArr) {
if (CurrMax <= EachInt) {
Answer++;
CurrMax = EachInt;
}
}
Console.WriteLine(Answer);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static string InputPattern = "InputX";
static List<string> GetInputList() {
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("4");
WillReturn.Add("6 5 6 8");
// 3
} else if (InputPattern == "Input2") {
WillReturn.Add("5");
WillReturn.Add("4 5 3 5 4");
// 3
} else if (InputPattern == "Input3") {
WillReturn.Add("5");
WillReturn.Add("9 5 6 8 4");
// 1
} else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null)
WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main() {
List<string> InputList = GetInputList();
int[] HArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();
int CurrMax = int.MinValue;
int Answer = 0;
foreach (int EachInt in HArr) {
if (CurrMax <= EachInt) {
Answer++;
CurrMax = EachInt;
}
}
Console.WriteLine(Answer);
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222]]
| 8
| 260
| 2
|
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(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
//おおきい方を2倍して1引く。ただし、同じときはa+b
if (a > b)
Console.WriteLine(2 * a - 1);
else if (a < b)
Console.WriteLine(2 * b - 1);
else
Console.WriteLine(a + b);
}
}
class ProgramB {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
string[] h = Console.ReadLine().Split(' ');
int count = 0;
//ダメな旅館数を数える
for (int i = 1; i < n; i++)
for (int j = 0; j < i; j++) {
if (int.Parse(h[i]) < int.Parse(h[j])) {
count++;
break;
}
}
//答え出力
Console.WriteLine(n - count);
}
}
class ProgramC {
public void main() {
//入力
string s = Console.ReadLine();
//候補は101010....か0101010しかないので両方実験してみる
int count1 = 0;
int count2 = 0;
// 10101010
for (int i = 1; i < s.Length; i++) {
if (i % 2 == 0)
if (s[i] == '0')
count1++;
if (i % 2 == 1)
if (s[i] == '1')
count1++;
}
// 010101010
for (int i = 1; i < s.Length; i++) {
if (i % 2 == 0)
if (s[i] == '1')
count2++;
if (i % 2 == 1)
if (s[i] == '0')
count2++;
}
//答えを出力
Console.WriteLine(Math.Min(count1, count2));
}
}
class ProgramD {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
string[] a = Console.ReadLine().Split(' ');
long[] dp_u = new long[n];
long[] dp_d = new long[n];
dp_u[1] = -(long.Parse(a[0]) + long.Parse(a[1]));
dp_d[1] = long.Parse(a[0]) + long.Parse(a[1]);
for (int i = 2; i < n; i++) {
dp_u[i] =
Math.Max(dp_u[i - 1] - long.Parse(a[i]) + 2 * long.Parse(a[i - 1]),
dp_d[i - 1] - long.Parse(a[i]) - 2 * long.Parse(a[i - 1]));
dp_d[i] = Math.Max(dp_u[i - 1] + long.Parse(a[i]),
dp_d[i - 1] + long.Parse(a[i]));
}
//答を出す
Console.WriteLine(Math.Max(dp_u[n - 1], dp_d[n - 1]));
}
}
class ProgramD2 {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
string[] a = Console.ReadLine().Split(' ');
long count = 0;
int flag = 0;
long min = 10000000000;
long sum = 0;
//いれて0があるか、負の数は何個か、絶対値の最小は何か求めておく
for (int i = 0; i < n; i++) {
long temp = long.Parse(a[i]);
if (temp == 0)
flag = 1;
if (temp < 0)
count++;
sum += Math.Abs(temp);
min = Math.Min(Math.Abs(temp), min);
}
//答を出す
if (flag == 1 || count % 2 == 0)
Console.WriteLine(sum);
else
Console.WriteLine(sum - 2 * min);
}
}
}
|
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(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
//おおきい方を2倍して1引く。ただし、同じときはa+b
if (a > b)
Console.WriteLine(2 * a - 1);
else if (a < b)
Console.WriteLine(2 * b - 1);
else
Console.WriteLine(a + b);
}
}
class ProgramB {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
string[] h = Console.ReadLine().Split(' ');
int count = 0;
//ダメな旅館数を数える
for (int i = 1; i < n; i++)
for (int j = 0; j < i; j++) {
if (int.Parse(h[i]) < int.Parse(h[j])) {
count++;
break;
}
}
//答え出力
Console.WriteLine(n - count);
}
}
class ProgramC {
public void main() {
//入力
string s = Console.ReadLine();
//候補は101010....か0101010しかないので両方実験してみる
int count1 = 0;
int count2 = 0;
// 10101010
for (int i = 0; i < s.Length; i++) {
if (i % 2 == 0)
if (s[i] == '0')
count1++;
if (i % 2 == 1)
if (s[i] == '1')
count1++;
}
// 010101010
for (int i = 0; i < s.Length; i++) {
if (i % 2 == 0)
if (s[i] == '1')
count2++;
if (i % 2 == 1)
if (s[i] == '0')
count2++;
}
//答えを出力
Console.WriteLine(Math.Min(count1, count2));
}
}
class ProgramD {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
string[] a = Console.ReadLine().Split(' ');
long[] dp_u = new long[n];
long[] dp_d = new long[n];
dp_u[1] = -(long.Parse(a[0]) + long.Parse(a[1]));
dp_d[1] = long.Parse(a[0]) + long.Parse(a[1]);
for (int i = 2; i < n; i++) {
dp_u[i] =
Math.Max(dp_u[i - 1] - long.Parse(a[i]) + 2 * long.Parse(a[i - 1]),
dp_d[i - 1] - long.Parse(a[i]) - 2 * long.Parse(a[i - 1]));
dp_d[i] = Math.Max(dp_u[i - 1] + long.Parse(a[i]),
dp_d[i - 1] + long.Parse(a[i]));
}
//答を出す
Console.WriteLine(Math.Max(dp_u[n - 1], dp_d[n - 1]));
}
}
class ProgramD2 {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
string[] a = Console.ReadLine().Split(' ');
long count = 0;
int flag = 0;
long min = 10000000000;
long sum = 0;
//いれて0があるか、負の数は何個か、絶対値の最小は何か求めておく
for (int i = 0; i < n; i++) {
long temp = long.Parse(a[i]);
if (temp == 0)
flag = 1;
if (temp < 0)
count++;
sum += Math.Abs(temp);
min = Math.Min(Math.Abs(temp), min);
}
//答を出す
if (flag == 1 || count % 2 == 0)
Console.WriteLine(sum);
else
Console.WriteLine(sum - 2 * min);
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 905
| 4
|
using System;
namespace abc {
class C {
static void Main() {
char[] s = Console.ReadLine().ToCharArray();
int tans = 0;
int ans = 0;
bool tobe0 = true;
for (int i = 0; i < s.Length; i++) {
if (tobe0) {
if (s[i] == '1')
tans++;
tobe0 = false;
} else {
if (s[i] == '0')
tans++;
tobe0 = true;
}
}
ans = tans;
tobe0 = false;
for (int i = 0; i < s.Length; i++) {
if (tobe0) {
if (s[i] == '1')
tans++;
tobe0 = false;
} else {
if (s[i] == '0')
tans++;
tobe0 = true;
}
}
if (ans > tans)
Console.WriteLine(tans);
else {
Console.WriteLine(ans);
}
}
}
}
|
using System;
namespace abc {
class C {
static void Main() {
char[] s = Console.ReadLine().ToCharArray();
int tans = 0;
int ans = 0;
bool tobe0 = true;
for (int i = 0; i < s.Length; i++) {
if (tobe0) {
if (s[i] == '1')
tans++;
tobe0 = false;
} else {
if (s[i] == '0')
tans++;
tobe0 = true;
}
}
ans = tans;
tans = 0;
tobe0 = false;
for (int i = 0; i < s.Length; i++) {
if (tobe0) {
if (s[i] == '1')
tans++;
tobe0 = false;
} else {
if (s[i] == '0')
tans++;
tobe0 = true;
}
}
if (ans > tans)
Console.WriteLine(tans);
else {
Console.WriteLine(ans);
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 205
| 4
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace ABC124.C
{
using static Util;
public class Solver : SolverBase
{
public void Run() {
var S = ReadLine();
// 奇数枚目と偶数枚目の 0 の数を数える
int o0 = 0;
int e0 = 0;
for (int i = 0; i < S.Length; i++) {
if (S[i] != '0') continue;
if (i % 2 == 0)
++e0;
else
++o0;
}
int oTotal = S.Length / 2;
int eTotal = S.Length - oTotal;
// e0 o1 にする場合
var ans01 = eTotal - e0 + o0;
// e1 o0 にする場合
var ans10 = o0 + oTotal - o0;
var ans = Math.Min(ans01, ans10);
WriteLine(ans);
}
#if !MYHOME
public static void Main(string[] args) {
new Solver().Run();
}
#endif
}
public static class Util
{
/// <summary>
/// 最大公約数 ※ユークリッドの互除法
/// ※a,bどちらかが0の場合は0じゃない方を、両方0の場合は0を返す。
/// </summary>
public static int Gcd(int a, int b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public static int Gcd(params int[] nums) {
if (nums == null || nums.Length < 1)
throw new ArgumentException(nameof(nums));
if (nums.Length == 1)
return nums[0];
var g = Gcd(nums[0], nums[1]);
for (int i = 2; i < nums.Length; i++) {
g = Gcd(g, nums[i]);
}
return g;
}
public readonly static long MOD = 1000000007;
public static string DumpToString<T>(IEnumerable<T> array) where T : IFormattable {
var sb = new StringBuilder();
foreach (var item in array) {
sb.Append(item);
sb.Append(", ");
}
return sb.ToString();
}
public static string DumpToString<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>> dic) {
var sb = new StringBuilder();
foreach (var kv in dic) {
sb.Append($"({kv.Key}, {kv.Value})");
sb.Append(", ");
}
return sb.ToString();
}
public static void InitArray<T>(T[] ary, T value) {
for (int i = 0; i < ary.Length; i++) {
ary[i] = value;
}
}
public static void InitDP2<T>(T[,] dp, T value) {
for (int i = 0; i < dp.GetLength(0); i++) {
for (int j = 0; j < dp.GetLength(1); j++) {
dp[i, j] = value;
}
}
}
public static void InitDP3<T>(T[,,] dp, T value) {
for (int i = 0; i < dp.GetLength(0); i++) {
for (int j = 0; j < dp.GetLength(1); j++) {
for (int k = 0; k < dp.GetLength(2); k++) {
dp[i, j, k] = value;
}
}
}
}
public static T Max<T>(params T[] nums) where T : IComparable {
if (nums.Length == 0) return default(T);
T max = nums[0];
for (int i = 1; i < nums.Length; i++) {
max = max.CompareTo(nums[i]) > 0 ? max : nums[i];
}
return max;
}
public static T Min<T>(params T[] nums) where T : IComparable {
if (nums.Length == 0) return default(T);
T min = nums[0];
for (int i = 1; i < nums.Length; i++) {
min = min.CompareTo(nums[i]) < 0 ? min : nums[i];
}
return min;
}
/// <summary>
/// ソート済み配列 ary に同じ値の要素が含まれている?
/// ※ソート順は昇順/降順どちらでもよい
/// </summary>
public static bool HasDuplicateInSortedArray<T>(T[] ary) where T : IComparable, IComparable<T> {
if (ary.Length <= 1) return false;
var lastNum = ary[ary.Length - 1];
foreach (var n in ary) {
if (lastNum.CompareTo(n) == 0) {
return true;
} else {
lastNum = n;
}
}
return false;
}
/// <summary>
/// 二分探索
/// ※条件を満たす最小のidxを返す
/// ※満たすものがない場合は ary.Length を返す
/// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提
/// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。
/// </summary>
/// <param name="ary">探索対象配列 ★ソート済みであること</param>
/// <param name="key">探索値 ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param>
public static int BinarySearch<T>(T[] ary, T key) where T : IComparable, IComparable<T> {
int left = -1;
int right = ary.Length;
while (1 < right - left) {
var mid = left + (right - left) / 2;
if (IsOK(ary, mid, key)) {
right = mid;
} else {
left = mid;
}
}
// left は条件を満たさない最大の値、right は条件を満たす最小の値になっている
return right;
}
public static bool IsOK<T>(T[] ary, int idx, T key) where T : IComparable, IComparable<T> {
// key <= ary[idx] と同じ意味
return key.CompareTo(ary[idx]) <= 0;
}
}
public class SolverBase
{
virtual protected string ReadLine() => Console.ReadLine();
virtual protected int ReadInt() => int.Parse(ReadLine());
//virtual protected void ReadInt2(out int x, out int y) {
// var aryS = ReadLine().Split(' ');
// x = int.Parse(aryS[0]);
// y = int.Parse(aryS[1]);
//}
virtual protected long ReadLong() => long.Parse(ReadLine());
virtual protected string[] ReadStringArray() => ReadLine().Split(' ');
virtual protected int[] ReadIntArray() => ReadLine().Split(' ').Select<string, int>(s => int.Parse(s)).ToArray();
virtual protected long[] ReadLongArray() => ReadLine().Split(' ').Select<string, long>(s => long.Parse(s)).ToArray();
virtual protected double[] ReadDoubleArray() => ReadLine().Split(' ').Select<string, double>(s => double.Parse(s)).ToArray();
virtual protected void WriteLine(string line) => Console.WriteLine(line);
virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}");
virtual protected void WriteLine<T>(T value) where T : IFormattable => Console.WriteLine(value);
[Conditional("DEBUG")]
protected void Dump(string s) => Console.WriteLine(s);
[Conditional("DEBUG")]
protected void Dump(char c) => Console.WriteLine(c);
[Conditional("DEBUG")]
protected void Dump(double d) => Console.WriteLine($"{d:F9}");
[Conditional("DEBUG")]
protected void Dump<T>(IEnumerable<T> array) where T : IFormattable {
string s = Util.DumpToString(array);
// Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。
Console.WriteLine(s);
//_writer.WriteLine(s);
}
[Conditional("DEBUG")]
protected void Dump<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>> dic) {
string s = Util.DumpToString(dic);
Console.WriteLine(s);
}
[Conditional("DEBUG")]
protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) where T : IFormattable {
var sb = new StringBuilder();
foreach (var a in arrayOfArray) {
sb.AppendLine(Util.DumpToString(a));
}
// Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。
Console.WriteLine(sb.ToString());
//_writer.WriteLine(sb.ToString());
}
[Conditional("DEBUG")]
protected void DumpDP<T>(T[,] dp) where T : IFormattable {
var sb = new StringBuilder();
for (int i = 0; i < dp.GetLength(0); i++) {
for (int j = 0; j < dp.GetLength(1); j++) {
sb.Append(dp[i, j]);
sb.Append(", ");
}
sb.AppendLine();
}
Console.WriteLine(sb.ToString());
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace ABC124.C
{
using static Util;
public class Solver : SolverBase
{
public void Run() {
var S = ReadLine();
// 奇数枚目と偶数枚目の 0 の数を数える
int o0 = 0;
int e0 = 0;
for (int i = 0; i < S.Length; i++) {
if (S[i] != '0') continue;
if (i % 2 == 0)
++e0;
else
++o0;
}
int oTotal = S.Length / 2;
int eTotal = S.Length - oTotal;
// e0 o1 にする場合
var ans01 = eTotal - e0 + o0;
// e1 o0 にする場合
var ans10 = e0 + oTotal - o0;
var ans = Math.Min(ans01, ans10);
WriteLine(ans);
}
#if !MYHOME
public static void Main(string[] args) {
new Solver().Run();
}
#endif
}
public static class Util
{
/// <summary>
/// 最大公約数 ※ユークリッドの互除法
/// ※a,bどちらかが0の場合は0じゃない方を、両方0の場合は0を返す。
/// </summary>
public static int Gcd(int a, int b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public static int Gcd(params int[] nums) {
if (nums == null || nums.Length < 1)
throw new ArgumentException(nameof(nums));
if (nums.Length == 1)
return nums[0];
var g = Gcd(nums[0], nums[1]);
for (int i = 2; i < nums.Length; i++) {
g = Gcd(g, nums[i]);
}
return g;
}
public readonly static long MOD = 1000000007;
public static string DumpToString<T>(IEnumerable<T> array) where T : IFormattable {
var sb = new StringBuilder();
foreach (var item in array) {
sb.Append(item);
sb.Append(", ");
}
return sb.ToString();
}
public static string DumpToString<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>> dic) {
var sb = new StringBuilder();
foreach (var kv in dic) {
sb.Append($"({kv.Key}, {kv.Value})");
sb.Append(", ");
}
return sb.ToString();
}
public static void InitArray<T>(T[] ary, T value) {
for (int i = 0; i < ary.Length; i++) {
ary[i] = value;
}
}
public static void InitDP2<T>(T[,] dp, T value) {
for (int i = 0; i < dp.GetLength(0); i++) {
for (int j = 0; j < dp.GetLength(1); j++) {
dp[i, j] = value;
}
}
}
public static void InitDP3<T>(T[,,] dp, T value) {
for (int i = 0; i < dp.GetLength(0); i++) {
for (int j = 0; j < dp.GetLength(1); j++) {
for (int k = 0; k < dp.GetLength(2); k++) {
dp[i, j, k] = value;
}
}
}
}
public static T Max<T>(params T[] nums) where T : IComparable {
if (nums.Length == 0) return default(T);
T max = nums[0];
for (int i = 1; i < nums.Length; i++) {
max = max.CompareTo(nums[i]) > 0 ? max : nums[i];
}
return max;
}
public static T Min<T>(params T[] nums) where T : IComparable {
if (nums.Length == 0) return default(T);
T min = nums[0];
for (int i = 1; i < nums.Length; i++) {
min = min.CompareTo(nums[i]) < 0 ? min : nums[i];
}
return min;
}
/// <summary>
/// ソート済み配列 ary に同じ値の要素が含まれている?
/// ※ソート順は昇順/降順どちらでもよい
/// </summary>
public static bool HasDuplicateInSortedArray<T>(T[] ary) where T : IComparable, IComparable<T> {
if (ary.Length <= 1) return false;
var lastNum = ary[ary.Length - 1];
foreach (var n in ary) {
if (lastNum.CompareTo(n) == 0) {
return true;
} else {
lastNum = n;
}
}
return false;
}
/// <summary>
/// 二分探索
/// ※条件を満たす最小のidxを返す
/// ※満たすものがない場合は ary.Length を返す
/// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提
/// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。
/// </summary>
/// <param name="ary">探索対象配列 ★ソート済みであること</param>
/// <param name="key">探索値 ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param>
public static int BinarySearch<T>(T[] ary, T key) where T : IComparable, IComparable<T> {
int left = -1;
int right = ary.Length;
while (1 < right - left) {
var mid = left + (right - left) / 2;
if (IsOK(ary, mid, key)) {
right = mid;
} else {
left = mid;
}
}
// left は条件を満たさない最大の値、right は条件を満たす最小の値になっている
return right;
}
public static bool IsOK<T>(T[] ary, int idx, T key) where T : IComparable, IComparable<T> {
// key <= ary[idx] と同じ意味
return key.CompareTo(ary[idx]) <= 0;
}
}
public class SolverBase
{
virtual protected string ReadLine() => Console.ReadLine();
virtual protected int ReadInt() => int.Parse(ReadLine());
//virtual protected void ReadInt2(out int x, out int y) {
// var aryS = ReadLine().Split(' ');
// x = int.Parse(aryS[0]);
// y = int.Parse(aryS[1]);
//}
virtual protected long ReadLong() => long.Parse(ReadLine());
virtual protected string[] ReadStringArray() => ReadLine().Split(' ');
virtual protected int[] ReadIntArray() => ReadLine().Split(' ').Select<string, int>(s => int.Parse(s)).ToArray();
virtual protected long[] ReadLongArray() => ReadLine().Split(' ').Select<string, long>(s => long.Parse(s)).ToArray();
virtual protected double[] ReadDoubleArray() => ReadLine().Split(' ').Select<string, double>(s => double.Parse(s)).ToArray();
virtual protected void WriteLine(string line) => Console.WriteLine(line);
virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}");
virtual protected void WriteLine<T>(T value) where T : IFormattable => Console.WriteLine(value);
[Conditional("DEBUG")]
protected void Dump(string s) => Console.WriteLine(s);
[Conditional("DEBUG")]
protected void Dump(char c) => Console.WriteLine(c);
[Conditional("DEBUG")]
protected void Dump(double d) => Console.WriteLine($"{d:F9}");
[Conditional("DEBUG")]
protected void Dump<T>(IEnumerable<T> array) where T : IFormattable {
string s = Util.DumpToString(array);
// Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。
Console.WriteLine(s);
//_writer.WriteLine(s);
}
[Conditional("DEBUG")]
protected void Dump<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>> dic) {
string s = Util.DumpToString(dic);
Console.WriteLine(s);
}
[Conditional("DEBUG")]
protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) where T : IFormattable {
var sb = new StringBuilder();
foreach (var a in arrayOfArray) {
sb.AppendLine(Util.DumpToString(a));
}
// Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。
Console.WriteLine(sb.ToString());
//_writer.WriteLine(sb.ToString());
}
[Conditional("DEBUG")]
protected void DumpDP<T>(T[,] dp) where T : IFormattable {
var sb = new StringBuilder();
for (int i = 0; i < dp.GetLength(0); i++) {
for (int j = 0; j < dp.GetLength(1); j++) {
sb.Append(dp[i, j]);
sb.Append(", ");
}
sb.AppendLine();
}
Console.WriteLine(sb.ToString());
}
}
}
|
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22]]
| 8
| 1,721
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections;
using System.Linq.Expressions;
using Pair = System.Tuple<long, long>;
using Graph =
System.Collections.Generic.List<System.Collections.Generic.List<long>>;
using static _20200214.Cin;
using static _20200214.Util;
namespace _20200214 {
public class Program {
public static void Main(string[] args) {
// ABC006_B(); 12min
// ABC075_C(); 20min
// ABC028_D(); 25min
// ABC124_D(); 30min
}
/// <summary>
/// D - Handstand
/// </summary>
public static void ABC124_D() {
long N = rl;
long K = rl;
string S = rs;
List<long> a = new List<long>();
if (S[0] == '0')
a.Add(0);
for (int i = 0; i < N;) {
int j = i;
while (j < N && S[j] == S[i])
j++;
a.Add(j - i);
i = j;
}
if (S[S.Length - 1] == '0')
a.Add(0);
var len = a.Count;
var acc = Accumulate(a.ToArray());
long ans = 0;
if (2 * K + 1 > len)
ans = acc[len];
for (int i = 0; i + 2 * K + 1 <= len; i += 2) {
ChMax(ref ans, acc[i + 2 * K + 1] - acc[i]);
}
Console.WriteLine(ans);
}
/// <summary>
/// D - 乱数生成
/// </summary>
public static void ABC028_D() {
long N = rl;
long K = rl;
double ans = 0;
// K が 3個
ans += 1;
// K が 2個
ans += (N - 1) * 3;
// K が 1個
ans += (K - 1) * (N - K) * 3 * 2;
ans /= N;
ans /= N;
ans /= N;
Console.WriteLine(ans);
}
/// <summary>
/// C - Bridge
/// </summary>
public static void ABC075_C() {
long N = rl;
long M = rl;
Pair[] edges = new Pair[M];
for (int i = 0; i < M; i++) {
edges[i] = new Pair(rl - 1, rl - 1);
}
List<long>[] edgeIndexes = new List<long>[N];
for (int i = 0; i < N; i++) {
edgeIndexes[i] = new List<long>();
}
for (int i = 0; i < M; i++) {
edgeIndexes[edges[i].Item1].Add(i);
edgeIndexes[edges[i].Item2].Add(i);
}
long cnt = 0;
for (int i = 0; i < M; i++) {
bool[] vis = new bool[N];
Queue<long> q = new Queue<long>();
q.Enqueue(0);
while (q.Any()) {
long v = q.Dequeue();
vis[v] = true;
foreach (var idx in edgeIndexes[v]) {
if (idx == i)
continue;
long v2 = edges[idx].Item1 + edges[idx].Item2 - v;
if (vis[v])
continue;
q.Enqueue(v2);
}
}
if (vis.Any(v => !v))
cnt++;
}
Console.WriteLine(cnt);
}
/// <summary>
/// B - トリボナッチ数列
/// </summary>
public static void ABC006_B() {
long N = rl;
long[] table = new long[3];
table[0] = 0;
table[1] = 0;
table[2] = 1;
for (int i = 3; i < N; i++) {
table[i % 3] = (table[0] + table[1] + table[2]) % 10007;
}
Console.WriteLine(table[(N - 1) % 3]);
}
}
public class HashMap<K, V> : Dictionary<K, V> {
V i;
static Func<V> j =
Expression.Lambda<Func<V>>(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 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++];
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections;
using System.Linq.Expressions;
using Pair = System.Tuple<long, long>;
using Graph =
System.Collections.Generic.List<System.Collections.Generic.List<long>>;
using static _20200214.Cin;
using static _20200214.Util;
namespace _20200214 {
public class Program {
public static void Main(string[] args) {
// ABC006_B(); 12min
// ABC075_C(); 20min
// ABC028_D(); 25min
ABC124_D();
}
/// <summary>
/// D - Handstand
/// </summary>
public static void ABC124_D() {
long N = rl;
long K = rl;
string S = rs;
List<long> a = new List<long>();
if (S[0] == '0')
a.Add(0);
for (int i = 0; i < N;) {
int j = i;
while (j < N && S[j] == S[i])
j++;
a.Add(j - i);
i = j;
}
if (S[S.Length - 1] == '0')
a.Add(0);
var len = a.Count;
var acc = Accumulate(a.ToArray());
long ans = 0;
if (2 * K + 1 > len)
ans = acc[len];
for (int i = 0; i + 2 * K + 1 <= len; i += 2) {
ChMax(ref ans, acc[i + 2 * K + 1] - acc[i]);
}
Console.WriteLine(ans);
}
/// <summary>
/// D - 乱数生成
/// </summary>
public static void ABC028_D() {
long N = rl;
long K = rl;
double ans = 0;
// K が 3個
ans += 1;
// K が 2個
ans += (N - 1) * 3;
// K が 1個
ans += (K - 1) * (N - K) * 3 * 2;
ans /= N;
ans /= N;
ans /= N;
Console.WriteLine(ans);
}
/// <summary>
/// C - Bridge
/// </summary>
public static void ABC075_C() {
long N = rl;
long M = rl;
Pair[] edges = new Pair[M];
for (int i = 0; i < M; i++) {
edges[i] = new Pair(rl - 1, rl - 1);
}
List<long>[] edgeIndexes = new List<long>[N];
for (int i = 0; i < N; i++) {
edgeIndexes[i] = new List<long>();
}
for (int i = 0; i < M; i++) {
edgeIndexes[edges[i].Item1].Add(i);
edgeIndexes[edges[i].Item2].Add(i);
}
long cnt = 0;
for (int i = 0; i < M; i++) {
bool[] vis = new bool[N];
Queue<long> q = new Queue<long>();
q.Enqueue(0);
while (q.Any()) {
long v = q.Dequeue();
vis[v] = true;
foreach (var idx in edgeIndexes[v]) {
if (idx == i)
continue;
long v2 = edges[idx].Item1 + edges[idx].Item2 - v;
if (vis[v])
continue;
q.Enqueue(v2);
}
}
if (vis.Any(v => !v))
cnt++;
}
Console.WriteLine(cnt);
}
/// <summary>
/// B - トリボナッチ数列
/// </summary>
public static void ABC006_B() {
long N = rl;
long[] table = new long[3];
table[0] = 0;
table[1] = 0;
table[2] = 1;
for (int i = 3; i < N; i++) {
table[i % 3] = (table[0] + table[1] + table[2]) % 10007;
}
Console.WriteLine(table[(N - 1) % 3]);
}
}
public class HashMap<K, V> : Dictionary<K, V> {
V i;
static Func<V> j =
Expression.Lambda<Func<V>>(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 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++];
}
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 2,309
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC124 {
class Program {
static void Main(string[] args) {
// Buttons(); // 8min
// GreatOceanView(); // 15min
// ColoringColorfully(); // 32min
Handstand();
}
static void Handstand() {
int[] tmp = ReadIntArray();
int n = tmp[0];
int k = tmp[1];
bool[] xs = ReadBoolArray();
List<int> ary = new List<int>();
if (xs[0] == false) {
ary.Add(0);
}
for (int i = 0; i < n; i++) {
int j = i;
while (j < n && xs[j] == xs[i])
j++;
ary.Add(j - i);
i = j;
}
if (xs[n - 1] == false) {
ary.Add(0);
}
// 累積和を作る
int len = ary.Count() + 1;
int[] cusum = new int[len];
for (int i = 0; i < len - 1; i++) {
cusum[i + 1] = cusum[i] + ary[i];
}
// 答えを出す
int ans = 0;
for (int i = 0; i < len; i += 2) {
int left = i;
int right = Math.Min(len - 1, i + k * 2 + 1);
ans = Math.Max(ans, cusum[right] - cusum[left]);
}
Console.WriteLine(ans);
}
static void ColoringColorfully() {
bool[] xs = ReadBoolArray();
int n = xs.Length;
int ans = 0;
for (int i = 0; i < n; i++) {
if (xs[i] == (i % 2 == 0)) {
ans++;
}
}
ans = Math.Min(ans, n - ans);
Console.WriteLine(ans);
}
static void GreatOceanView() {
int n = ReadInt();
int[] xs = ReadIntArray();
int ans = 0;
int max = 0;
for (int i = 0; i < n; i++) {
if (max <= xs[i]) {
max = xs[i];
ans++;
}
}
Console.WriteLine(ans);
}
static void Buttons() {
int[] xs = ReadIntArray();
int ans = 0;
for (int i = 0; i < 2; i++) {
if (xs[0] > xs[1]) {
ans += xs[0]--;
} else {
ans += xs[1]--;
}
}
Console.WriteLine(ans);
}
public static bool[] ReadBoolArray() {
return Console.ReadLine().Select(c => c == '1').ToArray();
}
public static int ReadInt() { return int.Parse(Console.ReadLine()); }
public static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC124 {
class Program {
static void Main(string[] args) {
// Buttons(); // 8min
// GreatOceanView(); // 15min
// ColoringColorfully(); // 32min
Handstand();
}
static void Handstand() {
int[] tmp = ReadIntArray();
int n = tmp[0];
int k = tmp[1];
bool[] xs = ReadBoolArray();
List<int> ary = new List<int>();
if (xs[0] == false) {
ary.Add(0);
}
// 連続する個数のリストに変換する
for (int i = 0; i < n;) {
int j = i;
while (j < n && xs[j] == xs[i])
j++;
ary.Add(j - i);
i = j;
}
if (xs[n - 1] == false) {
ary.Add(0);
}
// 累積和を作る
int len = ary.Count() + 1;
int[] cusum = new int[len];
for (int i = 0; i < len - 1; i++) {
cusum[i + 1] = cusum[i] + ary[i];
}
// 答えを出す
int ans = 0;
for (int i = 0; i < len; i += 2) {
int left = i;
int right = Math.Min(len - 1, i + k * 2 + 1);
ans = Math.Max(ans, cusum[right] - cusum[left]);
}
Console.WriteLine(ans);
}
static void ColoringColorfully() {
bool[] xs = ReadBoolArray();
int n = xs.Length;
int ans = 0;
for (int i = 0; i < n; i++) {
if (xs[i] == (i % 2 == 0)) {
ans++;
}
}
ans = Math.Min(ans, n - ans);
Console.WriteLine(ans);
}
static void GreatOceanView() {
int n = ReadInt();
int[] xs = ReadIntArray();
int ans = 0;
int max = 0;
for (int i = 0; i < n; i++) {
if (max <= xs[i]) {
max = xs[i];
ans++;
}
}
Console.WriteLine(ans);
}
static void Buttons() {
int[] xs = ReadIntArray();
int ans = 0;
for (int i = 0; i < 2; i++) {
if (xs[0] > xs[1]) {
ans += xs[0]--;
} else {
ans += xs[1]--;
}
}
Console.WriteLine(ans);
}
public static bool[] ReadBoolArray() {
return Console.ReadLine().Select(c => c == '1').ToArray();
}
public static int ReadInt() { return int.Parse(Console.ReadLine()); }
public static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29]]
| 8
| 656
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static AtCoderTemplate.MyExtensions;
using static AtCoderTemplate.MyInputOutputs;
using static AtCoderTemplate.MyNumericFunctions;
namespace AtCoderTemplate {
public class Program {
public static void Main(string[] args) {
var NK = ReadInts();
var N = NK[0];
var K = NK[1];
var S = Console.ReadLine();
var gaps = new List<int> { 0 };
foreach (var i in Enumerable.Range(1, S.Count() - 1)) {
if (S[i - 1] != S[i]) {
gaps.Add(i);
}
}
gaps.Add(S.Length);
var gapNum = gaps.MapAdjacent((gap1, gap2) => Abs(gap2 - gap1)).ToList();
if (S[0] == '0')
gapNum = gapNum.Prepend(0).ToList();
if (S[S.Length - 1] == '1')
gapNum.Add(0);
// PrintRow (gapNum);
// 累積和
var firstSum = gapNum.Take(2 * K + 1).Sum();
var sum = new List<int> { firstSum };
var k = 1;
while (2 * (k + K) < gaps.Count) {
sum.Add(sum[k - 1] - (gapNum[2 * (k - 1)] + gapNum[2 * (k - 1) + 1]) +
(gapNum[2 * (k + K) - 1] + gapNum[2 * (k + K)]));
// Print ($"{k} {sum[k]}");
k++;
}
Print(sum.Max());
}
}
static class MyInputOutputs {
/* Input & Output*/
public static int ReadInt() { return int.Parse(Console.ReadLine()); }
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static List<int> ReadInts() {
return Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList();
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(c => long.Parse(c)).ToList();
}
public static List<List<int>> ReadIntColumns(int n) {
/*
入力例
A1 B1
A2 B2
...
An Bn
出力例
[[A1,A2,...,An], [B1,B2,...,Bn]]
*/
var rows = Enumerable.Range(0, n).Select(i => ReadInts()).ToList();
var m = rows.FirstOrDefault()?.Count() ?? 0;
return Enumerable.Range(0, m)
.Select(i => rows.Select(items => items[i]).ToList())
.ToList();
}
public static List<List<long>> ReadLongColumns(int n) {
/*
入力例
A1 B1
A2 B2
...
An Bn
出力例
[[A1,A2,...,An], [B1,B2,...,Bn]]
*/
var rows = Enumerable.Range(0, n).Select(i => ReadLongs()).ToList();
var m = rows.FirstOrDefault()?.Count() ?? 0;
return Enumerable.Range(0, m)
.Select(i => rows.Select(items => items[i]).ToList())
.ToList();
}
public static void Print<T>(T item) { Console.WriteLine(item); }
public static void PrintIf<T1, T2>(bool condition, T1 trueResult,
T2 falseResult) {
if (condition) {
Console.WriteLine(trueResult);
} else {
Console.WriteLine(falseResult);
}
}
public static void PrintRow<T>(IEnumerable<T> list) {
/* 横ベクトルで表示
A B C D ...
*/
if (!list.IsEmpty()) {
Console.Write(list.First());
foreach (var item in list.Skip(1)) {
Console.Write($" {item}");
}
}
Console.Write("\n");
}
public static void PrintColomn<T>(IEnumerable<T> list) {
/* 縦ベクトルで表示
A
B
C
D
...
*/
foreach (var item in list) {
Console.WriteLine(item);
}
}
public static void Print2DArray<T>(IEnumerable<IEnumerable<T>> sources) {
foreach (var row in sources) {
PrintRow(row);
}
}
}
static class MyNumericFunctions {
public static bool isEven(int a) { return a % 2 == 0; }
public static bool isEven(long a) { return a % 2 == 0; }
public static bool isOdd(int a) { return !isEven(a); }
public static bool isOdd(long a) { return !isEven(a); }
public static long nPk(int n, int k) {
if (k > n) {
return 0;
} else {
return Enumerable.Range(n - k + 1, k)
.Aggregate((long)1, ((i, m) => i * m));
}
}
public static long Fact(int n) { return nPk(n, n); }
public static long nCk(int n, int k) {
if (k > n) {
return 0;
} else {
return nPk(n, k) / Fact(k);
}
}
// 最大公約数
public static long GCD(long m, long n) {
if (m < n) {
return GCD(n, m);
} else if (n == 0) {
return m;
} else {
return GCD(n, m % n);
}
}
// 最小公倍数
public static long LCM(long m, long n) {
if (m < n) {
return LCM(n, m);
} else {
return (m * n) / GCD(m, n);
}
}
}
static class MyExtensions {
// AppendとPrependが、.NET Standard 1.6からの追加で、Mono 4.6.2
// はそれに対応して仕様はあるが、実装がない
public static IEnumerable<T> Append<T>(this IEnumerable<T> source,
T element) {
return source.Concat(Enumerable.Repeat(element, 1));
}
public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source,
T element) {
return Enumerable.Repeat(element, 1).Concat(source);
}
// TakeLastとSkipLastが、.Net Standard 2.1からの追加で、Mono 4.6.2
// はそれに対応していない
public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source,
int count) {
return source.Skip(source.Count() - count);
}
public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source,
int count) {
return source.Take(source.Count() - count);
}
public static bool IsEmpty<T>(this IEnumerable<T> source) {
return !source.Any();
}
/// <summary>
/// インデックスiの位置の要素からk個取り除く
/// O(N)
/// </summary>
public static IEnumerable<T> TakeAwayRange<T>(this IEnumerable<T> source,
int i, int count) {
return source.Take(i).Concat(source.Skip(i + count));
}
/// <summary>
/// インデックスiの位置の要素を取り除く
/// O(N)
/// </summary>
public static IEnumerable<T> TakeAwayAt<T>(this IEnumerable<T> source,
int i) {
return source.TakeAwayRange(i, 1);
}
/// <summary>
/// インデックスiの位置にシーケンスを挿入する
/// O(N + K)
/// </summary>
public static IEnumerable<T> InsertEnumAt<T>(this IEnumerable<T> source,
int i, IEnumerable<T> inserted) {
return source.Take(i).Concat(inserted).Concat(source.Skip(i));
}
/// <summary>
/// 順列を得る
/// O(N!)
/// </summary>
public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> source,
int n) {
if (n == 0 || source.IsEmpty() || source.Count() < n) {
return Enumerable.Empty<IEnumerable<T>>();
} else if (n == 1) {
return source.Select(i => new List<T> { i });
} else {
var nexts = source.Select(
(x, i) => new { next = source.Take(i).Concat(source.Skip(i + 1)),
selected = source.Take(i + 1).Last() });
return nexts.SelectMany(
next => Perm(next.next, n - 1)
.Select(item => item.Prepend(next.selected)));
}
}
/// <summary>
/// シーケンスの隣り合う要素を2引数の関数に適用したシーケンスを得る
/// </summary>
/// <para>O(N)</para>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数</param>
/// <example>[1,2,3,4].MapAdjacent(f) => [f(1,2), f(2,3), f(3,4)]</example>
public static IEnumerable<TR> MapAdjacent<T1, TR>(this IEnumerable<T1> source,
Func<T1, T1, TR> func) {
var list = source.ToList();
return Enumerable.Range(1, list.Count - 1)
.Select(i => func(list[i], list[i - 1]));
}
/// <summary>
/// 累積項を要素にもつシーケンスを得る(初項は、first)
/// <para>O(N)</para>
/// </summary>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数f</param>
/// <param name="first">func(first, source[0])のための初項</param>
/// <example> [1,2,3].Scanl1(f,0) => [0, f(0,1), f(f(0,1),2),
/// f(f(f(0,1),2),3)]</example>
public static IEnumerable<TR> Scanl<T, TR>(this IEnumerable<T> source,
Func<TR, T, TR> func, TR first) {
var list = source.ToList();
var result = new List<TR> { first };
foreach (var i in Enumerable.Range(1, source.Count())) {
result.Add(func(result[i - 1], list[i]));
}
return result;
}
/// <summary>
/// 累積項を要素にもつシーケンスを得る(初項は、source.First())
/// <para>O(N)</para>
/// </summary>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数f</param>
/// <example> [1,2,3].Scanl1(f) => [1, f(1,2), f(f(1,2),3)]</example>
public static IEnumerable<T> Scanl1<T>(this IEnumerable<T> source,
Func<T, T, T> func) {
var list = source.ToList();
var result = new List<T> { list[0] };
foreach (var i in Enumerable.Range(1, source.Count() - 1)) {
result.Add(func(result[i - 1], list[i]));
}
return result;
}
/// <summary>
/// 昇順にソートしたインデックスを得る
/// </summary>
/// <para>O(N * log N)</para>
public static IEnumerable<int> SortIndex<T>(this IEnumerable<T> source) {
return source.Select((item, i) => new { Item = item, Index = i })
.OrderBy(x => x.Item)
.Select(x => x.Index);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static AtCoderTemplate.MyExtensions;
using static AtCoderTemplate.MyInputOutputs;
using static AtCoderTemplate.MyNumericFunctions;
namespace AtCoderTemplate {
public class Program {
public static void Main(string[] args) {
var NK = ReadInts();
var N = NK[0];
var K = NK[1];
var S = Console.ReadLine();
var gaps = new List<int> { 0 };
foreach (var i in Enumerable.Range(1, S.Count() - 1)) {
if (S[i - 1] != S[i]) {
gaps.Add(i);
}
}
gaps.Add(S.Length);
var gapNum = gaps.MapAdjacent((gap1, gap2) => Abs(gap2 - gap1)).ToList();
if (S[0] == '0')
gapNum = gapNum.Prepend(0).ToList();
if (S[S.Length - 1] == '0')
gapNum.Add(0);
// PrintRow (gapNum);
// 累積和
var firstSum = gapNum.Take(2 * K + 1).Sum();
// PrintRow (gapNum.Take (2 * K + 1));
var sum = new List<int> { firstSum };
var k = 1;
while (2 * (k + K) < gapNum.Count) {
sum.Add(sum[k - 1] - (gapNum[2 * (k - 1)] + gapNum[2 * (k - 1) + 1]) +
(gapNum[2 * (k + K) - 1] + gapNum[2 * (k + K)]));
// Print ($"{k} {sum[k]}");
k++;
}
Print(sum.Max());
}
}
static class MyInputOutputs {
/* Input & Output*/
public static int ReadInt() { return int.Parse(Console.ReadLine()); }
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static List<int> ReadInts() {
return Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList();
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(c => long.Parse(c)).ToList();
}
public static List<List<int>> ReadIntColumns(int n) {
/*
入力例
A1 B1
A2 B2
...
An Bn
出力例
[[A1,A2,...,An], [B1,B2,...,Bn]]
*/
var rows = Enumerable.Range(0, n).Select(i => ReadInts()).ToList();
var m = rows.FirstOrDefault()?.Count() ?? 0;
return Enumerable.Range(0, m)
.Select(i => rows.Select(items => items[i]).ToList())
.ToList();
}
public static List<List<long>> ReadLongColumns(int n) {
/*
入力例
A1 B1
A2 B2
...
An Bn
出力例
[[A1,A2,...,An], [B1,B2,...,Bn]]
*/
var rows = Enumerable.Range(0, n).Select(i => ReadLongs()).ToList();
var m = rows.FirstOrDefault()?.Count() ?? 0;
return Enumerable.Range(0, m)
.Select(i => rows.Select(items => items[i]).ToList())
.ToList();
}
public static void Print<T>(T item) { Console.WriteLine(item); }
public static void PrintIf<T1, T2>(bool condition, T1 trueResult,
T2 falseResult) {
if (condition) {
Console.WriteLine(trueResult);
} else {
Console.WriteLine(falseResult);
}
}
public static void PrintRow<T>(IEnumerable<T> list) {
/* 横ベクトルで表示
A B C D ...
*/
if (!list.IsEmpty()) {
Console.Write(list.First());
foreach (var item in list.Skip(1)) {
Console.Write($" {item}");
}
}
Console.Write("\n");
}
public static void PrintColomn<T>(IEnumerable<T> list) {
/* 縦ベクトルで表示
A
B
C
D
...
*/
foreach (var item in list) {
Console.WriteLine(item);
}
}
public static void Print2DArray<T>(IEnumerable<IEnumerable<T>> sources) {
foreach (var row in sources) {
PrintRow(row);
}
}
}
static class MyNumericFunctions {
public static bool isEven(int a) { return a % 2 == 0; }
public static bool isEven(long a) { return a % 2 == 0; }
public static bool isOdd(int a) { return !isEven(a); }
public static bool isOdd(long a) { return !isEven(a); }
public static long nPk(int n, int k) {
if (k > n) {
return 0;
} else {
return Enumerable.Range(n - k + 1, k)
.Aggregate((long)1, ((i, m) => i * m));
}
}
public static long Fact(int n) { return nPk(n, n); }
public static long nCk(int n, int k) {
if (k > n) {
return 0;
} else {
return nPk(n, k) / Fact(k);
}
}
// 最大公約数
public static long GCD(long m, long n) {
if (m < n) {
return GCD(n, m);
} else if (n == 0) {
return m;
} else {
return GCD(n, m % n);
}
}
// 最小公倍数
public static long LCM(long m, long n) {
if (m < n) {
return LCM(n, m);
} else {
return (m * n) / GCD(m, n);
}
}
}
static class MyExtensions {
// AppendとPrependが、.NET Standard 1.6からの追加で、Mono 4.6.2
// はそれに対応して仕様はあるが、実装がない
public static IEnumerable<T> Append<T>(this IEnumerable<T> source,
T element) {
return source.Concat(Enumerable.Repeat(element, 1));
}
public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source,
T element) {
return Enumerable.Repeat(element, 1).Concat(source);
}
// TakeLastとSkipLastが、.Net Standard 2.1からの追加で、Mono 4.6.2
// はそれに対応していない
public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source,
int count) {
return source.Skip(source.Count() - count);
}
public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source,
int count) {
return source.Take(source.Count() - count);
}
public static bool IsEmpty<T>(this IEnumerable<T> source) {
return !source.Any();
}
/// <summary>
/// インデックスiの位置の要素からk個取り除く
/// O(N)
/// </summary>
public static IEnumerable<T> TakeAwayRange<T>(this IEnumerable<T> source,
int i, int count) {
return source.Take(i).Concat(source.Skip(i + count));
}
/// <summary>
/// インデックスiの位置の要素を取り除く
/// O(N)
/// </summary>
public static IEnumerable<T> TakeAwayAt<T>(this IEnumerable<T> source,
int i) {
return source.TakeAwayRange(i, 1);
}
/// <summary>
/// インデックスiの位置にシーケンスを挿入する
/// O(N + K)
/// </summary>
public static IEnumerable<T> InsertEnumAt<T>(this IEnumerable<T> source,
int i, IEnumerable<T> inserted) {
return source.Take(i).Concat(inserted).Concat(source.Skip(i));
}
/// <summary>
/// 順列を得る
/// O(N!)
/// </summary>
public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> source,
int n) {
if (n == 0 || source.IsEmpty() || source.Count() < n) {
return Enumerable.Empty<IEnumerable<T>>();
} else if (n == 1) {
return source.Select(i => new List<T> { i });
} else {
var nexts = source.Select(
(x, i) => new { next = source.Take(i).Concat(source.Skip(i + 1)),
selected = source.Take(i + 1).Last() });
return nexts.SelectMany(
next => Perm(next.next, n - 1)
.Select(item => item.Prepend(next.selected)));
}
}
/// <summary>
/// シーケンスの隣り合う要素を2引数の関数に適用したシーケンスを得る
/// </summary>
/// <para>O(N)</para>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数</param>
/// <example>[1,2,3,4].MapAdjacent(f) => [f(1,2), f(2,3), f(3,4)]</example>
public static IEnumerable<TR> MapAdjacent<T1, TR>(this IEnumerable<T1> source,
Func<T1, T1, TR> func) {
var list = source.ToList();
return Enumerable.Range(1, list.Count - 1)
.Select(i => func(list[i], list[i - 1]));
}
/// <summary>
/// 累積項を要素にもつシーケンスを得る(初項は、first)
/// <para>O(N)</para>
/// </summary>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数f</param>
/// <param name="first">func(first, source[0])のための初項</param>
/// <example> [1,2,3].Scanl1(f,0) => [0, f(0,1), f(f(0,1),2),
/// f(f(f(0,1),2),3)]</example>
public static IEnumerable<TR> Scanl<T, TR>(this IEnumerable<T> source,
Func<TR, T, TR> func, TR first) {
var list = source.ToList();
var result = new List<TR> { first };
foreach (var i in Enumerable.Range(1, source.Count())) {
result.Add(func(result[i - 1], list[i]));
}
return result;
}
/// <summary>
/// 累積項を要素にもつシーケンスを得る(初項は、source.First())
/// <para>O(N)</para>
/// </summary>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数f</param>
/// <example> [1,2,3].Scanl1(f) => [1, f(1,2), f(f(1,2),3)]</example>
public static IEnumerable<T> Scanl1<T>(this IEnumerable<T> source,
Func<T, T, T> func) {
var list = source.ToList();
var result = new List<T> { list[0] };
foreach (var i in Enumerable.Range(1, source.Count() - 1)) {
result.Add(func(result[i - 1], list[i]));
}
return result;
}
/// <summary>
/// 昇順にソートしたインデックスを得る
/// </summary>
/// <para>O(N * log N)</para>
public static IEnumerable<int> SortIndex<T>(this IEnumerable<T> source) {
return source.Select((item, i) => new { Item = item, Index = i })
.OrderBy(x => x.Item)
.Select(x => x.Index);
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["-", 8, 196, 0, 52, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 52, 15, 16, 12, 214, 205, 22]]
| 8
| 2,039
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace D___Handstand {
class Program {
static void Main(string[] args) {
var read = Console.ReadLine().Split(' ');
var N = int.Parse(read[0]);
var K = int.Parse(read[1]);
var S = Console.ReadLine();
var switch01 = new List<int>();
switch01.Add(0);
for (int i = 1; i < S.Length - 1; i++)
if (S[i] != S[i - 1])
switch01.Add(i);
switch01.Add(S.Length);
var continuousHandstand = new List<int>();
for (int i = 0; i < switch01.Count - 1; i++)
continuousHandstand.Add(
S[switch01[i]] == 0
? switch01[Math.Min(switch01.Count - 1, i + 2 * K)] - switch01[i]
: switch01[Math.Min(switch01.Count - 1, i + 2 * K + 1)] -
switch01[i]);
Console.WriteLine(continuousHandstand.Max());
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace D___Handstand {
class Program {
static void Main(string[] args) {
var read = Console.ReadLine().Split(' ');
var N = int.Parse(read[0]);
var K = int.Parse(read[1]);
var S = Console.ReadLine();
var switch01 = new List<int>();
switch01.Add(0);
for (int i = 1; i < S.Length; i++)
if (S[i] != S[i - 1])
switch01.Add(i);
switch01.Add(S.Length);
var continuousHandstand = new List<int>();
for (int i = 0; i < switch01.Count - 1; i++)
continuousHandstand.Add(
S[switch01[i]] == '0'
? switch01[Math.Min(switch01.Count - 1, i + 2 * K)] - switch01[i]
: switch01[Math.Min(switch01.Count - 1, i + 2 * K + 1)] -
switch01[i]);
Console.WriteLine(continuousHandstand.Max());
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 28, 0, 41, 15, 16, 12, 252, 0, 104]]
| 8
| 258
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class340 {
static void Main() {
int N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
var d1 = new int[N];
var d2 = new int[N];
d1[0] = A[0];
d2[0] = A[N - 1];
for (int i = 0; i < N - 1; i++) {
d1[i + 1] = GCD(d1[i], A[i + 1]);
d2[i + 1] = GCD(d2[i], A[N - 2 - i]);
}
int ans = 0;
for (int i = 0; i < N; i++) {
if (i == 0)
ans = Math.Max(ans, d2[N - 1]);
else if (i == N - 1)
ans = Math.Max(ans, d1[N - 1]);
else {
ans = Math.Max(ans, GCD(d1[i - 1], d2[N - 2 - i]));
}
}
Console.WriteLine(ans);
}
static int GCD(int a, int b) => a <= 0 ? b : GCD(b % a, a);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class340 {
static void Main() {
int N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
var d1 = new int[N];
var d2 = new int[N];
d1[0] = A[0];
d2[0] = A[N - 1];
for (int i = 0; i < N - 1; i++) {
d1[i + 1] = GCD(d1[i], A[i + 1]);
d2[i + 1] = GCD(d2[i], A[N - 2 - i]);
}
int ans = 0;
for (int i = 0; i < N; i++) {
if (i == 0)
ans = Math.Max(ans, d2[N - 2]);
else if (i == N - 1)
ans = Math.Max(ans, d1[N - 2]);
else {
ans = Math.Max(ans, GCD(d1[i - 1], d2[N - 2 - i]));
}
}
Console.WriteLine(ans);
}
static int GCD(int a, int b) => a <= 0 ? b : GCD(b % a, a);
}
}
|
[["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 316
| 4
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
static class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
//
var N = GetInt();
var A = GetLongArray();
var leftpro = new long[N];
leftpro[0] = A.First();
var rightpro = new long[N];
rightpro[0] = A.Last();
for (int i = 1; i < N; i++) {
leftpro[i] = GCD(leftpro[i - 1], A[i]);
rightpro[i] = GCD(rightpro[i - 1], A[N - 1 - i]);
}
var max = Math.Max(leftpro[N - 2], rightpro[N - 2]);
for (int i = 1; i < N - 1; i++) {
max = Math.Max(max, GCD(rightpro[i - 1], leftpro[N - 1 - i]));
}
Console.WriteLine(max);
//
Console.Out.Flush();
Console.ReadKey();
}
static void Solve() {}
static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
static public string GetStr() { return Console.ReadLine().Trim(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
static public int[] GetIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Split(' ').Select(char.Parse).ToArray();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteObjects<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
static string yesno(this bool b) { return b ? "yes" : "no"; }
static string YesNo(this bool b) { return b ? "Yes" : "No"; }
static string YESNO(this bool b) { return b ? "YES" : "NO"; }
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V>(out T a, out U b, out V c, out V d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<V>(ar[3]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
static class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
//
var N = GetInt();
var A = GetLongArray();
var leftpro = new long[N];
leftpro[0] = A.First();
var rightpro = new long[N];
rightpro[0] = A.Last();
for (int i = 1; i < N; i++) {
leftpro[i] = GCD(leftpro[i - 1], A[i]);
rightpro[i] = GCD(rightpro[i - 1], A[N - 1 - i]);
}
var max = Math.Max(leftpro[N - 2], rightpro[N - 2]);
for (int i = 1; i < N - 1; i++) {
max = Math.Max(max, GCD(rightpro[i - 1], leftpro[N - 2 - i]));
}
Console.WriteLine(max);
//
Console.Out.Flush();
Console.ReadKey();
}
static void Solve() {}
static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
static public string GetStr() { return Console.ReadLine().Trim(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
static public int[] GetIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Split(' ').Select(char.Parse).ToArray();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteObjects<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
static string yesno(this bool b) { return b ? "yes" : "no"; }
static string YesNo(this bool b) { return b ? "Yes" : "No"; }
static string YESNO(this bool b) { return b ? "YES" : "NO"; }
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V>(out T a, out U b, out V c, out V d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<V>(ar[3]);
}
}
}
|
[["-", 206, 207, 0, 28, 0, 16, 31, 16, 12, 203], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 12, 203]]
| 8
| 1,033
| 2
|
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(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
int t = int.Parse(s[2]);
// b*(t/a)が答え
Console.WriteLine(b * (t / a));
}
}
class ProgramB {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
string[] v = Console.ReadLine().Split(' ');
string[] c = Console.ReadLine().Split(' ');
int sum = 0;
// v-cをしてマイナスでなければ足す
for (int i = 0; i < n; i++) {
if (int.Parse(v[i]) - int.Parse(c[i]) > 0)
sum += int.Parse(v[i]) - int.Parse(c[i]);
}
//答え出力
Console.WriteLine(sum);
}
}
class ProgramC {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
long[] R = new long[n];
long[] L = new long[n];
string[] a = Console.ReadLine().Split(' ');
L[0] = long.Parse(a[0]);
R[0] = long.Parse(a[n - 1]);
//左からのgcdと右からのgcdを求める
for (int i = 1; i < n; i++) {
L[i] = gcd(L[i - 1], long.Parse(a[i]));
R[i] = gcd(R[i - 1], long.Parse(a[n - 1 - i]));
}
long max = 0;
for (int i = 0; i < n; i++) {
//それぞれの位置で引き出す
long temp = 0;
if (i == 0) //一番左は右n-1個分のみで考える
temp = R[n - 2];
else if (i == n - 1) //一番右は左n-1個分のみで考える
temp = L[n - 2];
else
temp = gcd(L[i], R[n - 2 - i]);
//最大を求める
max = Math.Max(max, temp);
}
//答えを出力
Console.WriteLine(max);
}
/*最大公約数を求める関数*/
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 {
static void main() {
//入力
string[] input = Console.ReadLine().Split(' ');
int H = int.Parse(input[0]);
int W = int.Parse(input[1]);
int INF = 1000000;
//ワーシャルフロイド法の準備。すべてとりあえず#とする。(そうするとこのあと.だけの判定で済む)
int[,] dis = new int[H * W + 1, H * W + 1];
for (int i = 0; i < H * W; i++)
for (int j = 0; j < H * W; j++) {
if (i == j)
dis[i, j] = 0;
else
dis[i, j] = INF;
}
//前の迷路状態を記録して置くためにmaze2を作成。
string maze2 = "####################";
for (int i = 0; i < H; i++) {
//迷路を読み込む
string maze = Console.ReadLine();
for (int j = 0; j < W; j++) {
//横のつながりを判定する。つながっていれば1を代入
if (j > 0 && maze[j - 1] == '.' && maze[j] == '.') {
dis[i * W + j, i * W + j - 1] = 1;
dis[i * W + j - 1, i * W + j] = 1;
}
//縦のつながりを判定する。ひとつ上と判定します。
if (i > 0 && maze2[j] == '.' && maze[j] == '.') {
dis[i * W + j, (i - 1) * W + j] = 1;
dis[(i - 1) * W + j, i * W + j] = 1;
}
}
//メイズを記録する
maze2 = maze;
}
//ワーシャルフロイド法を用いる
for (int k = 0; k < H * W; k++) // 経由する頂点
for (int i = 0; i < H * W; i++) // 始点
for (int j = 0; j < H * W; j++) // 終点
dis[i, j] = Math.Min(dis[i, j], dis[i, k] + dis[k, j]);
int ans = 0;
//最大の経路を算出する
for (int i = 0; i < H * W; i++)
for (int j = 0; j < H * W; j++) {
if (dis[i, j] <= INF) {
int temp = dis[i, j];
if (ans < temp)
ans = temp;
}
}
//答を出す
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(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
int t = int.Parse(s[2]);
// b*(t/a)が答え
Console.WriteLine(b * (t / a));
}
}
class ProgramB {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
string[] v = Console.ReadLine().Split(' ');
string[] c = Console.ReadLine().Split(' ');
int sum = 0;
// v-cをしてマイナスでなければ足す
for (int i = 0; i < n; i++) {
if (int.Parse(v[i]) - int.Parse(c[i]) > 0)
sum += int.Parse(v[i]) - int.Parse(c[i]);
}
//答え出力
Console.WriteLine(sum);
}
}
class ProgramC {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
long[] R = new long[n];
long[] L = new long[n];
string[] a = Console.ReadLine().Split(' ');
L[0] = long.Parse(a[0]);
R[0] = long.Parse(a[n - 1]);
//左からのgcdと右からのgcdを求める
for (int i = 1; i < n; i++) {
L[i] = gcd(L[i - 1], long.Parse(a[i]));
R[i] = gcd(R[i - 1], long.Parse(a[n - 1 - i]));
}
long max = 0;
for (int i = 0; i < n; i++) {
//それぞれの位置で引き出す
long temp = 0;
if (i == 0) //一番左は右n-1個分のみで考える
temp = R[n - 2];
else if (i == n - 1) //一番右は左n-1個分のみで考える
temp = L[n - 2];
else
temp = gcd(L[i - 1], R[n - 2 - i]);
//最大を求める
max = Math.Max(max, temp);
}
//答えを出力
Console.WriteLine(max);
}
/*最大公約数を求める関数*/
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 {
static void main() {
//入力
string[] input = Console.ReadLine().Split(' ');
int H = int.Parse(input[0]);
int W = int.Parse(input[1]);
int INF = 1000000;
//ワーシャルフロイド法の準備。すべてとりあえず#とする。(そうするとこのあと.だけの判定で済む)
int[,] dis = new int[H * W + 1, H * W + 1];
for (int i = 0; i < H * W; i++)
for (int j = 0; j < H * W; j++) {
if (i == j)
dis[i, j] = 0;
else
dis[i, j] = INF;
}
//前の迷路状態を記録して置くためにmaze2を作成。
string maze2 = "####################";
for (int i = 0; i < H; i++) {
//迷路を読み込む
string maze = Console.ReadLine();
for (int j = 0; j < W; j++) {
//横のつながりを判定する。つながっていれば1を代入
if (j > 0 && maze[j - 1] == '.' && maze[j] == '.') {
dis[i * W + j, i * W + j - 1] = 1;
dis[i * W + j - 1, i * W + j] = 1;
}
//縦のつながりを判定する。ひとつ上と判定します。
if (i > 0 && maze2[j] == '.' && maze[j] == '.') {
dis[i * W + j, (i - 1) * W + j] = 1;
dis[(i - 1) * W + j, i * W + j] = 1;
}
}
//メイズを記録する
maze2 = maze;
}
//ワーシャルフロイド法を用いる
for (int k = 0; k < H * W; k++) // 経由する頂点
for (int i = 0; i < H * W; i++) // 始点
for (int j = 0; j < H * W; j++) // 終点
dis[i, j] = Math.Min(dis[i, j], dis[i, k] + dis[k, j]);
int ans = 0;
//最大の経路を算出する
for (int i = 0; i < H * W; i++)
for (int j = 0; j < H * W; j++) {
if (dis[i, j] <= INF) {
int temp = dis[i, j];
if (ans < temp)
ans = temp;
}
}
//答を出す
Console.WriteLine(ans);
}
}
}
|
[["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 1,121
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
namespace CSharpSpiral {
class Program {
static void Main(string[] args) {
var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
#if DEBUG
true
#else
false
#endif
};
Console.SetOut(sw);
new Program().Solve(new ConsoleInput(
#if DEBUG
new StreamReader("../../../inputData.txt")
#else
Console.In
#endif
,
' '));
Console.Out.Flush();
}
public void Solve(ConsoleInput cin) {
var N = cin.ReadInt;
var A = cin.ReadIntArray(N);
var LeftGCD = new int[N];
var RightGCD = new int[N];
LeftGCD[0] = A[0];
RightGCD[N - 1] = A[N - 1];
for (int i = 1; i < N; i++)
LeftGCD[i] = gcd(LeftGCD[0], A[i]);
for (int i = N - 2; i >= 0; i--)
RightGCD[i] = gcd(RightGCD[i + 1], A[i]);
var Res = new int[N];
Res[0] = RightGCD[1];
Res[N - 1] = LeftGCD[N - 2];
for (int i = 1; i < N - 1; i++)
Res[i] = gcd(LeftGCD[i - 1], RightGCD[i + 1]);
Console.WriteLine(Res.Max());
}
private static int gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
}
static class ExtendClass {
public static void Swap<T>(this T[] A, int x, int y) {
var tmp = A[x];
A[x] = A[y];
A[y] = tmp;
}
public static string Join<T>(this IEnumerable<T> X,
string separator = " ") => string.Join(separator,
X);
public static IEnumerable<int>
Indices<T>(this T[] X) => Enumerable.Range(0, X.Length);
public static IEnumerable<int>
Indices<T>(this T[,] X, int dim) => Enumerable.Range(0, X.GetLength(dim));
public static string Join<T>(this T[,] X, string separatorD2 = ",",
string separatorD1 = "\n") =>
X.Indices(0)
.Select(i => X.Indices(1).Select(j => X[i, j]).Join(separatorD2))
.Join(separatorD1);
}
class ConsoleInput {
private readonly TextReader _stream;
private readonly char _separator = ' ';
private readonly Queue<string> inputStream;
public ConsoleInput(TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
public double[] ReadDoubleArray(long N) {
var ret = new double[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadDouble;
return ret;
}
public bool isEOF {
get { return _stream.Peek() == -1; }
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
namespace CSharpSpiral {
class Program {
static void Main(string[] args) {
var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
#if DEBUG
true
#else
false
#endif
};
Console.SetOut(sw);
new Program().Solve(new ConsoleInput(
#if DEBUG
new StreamReader("../../../inputData.txt")
#else
Console.In
#endif
,
' '));
Console.Out.Flush();
}
public void Solve(ConsoleInput cin) {
var N = cin.ReadInt;
var A = cin.ReadIntArray(N);
var LeftGCD = new int[N];
var RightGCD = new int[N];
LeftGCD[0] = A[0];
RightGCD[N - 1] = A[N - 1];
for (int i = 1; i < N; i++)
LeftGCD[i] = gcd(LeftGCD[i - 1], A[i]);
for (int i = N - 2; i >= 0; i--)
RightGCD[i] = gcd(RightGCD[i + 1], A[i]);
var Res = new int[N];
Res[0] = RightGCD[1];
Res[N - 1] = LeftGCD[N - 2];
for (int i = 1; i < N - 1; i++)
Res[i] = gcd(LeftGCD[i - 1], RightGCD[i + 1]);
Console.WriteLine(Res.Max());
}
private static int gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
}
static class ExtendClass {
public static void Swap<T>(this T[] A, int x, int y) {
var tmp = A[x];
A[x] = A[y];
A[y] = tmp;
}
public static string Join<T>(this IEnumerable<T> X,
string separator = " ") => string.Join(separator,
X);
public static IEnumerable<int>
Indices<T>(this T[] X) => Enumerable.Range(0, X.Length);
public static IEnumerable<int>
Indices<T>(this T[,] X, int dim) => Enumerable.Range(0, X.GetLength(dim));
public static string Join<T>(this T[,] X, string separatorD2 = ",",
string separatorD1 = "\n") =>
X.Indices(0)
.Select(i => X.Indices(1).Select(j => X[i, j]).Join(separatorD2))
.Join(separatorD1);
}
class ConsoleInput {
private readonly TextReader _stream;
private readonly char _separator = ' ';
private readonly Queue<string> inputStream;
public ConsoleInput(TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
public double[] ReadDoubleArray(long N) {
var ret = new double[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadDouble;
return ret;
}
public bool isEOF {
get { return _stream.Peek() == -1; }
}
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 995
| 4
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var N = sc.ReadInt();
var A = sc.ReadLongArray(N);
var gr = new long[N];
var gl = new long[N];
gl[0] = A[0];
for (int i = 1; i < N; i++) {
gl[i] = Gcd(gl[i - 1], A[i]);
}
gr[N - 1] = A[N - 1];
for (int i = N - 2; i >= 0; i--) {
gr[i] = Gcd(gr[i + 1], A[i]);
}
var ans = 1L;
for (int i = 0; i < N; i++) {
if (i == 0) {
ans = Math.Max(ans, gr[N - 2]);
} else if (i == N - 1) {
ans = Math.Max(ans, gl[N - 2]);
} else {
var l = gl[i - 1];
var r = gr[i + 1];
ans = Math.Max(ans, Gcd(l, r));
}
}
Console.WriteLine(ans);
}
static long Gcd(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var N = sc.ReadInt();
var A = sc.ReadLongArray(N);
var gr = new long[N];
var gl = new long[N];
gl[0] = A[0];
for (int i = 1; i < N; i++) {
gl[i] = Gcd(gl[i - 1], A[i]);
}
gr[N - 1] = A[N - 1];
for (int i = N - 2; i >= 0; i--) {
gr[i] = Gcd(gr[i + 1], A[i]);
}
var ans = 1L;
for (int i = 0; i < N; i++) {
if (i == 0) {
ans = Math.Max(ans, gr[1]);
} else if (i == N - 1) {
ans = Math.Max(ans, gl[N - 2]);
} else {
var l = gl[i - 1];
var r = gr[i + 1];
ans = Math.Max(ans, Gcd(l, r));
}
}
Console.WriteLine(ans);
}
static long Gcd(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["-", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 1,366
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Hello {
static public int mod = 1000000007;
public static void Main() {
// 方針
//
int n = rint();
long[] a = longa();
long[] lgcd = new long[n - 1];
long[] rgcd = new long[n - 1];
lgcd[0] = a[0];
rgcd[n - 2] = a[n - 1];
for (int i = 1; i < n - 1; i++) {
lgcd[i] = GCD(lgcd[i - 1], a[i]);
}
for (int i = n - 3; i >= 0; i--) {
rgcd[i] = GCD(rgcd[i + 1], a[i + 1]);
}
long max = 0;
// WriteLine(string.Join(" ",rgcd));
for (int i = 0; i < n - 1; i++) {
if (i == 0) {
max = Max(max, rgcd[i]);
} else if (i == n - 2) {
max = Max(max, lgcd[i]);
} else {
max = Max(max, GCD(rgcd[i], lgcd[i - 1]));
}
}
WriteLine(max);
}
static void unionfind(ref int[] uni, int a, int b) {
var memo = new List<int>();
memo.Add(a);
memo.Add(b);
int min = Min(a, b);
while (uni[a] != a) {
a = uni[a];
memo.Add(a);
}
while (uni[b] != b) {
b = uni[b];
memo.Add(b);
}
min = Min(min, a);
min = Min(min, b);
foreach (var k in memo) {
uni[k] = min;
}
}
static int unionfind2(ref int[] uni, int a) {
var memo = new List<int>();
memo.Add(a);
while (uni[a] != a) {
a = uni[a];
memo.Add(a);
}
foreach (var k in memo) {
uni[k] = a;
}
return a;
}
static int binarysearchd(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] >= b) {
return 0;
} else if (a[leng - 1] < b) {
return leng;
} else {
if (a[max] < b) {
return max + 1;
}
return min + 1;
}
}
static int binarysearchu(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] > b) {
return leng;
} else if (a[leng - 1] <= b) {
return 0;
} else {
if (a[max] <= b) {
return leng - (max + 1);
}
return leng - (min + 1);
}
}
// 1からaまでの数字並べ替え全通り返すやつ
static List<string> permutation(int a) {
var list = new List<string>();
if (a == 1) {
list.Add("1");
return list;
} else {
foreach (var k in permutation(a - 1)) {
var ch = k.ToCharArray();
for (int i = 0; i <= ch.Length; i++) {
string intemp = "";
if (i == 0) {
intemp += a.ToString();
}
for (int j = 0; j < ch.Length; j++) {
intemp += ch[j].ToString();
if (i == j + 1) {
intemp += a.ToString();
}
}
list.Add(intemp);
}
}
}
return list;
}
static void swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}
static void charswap(ref char a, ref char b) {
char temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
static int square2(int a, int b) {
long output = 1;
var list = new List<long>();
int sh = 1;
long n = a;
list.Add(a);
while (sh < b) {
sh *= 2;
n = n * n % mod;
list.Add(n);
}
for (int i = list.Count - 1; i >= 0; i--) {
if (b > sh) {
b -= sh;
sh /= 2;
output = output * list[i] % mod;
}
}
return (int)output;
}
//各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
//知見
// (string) hogestr -> (char[]) hoge
// char hoge = hogestr.ToCharArray();
// (char[]) hoge -> (string) hogestr
// string hoge = new string(hoge);
// Hashtable × Dictionary ○
// Dictionary hoge<string,int>
// hoge.ContainsKey(string) -> return boolean
// hoge[string] -> return int
// hoge[int] -> CE
// Dictionary hoge<int1,int2>
// hoge<int1,int2>: hoge[int1] -> return int2
// KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2
// SortedDictionary() > SortedList() ???
// キュー -> 幅優先 ???
// var queue = new Queue<int>(); queue.Enqueue() queue.Dequeue()
// スタック -> 深さ優先 ???
// var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stackPeek()
// stack.Count
// if (list?.Count > 0) リストが空でもnullでもない
// ソート
// list.Sort(StringComparer.Ordinal); listの(辞書順?)ソート
// StringComparer.Ordinal とは
// Array.Sort(list1,list2);
// 出力
// foreach(var a int list){ WriteLine(a); } より
// WriteLine(string.Join("\n", list)); が速い
// var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
// Console.SetOut(sw);
// foreach(var k in list[num-1]){
// WriteLine(k);
// }
// Console.Out.Flush();
// 未知
// 最小費用流
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Hello {
static public int mod = 1000000007;
public static void Main() {
// 方針
//
int n = rint();
long[] a = longa();
long[] lgcd = new long[n - 1];
long[] rgcd = new long[n - 1];
lgcd[0] = a[0];
rgcd[n - 2] = a[n - 1];
for (int i = 1; i < n - 1; i++) {
lgcd[i] = GCD(lgcd[i - 1], a[i]);
}
for (int i = n - 3; i >= 0; i--) {
rgcd[i] = GCD(rgcd[i + 1], a[i + 1]);
}
long max = 0;
// WriteLine(string.Join(" ",rgcd));
for (int i = 0; i < n; i++) {
if (i == 0) {
max = Max(max, rgcd[i]);
} else if (i == n - 1) {
max = Max(max, lgcd[i - 1]);
} else {
max = Max(max, GCD(rgcd[i], lgcd[i - 1]));
// WriteLine($"{rgcd[i]} {lgcd[i-1]}");
}
}
WriteLine(max);
}
static void unionfind(ref int[] uni, int a, int b) {
var memo = new List<int>();
memo.Add(a);
memo.Add(b);
int min = Min(a, b);
while (uni[a] != a) {
a = uni[a];
memo.Add(a);
}
while (uni[b] != b) {
b = uni[b];
memo.Add(b);
}
min = Min(min, a);
min = Min(min, b);
foreach (var k in memo) {
uni[k] = min;
}
}
static int unionfind2(ref int[] uni, int a) {
var memo = new List<int>();
memo.Add(a);
while (uni[a] != a) {
a = uni[a];
memo.Add(a);
}
foreach (var k in memo) {
uni[k] = a;
}
return a;
}
static int binarysearchd(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] >= b) {
return 0;
} else if (a[leng - 1] < b) {
return leng;
} else {
if (a[max] < b) {
return max + 1;
}
return min + 1;
}
}
static int binarysearchu(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] > b) {
return leng;
} else if (a[leng - 1] <= b) {
return 0;
} else {
if (a[max] <= b) {
return leng - (max + 1);
}
return leng - (min + 1);
}
}
// 1からaまでの数字並べ替え全通り返すやつ
static List<string> permutation(int a) {
var list = new List<string>();
if (a == 1) {
list.Add("1");
return list;
} else {
foreach (var k in permutation(a - 1)) {
var ch = k.ToCharArray();
for (int i = 0; i <= ch.Length; i++) {
string intemp = "";
if (i == 0) {
intemp += a.ToString();
}
for (int j = 0; j < ch.Length; j++) {
intemp += ch[j].ToString();
if (i == j + 1) {
intemp += a.ToString();
}
}
list.Add(intemp);
}
}
}
return list;
}
static void swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}
static void charswap(ref char a, ref char b) {
char temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
static int square2(int a, int b) {
long output = 1;
var list = new List<long>();
int sh = 1;
long n = a;
list.Add(a);
while (sh < b) {
sh *= 2;
n = n * n % mod;
list.Add(n);
}
for (int i = list.Count - 1; i >= 0; i--) {
if (b > sh) {
b -= sh;
sh /= 2;
output = output * list[i] % mod;
}
}
return (int)output;
}
//各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
//知見
// (string) hogestr -> (char[]) hoge
// char hoge = hogestr.ToCharArray();
// (char[]) hoge -> (string) hogestr
// string hoge = new string(hoge);
// Hashtable × Dictionary ○
// Dictionary hoge<string,int>
// hoge.ContainsKey(string) -> return boolean
// hoge[string] -> return int
// hoge[int] -> CE
// Dictionary hoge<int1,int2>
// hoge<int1,int2>: hoge[int1] -> return int2
// KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2
// SortedDictionary() > SortedList() ???
// キュー -> 幅優先 ???
// var queue = new Queue<int>(); queue.Enqueue() queue.Dequeue()
// スタック -> 深さ優先 ???
// var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stackPeek()
// stack.Count
// if (list?.Count > 0) リストが空でもnullでもない
// ソート
// list.Sort(StringComparer.Ordinal); listの(辞書順?)ソート
// StringComparer.Ordinal とは
// Array.Sort(list1,list2);
// 出力
// foreach(var a int list){ WriteLine(a); } より
// WriteLine(string.Join("\n", list)); が速い
// var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
// Console.SetOut(sw);
// foreach(var k in list[num-1]){
// WriteLine(k);
// }
// Console.Out.Flush();
// 未知
// 最小費用流
// 二分探索の理解が浅い
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 1,936
| 6
|
using System;
using System.Linq;
public class HelloWorld {
static long[] A;
static long N;
static long[] left;
static long[] right;
static public void Main() {
//
N = long.Parse(Console.ReadLine());
A = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray();
left = new long[N];
right = new long[N];
var ans = 1L;
lgcd(0);
rgcd(N - 1);
// Console.WriteLine(String.Join(" ",right));
for (int i = 0; i < N; i++) {
long l = 1;
long r = 1;
//左のループ
if (i != 0) {
l = left[i - 1];
}
//右のループ
if (i != N - 1) {
r = right[i + 1];
} else {
r = l;
}
// Console.WriteLine('a');
if (i == 0) {
l = r;
}
// Console.WriteLine(l+""+r);
var tmp = GCD(l, r);
// Console.WriteLine('a');
if (ans < tmp) {
ans = tmp;
}
}
Console.WriteLine(ans);
}
static void lgcd(long n) {
if (n == N - 1) {
return;
} else if (n == 0) {
left[n] = A[0];
lgcd(n + 1);
return;
} else {
left[n] = GCD(left[n - 1], A[n]);
lgcd(n + 1);
return;
}
}
static void rgcd(long n) {
if (n == N - 1) {
right[n] = A[N - 1];
rgcd(n - 1);
return;
} else if (n == 0) {
return;
} else {
right[n] = GCD(right[n + 1], A[n]);
rgcd(n - 1);
return;
}
}
static long GCDP(long s, long g) {
var res = A[s];
for (long i = s + 1; i <= g; i++) {
res = GCD(res, A[i]);
}
return res;
}
static long GCD(long A, long B) {
if (A < B) {
GCD(B, A);
}
long r = A % B;
while (r != 0) {
r = A % B;
A = B;
B = r;
}
return A;
}
}
|
using System;
using System.Linq;
public class HelloWorld {
static long[] A;
static long N;
static long[] left;
static long[] right;
static public void Main() {
//
N = long.Parse(Console.ReadLine());
A = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray();
left = new long[N];
right = new long[N];
var ans = 1L;
lgcd(0);
rgcd(N - 1);
// Console.WriteLine(String.Join(" ",right));
for (int i = 0; i < N; i++) {
long l = 1;
long r = 1;
//左のループ
if (i != 0) {
l = left[i - 1];
}
//右のループ
if (i != N - 1) {
r = right[i + 1];
} else {
r = l;
}
// Console.WriteLine('a');
if (i == 0) {
l = r;
}
// Console.WriteLine(l+""+r);
var tmp = GCD(l, r);
// Console.WriteLine('a');
if (ans < tmp) {
ans = tmp;
}
}
Console.WriteLine(ans);
}
static void lgcd(long n) {
if (n == N - 1) {
return;
} else if (n == 0) {
left[n] = A[0];
lgcd(n + 1);
return;
} else {
left[n] = GCD(left[n - 1], A[n]);
lgcd(n + 1);
return;
}
}
static void rgcd(long n) {
if (n == N - 1) {
right[n] = A[N - 1];
rgcd(n - 1);
return;
} else if (n == 0) {
return;
} else {
right[n] = GCD(right[n + 1], A[n]);
rgcd(n - 1);
return;
}
}
static long GCDP(long s, long g) {
var res = A[s];
for (long i = s + 1; i <= g; i++) {
res = GCD(res, A[i]);
}
return res;
}
static long GCD(long A, long B) {
if (A < B) {
GCD(B, A);
}
long r = A % B;
while (A % B != 0) {
r = A % B;
A = B;
B = r;
}
return B;
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 22]]
| 8
| 510
| 6
|
using System;
using System.Linq;
class C {
static void Main() {
var n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var l = new int[n];
var r = new int[n];
l[0] = a[0];
r[n - 1] = a[n - 1];
for (int i = 1; i < n; i++) {
l[i] = Gcd(l[i - 1], a[i]);
r[n - 1 - i] = Gcd(r[n - i], a[n - 1 - i]);
}
var M1 = Math.Max(r[1], l[n - 2]);
var M2 = Enumerable.Range(1, n - 2).Max(i => Gcd(l[i - 1], r[i + 1]));
Console.WriteLine(Math.Max(M1, M2));
}
static int Gcd(int x, int y) {
for (int r; (r = x % y) > 0; x = y, y = r)
;
return y;
}
}
|
using System;
using System.Linq;
class C {
static void Main() {
var n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var l = new int[n];
var r = new int[n];
l[0] = a[0];
r[n - 1] = a[n - 1];
for (int i = 1; i < n; i++) {
l[i] = Gcd(l[i - 1], a[i]);
r[n - 1 - i] = Gcd(r[n - i], a[n - 1 - i]);
}
var M1 = Math.Max(r[1], l[n - 2]);
var M2 = n <= 2
? 1
: Enumerable.Range(1, n - 2).Max(i => Gcd(l[i - 1], r[i + 1]));
Console.WriteLine(Math.Max(M1, M2));
}
static int Gcd(int x, int y) {
for (int r; (r = x % y) > 0; x = y, y = r)
;
return y;
}
}
|
[["+", 0, 200, 0, 212, 0, 41, 15, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 19], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 64, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102]]
| 8
| 272
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions {
public static int ToInt(this string s) => int.Parse(s);
public static long ToLong(this string s) => long.Parse(s);
public static char ToChar(this string s) => char.Parse(s);
public static double ToDouble(this string s) => double.Parse(s);
public static int[] ToIntArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
public static long[] ToLongArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
public static double[] ToDoubleArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
public static Queue<T>
ToQueue<T>(this IEnumerable<T> seq) => new Queue<T>(seq);
public static Stack<T>
ToStack<T>(this IEnumerable<T> seq) => new Stack<T>(seq);
public static HashSet<T>
ToHashSet<T>(this IEnumerable<T> seq) => new HashSet<T>(seq);
}
static class MyMath {
// static private long gcdInner(long a, long b) => (a % b == 0) ? b :
// gcdInner(b, a % b); static public long GCD(long a, long b) => (a > b) ?
// gcdInner(a, b) : gcdInner(b, a);
static public long GCD(long a,
long b) => (a < b)
? GCD(b, a)
: ((a % b == 0) ? b : GCD(b, a % b));
static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b)
: (b / GCD(a, b) * a);
static private readonly long _m = 1000000000 + 7;
static public long Mod(long val) => (val % _m + _m) % _m;
static private long extGCD(long a, long b, ref long x, ref long y) =>
(b == 0) ? (a + (x = 1) * 0 + (y = 0) * 0)
: (extGCD(b, a % b, ref y, ref x) + (y -= a / b * x) * 0);
static public long ModInverse(long a, long dummy1 = 0, long dummy2 = 0) =>
extGCD(a, _m, ref dummy1, ref dummy2) * 0 + Mod(dummy1);
}
class Program {
static string[] ReadLines(int n) =>
Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();
static void Main() {
int N = int.Parse(Console.ReadLine());
int[] AList =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int[] GCD_Ruiseki_L = new int[N];
int[] GCD_Ruiseki_R = new int[N];
// Lには、i番目よりも左側にある数のGCDをiに入れる。
// Rには、i番目よりも右側にある数のGCDをiに入れる。
for (int i = 1; i < N; i++) {
GCD_Ruiseki_L[i] = (int)MyMath.GCD(GCD_Ruiseki_L[i - 1], AList[i - 1]);
GCD_Ruiseki_R[N - 1 - i] =
(int)MyMath.GCD(GCD_Ruiseki_R[N - 1 - i + 1], AList[N - 1 - i + 1]);
}
Console.WriteLine(Enumerable.Range(0, N).Max(
n => MyMath.GCD(GCD_Ruiseki_R[n], GCD_Ruiseki_L[n])));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions {
public static int ToInt(this string s) => int.Parse(s);
public static long ToLong(this string s) => long.Parse(s);
public static char ToChar(this string s) => char.Parse(s);
public static double ToDouble(this string s) => double.Parse(s);
public static int[] ToIntArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
public static long[] ToLongArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
public static double[] ToDoubleArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
public static Queue<T>
ToQueue<T>(this IEnumerable<T> seq) => new Queue<T>(seq);
public static Stack<T>
ToStack<T>(this IEnumerable<T> seq) => new Stack<T>(seq);
public static HashSet<T>
ToHashSet<T>(this IEnumerable<T> seq) => new HashSet<T>(seq);
}
static class MyMath {
// static private long gcdInner(long a, long b) => (a % b == 0) ? b :
// gcdInner(b, a % b);
static public long GCD(long a,
long b) => (a < b) ? GCD(b, a)
: ((b == 0) ? a : GCD(b, a % b));
static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b)
: (b / GCD(a, b) * a);
static private readonly long _m = 1000000000 + 7;
static public long Mod(long val) => (val % _m + _m) % _m;
static private long extGCD(long a, long b, ref long x, ref long y) =>
(b == 0) ? (a + (x = 1) * 0 + (y = 0) * 0)
: (extGCD(b, a % b, ref y, ref x) + (y -= a / b * x) * 0);
static public long ModInverse(long a, long dummy1 = 0, long dummy2 = 0) =>
extGCD(a, _m, ref dummy1, ref dummy2) * 0 + Mod(dummy1);
}
class Program {
static string[] ReadLines(int n) =>
Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();
static void Main() {
int N = int.Parse(Console.ReadLine());
int[] AList =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int[] GCD_Ruiseki_L = new int[N];
int[] GCD_Ruiseki_R = new int[N];
// Lには、i番目よりも左側にある数のGCDをiに入れる。
// Rには、i番目よりも右側にある数のGCDをiに入れる。
for (int i = 1; i < N; i++) {
GCD_Ruiseki_L[i] = (int)MyMath.GCD(GCD_Ruiseki_L[i - 1], AList[i - 1]);
GCD_Ruiseki_R[N - 1 - i] =
(int)MyMath.GCD(GCD_Ruiseki_R[N - 1 - i + 1], AList[N - 1 - i + 1]);
}
Console.WriteLine(Enumerable.Range(0, N).Max(
n => MyMath.GCD(GCD_Ruiseki_R[n], GCD_Ruiseki_L[n])));
}
}
|
[["-", 0, 41, 15, 23, 0, 16, 31, 16, 31, 22], ["-", 0, 41, 15, 23, 0, 16, 31, 16, 17, 109], ["-", 8, 306, 0, 41, 75, 23, 0, 41, 64, 22], ["+", 8, 306, 0, 41, 75, 23, 0, 41, 64, 22]]
| 8
| 811
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
class Program {
static void Main() {
int N = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
// Aの左からインデックスiまでの最大公約数をインデックスiに格納する配列
int[] X1 = new int[N];
X1[0] = A[0];
for (int i = 1; i < N; i++) {
X1[i] = GCD(X1[i - 1], A[i]);
}
// Aの右からインデックスiまでの最大公約数をインデックスiに格納する配列
int[] X2 = new int[N];
X2[N - 1] = A[N - 1];
for (int i = N - 2; i >= 0; i--) {
X2[i] = GCD(X2[i + 1], A[i]);
}
int max = 0;
for (int i = 0; i < N; i++) {
if (i - 1 < 0) {
max = Math.Max(max, X2[i + 1]);
} else if (i + 1 > N - 1) {
max = Math.Max(max, X1[i - 1]);
} else {
Math.Max(max, GCD(X1[i - 1], X2[i + 1]));
}
}
Console.WriteLine(max);
}
static int GCD(int num1, int num2) {
if (num1 <= num2) {
int tmp = num1;
num1 = num2;
num2 = tmp;
}
int rem;
Math.DivRem(num1, num2, out rem);
if (rem == 0) {
return num2;
} else {
return GCD(num2, rem);
}
}
}
static class MathUtil {
public static IEnumerable<IEnumerable<int>> GetPermutation(int n) {
if (n == 0) {
yield return Single(0);
yield break;
}
for (int i = 0; i <= n; i++) {
foreach (var x in GetPermutation(n - 1)) {
yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
}
}
}
private static IEnumerable<int> Single(int x) { yield return x; }
public static IEnumerable<int> EnumeratePrimeNumbers() {
List<int> primes = new List<int>() { 2 };
yield return 2;
for (int i = 3; i < int.MaxValue; i++) {
bool isPrime = true;
int Sqrt = (int)Math.Sqrt(i) + 1;
foreach (var prime in primes) {
if (prime > Sqrt) {
break;
}
if (i % prime == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.Add(i);
yield return i;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
class Program {
static void Main() {
int N = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
// Aの左からインデックスiまでの最大公約数をインデックスiに格納する配列
int[] X1 = new int[N];
X1[0] = A[0];
for (int i = 1; i < N; i++) {
X1[i] = GCD(X1[i - 1], A[i]);
}
// Aの右からインデックスiまでの最大公約数をインデックスiに格納する配列
int[] X2 = new int[N];
X2[N - 1] = A[N - 1];
for (int i = N - 2; i >= 0; i--) {
X2[i] = GCD(X2[i + 1], A[i]);
}
int max = 0;
for (int i = 0; i < N; i++) {
if (i - 1 < 0) {
max = Math.Max(max, X2[i + 1]);
} else if (i + 1 > N - 1) {
max = Math.Max(max, X1[i - 1]);
} else {
max = Math.Max(max, GCD(X1[i - 1], X2[i + 1]));
}
}
Console.WriteLine(max);
}
static int GCD(int num1, int num2) {
if (num1 <= num2) {
int tmp = num1;
num1 = num2;
num2 = tmp;
}
int rem;
Math.DivRem(num1, num2, out rem);
if (rem == 0) {
return num2;
} else {
return GCD(num2, rem);
}
}
}
static class MathUtil {
public static IEnumerable<IEnumerable<int>> GetPermutation(int n) {
if (n == 0) {
yield return Single(0);
yield break;
}
for (int i = 0; i <= n; i++) {
foreach (var x in GetPermutation(n - 1)) {
yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
}
}
}
private static IEnumerable<int> Single(int x) { yield return x; }
public static IEnumerable<int> EnumeratePrimeNumbers() {
List<int> primes = new List<int>() { 2 };
yield return 2;
for (int i = 3; i < int.MaxValue; i++) {
bool isPrime = true;
int Sqrt = (int)Math.Sqrt(i) + 1;
foreach (var prime in primes) {
if (prime > Sqrt) {
break;
}
if (i % prime == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.Add(i);
yield return i;
}
}
}
}
|
[["+", 75, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32]]
| 8
| 630
| 2
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using static AtCoder.AtCoderLib;
namespace AtCoder {
class Program {
static void Main(string[] args) {
new ABC125().SolveC(new ConsoleInput(Console.In, ' '));
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
public static class AtCoderLib {
// ユークリッドの互除法
public static int Gcd(int a, int b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
}
class ABC125 {
public void SolveC(ConsoleInput cin) {
var n = cin.ReadInt;
var A = cin.ReadIntArray(n);
var gcdList = new int[n];
var newA = A.OrderBy(x => x).ToArray();
gcdList[0] = newA[0];
for (int i = 1; i < n; i++) {
gcdList[i] = Gcd(gcdList[i - 1], newA[i]);
}
var revA = A.OrderByDescending(x => x).ToArray();
var gcdListRev = new int[n];
gcdListRev[0] = revA[0];
for (int i = 1; i < n; i++) {
gcdListRev[i] = Gcd(gcdListRev[i - 1], revA[i]);
}
var resultList = new int[n];
resultList[0] = gcdListRev[n - 2];
for (int i = 1; i < n - 1; i++) {
resultList[i] = Gcd(gcdList[i - 1], gcdListRev[i - 1]);
}
resultList[n - 1] = gcdList[n - 2];
WriteLine(resultList.Max());
ReadLine();
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using static AtCoder.AtCoderLib;
namespace AtCoder {
class Program {
static void Main(string[] args) {
new ABC125().SolveC(new ConsoleInput(Console.In, ' '));
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
public static class AtCoderLib {
// ユークリッドの互除法
public static int Gcd(int a, int b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
}
class ABC125 {
public void SolveC(ConsoleInput cin) {
var n = cin.ReadInt;
var A = cin.ReadIntArray(n);
var gcdList = new int[n];
var newA = A.OrderBy(x => x).ToArray();
gcdList[0] = newA[0];
for (int i = 1; i < n; i++) {
gcdList[i] = Gcd(gcdList[i - 1], newA[i]);
}
var revA = A.OrderByDescending(x => x).ToArray();
var gcdListRev = new int[n];
gcdListRev[0] = revA[0];
for (int i = 1; i < n; i++) {
gcdListRev[i] = Gcd(gcdListRev[i - 1], revA[i]);
}
var resultList = new int[n];
resultList[0] = gcdListRev[n - 2];
for (int i = 1; i < n - 1; i++) {
resultList[i] = Gcd(gcdList[i - 1], gcdListRev[n - i - 2]);
}
resultList[n - 1] = gcdList[n - 2];
WriteLine(resultList.Max());
ReadLine();
}
}
}
|
[["+", 206, 207, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 740
| 4
|
using System;
using System.Linq;
class Program {
static int Gcd(int a, int b) {
if (a < b) {
var t = a;
a = b;
b = t;
}
if (b == 0)
return a;
return Gcd(b, a % b);
}
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var inArr = new int[N];
var pref = new int[N];
var suf = new int[N];
var inputs =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
for (var i = 1; i <= N; i++) {
inArr[i] = inputs[i - 1];
pref[i] = Gcd(pref[i - 1], inArr[i]);
}
for (var i = N; i >= 1; i--) {
suf[i] = Gcd(suf[i + 1], inArr[i]);
}
var max = 0;
for (var i = 1; i <= N; i++) {
max = Math.Max(max, Gcd(pref[i - 1], suf[i + 1]));
}
Console.WriteLine(max);
}
}
|
using System;
using System.Linq;
class Program {
static int Gcd(int a, int b) {
if (a < b) {
var t = a;
a = b;
b = t;
}
if (b == 0)
return a;
return Gcd(b, a % b);
}
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var inArr = new int[N + 2];
var pref = new int[N + 2];
var suf = new int[N + 2];
var inputs =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
for (var i = 1; i <= N; i++) {
inArr[i] = inputs[i - 1];
pref[i] = Gcd(pref[i - 1], inArr[i]);
}
for (var i = N; i >= 1; i--) {
suf[i] = Gcd(suf[i + 1], inArr[i]);
}
var max = 0;
for (var i = 1; i <= N; i++) {
max = Math.Max(max, Gcd(pref[i - 1], suf[i + 1]));
}
Console.WriteLine(max);
}
}
|
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203]]
| 8
| 286
| 6
|
using System;
using static System.Console;
using System.Text;
using System.Linq;
using static System.Math;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program {
public static int count = 0;
static void Main(string[] args) {
var alg = new cp();
var n = alg.inputInt();
var arr = alg.inputSplitInt();
var leftlist = new List<int>();
var rightlist = new List<int>();
for (int a = 0; a < n; a++) {
if (a == 0) {
leftlist.Add(arr[a]);
} else {
leftlist.Add(alg.GCD(leftlist[a - 1], arr[a]));
}
}
for (int a = n - 1; a >= 0; a--) {
if (a == n - 1) {
rightlist.Add(arr[a]);
} else {
rightlist.Insert(0, alg.GCD(rightlist[a - 1], arr[a]));
}
}
int max = 0;
for (int a = 0; a < n; a++) {
if (a == 0) {
max = Math.Max(max, rightlist[a + 1]);
} else if (a == n - 1) {
max = Math.Max(max, leftlist[a - 1]);
} else {
max = Math.Max(max, alg.GCD(leftlist[a - 1], rightlist[a + 1]));
}
}
WriteLine(max);
}
}
class cp {
public cp() {}
public int GCD(int a, int b) { return a % b == 0 ? b : GCD(b, a % b); }
public int LCM(int a, int b) { return a * b / GCD(a, b); }
public int countChar(string s, string key) {
return s.Length - s.Replace(key, "").Length;
}
public string YesNo(bool f, string type = null) {
string str;
if (f)
str = "Yes";
else
str = "No";
if (type == "lower")
return str.ToLower();
else if (type == "upper")
return str.ToUpper();
else
return str;
}
public void inputSkip() {
ReadLine();
return;
}
public string inputString() { return ReadLine(); }
public string[] inputSplitString() { return ReadLine().Split(); }
public string[] inputLinesString(int len) {
var arr = new string[len];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine();
}
return arr;
}
public string[][] inputJaggedArrayString(int len) {
var arr = new string[len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split();
}
return arr;
}
public int inputInt() { return int.Parse(ReadLine()); }
public int[] inputSplitInt() {
return ReadLine().Split().Select(i => int.Parse(i)).ToArray();
}
public int[] inputLinesInt(int len) {
var arr = new int[len];
for (int a = 0; a < len; a++) {
arr[a] = int.Parse(ReadLine());
}
return arr;
}
public int[][] inputJaggedArrayInt(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 inputLong() { return long.Parse(ReadLine()); }
public long[] inputSplitLong() {
return ReadLine().Split().Select(i => long.Parse(i)).ToArray();
}
public long[] inputLinesLong(int len) {
var arr = new long[len];
for (int a = 0; a < len; a++) {
arr[a] = long.Parse(ReadLine());
}
return arr;
}
public long[][] inputJaggedArrayLong(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 inputDouble() { return double.Parse(ReadLine()); }
public double[] inputSplitDouble() {
return ReadLine().Split().Select(i => double.Parse(i)).ToArray();
}
public double[] inputLinesDouble(int len) {
var arr = new double[len];
for (int a = 0; a < len; a++) {
arr[a] = double.Parse(ReadLine());
}
return arr;
}
public double[][] inputJaggedArrayDouble(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 static System.Console;
using System.Text;
using System.Linq;
using static System.Math;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program {
public static int count = 0;
static void Main(string[] args) {
var alg = new cp();
var n = alg.inputInt();
var arr = alg.inputSplitInt();
var leftlist = new List<int>();
var rightlist = new List<int>();
for (int a = 0; a < n; a++) {
if (a == 0) {
leftlist.Add(arr[a]);
} else {
leftlist.Add(alg.GCD(leftlist[a - 1], arr[a]));
}
}
for (int a = n - 1; a >= 0; a--) {
if (a == n - 1) {
rightlist.Add(arr[a]);
} else {
rightlist.Insert(0, alg.GCD(rightlist[0], arr[a]));
}
}
int max = 0;
for (int a = 0; a < n; a++) {
if (a == 0) {
max = Math.Max(max, rightlist[a + 1]);
} else if (a == n - 1) {
max = Math.Max(max, leftlist[a - 1]);
} else {
max = Math.Max(max, alg.GCD(leftlist[a - 1], rightlist[a + 1]));
}
}
WriteLine(max);
}
}
class cp {
public cp() {}
public int GCD(int a, int b) { return a % b == 0 ? b : GCD(b, a % b); }
public int LCM(int a, int b) { return a * b / GCD(a, b); }
public int countChar(string s, string key) {
return s.Length - s.Replace(key, "").Length;
}
public string YesNo(bool f, string type = null) {
string str;
if (f)
str = "Yes";
else
str = "No";
if (type == "lower")
return str.ToLower();
else if (type == "upper")
return str.ToUpper();
else
return str;
}
public void inputSkip() {
ReadLine();
return;
}
public string inputString() { return ReadLine(); }
public string[] inputSplitString() { return ReadLine().Split(); }
public string[] inputLinesString(int len) {
var arr = new string[len];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine();
}
return arr;
}
public string[][] inputJaggedArrayString(int len) {
var arr = new string[len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split();
}
return arr;
}
public int inputInt() { return int.Parse(ReadLine()); }
public int[] inputSplitInt() {
return ReadLine().Split().Select(i => int.Parse(i)).ToArray();
}
public int[] inputLinesInt(int len) {
var arr = new int[len];
for (int a = 0; a < len; a++) {
arr[a] = int.Parse(ReadLine());
}
return arr;
}
public int[][] inputJaggedArrayInt(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 inputLong() { return long.Parse(ReadLine()); }
public long[] inputSplitLong() {
return ReadLine().Split().Select(i => long.Parse(i)).ToArray();
}
public long[] inputLinesLong(int len) {
var arr = new long[len];
for (int a = 0; a < len; a++) {
arr[a] = long.Parse(ReadLine());
}
return arr;
}
public long[][] inputJaggedArrayLong(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 inputDouble() { return double.Parse(ReadLine()); }
public double[] inputSplitDouble() {
return ReadLine().Split().Select(i => double.Parse(i)).ToArray();
}
public double[] inputLinesDouble(int len) {
var arr = new double[len];
for (int a = 0; a < len; a++) {
arr[a] = double.Parse(ReadLine());
}
return arr;
}
public double[][] inputJaggedArrayDouble(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;
}
}
|
[["-", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 1,188
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) { new Program().Solve(); }
void Solve() {
Scanner cin = new Scanner();
int N = cin.NextInt();
long[] A = cin.ArrayLong(N);
long[] gcd = new long[N + 2]; // gcd[i] is gcd with removing i-th number
long[] L = new long[N + 2];
long[] R = new long[N + 2];
L[0] = A[0];
R[N - 1] = A[N - 1];
for (int i = 0; i < N - 1; ++i) {
L[i + 1] = CalcGCD(L[i], A[i]);
}
for (int i = N - 2; 0 <= i; --i) {
R[i] = CalcGCD(R[i + 1], A[i]);
}
long ans = Math.Max(L[N - 2], R[1]);
for (int i = 0; i < N - 1; ++i) {
long tmp = CalcGCD(L[i - 1], R[i + 1]) /*without i-th*/;
// long tmp = Math.Max(
// CalcGCD(L[i], R[i + 1])/*without i-th*/,
// CalcGCD(L[i], R[i])/*with i-th*/);
ans = ans <= tmp ? tmp : ans;
}
Console.WriteLine(ans);
}
private long CalcGCD(long a, long b) {
if (b == 0) {
return a;
}
if (a == 0) {
return b;
}
if (a < b) {
long residual = b % a;
return CalcGCD(a, residual);
} else {
long residual = a % b;
return CalcGCD(b, residual);
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return Next();
i = 0;
return s[i++];
}
public int NextInt() { return int.Parse(Next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = NextInt() + add;
}
return Array;
}
public long NextLong() { return long.Parse(Next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = NextLong() + add;
}
return Array;
}
public double NextDouble() { return double.Parse(Next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = NextDouble() + add;
}
return Array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) { new Program().Solve(); }
void Solve() {
Scanner cin = new Scanner();
int N = cin.NextInt();
long[] A = cin.ArrayLong(N);
long[] gcd = new long[N + 2]; // gcd[i] is gcd with removing i-th number
long[] L = new long[N + 2];
long[] R = new long[N + 2];
L[0] = A[0];
R[N - 1] = A[N - 1];
for (int i = 0; i < N - 1; ++i) {
L[i + 1] = CalcGCD(L[i], A[i + 1]);
}
for (int i = N - 2; 0 <= i; --i) {
R[i] = CalcGCD(R[i + 1], A[i]);
}
long ans = Math.Max(L[N - 2], R[1]);
for (int i = 1; i < N - 1; ++i) {
long tmp = CalcGCD(L[i - 1], R[i + 1]) /*without i-th*/;
// long tmp = Math.Max(
// CalcGCD(L[i], R[i + 1])/*without i-th*/,
// CalcGCD(L[i], R[i])/*with i-th*/);
ans = ans <= tmp ? tmp : ans;
}
Console.WriteLine(ans);
}
private long CalcGCD(long a, long b) {
if (b == 0) {
return a;
}
if (a == 0) {
return b;
}
if (a < b) {
long residual = b % a;
return CalcGCD(a, residual);
} else {
long residual = a % b;
return CalcGCD(b, residual);
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return Next();
i = 0;
return s[i++];
}
public int NextInt() { return int.Parse(Next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = NextInt() + add;
}
return Array;
}
public long NextLong() { return long.Parse(Next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = NextLong() + add;
}
return Array;
}
public double NextDouble() { return double.Parse(Next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = NextDouble() + add;
}
return Array;
}
}
|
[["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 730
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var sc = new Scanner();
int n = sc.NextInt();
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = sc.NextLong();
long[] l = new long[n + 1];
long[] r = new long[n + 1];
l[1] = a[0];
r[n - 1] = a[n - 1];
for (int i = 2; i <= n; i++) {
l[i] = Gcd(l[i - 1], a[i - 1]);
r[n - i] = Gcd(r[n - i + 1], a[n - i]);
}
long ans = 0;
for (int i = 0; i < n - 1; i++) {
long g = Gcd(l[i], r[i + 1]);
if (g > ans)
ans = g;
}
Console.WriteLine(ans);
}
static long Gcd(long a, long b) {
if (a < b)
return Gcd(b, a);
if (b == 0)
return a;
return Gcd(b, a % b);
}
}
class Scanner {
int index = -1;
string[] buf;
public Scanner() {}
public int NextInt() {
CheckNext();
return int.Parse(buf[index++]);
}
public long NextLong() {
CheckNext();
return long.Parse(buf[index++]);
}
public double NextDouble() {
CheckNext();
return double.Parse(buf[index++]);
}
public string NextString() {
CheckNext();
return buf[index++];
}
private void CheckNext() {
if (index >= 0 && index < buf.Length)
return;
buf = Console.ReadLine().Split(' ');
index = 0;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var sc = new Scanner();
int n = sc.NextInt();
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = sc.NextLong();
long[] l = new long[n + 1];
long[] r = new long[n + 1];
l[1] = a[0];
r[n - 1] = a[n - 1];
for (int i = 2; i <= n; i++) {
l[i] = Gcd(l[i - 1], a[i - 1]);
r[n - i] = Gcd(r[n - i + 1], a[n - i]);
}
long ans = 0;
for (int i = 0; i < n; i++) {
long g = Gcd(l[i], r[i + 1]);
if (g > ans)
ans = g;
}
Console.WriteLine(ans);
}
static long Gcd(long a, long b) {
if (a < b)
return Gcd(b, a);
if (b == 0)
return a;
return Gcd(b, a % b);
}
}
class Scanner {
int index = -1;
string[] buf;
public Scanner() {}
public int NextInt() {
CheckNext();
return int.Parse(buf[index++]);
}
public long NextLong() {
CheckNext();
return long.Parse(buf[index++]);
}
public double NextDouble() {
CheckNext();
return double.Parse(buf[index++]);
}
public string NextString() {
CheckNext();
return buf[index++];
}
private void CheckNext() {
if (index >= 0 && index < buf.Length)
return;
buf = Console.ReadLine().Split(' ');
index = 0;
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 460
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
public static partial class Program {
public static void Main() {
var n = CRL().ToInt();
var ais = CRL().ArrayInts();
var lgcd = new int[n - 1];
var rgcd = new int[n - 1];
//最初に最初を入れる
lgcd[0] = ais[0];
for (int i = 1; i < n - 1; i++) {
lgcd[i] = GCD(lgcd[i - 1], ais[i]);
}
//最後に最後を入れる
rgcd[rgcd.Length - 1] = ais[n - 1];
for (int i = 1; i < n - 1; i++) {
rgcd[n - i - 2] = GCD(rgcd[n - i - 1], ais[n - i]);
}
var max = rgcd[0];
for (int i = 0; i < n - 1; i++) {
max = Math.Max(max, GCD(lgcd[i], rgcd[i]));
}
max = Math.Max(max, lgcd[lgcd.Length - 1]);
CWL(max);
}
}
public static partial class Program {
//テンプレここから
public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);
public static int GCD(int a, int b) => b == 0 ? a : GCD(b, a % b);
public static long LCM(long a, long b) => a * b / GCD(a, b);
public static int LCM(int a, int b) => a * b / GCD(a, b);
public static int ToInt(this double d) => (int)d;
public static long ToLong(this double d) => (long)d;
public static int ToInt(this string str) => int.Parse(str);
public static long ToLong(this string str) => long.Parse(str);
public static long[] ToLong(this IEnumerable<string> strs) =>
strs.Select(x => x.ToLong()).ToArray();
public static int[] ToInt(this IEnumerable<string> strs) =>
strs.Select(x => x.ToInt()).ToArray();
public static long[] ArrayLongs(this string str,
char opr = ' ') => str.Split(opr).ToLong();
public static int[] ArrayInts(this string str,
char opr = ' ') => str.Split(opr).ToInt();
public static string CRL() => Console.ReadLine();
public static string RL() => ReadLine();
public static void CWL(object obj) => Console.WriteLine(obj);
public static void WL(object obj) => WriteLine(obj);
public static long Diff(long a,
long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
public static int Diff(int a,
int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
public static long Sign(this long i) => Math.Sign(i);
public static bool IsEven(this long i) => i % 2 == 0;
public static bool IsEven(this int i) => i % 2 == 0;
public static long[] dx = new long[] { 0, -1, 0, 1 };
public static long[] dy = new long[] { -1, 0, 1, 0 };
public static long mod = 1000000007;
public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
public static long ToLong(this char c) => c.ToString().ToInt();
public static long[] Sort(this long[] array) =>
array.OrderBy(x => x).ToArray();
public static int[] Sort(this int[] array) => array.OrderBy(x => x).ToArray();
public static long[] DSort(this long[] array) =>
array.OrderByDescending(x => x).ToArray();
public static int[] DSort(this int[] array) =>
array.OrderByDescending(x => x).ToArray();
public static string Join(this IEnumerable<string> array,
string sep = "") => string.Join(sep, array);
public static string Join(this IEnumerable<char> array,
string sep = "") => string.Join(sep, array);
//テンプレここまで
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
public static partial class Program {
public static void Main() {
var n = CRL().ToInt();
var ais = CRL().ArrayInts();
var lgcd = new int[n - 1];
var rgcd = new int[n - 1];
//最初に最初を入れる
lgcd[0] = ais[0];
for (int i = 1; i < n - 1; i++) {
lgcd[i] = GCD(lgcd[i - 1], ais[i]);
}
//最後に最後を入れる
rgcd[rgcd.Length - 1] = ais[n - 1];
for (int i = 1; i < n - 1; i++) {
rgcd[n - i - 2] = GCD(rgcd[n - i - 1], ais[n - i - 1]);
}
var max = rgcd[0];
for (int i = 1; i < n - 1; i++) {
max = Math.Max(max, GCD(lgcd[i - 1], rgcd[i]));
}
max = Math.Max(max, lgcd[lgcd.Length - 1]);
CWL(max);
}
}
public static partial class Program {
//テンプレここから
public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);
public static int GCD(int a, int b) => b == 0 ? a : GCD(b, a % b);
public static long LCM(long a, long b) => a * b / GCD(a, b);
public static int LCM(int a, int b) => a * b / GCD(a, b);
public static int ToInt(this double d) => (int)d;
public static long ToLong(this double d) => (long)d;
public static int ToInt(this string str) => int.Parse(str);
public static long ToLong(this string str) => long.Parse(str);
public static long[] ToLong(this IEnumerable<string> strs) =>
strs.Select(x => x.ToLong()).ToArray();
public static int[] ToInt(this IEnumerable<string> strs) =>
strs.Select(x => x.ToInt()).ToArray();
public static long[] ArrayLongs(this string str,
char opr = ' ') => str.Split(opr).ToLong();
public static int[] ArrayInts(this string str,
char opr = ' ') => str.Split(opr).ToInt();
public static string CRL() => Console.ReadLine();
public static string RL() => ReadLine();
public static void CWL(object obj) => Console.WriteLine(obj);
public static void WL(object obj) => WriteLine(obj);
public static long Diff(long a,
long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
public static int Diff(int a,
int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
public static long Sign(this long i) => Math.Sign(i);
public static bool IsEven(this long i) => i % 2 == 0;
public static bool IsEven(this int i) => i % 2 == 0;
public static long[] dx = new long[] { 0, -1, 0, 1 };
public static long[] dy = new long[] { -1, 0, 1, 0 };
public static long mod = 1000000007;
public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
public static long ToLong(this char c) => c.ToString().ToInt();
public static long[] Sort(this long[] array) =>
array.OrderBy(x => x).ToArray();
public static int[] Sort(this int[] array) => array.OrderBy(x => x).ToArray();
public static long[] DSort(this long[] array) =>
array.OrderByDescending(x => x).ToArray();
public static int[] DSort(this int[] array) =>
array.OrderByDescending(x => x).ToArray();
public static string Join(this IEnumerable<string> array,
string sep = "") => string.Join(sep, array);
public static string Join(this IEnumerable<char> array,
string sep = "") => string.Join(sep, array);
//テンプレここまで
}
|
[["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 977
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp3 {
class Program {
static long gcd(long A, long B) {
while (B > 0) {
var c = A % B;
A = B;
B = c;
}
return A;
}
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split(' ').Select((c => int.Parse(c))).ToArray();
var L = new long[N + 1];
var R = new long[N + 1];
L[0] = A[0];
R[N - 1] = A[N - 1];
for (int i = 1; i < N - 1; i++) {
L[i] = gcd(L[0], A[i]);
R[N - i - 1] = gcd(R[N - i], A[N - i - 1]);
}
long ans = 0;
for (int i = 0; i < N; i++) {
if (i == 0) {
ans = Math.Max(ans, R[i + 1]);
} else if (i == N - 1) {
ans = Math.Max(ans, L[i - 1]);
} else {
ans = Math.Max(ans, gcd(L[i - 1], R[i + 1]));
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp3 {
class Program {
static long gcd(long A, long B) {
while (B > 0) {
var c = A % B;
A = B;
B = c;
}
return A;
}
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split(' ').Select((c => int.Parse(c))).ToArray();
var L = new long[N + 1];
var R = new long[N + 1];
L[0] = A[0];
R[N - 1] = A[N - 1];
for (int i = 1; i < N - 1; i++) {
L[i] = gcd(L[i - 1], A[i]);
R[N - i - 1] = gcd(R[N - i], A[N - i - 1]);
}
long ans = 0;
for (int i = 0; i < N; i++) {
if (i == 0) {
ans = Math.Max(ans, R[i + 1]);
} else if (i == N - 1) {
ans = Math.Max(ans, L[i - 1]);
} else {
ans = Math.Max(ans, gcd(L[i - 1], R[i + 1]));
}
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 338
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
class Pair {
public int x;
public int y;
public Pair(int X, int Y) {
x = X;
y = Y;
}
}
class Program {
static void Main(string[] args) {
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
int n = scan.Integer();
long[] A = scan.Long(n);
Array.Sort(A);
int minuses = 0;
long Abssum = 0;
long buf = long.MaxValue;
for (int i = 0; i < n; i++) {
if (A[i] < 0) {
minuses++;
minuses %= 2;
Abssum -= A[i];
} else if (A[i] == 0) {
minuses = 0;
} else {
Abssum += A[i];
}
if (Math.Abs(buf) > Math.Abs(A[i])) {
buf = A[i];
}
}
if (minuses == 1) {
Abssum -= 2 * buf;
}
Console.WriteLine(Abssum);
}
static int solve(int[][] s, int k, int defkaisu) {
int w = s[0].Length;
int h = s.GetLength(0);
int[] buf = new int[h];
int kaisu = defkaisu;
bool done = false;
for (int j = 0; j < w; j++) {
done = false;
for (int i = 0; i < h; i++) {
if (done) {
continue;
}
if (s[i][j] > k) {
return int.MaxValue;
}
if (j > 0) {
if (buf[i] + s[i][j] > k) {
for (int l = 0; l < h; l++) {
buf[l] = s[l][j];
}
kaisu++;
done = true;
} else {
buf[i] += s[i][j];
}
} else {
for (int l = 0; l < h; l++) {
buf[l] = s[l][j];
}
} // j=0で↑をやり過ごしているならカットは不要
}
}
return kaisu;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
static long solve(int mae, int ushiro, long[,] dp, int[] a, bool taro) {
if (dp[mae, ushiro] > long.MinValue) {
return dp[mae, ushiro];
}
if (ushiro - mae == 1) {
if (taro) {
dp[mae, ushiro] = a[mae];
return dp[mae, ushiro];
} else {
dp[mae, ushiro] = -a[mae];
return dp[mae, ushiro];
}
}
if (taro) {
long max = Math.Max(a[mae] + solve(mae + 1, ushiro, dp, a, !taro),
a[ushiro - 1] + solve(mae, ushiro - 1, dp, a, !taro));
dp[mae, ushiro] = max;
return dp[mae, ushiro];
} else {
long min =
Math.Min(-a[mae] + solve(mae + 1, ushiro, dp, a, !taro),
-a[ushiro - 1] + solve(mae, ushiro - 1, dp, a, !taro));
dp[mae, ushiro] = min;
return dp[mae, ushiro];
}
}
static int nibutan(int med, int[] a) // med以上が何個あるか
{
int mae = 0;
int ato = a.Length;
while (true) {
if (ato - mae <= 1) {
return mae;
}
int mid = (mae + ato) / 2;
if (a[mid] > med) {
ato = mid;
}
if (a[mid] <= med) {
mae = mid;
}
}
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static bool isOK(int index, int key, int[] moto) {
return moto[index] >= key;
}
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(int n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public int Integer() { return (int)Long(); }
public int[] Integer(int n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
public Mlong modjyo(Mlong x) { return num * x.Pow(mod - 2); }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
if (n == 1) {
return this % mod;
}
if (n % 2 == 1) {
return (this * Pow(n - 1)) % mod;
}
Mlong buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
}
public class Mint {
private static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
if (n == 1) {
return this % mod;
}
if (n % 2 == 1) {
return (this * Pow(n - 1)) % mod;
}
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static Mint Comb(Mint n, Mint a) {
Mint buf1 = 1;
Mint buf2 = 1;
for (int i = 0; i < a; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
class Pair {
public int x;
public int y;
public Pair(int X, int Y) {
x = X;
y = Y;
}
}
class Program {
static void Main(string[] args) {
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
int n = scan.Integer();
long[] A = scan.Long(n);
Array.Sort(A);
int minuses = 0;
long Abssum = 0;
long buf = long.MaxValue;
for (int i = 0; i < n; i++) {
if (A[i] < 0) {
minuses++;
minuses %= 2;
Abssum -= A[i];
} else if (A[i] == 0) {
minuses = 0;
} else {
Abssum += A[i];
}
if (Math.Abs(buf) > Math.Abs(A[i])) {
buf = A[i];
}
}
if (minuses == 1) {
Abssum -= 2 * Math.Abs(buf);
}
Console.WriteLine(Abssum);
}
static int solve(int[][] s, int k, int defkaisu) {
int w = s[0].Length;
int h = s.GetLength(0);
int[] buf = new int[h];
int kaisu = defkaisu;
bool done = false;
for (int j = 0; j < w; j++) {
done = false;
for (int i = 0; i < h; i++) {
if (done) {
continue;
}
if (s[i][j] > k) {
return int.MaxValue;
}
if (j > 0) {
if (buf[i] + s[i][j] > k) {
for (int l = 0; l < h; l++) {
buf[l] = s[l][j];
}
kaisu++;
done = true;
} else {
buf[i] += s[i][j];
}
} else {
for (int l = 0; l < h; l++) {
buf[l] = s[l][j];
}
} // j=0で↑をやり過ごしているならカットは不要
}
}
return kaisu;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
static long solve(int mae, int ushiro, long[,] dp, int[] a, bool taro) {
if (dp[mae, ushiro] > long.MinValue) {
return dp[mae, ushiro];
}
if (ushiro - mae == 1) {
if (taro) {
dp[mae, ushiro] = a[mae];
return dp[mae, ushiro];
} else {
dp[mae, ushiro] = -a[mae];
return dp[mae, ushiro];
}
}
if (taro) {
long max = Math.Max(a[mae] + solve(mae + 1, ushiro, dp, a, !taro),
a[ushiro - 1] + solve(mae, ushiro - 1, dp, a, !taro));
dp[mae, ushiro] = max;
return dp[mae, ushiro];
} else {
long min =
Math.Min(-a[mae] + solve(mae + 1, ushiro, dp, a, !taro),
-a[ushiro - 1] + solve(mae, ushiro - 1, dp, a, !taro));
dp[mae, ushiro] = min;
return dp[mae, ushiro];
}
}
static int nibutan(int med, int[] a) // med以上が何個あるか
{
int mae = 0;
int ato = a.Length;
while (true) {
if (ato - mae <= 1) {
return mae;
}
int mid = (mae + ato) / 2;
if (a[mid] > med) {
ato = mid;
}
if (a[mid] <= med) {
mae = mid;
}
}
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static bool isOK(int index, int key, int[] moto) {
return moto[index] >= key;
}
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(int n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public int Integer() { return (int)Long(); }
public int[] Integer(int n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
public Mlong modjyo(Mlong x) { return num * x.Pow(mod - 2); }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
if (n == 1) {
return this % mod;
}
if (n % 2 == 1) {
return (this * Pow(n - 1)) % mod;
}
Mlong buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
}
public class Mint {
private static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
if (n == 1) {
return this % mod;
}
if (n % 2 == 1) {
return (this * Pow(n - 1)) % mod;
}
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static Mint Comb(Mint n, Mint a) {
Mint buf1 = 1;
Mint buf2 = 1;
for (int i = 0; i < a; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
}
|
[["+", 0, 11, 12, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 6,008
| 5
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
namespace cc {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
long ans = 0;
List<long> posList = new List<long>();
List<long> negList = new List<long>();
string[] strs = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
long inVal = long.Parse(strs[i]);
if (inVal > 0) {
posList.Add(inVal);
} else {
negList.Add(-inVal);
}
}
if (negList.Count % 2 == 0 || negList.Count == 0) {
foreach (long a in negList) {
ans += a;
}
foreach (long a in posList) {
ans += a;
}
}
if (posList.Count == 0) {
negList.Sort();
for (int i = 1; i < negList.Count; i++) {
ans += negList[i];
}
ans -= negList[0];
} else {
negList.Sort();
posList.Sort();
if (negList[0] < posList[0]) {
foreach (long a in posList) {
ans += a;
}
for (int i = 1; i < negList.Count; i++) {
ans += negList[i];
}
ans -= negList[0];
} else {
foreach (long a in negList) {
ans += a;
}
for (int i = 1; i < posList.Count; i++) {
ans += posList[i];
}
ans -= posList[0];
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
namespace cc {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
long ans = 0;
List<long> posList = new List<long>();
List<long> negList = new List<long>();
string[] strs = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
long inVal = long.Parse(strs[i]);
if (inVal > 0) {
posList.Add(inVal);
} else {
negList.Add(-inVal);
}
}
if (negList.Count % 2 == 0 || negList.Count == 0) {
foreach (long a in negList) {
ans += a;
}
foreach (long a in posList) {
ans += a;
}
} else if (posList.Count == 0) {
negList.Sort();
for (int i = 1; i < negList.Count; i++) {
ans += negList[i];
}
ans -= negList[0];
} else {
negList.Sort();
posList.Sort();
if (negList[0] < posList[0]) {
foreach (long a in posList) {
ans += a;
}
for (int i = 1; i < negList.Count; i++) {
ans += negList[i];
}
ans -= negList[0];
} else {
foreach (long a in negList) {
ans += a;
}
for (int i = 1; i < posList.Count; i++) {
ans += posList[i];
}
ans -= posList[0];
}
}
Console.WriteLine(ans);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
| 8
| 380
| 1
|
using System;
using System.Collections.Generic;
using System.Linq;
class Procon {
public Procon() {}
static void Main(string[] agrs) { new Procon().Do(); }
Scanner cin;
public void Do() {
cin = new Scanner();
int N = cin.nextInt();
long[] A = cin.arrayLong();
int count = 0;
long min = 1000000001;
long sum = 0;
for (int i = 0; i < N; i++) {
if (A[i] < 0) {
count++;
}
min = Math.Min(min, Math.Abs(A[i]));
sum += Math.Abs(A[i]);
}
if (count == 0) {
Console.WriteLine(sum);
} else {
Console.WriteLine(sum - 2 * min);
}
}
}
class Scanner {
string[] s;
int i;
int max_i;
public Scanner() {
s = new string[0];
max_i = 0;
i = 0;
}
public string nextString() {
if (i >= s.Length) {
s = Console.ReadLine().Split(' ');
max_i = s.Length;
i = 0;
if (max_i == 0) {
return "";
}
return s[i++];
} else {
return s[i++];
}
}
public int nextInt() { return int.Parse(nextString()); }
public long nextLong() { return long.Parse(nextString()); }
public double nextDouble() { return double.Parse(nextString()); }
public string[] arrayString() { return Console.ReadLine().Split(' '); }
public int[] arrayInt() {
string[] str = Console.ReadLine().Split(' ');
int[] array = new int[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = int.Parse(str[i]);
}
return array;
}
public long[] arrayLong() {
string[] str = Console.ReadLine().Split(' ');
long[] array = new long[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = long.Parse(str[i]);
}
return array;
}
public double[] arrayDouble() {
string[] str = Console.ReadLine().Split(' ');
double[] array = new double[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = double.Parse(str[i]);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Procon {
public Procon() {}
static void Main(string[] agrs) { new Procon().Do(); }
Scanner cin;
public void Do() {
cin = new Scanner();
int N = cin.nextInt();
long[] A = cin.arrayLong();
int count = 0;
long min = 1000000001;
long sum = 0;
for (int i = 0; i < N; i++) {
if (A[i] < 0) {
count++;
}
min = Math.Min(min, Math.Abs(A[i]));
sum += Math.Abs(A[i]);
}
if (count % 2 == 0) {
Console.WriteLine(sum);
} else {
Console.WriteLine(sum - 2 * min);
}
}
}
class Scanner {
string[] s;
int i;
int max_i;
public Scanner() {
s = new string[0];
max_i = 0;
i = 0;
}
public string nextString() {
if (i >= s.Length) {
s = Console.ReadLine().Split(' ');
max_i = s.Length;
i = 0;
if (max_i == 0) {
return "";
}
return s[i++];
} else {
return s[i++];
}
}
public int nextInt() { return int.Parse(nextString()); }
public long nextLong() { return long.Parse(nextString()); }
public double nextDouble() { return double.Parse(nextString()); }
public string[] arrayString() { return Console.ReadLine().Split(' '); }
public int[] arrayInt() {
string[] str = Console.ReadLine().Split(' ');
int[] array = new int[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = int.Parse(str[i]);
}
return array;
}
public long[] arrayLong() {
string[] str = Console.ReadLine().Split(' ');
long[] array = new long[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = long.Parse(str[i]);
}
return array;
}
public double[] arrayDouble() {
string[] str = Console.ReadLine().Split(' ');
double[] array = new double[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = double.Parse(str[i]);
}
return array;
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
| 8
| 597
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class MainClass {
public static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
List<int> originalValues =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var negativeCount = originalValues.Count(num => num < 0);
// 全て正の数にする
// マイナスが偶数個なら、全てのマイナスを消せる
List<int> vals = originalValues.Select(num => Math.Abs(num)).ToList();
if (negativeCount % 2 != 0) {
// マイナスが奇数個なら、かならず1つマイナスが残る→最小値をマイナスにする
var min = vals.Min();
vals.RemoveAt(vals.IndexOf(min));
vals.Add(-min);
}
Console.WriteLine(vals.Sum());
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class MainClass {
public static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
List<long> originalValues =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
int negativeCount = originalValues.Count(num => num < 0);
// 全て正の数にする
// マイナスが偶数個なら、全てのマイナスを消せる
List<long> vals = originalValues.Select(num => Math.Abs(num)).ToList();
if (negativeCount % 2 != 0) {
// マイナスが奇数個なら、かならず1つマイナスが残る→最小値をマイナスにする
long min = vals.Min();
vals.RemoveAt(vals.IndexOf(min));
vals.Add(-min);
}
Console.WriteLine(vals.Sum());
}
}
|
[["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 64, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 171
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC125C {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
var numbers = Console.ReadLine().Split().Select(long.Parse).ToList();
var count = 0;
long sum = 0;
long small = 0;
var firstflag = true;
long abs = 0;
foreach (var number in numbers) {
abs = Math.Abs(number);
if (firstflag) {
small = number;
firstflag = false;
} else {
if (small > abs) {
small = abs;
}
}
sum += abs;
if (number <= 0) {
count++;
}
}
if (count % 2 == 0) {
Console.WriteLine(sum);
} else {
Console.WriteLine(sum - small * 2);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC125C {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
var numbers = Console.ReadLine().Split().Select(long.Parse).ToList();
var count = 0;
long sum = 0;
long small = 0;
var firstflag = true;
long abs = 0;
foreach (var number in numbers) {
abs = Math.Abs(number);
if (firstflag) {
small = abs;
firstflag = false;
} else {
if (small > abs) {
small = abs;
}
}
sum += abs;
if (number < 0) {
count++;
}
}
if (count % 2 == 0) {
Console.WriteLine(sum);
} else {
Console.WriteLine(sum - small * 2);
}
}
}
}
|
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 202
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
class Program {
static void Main() {
int N = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
//ひっくり返すかひっくり返さないか
int[,] DP = new int[N, 2];
//インデックスiを逆転したとき(i+1も逆転されている)の0~iまでの和の最大値をDP[i,1]とする。
//インデックスiを逆転していないとき(i+1も逆転されていないとき)の0~iまでの和の最大値をDP[i,1]とする。
DP[0, 0] = A[0];
DP[0, 1] = -A[0];
for (int i = 1; i <= N - 1; i++) {
DP[i, 0] = Math.Max(DP[i - 1, 0] + A[i], DP[i - 1, 1] - A[i]);
DP[i, 1] = Math.Max(DP[i - 1, 0] - A[i], DP[i - 1, 1] + A[i]);
}
Console.WriteLine(
Math.Max(DP[N - 2, 0] + A[N - 1], DP[N - 2, 1] - A[N - 1]));
}
}
static class MathUtil {
public static IEnumerable<IEnumerable<int>> GetPermutation(int n) {
if (n == 0) {
yield return Single(0);
yield break;
}
for (int i = 0; i <= n; i++) {
foreach (var x in GetPermutation(n - 1)) {
yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
}
}
}
private static IEnumerable<int> Single(int x) { yield return x; }
public static IEnumerable<int> EnumeratePrimeNumbers() {
List<int> primes = new List<int>() { 2 };
yield return 2;
for (int i = 3; i < int.MaxValue; i++) {
bool isPrime = true;
int Sqrt = (int)Math.Sqrt(i) + 1;
foreach (var prime in primes) {
if (prime > Sqrt) {
break;
}
if (i % prime == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.Add(i);
yield return i;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
class Program {
static void Main() {
int N = int.Parse(Console.ReadLine());
long[] A =
Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
//ひっくり返すかひっくり返さないか
long[,] DP = new long[N, 2];
//インデックスiを逆転したとき(i+1も逆転されている)の0~iまでの和の最大値をDP[i,1]とする。
//インデックスiを逆転していないとき(i+1も逆転されていないとき)の0~iまでの和の最大値をDP[i,0]とする。
DP[0, 0] = A[0];
DP[0, 1] = -A[0];
for (int i = 1; i <= N - 1; i++) {
DP[i, 0] = Math.Max(DP[i - 1, 0] + A[i], DP[i - 1, 1] - A[i]);
DP[i, 1] = Math.Max(DP[i - 1, 0] - A[i], DP[i - 1, 1] + A[i]);
}
Console.WriteLine(
Math.Max(DP[N - 2, 0] + A[N - 1], DP[N - 2, 1] - A[N - 1]));
}
}
static class MathUtil {
public static IEnumerable<IEnumerable<int>> GetPermutation(int n) {
if (n == 0) {
yield return Single(0);
yield break;
}
for (int i = 0; i <= n; i++) {
foreach (var x in GetPermutation(n - 1)) {
yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
}
}
}
private static IEnumerable<int> Single(int x) { yield return x; }
public static IEnumerable<int> EnumeratePrimeNumbers() {
List<int> primes = new List<int>() { 2 };
yield return 2;
for (int i = 3; i < int.MaxValue; i++) {
bool isPrime = true;
int Sqrt = (int)Math.Sqrt(i) + 1;
foreach (var prime in primes) {
if (prime > Sqrt) {
break;
}
if (i % prime == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.Add(i);
yield return i;
}
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199]]
| 8
| 510
| 8
|
using System;
using System.Collections.Generic;
using static Exter;
using System.Linq;
#if DEBUG
#else
using console = System.Console;
#endif
public class App {
public static void Main(string[] args) {
int n = readarr[0];
cout = readarr.Sum(v => Math.Abs(v)) -
(preadarr.Count(v => v < 0) % 2 == 0
? 0
: preadarr.Min(v => Math.Abs(v)) * 2);
}
}
public static class Exter {
public static void rep(int loop, Action<int> act) {
for (int i = 0; i < loop; i++)
act(i);
}
public static int ToInt(this string v) => int.Parse(v);
public static int Max(params int[] p) => p.Max();
public static long Max(params long[] p) => p.Max();
public static int Min(params int[] p) => p.Min();
public static long Min(params long[] p) => p.Min();
public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static int GcdRecursive(int a,
int b) => b == 0 ? a : GcdRecursive(b, a % b);
public static object cout {
set {
console.Write(value.ToString());
console.WriteLine();
}
}
public static void ToCout<t>(this IEnumerable<t> v) {
cout = string.Join(",", v);
}
public static int[] readarr {
get {
preadarr = console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
return preadarr;
}
}
public static int[] preadarr;
}
#if DEBUG
public static class console {
static int cursorLine = 0;
static readonly string[] cin = new string[] { "3", "-10 5 -4" };
static public string ReadLine() { return cin[cursorLine++]; }
static public void WriteLine() { Console.WriteLine(); }
static public void WriteLine<T>(T input) { Console.WriteLine(input); }
static public void Write<T>(T input) { Console.Write(input); }
static public void WriteLine(string s, params object[] arr) {
Console.WriteLine(s, arr);
}
}
#endif
|
using System;
using System.Collections.Generic;
using static Exter;
using System.Linq;
#if DEBUG
#else
using console = System.Console;
#endif
public class App {
public static void Main(string[] args) {
long n = readarr[0];
cout = readarr.Sum(v => Math.Abs(v)) -
(preadarr.Count(v => v < 0) % 2 == 0
? 0
: preadarr.Min(v => Math.Abs(v)) * 2);
}
}
public static class Exter {
public static void rep(int loop, Action<int> act) {
for (int i = 0; i < loop; i++)
act(i);
}
public static int ToInt(this string v) => int.Parse(v);
public static int Max(params int[] p) => p.Max();
public static long Max(params long[] p) => p.Max();
public static int Min(params int[] p) => p.Min();
public static long Min(params long[] p) => p.Min();
public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static int GcdRecursive(int a,
int b) => b == 0 ? a : GcdRecursive(b, a % b);
public static object cout {
set {
console.Write(value.ToString());
console.WriteLine();
}
}
public static void ToCout<t>(this IEnumerable<t> v) {
cout = string.Join(",", v);
}
public static long[] readarr {
get {
preadarr =
console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
return preadarr;
}
}
public static long[] preadarr;
}
#if DEBUG
public static class console {
static int cursorLine = 0;
static readonly string[] cin = new string[] { "3", "-10 5 -4" };
static public string ReadLine() { return cin[cursorLine++]; }
static public void WriteLine() { Console.WriteLine(); }
static public void WriteLine<T>(T input) { Console.WriteLine(input); }
static public void Write<T>(T input) { Console.Write(input); }
static public void WriteLine(string s, params object[] arr) {
Console.WriteLine(s, arr);
}
}
#endif
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 235, 8, 201, 0, 277, 39, 224, 39, 199], ["+", 0, 235, 8, 201, 0, 277, 39, 224, 39, 199], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199]]
| 8
| 533
| 8
|
using System;
using System.Linq;
namespace d {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
if (A.Count(x => x < 0) % 2 == 0) {
Console.WriteLine(A.Sum(x => Math.Abs(x)));
} else {
Console.WriteLine(A.Sum(x => Math.Abs(x)) - 2 * A.Min(x => Math.Abs(x)));
}
}
}
}
|
using System;
using System.Linq;
namespace d {
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
if (A.Count(x => x < 0) % 2 == 0) {
Console.WriteLine(A.Sum(x => Math.Abs(x)));
} else {
Console.WriteLine(A.Sum(x => Math.Abs(x)) - 2 * A.Min(x => Math.Abs(x)));
}
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
| 8
| 144
| 6
|
using System;
using System.Linq;
using System.Threading.Tasks;
static class Program {
static void Main() {
int nGem = int.Parse(Console.ReadLine());
var values =
Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray();
bool isEven = (values.Select(v => v < 0 ? 1 : 0).Sum() % 2 == 0);
isEven |= values.Any(v => v == 0);
var absValue = values.Select(v => Math.Abs(v));
long result = absValue.Sum();
if (isEven == false) {
long adjust = absValue.Min() * 2;
result -= adjust;
}
Console.WriteLine(result);
}
}
|
using System;
using System.Linq;
using System.Threading.Tasks;
static class Program {
static void Main() {
int nGem = int.Parse(Console.ReadLine());
var values = Console.ReadLine().Split(' ').Select(c => long.Parse(c));
// int nGem = 5;
// var values = new long[] {
// -1000000000,1000000000,-1000000000,1000000000,-1000000000,0,1000000000,-1000000000,1000000000,-1000000000,1000000000};
bool isEven = (values.Select(v => v < 0 ? 1 : 0).Sum() % 2 == 0);
isEven |= values.Any(v => v == 0);
var absValue = values.Select(v => Math.Abs(v));
long result = absValue.Sum();
if (isEven == false) {
long adjust = absValue.Min() * 2;
result -= adjust;
}
Console.WriteLine(result);
}
}
|
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 0, 28, 0, 218, 8, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24]]
| 8
| 170
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC125_D {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
List<long> numList =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToList();
numList = numList.OrderByDescending(i => Math.Abs(i)).ToList();
for (int i = 0; i < n - 1; i++) {
if (numList[i] < 0) {
numList[i] *= -1;
numList[i + 1] *= -1;
}
}
long ans = 0;
for (int i = 0; i < n - 1; i++) {
ans += numList[i];
}
Console.WriteLine(ans);
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC125_D {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
List<long> numList =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToList();
numList = numList.OrderByDescending(i => Math.Abs(i)).ToList();
for (int i = 0; i < n - 1; i++) {
if (numList[i] < 0) {
numList[i] *= -1;
numList[i + 1] *= -1;
}
}
long ans = 0;
for (int i = 0; i < n; i++) {
ans += numList[i];
}
Console.WriteLine(ans);
Console.ReadLine();
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 205
| 2
|
using System;
class Tenka_A {
static void Main() {
int[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int H1 = Ar[0], H2 = Ar[1], H3 = Ar[2];
if ((H1 < H2 && H2 > H3) || (H1 > H2 && H2 < H3))
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
|
using System;
class Tenka_A {
static void Main() {
int[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int H1 = Ar[0], H2 = Ar[1], H3 = Ar[2];
if ((H1 < H3 && H2 > H3) || (H1 > H3 && H2 < H3))
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
|
[["-", 15, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 12, 22]]
| 8
| 104
| 4
|
using System;
using System.Linq;
class Mainp {
public static void Main() {
var str = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
if (Math.Abs(str[0] - str[1]) >=
(Math.Abs(str[0] - str[2]) + Math.Abs(str[1] - str[2])))
Console.WriteLine("NO");
else
Console.WriteLine("YES");
}
}
|
using System;
using System.Linq;
class Mainp {
public static void Main() {
var str = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
if (Math.Abs(str[0] - str[1]) >=
(Math.Abs(str[0] - str[2]) + Math.Abs(str[1] - str[2])))
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 120
| 4
|
using System;
namespace Project {
class Program {
static void Main() {
int[] args = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int a = args[0];
int b = args[1];
int c = args[2];
Console.WriteLine((a < c && c < b) || (b < c && a < c) ? "Yes" : "No");
}
}
}
|
using System;
namespace Project {
class Program {
static void Main() {
int[] args = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int a = args[0];
int b = args[1];
int c = args[2];
Console.WriteLine((a < c && c < b) || (b < c && c < a) ? "Yes" : "No");
}
}
}
|
[["-", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 17, 18], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 18], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 22]]
| 8
| 102
| 4
|
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var a = int.Parse(line[0]);
var b = int.Parse(line[1]);
var c = int.Parse(line[2]);
if (a < b && a < c && c < b)
Console.WriteLine("Yes");
else if (b > a && b < c && c < a)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
|
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var a = int.Parse(line[0]);
var b = int.Parse(line[1]);
var c = int.Parse(line[2]);
if (a < b && a < c && c < b)
Console.WriteLine("Yes");
else if (a > b && b < c && c < a)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
|
[["-", 75, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 75, 57, 15, 16, 31, 16, 31, 16, 17, 47], ["+", 75, 57, 15, 16, 31, 16, 31, 16, 17, 47], ["+", 75, 57, 15, 16, 31, 16, 31, 16, 12, 22]]
| 8
| 134
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
// using Debug;
// using static System.Globalization.CultureInfo;
class Program {
static void Main(string[] args) {
Solve();
// WriteLine(Solve());
}
static void Solve() {
var abc = Input.ar;
WriteLine(Min(abc[0], abc[1]) < abc[2] || abc[2] < Max(abc[0], abc[1])
? "Yes"
: "No");
}
}
public class Input {
public static string read => ReadLine();
public static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
public static int num => ToInt32(read);
public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
public static long numL => ToInt64(read);
public static char[][] gred(int h) =>
Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
public static int[][] ar2D(int num) =>
Enumerable.Repeat(0, num).Select(v => ar).ToArray();
public static long[][] arL2D(int num) =>
Enumerable.Repeat(0, num).Select(v => arL).ToArray();
public const long Inf = (long)1e18;
public const double eps = 1e-6;
public const string Alfa = "abcdefghijklmnopqrstuvwxyz";
public const int MOD = 1000000007;
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
// using Debug;
// using static System.Globalization.CultureInfo;
class Program {
static void Main(string[] args) {
Solve();
// WriteLine(Solve());
}
static void Solve() {
var abc = Input.ar;
WriteLine(Min(abc[0], abc[1]) < abc[2] && abc[2] < Max(abc[0], abc[1])
? "Yes"
: "No");
}
}
public class Input {
public static string read => ReadLine();
public static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
public static int num => ToInt32(read);
public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
public static long numL => ToInt64(read);
public static char[][] gred(int h) =>
Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
public static int[][] ar2D(int num) =>
Enumerable.Repeat(0, num).Select(v => ar).ToArray();
public static long[][] arL2D(int num) =>
Enumerable.Repeat(0, num).Select(v => arL).ToArray();
public const long Inf = (long)1e18;
public const double eps = 1e-6;
public const string Alfa = "abcdefghijklmnopqrstuvwxyz";
public const int MOD = 1000000007;
}
|
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 106], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 98]]
| 8
| 362
| 2
|
using System;
namespace Tenka1A {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
int C = int.Parse(input[2]);
bool flg = false;
if (A > B) {
if (C > B && C > A) {
flg = true;
}
} else if (B > A) {
if (B > C && C > A) {
flg = true;
}
}
if (flg) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
namespace Tenka1A {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
int C = int.Parse(input[2]);
bool flg = false;
if (A > B) {
if (C > B && A > C) {
flg = true;
}
} else if (B > A) {
if (B > C && C > A) {
flg = true;
}
}
if (flg) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["-", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 64, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 160
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class myon {
public static void Main(string[] args) { var myon = new myon(); }
public myon() {
string[] input = Console.ReadLine().Split(' ');
int[] intin = new int[3];
for (int i = 0; i < 3; i++) {
intin[i] = int.Parse(input[i]);
}
if (intin[0] < intin[1] && intin[0] < intin[2] && intin[1] > intin[2])
Console.WriteLine("Yes");
else if (intin[1] < intin[0] && intin[1] < intin[2] && intin[1] < intin[0])
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class myon {
public static void Main(string[] args) { var myon = new myon(); }
public myon() {
string[] input = Console.ReadLine().Split(' ');
int[] intin = new int[3];
for (int i = 0; i < 3; i++) {
intin[i] = int.Parse(input[i]);
}
if (intin[0] < intin[1] && intin[0] < intin[2] && intin[1] > intin[2])
Console.WriteLine("Yes");
else if (intin[1] < intin[0] && intin[1] < intin[2] && intin[0] > intin[2])
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
|
[["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 47], ["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 203
| 6
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.