buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Collections.Generic;
using System.Linq;
class F {
struct LR {
public long L, R;
}
static void Main() {
var h = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = h[0], x = h[1], d = h[2];
if (d == 0) {
Console.WriteLine(x == 0 ? 1 : n + 1);
return;
}
if (d < 0) {
d = -d;
x = -x;
}
var map = new Dictionary<long, List<LR>>();
for (long i = 0; i <= n; i++) {
var l = i * (i - 1) / 2;
var r = n * (n - 1) / 2 - (n - i) * (n - i - 1) / 2;
var a = i * x;
var m = a % d;
if (m < 0)
m += d;
a = (a - m) / d;
if (!map.ContainsKey(m))
map[m] = new List<LR>();
map[m].Add(new LR { L = a + l, R = a + r });
}
var c = 0L;
foreach (var lrs in map.Values) {
var M = long.MinValue;
foreach (var lr in lrs.OrderBy(s => s.L).ThenBy(s => s.R)) {
c += lr.R - Math.Max(M, lr.L - 1);
M = Math.Max(M, lr.R);
}
}
Console.WriteLine(c);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class F {
struct LR {
public long L, R;
}
static void Main() {
var h = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = h[0], x = h[1], d = h[2];
if (d == 0) {
Console.WriteLine(x == 0 ? 1 : n + 1);
return;
}
if (d < 0) {
d = -d;
x = -x;
}
var map = new Dictionary<long, List<LR>>();
for (long i = 0; i <= n; i++) {
var l = i * (i - 1) / 2;
var r = n * (n - 1) / 2 - (n - i) * (n - i - 1) / 2;
var a = i * x;
var m = a % d;
if (m < 0)
m += d;
a = (a - m) / d;
if (!map.ContainsKey(m))
map[m] = new List<LR>();
map[m].Add(new LR { L = a + l, R = a + r });
}
var c = 0L;
foreach (var lrs in map.Values) {
var M = long.MinValue;
foreach (var lr in lrs.OrderBy(s => s.L)) {
c += Math.Max(0, lr.R - Math.Max(M, lr.L - 1));
M = Math.Max(M, lr.R);
}
}
Console.WriteLine(c);
}
}
|
[["-", 8, 196, 0, 210, 12, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 210, 12, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 12, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["-", 8, 196, 0, 210, 12, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 369
| 16
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using E = System.Linq.Enumerable;
internal partial class Solver {
public void Run() {
var N = ni();
var X = ni();
var D = ni();
cout.WriteLine(Solve(N, X, D));
}
private long SolveNaive(int n, long x, long d) {
var a = new long[n];
a[0] = x;
for (int i = 1; i < n; i++) {
a[i] = a[i - 1] + d;
}
var hashset = new HashSet<long>();
for (int i = 0; i < (1 << n); i++) {
var s = 0L;
for (int j = 0; j < n; j++) {
if (((1 << j) & i) != 0) {
s += a[j];
}
}
hashset.Add(s);
}
return hashset.Count;
}
private long Solve(int n, long x, long d) {
if (d == 0)
return n + 1;
if (n == 1)
return 1;
long lower = 0;
long upper = 0;
var segments = new Dictionary<long, List<Tuple<long, long>>>();
segments[0] = new List<Tuple<long, long>> { Tuple.Create(0L, 0L) };
for (int i = 1; i <= n; i++) {
lower += i - 1;
upper += n - i;
// k*X + t*D
var mod = (1L * i * x) % Math.Abs(d);
if (mod < 0)
mod += Math.Abs(d);
var offset = (i * x - mod) / Math.Abs(d);
List<Tuple<long, long>> list;
if (!segments.TryGetValue(mod, out list)) {
list = new List<Tuple<long, long>>();
segments.Add(mod, list);
}
// new { mod, lower, upper, offset }.Dump();
if (d > 0) {
list.Add(Tuple.Create(lower + offset, upper + offset));
} else {
list.Add(Tuple.Create(-upper + offset, -lower + offset));
}
}
long ans = 0;
foreach (var kv in segments) {
ans += Count(kv.Value);
}
// segments.Dump();
return ans;
}
private long Count(List<Tuple<long, long>> segments) {
segments.Sort((v1, v2) => v1.Item1.CompareTo(v2.Item1));
long left = long.MinValue;
long right = long.MinValue;
long ans = 0;
foreach (var seg in segments) {
if (seg.Item1 <= right) { // have common
right = Math.Max(right, seg.Item2);
} else {
if (left != long.MinValue) {
ans += right - left + 1;
}
left = seg.Item1;
right = seg.Item2;
}
}
if (left != long.MinValue) {
ans += right - left + 1;
}
return ans;
}
public static long DivLower(long x, long y) {
if (y < 0) {
return DivLower(-x, -y);
}
if (x >= 0) {
return x / y;
}
return x / y - (x % y == 0 ? 0 : 1);
}
}
// PREWRITEN CODE BEGINS FROM HERE
internal partial class Solver : Scanner {
public static void Main(string[] args) {
#if LOCAL
byte[] inputBuffer = new byte[1000000];
var inputStream = Console.OpenStandardInput(inputBuffer.Length);
using (var reader = new StreamReader(inputStream, Console.InputEncoding,
false, inputBuffer.Length)) {
Console.SetIn(reader);
new Solver(Console.In, Console.Out).Run();
}
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver(Console.In, Console.Out).Run();
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
internal static class LinqPadExtension {
public static T Dump<T>(this T obj) {
#if LOCAL
return LINQPad.Extensions.Dump(obj);
#else
return obj;
#endif
}
}
public class Scanner {
private readonly TextReader Reader;
private readonly Queue<string> TokenQueue = new Queue<string>();
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return int.Parse(Next(), ci); }
public long NextLong() { return long.Parse(Next(), ci); }
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (TokenQueue.Count == 0) {
if (!StockTokens()) {
throw new InvalidOperationException();
}
}
return TokenQueue.Dequeue();
}
public bool HasNext() {
if (TokenQueue.Count > 0) {
return true;
}
return StockTokens();
}
private static readonly char[] _separator = new[] { ' ', '\t' };
private bool StockTokens() {
while (true) {
string line = Reader.ReadLine();
if (line == null) {
return false;
}
string[] tokens =
line.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length == 0) {
continue;
}
foreach (string token in tokens) {
TokenQueue.Enqueue(token);
}
return true;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using E = System.Linq.Enumerable;
internal partial class Solver {
public void Run() {
var N = ni();
var X = ni();
var D = ni();
cout.WriteLine(Solve(N, X, D));
}
internal static long SolveNaive(int n, long x, long d) {
var a = new long[n];
a[0] = x;
for (int i = 1; i < n; i++) {
a[i] = a[i - 1] + d;
}
var hashset = new HashSet<long>();
for (int i = 0; i < (1 << n); i++) {
var s = 0L;
for (int j = 0; j < n; j++) {
if (((1 << j) & i) != 0) {
s += a[j];
}
}
hashset.Add(s);
}
return hashset.Count;
}
internal static long Solve(int n, long x, long d) {
if (d == 0) {
return x == 0 ? 1 : n + 1;
}
long lower = 0;
long upper = 0;
var segments = new Dictionary<long, List<Tuple<long, long>>>();
segments[0] = new List<Tuple<long, long>> { Tuple.Create(0L, 0L) };
for (int i = 1; i <= n; i++) {
lower += i - 1;
upper += n - i;
// k*X + t*D
var mod = (1L * i * x) % Math.Abs(d);
if (mod < 0)
mod += Math.Abs(d);
var offset = (i * x - mod) / Math.Abs(d);
List<Tuple<long, long>> list;
if (!segments.TryGetValue(mod, out list)) {
list = new List<Tuple<long, long>>();
segments.Add(mod, list);
}
// new { mod, lower, upper, offset }.Dump();
if (d > 0) {
list.Add(Tuple.Create(lower + offset, upper + offset));
} else {
list.Add(Tuple.Create(-upper + offset, -lower + offset));
}
}
long ans = 0;
foreach (var kv in segments) {
ans += Count(kv.Value);
}
// segments.Dump();
return ans;
}
static private long Count(List<Tuple<long, long>> segments) {
segments.Sort((v1, v2) => v1.Item1.CompareTo(v2.Item1));
long left = long.MinValue;
long right = long.MinValue;
long ans = 0;
foreach (var seg in segments) {
if (seg.Item1 <= right) { // have common
right = Math.Max(right, seg.Item2);
} else {
if (left != long.MinValue) {
ans += right - left + 1;
}
left = seg.Item1;
right = seg.Item2;
}
}
if (left != long.MinValue) {
ans += right - left + 1;
}
return ans;
}
public static long DivLower(long x, long y) {
if (y < 0) {
return DivLower(-x, -y);
}
if (x >= 0) {
return x / y;
}
return x / y - (x % y == 0 ? 0 : 1);
}
}
// PREWRITEN CODE BEGINS FROM HERE
internal partial class Solver : Scanner {
public static void Main(string[] args) {
#if LOCAL
byte[] inputBuffer = new byte[1000000];
var inputStream = Console.OpenStandardInput(inputBuffer.Length);
using (var reader = new StreamReader(inputStream, Console.InputEncoding,
false, inputBuffer.Length)) {
Console.SetIn(reader);
new Solver(Console.In, Console.Out).Run();
}
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver(Console.In, Console.Out).Run();
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
internal static class LinqPadExtension {
public static T Dump<T>(this T obj) {
#if LOCAL
return LINQPad.Extensions.Dump(obj);
#else
return obj;
#endif
}
}
public class Scanner {
private readonly TextReader Reader;
private readonly Queue<string> TokenQueue = new Queue<string>();
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return int.Parse(Next(), ci); }
public long NextLong() { return long.Parse(Next(), ci); }
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (TokenQueue.Count == 0) {
if (!StockTokens()) {
throw new InvalidOperationException();
}
}
return TokenQueue.Dequeue();
}
public bool HasNext() {
if (TokenQueue.Count > 0) {
return true;
}
return StockTokens();
}
private static readonly char[] _separator = new[] { ' ', '\t' };
private bool StockTokens() {
while (true) {
string line = Reader.ReadLine();
if (line == null) {
return false;
}
string[] tokens =
line.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length == 0) {
continue;
}
foreach (string token in tokens) {
TokenQueue.Enqueue(token);
}
return true;
}
}
}
|
[["-", 0, 235, 8, 201, 0, 195, 0, 251, 0, 261], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 305], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 115], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 37, 0, 16, 31, 22], ["-", 8, 196, 0, 57, 64, 37, 0, 16, 17, 72], ["-", 8, 196, 0, 57, 64, 37, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 64, 196, 0, 37, 0, 41, 15, 16, 31, 22], ["+", 64, 196, 0, 37, 0, 41, 15, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 37, 0, 41, 0, 101], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 37, 0, 41, 0, 102], ["+", 64, 196, 0, 37, 0, 41, 75, 16, 31, 22], ["+", 64, 196, 0, 37, 0, 41, 75, 16, 17, 72], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 1,610
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Text;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
var solver = new Solver(sw);
// var t = new Thread(solver.solve, 1 << 26); // 64 MB
// t.Start();
// t.Join();
solver.solve();
sw.Flush();
}
}
class Solver {
StreamWriter sw;
Scan sc;
void Prt(string a) => sw.WriteLine(a);
void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
void Prt(params object[] a) => Prt(string.Join(" ", a));
public Solver(StreamWriter sw) {
this.sw = sw;
this.sc = new Scan();
}
public void solve() {
int n;
long x, d;
sc.Multi(out n, out x, out d);
if (d == 0) {
if (x == 0) {
Prt(1);
} else
Prt(n + 1);
return;
}
if (d < 0) {
x = -x;
d = -d;
}
var dic = new Dictionary<long, List<pair<long, long>>>();
for (int i = 0; i <= n; i++) {
long p = x * i;
long l = i * (long)(i - 1) / 2;
long r = i * (long)(n * 2 - i - 1) / 2 + 1;
{
long q = p / d;
l += q;
r += q;
p -= q * d;
}
while (p < 0) {
p += d;
--l;
--r;
}
if (r <= l)
continue;
if (!dic.ContainsKey(p)) {
dic.Add(p, new List<pair<long, long>>());
}
dic[p].Add(new pair<long, long>(l, r));
}
long ans = 0;
foreach (var item in dic) {
long las = -LM;
item.Value.Sort();
foreach (var p in item.Value) {
ans += Math.Max(0, p.v2 - Math.Max(las, p.v1));
las = p.v2;
}
}
Prt(ans);
}
}
class pair<T, U> : IComparable<pair<T, U>> {
public T v1;
public U v2;
public pair() : this(default(T), default(U)) {}
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) {
int c = Comparer<T>.Default.Compare(v1, a.v1);
return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2);
}
public override string ToString() => v1 + " " + v2;
public void Deconstruct(out T a, out U b) {
a = v1;
b = v2;
}
}
static class util {
public static readonly int M = 1000000007;
// public static readonly int M = 998244353;
public static readonly long LM = 1L << 60;
public static readonly double eps = 1e-11;
public static void DBG(string a) => Console.Error.WriteLine(a);
public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
public static void DBG(params object[] a) => DBG(string.Join(" ", a));
public static void Assert(bool cond) {
if (!cond)
throw new Exception();
}
public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1,
v2);
public static int CompareList<T>(IList<T> a, IList<T> b)
where T : IComparable<T> {
for (int i = 0; i < a.Count && i < b.Count; i++)
if (a[i].CompareTo(b[i]) != 0)
return a[i].CompareTo(b[i]);
return a.Count.CompareTo(b.Count);
}
public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h
&& j >= 0 && j < w;
static readonly int[] dd = { 0, 1, 0, -1 };
// static readonly string dstring = "RDLU";
public static P[] adjacents(int i,
int j) => Enumerable.Range(0, dd.Length)
.Select(k => new P(i + dd[k],
j + dd[k ^ 1]))
.ToArray();
public static P[] adjacents(int i, int j, int h, int w) =>
Enumerable.Range(0, dd.Length)
.Select(k => new P(i + dd[k], j + dd[k ^ 1]))
.Where(p => inside(p.v1, p.v2, h, w))
.ToArray();
public static P[] adjacents(this P p) => adjacents(p.v1, p.v2);
public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2,
h, w);
public static Dictionary<T, int>
compress<T>(this IEnumerable<T> a) => a.Distinct()
.OrderBy(v => v)
.Select((v, i) => new { v, i })
.ToDictionary(p => p.v, p => p.i);
public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) =>
compress(a.Aggregate(Enumerable.Union));
public static T[] inv<T>(this Dictionary<T, int> dic) {
var res = new T[dic.Count];
foreach (var item in dic)
res[item.Value] = item.Key;
return res;
}
public static void swap<T>(ref T a, ref T b)
where T : struct {
var t = a;
a = b;
b = t;
}
public static void swap<T>(this IList<T> a, int i, int j)
where T : struct {
var t = a[i];
a[i] = a[j];
a[j] = t;
}
public static T[] copy<T>(this IList<T> a) {
var ret = new T[a.Count];
for (int i = 0; i < a.Count; i++)
ret[i] = a[i];
return ret;
}
}
class Scan {
StreamReader sr;
public Scan() { sr = new StreamReader(Console.OpenStandardInput()); }
public Scan(string path) { sr = new StreamReader(path); }
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => sr.ReadLine().Trim();
public pair<T, U> Pair<T, U>() {
T a;
U b;
Multi(out a, out b);
return new pair<T, U>(a, b);
}
public P P => Pair<int, int>();
public int[] IntArr => StrArr.Select(int.Parse).ToArray();
public long[] LongArr => StrArr.Select(long.Parse).ToArray();
public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
public string[] StrArr =>
Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
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);
public void Multi<T>(out T a) => a = cv<T>(Str);
public void Multi<T, U>(out T a, out U b) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
public void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Text;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
var solver = new Solver(sw);
// var t = new Thread(solver.solve, 1 << 26); // 64 MB
// t.Start();
// t.Join();
solver.solve();
sw.Flush();
}
}
class Solver {
StreamWriter sw;
Scan sc;
void Prt(string a) => sw.WriteLine(a);
void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
void Prt(params object[] a) => Prt(string.Join(" ", a));
public Solver(StreamWriter sw) {
this.sw = sw;
this.sc = new Scan();
}
public void solve() {
int n;
long x, d;
sc.Multi(out n, out x, out d);
if (d == 0) {
if (x == 0) {
Prt(1);
} else
Prt(n + 1);
return;
}
if (d < 0) {
x = -x;
d = -d;
}
var dic = new Dictionary<long, List<pair<long, long>>>();
for (int i = 0; i <= n; i++) {
long p = x * i;
long l = i * (long)(i - 1) / 2;
long r = i * (long)(n * 2 - i - 1) / 2 + 1;
{
long q = p / d;
l += q;
r += q;
p -= q * d;
}
while (p < 0) {
p += d;
--l;
--r;
}
if (r <= l)
continue;
if (!dic.ContainsKey(p)) {
dic.Add(p, new List<pair<long, long>>());
}
dic[p].Add(new pair<long, long>(l, r));
}
long ans = 0;
foreach (var item in dic) {
long las = -LM;
item.Value.Sort();
foreach (var p in item.Value) {
ans += Math.Max(0, p.v2 - Math.Max(las, p.v1));
las = Math.Max(las, p.v2);
}
}
Prt(ans);
}
}
class pair<T, U> : IComparable<pair<T, U>> {
public T v1;
public U v2;
public pair() : this(default(T), default(U)) {}
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) {
int c = Comparer<T>.Default.Compare(v1, a.v1);
return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2);
}
public override string ToString() => v1 + " " + v2;
public void Deconstruct(out T a, out U b) {
a = v1;
b = v2;
}
}
static class util {
public static readonly int M = 1000000007;
// public static readonly int M = 998244353;
public static readonly long LM = 1L << 60;
public static readonly double eps = 1e-11;
public static void DBG(string a) => Console.Error.WriteLine(a);
public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
public static void DBG(params object[] a) => DBG(string.Join(" ", a));
public static void Assert(bool cond) {
if (!cond)
throw new Exception();
}
public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1,
v2);
public static int CompareList<T>(IList<T> a, IList<T> b)
where T : IComparable<T> {
for (int i = 0; i < a.Count && i < b.Count; i++)
if (a[i].CompareTo(b[i]) != 0)
return a[i].CompareTo(b[i]);
return a.Count.CompareTo(b.Count);
}
public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h
&& j >= 0 && j < w;
static readonly int[] dd = { 0, 1, 0, -1 };
// static readonly string dstring = "RDLU";
public static P[] adjacents(int i,
int j) => Enumerable.Range(0, dd.Length)
.Select(k => new P(i + dd[k],
j + dd[k ^ 1]))
.ToArray();
public static P[] adjacents(int i, int j, int h, int w) =>
Enumerable.Range(0, dd.Length)
.Select(k => new P(i + dd[k], j + dd[k ^ 1]))
.Where(p => inside(p.v1, p.v2, h, w))
.ToArray();
public static P[] adjacents(this P p) => adjacents(p.v1, p.v2);
public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2,
h, w);
public static Dictionary<T, int>
compress<T>(this IEnumerable<T> a) => a.Distinct()
.OrderBy(v => v)
.Select((v, i) => new { v, i })
.ToDictionary(p => p.v, p => p.i);
public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) =>
compress(a.Aggregate(Enumerable.Union));
public static T[] inv<T>(this Dictionary<T, int> dic) {
var res = new T[dic.Count];
foreach (var item in dic)
res[item.Value] = item.Key;
return res;
}
public static void swap<T>(ref T a, ref T b)
where T : struct {
var t = a;
a = b;
b = t;
}
public static void swap<T>(this IList<T> a, int i, int j)
where T : struct {
var t = a[i];
a[i] = a[j];
a[j] = t;
}
public static T[] copy<T>(this IList<T> a) {
var ret = new T[a.Count];
for (int i = 0; i < a.Count; i++)
ret[i] = a[i];
return ret;
}
}
class Scan {
StreamReader sr;
public Scan() { sr = new StreamReader(Console.OpenStandardInput()); }
public Scan(string path) { sr = new StreamReader(path); }
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => sr.ReadLine().Trim();
public pair<T, U> Pair<T, U>() {
T a;
U b;
Multi(out a, out b);
return new pair<T, U>(a, b);
}
public P P => Pair<int, int>();
public int[] IntArr => StrArr.Select(int.Parse).ToArray();
public long[] LongArr => StrArr.Select(long.Parse).ToArray();
public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
public string[] StrArr =>
Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
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);
public void Multi<T>(out T a) => a = cv<T>(Str);
public void Multi<T, U>(out T a, out U b) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
public void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
|
[["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
| 8
| 2,227
| 7
|
using static System.Console;
class Program {
static void Main(string[] args) {
string[] input = ReadLine().Split(' ');
string[] input2 = ReadLine().Split(' ');
int M1 = int.Parse(input[0]);
int D1 = int.Parse(input[1]);
int M2 = int.Parse(input2[0]);
int D2 = int.Parse(input2[1]);
if (M1 == M2 && D2 - D1 == 1 || M2 - M1 == 1 && D2 == 1 ||
M2 == 1 && D2 == 1) {
WriteLine(1);
} else {
WriteLine(0);
}
}
}
|
using static System.Console;
class Program {
static void Main(string[] args) {
string[] input = ReadLine().Split(' ');
string[] input2 = ReadLine().Split(' ');
int M1 = int.Parse(input[0]);
int D1 = int.Parse(input[1]);
int M2 = int.Parse(input2[0]);
int D2 = int.Parse(input2[1]);
if (D2 == 1) {
WriteLine(1);
} else {
WriteLine(0);
}
}
}
|
[["-", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 60], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["-", 31, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["-", 31, 16, 31, 16, 12, 16, 31, 16, 17, 33], ["-", 31, 16, 31, 16, 12, 16, 31, 16, 12, 22], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 17, 60], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["-", 31, 16, 12, 16, 31, 16, 31, 16, 31, 22], ["-", 31, 16, 12, 16, 31, 16, 31, 16, 17, 33], ["-", 31, 16, 12, 16, 31, 16, 31, 16, 12, 22], ["-", 15, 16, 31, 16, 12, 16, 31, 16, 17, 60], ["-", 15, 16, 31, 16, 12, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 98], ["-", 15, 16, 31, 16, 12, 16, 12, 16, 17, 60], ["-", 15, 16, 31, 16, 12, 16, 12, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22]]
| 8
| 150
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long n = sc.NextLong();
long answer = n * 100 / 108;
if (answer * 108 / 100 != n) {
Console.WriteLine(":(");
return;
}
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long n = sc.NextLong();
for (long i = 0; i <= n; i++) {
if (i * 108 / 100 == n) {
Console.WriteLine(i);
return;
}
}
Console.WriteLine(":(");
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 382
| 29
|
using System;
namespace ChokudaiScanner {
class MainClass {
static void Main() {
Scanner cin = new Scanner();
double b, c = cin.NextDouble();
b = c;
while (!(b == 0)) {
b--;
if (Math.Floor(b * 1.08) == c) {
Console.WriteLine(b);
break;
}
if (b == 0) {
Console.WriteLine(":(");
}
}
}
}
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;
namespace ChokudaiScanner {
class MainClass {
static void Main() {
Scanner cin = new Scanner();
double b, c = cin.NextDouble();
b = Math.Ceiling(c / 1.08);
if (Math.Floor(b * 1.08) == c) {
Console.WriteLine(b);
} else {
Console.WriteLine(":(");
}
}
}
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, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["-", 0, 195, 8, 196, 0, 52, 15, 241, 0, 111], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 52, 15, 241, 0, 23, 0, 16, 31, 22], ["-", 0, 52, 15, 241, 0, 23, 0, 16, 17, 60], ["-", 0, 52, 15, 241, 0, 23, 0, 16, 12, 203], ["-", 8, 196, 0, 52, 15, 241, 0, 23, 0, 25], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 250], ["-", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 446
| 28
|
using System;
using System.Collections;
using System.Collections.Generic;
using static Exter;
using System.Linq;
using System.Numerics;
#if DEBUG
#else
using console = System.Console;
#endif
public class App {
public static void Main(string[] args) {
var v = readarr[0];
for (int i = 0; i < 50000; i++) {
if (Math.Floor(i * 1.08) == v) {
cout = i;
break;
}
}
}
public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static long GcdRecursive(long a, long b) {
if (b == 0)
return a;
return GcdRecursive(b, a % b);
}
}
public class RollingHash {
long[] h;
long m = 2147483647;
int b = 524287;
Power baser;
public RollingHash(string s) {
baser = new Power(b);
h = new long[s.Length];
h[0] = 0;
for (int i = 1; i < s.Length; i++) {
h[i] = (h[i - 1] * b + s[i]) % m;
}
}
public long Calc(int l, int r) {
cout = h[r];
cout = h[l] * baser.GetEntry(r - l - 1);
return 0;
}
}
public class PriorityQueue<T> : IEnumerable<T>
where T : IComparable {
List<T> buffer = new List<T>();
static void PushHeap(List<T> array, T elem) {
int n = array.Count;
array.Add(elem);
while (n != 0) {
int i = (n - 1) / 2;
if (array[n].CompareTo(array[i]) < 0) {
T tmp = array[n];
array[n] = array[i];
array[i] = tmp;
}
n = i;
}
}
static void PopHeap(List<T> array) {
int n = array.Count - 1;
array[0] = array[n];
array.RemoveAt(array.Count - 1);
for (int i = 0, j; (j = 2 * i + 1) < n;) {
if ((j != n - 1) && (array[j].CompareTo(array[j + 1]) > 0))
j++;
if (array[i].CompareTo(array[j]) > 0) {
T tmp = array[j];
array[j] = array[i];
array[i] = tmp;
}
i = j;
}
}
public int Count {
get { return buffer.Count; }
}
public void Push(T elem) { PushHeap(this.buffer, elem); }
public T Peek() { return buffer[0]; }
public T Pop() {
T a = buffer[0];
PopHeap(this.buffer);
return a;
}
public IEnumerator<T> GetEnumerator() {
var v = new List<T>(buffer);
while (v.Count != 0) {
yield return v[0];
PopHeap(v);
}
}
IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
}
public class Power {
public int Base;
private List<long> Value = new List<long>();
public Power(int v) {
if (v == 1)
new ArgumentOutOfRangeException();
long prev = -1;
long g = v;
Base = v;
while (g > prev) {
Value.Add(g);
prev = g;
g *= g;
}
}
public long GetEntry(int exponent) {
long s = 1;
for (int i = 0; (1 << i) <= exponent; i++) {
if ((exponent & (1 << i)) != 0) {
s *= Value[i];
}
}
return s;
}
}
public static class Exter {
public static IEnumerable<long> PrimeFactors(long n) {
int i = 2;
long tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
public class LoopArray<T> {
public readonly int Length;
private T[] arr;
public LoopArray(int Capacity) { Length = Capacity; }
public LoopArray(T[] ar) {
arr = new T[ar.Length];
Array.Copy(ar, arr, ar.Length);
}
}
public class Point {
public Point(int cx, int cy) {
x = cx;
y = cy;
}
public int x;
public int y;
}
public static IEnumerable<Result>
ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b,
Func<T1, T2, Result> f) {
foreach (var v in a) {
foreach (var w in b)
yield return f(v, w);
}
}
public static IEnumerable<Result>
ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b,
Func<T1, T2, Result> f, Func<T1, T2, bool> s) {
foreach (var v in a) {
foreach (var w in b)
if (s(v, w))
yield return f(v, w);
}
}
public static int ToInt(this long v) => (int)v;
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 = System.IO.File.ReadAllLines("Input.txt");
static public string ReadLine() {
if (cursorLine == cin.Length)
cout = "Out";
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;
using System.Collections.Generic;
using static Exter;
using System.Linq;
using System.Numerics;
#if DEBUG
#else
using console = System.Console;
#endif
public class App {
public static void Main(string[] args) {
var v = readarr[0];
for (int i = 0; i < 50000; i++) {
if (Math.Floor(i * 1.08) == v) {
cout = i;
break;
}
if (i == 49999)
cout = ":(";
}
}
public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static long GcdRecursive(long a, long b) {
if (b == 0)
return a;
return GcdRecursive(b, a % b);
}
}
public class RollingHash {
long[] h;
long m = 2147483647;
int b = 524287;
Power baser;
public RollingHash(string s) {
baser = new Power(b);
h = new long[s.Length];
h[0] = 0;
for (int i = 1; i < s.Length; i++) {
h[i] = (h[i - 1] * b + s[i]) % m;
}
}
public long Calc(int l, int r) {
cout = h[r];
cout = h[l] * baser.GetEntry(r - l - 1);
return 0;
}
}
public class PriorityQueue<T> : IEnumerable<T>
where T : IComparable {
List<T> buffer = new List<T>();
static void PushHeap(List<T> array, T elem) {
int n = array.Count;
array.Add(elem);
while (n != 0) {
int i = (n - 1) / 2;
if (array[n].CompareTo(array[i]) < 0) {
T tmp = array[n];
array[n] = array[i];
array[i] = tmp;
}
n = i;
}
}
static void PopHeap(List<T> array) {
int n = array.Count - 1;
array[0] = array[n];
array.RemoveAt(array.Count - 1);
for (int i = 0, j; (j = 2 * i + 1) < n;) {
if ((j != n - 1) && (array[j].CompareTo(array[j + 1]) > 0))
j++;
if (array[i].CompareTo(array[j]) > 0) {
T tmp = array[j];
array[j] = array[i];
array[i] = tmp;
}
i = j;
}
}
public int Count {
get { return buffer.Count; }
}
public void Push(T elem) { PushHeap(this.buffer, elem); }
public T Peek() { return buffer[0]; }
public T Pop() {
T a = buffer[0];
PopHeap(this.buffer);
return a;
}
public IEnumerator<T> GetEnumerator() {
var v = new List<T>(buffer);
while (v.Count != 0) {
yield return v[0];
PopHeap(v);
}
}
IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
}
public class Power {
public int Base;
private List<long> Value = new List<long>();
public Power(int v) {
if (v == 1)
new ArgumentOutOfRangeException();
long prev = -1;
long g = v;
Base = v;
while (g > prev) {
Value.Add(g);
prev = g;
g *= g;
}
}
public long GetEntry(int exponent) {
long s = 1;
for (int i = 0; (1 << i) <= exponent; i++) {
if ((exponent & (1 << i)) != 0) {
s *= Value[i];
}
}
return s;
}
}
public static class Exter {
public static IEnumerable<long> PrimeFactors(long n) {
int i = 2;
long tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
public class LoopArray<T> {
public readonly int Length;
private T[] arr;
public LoopArray(int Capacity) { Length = Capacity; }
public LoopArray(T[] ar) {
arr = new T[ar.Length];
Array.Copy(ar, arr, ar.Length);
}
}
public class Point {
public Point(int cx, int cy) {
x = cx;
y = cy;
}
public int x;
public int y;
}
public static IEnumerable<Result>
ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b,
Func<T1, T2, Result> f) {
foreach (var v in a) {
foreach (var w in b)
yield return f(v, w);
}
}
public static IEnumerable<Result>
ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b,
Func<T1, T2, Result> f, Func<T1, T2, bool> s) {
foreach (var v in a) {
foreach (var w in b)
if (s(v, w))
yield return f(v, w);
}
}
public static int ToInt(this long v) => (int)v;
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 = System.IO.File.ReadAllLines("Input.txt");
static public string ReadLine() {
if (cursorLine == cin.Length)
cout = "Out";
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
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 5, 0, 62], ["+", 0, 57, 64, 1, 0, 11, 12, 5, 0, 222], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 1,573
| 12
|
using System;
class Program {
static void Main(string[] args) {
// while (true)
//{
// 整数の入力
int N = int.Parse(Console.ReadLine());
if ((N + 1) / 13.5 - (N + 1 % 13.5) < 0.04) {
Console.WriteLine(":(");
return;
}
int X = N - (int)(N / 13.5);
Console.WriteLine(X);
//}
}
}
|
using System;
class Program {
static void Main(string[] args) {
// 整数の入力
int N = int.Parse(Console.ReadLine());
if ((N + 1) / 13.5 - ((int)((N + 1) / 13.5)) < 0.04) {
Console.WriteLine(":(");
return;
}
int X = N - (int)(N / 13.5);
Console.WriteLine(X);
}
}
|
[["+", 15, 16, 31, 16, 12, 23, 0, 74, 0, 24], ["+", 15, 16, 31, 16, 12, 23, 0, 74, 39, 199], ["+", 15, 16, 31, 16, 12, 23, 0, 74, 0, 25], ["+", 31, 16, 12, 23, 0, 74, 51, 23, 0, 24], ["+", 0, 74, 51, 23, 0, 16, 31, 23, 0, 24], ["-", 31, 16, 12, 23, 0, 16, 12, 16, 17, 109], ["+", 0, 74, 51, 23, 0, 16, 31, 23, 0, 25], ["+", 12, 23, 0, 74, 51, 23, 0, 16, 17, 85], ["+", 31, 16, 12, 23, 0, 74, 51, 23, 0, 25]]
| 8
| 90
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace AtCoder {
static class Program {
static void Main() {
//ここから
int N = IO.ReadLineToInt();
string ans = ":(";
for (int i = 1; i < N; i++) {
if (Math.Floor(i * 1.08) == N) {
ans = i.ToString();
continue;
}
}
//ここまで
Console.WriteLine(ans);
Console.ReadKey();
}
}
static class Func {
static public long mod = 1000000007;
static public void Swap<T>(ref T a, ref T b) {
T temp = a;
a = b;
b = temp;
}
static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
static public long Factorial(long a) {
return a == 1 ? a : a * Factorial(a - 1);
}
public static double ToAngle(this double radian) {
return (double)(radian * 180 / Math.PI);
}
public static double ToRadian(this double angle) {
return (double)(angle * Math.PI / 180);
}
static public long Conbination(long n, long m) {
if (m == 0)
return 1;
if (n == 0)
return 0;
return n * Conbination(n - 1, m - 1) / m;
}
static public void Factoring(long num, ref long[] vs) {
if (num == 1) {
vs[1]++;
}
for (long i = 2; i < Math.Sqrt(num); i++) {
if (num % i == 0) {
vs[i]++;
Factoring(num / i, ref vs);
}
}
vs[1]++;
}
}
static class IO {
static public string ReadLineToString() { return Console.ReadLine(); }
static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
static public List<string> ReadLineToStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> ReadLineToIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> ReadLineToLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
static public List<double> ReadLineToDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteStrings(object[] strings) {
foreach (var o in strings) {
Console.Write(o + " ");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace AtCoder {
static class Program {
static void Main() {
//ここから
int N = IO.ReadLineToInt();
string ans = ":(";
for (int X = 1; X <= N; X++) {
if (Math.Floor(X * 1.08) == N) {
ans = X.ToString();
break;
}
}
//ここまで
Console.WriteLine(ans);
Console.ReadKey();
}
}
static class Func {
static public long mod = 1000000007;
static public void Swap<T>(ref T a, ref T b) {
T temp = a;
a = b;
b = temp;
}
static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
static public long Factorial(long a) {
return a == 1 ? a : a * Factorial(a - 1);
}
public static double ToAngle(this double radian) {
return (double)(radian * 180 / Math.PI);
}
public static double ToRadian(this double angle) {
return (double)(angle * Math.PI / 180);
}
static public long Conbination(long n, long m) {
if (m == 0)
return 1;
if (n == 0)
return 0;
return n * Conbination(n - 1, m - 1) / m;
}
static public void Factoring(long num, ref long[] vs) {
if (num == 1) {
vs[1]++;
}
for (long i = 2; i < Math.Sqrt(num); i++) {
if (num % i == 0) {
vs[i]++;
Factoring(num / i, ref vs);
}
}
vs[1]++;
}
}
static class IO {
static public string ReadLineToString() { return Console.ReadLine(); }
static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
static public List<string> ReadLineToStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> ReadLineToIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> ReadLineToLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
static public List<double> ReadLineToDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteStrings(object[] strings) {
foreach (var o in strings) {
Console.Write(o + " ");
}
}
}
}
|
[["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
| 8
| 655
| 14
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace sumitomo2019 {
class Program {
static void Main(string[] args) {
// Console.SetIn(new StreamReader("input.txt"));
solve_sumitomo2019B();
}
public static void solve_sumitomo2019B() {
int n = Convert.ToInt32(Console.ReadLine());
int div = (int)Math.Floor(n / 1.08);
if (Math.Floor(div * 1.08) == n) {
Console.WriteLine(div);
} else {
Console.WriteLine(":(");
}
}
public static void solve_sumitomo2019A() {
int[] md1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int[] md2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
Console.WriteLine(md2[0] != md1[0] ? 1 : 0);
}
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace sumitomo2019 {
class Program {
static void Main(string[] args) {
// Console.SetIn(new StreamReader("input.txt"));
solve_sumitomo2019B();
}
public static void solve_sumitomo2019B() {
int n = Convert.ToInt32(Console.ReadLine());
double div = n / 1.08;
if (Math.Floor(Math.Ceiling(div) * 1.08) == n) {
Console.WriteLine(Math.Ceiling(div));
} else {
Console.WriteLine(":(");
}
}
public static void solve_sumitomo2019A() {
int[] md1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int[] md2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
Console.WriteLine(md2[0] != md1[0] ? 1 : 0);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 0, 212, 0, 74, 51, 213, 63, 214, 205, 22], ["-", 0, 212, 0, 74, 51, 213, 63, 214, 0, 131], ["-", 0, 212, 0, 74, 51, 213, 63, 214, 141, 22], ["-", 0, 212, 0, 74, 51, 213, 3, 4, 0, 24], ["-", 0, 212, 0, 74, 51, 213, 3, 4, 0, 25], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 195
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6 {
class Program {
static void Main(string[] args) {
bool ret = false;
var s = Console.ReadLine();
int X = int.Parse(s);
int min = (int)((X / 1.1));
for (; min < X; min++) {
if (getX(min) == X) {
ret = true;
break;
}
}
if (ret) {
Console.WriteLine(min);
} else {
Console.WriteLine(":(");
}
// Console.ReadLine();
}
static int getX(int def) { return (int)(def * 1.08); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6 {
class Program {
static void Main(string[] args) {
bool ret = false;
var s = Console.ReadLine();
int X = int.Parse(s);
int min = (int)((X / 1.1));
for (; min <= X; min++) {
if (getX(min) == X) {
ret = true;
break;
}
}
if (ret) {
Console.WriteLine(min);
} else {
Console.WriteLine(":(");
}
Console.ReadLine();
}
static int getX(int def) { return (int)(def * 1.08); }
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 158
| 8
|
using System;
using System.Text;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string ret = string.Empty;
double value = n / 1.08;
int[] applePie = new int[2];
int[] tax = new int[2];
applePie[0] = (int)value;
applePie[1] = (int)value + 1;
tax[0] = (int)(applePie[0] * 1.08);
tax[1] = (int)(applePie[1] * 1.08);
if (tax[0] == applePie[0]) {
ret = applePie[0].ToString();
} else if (tax[1] == applePie[1]) {
ret = applePie[1].ToString();
} else {
ret = ":(" + Environment.NewLine;
}
Console.WriteLine(ret);
}
}
|
using System;
using System.Text;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string ret = string.Empty;
double value = n / 1.08;
int[] applePie = new int[2];
int[] tax = new int[2];
applePie[0] = (int)value;
applePie[1] = (int)value + 1;
tax[0] = (int)(applePie[0] * 1.08);
tax[1] = (int)(applePie[1] * 1.08);
if (tax[0] == n) {
ret = applePie[0].ToString();
} else if (tax[1] == n) {
ret = applePie[1].ToString();
} else {
ret = ":(" + Environment.NewLine;
}
Console.WriteLine(ret);
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 57, 75, 57, 15, 16, 12, 204, 205, 22], ["-", 75, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 75, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22]]
| 8
| 200
| 10
|
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.IO;
using System.Text;
using N = System.Int32;
public class Solver {
public void Solve() {
N n = ri;
if ((n * 25) % 27 >= 3 || n % 27 == 0) {
Write(n * 25 / 27);
} else {
Write(":(");
}
}
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 StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
public Algorithm alg = new Algorithm();
private const N mod = 1000000007;
N Reverse(N n) { return Pow(n, mod - 2); }
N Mul(params N[] n) {
N p = n[0];
for (N i = 1; i < n.Length; i++) {
p = (p * n[i]) % mod;
}
return p;
}
N Pow(N n, N p) {
N t = n, q = 1;
while (p > 0) {
if (p % 2 == 1) {
q = (q * t) % mod;
}
t = (t * t) % mod;
p >>= 1;
}
return q;
}
N PowUpper(N n, N b) {
N p = 1;
while (p <= n) {
p *= b;
}
return p;
}
N Sign(N n) { return n == 0 ? 0 : n > 0 ? 1 : -1; }
N Abs(N n) { return (n > 0) ? n : -n; }
N Gcd(params N[] n) {
N p = n[0];
for (N i = 1; i < n.Length; i++) {
p = Gcd(p, n[i]);
}
return p;
}
N Gcd(N a, N b) { return (a == 0) ? b : Gcd(b % a, a); }
N Lcm(params N[] n) {
N p = n[0];
for (N i = 1; i < n.Length; i++) {
p = Lcm(p, n[i]);
}
return p;
}
N Lcm(N a, N b) { return (a / Gcd(a, b) * b) % mod; }
void Write<T>(T t) { Console.WriteLine(t.ToString()); }
void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
}
static class Program {
static public void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var solver = new Solver();
solver.Solve();
Console.Out.Flush();
}
}
public class Algorithm {
public int[] ZAlgorithm(string s) {
int[] p = new int[s.Length];
p[0] = s.Length;
int i = 1, j = 0;
while (i < s.Length) {
while (i + j < s.Length && s[j] == s[i + j])
++j;
p[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < s.Length && k + p[k] < j) {
p[i + k] = p[k];
++k;
}
i += k;
j -= k;
}
return p;
}
public List<int> SieveOfEratosthenes(int n) {
List<int> l = new List<int>();
if (n >= 2) {
l.Add(2);
}
bool[] t = new bool[(n - 1) / 2];
for (int p = 3; p <= n; p += 2) {
if (!t[(p - 3) / 2]) {
l.Add(p);
for (int q = p * p; q <= n; q += p) {
t[(q - 3) / 2] = true;
}
}
}
return l;
}
public Dictionary<int, int> PrimeFactor(int n, List<int> primetable) {
Dictionary<int, int> d = new Dictionary<int, int>();
int t = 0;
foreach (int i in primetable) {
if (n % i == 0) {
while (n % 2 == 0) {
n /= i;
t++;
}
d.Add(i, t);
}
}
if (n > 1) {
d.Add(n, 1);
}
return d;
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(IComparer<T> comparer) {
_heap = new T[128];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int type = 0) {
_heap = new T[128];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
if (_count > _heap.Length) {
var newheap = new T[_heap.Length * 2];
for (int n = 0; n < _heap.Length; n++)
newheap[n] = _heap[n];
_heap = newheap;
}
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public 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 int Integer() { return (int)Long(); }
public double Double() { return double.Parse(Scan()); }
}
|
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.IO;
using System.Text;
using N = System.Int32;
public class Solver {
public void Solve() {
N n = ri;
for (int i = 1; i <= n; i++) {
if (i * 27 / 25 == n) {
Write(i);
return;
}
}
Write(":(");
}
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 StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
public Algorithm alg = new Algorithm();
private const N mod = 1000000007;
N Reverse(N n) { return Pow(n, mod - 2); }
N Mul(params N[] n) {
N p = n[0];
for (N i = 1; i < n.Length; i++) {
p = (p * n[i]) % mod;
}
return p;
}
N Pow(N n, N p) {
N t = n, q = 1;
while (p > 0) {
if (p % 2 == 1) {
q = (q * t) % mod;
}
t = (t * t) % mod;
p >>= 1;
}
return q;
}
N PowUpper(N n, N b) {
N p = 1;
while (p <= n) {
p *= b;
}
return p;
}
N Sign(N n) { return n == 0 ? 0 : n > 0 ? 1 : -1; }
N Abs(N n) { return (n > 0) ? n : -n; }
N Gcd(params N[] n) {
N p = n[0];
for (N i = 1; i < n.Length; i++) {
p = Gcd(p, n[i]);
}
return p;
}
N Gcd(N a, N b) { return (a == 0) ? b : Gcd(b % a, a); }
N Lcm(params N[] n) {
N p = n[0];
for (N i = 1; i < n.Length; i++) {
p = Lcm(p, n[i]);
}
return p;
}
N Lcm(N a, N b) { return (a / Gcd(a, b) * b) % mod; }
void Write<T>(T t) { Console.WriteLine(t.ToString()); }
void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
}
static class Program {
static public void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var solver = new Solver();
solver.Solve();
Console.Out.Flush();
}
}
public class Algorithm {
public int[] ZAlgorithm(string s) {
int[] p = new int[s.Length];
p[0] = s.Length;
int i = 1, j = 0;
while (i < s.Length) {
while (i + j < s.Length && s[j] == s[i + j])
++j;
p[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < s.Length && k + p[k] < j) {
p[i + k] = p[k];
++k;
}
i += k;
j -= k;
}
return p;
}
public List<int> SieveOfEratosthenes(int n) {
List<int> l = new List<int>();
if (n >= 2) {
l.Add(2);
}
bool[] t = new bool[(n - 1) / 2];
for (int p = 3; p <= n; p += 2) {
if (!t[(p - 3) / 2]) {
l.Add(p);
for (int q = p * p; q <= n; q += p) {
t[(q - 3) / 2] = true;
}
}
}
return l;
}
public Dictionary<int, int> PrimeFactor(int n, List<int> primetable) {
Dictionary<int, int> d = new Dictionary<int, int>();
int t = 0;
foreach (int i in primetable) {
if (n % i == 0) {
while (n % 2 == 0) {
n /= i;
t++;
}
d.Add(i, t);
}
}
if (n > 1) {
d.Add(n, 1);
}
return d;
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(IComparer<T> comparer) {
_heap = new T[128];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int type = 0) {
_heap = new T[128];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
if (_count > _heap.Length) {
var newheap = new T[_heap.Length * 2];
for (int n = 0; n < _heap.Length; n++)
newheap[n] = _heap[n];
_heap = newheap;
}
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public 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 int Integer() { return (int)Long(); }
public double Double() { return double.Parse(Scan()); }
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 15, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 31, 16, 31, 16, 31, 23, 0, 16, 17, 48], ["-", 31, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 109], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 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, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 2,057
| 43
|
using System;
using System.Linq;
namespace kakomon {
class Program {
static void Main(string[] args) { sumitb2019_c(); }
static void sumitb2019_c() {
// C - 100 to 105
long x = long.Parse(Console.ReadLine());
long min_pcs = (long)(x / 105);
long max_pcs = (long)(x / 100);
bool succ = false;
for (long k = min_pcs; k <= max_pcs; k++) {
long rest = x - k * 100;
Console.WriteLine(string.Format("{0}, {1}, {2}", k, rest, k * 5));
if (rest <= k * 5) {
succ = true;
break;
}
}
if (succ)
Console.WriteLine(1);
else
Console.WriteLine(0);
}
}
}
|
using System;
using System.Linq;
namespace kakomon {
class Program {
static void Main(string[] args) { sumitb2019_c(); }
static void sumitb2019_c() {
// C - 100 to 105
long x = long.Parse(Console.ReadLine());
long min_pcs = (long)(x / 105);
long max_pcs = (long)(x / 100);
bool succ = false;
for (long k = min_pcs; k <= max_pcs; k++) {
long rest = x - k * 100;
if (rest <= k * 5) {
succ = true;
break;
}
}
if (succ)
Console.WriteLine(1);
else
Console.WriteLine(0);
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 164
| 22
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
using ll = System.Int64;
public class Contest {
static void Swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static void Swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
Swap1(ref a, ref b);
} // b の方が小さければ交換
static bool Chmin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
} // b の方が小さければ a を更新
static bool Chmax<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
} // b の方が大きければ a を更新
static T[][] InitMat<T>(long len1, long len2, T val) {
T[][] m = new T[len1][];
for (int i = 0; i < m.Length; i++)
m[i] = Enumerable.Repeat(val, (int)len2).ToArray();
return m;
}
static T[][][] InitMat<T>(long len1, long len2, long len3, T val) {
T[][][] m = new T[len1][][];
for (int i = 0; i < m.Length; i++)
m[i] = InitMat(len2, len3, val);
return m;
}
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public static void Main() { Solve_C(); }
public static void Solve_A() {
long n1, m1;
long n2, m2;
MyIO.ReadMulti(out n1, out m1);
MyIO.ReadMulti(out n2, out m2);
long ans = 0;
if (n1 == n2) {
ans = 0;
} else {
ans = 1;
}
MyIO.WriteMulti(ans);
}
public static void Solve_B() {
long n;
MyIO.ReadMulti(out n);
ll a = (ll)(n / 1.08) - 2;
string ans = ":(";
if ((ll)(a * 1.08) == n)
ans = a.ToString();
if ((ll)((a + 1) * 1.08) == n)
ans = (a + 1).ToString();
if ((ll)((a + 2) * 1.08) == n)
ans = (a + 2).ToString();
if ((ll)((a + 3) * 1.08) == n)
ans = (a + 3).ToString();
if ((ll)((a + 4) * 1.08) == n)
ans = (a + 4).ToString();
MyIO.WriteMulti(ans);
}
public static void Solve_C() {
long n;
MyIO.ReadMulti(out n);
ll c5 = (n % 100) / 5;
ll c0 = (n % 100) % 5 == 0 ? 0 : 1;
long ans = 0;
if (c5 + c0 < n / 100)
ans = 1;
MyIO.WriteMulti(ans);
}
public static void Solve_D() {
long n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_E() {
long n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_F() {
long n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
}
#region MyIO
public struct VT<T, U> {
public T Item1;
public U Item2;
public VT(T a, U b) {
Item1 = a;
Item2 = b;
}
}
public struct VT<T, U, V> {
public T Item1;
public U Item2;
public V Item3;
public VT(T a, U b, V c) {
Item1 = a;
Item2 = b;
Item3 = c;
}
}
public struct VT<T, U, V, W> {
public T Item1;
public U Item2;
public V Item3;
public W Item4;
public VT(T a, U b, V c, W d) {
Item1 = a;
Item2 = b;
Item3 = c;
Item4 = d;
}
}
public class Printer : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Printer(System.IO.Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(System.IO.Stream stream, Encoding encoding)
: base(stream, encoding) {}
}
public static class MyIO {
private static char[] splitter = new char[] { ' ' };
private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
private static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] ReadMulti<T>(out T a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(ar[0]);
return ar;
}
public static string[] ReadMulti<T, U>(out T a, out U b) {
var ar = ReadMulti<T>(out a);
b = cv<U>(ar[1]);
return ar;
}
public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
var ar = ReadMulti<T, U>(out a, out b);
c = cv<V>(ar[2]);
return ar;
}
public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c,
out W d) {
var ar = ReadMulti<T, U, V>(out a, out b, out c);
d = cv<W>(ar[3]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c,
out W d, out X e) {
var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(ar[4]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e,
out Y f) {
var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(ar[5]);
return ar;
}
public static string[] ReadArray<T>(out T[] a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = ar.Select(cv<T>).ToArray();
return ar;
}
public static string[][] ReadLines<T>(long n, out T[] a) {
a = new T[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadMulti(out a[i]);
return arr;
}
public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) {
a = new VT<T, U>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
arr[i] = ReadMulti(out o, out p);
a[i] = new VT<T, U>(o, p);
}
return arr;
}
public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) {
a = new VT<T, U, V>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
arr[i] = ReadMulti(out o, out p, out q);
a[i] = new VT<T, U, V>(o, p, q);
}
return arr;
}
public static string[][] ReadLines<T, U, V, W>(long n,
out VT<T, U, V, W>[] a) {
a = new VT<T, U, V, W>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
arr[i] = ReadMulti(out o, out p, out q, out r);
a[i] = new VT<T, U, V, W>(o, p, q, r);
}
return arr;
}
public static string[][] ReadMatrix<T>(long n, out T[][] a) {
a = new T[n][];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadArray(out a[i]);
return arr;
}
private static void wwp(Action act) {
var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}"
: "{0}";
public static void WriteMulti(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length; i++) {
string fs = wfm(a[i].GetType()) +
((i < a.Length - 1) ? " " : Environment.NewLine);
Console.Write(fs, a[i]);
}
});
}
public static void WriteArray<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T));
string fs1 = fs + " ";
string fs2 = fs + Environment.NewLine;
for (int i = 0; i < a.Length; i++)
Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]);
});
}
public static void WriteLines<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T)) + Environment.NewLine;
foreach (T x in a)
Console.Write(fs, x);
});
}
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
using ll = System.Int64;
public class Contest {
static void Swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static void Swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
Swap1(ref a, ref b);
} // b の方が小さければ交換
static bool Chmin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
} // b の方が小さければ a を更新
static bool Chmax<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
} // b の方が大きければ a を更新
static T[][] InitMat<T>(long len1, long len2, T val) {
T[][] m = new T[len1][];
for (int i = 0; i < m.Length; i++)
m[i] = Enumerable.Repeat(val, (int)len2).ToArray();
return m;
}
static T[][][] InitMat<T>(long len1, long len2, long len3, T val) {
T[][][] m = new T[len1][][];
for (int i = 0; i < m.Length; i++)
m[i] = InitMat(len2, len3, val);
return m;
}
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public static void Main() { Solve_C(); }
public static void Solve_A() {
long n1, m1;
long n2, m2;
MyIO.ReadMulti(out n1, out m1);
MyIO.ReadMulti(out n2, out m2);
long ans = 0;
if (n1 == n2) {
ans = 0;
} else {
ans = 1;
}
MyIO.WriteMulti(ans);
}
public static void Solve_B() {
long n;
MyIO.ReadMulti(out n);
ll a = (ll)(n / 1.08) - 2;
string ans = ":(";
if ((ll)(a * 1.08) == n)
ans = a.ToString();
if ((ll)((a + 1) * 1.08) == n)
ans = (a + 1).ToString();
if ((ll)((a + 2) * 1.08) == n)
ans = (a + 2).ToString();
if ((ll)((a + 3) * 1.08) == n)
ans = (a + 3).ToString();
if ((ll)((a + 4) * 1.08) == n)
ans = (a + 4).ToString();
MyIO.WriteMulti(ans);
}
public static void Solve_C() {
long n;
MyIO.ReadMulti(out n);
ll c5 = (n % 100) / 5;
ll c0 = (n % 100) % 5 == 0 ? 0 : 1;
long ans = 0;
if ((c5 + c0) <= (ll)(n / 100))
ans = 1;
MyIO.WriteMulti(ans);
}
public static void Solve_D() {
long n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_E() {
long n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_F() {
long n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
}
#region MyIO
public struct VT<T, U> {
public T Item1;
public U Item2;
public VT(T a, U b) {
Item1 = a;
Item2 = b;
}
}
public struct VT<T, U, V> {
public T Item1;
public U Item2;
public V Item3;
public VT(T a, U b, V c) {
Item1 = a;
Item2 = b;
Item3 = c;
}
}
public struct VT<T, U, V, W> {
public T Item1;
public U Item2;
public V Item3;
public W Item4;
public VT(T a, U b, V c, W d) {
Item1 = a;
Item2 = b;
Item3 = c;
Item4 = d;
}
}
public class Printer : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Printer(System.IO.Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(System.IO.Stream stream, Encoding encoding)
: base(stream, encoding) {}
}
public static class MyIO {
private static char[] splitter = new char[] { ' ' };
private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
private static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] ReadMulti<T>(out T a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(ar[0]);
return ar;
}
public static string[] ReadMulti<T, U>(out T a, out U b) {
var ar = ReadMulti<T>(out a);
b = cv<U>(ar[1]);
return ar;
}
public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
var ar = ReadMulti<T, U>(out a, out b);
c = cv<V>(ar[2]);
return ar;
}
public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c,
out W d) {
var ar = ReadMulti<T, U, V>(out a, out b, out c);
d = cv<W>(ar[3]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c,
out W d, out X e) {
var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(ar[4]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e,
out Y f) {
var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(ar[5]);
return ar;
}
public static string[] ReadArray<T>(out T[] a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = ar.Select(cv<T>).ToArray();
return ar;
}
public static string[][] ReadLines<T>(long n, out T[] a) {
a = new T[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadMulti(out a[i]);
return arr;
}
public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) {
a = new VT<T, U>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
arr[i] = ReadMulti(out o, out p);
a[i] = new VT<T, U>(o, p);
}
return arr;
}
public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) {
a = new VT<T, U, V>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
arr[i] = ReadMulti(out o, out p, out q);
a[i] = new VT<T, U, V>(o, p, q);
}
return arr;
}
public static string[][] ReadLines<T, U, V, W>(long n,
out VT<T, U, V, W>[] a) {
a = new VT<T, U, V, W>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
arr[i] = ReadMulti(out o, out p, out q, out r);
a[i] = new VT<T, U, V, W>(o, p, q, r);
}
return arr;
}
public static string[][] ReadMatrix<T>(long n, out T[][] a) {
a = new T[n][];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadArray(out a[i]);
return arr;
}
private static void wwp(Action act) {
var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}"
: "{0}";
public static void WriteMulti(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length; i++) {
string fs = wfm(a[i].GetType()) +
((i < a.Length - 1) ? " " : Environment.NewLine);
Console.Write(fs, a[i]);
}
});
}
public static void WriteArray<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T));
string fs1 = fs + " ";
string fs2 = fs + Environment.NewLine;
for (int i = 0; i < a.Length; i++)
Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]);
});
}
public static void WriteLines<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T)) + Environment.NewLine;
foreach (T x in a)
Console.Write(fs, x);
});
}
}
#endregion
|
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 39, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 0, 25], ["+", 0, 57, 15, 16, 12, 74, 51, 23, 0, 24], ["+", 0, 57, 15, 16, 12, 74, 51, 23, 0, 25]]
| 8
| 2,591
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sumitb2019_c {
class Program {
static void Main(string[] args) {
int X = 99998;
int XS = X;
int[] S = new int[] { 100, 101, 102, 103, 104, 105 };
bool b = false;
for (int i = 0; i <= X / S[0]; i++) {
for (int j = 0; j <= (X - (S[0] * i)) / S[1]; j++) {
for (int k = 0; k <= (X - (S[0] * i) - (S[1] * j)) / S[2]; k++) {
for (int l = 0;
l <= (X - (S[0] * i) - (S[1] * j) - (S[2] * k)) / S[3]; l++) {
for (int m = 0;
m <=
(X - (S[0] * i) - (S[1] * j) - (S[2] * k) - (S[3] * l)) / S[4];
m++) {
int x1 = 100 * i + 101 * j + 102 * k + 103 * l + 104 * m;
int n = (X - x1) / S[5];
int xr = x1 + (S[5] * n);
if (xr == X) {
b = true;
break;
}
}
if (b)
break;
}
if (b)
break;
}
if (b)
break;
}
if (b)
break;
}
Console.WriteLine(b ? "1" : "0");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sumitb2019_c {
class Program {
static void Main(string[] args) {
int X = int.Parse(Console.ReadLine());
int[] S = new int[] { 100, 101, 102, 103, 104, 105 };
bool b = false;
for (int i = 0; i <= X / S[0]; i++) {
for (int j = 0; j <= (X - (S[0] * i)) / S[1]; j++) {
for (int k = 0; k <= (X - (S[0] * i) - (S[1] * j)) / S[2]; k++) {
for (int l = 0;
l <= (X - (S[0] * i) - (S[1] * j) - (S[2] * k)) / S[3]; l++) {
for (int m = 0;
m <=
(X - (S[0] * i) - (S[1] * j) - (S[2] * k) - (S[3] * l)) / S[4];
m++) {
int x1 = 100 * i + 101 * j + 102 * k + 103 * l + 104 * m;
int n = (X - x1) / S[5];
int xr = x1 + (S[5] * n);
if (xr == X) {
b = true;
break;
}
}
if (b)
break;
}
if (b)
break;
}
if (b)
break;
}
if (b)
break;
}
Console.WriteLine(b ? "1" : "0");
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 391
| 14
|
using System;
public class Program {
private static int Check(int price, int[] source, int[] count) {
return source[0] * count[0] + source[1] * count[1] + source[2] * count[2] +
source[3] * count[3] + source[4] * count[4] + source[5] * count[5];
}
private static int Sum(int[] a) {
int sum = 0;
foreach (int n in a) {
sum += n;
}
return sum;
}
public static void Main() {
int[] P = new int[6] { 100, 101, 102, 103, 104, 105 };
int price = int.Parse(Console.ReadLine());
int count = (int)(price / 100);
int[] c = new int[6] { 0, 0, 0, 0, 0, 0 };
for (c[0] = 0; c[0] < count; c[0]++) {
for (c[1] = 0; c[1] < count; c[1]++) {
for (c[2] = 0; c[2] < count; c[2]++) {
for (c[3] = 0; c[3] < count; c[3]++) {
for (c[4] = 0; c[4] < count; c[4]++) {
for (c[5] = 0; c[5] < count; c[5]++) {
if (price == Check(price, P, c)) {
Console.WriteLine(1);
return;
}
}
}
}
}
}
}
Console.WriteLine(0);
}
}
|
using System;
public class Program {
private static bool Check(int price, int[] source, int[] count) {
return price == source[0] * count[0] + source[1] * count[1] +
source[2] * count[2] + source[3] * count[3] +
source[4] * count[4] + source[5] * count[5];
}
private static int Sum(int[] a) {
int sum = 0;
foreach (int n in a) {
sum += n;
}
return sum;
}
public static void Main() {
int[] P = new int[6] { 100, 101, 102, 103, 104, 105 };
int price = int.Parse(Console.ReadLine());
int count = (int)(price / 100) + 1;
int[] c = new int[6] { 0, 0, 0, 0, 0, 0 };
for (c[0] = 0; c[0] < count; c[0]++) {
for (c[1] = 0; c[1] < count; c[1]++) {
for (c[2] = 0; c[2] < count; c[2]++) {
for (c[3] = 0; c[3] < count; c[3]++) {
for (c[4] = 0; c[4] < count; c[4]++) {
for (c[5] = 0; c[5] < count; c[5]++) {
if (Check(price, P, c)) {
Console.WriteLine(1);
return;
}
}
}
}
}
}
}
Console.WriteLine(0);
}
}
|
[["-", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 17, 60], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60]]
| 8
| 379
| 8
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace MSBPC2019 {
class C {
static void Main(string[] args) {
long X = long.Parse(Console.ReadLine());
int[] price = new int[] { 100, 101, 102, 103, 104, 105 };
List<long> list = new List<long>();
for (int bit = 0; bit <= (1 << 6); bit++) {
long sum = 0;
for (int i = 0; i < 6; i++) {
if ((bit & (1 << i)) > 0) {
sum += price[i];
}
}
list.Add(sum);
}
for (int i = 0; i < list.Count; i++) {
if (list[i] != 0 && X % list[i] == 0) {
Console.WriteLine(1);
return;
}
}
Console.WriteLine(0);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace MSBPC2019 {
class C {
static void Main(string[] args) {
long X = long.Parse(Console.ReadLine());
int[] price = new int[] { 100, 101, 102, 103, 104, 105 };
List<long> list = new List<long>();
for (int bit = 0; bit < (1 << 6); bit++) {
long sum = 0;
for (int i = 0; i < 6; i++) {
if ((bit & (1 << i)) > 0) {
sum += price[i];
}
}
list.Add(sum);
}
// Console.WriteLine(string.Join(",", list));
// Console.WriteLine(list.Count);
for (int i = 0; i < list.Count; i++) {
if (list[i] != 0 && (X % list[i] == 0 || (X % list[i]) % 100 == 0)) {
Console.WriteLine(1);
return;
}
}
Console.WriteLine(0);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 106], ["+", 0, 16, 12, 16, 31, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 17, 109], ["+", 31, 16, 31, 23, 0, 16, 12, 204, 205, 22], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 16, 12, 16, 31, 16, 31, 23, 0, 25], ["+", 12, 23, 0, 16, 12, 16, 31, 16, 17, 109], ["+", 12, 23, 0, 16, 12, 16, 31, 16, 12, 203], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 60], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
| 8
| 210
| 17
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;
public class C {
public static void Main() => (new Solver()).Solve();
}
public class Solver {
public void Solve() {
int X = GetInt();
int q = X / 100;
int r = X % 100;
int must = r / 5 + 1;
WriteLine((must <= q) ? 1 : 0);
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() => int.Parse(getArg());
public static long GetLong() => long.Parse(getArg());
public static double GetDouble() => double.Parse(getArg());
public static string GetString() => getArg();
public static char GetChar() => getArg()[0];
public static int[] GetInts(int N) =>
Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
public static long[] GetLongs(int N) =>
Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
public static double[] GetDoubles(int N) =>
Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
public static string[] GetStrings(int N) =>
Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}
public static class MyUtil {
public static void chmax<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) < 0)
x = y;
}
public static void chmin<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) > 0)
x = y;
}
public static void swap<T>(ref T x, ref T y) {
T tmp = x;
x = y;
y = tmp;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;
public class C {
public static void Main() => (new Solver()).Solve();
}
public class Solver {
public void Solve() {
int X = GetInt();
int q = X / 100;
int r = X % 100;
int must = r / 5;
if (r % 5 != 0)
must++;
WriteLine((must <= q) ? 1 : 0);
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() => int.Parse(getArg());
public static long GetLong() => long.Parse(getArg());
public static double GetDouble() => double.Parse(getArg());
public static string GetString() => getArg();
public static char GetChar() => getArg()[0];
public static int[] GetInts(int N) =>
Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
public static long[] GetLongs(int N) =>
Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
public static double[] GetDoubles(int N) =>
Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
public static string[] GetStrings(int N) =>
Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}
public static class MyUtil {
public static void chmax<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) < 0)
x = y;
}
public static void chmin<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) > 0)
x = y;
}
public static void swap<T>(ref T x, ref T y) {
T tmp = x;
x = y;
y = tmp;
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29]]
| 8
| 524
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using Extensions;
using static System.Math;
using static Extensions.MathExtension;
using static Extensions.ConsoleInputExtension;
using static Extensions.ConsoleOutputExtension;
class Solver {
public void Solve() {
// Solve Code Here
int N = Cin;
var dp = new bool[N + 1, 7];
for (int i = 0; i < 7; i++)
dp[0, i] = true;
for (int i = 1; i < 7; i++) {
for (int n = (99 + i); n <= N; n++) {
dp[n, i] =
dp[n - (99 + i), i] || dp[n - (99 + i), i - 1] || dp[n, i - 1];
}
}
Coutln(dp[N, 6] ? 1 : 0);
}
// Other Functions Here
}
// Other Classes Here
#if !DEBUG
class EntryPoint {
static void Main(string[] args) {
new Solver().Solve();
Flush();
}
}
#endif
class PriorityQueue<T> {
private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>();
public int Count { get; private set; } = 0;
public PriorityQueue() {
_list.Add(null);
_list.Add(null);
_list.Add(null);
}
public void Push(T item, int priority) {
var itemIndex = Count++;
_list[itemIndex] = Tuple.Create(priority, item);
while (_list.Count < Count + 2)
_list.Add(null);
int parentIndex;
while ((parentIndex = GetParentIndex(itemIndex)) != -1 &&
priority > (_list[parentIndex]?.Item1 ?? int.MaxValue)) {
Swap(itemIndex, parentIndex);
itemIndex = parentIndex;
}
}
private int GetParentIndex(int index) {
if (index == 0)
return -1;
return ((index + 1) >> 1) - 1;
}
private Tuple<int, int> GetChildrenIndex(int index) {
var item2 = (index + 1) << 1;
var item1 = item2 - 1;
return item2 >= _list.Count ? null : Tuple.Create(item1, item2);
}
public T Pop() {
if (_list.Count <= 0 || _list[0] == null)
throw new IndexOutOfRangeException();
var item = _list[0].Item2;
_list[0] = null;
Tuple<int, int> childrenIndex;
int index = 0;
while ((childrenIndex = GetChildrenIndex(index)) != null &&
(_list[childrenIndex.Item1] != null ||
_list[childrenIndex.Item2] != null)) {
if ((_list[childrenIndex.Item1]?.Item1 ?? int.MaxValue) >
(_list[childrenIndex.Item2]?.Item1 ?? int.MinValue)) {
_list[index] = _list[childrenIndex.Item1];
_list[childrenIndex.Item1] = null;
index = childrenIndex.Item1;
} else {
_list[index] = _list[childrenIndex.Item2];
_list[childrenIndex.Item2] = null;
index = childrenIndex.Item2;
}
}
Count--;
return item;
}
public T Peek() { return _list[0].Item2; }
private void Swap(int index1, int index2) {
var tmp = _list[index1];
_list[index1] = _list[index2];
_list[index2] = tmp;
}
}
struct Rational {
private long _numerator;
private long _denominator;
public long Numerator => _numerator;
public long Denominator => _denominator;
public Rational(long numerator, long denominator) {
var gcd = GCD(numerator, denominator);
_numerator = numerator / gcd;
_denominator = denominator / gcd;
}
public static Rational operator +(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator +
b._numerator * a._denominator,
a._denominator * b._denominator);
}
public static Rational operator -(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator -
b._numerator * a._denominator,
a._denominator * b._denominator);
}
public static Rational operator *(Rational a, Rational b) {
return new Rational(a._numerator * b._numerator,
a._denominator * b._denominator);
}
public static Rational operator /(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator,
a._denominator * b._numerator);
}
public static explicit operator Rational(int i) { return new Rational(i, 1); }
public static explicit operator Rational(long l) {
return new Rational(l, 1);
}
public static explicit operator Rational(double d) {
long denominator = 1;
while (d % 1 != 0) {
denominator *= 2;
d *= 2;
}
return new Rational((long)d, denominator);
}
public static explicit operator Rational(float f) {
long denominator = 1;
while (f % 1 != 0) {
denominator *= 2;
f *= 2;
}
return new Rational((long)f, denominator);
}
}
struct ModInt {
public long Value { get; }
public static long Mod { get; set; } = 1000000000L + 7;
public ModInt(long l) {
long value = l % Mod;
while (value < 0)
value += Mod;
Value = value % Mod;
}
public static implicit operator long(ModInt m) { return m.Value; }
public static explicit operator ModInt(long l) { return new ModInt(l); }
public static ModInt operator +(ModInt a, ModInt b) {
return new ModInt(a.Value + b.Value);
}
public static ModInt operator -(ModInt a, ModInt b) {
return new ModInt(a.Value - b.Value);
}
public static ModInt operator *(ModInt a, ModInt b) {
return new ModInt(a.Value * b.Value);
}
public static ModInt operator /(ModInt a, ModInt b) {
return new ModInt(a * b.Inverse());
}
public override string ToString() { return Value.ToString(); }
}
static class ModIntMath {
public static ModInt Pow(this ModInt a, ModInt b) {
var pow = b.Value;
var m = a;
ModInt ans = new ModInt(1);
while (pow != 0) {
if ((pow & 1) == 1) {
ans *= m;
}
pow >>= 1;
m *= m;
}
return ans;
}
public static ModInt Inverse(this ModInt m) {
return m.Pow((ModInt)(ModInt.Mod - 2));
}
}
class UnionFind {
private readonly int[] _array;
public UnionFind(int N) {
_array = new int[N];
for (int i = 0; i < N; i++) {
_array[i] = i;
}
}
public int GetRootNode(int n) {
if (_array[n] == n)
return n;
return _array[n] = GetRootNode(_array[n]);
}
public void UnionGroup(int a, int b) {
var rootA = GetRootNode(a);
var rootB = GetRootNode(b);
if (rootA == rootB)
return;
_array[rootA] = rootB;
}
public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b);
public bool IsRoot(int n) => _array[n] == n;
}
namespace Extensions {
public class ConsoleInputExtension {
private static readonly ConsoleInputExtension _cin =
new ConsoleInputExtension();
public static ConsoleInputExtension Cin => _cin;
private static readonly Queue<string> _inputQueue = new Queue<string>();
private ConsoleInputExtension() {}
public static implicit operator string(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return _inputQueue.Dequeue();
}
public static implicit operator int(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return int.Parse(_inputQueue.Dequeue());
}
public static implicit operator long(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return long.Parse(_inputQueue.Dequeue());
}
public static implicit operator float(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return float.Parse(_inputQueue.Dequeue());
}
public static implicit operator double(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return double.Parse(_inputQueue.Dequeue());
}
}
public static class ConsoleOutputExtension {
private static StringBuilder _builder = new StringBuilder();
public static void Cout(object o) { _builder.Append(o); }
public static void CoutF(object o) {
_builder.Append(o);
Flush();
}
public static void Coutln(object o) {
_builder.Append(o);
_builder.Append('\n');
}
public static void Coutln() { _builder.Append('\n'); }
public static void CoutlnF(object o) {
_builder.Append(o);
_builder.Append('\n');
Flush();
}
public static void Flush() {
Console.Write(_builder.ToString());
_builder.Clear();
}
}
public static class MathExtension {
//最小公倍数
public static int LCM(int num1, int num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
public static long LCM(long num1, long num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
//最大公約数
public static int GCD(int num1, int num2) {
int a = Math.Max(num1, num2);
int b = Math.Min(num1, num2);
int mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
public static long GCD(long num1, long num2) {
long a = Math.Max(num1, num2);
long b = Math.Min(num1, num2);
long mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
}
public 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;
using System.Net.NetworkInformation;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using Extensions;
using static System.Math;
using static Extensions.MathExtension;
using static Extensions.ConsoleInputExtension;
using static Extensions.ConsoleOutputExtension;
class Solver {
public void Solve() {
// Solve Code Here
int N = Cin;
var dp = new bool[N + 1, 7];
for (int i = 0; i < 7; i++)
dp[0, i] = true;
for (int i = 1; i < 7; i++) {
for (int n = 1; n <= N; n++) {
if (n >= 99 + i)
dp[n, i] = dp[n - (99 + i), i] || dp[n, i - 1];
else
dp[n, i] = dp[n, i - 1];
}
}
Coutln(dp[N, 6] ? 1 : 0);
}
// Other Functions Here
}
// Other Classes Here
#if !DEBUG
class EntryPoint {
static void Main(string[] args) {
new Solver().Solve();
Flush();
}
}
#endif
class PriorityQueue<T> {
private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>();
public int Count { get; private set; } = 0;
public PriorityQueue() {
_list.Add(null);
_list.Add(null);
_list.Add(null);
}
public void Push(T item, int priority) {
var itemIndex = Count++;
_list[itemIndex] = Tuple.Create(priority, item);
while (_list.Count < Count + 2)
_list.Add(null);
int parentIndex;
while ((parentIndex = GetParentIndex(itemIndex)) != -1 &&
priority > (_list[parentIndex]?.Item1 ?? int.MaxValue)) {
Swap(itemIndex, parentIndex);
itemIndex = parentIndex;
}
}
private int GetParentIndex(int index) {
if (index == 0)
return -1;
return ((index + 1) >> 1) - 1;
}
private Tuple<int, int> GetChildrenIndex(int index) {
var item2 = (index + 1) << 1;
var item1 = item2 - 1;
return item2 >= _list.Count ? null : Tuple.Create(item1, item2);
}
public T Pop() {
if (_list.Count <= 0 || _list[0] == null)
throw new IndexOutOfRangeException();
var item = _list[0].Item2;
_list[0] = null;
Tuple<int, int> childrenIndex;
int index = 0;
while ((childrenIndex = GetChildrenIndex(index)) != null &&
(_list[childrenIndex.Item1] != null ||
_list[childrenIndex.Item2] != null)) {
if ((_list[childrenIndex.Item1]?.Item1 ?? int.MaxValue) >
(_list[childrenIndex.Item2]?.Item1 ?? int.MinValue)) {
_list[index] = _list[childrenIndex.Item1];
_list[childrenIndex.Item1] = null;
index = childrenIndex.Item1;
} else {
_list[index] = _list[childrenIndex.Item2];
_list[childrenIndex.Item2] = null;
index = childrenIndex.Item2;
}
}
Count--;
return item;
}
public T Peek() { return _list[0].Item2; }
private void Swap(int index1, int index2) {
var tmp = _list[index1];
_list[index1] = _list[index2];
_list[index2] = tmp;
}
}
struct Rational {
private long _numerator;
private long _denominator;
public long Numerator => _numerator;
public long Denominator => _denominator;
public Rational(long numerator, long denominator) {
var gcd = GCD(numerator, denominator);
_numerator = numerator / gcd;
_denominator = denominator / gcd;
}
public static Rational operator +(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator +
b._numerator * a._denominator,
a._denominator * b._denominator);
}
public static Rational operator -(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator -
b._numerator * a._denominator,
a._denominator * b._denominator);
}
public static Rational operator *(Rational a, Rational b) {
return new Rational(a._numerator * b._numerator,
a._denominator * b._denominator);
}
public static Rational operator /(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator,
a._denominator * b._numerator);
}
public static explicit operator Rational(int i) { return new Rational(i, 1); }
public static explicit operator Rational(long l) {
return new Rational(l, 1);
}
public static explicit operator Rational(double d) {
long denominator = 1;
while (d % 1 != 0) {
denominator *= 2;
d *= 2;
}
return new Rational((long)d, denominator);
}
public static explicit operator Rational(float f) {
long denominator = 1;
while (f % 1 != 0) {
denominator *= 2;
f *= 2;
}
return new Rational((long)f, denominator);
}
}
struct ModInt {
public long Value { get; }
public static long Mod { get; set; } = 1000000000L + 7;
public ModInt(long l) {
long value = l % Mod;
while (value < 0)
value += Mod;
Value = value % Mod;
}
public static implicit operator long(ModInt m) { return m.Value; }
public static explicit operator ModInt(long l) { return new ModInt(l); }
public static ModInt operator +(ModInt a, ModInt b) {
return new ModInt(a.Value + b.Value);
}
public static ModInt operator -(ModInt a, ModInt b) {
return new ModInt(a.Value - b.Value);
}
public static ModInt operator *(ModInt a, ModInt b) {
return new ModInt(a.Value * b.Value);
}
public static ModInt operator /(ModInt a, ModInt b) {
return new ModInt(a * b.Inverse());
}
public override string ToString() { return Value.ToString(); }
}
static class ModIntMath {
public static ModInt Pow(this ModInt a, ModInt b) {
var pow = b.Value;
var m = a;
ModInt ans = new ModInt(1);
while (pow != 0) {
if ((pow & 1) == 1) {
ans *= m;
}
pow >>= 1;
m *= m;
}
return ans;
}
public static ModInt Inverse(this ModInt m) {
return m.Pow((ModInt)(ModInt.Mod - 2));
}
}
class UnionFind {
private readonly int[] _array;
public UnionFind(int N) {
_array = new int[N];
for (int i = 0; i < N; i++) {
_array[i] = i;
}
}
public int GetRootNode(int n) {
if (_array[n] == n)
return n;
return _array[n] = GetRootNode(_array[n]);
}
public void UnionGroup(int a, int b) {
var rootA = GetRootNode(a);
var rootB = GetRootNode(b);
if (rootA == rootB)
return;
_array[rootA] = rootB;
}
public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b);
public bool IsRoot(int n) => _array[n] == n;
}
namespace Extensions {
public class ConsoleInputExtension {
private static readonly ConsoleInputExtension _cin =
new ConsoleInputExtension();
public static ConsoleInputExtension Cin => _cin;
private static readonly Queue<string> _inputQueue = new Queue<string>();
private ConsoleInputExtension() {}
public static implicit operator string(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return _inputQueue.Dequeue();
}
public static implicit operator int(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return int.Parse(_inputQueue.Dequeue());
}
public static implicit operator long(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return long.Parse(_inputQueue.Dequeue());
}
public static implicit operator float(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return float.Parse(_inputQueue.Dequeue());
}
public static implicit operator double(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return double.Parse(_inputQueue.Dequeue());
}
}
public static class ConsoleOutputExtension {
private static StringBuilder _builder = new StringBuilder();
public static void Cout(object o) { _builder.Append(o); }
public static void CoutF(object o) {
_builder.Append(o);
Flush();
}
public static void Coutln(object o) {
_builder.Append(o);
_builder.Append('\n');
}
public static void Coutln() { _builder.Append('\n'); }
public static void CoutlnF(object o) {
_builder.Append(o);
_builder.Append('\n');
Flush();
}
public static void Flush() {
Console.Write(_builder.ToString());
_builder.Clear();
}
}
public static class MathExtension {
//最小公倍数
public static int LCM(int num1, int num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
public static long LCM(long num1, long num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
//最大公約数
public static int GCD(int num1, int num2) {
int a = Math.Max(num1, num2);
int b = Math.Min(num1, num2);
int mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
public static long GCD(long num1, long num2) {
long a = Math.Max(num1, num2);
long b = Math.Min(num1, num2);
long mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
}
public 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);
}
}
}
}
|
[["-", 10, 198, 0, 200, 0, 212, 0, 23, 0, 24], ["-", 0, 200, 0, 212, 0, 23, 0, 16, 31, 203], ["-", 0, 200, 0, 212, 0, 23, 0, 16, 17, 72], ["-", 0, 200, 0, 212, 0, 23, 0, 16, 12, 22], ["-", 10, 198, 0, 200, 0, 212, 0, 23, 0, 25], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 206, 207, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 31, 203], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 12, 22], ["-", 206, 207, 0, 28, 0, 16, 12, 23, 0, 25], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 106], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 11, 31, 204, 205, 22], ["+", 75, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["+", 75, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32]]
| 8
| 2,304
| 30
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var S = sc.ReadStr();
var counts = new int[N, 10];
for (int i = 0; i < N; i++) {
for (int j = 0; j < 10; j++) {
if (i > 0) {
counts[i, j] = counts[i - 1, j];
}
}
var n = (int)S[i] - '0';
counts[i, n]++;
}
var dic = new Dictionary<Tuple<int, int, int>, bool>();
for (int i = 1; i < N - 1; i++) {
for (int j = 0; j < 10; j++) {
if (counts[i - 1, j] == 0)
continue;
for (int k = 0; k < 10; k++) {
if (counts[N - 1, k] - counts[i, k] == 0)
continue;
var key = Tuple.Create(j, i, k);
dic[key] = true;
}
}
}
var ans = dic.Count();
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public 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.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var S = sc.ReadStr();
var counts = new int[N, 10];
for (int i = 0; i < N; i++) {
for (int j = 0; j < 10; j++) {
if (i > 0) {
counts[i, j] = counts[i - 1, j];
}
}
var n = (int)S[i] - '0';
counts[i, n]++;
}
var dic = new Dictionary<Tuple<int, int, int>, bool>();
for (int i = 1; i < N - 1; i++) {
for (int j = 0; j < 10; j++) {
if (counts[i - 1, j] == 0)
continue;
for (int k = 0; k < 10; k++) {
if (counts[N - 1, k] - counts[i, k] == 0)
continue;
var key = Tuple.Create(j, (int)S[i] - '0', k);
dic[key] = true;
}
}
}
var ans = dic.Count();
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public 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;
}
}
|
[["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25], ["+", 0, 28, 0, 16, 31, 74, 51, 204, 205, 22], ["+", 0, 16, 31, 74, 51, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 74, 51, 204, 206, 207, 0, 73], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 252, 0, 104], ["+", 3, 4, 0, 28, 0, 16, 12, 252, 0, 253]]
| 8
| 1,253
| 10
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Collections;
using System.Runtime.Serialization;
using System.Collections.Specialized;
using System.Security.Cryptography;
using System.Globalization;
class Program {
#region Reader
static string ReadStr => Console.ReadLine();
static string[] ReadStrs => Console.ReadLine().Split(' ');
static int ReadInt => Convert.ToInt32(Console.ReadLine());
static int[] ReadInts =>
Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
static long ReadLong => Convert.ToInt64(Console.ReadLine());
static long[] ReadLongs =>
Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
#endregion
#region Method
const int mod = 1000000007;
public static int Mod(int a, int mod) {
return a % mod >= 0 ? a % mod : a % mod + mod;
}
public static long Mod(long a, long mod = mod) {
return a % mod >= 0 ? a % mod : a % mod + mod;
}
#endregion
static void Main() {
int N = ReadInt;
int[] As = ReadInts;
long ans = 1;
int[] d = { 0, 0, 0 };
// 0番目は任意
d[0]++;
ans *= 3;
for (int i = 1; i < N; i++) {
int options = 0;
int color = -1;
if (As[i] == d[0]) {
options++;
color = 0;
}
if (As[i] == d[1]) {
options++;
color = 1;
}
if (As[i] == d[2]) {
options++;
color = 2;
}
if (color == -1) {
options++;
color = 2;
}
ans *= options;
ans %= mod;
d[color]++;
}
WriteLine(ans);
}
}
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Collections;
using System.Runtime.Serialization;
using System.Collections.Specialized;
using System.Security.Cryptography;
using System.Globalization;
class Program {
#region Reader
static string ReadStr => Console.ReadLine();
static string[] ReadStrs => Console.ReadLine().Split(' ');
static int ReadInt => Convert.ToInt32(Console.ReadLine());
static int[] ReadInts =>
Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
static long ReadLong => Convert.ToInt64(Console.ReadLine());
static long[] ReadLongs =>
Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
#endregion
#region Method
const int mod = 1000000007;
public static int Mod(int a, int mod) {
return a % mod >= 0 ? a % mod : a % mod + mod;
}
public static long Mod(long a, long mod = mod) {
return a % mod >= 0 ? a % mod : a % mod + mod;
}
#endregion
static void Main() {
int N = ReadInt;
int[] As = ReadInts;
long ans = 1;
int[] d = { 0, 0, 0 };
for (int i = 0; i < N; i++) {
int options = 0;
int color = -1;
if (As[i] == d[0]) {
options++;
color = 0;
}
if (As[i] == d[1]) {
options++;
color = 1;
}
if (As[i] == d[2]) {
options++;
color = 2;
}
if (color == -1) {
WriteLine(0);
return;
}
ans *= options;
ans %= mod;
d[color]++;
}
WriteLine(ans);
}
}
|
[["-", 8, 196, 0, 1, 0, 223, 0, 204, 205, 22], ["-", 0, 1, 0, 223, 0, 204, 206, 207, 0, 70], ["-", 0, 223, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 1, 0, 223, 0, 204, 206, 207, 0, 73], ["-", 0, 195, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
| 8
| 442
| 22
|
using System;
using System.Collections.Generic;
namespace abc144_e {
class Program {
static void Main(string[] args) {
var n = CIn.ReadInt();
var k = CIn.ReadLong();
var a = CIn.ReadIntArray(n);
var f = CIn.ReadIntArray(n);
Array.Sort(a);
Array.Sort(f);
Array.Reverse(f);
var ok = (long)a[n - 1] * f[0];
var ng = -1L;
while (ok - ng > 1) {
var mid = (ok + ng) / 2;
var sum = 0L;
for (var i = 0; i < n; i++) {
sum += a[i] - mid / f[i];
if (sum > k) {
break;
}
}
if (sum > k) {
ng = mid;
} else {
ok = mid;
}
}
Console.WriteLine(ok);
}
}
class CIn {
private static readonly Queue<string> fieldBuffer = new Queue<string>();
public static string Read() {
if (fieldBuffer.Count == 0) {
foreach (var field in Console.ReadLine().Split()) {
fieldBuffer.Enqueue(field);
}
}
return fieldBuffer.Dequeue();
}
public static int ReadInt() => int.Parse(Read());
public static long ReadLong() => long.Parse(Read());
public static double ReadDouble() => double.Parse(Read());
public static string[] ReadStringArray(long n) {
var array = new string[n];
for (var i = 0; i < n; i++) {
array[i] = Read();
}
return array;
}
public static int[] ReadIntArray(long n) {
var array = new int[n];
for (var i = 0; i < n; i++) {
array[i] = ReadInt();
}
return array;
}
public static long[] ReadLongArray(long n) {
var array = new long[n];
for (var i = 0; i < n; i++) {
array[i] = ReadLong();
}
return array;
}
public static double[] ReadDoubleArray(long n) {
var array = new double[n];
for (var i = 0; i < n; i++) {
array[i] = ReadDouble();
}
return array;
}
}
}
|
using System;
using System.Collections.Generic;
namespace abc144_e {
class Program {
static void Main(string[] args) {
var n = CIn.ReadInt();
var k = CIn.ReadLong();
var a = CIn.ReadIntArray(n);
var f = CIn.ReadIntArray(n);
Array.Sort(a);
Array.Sort(f);
Array.Reverse(f);
var ok = (long)a[n - 1] * f[0];
var ng = -1L;
while (ok - ng > 1) {
var mid = (ok + ng) / 2;
var sum = 0L;
for (var i = 0; i < n; i++) {
var aa = mid / f[i];
if (a[i] > aa) {
sum += a[i] - aa;
}
if (sum > k) {
break;
}
}
if (sum > k) {
ng = mid;
} else {
ok = mid;
}
}
Console.WriteLine(ok);
}
}
class CIn {
private static readonly Queue<string> fieldBuffer = new Queue<string>();
public static string Read() {
if (fieldBuffer.Count == 0) {
foreach (var field in Console.ReadLine().Split()) {
fieldBuffer.Enqueue(field);
}
}
return fieldBuffer.Dequeue();
}
public static int ReadInt() => int.Parse(Read());
public static long ReadLong() => long.Parse(Read());
public static double ReadDouble() => double.Parse(Read());
public static string[] ReadStringArray(long n) {
var array = new string[n];
for (var i = 0; i < n; i++) {
array[i] = Read();
}
return array;
}
public static int[] ReadIntArray(long n) {
var array = new int[n];
for (var i = 0; i < n; i++) {
array[i] = ReadInt();
}
return array;
}
public static long[] ReadLongArray(long n) {
var array = new long[n];
for (var i = 0; i < n; i++) {
array[i] = ReadLong();
}
return array;
}
public static double[] ReadDoubleArray(long n) {
var array = new double[n];
for (var i = 0; i < n; i++) {
array[i] = ReadDouble();
}
return array;
}
}
}
|
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22], ["+", 0, 212, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 212, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 17, 85], ["-", 0, 11, 12, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 518
| 28
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
static class Extensions {
public static int LowerBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c > 0)
l = m + 1;
else
r = m;
}
return l;
}
public static int UpperBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c >= 0)
l = m + 1;
else
r = m;
}
return r;
}
}
class Program {
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int[] ReadIntArray(int n) {
var a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ReadInt();
}
return a;
}
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long[] ReadLongArray(int n) {
var a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ReadLong();
}
return a;
}
public static int[] ZAlgotithm(string s) {
var len = s.Length;
var a = new int[len];
a[0] = len;
var i = 1;
var j = 0;
while (i < len) {
while (i + j < len && s[j] == s[i + j])
j++;
a[i] = j;
if (j == 0) {
i++;
continue;
}
var k = 1;
while (i + k < len && k + a[k] < j) {
a[i + k] = a[k];
k++;
}
i += k;
j -= k;
}
return a;
}
public class MaxHeap<T> : IEnumerable<T> {
private List<T> _list;
private Comparer<T> _comp;
public int Count {
get { return _list.Count; }
}
public MaxHeap() : this(0) {}
public MaxHeap(int capacity, Comparison<T> comp = null) {
_list = new List<T>(capacity);
if (comp == null) {
_comp = Comparer<T>.Default;
} else {
_comp = Comparer<T>.Create(comp);
}
}
public void Push(T elem) { Upheap(elem); }
public T Pop() { return Downheap(); }
public T Peek() { return _list[0]; }
private void Swap(int i, int j) {
var a = _list[j];
_list[j] = _list[i];
_list[i] = a;
}
private void Upheap(T elem) {
_list.Add(elem);
var i = _list.Count - 1;
while (true) {
if (i == 0)
return;
var j = (i - 1) / 2;
var e = _list[i];
var p = _list[j];
var c = _comp.Compare(e, p);
if (c > 0) {
Swap(i, j);
i = j;
continue;
} else {
break;
}
}
}
private T Downheap() {
var result = _list[0];
var last = _list.Count - 1;
Swap(0, last);
_list.RemoveAt(last);
if (_list.Count == 0)
return result;
var i = 0;
while (true) {
if (i == _list.Count - 1)
return result;
var p = _list[i];
var j = i * 2 + 1;
if (j >= _list.Count)
return result;
if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) {
j++;
}
if (_comp.Compare(_list[i], _list[j]) < 0) {
Swap(i, j);
i = j;
} else {
return result;
}
}
}
public MaxHeap<T> Copy(Comparison<T> comp = null) {
var c = new MaxHeap<T>(0, comp);
c._list = _list.ToList();
return c;
}
public MaxHeap(List<T> list) {
_list = list;
_comp = Comparer<T>.Default;
}
public List<T> GetList() { return _list; }
public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
class InputLine {
private string[] _inputs;
private int _index = 0;
InputLine(string input) {
_inputs = input.Split();
_index = 0;
}
public static InputLine Read() { return new InputLine(Console.ReadLine()); }
public int NextInt() { return int.Parse(_inputs[_index++]); }
public long NextLong() { return long.Parse(_inputs[_index++]); }
public double NextDouble() { return double.Parse(_inputs[_index++]); }
}
public static int GCD(int x, int y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
public static long GCD(long x, long y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
static long ModPower(long x, long y, long mod) {
var bytes = BitConverter.GetBytes(y);
var bits = new System.Collections.BitArray(bytes);
var max2 = 0;
for (int i = bits.Length - 1; i >= 0; i--) {
if (bits[i]) {
max2 = i;
break;
}
}
long result = 1;
for (int i = max2; i >= 0; i--) {
result = (result * result) % mod;
if (bits[i]) {
result = (result * x) % mod;
}
}
return result;
}
static long ModFact(long n, long mod) {
long result = 1;
for (int i = 1; i <= n; i++) {
result = result * i % mod;
}
return result;
}
static long ModAdd(long x, long y, long mod) {
return ((x % mod) + (y % mod)) % mod;
}
static long ModMal(long x, long y, long mod) {
return ((x % mod) * (y % mod)) % mod;
}
static long ModDiv(long x, long y, long mod) {
//フェルマーの小定理より、a^(-1) = a^(p-2)
return ModMal(x, ModPower(y, mod - 2, mod), mod);
}
static long ModComb(long n, long r, long mod) {
long numerator = 1;
for (int i = 0; i < r; i++) {
numerator = ModMal(numerator, n - i, mod);
}
long denominator = ModFact(r, mod);
return ModDiv(numerator, denominator, mod);
}
class Graph {
private int _size;
private List<int>[] _map;
public IEnumerable<int> this[int i] {
get {
if (_map[i] == null)
return Enumerable.Empty<int>();
return _map[i];
}
}
public Graph(int size) {
_size = size;
_map = new List<int>[size];
}
public void Add(int from, int to) {
if (_map[from] == null) {
_map[from] = new List<int>();
}
_map[from].Add(to);
}
}
static long p1097 = 1000000007;
static void Main(string[] args) {
//↓
var input = InputLine.Read();
var n = input.NextInt();
var k = input.NextLong();
var aas = ReadLongArray();
var fs = ReadLongArray();
Array.Sort(aas);
Array.Sort(fs);
var l = new List<Tuple<long, long>>(n);
long max = 0;
for (int i = 0; i < n; i++) {
var a = aas[i];
var f = fs[n - i - 1];
var af = a * f;
max = Math.Max(max, af);
l.Add(Tuple.Create(f, af));
}
long left = 0;
long right = max + 1;
while (left + 1 < right) {
var score = left + (right - left) / 2;
long count = 0;
foreach (var t in l) {
if (score < t.Item2) {
count += (t.Item2 - score) / t.Item1 + 1;
}
if (count > k)
break;
}
if (count <= k) {
right = score;
} else {
left = score;
}
}
Console.WriteLine(right - 1);
//↑
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
static class Extensions {
public static int LowerBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c > 0)
l = m + 1;
else
r = m;
}
return l;
}
public static int UpperBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c >= 0)
l = m + 1;
else
r = m;
}
return r;
}
}
class Program {
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int[] ReadIntArray(int n) {
var a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ReadInt();
}
return a;
}
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long[] ReadLongArray(int n) {
var a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ReadLong();
}
return a;
}
public static int[] ZAlgotithm(string s) {
var len = s.Length;
var a = new int[len];
a[0] = len;
var i = 1;
var j = 0;
while (i < len) {
while (i + j < len && s[j] == s[i + j])
j++;
a[i] = j;
if (j == 0) {
i++;
continue;
}
var k = 1;
while (i + k < len && k + a[k] < j) {
a[i + k] = a[k];
k++;
}
i += k;
j -= k;
}
return a;
}
public class MaxHeap<T> : IEnumerable<T> {
private List<T> _list;
private Comparer<T> _comp;
public int Count {
get { return _list.Count; }
}
public MaxHeap() : this(0) {}
public MaxHeap(int capacity, Comparison<T> comp = null) {
_list = new List<T>(capacity);
if (comp == null) {
_comp = Comparer<T>.Default;
} else {
_comp = Comparer<T>.Create(comp);
}
}
public void Push(T elem) { Upheap(elem); }
public T Pop() { return Downheap(); }
public T Peek() { return _list[0]; }
private void Swap(int i, int j) {
var a = _list[j];
_list[j] = _list[i];
_list[i] = a;
}
private void Upheap(T elem) {
_list.Add(elem);
var i = _list.Count - 1;
while (true) {
if (i == 0)
return;
var j = (i - 1) / 2;
var e = _list[i];
var p = _list[j];
var c = _comp.Compare(e, p);
if (c > 0) {
Swap(i, j);
i = j;
continue;
} else {
break;
}
}
}
private T Downheap() {
var result = _list[0];
var last = _list.Count - 1;
Swap(0, last);
_list.RemoveAt(last);
if (_list.Count == 0)
return result;
var i = 0;
while (true) {
if (i == _list.Count - 1)
return result;
var p = _list[i];
var j = i * 2 + 1;
if (j >= _list.Count)
return result;
if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) {
j++;
}
if (_comp.Compare(_list[i], _list[j]) < 0) {
Swap(i, j);
i = j;
} else {
return result;
}
}
}
public MaxHeap<T> Copy(Comparison<T> comp = null) {
var c = new MaxHeap<T>(0, comp);
c._list = _list.ToList();
return c;
}
public MaxHeap(List<T> list) {
_list = list;
_comp = Comparer<T>.Default;
}
public List<T> GetList() { return _list; }
public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
class InputLine {
private string[] _inputs;
private int _index = 0;
InputLine(string input) {
_inputs = input.Split();
_index = 0;
}
public static InputLine Read() { return new InputLine(Console.ReadLine()); }
public int NextInt() { return int.Parse(_inputs[_index++]); }
public long NextLong() { return long.Parse(_inputs[_index++]); }
public double NextDouble() { return double.Parse(_inputs[_index++]); }
}
public static int GCD(int x, int y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
public static long GCD(long x, long y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
static long ModPower(long x, long y, long mod) {
var bytes = BitConverter.GetBytes(y);
var bits = new System.Collections.BitArray(bytes);
var max2 = 0;
for (int i = bits.Length - 1; i >= 0; i--) {
if (bits[i]) {
max2 = i;
break;
}
}
long result = 1;
for (int i = max2; i >= 0; i--) {
result = (result * result) % mod;
if (bits[i]) {
result = (result * x) % mod;
}
}
return result;
}
static long ModFact(long n, long mod) {
long result = 1;
for (int i = 1; i <= n; i++) {
result = result * i % mod;
}
return result;
}
static long ModAdd(long x, long y, long mod) {
return ((x % mod) + (y % mod)) % mod;
}
static long ModMal(long x, long y, long mod) {
return ((x % mod) * (y % mod)) % mod;
}
static long ModDiv(long x, long y, long mod) {
//フェルマーの小定理より、a^(-1) = a^(p-2)
return ModMal(x, ModPower(y, mod - 2, mod), mod);
}
static long ModComb(long n, long r, long mod) {
long numerator = 1;
for (int i = 0; i < r; i++) {
numerator = ModMal(numerator, n - i, mod);
}
long denominator = ModFact(r, mod);
return ModDiv(numerator, denominator, mod);
}
class Graph {
private int _size;
private List<int>[] _map;
public IEnumerable<int> this[int i] {
get {
if (_map[i] == null)
return Enumerable.Empty<int>();
return _map[i];
}
}
public Graph(int size) {
_size = size;
_map = new List<int>[size];
}
public void Add(int from, int to) {
if (_map[from] == null) {
_map[from] = new List<int>();
}
_map[from].Add(to);
}
}
static long p1097 = 1000000007;
static void Main(string[] args) {
//↓
var input = InputLine.Read();
var n = input.NextInt();
var k = input.NextLong();
var aas = ReadLongArray();
var fs = ReadLongArray();
Array.Sort(aas);
Array.Sort(fs);
var l = new List<Tuple<long, long>>(n);
long max = 0;
for (int i = 0; i < n; i++) {
var a = aas[i];
var f = fs[n - i - 1];
var af = a * f;
max = Math.Max(max, af);
l.Add(Tuple.Create(f, af));
}
long left = -1;
long right = max;
while (left + 1 < right) {
var score = left + (right - left) / 2;
long count = 0;
foreach (var t in l) {
if (score < t.Item2) {
count += (t.Item2 - score + t.Item1 - 1) / t.Item1;
}
if (count > k)
break;
}
if (count <= k) {
right = score;
} else {
left = score;
}
}
Console.WriteLine(right);
//↑
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["+", 31, 23, 0, 16, 31, 16, 12, 214, 205, 22], ["+", 31, 23, 0, 16, 31, 16, 12, 214, 0, 131], ["+", 31, 23, 0, 16, 31, 16, 12, 214, 141, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 203], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 2,148
| 15
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
namespace Program {
public static class ABC144E {
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var K = NN;
var AList = NNList(N);
var FList = NNList(N);
var sortedA = AList.OrderByRand().OrderBy(e => e).ToList();
var sortedF = FList.OrderByRand().OrderByDescending(e => e).ToList();
var left = -1L;
var right = 0L;
for (var i = 0; i < N; i++)
right += sortedA[i] * sortedF[i];
while (right - left > 1) {
var mid = (right - left) / 2 + left;
var kCount = 0L;
for (var i = 0; i < N; i++) {
var a = sortedA[i];
var f = sortedF[i];
kCount += a - mid / f;
}
if (kCount <= K) {
right = mid;
} else {
left = mid;
}
}
Console.WriteLine(right);
}
static public void Main(string[] args) {
if (args.Length == 0) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
Console.Out.Flush();
}
static class Console_ {
static Queue<string> param = new Queue<string>();
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static IEnumerable<long> Primes(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
static IEnumerable<long> Factors(long x) {
if (x < 2)
yield break;
while (x % 2 == 0) {
x /= 2;
yield return 2;
}
var max = (long)Math.Sqrt(x);
for (long i = 3; i <= max; i += 2)
while (x % i == 0) {
x /= i;
yield return i;
}
if (x != 1)
yield return x;
}
static IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
static long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
static long LCM(long a, long b) => a * b / GCD(a, b);
static Mod Pow(Mod x, long y) {
Mod a = 1;
while (y != 0) {
if ((y & 1) == 1)
a.Mul(x);
x.Mul(x);
y >>= 1;
}
return a;
}
static long Pow(long x, long y) {
long a = 1;
while (y != 0) {
if ((y & 1) == 1)
a *= x;
x *= x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>() { 1 };
static void _B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static long Comb(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static long Perm(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) {
Func<TR> t = () => default(TR);
return t = () => f(t);
}
static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) {
Func<T1, TR> t = x1 => default(TR);
return t = x1 => f(x1, t);
}
static Func<T1, T2, TR>
Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) {
Func<T1, T2, TR> t = (x1, x2) => default(TR);
return t = (x1, x2) => f(x1, x2, t);
}
static Func<T1, T2, T3, TR>
Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) {
Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR);
return t = (x1, x2, x3) => f(x1, x2, x3, t);
}
static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>(
Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) {
Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR);
return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t);
}
static List<T> LCS<T>(T[] s, T[] t)
where T : IEquatable<T> {
int sl = s.Length, tl = t.Length;
var dp = new int[sl + 1, tl + 1];
for (var i = 0; i < sl; i++)
for (var j = 0; j < tl; j++)
dp[i + 1, j + 1] =
s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]);
{
var r = new List<T>();
int i = sl, j = tl;
while (i > 0 && j > 0)
if (s[--i].Equals(t[--j]))
r.Add(s[i]);
else if (dp[i, j + 1] > dp[i + 1, j])
++j;
else
++i;
r.Reverse();
return r;
}
}
static long LIS<T>(T[] array, bool strict) {
var l = new List<T>();
foreach (var e in array) {
var i = l.BinarySearch(e);
if (i < 0)
i = ~i;
else if (!strict)
++i;
if (i == l.Count)
l.Add(e);
else
l[i] = e;
}
return l.Count;
}
class PQ<T> {
List<T> h;
Comparison<T> c;
public T Peek => h[0];
public int Count => h.Count;
public PQ(int cap, Comparison<T> c, bool asc = true) {
h = new List<T>(cap);
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(Comparison<T> c, bool asc = true) {
h = new List<T>();
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(int cap, bool asc = true)
: this(cap, Comparer<T>.Default.Compare, asc) {}
public PQ(bool asc = true) : this(Comparer<T>.Default.Compare, asc) {}
public void Push(T v) {
var i = h.Count;
h.Add(v);
while (i > 0) {
var ni = (i - 1) / 2;
if (c(v, h[ni]) >= 0)
break;
h[i] = h[ni];
i = ni;
}
h[i] = v;
}
public T Pop() {
var r = h[0];
var v = h[h.Count - 1];
h.RemoveAt(h.Count - 1);
if (h.Count == 0)
return r;
var i = 0;
while (i * 2 + 1 < h.Count) {
var i1 = i * 2 + 1;
var i2 = i * 2 + 2;
if (i2 < h.Count && c(h[i1], h[i2]) > 0)
i1 = i2;
if (c(v, h[i1]) <= 0)
break;
h[i] = h[i1];
i = i1;
}
h[i] = v;
return r;
}
}
class PQ<TK, TV> {
PQ<Tuple<TK, TV>> q;
public Tuple<TK, TV> Peek => q.Peek;
public int Count => q.Count;
public PQ(int cap, Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(int cap, bool asc = true)
: this(cap, Comparer<TK>.Default.Compare, asc) {}
public PQ(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) {}
public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v));
public Tuple<TK, TV> Pop() => q.Pop();
}
public class UF {
long[] d;
public UF(long s) { d = Repeat(-1L, s).ToArray(); }
public bool Unite(long x, long y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (d[y] < d[x]) {
var t = y;
y = x;
x = t;
}
d[x] += d[y];
d[y] = x;
}
return x != y;
}
public bool IsSame(long x, long y) => Root(x) == Root(y);
public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
public long Count(long x) => -d[Root(x)];
}
struct Mod : IEquatable<Mod>, IEquatable<long> {
static public long _mod = 1000000007;
long v;
public Mod(long x) {
if (x < _mod && x >= 0)
v = x;
else if ((v = x % _mod) < 0)
v += _mod;
}
static public implicit operator Mod(long x) => new Mod(x);
static public implicit operator long(Mod x) => x.v;
public void Add(Mod x) {
if ((v += x.v) >= _mod)
v -= _mod;
}
public void Sub(Mod x) {
if ((v -= x.v) < 0)
v += _mod;
}
public void Mul(Mod x) => v = (v * x.v) % _mod;
public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod;
static public Mod operator +(Mod x, Mod y) {
var t = x.v + y.v;
return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t };
}
static public Mod operator -(Mod x, Mod y) {
var t = x.v - y.v;
return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t };
}
static public Mod operator *(Mod x, Mod y) => x.v * y.v;
static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v);
static public bool operator ==(Mod x, Mod y) => x.v == y.v;
static public bool operator !=(Mod x, Mod y) => x.v != y.v;
static public long Inverse(long x) {
long b = _mod, r = 1, u = 0, t = 0;
while (b > 0) {
var q = x / b;
t = u;
u = r - q * u;
r = t;
t = b;
b = x - q * b;
x = t;
}
return r < 0 ? r + _mod : r;
}
public bool Equals(Mod x) => v == x.v;
public bool Equals(long x) => v == x;
public override bool Equals(object x) => x == null ? false : Equals((Mod)x);
public override int GetHashCode() => v.GetHashCode();
public override string ToString() => v.ToString();
static List<Mod> _fact = new List<Mod>() { 1 };
static void B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static public Mod Comb(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static public Mod Perm(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
}
class Tree {
long N;
int l;
List<long>[] p;
int[] d;
long[][] pr;
long r;
Tuple<long, long, int>[] e;
Tuple<long, long>[] b;
bool lca;
bool euler;
bool bfs;
public Tree(List<long>[] p_, long r_) {
N = p_.Length;
p = p_;
r = r_;
lca = false;
euler = false;
}
public Tuple<long, long>[] BFSRoot() {
if (!bfs) {
var nb = new List<Tuple<long, long>>();
var q = new Queue<long>();
var d = new bool[N];
nb.Add(Tuple.Create(r, -1L));
d[r] = true;
q.Enqueue(r);
while (q.Count > 0) {
var w = q.Dequeue();
foreach (var i in p[w]) {
if (d[i])
continue;
d[i] = true;
q.Enqueue(i);
nb.Add(Tuple.Create(i, w));
}
}
b = nb.ToArray();
bfs = true;
}
return b;
}
public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray();
public Tuple<long, long, int>[] Euler() {
if (!euler) {
var ne = new List<Tuple<long, long, int>>();
var s = new Stack<Tuple<long, long>>();
var d = new bool[N];
d[r] = true;
s.Push(Tuple.Create(r, -1L));
while (s.Count > 0) {
var w = s.Peek();
var ad = true;
foreach (var i in p[w.Item1]) {
if (d[i])
continue;
d[i] = true;
ad = false;
s.Push(Tuple.Create(i, w.Item1));
}
if (!ad || p[w.Item1].Count == 1)
ne.Add(Tuple.Create(w.Item1, w.Item2, 1));
if (ad) {
s.Pop();
ne.Add(Tuple.Create(w.Item1, w.Item2, -1));
}
}
e = ne.ToArray();
euler = true;
}
return e;
}
public long LCA(long u, long v) {
if (!lca) {
l = 0;
while (N > (1 << l))
l++;
d = new int[N];
pr = Repeat(0, l).Select(_ => new long[N]).ToArray();
d[r] = 0;
pr[0][r] = -1;
var q = new Stack<long>();
q.Push(r);
while (q.Count > 0) {
var w = q.Pop();
foreach (var i in p[w]) {
if (i == pr[0][w])
continue;
q.Push(i);
d[i] = d[w] + 1;
pr[0][i] = w;
}
}
for (var k = 0; k + 1 < l; k++)
for (var w = 0; w < N; w++)
if (pr[k][w] < 0)
pr[k + 1][w] = -1;
else
pr[k + 1][w] = pr[k][pr[k][w]];
lca = true;
}
if (d[u] > d[v]) {
var t = u;
u = v;
v = t;
}
for (var k = 0; k < l; k++)
if ((((d[v] - d[u]) >> k) & 1) != 0)
v = pr[k][v];
if (u == v)
return u;
for (var k = l - 1; k >= 0; k--)
if (pr[k][u] != pr[k][v]) {
u = pr[k][u];
v = pr[k][v];
}
return pr[0][u];
}
}
class BT<T>
where T : IComparable {
class Node {
public Node l;
public Node r;
public T v;
public bool b;
public int c;
}
Comparison<T> c;
Node r;
bool ch;
T lm;
public BT(Comparison<T> _c) { c = _c; }
public BT() : this((x, y) => x.CompareTo(y)) {}
bool R(Node n) => n != null && !n.b;
bool B(Node n) => n != null && n.b;
long C(Node n) => n?.c ?? 0;
Node RtL(Node n) {
Node m = n.r, t = m.l;
m.l = n;
n.r = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtR(Node n) {
Node m = n.l, t = m.r;
m.r = n;
n.l = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtLR(Node n) {
n.l = RtL(n.l);
return RtR(n);
}
Node RtRL(Node n) {
n.r = RtR(n.r);
return RtL(n);
}
public void Add(T x) {
r = A(r, x);
r.b = true;
}
Node A(Node n, T x) {
if (n == null) {
ch = true;
return new Node() { v = x, c = 1 };
}
if (c(x, n.v) < 0)
n.l = A(n.l, x);
else
n.r = A(n.r, x);
n.c++;
return Bl(n);
}
Node Bl(Node n) {
if (!ch)
return n;
if (!B(n))
return n;
if (R(n.l) && R(n.l.l)) {
n = RtR(n);
n.l.b = true;
} else if (R(n.l) && R(n.l.r)) {
n = RtLR(n);
n.l.b = true;
} else if (R(n.r) && R(n.r.l)) {
n = RtRL(n);
n.r.b = true;
} else if (R(n.r) && R(n.r.r)) {
n = RtL(n);
n.r.b = true;
} else
ch = false;
return n;
}
public void Remove(T x) {
r = Rm(r, x);
if (r != null)
r.b = true;
}
Node Rm(Node n, T x) {
if (n == null) {
ch = false;
return n;
}
n.c--;
var r = c(x, n.v);
if (r < 0) {
n.l = Rm(n.l, x);
return BlL(n);
}
if (r > 0) {
n.r = Rm(n.r, x);
return BlR(n);
}
if (n.l == null) {
ch = n.b;
return n.r;
}
n.l = RmM(n.l);
n.v = lm;
return BlL(n);
}
Node RmM(Node n) {
n.c--;
if (n.r != null) {
n.r = RmM(n.r);
return BlR(n);
}
lm = n.v;
ch = n.b;
return n.l;
}
Node BlL(Node n) {
if (!ch)
return n;
if (B(n.r) && R(n.r.l)) {
var b = n.b;
n = RtRL(n);
n.b = b;
n.l.b = true;
ch = false;
} else if (B(n.r) && R(n.r.r)) {
var b = n.b;
n = RtL(n);
n.b = b;
n.r.b = true;
n.l.b = true;
ch = false;
} else if (B(n.r)) {
ch = n.b;
n.b = true;
n.r.b = false;
} else {
n = RtL(n);
n.b = true;
n.l.b = false;
n.l = BlL(n.l);
ch = false;
}
return n;
}
Node BlR(Node n) {
if (!ch)
return n;
if (B(n.l) && R(n.l.r)) {
var b = n.b;
n = RtLR(n);
n.b = b;
n.r.b = true;
ch = false;
} else if (B(n.l) && R(n.l.l)) {
var b = n.b;
n = RtR(n);
n.b = b;
n.l.b = true;
n.r.b = true;
ch = false;
} else if (B(n.l)) {
ch = n.b;
n.b = true;
n.l.b = false;
} else {
n = RtR(n);
n.b = true;
n.r.b = false;
n.r = BlR(n.r);
ch = false;
}
return n;
}
public T this[long i] {
get { return At(r, i); }
}
T At(Node n, long i) {
if (n == null)
return default(T);
if (n.l == null)
if (i == 0)
return n.v;
else
return At(n.r, i - 1);
if (n.l.c == i)
return n.v;
if (n.l.c > i)
return At(n.l, i);
return At(n.r, i - n.l.c - 1);
}
public bool Have(T x) {
var t = FindUpper(x);
return t < C(r) && c(At(r, t), x) == 0;
}
public long FindUpper(T x, bool allowSame = true) => allowSame
? FL(r, x) + 1
: FU(r, x);
long FU(Node n, T x) {
if (n == null)
return 0;
var r = c(x, n.v);
if (r < 0)
return FU(n.l, x);
return C(n.l) + 1 + FU(n.r, x);
}
public long FindLower(T x, bool allowSame = true) {
var t = FL(r, x);
if (allowSame)
return t + 1 < C(r) && c(At(r, t + 1), x) == 0 ? t + 1
: t < 0 ? C(r)
: t;
return t < 0 ? C(r) : t;
}
long FL(Node n, T x) {
if (n == null)
return -1;
var r = c(x, n.v);
if (r > 0)
return C(n.l) + 1 + FL(n.r, x);
return FL(n.l, x);
}
public T Min() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.l;
}
return p == null ? default(T) : p.v;
}
public T Max() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.r;
}
return p == null ? default(T) : p.v;
}
public bool Any() => r != null;
public long Count() => C(r);
public IEnumerable<T> List() => L(r);
IEnumerable<T> L(Node n) {
if (n == null)
yield break;
foreach (var i in L(n.l))
yield return i;
yield return n.v;
foreach (var i in L(n.r))
yield return i;
}
}
class Dict<K, V> : Dictionary<K, V> {
Func<K, V> d;
public Dict(Func<K, V> _d) { d = _d; }
public Dict() : this(_ => default(V)) {}
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = d(i);
}
set { base[i] = value; }
}
public override int GetHashCode() {
var ret = 0;
for (var e = GetEnumerator(); e.MoveNext();) {
ret ^= e.Current.Key.GetHashCode();
ret ^= e.Current.Value.GetHashCode();
}
return ret;
}
public override bool Equals(object obj) {
var o = (Dict<K, V>)obj;
foreach (var kv in o) {
if (!ContainsKey(kv.Key) || !this[kv.Key].Equals(kv.Value))
return false;
}
return o.Count == Count;
}
}
class Deque<T> {
T[] b;
int o, c;
public int Count;
public T this[int i] {
get { return b[gi(i)]; }
set { b[gi(i)] = value; }
}
public Deque(int cap = 16) { b = new T[c = cap]; }
int gi(int i) {
if (i >= c)
throw new Exception();
var r = o + i;
return r >= c ? r - c : r;
}
public void PushFront(T x) {
if (Count == c)
e();
if (--o < 0)
o += b.Length;
b[o] = x;
++Count;
}
public T PopFront() {
if (Count-- == 0)
throw new Exception();
var r = b[o++];
if (o >= c)
o -= c;
return r;
}
public T Front => b[o];
public void PushBack(T x) {
if (Count == c)
e();
var i = o + Count++;
b[i >= c ? i - c : i] = x;
}
public T PopBack() {
if (Count == 0)
throw new Exception();
return b[gi(--Count)];
}
public T Back => b[gi(Count - 1)];
void e() {
T[] nb = new T[c << 1];
if (o > c - Count) {
var l = b.Length - o;
Array.Copy(b, o, nb, 0, l);
Array.Copy(b, 0, nb, l, Count - l);
} else
Array.Copy(b, o, nb, 0, Count);
b = nb;
o = 0;
c <<= 1;
}
public void Insert(int i, T x) {
if (i > Count)
throw new Exception();
this.PushFront(x);
for (int j = 0; j < i; j++)
this[j] = this[j + 1];
this[i] = x;
}
public T RemoveAt(int i) {
if (i < 0 || i >= Count)
throw new Exception();
var r = this[i];
for (int j = i; j > 0; j--)
this[j] = this[j - 1];
this.PopFront();
return r;
}
}
class SegTree<T> {
int n;
T ti;
Func<T, T, T> f;
T[] dat;
public SegTree(long _n, T _ti, Func<T, T, T> _f) {
n = 1;
while (n < _n)
n <<= 1;
ti = _ti;
f = _f;
dat = Repeat(ti, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public void Update(long i, T v) {
dat[i += n] = v;
while ((i >>= 1) > 0)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public T Query(long l, long r) {
var vl = ti;
var vr = ti;
for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, dat[li++]);
if ((ri & 1) == 1)
vr = f(dat[--ri], vr);
}
return f(vl, vr);
}
public T this[long idx] {
get { return dat[idx + n]; }
set { Update(idx, value); }
}
}
class LazySegTree<T, E> {
int n, height;
T ti;
E ei;
Func<T, T, T> f;
Func<T, E, T> g;
Func<E, E, E> h;
T[] dat;
E[] laz;
public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g,
Func<E, E, E> _h) {
n = 1;
height = 0;
while (n < _n) {
n <<= 1;
++height;
}
ti = _ti;
ei = _ei;
f = _f;
g = _g;
h = _h;
dat = Repeat(ti, n << 1).ToArray();
laz = Repeat(ei, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f,
Func<T, E, T> _g, Func<E, E, E> _h)
: this(l.Count, _ti, _ei, _f, _g, _h) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]);
void Eval(long i) {
if (laz[i].Equals(ei))
return;
laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]);
laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]);
dat[i] = Reflect(i);
laz[i] = ei;
}
void Thrust(long i) {
for (var j = height; j > 0; j--)
Eval(i >> j);
}
void Recalc(long i) {
while ((i >>= 1) > 0)
dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1));
}
public void Update(long l, long r, E v) {
Thrust(l += n);
Thrust(r += n - 1);
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1) {
laz[li] = h(laz[li], v);
++li;
}
if ((ri & 1) == 1) {
--ri;
laz[ri] = h(laz[ri], v);
}
}
Recalc(l);
Recalc(r);
}
public T Query(long l, long r) {
Thrust(l += n);
Thrust(r += n - 1);
var vl = ti;
var vr = ti;
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, Reflect(li++));
if ((ri & 1) == 1)
vr = f(Reflect(--ri), vr);
}
return f(vl, vr);
}
public T this[long idx] {
get {
Thrust(idx += n);
return dat[idx] = Reflect(idx);
}
set {
Thrust(idx += n);
dat[idx] = value;
laz[idx] = ei;
Recalc(idx);
}
}
}
class SlidingWindowAggregation<T> {
T[][] l;
T[][] a;
int[] n;
Func<T, T, T> f;
public SlidingWindowAggregation(IEnumerable<T> ary, Func<T, T, T> _f) {
l = new T[2][];
a = new T[2][];
n = new int[2];
f = _f;
l[0] = new T[16];
a[0] = new T[16];
n[0] = 0;
if (ary.Any()) {
var t = ary.ToArray();
n[1] = t.Length;
l[1] = new T[n[1]];
a[1] = new T[n[1]];
for (var i = 0; i < l[1].Length; i++) {
l[1][i] = t[i];
if (i == 0)
a[1][i] = t[i];
else
a[1][i] = this.f(a[1][i - 1], t[i]);
}
} else {
l[1] = new T[16];
a[1] = new T[16];
n[1] = 0;
}
}
public SlidingWindowAggregation(Func<T, T, T> f) : this(new T[0], f) {}
public int Count => n[0] + n[1];
void Push(int la, T v) {
if (l[la].Length == n[la]) {
var nar = new T[n[la] * 2];
var nag = new T[n[la] * 2];
Array.Copy(l[la], nar, n[la]);
Array.Copy(a[la], nag, n[la]);
l[la] = nar;
a[la] = nag;
}
if (n[la] == 0)
a[la][0] = v;
else
a[la][n[la]] = la == 0 ? f(v, a[la][n[la] - 1]) : f(a[la][n[la] - 1], v);
l[la][n[la]++] = v;
}
public void PushBack(T val) => Push(1, val);
public void PushFront(T val) => Push(0, val);
public T Pop(int la) {
var lb = 1 - la;
if (n[la] == 0) {
if (n[lb] == 0)
throw new Exception();
var m = (n[lb] - 1) / 2;
if (l[la].Length <= m) {
l[la] = new T[m + 1];
a[la] = new T[m + 1];
}
n[la] = 0;
for (var i = m; i >= 0; i--) {
if (n[la] == 0)
a[la][n[la]] = l[lb][i];
else
a[la][n[la]] = la == 0 ? f(l[lb][i], a[la][n[la] - 1])
: f(a[la][n[la] - 1], l[lb][i]);
l[la][n[la]++] = l[lb][i];
}
for (var i = m + 1; i < n[lb]; i++) {
var j = i - m - 1;
if (j == 0)
a[lb][j] = l[lb][i];
else
a[lb][j] =
la == 0 ? f(l[lb][i], a[lb][j - 1]) : f(a[lb][j - 1], l[lb][i]);
l[lb][j] = l[lb][i];
}
n[lb] -= n[la];
}
return l[la][--n[la]];
}
public T PopBack() => Pop(1);
public T PopFront() => Pop(0);
public T Aggregate() {
if (n[0] == 0 && n[1] == 0)
throw new Exception();
else if (n[1] == 0)
return a[0][n[0] - 1];
else if (n[0] == 0)
return a[1][n[1] - 1];
else
return f(a[0][n[0] - 1], a[1][n[1] - 1]);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
namespace Program {
public static class ABC144E {
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var K = NN;
var AList = NNList(N);
var FList = NNList(N);
var sortedA = AList.OrderByRand().OrderBy(e => e).ToList();
var sortedF = FList.OrderByRand().OrderByDescending(e => e).ToList();
var left = -1L;
var right = 1000000000000000000;
while (right - left > 1) {
var mid = (right - left) / 2 + left;
var kCount = 0L;
for (var i = 0; i < N; i++) {
var a = sortedA[i];
var f = sortedF[i];
kCount += Max(0, a - mid / f);
}
if (kCount <= K) {
right = mid;
} else {
left = mid;
}
}
Console.WriteLine(right);
}
static public void Main(string[] args) {
if (args.Length == 0) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
Console.Out.Flush();
}
static class Console_ {
static Queue<string> param = new Queue<string>();
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static IEnumerable<long> Primes(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
static IEnumerable<long> Factors(long x) {
if (x < 2)
yield break;
while (x % 2 == 0) {
x /= 2;
yield return 2;
}
var max = (long)Math.Sqrt(x);
for (long i = 3; i <= max; i += 2)
while (x % i == 0) {
x /= i;
yield return i;
}
if (x != 1)
yield return x;
}
static IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
static long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
static long LCM(long a, long b) => a * b / GCD(a, b);
static Mod Pow(Mod x, long y) {
Mod a = 1;
while (y != 0) {
if ((y & 1) == 1)
a.Mul(x);
x.Mul(x);
y >>= 1;
}
return a;
}
static long Pow(long x, long y) {
long a = 1;
while (y != 0) {
if ((y & 1) == 1)
a *= x;
x *= x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>() { 1 };
static void _B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static long Comb(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static long Perm(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) {
Func<TR> t = () => default(TR);
return t = () => f(t);
}
static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) {
Func<T1, TR> t = x1 => default(TR);
return t = x1 => f(x1, t);
}
static Func<T1, T2, TR>
Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) {
Func<T1, T2, TR> t = (x1, x2) => default(TR);
return t = (x1, x2) => f(x1, x2, t);
}
static Func<T1, T2, T3, TR>
Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) {
Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR);
return t = (x1, x2, x3) => f(x1, x2, x3, t);
}
static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>(
Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) {
Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR);
return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t);
}
static List<T> LCS<T>(T[] s, T[] t)
where T : IEquatable<T> {
int sl = s.Length, tl = t.Length;
var dp = new int[sl + 1, tl + 1];
for (var i = 0; i < sl; i++)
for (var j = 0; j < tl; j++)
dp[i + 1, j + 1] =
s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]);
{
var r = new List<T>();
int i = sl, j = tl;
while (i > 0 && j > 0)
if (s[--i].Equals(t[--j]))
r.Add(s[i]);
else if (dp[i, j + 1] > dp[i + 1, j])
++j;
else
++i;
r.Reverse();
return r;
}
}
static long LIS<T>(T[] array, bool strict) {
var l = new List<T>();
foreach (var e in array) {
var i = l.BinarySearch(e);
if (i < 0)
i = ~i;
else if (!strict)
++i;
if (i == l.Count)
l.Add(e);
else
l[i] = e;
}
return l.Count;
}
class PQ<T> {
List<T> h;
Comparison<T> c;
public T Peek => h[0];
public int Count => h.Count;
public PQ(int cap, Comparison<T> c, bool asc = true) {
h = new List<T>(cap);
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(Comparison<T> c, bool asc = true) {
h = new List<T>();
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(int cap, bool asc = true)
: this(cap, Comparer<T>.Default.Compare, asc) {}
public PQ(bool asc = true) : this(Comparer<T>.Default.Compare, asc) {}
public void Push(T v) {
var i = h.Count;
h.Add(v);
while (i > 0) {
var ni = (i - 1) / 2;
if (c(v, h[ni]) >= 0)
break;
h[i] = h[ni];
i = ni;
}
h[i] = v;
}
public T Pop() {
var r = h[0];
var v = h[h.Count - 1];
h.RemoveAt(h.Count - 1);
if (h.Count == 0)
return r;
var i = 0;
while (i * 2 + 1 < h.Count) {
var i1 = i * 2 + 1;
var i2 = i * 2 + 2;
if (i2 < h.Count && c(h[i1], h[i2]) > 0)
i1 = i2;
if (c(v, h[i1]) <= 0)
break;
h[i] = h[i1];
i = i1;
}
h[i] = v;
return r;
}
}
class PQ<TK, TV> {
PQ<Tuple<TK, TV>> q;
public Tuple<TK, TV> Peek => q.Peek;
public int Count => q.Count;
public PQ(int cap, Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(int cap, bool asc = true)
: this(cap, Comparer<TK>.Default.Compare, asc) {}
public PQ(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) {}
public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v));
public Tuple<TK, TV> Pop() => q.Pop();
}
public class UF {
long[] d;
public UF(long s) { d = Repeat(-1L, s).ToArray(); }
public bool Unite(long x, long y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (d[y] < d[x]) {
var t = y;
y = x;
x = t;
}
d[x] += d[y];
d[y] = x;
}
return x != y;
}
public bool IsSame(long x, long y) => Root(x) == Root(y);
public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
public long Count(long x) => -d[Root(x)];
}
struct Mod : IEquatable<Mod>, IEquatable<long> {
static public long _mod = 1000000007;
long v;
public Mod(long x) {
if (x < _mod && x >= 0)
v = x;
else if ((v = x % _mod) < 0)
v += _mod;
}
static public implicit operator Mod(long x) => new Mod(x);
static public implicit operator long(Mod x) => x.v;
public void Add(Mod x) {
if ((v += x.v) >= _mod)
v -= _mod;
}
public void Sub(Mod x) {
if ((v -= x.v) < 0)
v += _mod;
}
public void Mul(Mod x) => v = (v * x.v) % _mod;
public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod;
static public Mod operator +(Mod x, Mod y) {
var t = x.v + y.v;
return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t };
}
static public Mod operator -(Mod x, Mod y) {
var t = x.v - y.v;
return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t };
}
static public Mod operator *(Mod x, Mod y) => x.v * y.v;
static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v);
static public bool operator ==(Mod x, Mod y) => x.v == y.v;
static public bool operator !=(Mod x, Mod y) => x.v != y.v;
static public long Inverse(long x) {
long b = _mod, r = 1, u = 0, t = 0;
while (b > 0) {
var q = x / b;
t = u;
u = r - q * u;
r = t;
t = b;
b = x - q * b;
x = t;
}
return r < 0 ? r + _mod : r;
}
public bool Equals(Mod x) => v == x.v;
public bool Equals(long x) => v == x;
public override bool Equals(object x) => x == null ? false : Equals((Mod)x);
public override int GetHashCode() => v.GetHashCode();
public override string ToString() => v.ToString();
static List<Mod> _fact = new List<Mod>() { 1 };
static void B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static public Mod Comb(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static public Mod Perm(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
}
class Tree {
long N;
int l;
List<long>[] p;
int[] d;
long[][] pr;
long r;
Tuple<long, long, int>[] e;
Tuple<long, long>[] b;
bool lca;
bool euler;
bool bfs;
public Tree(List<long>[] p_, long r_) {
N = p_.Length;
p = p_;
r = r_;
lca = false;
euler = false;
}
public Tuple<long, long>[] BFSRoot() {
if (!bfs) {
var nb = new List<Tuple<long, long>>();
var q = new Queue<long>();
var d = new bool[N];
nb.Add(Tuple.Create(r, -1L));
d[r] = true;
q.Enqueue(r);
while (q.Count > 0) {
var w = q.Dequeue();
foreach (var i in p[w]) {
if (d[i])
continue;
d[i] = true;
q.Enqueue(i);
nb.Add(Tuple.Create(i, w));
}
}
b = nb.ToArray();
bfs = true;
}
return b;
}
public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray();
public Tuple<long, long, int>[] Euler() {
if (!euler) {
var ne = new List<Tuple<long, long, int>>();
var s = new Stack<Tuple<long, long>>();
var d = new bool[N];
d[r] = true;
s.Push(Tuple.Create(r, -1L));
while (s.Count > 0) {
var w = s.Peek();
var ad = true;
foreach (var i in p[w.Item1]) {
if (d[i])
continue;
d[i] = true;
ad = false;
s.Push(Tuple.Create(i, w.Item1));
}
if (!ad || p[w.Item1].Count == 1)
ne.Add(Tuple.Create(w.Item1, w.Item2, 1));
if (ad) {
s.Pop();
ne.Add(Tuple.Create(w.Item1, w.Item2, -1));
}
}
e = ne.ToArray();
euler = true;
}
return e;
}
public long LCA(long u, long v) {
if (!lca) {
l = 0;
while (N > (1 << l))
l++;
d = new int[N];
pr = Repeat(0, l).Select(_ => new long[N]).ToArray();
d[r] = 0;
pr[0][r] = -1;
var q = new Stack<long>();
q.Push(r);
while (q.Count > 0) {
var w = q.Pop();
foreach (var i in p[w]) {
if (i == pr[0][w])
continue;
q.Push(i);
d[i] = d[w] + 1;
pr[0][i] = w;
}
}
for (var k = 0; k + 1 < l; k++)
for (var w = 0; w < N; w++)
if (pr[k][w] < 0)
pr[k + 1][w] = -1;
else
pr[k + 1][w] = pr[k][pr[k][w]];
lca = true;
}
if (d[u] > d[v]) {
var t = u;
u = v;
v = t;
}
for (var k = 0; k < l; k++)
if ((((d[v] - d[u]) >> k) & 1) != 0)
v = pr[k][v];
if (u == v)
return u;
for (var k = l - 1; k >= 0; k--)
if (pr[k][u] != pr[k][v]) {
u = pr[k][u];
v = pr[k][v];
}
return pr[0][u];
}
}
class BT<T>
where T : IComparable {
class Node {
public Node l;
public Node r;
public T v;
public bool b;
public int c;
}
Comparison<T> c;
Node r;
bool ch;
T lm;
public BT(Comparison<T> _c) { c = _c; }
public BT() : this((x, y) => x.CompareTo(y)) {}
bool R(Node n) => n != null && !n.b;
bool B(Node n) => n != null && n.b;
long C(Node n) => n?.c ?? 0;
Node RtL(Node n) {
Node m = n.r, t = m.l;
m.l = n;
n.r = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtR(Node n) {
Node m = n.l, t = m.r;
m.r = n;
n.l = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtLR(Node n) {
n.l = RtL(n.l);
return RtR(n);
}
Node RtRL(Node n) {
n.r = RtR(n.r);
return RtL(n);
}
public void Add(T x) {
r = A(r, x);
r.b = true;
}
Node A(Node n, T x) {
if (n == null) {
ch = true;
return new Node() { v = x, c = 1 };
}
if (c(x, n.v) < 0)
n.l = A(n.l, x);
else
n.r = A(n.r, x);
n.c++;
return Bl(n);
}
Node Bl(Node n) {
if (!ch)
return n;
if (!B(n))
return n;
if (R(n.l) && R(n.l.l)) {
n = RtR(n);
n.l.b = true;
} else if (R(n.l) && R(n.l.r)) {
n = RtLR(n);
n.l.b = true;
} else if (R(n.r) && R(n.r.l)) {
n = RtRL(n);
n.r.b = true;
} else if (R(n.r) && R(n.r.r)) {
n = RtL(n);
n.r.b = true;
} else
ch = false;
return n;
}
public void Remove(T x) {
r = Rm(r, x);
if (r != null)
r.b = true;
}
Node Rm(Node n, T x) {
if (n == null) {
ch = false;
return n;
}
n.c--;
var r = c(x, n.v);
if (r < 0) {
n.l = Rm(n.l, x);
return BlL(n);
}
if (r > 0) {
n.r = Rm(n.r, x);
return BlR(n);
}
if (n.l == null) {
ch = n.b;
return n.r;
}
n.l = RmM(n.l);
n.v = lm;
return BlL(n);
}
Node RmM(Node n) {
n.c--;
if (n.r != null) {
n.r = RmM(n.r);
return BlR(n);
}
lm = n.v;
ch = n.b;
return n.l;
}
Node BlL(Node n) {
if (!ch)
return n;
if (B(n.r) && R(n.r.l)) {
var b = n.b;
n = RtRL(n);
n.b = b;
n.l.b = true;
ch = false;
} else if (B(n.r) && R(n.r.r)) {
var b = n.b;
n = RtL(n);
n.b = b;
n.r.b = true;
n.l.b = true;
ch = false;
} else if (B(n.r)) {
ch = n.b;
n.b = true;
n.r.b = false;
} else {
n = RtL(n);
n.b = true;
n.l.b = false;
n.l = BlL(n.l);
ch = false;
}
return n;
}
Node BlR(Node n) {
if (!ch)
return n;
if (B(n.l) && R(n.l.r)) {
var b = n.b;
n = RtLR(n);
n.b = b;
n.r.b = true;
ch = false;
} else if (B(n.l) && R(n.l.l)) {
var b = n.b;
n = RtR(n);
n.b = b;
n.l.b = true;
n.r.b = true;
ch = false;
} else if (B(n.l)) {
ch = n.b;
n.b = true;
n.l.b = false;
} else {
n = RtR(n);
n.b = true;
n.r.b = false;
n.r = BlR(n.r);
ch = false;
}
return n;
}
public T this[long i] {
get { return At(r, i); }
}
T At(Node n, long i) {
if (n == null)
return default(T);
if (n.l == null)
if (i == 0)
return n.v;
else
return At(n.r, i - 1);
if (n.l.c == i)
return n.v;
if (n.l.c > i)
return At(n.l, i);
return At(n.r, i - n.l.c - 1);
}
public bool Have(T x) {
var t = FindUpper(x);
return t < C(r) && c(At(r, t), x) == 0;
}
public long FindUpper(T x, bool allowSame = true) => allowSame
? FL(r, x) + 1
: FU(r, x);
long FU(Node n, T x) {
if (n == null)
return 0;
var r = c(x, n.v);
if (r < 0)
return FU(n.l, x);
return C(n.l) + 1 + FU(n.r, x);
}
public long FindLower(T x, bool allowSame = true) {
var t = FL(r, x);
if (allowSame)
return t + 1 < C(r) && c(At(r, t + 1), x) == 0 ? t + 1
: t < 0 ? C(r)
: t;
return t < 0 ? C(r) : t;
}
long FL(Node n, T x) {
if (n == null)
return -1;
var r = c(x, n.v);
if (r > 0)
return C(n.l) + 1 + FL(n.r, x);
return FL(n.l, x);
}
public T Min() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.l;
}
return p == null ? default(T) : p.v;
}
public T Max() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.r;
}
return p == null ? default(T) : p.v;
}
public bool Any() => r != null;
public long Count() => C(r);
public IEnumerable<T> List() => L(r);
IEnumerable<T> L(Node n) {
if (n == null)
yield break;
foreach (var i in L(n.l))
yield return i;
yield return n.v;
foreach (var i in L(n.r))
yield return i;
}
}
class Dict<K, V> : Dictionary<K, V> {
Func<K, V> d;
public Dict(Func<K, V> _d) { d = _d; }
public Dict() : this(_ => default(V)) {}
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = d(i);
}
set { base[i] = value; }
}
public override int GetHashCode() {
var ret = 0;
for (var e = GetEnumerator(); e.MoveNext();) {
ret ^= e.Current.Key.GetHashCode();
ret ^= e.Current.Value.GetHashCode();
}
return ret;
}
public override bool Equals(object obj) {
var o = (Dict<K, V>)obj;
foreach (var kv in o) {
if (!ContainsKey(kv.Key) || !this[kv.Key].Equals(kv.Value))
return false;
}
return o.Count == Count;
}
}
class Deque<T> {
T[] b;
int o, c;
public int Count;
public T this[int i] {
get { return b[gi(i)]; }
set { b[gi(i)] = value; }
}
public Deque(int cap = 16) { b = new T[c = cap]; }
int gi(int i) {
if (i >= c)
throw new Exception();
var r = o + i;
return r >= c ? r - c : r;
}
public void PushFront(T x) {
if (Count == c)
e();
if (--o < 0)
o += b.Length;
b[o] = x;
++Count;
}
public T PopFront() {
if (Count-- == 0)
throw new Exception();
var r = b[o++];
if (o >= c)
o -= c;
return r;
}
public T Front => b[o];
public void PushBack(T x) {
if (Count == c)
e();
var i = o + Count++;
b[i >= c ? i - c : i] = x;
}
public T PopBack() {
if (Count == 0)
throw new Exception();
return b[gi(--Count)];
}
public T Back => b[gi(Count - 1)];
void e() {
T[] nb = new T[c << 1];
if (o > c - Count) {
var l = b.Length - o;
Array.Copy(b, o, nb, 0, l);
Array.Copy(b, 0, nb, l, Count - l);
} else
Array.Copy(b, o, nb, 0, Count);
b = nb;
o = 0;
c <<= 1;
}
public void Insert(int i, T x) {
if (i > Count)
throw new Exception();
this.PushFront(x);
for (int j = 0; j < i; j++)
this[j] = this[j + 1];
this[i] = x;
}
public T RemoveAt(int i) {
if (i < 0 || i >= Count)
throw new Exception();
var r = this[i];
for (int j = i; j > 0; j--)
this[j] = this[j - 1];
this.PopFront();
return r;
}
}
class SegTree<T> {
int n;
T ti;
Func<T, T, T> f;
T[] dat;
public SegTree(long _n, T _ti, Func<T, T, T> _f) {
n = 1;
while (n < _n)
n <<= 1;
ti = _ti;
f = _f;
dat = Repeat(ti, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public void Update(long i, T v) {
dat[i += n] = v;
while ((i >>= 1) > 0)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public T Query(long l, long r) {
var vl = ti;
var vr = ti;
for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, dat[li++]);
if ((ri & 1) == 1)
vr = f(dat[--ri], vr);
}
return f(vl, vr);
}
public T this[long idx] {
get { return dat[idx + n]; }
set { Update(idx, value); }
}
}
class LazySegTree<T, E> {
int n, height;
T ti;
E ei;
Func<T, T, T> f;
Func<T, E, T> g;
Func<E, E, E> h;
T[] dat;
E[] laz;
public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g,
Func<E, E, E> _h) {
n = 1;
height = 0;
while (n < _n) {
n <<= 1;
++height;
}
ti = _ti;
ei = _ei;
f = _f;
g = _g;
h = _h;
dat = Repeat(ti, n << 1).ToArray();
laz = Repeat(ei, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f,
Func<T, E, T> _g, Func<E, E, E> _h)
: this(l.Count, _ti, _ei, _f, _g, _h) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]);
void Eval(long i) {
if (laz[i].Equals(ei))
return;
laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]);
laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]);
dat[i] = Reflect(i);
laz[i] = ei;
}
void Thrust(long i) {
for (var j = height; j > 0; j--)
Eval(i >> j);
}
void Recalc(long i) {
while ((i >>= 1) > 0)
dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1));
}
public void Update(long l, long r, E v) {
Thrust(l += n);
Thrust(r += n - 1);
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1) {
laz[li] = h(laz[li], v);
++li;
}
if ((ri & 1) == 1) {
--ri;
laz[ri] = h(laz[ri], v);
}
}
Recalc(l);
Recalc(r);
}
public T Query(long l, long r) {
Thrust(l += n);
Thrust(r += n - 1);
var vl = ti;
var vr = ti;
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, Reflect(li++));
if ((ri & 1) == 1)
vr = f(Reflect(--ri), vr);
}
return f(vl, vr);
}
public T this[long idx] {
get {
Thrust(idx += n);
return dat[idx] = Reflect(idx);
}
set {
Thrust(idx += n);
dat[idx] = value;
laz[idx] = ei;
Recalc(idx);
}
}
}
class SlidingWindowAggregation<T> {
T[][] l;
T[][] a;
int[] n;
Func<T, T, T> f;
public SlidingWindowAggregation(IEnumerable<T> ary, Func<T, T, T> _f) {
l = new T[2][];
a = new T[2][];
n = new int[2];
f = _f;
l[0] = new T[16];
a[0] = new T[16];
n[0] = 0;
if (ary.Any()) {
var t = ary.ToArray();
n[1] = t.Length;
l[1] = new T[n[1]];
a[1] = new T[n[1]];
for (var i = 0; i < l[1].Length; i++) {
l[1][i] = t[i];
if (i == 0)
a[1][i] = t[i];
else
a[1][i] = this.f(a[1][i - 1], t[i]);
}
} else {
l[1] = new T[16];
a[1] = new T[16];
n[1] = 0;
}
}
public SlidingWindowAggregation(Func<T, T, T> f) : this(new T[0], f) {}
public int Count => n[0] + n[1];
void Push(int la, T v) {
if (l[la].Length == n[la]) {
var nar = new T[n[la] * 2];
var nag = new T[n[la] * 2];
Array.Copy(l[la], nar, n[la]);
Array.Copy(a[la], nag, n[la]);
l[la] = nar;
a[la] = nag;
}
if (n[la] == 0)
a[la][0] = v;
else
a[la][n[la]] = la == 0 ? f(v, a[la][n[la] - 1]) : f(a[la][n[la] - 1], v);
l[la][n[la]++] = v;
}
public void PushBack(T val) => Push(1, val);
public void PushFront(T val) => Push(0, val);
public T Pop(int la) {
var lb = 1 - la;
if (n[la] == 0) {
if (n[lb] == 0)
throw new Exception();
var m = (n[lb] - 1) / 2;
if (l[la].Length <= m) {
l[la] = new T[m + 1];
a[la] = new T[m + 1];
}
n[la] = 0;
for (var i = m; i >= 0; i--) {
if (n[la] == 0)
a[la][n[la]] = l[lb][i];
else
a[la][n[la]] = la == 0 ? f(l[lb][i], a[la][n[la] - 1])
: f(a[la][n[la] - 1], l[lb][i]);
l[la][n[la]++] = l[lb][i];
}
for (var i = m + 1; i < n[lb]; i++) {
var j = i - m - 1;
if (j == 0)
a[lb][j] = l[lb][i];
else
a[lb][j] =
la == 0 ? f(l[lb][i], a[lb][j - 1]) : f(a[lb][j - 1], l[lb][i]);
l[lb][j] = l[lb][i];
}
n[lb] -= n[la];
}
return l[la][--n[la]];
}
public T PopBack() => Pop(1);
public T PopFront() => Pop(0);
public T Aggregate() {
if (n[0] == 0 && n[1] == 0)
throw new Exception();
else if (n[1] == 0)
return a[0][n[0] - 1];
else if (n[0] == 0)
return a[1][n[1] - 1];
else
return f(a[0][n[0] - 1], a[1][n[1] - 1]);
}
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["-", 8, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["-", 8, 196, 0, 7, 8, 1, 0, 11, 31, 22], ["-", 0, 7, 8, 1, 0, 11, 0, 202, 0, 107], ["-", 8, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 1, 0, 11, 12, 16, 17, 48], ["-", 8, 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], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
| 8
| 9,720
| 33
|
using System;
namespace A {
class Program {
static void Main(string[] args) {
string[] AB = Console.ReadLine().Split(' ');
int A = int.Parse(AB[0]);
int B = int.Parse(AB[1]);
int C = A - (B * 2);
if (C < 0) {
Console.WriteLine("0");
} else {
Console.WriteLine(A % (B * 2));
}
}
}
}
|
using System;
namespace A {
class Program {
static void Main(string[] args) {
string[] AB = Console.ReadLine().Split(' ');
int A = int.Parse(AB[0]);
int B = int.Parse(AB[1]);
int C = A - (B * 2);
if (C < 0) {
Console.WriteLine("0");
} else {
Console.WriteLine(C);
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 48], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 110
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC143B {
class Input {
/// <summary>
/// 1行の入力を取得する
/// </summary>
/// <returns>文字列</returns>
public string String() { return Console.ReadLine(); }
/// <summary>
/// 複数行の入力を取得
/// </summary>
/// <returns>文字列の配列</returns>
public string[] ArrayString(int rowNumber) {
string[] s = new string[rowNumber];
for (int i = 0; i < rowNumber; i++) {
s[i] = String();
}
return s;
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>int型の値</returns>
public int Int() { return int.Parse(String()); }
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>int型の配列</returns>
public int[] ArrayInt() { return Split().Select(int.Parse).ToArray(); }
/// <summary>
/// 複数行の入力を取得
/// </summary>
/// <param name="rowNumber">行数</param>
/// <returns>int型の配列</returns>
public int[] ArrayInt(int rowNumber) {
int[] ints = new int[rowNumber];
for (int i = 0; i < rowNumber; i++) {
ints[i] = Int();
}
return ints;
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>long型の値</returns>
public long Long() { return long.Parse(String()); }
/// <summary>
/// 2つの整数が1行に書かれている入力を、2つのlongで受け取る
/// </summary>
/// <param name="A"></param>
/// <param name="B"></param>
public void Longs(ref long A, ref long B) {
var longs = ArrayLong();
A = longs[0];
B = longs[1];
}
/// <summary>
/// 3つの整数が1行に書かれている入力を、3つのlongで受け取る
/// </summary>
/// <param name="A"></param>
/// <param name="B"></param>
/// <param name="C"></param>
public void Longs(ref long A, ref long B, ref long C) {
var longs = ArrayLong();
A = longs[0];
B = longs[1];
C = longs[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 Longs(ref long A, ref long B, ref long C, ref long D) {
var longs = ArrayLong();
A = longs[0];
B = longs[1];
C = longs[2];
D = longs[3];
}
/// <summary>
/// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="A"></param>
/// <param name="B"></param>
public void LongsArray(long rowNumber, ref long[] A, ref long[] B) {
A = new long[rowNumber];
B = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
var l = ArrayLong();
A[i] = l[0];
B[i] = l[1];
}
}
/// <summary>
/// 3つの整数が複数行に書かれている入力を、2つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="A"></param>
/// <param name="B"></param>
/// <param name="C"></param>
public void LongsArray(long rowNumber, ref long[] A, ref long[] B,
ref long[] C) {
A = new long[rowNumber];
B = new long[rowNumber];
C = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
var l = ArrayLong();
A[i] = l[0];
B[i] = l[1];
C[i] = l[2];
}
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>long型の配列</returns>
public long[] ArrayLong() { return Split().Select(long.Parse).ToArray(); }
public long[] ArrayLong(int rowNumber) {
long[] longs = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
longs[i] = Long();
}
return longs;
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の値</returns>
public double Double() { return double.Parse(String()); }
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の配列</returns>
public double[] ArrayDouble() {
return Split().Select(double.Parse).ToArray();
}
private IEnumerable<string> Split() { return String().Split(' '); }
}
class Program {
static void Main(string[] args) {
Solver solver = new Solver();
solver.Solve();
}
}
class Solver {
public Solver() {
Input input = new Input();
N = input.Long();
D = input.ArrayLong();
}
private long N;
private long[] D;
public void Solve() {
long ans = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i == j) {
continue;
}
ans += D[i] * D[j];
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC143B {
class Input {
/// <summary>
/// 1行の入力を取得する
/// </summary>
/// <returns>文字列</returns>
public string String() { return Console.ReadLine(); }
/// <summary>
/// 複数行の入力を取得
/// </summary>
/// <returns>文字列の配列</returns>
public string[] ArrayString(int rowNumber) {
string[] s = new string[rowNumber];
for (int i = 0; i < rowNumber; i++) {
s[i] = String();
}
return s;
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>int型の値</returns>
public int Int() { return int.Parse(String()); }
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>int型の配列</returns>
public int[] ArrayInt() { return Split().Select(int.Parse).ToArray(); }
/// <summary>
/// 複数行の入力を取得
/// </summary>
/// <param name="rowNumber">行数</param>
/// <returns>int型の配列</returns>
public int[] ArrayInt(int rowNumber) {
int[] ints = new int[rowNumber];
for (int i = 0; i < rowNumber; i++) {
ints[i] = Int();
}
return ints;
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>long型の値</returns>
public long Long() { return long.Parse(String()); }
/// <summary>
/// 2つの整数が1行に書かれている入力を、2つのlongで受け取る
/// </summary>
/// <param name="A"></param>
/// <param name="B"></param>
public void Longs(ref long A, ref long B) {
var longs = ArrayLong();
A = longs[0];
B = longs[1];
}
/// <summary>
/// 3つの整数が1行に書かれている入力を、3つのlongで受け取る
/// </summary>
/// <param name="A"></param>
/// <param name="B"></param>
/// <param name="C"></param>
public void Longs(ref long A, ref long B, ref long C) {
var longs = ArrayLong();
A = longs[0];
B = longs[1];
C = longs[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 Longs(ref long A, ref long B, ref long C, ref long D) {
var longs = ArrayLong();
A = longs[0];
B = longs[1];
C = longs[2];
D = longs[3];
}
/// <summary>
/// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="A"></param>
/// <param name="B"></param>
public void LongsArray(long rowNumber, ref long[] A, ref long[] B) {
A = new long[rowNumber];
B = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
var l = ArrayLong();
A[i] = l[0];
B[i] = l[1];
}
}
/// <summary>
/// 3つの整数が複数行に書かれている入力を、2つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="A"></param>
/// <param name="B"></param>
/// <param name="C"></param>
public void LongsArray(long rowNumber, ref long[] A, ref long[] B,
ref long[] C) {
A = new long[rowNumber];
B = new long[rowNumber];
C = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
var l = ArrayLong();
A[i] = l[0];
B[i] = l[1];
C[i] = l[2];
}
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>long型の配列</returns>
public long[] ArrayLong() { return Split().Select(long.Parse).ToArray(); }
public long[] ArrayLong(int rowNumber) {
long[] longs = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
longs[i] = Long();
}
return longs;
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の値</returns>
public double Double() { return double.Parse(String()); }
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の配列</returns>
public double[] ArrayDouble() {
return Split().Select(double.Parse).ToArray();
}
private IEnumerable<string> Split() { return String().Split(' '); }
}
class Program {
static void Main(string[] args) {
Solver solver = new Solver();
solver.Solve();
}
}
class Solver {
public Solver() {
Input input = new Input();
N = input.Long();
D = input.ArrayLong();
}
private long N;
private long[] D;
public void Solve() {
long ans = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
ans += D[i] * D[j];
}
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 25], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 871
| 14
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;
class Sobaya {
static void Main() {
new Sobaya().calc();
return;
}
Scanner cin;
void calc() {
cin = new Scanner();
int n = cin.nextInt();
long[] a = cin.ArrayLong(n);
long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - 1 - i; j++) {
ans += a[i] * a[j];
}
}
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;
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;
class Sobaya {
static void Main() {
new Sobaya().calc();
return;
}
Scanner cin;
void calc() {
cin = new Scanner();
int n = cin.nextInt();
long[] a = cin.ArrayLong(n);
long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
ans += a[i] * a[j];
}
}
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;
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 7, 15, 16, 12, 16, 31, 16, 17, 33], ["-", 0, 7, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22]]
| 8
| 516
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder_solve {
class Program {
public const ulong mod = 1000000007;
static void Main(string[] args)
{
long n = long.Parse(Console.ReadLine());
var s = Console.ReadLine().ToArray();
// string ss = "";
ulong ans = 0;
for (long i = 1; i < n; i++) {
if (s[i - 1] != s[i]) {
ans++;
if (i == n - 1)
ans++;
}
// Console.WriteLine(ss);
}
if (ans == 0)
ans++;
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder_solve {
class Program {
public const ulong mod = 1000000007;
static void Main(string[] args)
{
long n = long.Parse(Console.ReadLine());
var s = Console.ReadLine().ToArray();
// string ss = "";
ulong ans = 1;
for (long i = 1; i < n; i++) {
if (s[i - 1] != s[i]) {
ans++;
}
// Console.WriteLine(ss);
}
// ans++;
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["-", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 64, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["-", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["-", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 149
| 22
|
using System;
class P {
static void Main() {
string color = Console.ReadLine();
char c = color[0];
int count = 1;
for (int i = 1; i < color.Length; i++) {
if (c != color[i]) {
c = color[i];
count++;
}
}
Console.WriteLine(count);
}
}
|
using System;
class P {
static void Main() {
string a = Console.ReadLine();
string color = Console.ReadLine();
char c = color[0];
int count = 1;
for (int i = 1; i < color.Length; i++) {
if (c != color[i]) {
c = color[i];
count++;
}
}
Console.WriteLine(count);
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 82
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atc_0027 {
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
if (s.Length % 2 == 1) {
Console.WriteLine("No");
return;
}
string h = s.Substring(0, s.Length / 2);
if ((h + h) == s) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atc_0027 {
class Program {
static void Main(string[] args) {
string n = Console.ReadLine();
string s = Console.ReadLine();
if (s.Length % 2 == 1) {
Console.WriteLine("No");
return;
}
string h = s.Substring(0, (s.Length / 2));
if ((h + h) == s) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 23, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 23, 0, 25]]
| 8
| 127
| 11
|
using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
namespace AtCoder_B___Echo {
class Program {
const string yes = "Yes";
const string no = "No";
static void Main(string[] args) {
string s = Console.ReadLine();
int halflength = s.Length / 2;
Console.WriteLine(
s.Take(halflength).SequenceEqual(s.Skip(halflength)) ? yes : no);
}
}
}
|
using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
namespace AtCoder_B___Echo {
class Program {
const string yes = "Yes";
const string no = "No";
static void Main(string[] args) {
string length = Console.ReadLine();
string s = Console.ReadLine();
int halflength = s.Length / 2;
Console.WriteLine(
s.Take(halflength).SequenceEqual(s.Skip(halflength)) ? yes : no);
}
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 96
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
if (1 < N) {
if ((S.Substring(0, N / 2) == S.Substring(N / 2, N / 2)) && N % 2 == 0) {
Console.WriteLine("Yes");
} else if ((S.Substring(0, N / 2) == S.Substring(N / 2, N / 2 + 1)) &&
N % 2 != 0) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else {
Console.WriteLine("No");
}
}
}
}
// 文字列の入力
// string s = Console.ReadLine();
// 整数の入力
// long n = long.Parse(Console.ReadLine());
// 文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
// 整数配列の入力
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
if (1 < N) {
if (N % 2 == 0) {
if ((S.Substring(0, N / 2) == S.Substring(N / 2, N / 2)) &&
N % 2 == 0) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else {
if (S.Substring(0, N / 2) == S.Substring(N / 2, N / 2 + 1)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
} else {
Console.WriteLine("No");
}
}
}
}
// 文字列の入力
// string s = Console.ReadLine();
// 整数の入力
// long n = long.Parse(Console.ReadLine());
// 文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
// 整数配列の入力
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
|
[["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 64, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["-", 64, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["-", 75, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 75, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["-", 75, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 79], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 203
| 32
|
using System;
namespace Sample {
class Sample {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
string ans1 = S.Substring(0, (N / 2));
string ans2 = S.Substring((N / 2), (N / 2));
if ((N >= 2) && (ans1 == ans2)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
namespace Sample {
class Sample {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
string ans1 = S.Substring(0, (N / 2));
string ans2 = S.Substring((N / 2), (N / 2));
if ((N >= 2) && (N % 2 == 0) && (ans1 == ans2)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["+", 31, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["+", 31, 16, 12, 23, 0, 16, 31, 16, 17, 109], ["+", 31, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 60], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24]]
| 8
| 118
| 8
|
using System;
namespace ABC145B {
class Program {
static void Main(string[] args) {
int a = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
int x = 0;
for (int i = 0; i <= a / 2 - 1; i++) {
if (s[i] == s[a / 2 + i])
x += 1;
}
if (x == a / 2)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
}
|
using System;
namespace ABC145B {
class Program {
static void Main(string[] args) {
int a = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
int x = 0;
for (int i = 0; i <= a / 2 - 1; i++) {
if (s[i] == s[a / 2 + i])
x += 1;
}
if (a % 2 != 0)
x -= 1;
if (x == a / 2)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 110], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24]]
| 8
| 117
| 12
|
using System;
using System.Collections.Generic;
namespace Echo {
class Program {
static void Main(string[] args) {
var inputN = int.Parse(Console.ReadLine());
string inputS = Console.ReadLine();
List<char> inputString = new List<char>(inputS);
int middlePoint = inputString.Count / 2;
if (middlePoint == 0) {
Console.WriteLine("No");
return;
}
for (int i = 0; i < middlePoint; i++) {
if (inputString[i] != inputString[middlePoint + i]) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
}
|
using System;
using System.Collections.Generic;
namespace Echo {
class Program {
static void Main(string[] args) {
var inputN = int.Parse(Console.ReadLine());
string inputS = Console.ReadLine();
List<char> inputString = new List<char>(inputS);
int middlePoint = inputString.Count / 2;
if (inputN % 2 != 0) {
Console.WriteLine("No");
return;
} else {
for (int i = 0; i < middlePoint; i++) {
if (inputString[i] != inputString[middlePoint + i]) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 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
| 147
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
static class Program {
static void Main() {
Solve();
Console.ReadKey();
}
static void Solve() {
var N = IO.GetInt();
var S = IO.GetString();
var ans = "Yes";
for (int i = 0; i < N / 2; i++) {
if (S[i] != S[i + N / 2]) {
ans = "No";
break;
}
}
Console.WriteLine(ans);
}
}
static class IO {
static public string GetString() { return Console.ReadLine(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public List<string> GetStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> GetIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> GetLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteStrings<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
static class Program {
static void Main() {
Solve();
Console.ReadKey();
}
static void Solve() {
var N = IO.GetInt();
var S = IO.GetString();
var ans = "Yes";
if (N % 2 != 0) {
ans = "No";
} else {
for (int i = 0; i < N / 2; i++) {
if (S[i] != S[i + N / 2]) {
ans = "No";
break;
}
}
}
Console.WriteLine(ans);
}
}
static class IO {
static public string GetString() { return Console.ReadLine(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public List<string> GetStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> GetIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> GetLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteStrings<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 62], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 369
| 19
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp7 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
string ans = "Yes";
for (int i = 0; i < N / 2; i++) {
if (S[i] != S[i + (N / 2)]) {
ans = "No";
break;
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp7 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
string ans = "Yes";
if (N % 2 == 0) {
for (int i = 0; i < N / 2; i++) {
if (S[i] != S[i + (N / 2)]) {
ans = "No";
break;
}
}
} else {
ans = "No";
}
Console.WriteLine(ans);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 5, 0, 62], ["+", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 129
| 19
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;
using Number = System.Int64;
class Solver {
Scanner sc = new Scanner();
//
public void Solve() {
var N = sc.Int;
var str = ReadLine();
if (str.Length % 2 == 1)
Fail("No");
WriteLine(new string(str.Take(str.Length / 2).ToArray()) ==
new string(str.Skip(str.Length / 2).ToArray())
? "Yes"
: "No");
;
}
}
#region Template
public class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve();
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == 1) {
num = val;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == -1) {
num = val;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T v1, ref T v2) {
var t = v2;
v2 = v1;
v1 = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
StreamReader sr;
public Scanner() { sr = new StreamReader(Console.OpenStandardInput()); }
public Scanner(string path) { sr = new StreamReader(path); }
public string Str => sr.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);
public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(),
Next<T2>());
public Pair<T1, T2, T3> PairMake<T1, T2, T3>() =>
new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>());
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 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 static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;
using Number = System.Int64;
class Solver {
Scanner sc = new Scanner();
//
public void Solve() {
var N = int.Parse(ReadLine());
var str = ReadLine();
if (str.Length % 2 == 1)
Fail("No");
WriteLine(new string(str.Take(str.Length / 2).ToArray()) ==
new string(str.Skip(str.Length / 2).ToArray())
? "Yes"
: "No");
;
}
}
#region Template
public class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve();
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == 1) {
num = val;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == -1) {
num = val;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T v1, ref T v2) {
var t = v2;
v2 = v1;
v1 = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
StreamReader sr;
public Scanner() { sr = new StreamReader(Console.OpenStandardInput()); }
public Scanner(string path) { sr = new StreamReader(path); }
public string Str => sr.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);
public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(),
Next<T2>());
public Pair<T1, T2, T3> PairMake<T1, T2, T3>() =>
new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>());
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 class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2> p) {
var c = Comparer<T1>.Default.Compare(v1, p.v1);
if (c == 0)
c = Comparer<T2>.Default.Compare(v2, p.v2);
return c;
}
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public void Deconstruct(out T1 a, out T2 b) {
a = v1;
b = v2;
}
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() {}
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2, T3> p) {
var c = base.CompareTo(p);
if (c == 0)
c = Comparer<T3>.Default.Compare(v3, p.v3);
return c;
}
public override string ToString() => $"{base.ToString()} {v3.ToString()}";
public void Deconstruct(out T1 a, out T2 b, out T3 c) {
Deconstruct(out a, out b);
c = v3;
}
}
#endregion
|
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 1,619
| 9
|
using System;
namespace abab145 {
class Program {
static void Main(string[] args) {
int a;
string b;
a = int.Parse(Console.ReadLine());
b = Console.ReadLine();
int len = b.Length;
var n = (len / 2) - 1;
var g = len - 1;
var c = n + 1;
var l = len / 2;
var str1 = b.Substring(0, l);
var str2 = b.Substring(l, l);
if (a >= 2 && a % 2 == 0) {
if (b == str1 + str2) {
Console.WriteLine("Yes");
}
}
else
Console.WriteLine("No");
}
}
}
|
using System;
namespace abab145 {
class Program {
static void Main(string[] args) {
int a;
string b;
a = int.Parse(Console.ReadLine());
b = Console.ReadLine();
int len = b.Length;
var n = (len / 2) - 1;
var g = len - 1;
var c = n + 1;
var l = len / 2;
var str1 = b.Substring(0, l);
var str2 = b.Substring(l, l);
if (a >= 2 && a % 2 == 0)
if (str1 == str2) {
Console.WriteLine("Yes");
} else
Console.WriteLine("No");
else
Console.WriteLine("No");
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["-", 64, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 57, 64, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 64, 57, 0, 95], ["+", 64, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 57, 75, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 57, 75, 1, 0, 35]]
| 8
| 155
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
int a = int.Parse(Console.ReadLine());
string b = Console.ReadLine();
if (a % 2 == 0) {
if (b.Substring(b.Length / 2) == b.Substring(0, b.Length / 2)) {
Console.WriteLine("Yes");
}
} else {
Console.Write("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
int a = int.Parse(Console.ReadLine());
string b = Console.ReadLine();
if (a % 2 == 0) {
if (b.Substring(b.Length / 2) == b.Substring(0, b.Length / 2)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else {
Console.WriteLine("No");
}
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22]]
| 8
| 128
| 14
|
using System;
using System.IO;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace atcoder {
class Program {
//メイン関数
static void Main(string[] args) {
int n = int.Parse(ReadLine());
string s = ReadLine();
if (s.Substring(0, s.Length / 2) == s.Substring(s.Length / 2, s.Length / 2))
WriteLine("Yes");
else
WriteLine("No");
}
#region 細々としたツール(関数)
#region 標準入力
//変数の入力
static string scan() => ReadLine();
static int scanInt() => int.Parse(ReadLine());
static long scanLong() => long.Parse(ReadLine());
//配列の入力
static string[] MultiScan(char Split) {
string[] N = ReadLine().Split(Split);
return N;
}
static string[] MultiScan() {
string[] N = ReadLine().Split(' ');
return N;
}
static List<int> MultiScanInt(char Split) {
string[] N = ReadLine().Split(Split);
List<int> output = new List<int>();
for (int i = 0; i < N.Length; i++) {
output.Add(int.Parse(N[i]));
}
return output;
}
static List<int> MultiScanInt(char Split, int roop) {
string[] N = ReadLine().Split(Split);
List<int> output = new List<int>();
for (int i = 0; i < roop; i++) {
output.Add(int.Parse(N[i]));
}
return output;
}
#endregion
#region 数学関連
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 Lcm(int a, int b) { return a * b / Gcd(a, b); } //最小公倍数
public static int PlusOneSigma(int x, int loop) {
int output = 0;
for (int i = 0; i < loop; i++) {
output = output + x + i;
}
return output;
} //1づつ加算のシグマ
#endregion
#endregion
}
}
|
using System;
using System.IO;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace atcoder {
class Program {
//メイン関数
static void Main(string[] args) {
int n = int.Parse(ReadLine());
string s = ReadLine();
if (s.Length % 2 == 0)
if (s.Substring(0, s.Length / 2) ==
s.Substring(s.Length / 2, s.Length / 2))
WriteLine("Yes");
else
WriteLine("No");
else
WriteLine("No");
}
#region 細々としたツール(関数)
#region 標準入力
//変数の入力
static string scan() => ReadLine();
static int scanInt() => int.Parse(ReadLine());
static long scanLong() => long.Parse(ReadLine());
//配列の入力
static string[] MultiScan(char Split) {
string[] N = ReadLine().Split(Split);
return N;
}
static string[] MultiScan() {
string[] N = ReadLine().Split(' ');
return N;
}
static List<int> MultiScanInt(char Split) {
string[] N = ReadLine().Split(Split);
List<int> output = new List<int>();
for (int i = 0; i < N.Length; i++) {
output.Add(int.Parse(N[i]));
}
return output;
}
static List<int> MultiScanInt(char Split, int roop) {
string[] N = ReadLine().Split(Split);
List<int> output = new List<int>();
for (int i = 0; i < roop; i++) {
output.Add(int.Parse(N[i]));
}
return output;
}
#endregion
#region 数学関連
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 Lcm(int a, int b) { return a * b / Gcd(a, b); } //最小公倍数
public static int PlusOneSigma(int x, int loop) {
int output = 0;
for (int i = 0; i < loop; i++) {
output = output + x + i;
}
return output;
} //1づつ加算のシグマ
#endregion
#endregion
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 64, 57, 0, 24], ["+", 64, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 64, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 64, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 57, 64, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 57, 0, 95], ["+", 0, 57, 64, 57, 75, 1, 0, 213, 63, 22], ["+", 64, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 523
| 18
|
using System;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
bool result = s.Substring(0, n / 2) == s.Substring(n / 2);
Console.WriteLine(result);
}
}
|
using System;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
bool result = s.Substring(0, n / 2) == s.Substring(n / 2);
Console.WriteLine(result ? "Yes" : "No");
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
| 8
| 71
| 8
|
using System;
public class Program {
public void Solve() {
var sc = new Scanner();
int n = sc.NextInt();
string s = sc.Next();
bool f = true;
for (int i = 0; i < n / 2; i++) {
if (s[i] != s[i + n / 2]) {
f = false;
break;
}
}
Console.WriteLine(f ? "Yes" : "No");
}
public static void Main(string[] args) { new Program().Solve(); }
}
class Scanner {
public Scanner() {
_pos = 0;
_line = new string[0];
}
const char Separator = ' ';
private int _pos;
private string[] _line;
#region スペース区切りで取得
public string Next() {
if (_pos >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_pos = 0;
}
return _line[_pos++];
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public double NextDouble() { return double.Parse(Next()); }
#endregion
#region 型変換
private int[] ToIntArray(string[] array) {
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
private long[] ToLongArray(string[] array) {
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
private double[] ToDoubleArray(string[] array) {
var result = new double[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = double.Parse(array[i]);
}
return result;
}
#endregion
#region 配列取得
public string[] Array() {
if (_pos >= _line.Length)
_line = Console.ReadLine().Split(Separator);
_pos = _line.Length;
return _line;
}
public int[] IntArray() { return ToIntArray(Array()); }
public long[] LongArray() { return ToLongArray(Array()); }
public double[] DoubleArray() { return ToDoubleArray(Array()); }
#endregion
}
|
using System;
public class Program {
public void Solve() {
var sc = new Scanner();
int n = sc.NextInt();
string s = sc.Next();
bool f = true;
if (n % 2 != 0) {
Console.WriteLine("No");
return;
}
for (int i = 0; i < n / 2; i++) {
if (s[i] != s[i + n / 2]) {
f = false;
break;
}
}
Console.WriteLine(f ? "Yes" : "No");
}
public static void Main(string[] args) { new Program().Solve(); }
}
class Scanner {
public Scanner() {
_pos = 0;
_line = new string[0];
}
const char Separator = ' ';
private int _pos;
private string[] _line;
#region スペース区切りで取得
public string Next() {
if (_pos >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_pos = 0;
}
return _line[_pos++];
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public double NextDouble() { return double.Parse(Next()); }
#endregion
#region 型変換
private int[] ToIntArray(string[] array) {
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
private long[] ToLongArray(string[] array) {
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
private double[] ToDoubleArray(string[] array) {
var result = new double[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = double.Parse(array[i]);
}
return result;
}
#endregion
#region 配列取得
public string[] Array() {
if (_pos >= _line.Length)
_line = Console.ReadLine().Split(Separator);
_pos = _line.Length;
return _line;
}
public int[] IntArray() { return ToIntArray(Array()); }
public long[] LongArray() { return ToLongArray(Array()); }
public double[] DoubleArray() { return ToDoubleArray(Array()); }
#endregion
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 541
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1 {
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
public class Class1 {
static void Main(string[] args) {
long n = Int64.Parse(Console.ReadLine());
var s = Console.ReadLine().ToCharArray();
if (s.Length % 2 == 1) {
Console.WriteLine("No");
return;
}
for (long i = 0; i < s.Length % 2; i++) {
if (s[i] == s[s.Length + i])
continue;
else {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
return;
}
static int rec(int[] n, int i, int j, int x) {
if (i + 1 == j) {
return Math.Min(n[j], x);
}
return rec(n, i + 1, j, n[i]) + rec(n, i, j - 1, n[j]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1 {
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
public class Class1 {
static void Main(string[] args) {
long n = Int64.Parse(Console.ReadLine());
var s = Console.ReadLine().ToCharArray();
if (s.Length % 2 == 1) {
Console.WriteLine("No");
return;
}
for (long i = 0; i < (n / 2); i++) {
if (s[i] == s[(n / 2) + i])
continue;
else {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
return;
}
static int rec(int[] n, int i, int j, int x) {
if (i + 1 == j) {
return Math.Min(n[j], x);
}
return rec(n, i + 1, j, n[i]) + rec(n, i, j - 1, n[j]);
}
}
}
|
[["-", 0, 7, 15, 16, 12, 16, 31, 214, 205, 22], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 0, 131], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 141, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 109], ["+", 8, 196, 0, 7, 15, 16, 12, 23, 0, 24], ["+", 0, 7, 15, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 7, 15, 16, 12, 23, 0, 16, 17, 85], ["+", 8, 196, 0, 7, 15, 16, 12, 23, 0, 25], ["-", 206, 207, 0, 28, 0, 16, 31, 214, 205, 22], ["-", 206, 207, 0, 28, 0, 16, 31, 214, 0, 131], ["-", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 85], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 206, 207, 0, 28, 0, 16, 31, 23, 0, 25]]
| 8
| 261
| 16
|
using System;
using System.Linq;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var r = int.Parse(Console.ReadLine());
var input = Console.ReadLine().OrderBy(x => x).ToArray();
for (int i = 0; i < input.Length; i += 2) {
if (input.Length <= 1 || input[i] != input[i + 1]) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
}
|
using System;
using System.Linq;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var r = int.Parse(Console.ReadLine());
var input = Console.ReadLine().OrderBy(x => x).ToArray();
for (int i = 0; i < input.Length; i += 2) {
if (input.Length == 1 || input.Length % 2 == 1 ||
input[i] != input[i + 1]) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 31, 16, 12, 16, 31, 16, 31, 214, 205, 22], ["+", 31, 16, 12, 16, 31, 16, 31, 214, 0, 131], ["+", 31, 16, 12, 16, 31, 16, 31, 214, 141, 22], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60]]
| 8
| 122
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp14 {
class Class34 {
static void Main() {
int N = int.Parse(Console.ReadLine());
var x = new double[N];
var y = new double[N];
for (int i = 0; i < N; i++) {
var read = Console.ReadLine().Split().Select(int.Parse).ToArray();
x[i] = read[0];
y[i] = read[1];
}
double ans = 0;
double sum = 0;
int count = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
sum += Math.Sqrt((x[i] - x[j]) * (x[i] - x[j]) +
(y[i] - y[j]) * (y[i] - y[j]));
count++;
}
}
ans = sum / count * 2;
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp14 {
class Class34 {
static void Main() {
int N = int.Parse(Console.ReadLine());
var x = new double[N];
var y = new double[N];
for (int i = 0; i < N; i++) {
var read = Console.ReadLine().Split().Select(int.Parse).ToArray();
x[i] = read[0];
y[i] = read[1];
}
double ans = 0;
double sum = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
sum += Math.Sqrt((x[i] - x[j]) * (x[i] - x[j]) +
(y[i] - y[j]) * (y[i] - y[j]));
}
}
ans = sum * 2 / N;
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 85], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 256
| 12
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
class Program {
static void Main() {
var n = Console.ReadLine().ToInt32();
var xy = new List<long[]>();
for (int i = 0; i < n; i++) {
var a = System.Console.ReadLine()
.Split(' ')
.Select((x) => long.Parse(x))
.ToArray();
xy.Add(a);
}
double disSum = 0;
var cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j)
continue;
var disX = Math.Pow(xy[i][0] - xy[j][0], 2);
var disY = Math.Pow(xy[i][1] - xy[j][1], 2);
var disXY = Math.Sqrt(disX + disY);
disSum += disXY;
cnt++;
}
}
var ans = disSum * 2 / cnt;
Output(ans.ToString());
}
private static void Output(string str) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Console.WriteLine(str);
Console.Out.Flush();
}
}
static class Extentions {
#region 拡張メソッド(string)
public static string LeftB(this string stTarget, int iByteSize) {
return MidB(stTarget, 1, iByteSize);
}
public static string MidB(this string stTarget, int iStart) {
System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8");
byte[] bBytes = hEncoding.GetBytes(stTarget);
return hEncoding.GetString(bBytes, iStart - 1, bBytes.Length - iStart + 1);
}
public static string MidB(this string stTarget, int iStart, int iByteSize) {
System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8");
byte[] bBytes = hEncoding.GetBytes(stTarget);
return hEncoding.GetString(bBytes, iStart - 1, iByteSize);
}
public static string RightB(this string stTarget, int iByteSize) {
System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8");
byte[] bBytes = hEncoding.GetBytes(stTarget);
return hEncoding.GetString(bBytes, bBytes.Length - iByteSize, iByteSize);
}
public static bool IsNullOrEmpty(this string str) {
return string.IsNullOrEmpty(str);
}
/// <summary>
/// カルチャに依存した比較、または大文字と小文字を区別しない比較などの序数による比較を指定できる
/// Contains。
/// </summary>
/// <param name="value">対象文字列</param>
/// <param name="partialValue">部分文字列</param>
/// <param
/// name="comparison">カルチャ、大文字と小文字の区別、および並べ替え規則を指定する
/// StringComparison</param> <returns>一致する場合に true
/// を返します。</returns>
public static bool Contains(this string value, string partialValue,
StringComparison comparison = 0) {
return value.IndexOf(partialValue, comparison) >= 0;
}
public static bool IsNumeric(this string value) {
return decimal.TryParse(value, out decimal d);
}
public static int ToInt32(this String number, int retValue = 0) {
if (!number.IsNumeric())
return retValue;
return int.Parse(number);
}
#endregion
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
class Program {
static void Main() {
var n = Console.ReadLine().ToInt32();
var xy = new List<double[]>();
for (int i = 0; i < n; i++) {
var a = System.Console.ReadLine()
.Split(' ')
.Select((x) => double.Parse(x))
.ToArray();
xy.Add(a);
}
double disSum = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
var disX = Math.Pow(xy[i][0] - xy[j][0], 2);
var disY = Math.Pow(xy[i][1] - xy[j][1], 2);
var disXY = Math.Sqrt(disX + disY);
disSum += disXY;
}
}
var ans = disSum * 2 / n;
Output(ans.ToString());
}
private static void Output(string str) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Console.WriteLine(str);
Console.Out.Flush();
}
}
static class Extentions {
#region 拡張メソッド(string)
public static string LeftB(this string stTarget, int iByteSize) {
return MidB(stTarget, 1, iByteSize);
}
public static string MidB(this string stTarget, int iStart) {
System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8");
byte[] bBytes = hEncoding.GetBytes(stTarget);
return hEncoding.GetString(bBytes, iStart - 1, bBytes.Length - iStart + 1);
}
public static string MidB(this string stTarget, int iStart, int iByteSize) {
System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8");
byte[] bBytes = hEncoding.GetBytes(stTarget);
return hEncoding.GetString(bBytes, iStart - 1, iByteSize);
}
public static string RightB(this string stTarget, int iByteSize) {
System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8");
byte[] bBytes = hEncoding.GetBytes(stTarget);
return hEncoding.GetString(bBytes, bBytes.Length - iByteSize, iByteSize);
}
public static bool IsNullOrEmpty(this string str) {
return string.IsNullOrEmpty(str);
}
/// <summary>
/// カルチャに依存した比較、または大文字と小文字を区別しない比較などの序数による比較を指定できる
/// Contains。
/// </summary>
/// <param name="value">対象文字列</param>
/// <param name="partialValue">部分文字列</param>
/// <param
/// name="comparison">カルチャ、大文字と小文字の区別、および並べ替え規則を指定する
/// StringComparison</param> <returns>一致する場合に true
/// を返します。</returns>
public static bool Contains(this string value, string partialValue,
StringComparison comparison = 0) {
return value.IndexOf(partialValue, comparison) >= 0;
}
public static bool IsNumeric(this string value) {
return decimal.TryParse(value, out decimal d);
}
public static int ToInt32(this String number, int retValue = 0) {
if (!number.IsNumeric())
return retValue;
return int.Parse(number);
}
#endregion
}
|
[["-", 0, 230, 39, 236, 237, 238, 0, 224, 39, 199], ["+", 0, 230, 39, 236, 237, 238, 0, 224, 39, 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], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
| 8
| 661
| 26
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
namespace atcorder1 {
class MainClass {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var n = Read();
var x = new long[n];
var y = new long[n];
var d = new double[n * (n - 1) / 2];
double d1 = 1;
for (int i = 0; i < n; i++) {
var input = Reads();
x[i] = input[0];
y[i] = input[1];
}
long c = 1;
for (long i = 1; i < n; i++) {
c *= i;
}
double sum = 0;
int k = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
d1 = Math.Pow(
(x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]), 0.5);
sum += d1;
}
}
Console.WriteLine(c);
Console.WriteLine(sum * 2 / n);
Console.Out.Flush();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
namespace atcorder1 {
class MainClass {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var n = Read();
var x = new long[n];
var y = new long[n];
var d = new double[n * (n - 1) / 2];
double d1 = 1;
for (int i = 0; i < n; i++) {
var input = Reads();
x[i] = input[0];
y[i] = input[1];
}
long c = 1;
for (long i = 1; i < n; i++) {
c *= i;
}
double sum = 0;
int k = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
d1 = Math.Pow(
(x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]), 0.5);
sum += d1;
}
}
Console.WriteLine(sum * 2 / n);
Console.Out.Flush();
}
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
| 8
| 365
| 7
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
static void Main(string[] args) {
var r = ReadSplit();
var x = r[0].ToInt64();
var y = r[1].ToInt64();
var ans = Combination((x + y) / 3, (2 * y - x) / 3);
if ((x + y) % 3 != 0)
ans = 0;
WriteRead(ans);
}
private static long mod = 1000000007;
public static long ModPow(long x, long n) {
x = x % mod;
if (n == 0) {
return 1;
} else if (n % 2 == 1) {
return (x * ModPow(x, n - 1)) % mod;
} else {
return ModPow((x * x) % mod, n / 2) % mod;
}
}
public static long Combination(long n, long k) {
long x = 1;
for (long i = n - k + 1; i <= n; i++) {
x = x * i % mod;
}
long y = 1;
for (int i = 1; i <= k; i++) {
y = y * i % mod;
}
y = ModPow(y, mod - 2);
return x * y % mod;
}
/// <summary>
/// 最小公倍数
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
public static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
}
}
public static class Extentions {
public static int ToInt32(this object obj) {
return int.Parse(obj.ToString());
}
public static long ToInt64(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal ToDecimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double ToDouble(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value))
{
return value;
}
return new T2();
}
}
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
static void Main(string[] args) {
var r = ReadSplit();
var x = r[0].ToInt64();
var y = r[1].ToInt64();
var ans = Combination((x + y) / 3, (2 * y - x) / 3);
if ((x + y) % 3 != 0 || x > 2 * y || y > 2 * x)
ans = 0;
WriteRead(ans);
}
private static long mod = 1000000007;
public static long ModPow(long x, long n) {
x = x % mod;
if (n == 0) {
return 1;
} else if (n % 2 == 1) {
return (x * ModPow(x, n - 1)) % mod;
} else {
return ModPow((x * x) % mod, n / 2) % mod;
}
}
public static long Combination(long n, long k) {
long x = 1;
for (long i = n - k + 1; i <= n; i++) {
x = x * i % mod;
}
long y = 1;
for (int i = 1; i <= k; i++) {
y = y * i % mod;
}
y = ModPow(y, mod - 2);
return x * y % mod;
}
/// <summary>
/// 最小公倍数
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
public static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
}
}
public static class Extentions {
public static int ToInt32(this object obj) {
return int.Parse(obj.ToString());
}
public static long ToInt64(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal ToDecimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double ToDouble(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value))
{
return value;
}
return new T2();
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 47], ["+", 15, 16, 31, 16, 12, 16, 12, 16, 31, 203], ["+", 15, 16, 31, 16, 12, 16, 12, 16, 17, 48], ["+", 15, 16, 31, 16, 12, 16, 12, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 31, 203], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 48], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 22]]
| 8
| 598
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC145D_2 {
class Program {
static void Main(string[] args) {
var XY = ReadInt();
int X = XY[0];
int Y = XY[1];
bool canGo = true;
if ((2 * X - Y) % 3 != 0)
canGo = false;
if ((2 * Y - X) % 3 != 0)
canGo = false;
if (canGo) {
int mod = 1000000007;
int a = (2 * X - Y) / 3;
int b = (2 * Y - X) / 3;
var ans = nCk(a + b, a, mod);
Console.WriteLine(ans);
} else
Console.WriteLine(0);
Console.ReadKey();
}
static int[] ReadInt() {
int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
return ret;
}
static long[] ReadLong() {
long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
return ret;
}
/// <summary>
/// a^n (mod p)
/// nが非常に大きい時に有効
/// </summary>
/// <param name="a"></param>
/// <param name="n"></param>
/// <param name="mod"></param>
/// <returns></returns>
public static long ModPow(long a, long n, long p) {
if (n == 0)
return 1;
if (n == 1)
return a % p;
if (n % 2 == 1)
return (a * ModPow(a, n - 1, p)) % p;
long t = ModPow(a, n / 2, p);
return (t * t) % p;
}
/// <summary>
/// 組み合わせ個数
/// </summary>
/// <param name="n"></param>
/// <param name="k"></param>
/// <param name="p"></param>
/// <returns></returns>
public static long nCk(long n, long k, long p) {
long ans = 1;
k = Math.Min(k, n - k);
for (long i = n; i > n - k; i--) {
ans = (ans * i) % p;
}
for (long i = 1; i <= k; i++) {
ans = (ans * ModPow(i, p - 2, p)) % p;
}
return ans;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC145D_2 {
class Program {
static void Main(string[] args) {
var XY = ReadInt();
int X = XY[0];
int Y = XY[1];
bool canGo = true;
if ((2 * X - Y) % 3 != 0 || (2 * X - Y) < 0)
canGo = false;
if ((2 * Y - X) % 3 != 0 || (2 * Y - X) < 0)
canGo = false;
if (canGo) {
int mod = 1000000007;
int a = (2 * X - Y) / 3;
int b = (2 * Y - X) / 3;
var ans = nCk(a + b, a, mod);
Console.WriteLine(ans);
} else
Console.WriteLine(0);
Console.ReadKey();
}
static int[] ReadInt() {
int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
return ret;
}
static long[] ReadLong() {
long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
return ret;
}
/// <summary>
/// a^n (mod p)
/// nが非常に大きい時に有効
/// </summary>
/// <param name="a"></param>
/// <param name="n"></param>
/// <param name="mod"></param>
/// <returns></returns>
public static long ModPow(long a, long n, long p) {
if (n == 0)
return 1;
if (n == 1)
return a % p;
if (n % 2 == 1)
return (a * ModPow(a, n - 1, p)) % p;
long t = ModPow(a, n / 2, p);
return (t * t) % p;
}
/// <summary>
/// 組み合わせ個数
/// </summary>
/// <param name="n"></param>
/// <param name="k"></param>
/// <param name="p"></param>
/// <returns></returns>
public static long nCk(long n, long k, long p) {
long ans = 1;
k = Math.Min(k, n - k);
for (long i = n; i > n - k; i--) {
ans = (ans * i) % p;
}
for (long i = 1; i <= k; i++) {
ans = (ans * ModPow(i, p - 2, p)) % p;
}
return ans;
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 31, 203], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 48], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
| 8
| 446
| 20
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AtCoder.D {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var inputs = ReadLongs();
var X = inputs[0];
var Y = inputs[1];
var b = (2D * X - Y) / 3D;
if (b < 0)
return 0;
if ((int)b != b)
return 0;
var a = X - 2 * b;
return Modular.Combination((long)a + (long)b, (long)a);
}
#region Console
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
public class Modular {
public long Value { get; private set; }
private static readonly long _mod = (long)Math.Pow(10, 9) + 7;
private static readonly List<int> _facCache = new List<int> { 1 };
public static explicit operator long(Modular m) => m.Value;
public static implicit operator Modular(long a) {
var m = a % _mod;
return new Modular { Value = (m < 0) ? m + _mod : m };
}
public static Modular operator +(Modular a, Modular b) => a.Value + b.Value;
public static Modular operator -(Modular a, Modular b) => a.Value - b.Value;
public static Modular operator *(Modular a, Modular b) => a.Value * b.Value;
public static Modular operator /(Modular a, Modular b) => a *
Pow(b, _mod - 2);
public static Modular Pow(Modular a, long n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular Factorial(long n) {
for (int i = _facCache.Count; i <= n; ++i) {
var fac = (int)(Math.BigMul(_facCache.Last(), i) % _mod);
_facCache.Add(fac);
}
return _facCache[(int)n];
}
public static Modular Combination(long n, long r) {
Modular ans = 1;
for (var i = 0; i < r; i++) {
ans *= n - i;
}
for (var i = 1; i <= r; i++) {
ans /= i;
}
return ans;
}
public override string ToString() { return Value.ToString(); }
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AtCoder.D {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var inputs = ReadLongs();
var X = inputs[0];
var Y = inputs[1];
var b = (2D * X - Y) / 3D;
if (b < 0)
return 0;
if ((int)b != b)
return 0;
var a = X - 2 * b;
if (a < 0)
return 0;
if ((int)a != a)
return 0;
return Modular.Combination((long)a + (long)b, (long)a);
}
#region Console
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
public class Modular {
public long Value { get; private set; }
private static readonly long _mod = (long)Math.Pow(10, 9) + 7;
private static readonly List<int> _facCache = new List<int> { 1 };
public static explicit operator long(Modular m) => m.Value;
public static implicit operator Modular(long a) {
var m = a % _mod;
return new Modular { Value = (m < 0) ? m + _mod : m };
}
public static Modular operator +(Modular a, Modular b) => a.Value + b.Value;
public static Modular operator -(Modular a, Modular b) => a.Value - b.Value;
public static Modular operator *(Modular a, Modular b) => a.Value * b.Value;
public static Modular operator /(Modular a, Modular b) => a *
Pow(b, _mod - 2);
public static Modular Pow(Modular a, long n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular Factorial(long n) {
for (int i = _facCache.Count; i <= n; ++i) {
var fac = (int)(Math.BigMul(_facCache.Last(), i) % _mod);
_facCache.Add(fac);
}
return _facCache[(int)n];
}
public static Modular Combination(long n, long r) {
Modular ans = 1;
for (var i = 0; i < r; i++) {
ans *= n - i;
}
for (var i = 1; i <= r; i++) {
ans /= i;
}
return ans;
}
public override string ToString() { return Value.ToString(); }
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 196, 0, 57, 15, 16, 31, 74, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 74, 39, 199], ["+", 8, 196, 0, 57, 15, 16, 31, 74, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 74, 51, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38]]
| 8
| 660
| 21
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static long P = 1000000007;
static void Main(string[] args) {
var xy = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int x = xy[0];
int y = xy[1];
long max = Math.Max(x, y);
long min = Math.Min(x, y);
long dif = max - min;
if ((min - dif) % 3 != 0) {
Console.WriteLine(0);
return;
}
long n = dif + (min - dif) / 3 * 2;
long k = (min - dif) / 3;
long[] fact = new long[n + 1];
long[] invfact = new long[n + 1];
long[] inv = new long[n + 1];
fact[0] = fact[1] = 1;
invfact[0] = invfact[1] = 1;
inv[1] = 1;
for (int i = 2; i < n + 1; i++) {
fact[i] = fact[i - 1] * i % P;
inv[i] = P - inv[P % i] * (P / i) % P;
invfact[i] = invfact[i - 1] * inv[i] % P;
}
long ans = (((fact[n] * invfact[n - k]) % P) * invfact[k]) % P;
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static long P = 1000000007;
static void Main(string[] args) {
var xy = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int x = xy[0];
int y = xy[1];
long max = Math.Max(x, y);
long min = Math.Min(x, y);
long dif = max - min;
if ((min - dif) % 3 != 0) {
Console.WriteLine(0);
return;
}
long n = dif + (min - dif) / 3 * 2;
long k = (min - dif) / 3;
if (n < k || n < 0 || k < 0) {
Console.WriteLine(0);
return;
}
long[] fact = new long[n + 1];
long[] invfact = new long[n + 1];
long[] inv = new long[n + 1];
fact[0] = fact[1] = 1;
invfact[0] = invfact[1] = 1;
inv[1] = 1;
for (int i = 2; i < n + 1; i++) {
fact[i] = fact[i - 1] * i % P;
inv[i] = P - inv[P % i] * (P / i) % P;
invfact[i] = invfact[i - 1] * inv[i] % P;
}
long ans = (((fact[n] * invfact[n - k]) % P) * invfact[k]) % P;
Console.WriteLine(ans);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 18], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 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, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 373
| 25
|
using System;
using System.Collections.Generic;
namespace Application {
class MainClass {
const long MOD = 1000000007;
public static void Main(string[] args) {
var xy = Console.ReadLine().Split();
var x = long.Parse(xy[0]);
var y = long.Parse(xy[1]);
if ((x + y) % 3 != 0) {
Console.WriteLine(0);
return;
}
var n = (x + y) / 3;
var m = x - n;
if (m < 0) {
Console.WriteLine(0);
return;
}
var ans = divM(factM(n), factM(n - m) * factM(m) % MOD);
Console.WriteLine(ans);
}
static long factM(long n) {
var ans = 1L;
for (long i = 2; i <= n; i++) {
ans *= i;
ans %= MOD;
}
return ans;
}
static long powM(long n, long m) {
if (m == 0)
return 1;
if (m % 2 == 1)
return n * powM(n, m - 1) % MOD;
var x = powM(n, m / 2);
return x * x % MOD;
}
static long divM(long n, long m) { return n * powM(m, MOD - 2) % MOD; }
}
}
|
using System;
using System.Collections.Generic;
namespace Application {
class MainClass {
const long MOD = 1000000007;
public static void Main(string[] args) {
var xy = Console.ReadLine().Split();
var x = long.Parse(xy[0]);
var y = long.Parse(xy[1]);
if ((x + y) % 3 != 0) {
Console.WriteLine(0);
return;
}
var n = (2 * y - x) / 3;
var m = (2 * x - y) / 3;
if (n < 0 || m < 0) {
Console.WriteLine(0);
return;
}
var ans = divM(factM(n + m), factM(n) * factM(m) % MOD);
Console.WriteLine(ans);
}
static long factM(long n) {
var ans = 1L;
for (long i = 2; i <= n; i++) {
ans *= i;
ans %= MOD;
}
return ans;
}
static long powM(long n, long m) {
if (m == 0)
return 1;
if (m % 2 == 1)
return n * powM(n, m - 1) % MOD;
var x = powM(n, m / 2);
return x * x % MOD;
}
static long divM(long n, long m) { return n * powM(m, MOD - 2) % MOD; }
}
}
|
[["-", 0, 212, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 31, 203], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 48], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 294
| 22
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Threading;
using System.Threading.Tasks;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var X = cin.ReadInt;
var Y = cin.ReadInt;
if (2 * Y < X || Y > 2 * X || (X * 2 - Y) % 3 != 0 ||
(Y * 2 - X) % 3 != 0) {
Console.WriteLine(0);
return;
}
var X2 = (X * 2 - Y) / 3;
var Y2 = (Y * 2 - X) / 3;
var MOD = 1000000007L;
// (X2+Y2)_C_X2
var facts = new long[X2 + Y2 + 1];
var invs = new long[X2 + Y2 + 1];
facts[0] = 1;
for (var i = 1; i <= X2 + Y2; i++) {
facts[i] = (facts[i - 1] * i) % MOD;
invs[i] = ModInv(facts[i], MOD);
}
var ans = (((facts[X2 + Y2] * invs[X2]) % MOD) * invs[Y2]) % MOD;
Console.WriteLine(ans);
}
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
static long ExtGcd(long a, long b, ref long x, ref long y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
long d = ExtGcd(b, a % b, ref y, ref x);
y -= a / b * x;
return d;
}
static long ModInv(long a, long mod) {
long x = 0, y = 0;
ExtGcd(a, mod, ref x, ref y);
if (x < 0)
x += mod; // modInv will never be negative
return x;
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Threading;
using System.Threading.Tasks;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var X = cin.ReadInt;
var Y = cin.ReadInt;
if (2 * Y < X || Y > 2 * X || (X * 2 - Y) % 3 != 0 ||
(Y * 2 - X) % 3 != 0) {
Console.WriteLine(0);
return;
}
var X2 = (X * 2 - Y) / 3;
var Y2 = (Y * 2 - X) / 3;
var MOD = 1000000007L;
// (X2+Y2)_C_X2
var facts = new long[X2 + Y2 + 1];
var invs = new long[X2 + Y2 + 1];
facts[0] = 1;
invs[0] = 1;
for (var i = 1; i <= X2 + Y2; i++) {
facts[i] = (facts[i - 1] * i) % MOD;
invs[i] = ModInv(facts[i], MOD);
}
var ans = (((facts[X2 + Y2] * invs[X2]) % MOD) * invs[Y2]) % MOD;
Console.WriteLine(ans);
}
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
static long ExtGcd(long a, long b, ref long x, ref long y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
long d = ExtGcd(b, a % b, ref y, ref x);
y -= a / b * x;
return d;
}
static long ModInv(long a, long mod) {
long x = 0, y = 0;
ExtGcd(a, mod, ref x, ref y);
if (x < 0)
x += mod; // modInv will never be negative
return x;
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 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
| 770
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var waaaa = new waaaa();
waaaa.Solve();
}
}
public class waaaa {
const int MOD = 1000000007;
const long INF = 1 << 61;
const int MOD2 = 998244353;
Scaner cin = new Scaner();
write cout = new write();
Math2 mmath = new Math2();
public void Solve() {
mmath.FactoricalModSet(1000000);
//ここから
var o = cin.LongM;
var X = o[0];
var Y = o[1];
if (X >= 3 * Y || Y >= 3 * X)
cout.wri(0);
else if ((2 * X - Y) / 3 < 0)
cout.wri(0);
else if ((X + Y) / 3 < (2 * X - Y) / 3)
cout.wri(0);
else
cout.wri(mmath.nCr((X + Y) / 3, (2 * X - Y) / 3));
}
public static bool NextPermutation<T>(T[] array, int start, int length)
where T : IComparable {
int end = start + length - 1;
// 範囲が狭すぎる
if (end <= start)
return false;
int last = end;
while (true) {
int pos = last--;
if (array[last].CompareTo(array[pos]) < 0) {
int i;
for (i = end + 1; array[last].CompareTo(array[--i]) >= 0;) {
}
T tmp = array[last];
array[last] = array[i];
array[i] = tmp;
Array.Reverse(array, pos, end - pos + 1);
return true;
}
if (last == start) // 最後の順列
{
Array.Reverse(array, start, end - start);
return false;
}
}
// ここに来ることはない
throw new Exception("NextPermutation: Fatal error");
}
}
// b-aで降順
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
public class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
// Nまでの階乗をセットしておく
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = pow(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
// nCr 引数:n r (mod)
public long nCr(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
//階乗(O(logN)) 引数:底x n乗 (MOD)
public long pow(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
//最大公約数 引数:整数x,y
public long GCD(long x, long y) {
while (y != 0) {
var r = x % y;
x = y;
y = r;
}
return x;
}
//最小公倍数 引数:整数x,y
public long LCM(long x, long y) { return x * y / GCD(x, y); }
//素因数分解 引数:整数N
public Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> PrimeFactorization2(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
namespace CompLib.Algorithms {
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrM => Str.Split(' ');
public long[] LongM => StrM.Select(long.Parse).ToArray();
public int[] IntM => StrM.Select(int.Parse).ToArray();
public char[] CharM => Str.ToArray();
public long Long1 => LongM[0];
public int Int1 => IntM[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var waaaa = new waaaa();
waaaa.Solve();
}
}
public class waaaa {
const int MOD = 1000000007;
const long INF = 1 << 61;
const int MOD2 = 998244353;
Scaner cin = new Scaner();
write cout = new write();
Math2 mmath = new Math2();
public void Solve() {
mmath.FactoricalModSet(1000000);
//ここから
var o = cin.LongM;
var X = o[0];
var Y = o[1];
if ((X + Y) % 3 != 0)
cout.wri(0);
else if (X >= 3 * Y || Y >= 3 * X)
cout.wri(0);
else if ((2 * X - Y) / 3 < 0)
cout.wri(0);
else if ((X + Y) / 3 < (2 * X - Y) / 3)
cout.wri(0);
else
cout.wri(mmath.nCr((X + Y) / 3, (2 * X - Y) / 3));
}
public static bool NextPermutation<T>(T[] array, int start, int length)
where T : IComparable {
int end = start + length - 1;
// 範囲が狭すぎる
if (end <= start)
return false;
int last = end;
while (true) {
int pos = last--;
if (array[last].CompareTo(array[pos]) < 0) {
int i;
for (i = end + 1; array[last].CompareTo(array[--i]) >= 0;) {
}
T tmp = array[last];
array[last] = array[i];
array[i] = tmp;
Array.Reverse(array, pos, end - pos + 1);
return true;
}
if (last == start) // 最後の順列
{
Array.Reverse(array, start, end - start);
return false;
}
}
// ここに来ることはない
throw new Exception("NextPermutation: Fatal error");
}
}
// b-aで降順
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
public class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
// Nまでの階乗をセットしておく
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = pow(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
// nCr 引数:n r (mod)
public long nCr(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
//階乗(O(logN)) 引数:底x n乗 (MOD)
public long pow(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
//最大公約数 引数:整数x,y
public long GCD(long x, long y) {
while (y != 0) {
var r = x % y;
x = y;
y = r;
}
return x;
}
//最小公倍数 引数:整数x,y
public long LCM(long x, long y) { return x * y / GCD(x, y); }
//素因数分解 引数:整数N
public Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> PrimeFactorization2(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
namespace CompLib.Algorithms {
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrM => Str.Split(' ');
public long[] LongM => StrM.Select(long.Parse).ToArray();
public int[] IntM => StrM.Select(int.Parse).ToArray();
public char[] CharM => Str.ToArray();
public long Long1 => LongM[0];
public int Int1 => IntM[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
[["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24]]
| 8
| 1,749
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC145D {
class Program {
static void Main(string[] args) {
var xy = Cin.LArr();
var solver = new Solver(xy[0], xy[1]);
Console.WriteLine(solver.Solve());
}
}
class Solver {
private long x;
private long y;
public Solver(long X, long Y) {
x = X;
y = Y;
}
public IConvertible Solve() {
int a = 0;
int b = 0;
if ((x + y) % 3 != 0) {
return 0;
}
while (x + y >= 3) {
if (x >= y) {
x -= 2;
y -= 1;
a++;
continue;
}
if (y > x) {
y -= 2;
x -= 1;
b++;
}
}
return (int)Modular.Ncr(a + b, a);
}
}
class Modular {
public static int M = 1000000007;
private long V;
public Modular(long v) { V = v; }
public static implicit operator Modular(long a) {
var m = a % M;
return new Modular(m < 0 ? m + M : m);
}
public static Modular operator +(Modular a, Modular b) { return a.V + b.V; }
public static Modular operator -(Modular a, Modular b) { return a.V - b.V; }
public static Modular operator *(Modular a, Modular b) { return a.V * b.V; }
public static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b) {
return a * Pow(b, M - 2);
}
private static readonly List<int> Facts = new List<int> { 1 };
public static Modular Fac(int n) {
for (int i = Facts.Count; i <= n; ++i) {
Facts.Add((int)(Math.BigMul(Facts.Last(), i) % M));
}
return Facts[n];
}
public static Modular Ncr(int n, int r) {
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
return Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a) { return (int)a.V; }
}
internal static class Cin {
public static string String() { return Console.ReadLine(); }
public static int Int() { return int.Parse(String()); }
public static int[] IArr() { return Split().Select(int.Parse).ToArray(); }
public static long Long() { return long.Parse(String()); }
public static long[] LArr() { return Split().Select(long.Parse).ToArray(); }
public static double Double() { return double.Parse(String()); }
public static double[] DArr() {
return Split().Select(double.Parse).ToArray();
}
private static IEnumerable<String> Split() { return String().Split(' '); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC145D {
class Program {
static void Main(string[] args) {
var xy = Cin.LArr();
var solver = new Solver(xy[0], xy[1]);
Console.WriteLine(solver.Solve());
}
}
class Solver {
private long x;
private long y;
public Solver(long X, long Y) {
x = X;
y = Y;
}
public IConvertible Solve() {
int a = 0;
int b = 0;
if ((x + y) % 3 != 0) {
return 0;
}
while (x + y >= 3) {
if (x >= y) {
x -= 2;
y -= 1;
a++;
} else {
y -= 2;
x -= 1;
b++;
}
}
if (x != 0 || y != 0) {
return 0;
}
return (int)Modular.Ncr(a + b, a);
}
}
class Modular {
public static int M = 1000000007;
private long V;
public Modular(long v) { V = v; }
public static implicit operator Modular(long a) {
var m = a % M;
return new Modular(m < 0 ? m + M : m);
}
public static Modular operator +(Modular a, Modular b) { return a.V + b.V; }
public static Modular operator -(Modular a, Modular b) { return a.V - b.V; }
public static Modular operator *(Modular a, Modular b) { return a.V * b.V; }
public static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b) {
return a * Pow(b, M - 2);
}
private static readonly List<int> Facts = new List<int> { 1 };
public static Modular Fac(int n) {
for (int i = Facts.Count; i <= n; ++i) {
Facts.Add((int)(Math.BigMul(Facts.Last(), i) % M));
}
return Facts[n];
}
public static Modular Ncr(int n, int r) {
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
return Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a) { return (int)a.V; }
}
internal static class Cin {
public static string String() { return Console.ReadLine(); }
public static int Int() { return int.Parse(String()); }
public static int[] IArr() { return Split().Select(int.Parse).ToArray(); }
public static long Long() { return long.Parse(String()); }
public static long[] LArr() { return Split().Select(long.Parse).ToArray(); }
public static double Double() { return double.Parse(String()); }
public static double[] DArr() {
return Split().Select(double.Parse).ToArray();
}
private static IEnumerable<String> Split() { return String().Split(' '); }
}
}
|
[["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 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, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
| 8
| 742
| 24
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;
namespace SolutionCS {
class Program {
class modMCalc {
private const int M = 1000000007; // 素数(int範囲)
// 乗算結果 % Mを求める
static public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); }
// 冪乗(mod M)
static public int Pow(int a, int m) {
if (0 == m) {
return 1;
}
if (1 == m) {
return a;
}
int result = 1;
int param = a;
for (; m > 0; m >>= 1) {
if ((m & 0x01) == 1) {
result = Mul(result, param);
}
param = Mul(param, param);
}
return result;
}
// 除算(mod M)
static public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); }
}
class CombinationPermutation {
private readonly int[] fac;
// コンストラクタ
// (mod Mの)階乗テーブル作成する
public CombinationPermutation(int n) {
fac = new int[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; ++i) {
fac[i] = modMCalc.Mul(fac[i - 1], i);
}
}
// 階乗求める
public int Factorial(int n) { return fac[n]; }
// nPr
public int nPr(int n, int r) {
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int result = Factorial(n);
result = modMCalc.Div(result, Factorial(n - r));
return result;
}
// nCr
public int nCr(int n, int r) {
return modMCalc.Div(nPr(n, r), Factorial(r));
}
}
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(' ');
int X = int.Parse(s[0]);
int Y = int.Parse(s[1]);
if (0 != ((X + Y) % 3)) {
Console.WriteLine(0);
return;
}
if (X > Y * 2 || Y > X * 2) {
Console.WriteLine(0);
return;
}
int total = (X + Y) / 3;
int ont = (2 * Y - X) / 3;
CombinationPermutation p = new CombinationPermutation(total);
int ans = p.nCr(total, ont);
Console.WriteLine(ans);
return;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;
namespace SolutionCS {
class Program {
class modMCalc {
private const int M = 1000000007; // 素数(int範囲)
// 乗算結果 % Mを求める
static public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); }
// 冪乗(mod M)
static public int Pow(int a, int m) {
if (0 == m) {
return 1;
}
if (1 == m) {
return a;
}
int result = 1;
int param = a;
for (; m > 0; m >>= 1) {
if ((m & 0x01) == 1) {
result = Mul(result, param);
}
param = Mul(param, param);
}
return result;
}
// 除算(mod M)
static public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); }
}
class CombinationPermutation {
private readonly int[] fac;
// コンストラクタ
// (mod Mの)階乗テーブル作成する
public CombinationPermutation(int n) {
fac = new int[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; ++i) {
fac[i] = modMCalc.Mul(fac[i - 1], i);
}
}
// 階乗求める
public int Factorial(int n) { return fac[n]; }
// nPr
public int nPr(int n, int r) {
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int result = Factorial(n);
result = modMCalc.Div(result, Factorial(n - r));
return result;
}
// nCr
public int nCr(int n, int r) {
return modMCalc.Div(nPr(n, r), Factorial(r));
}
}
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(' ');
int X = int.Parse(s[0]);
int Y = int.Parse(s[1]);
if (0 != ((X + Y) % 3)) {
Console.WriteLine(0);
return;
}
if (X > Y * 2 || Y > X * 2) {
Console.WriteLine(0);
return;
}
if (X < Y) {
int t = Y;
Y = X;
X = t;
}
int total = (X + Y) / 3;
int ont = (2 * Y - X) / 3;
CombinationPermutation p = new CombinationPermutation(total);
int ans = p.nCr(total, ont);
Console.WriteLine(ans);
return;
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 538
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
public class ABC {
// long[] sp = Console.ReadLine().Split().Select(long
// .Parse).ToArray(); int[] sp =
// Console.ReadLine().Split().Select(int.Parse).ToArray(); int N =
// int.Parse(Console.ReadLine());
// CompLib.Collections.PriorityQueue<?>
public static Dictionary<Tuple<int, int>, int> dictionary;
public static void Main() {
Util.factorial_modM_Prepare(10000000);
int X = 0, Y = 0;
new readint(out X, out Y);
Console.WriteLine(DP(X, Y));
}
public static int DP(int X, int Y) {
if ((X + Y) % 3 != 0)
return 0;
else {
int leftX = (X + Y) / 3;
int a = X - leftX;
return Util.nCr_modM(leftX, a);
}
}
}
class readint {
public readint(out int i) { i = int.Parse(Console.ReadLine()); }
public readint(out int a, out int b) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readint(out int a, out int b, out int c) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readint(out int a, out int b, out int c, out int d) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class readlong {
public readlong(out long i) { i = long.Parse(Console.ReadLine()); }
public readlong(out long a, out long b) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readlong(out long a, out long b, out long c) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readlong(out long a, out long b, out long c, out long d) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class Util {
public static long GCD(long a, long b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
public static int GCD(int a, int b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
public static void swap<T>(ref T a, ref T b) {
T temp = b;
b = a;
a = temp;
}
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); }
public static int M = (int)(Math.Pow(10, 9)) + 7;
private static int[] factorial_modM;
public static int Multiple_modM(int a, int b) {
return (int)(Math.BigMul(a, b) % M);
}
public static void factorial_modM_Prepare(int n) {
factorial_modM = new int[n + 1];
factorial_modM[0] = 1;
for (int i = 1; i <= n; ++i) {
factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i);
}
}
public static int Factorial(int n) { return factorial_modM[n]; }
public static int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Multiple_modM(p1, p1);
return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a);
}
}
public static int Div(int a, int b) {
return Multiple_modM(a, Pow(b, M - 2));
}
public static int nCr_modM(int n, int r) {
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int res = Factorial(n);
res = Div(res, Factorial(r));
res = Div(res, Factorial(n - r));
return res;
}
}
class UnionFind<T> {
public int tree_height;
public UnionFind<T> parent;
public T item { get; private set; }
public UnionFind(T item) {
tree_height = 0;
parent = this;
}
public UnionFind<T> FindAdam() {
if (parent == this)
return this;
else {
UnionFind<T> ParentOfParent = parent.FindAdam();
parent = ParentOfParent; //縦長な構成をつなぎ直している
return ParentOfParent;
}
}
public static void Unite(UnionFind<T> a, UnionFind<T> b) {
UnionFind<T> ParentOfA = a.FindAdam();
UnionFind<T> ParentOfB = b.FindAdam();
if (ParentOfA.tree_height < ParentOfB.tree_height) {
ParentOfA.parent = ParentOfB;
ParentOfB.tree_height =
Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height);
} else {
ParentOfB.parent = ParentOfA;
ParentOfA.tree_height =
Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height);
}
}
}
// Treap 平衡二分木
class Treap<T>
where T : IComparable {
private class Node {
private static Random g_rand = new Random();
private readonly int m_rank = g_rand.Next();
private readonly T m_value;
private Node m_lch;
private Node m_rch;
private int m_count;
public Node(T value) {
m_value = value;
m_count = 1;
}
private static int Count(Node node) {
return (node != null) ? node.m_count : 0;
}
private Node Update() {
m_count = Count(m_lch) + Count(m_rch) + 1;
return this;
}
public static Node Merge(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
if (a.m_rank < b.m_rank) {
a.m_rch = Merge(a.m_rch, b);
return a.Update();
} else {
b.m_lch = Merge(a, b.m_lch);
return b.Update();
}
}
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null) {
return new Tuple<Node, Node>(null, null);
}
if (k <= Count(t.m_lch)) {
var pair = Split(t.m_lch, k);
t.m_lch = pair.Item2;
return new Tuple<Node, Node>(pair.Item1, t.Update());
} else {
var pair = Split(t.m_rch, k - Count(t.m_lch) - 1);
t.m_rch = pair.Item1;
return new Tuple<Node, Node>(t.Update(), pair.Item2);
}
}
public int FindIndex(T value) {
int L = Count(m_lch);
if (value.CompareTo(m_value) < 0) {
return (m_lch != null) ? m_lch.FindIndex(value) : 0;
} else if (value.CompareTo(m_value) > 0) {
return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1;
} else {
return L;
}
}
public T this[int i] {
get {
int L = Count(m_lch);
if (i < L) {
return m_lch[i];
} else if (i > L) {
return m_rch[i - L - 1];
} else {
return m_value;
}
}
}
}
private Node node;
public void Insert(T value) {
if (node != null) {
int k = node.FindIndex(value);
var pair = Node.Split(node, k);
node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2);
} else {
node = new Node(value);
}
}
public int FindIndex(T value) { return node.FindIndex(value); }
public T this[int i] {
get { return node[i]; }
}
}
static class Permutation<T> {
private static void Search(List<T[]> perms, Stack<T> stack, T[] a) {
int N = a.Length;
if (N == 0) {
perms.Add(stack.Reverse().ToArray());
} else {
var b = new T[N - 1];
Array.Copy(a, 1, b, 0, N - 1);
for (int i = 0; i < a.Length; ++i) {
stack.Push(a[i]);
Search(perms, stack, b);
if (i < b.Length) {
b[i] = a[i];
}
stack.Pop();
}
}
}
public static IEnumerable<T[]> All(IEnumerable<T> src) {
var perms = new List<T[]>();
Search(perms, new Stack<T>(), src.ToArray());
return perms;
}
}
namespace CompLib.Collections {
#region PriorityQueue
/// <summary>
/// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します.
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam>
/// <remarks>内部的にはバイナリヒープによって実装されています.</remarks>
public class PriorityQueue<T> {
readonly List<T> heap = new List<T>();
readonly Comparison<T> cmp;
/// <summary>
/// デフォルトの比較子を使用してインスタンスを初期化します.
/// </summary>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue() { cmp = Comparer<T>.Default.Compare; }
/// <summary>
/// デリゲートで表されるような比較関数を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparison"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }
/// <summary>
/// 指定された比較子を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparer"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; }
/// <summary>
/// 優先度付きキューに要素を追加します.
/// </summary>
/// <param name="item">優先度付きキューに追加される要素</param>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public void Enqueue(T item) {
var pos = heap.Count;
heap.Add(item);
while (pos > 0) {
var par = (pos - 1) / 2;
if (cmp(heap[par], item) <= 0)
break;
heap[pos] = heap[par];
pos = par;
}
heap[pos] = item;
}
/// <summary>
/// 優先度付きキューから最も価値が低い要素を削除し,返します.
/// </summary>
/// <returns>優先度付きキューから削除された要素.</returns>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public T Dequeue() {
var ret = heap[0];
var pos = 0;
var x = heap[heap.Count - 1];
while (pos * 2 + 1 < heap.Count - 1) {
var lch = pos * 2 + 1;
var rch = pos * 2 + 2;
if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0)
lch = rch;
if (cmp(heap[lch], x) >= 0)
break;
heap[pos] = heap[lch];
pos = lch;
}
heap[pos] = x;
heap.RemoveAt(heap.Count - 1);
return ret;
}
/// <summary>
/// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します.
/// </summary>
/// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public T Peek() { return heap[0]; }
/// <summary>
/// 優先度付きキュー内の要素の数を取得します.
/// </summary>
/// <returns>優先度付キュー内にある要素の数</returns>
/// <remarks>最悪計算量 O(1) で実行されます.</remarks>
public int Count {
get { return heap.Count; }
}
/// <summary>
/// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します.
/// </summary>
/// <returns>優先度付キュー内にある要素が存在するならば
/// true,そうでなければ false.</returns> <remarks>この操作は O(1)
/// で実行されます.</remarks>
public bool Any() { return heap.Count > 0; }
/// <summary>
/// 優先度付きキューに含まれる要素を昇順に並べて返します.
/// </summary>
/// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks>
public T[] Items {
get {
var ret = heap.ToArray();
Array.Sort(ret, cmp);
return ret;
}
}
}
#endregion
}
/// <summary>
/// SEGTREEは1-BASE運用でございます
/// よろしくおねがいします
/// </summary>
/// <typeparam name="T"></typeparam>
class Segtree<T> {
int n; //高さ
T[] tree; //本体
Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか
T exnum; //初期値
int count;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.count = 0;
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
this.count = 0;
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) // j番目をxにする
{
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
this.count++;
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
public void delete (int j) {
int i = j + n - 1;
tree[i] = exnum;
int moved = 0;
while (true) {
tree[i + 1] = tree[i];
T check = tree[i];
moved++;
if (moved + j + 2 > count) {
break;
}
}
all_update();
}
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
public class ABC {
// long[] sp = Console.ReadLine().Split().Select(long
// .Parse).ToArray(); int[] sp =
// Console.ReadLine().Split().Select(int.Parse).ToArray(); int N =
// int.Parse(Console.ReadLine());
// CompLib.Collections.PriorityQueue<?>
public static Dictionary<Tuple<int, int>, int> dictionary;
public static void Main() {
Util.factorial_modM_Prepare(10000000);
int X = 0, Y = 0;
/*
for (int i = 1; i <= 100000; i++)
{
for (int j = 1; j <= 100000; j++)
{
int x =DP(i, j);
}
}
*/
new readint(out X, out Y);
Console.WriteLine(DP(X, Y));
}
public static int DP(int X, int Y) {
if ((X + Y) % 3 != 0)
return 0;
else {
int leftX = (X + Y) / 3;
int a = X - leftX;
return Util.nCr_modM(leftX, a);
}
}
}
class readint {
public readint(out int i) { i = int.Parse(Console.ReadLine()); }
public readint(out int a, out int b) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readint(out int a, out int b, out int c) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readint(out int a, out int b, out int c, out int d) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class readlong {
public readlong(out long i) { i = long.Parse(Console.ReadLine()); }
public readlong(out long a, out long b) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readlong(out long a, out long b, out long c) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readlong(out long a, out long b, out long c, out long d) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class Util {
public static long GCD(long a, long b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
public static int GCD(int a, int b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
public static void swap<T>(ref T a, ref T b) {
T temp = b;
b = a;
a = temp;
}
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); }
public static int M = (int)(Math.Pow(10, 9)) + 7;
private static int[] factorial_modM;
public static int Multiple_modM(int a, int b) {
return (int)(Math.BigMul(a, b) % M);
}
public static void factorial_modM_Prepare(int n) {
factorial_modM = new int[n + 1];
factorial_modM[0] = 1;
for (int i = 1; i <= n; ++i) {
factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i);
}
}
public static int Factorial(int n) { return factorial_modM[n]; }
public static int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Multiple_modM(p1, p1);
return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a);
}
}
public static int Div(int a, int b) {
return Multiple_modM(a, Pow(b, M - 2));
}
public static int nCr_modM(int n, int r) {
if (r < 0)
return 0;
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int res = Factorial(n);
res = Div(res, Factorial(r));
res = Div(res, Factorial(n - r));
return res;
}
}
class UnionFind<T> {
public int tree_height;
public UnionFind<T> parent;
public T item { get; private set; }
public UnionFind(T item) {
tree_height = 0;
parent = this;
}
public UnionFind<T> FindAdam() {
if (parent == this)
return this;
else {
UnionFind<T> ParentOfParent = parent.FindAdam();
parent = ParentOfParent; //縦長な構成をつなぎ直している
return ParentOfParent;
}
}
public static void Unite(UnionFind<T> a, UnionFind<T> b) {
UnionFind<T> ParentOfA = a.FindAdam();
UnionFind<T> ParentOfB = b.FindAdam();
if (ParentOfA.tree_height < ParentOfB.tree_height) {
ParentOfA.parent = ParentOfB;
ParentOfB.tree_height =
Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height);
} else {
ParentOfB.parent = ParentOfA;
ParentOfA.tree_height =
Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height);
}
}
}
// Treap 平衡二分木
class Treap<T>
where T : IComparable {
private class Node {
private static Random g_rand = new Random();
private readonly int m_rank = g_rand.Next();
private readonly T m_value;
private Node m_lch;
private Node m_rch;
private int m_count;
public Node(T value) {
m_value = value;
m_count = 1;
}
private static int Count(Node node) {
return (node != null) ? node.m_count : 0;
}
private Node Update() {
m_count = Count(m_lch) + Count(m_rch) + 1;
return this;
}
public static Node Merge(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
if (a.m_rank < b.m_rank) {
a.m_rch = Merge(a.m_rch, b);
return a.Update();
} else {
b.m_lch = Merge(a, b.m_lch);
return b.Update();
}
}
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null) {
return new Tuple<Node, Node>(null, null);
}
if (k <= Count(t.m_lch)) {
var pair = Split(t.m_lch, k);
t.m_lch = pair.Item2;
return new Tuple<Node, Node>(pair.Item1, t.Update());
} else {
var pair = Split(t.m_rch, k - Count(t.m_lch) - 1);
t.m_rch = pair.Item1;
return new Tuple<Node, Node>(t.Update(), pair.Item2);
}
}
public int FindIndex(T value) {
int L = Count(m_lch);
if (value.CompareTo(m_value) < 0) {
return (m_lch != null) ? m_lch.FindIndex(value) : 0;
} else if (value.CompareTo(m_value) > 0) {
return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1;
} else {
return L;
}
}
public T this[int i] {
get {
int L = Count(m_lch);
if (i < L) {
return m_lch[i];
} else if (i > L) {
return m_rch[i - L - 1];
} else {
return m_value;
}
}
}
}
private Node node;
public void Insert(T value) {
if (node != null) {
int k = node.FindIndex(value);
var pair = Node.Split(node, k);
node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2);
} else {
node = new Node(value);
}
}
public int FindIndex(T value) { return node.FindIndex(value); }
public T this[int i] {
get { return node[i]; }
}
}
static class Permutation<T> {
private static void Search(List<T[]> perms, Stack<T> stack, T[] a) {
int N = a.Length;
if (N == 0) {
perms.Add(stack.Reverse().ToArray());
} else {
var b = new T[N - 1];
Array.Copy(a, 1, b, 0, N - 1);
for (int i = 0; i < a.Length; ++i) {
stack.Push(a[i]);
Search(perms, stack, b);
if (i < b.Length) {
b[i] = a[i];
}
stack.Pop();
}
}
}
public static IEnumerable<T[]> All(IEnumerable<T> src) {
var perms = new List<T[]>();
Search(perms, new Stack<T>(), src.ToArray());
return perms;
}
}
namespace CompLib.Collections {
#region PriorityQueue
/// <summary>
/// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します.
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam>
/// <remarks>内部的にはバイナリヒープによって実装されています.</remarks>
public class PriorityQueue<T> {
readonly List<T> heap = new List<T>();
readonly Comparison<T> cmp;
/// <summary>
/// デフォルトの比較子を使用してインスタンスを初期化します.
/// </summary>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue() { cmp = Comparer<T>.Default.Compare; }
/// <summary>
/// デリゲートで表されるような比較関数を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparison"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }
/// <summary>
/// 指定された比較子を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparer"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; }
/// <summary>
/// 優先度付きキューに要素を追加します.
/// </summary>
/// <param name="item">優先度付きキューに追加される要素</param>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public void Enqueue(T item) {
var pos = heap.Count;
heap.Add(item);
while (pos > 0) {
var par = (pos - 1) / 2;
if (cmp(heap[par], item) <= 0)
break;
heap[pos] = heap[par];
pos = par;
}
heap[pos] = item;
}
/// <summary>
/// 優先度付きキューから最も価値が低い要素を削除し,返します.
/// </summary>
/// <returns>優先度付きキューから削除された要素.</returns>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public T Dequeue() {
var ret = heap[0];
var pos = 0;
var x = heap[heap.Count - 1];
while (pos * 2 + 1 < heap.Count - 1) {
var lch = pos * 2 + 1;
var rch = pos * 2 + 2;
if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0)
lch = rch;
if (cmp(heap[lch], x) >= 0)
break;
heap[pos] = heap[lch];
pos = lch;
}
heap[pos] = x;
heap.RemoveAt(heap.Count - 1);
return ret;
}
/// <summary>
/// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します.
/// </summary>
/// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public T Peek() { return heap[0]; }
/// <summary>
/// 優先度付きキュー内の要素の数を取得します.
/// </summary>
/// <returns>優先度付キュー内にある要素の数</returns>
/// <remarks>最悪計算量 O(1) で実行されます.</remarks>
public int Count {
get { return heap.Count; }
}
/// <summary>
/// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します.
/// </summary>
/// <returns>優先度付キュー内にある要素が存在するならば
/// true,そうでなければ false.</returns> <remarks>この操作は O(1)
/// で実行されます.</remarks>
public bool Any() { return heap.Count > 0; }
/// <summary>
/// 優先度付きキューに含まれる要素を昇順に並べて返します.
/// </summary>
/// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks>
public T[] Items {
get {
var ret = heap.ToArray();
Array.Sort(ret, cmp);
return ret;
}
}
}
#endregion
}
/// <summary>
/// SEGTREEは1-BASE運用でございます
/// よろしくおねがいします
/// </summary>
/// <typeparam name="T"></typeparam>
class Segtree<T> {
int n; //高さ
T[] tree; //本体
Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか
T exnum; //初期値
int count;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.count = 0;
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
this.count = 0;
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) // j番目をxにする
{
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
this.count++;
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
public void delete (int j) {
int i = j + n - 1;
tree[i] = exnum;
int moved = 0;
while (true) {
tree[i + 1] = tree[i];
T check = tree[i];
moved++;
if (moved + j + 2 > count) {
break;
}
}
all_update();
}
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24]]
| 8
| 3,134
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using Extensions;
using static System.Math;
using static Extensions.MathExtension;
using static Extensions.ConsoleInputExtension;
using static Extensions.ConsoleOutputExtension;
class Solver {
public void Solve() {
// Solve Code Here
long X = Cin, Y = Cin;
if ((2 * Y - X) % 3 != 0 || (2 * X - Y) % 3 != 0) {
Coutln(0);
return;
}
long k = (2 * X - Y) / 3;
long m = (2 * Y - X) / 3;
ModInt.Mod = 1000000007;
// ModInt km = (ModInt) 1;
// ModInt kk = (ModInt) 1;
// ModInt mm = (ModInt) 1;
// for (long i = 1; i <= k + m; i++) km *= (ModInt) i;
// for (long i = 1; i <= k; i++) kk *= (ModInt) i;
// for (long i = 1; i <= m; i++) mm *= (ModInt) i;
ModInt a = (ModInt)1;
ModInt b = (ModInt)1;
for (long i = Max(k, m) + 1; i <= k + m; i++)
a *= (ModInt)i;
for (long i = 1; i <= Min(k, m); i++)
b *= (ModInt)i;
Coutln(a / b);
}
// Other Functions Here
}
// Other Classes Here
#if !DEBUG
class EntryPoint {
static void Main(string[] args) {
new Solver().Solve();
Flush();
}
}
#endif
class PriorityQueue<T> {
private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>();
public int Count { get; private set; } = 0;
public PriorityQueue() {
_list.Add(null);
_list.Add(null);
_list.Add(null);
}
public void Push(T item, int priority) {
var itemIndex = Count++;
_list[itemIndex] = Tuple.Create(priority, item);
while (_list.Count < Count + 2)
_list.Add(null);
int parentIndex;
while ((parentIndex = GetParentIndex(itemIndex)) != -1 &&
priority > (_list[parentIndex]?.Item1 ?? int.MaxValue)) {
Swap(itemIndex, parentIndex);
itemIndex = parentIndex;
}
}
private int GetParentIndex(int index) {
if (index == 0)
return -1;
return ((index + 1) >> 1) - 1;
}
private Tuple<int, int> GetChildrenIndex(int index) {
var item2 = (index + 1) << 1;
var item1 = item2 - 1;
return item2 >= _list.Count ? null : Tuple.Create(item1, item2);
}
public T Pop() {
if (_list.Count <= 0 || _list[0] == null)
throw new IndexOutOfRangeException();
var item = _list[0].Item2;
_list[0] = null;
Tuple<int, int> childrenIndex;
int index = 0;
while ((childrenIndex = GetChildrenIndex(index)) != null &&
(_list[childrenIndex.Item1] != null ||
_list[childrenIndex.Item2] != null)) {
if ((_list[childrenIndex.Item1]?.Item1 ?? int.MaxValue) >
(_list[childrenIndex.Item2]?.Item1 ?? int.MinValue)) {
_list[index] = _list[childrenIndex.Item1];
_list[childrenIndex.Item1] = null;
index = childrenIndex.Item1;
} else {
_list[index] = _list[childrenIndex.Item2];
_list[childrenIndex.Item2] = null;
index = childrenIndex.Item2;
}
}
Count--;
return item;
}
public T Peek() { return _list[0].Item2; }
private void Swap(int index1, int index2) {
var tmp = _list[index1];
_list[index1] = _list[index2];
_list[index2] = tmp;
}
}
struct Rational {
private long _numerator;
private long _denominator;
public long Numerator => _numerator;
public long Denominator => _denominator;
public Rational(long numerator, long denominator) {
var gcd = GCD(numerator, denominator);
_numerator = numerator / gcd;
_denominator = denominator / gcd;
}
public static Rational operator +(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator +
b._numerator * a._denominator,
a._denominator * b._denominator);
}
public static Rational operator -(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator -
b._numerator * a._denominator,
a._denominator * b._denominator);
}
public static Rational operator *(Rational a, Rational b) {
return new Rational(a._numerator * b._numerator,
a._denominator * b._denominator);
}
public static Rational operator /(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator,
a._denominator * b._numerator);
}
public static explicit operator Rational(int i) { return new Rational(i, 1); }
public static explicit operator Rational(long l) {
return new Rational(l, 1);
}
public static explicit operator Rational(double d) {
long denominator = 1;
while (d % 1 != 0) {
denominator *= 2;
d *= 2;
}
return new Rational((long)d, denominator);
}
public static explicit operator Rational(float f) {
long denominator = 1;
while (f % 1 != 0) {
denominator *= 2;
f *= 2;
}
return new Rational((long)f, denominator);
}
}
struct ModInt {
public long Value { get; }
public static long Mod { get; set; } = 1000000000L + 7;
public ModInt(long l) {
long value = l % Mod;
while (value < 0)
value += Mod;
Value = value % Mod;
}
public static implicit operator long(ModInt m) { return m.Value; }
public static explicit operator ModInt(long l) { return new ModInt(l); }
public static ModInt operator +(ModInt a, ModInt b) {
return new ModInt(a.Value + b.Value);
}
public static ModInt operator -(ModInt a, ModInt b) {
return new ModInt(a.Value - b.Value);
}
public static ModInt operator *(ModInt a, ModInt b) {
return new ModInt(a.Value * b.Value);
}
public static ModInt operator /(ModInt a, ModInt b) {
return new ModInt(a * b.Inverse());
}
public override string ToString() { return Value.ToString(); }
}
static class ModIntMath {
public static ModInt Pow(this ModInt a, ModInt b) {
var pow = b.Value;
var m = a;
ModInt ans = new ModInt(1);
while (pow != 0) {
if ((pow & 1) == 1) {
ans *= m;
}
pow >>= 1;
m *= m;
}
return ans;
}
public static ModInt Inverse(this ModInt m) {
return m.Pow((ModInt)(ModInt.Mod - 2));
}
}
class UnionFind {
private readonly int[] _array;
public UnionFind(int N) {
_array = new int[N];
for (int i = 0; i < N; i++) {
_array[i] = i;
}
}
public int GetRootNode(int n) {
if (_array[n] == n)
return n;
return _array[n] = GetRootNode(_array[n]);
}
public void UnionGroup(int a, int b) {
var rootA = GetRootNode(a);
var rootB = GetRootNode(b);
if (rootA == rootB)
return;
_array[rootA] = rootB;
}
public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b);
public bool IsRoot(int n) => _array[n] == n;
}
namespace Extensions {
public class ConsoleInputExtension {
private static readonly ConsoleInputExtension _cin =
new ConsoleInputExtension();
public static ConsoleInputExtension Cin => _cin;
private static readonly Queue<string> _inputQueue = new Queue<string>();
private ConsoleInputExtension() {}
public static implicit operator string(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return _inputQueue.Dequeue();
}
public static implicit operator int(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return int.Parse(_inputQueue.Dequeue());
}
public static implicit operator long(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return long.Parse(_inputQueue.Dequeue());
}
public static implicit operator float(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return float.Parse(_inputQueue.Dequeue());
}
public static implicit operator double(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return double.Parse(_inputQueue.Dequeue());
}
}
public static class ConsoleOutputExtension {
private static StringBuilder _builder = new StringBuilder();
public static void Cout(object o) { _builder.Append(o); }
public static void CoutF(object o) {
_builder.Append(o);
Flush();
}
public static void Coutln(object o) {
_builder.Append(o);
_builder.Append('\n');
}
public static void Coutln() { _builder.Append('\n'); }
public static void CoutlnF(object o) {
_builder.Append(o);
_builder.Append('\n');
Flush();
}
public static void Flush() {
Console.Write(_builder.ToString());
_builder.Clear();
}
}
public static class MathExtension {
//最小公倍数
public static int LCM(int num1, int num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
public static long LCM(long num1, long num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
//最大公約数
public static int GCD(int num1, int num2) {
int a = Math.Max(num1, num2);
int b = Math.Min(num1, num2);
int mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
public static long GCD(long num1, long num2) {
long a = Math.Max(num1, num2);
long b = Math.Min(num1, num2);
long mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
}
public 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;
using System.Net.NetworkInformation;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using Extensions;
using static System.Math;
using static Extensions.MathExtension;
using static Extensions.ConsoleInputExtension;
using static Extensions.ConsoleOutputExtension;
class Solver {
public void Solve() {
// Solve Code Here
long X = Cin, Y = Cin;
if ((2 * Y - X) % 3 != 0 || (2 * X - Y) % 3 != 0) {
Coutln(0);
return;
}
long k = (2 * X - Y) / 3;
long m = (2 * Y - X) / 3;
if (k < 0 || m < 0) {
Coutln(0);
return;
}
ModInt.Mod = 1000000007;
// ModInt km = (ModInt) 1;
// ModInt kk = (ModInt) 1;
// ModInt mm = (ModInt) 1;
// for (long i = 1; i <= k + m; i++) km *= (ModInt) i;
// for (long i = 1; i <= k; i++) kk *= (ModInt) i;
// for (long i = 1; i <= m; i++) mm *= (ModInt) i;
ModInt a = (ModInt)1;
ModInt b = (ModInt)1;
for (long i = Max(k, m) + 1; i <= k + m; i++)
a *= (ModInt)i;
for (long i = 1; i <= Min(k, m); i++)
b *= (ModInt)i;
Coutln(a / b);
}
// Other Functions Here
}
// Other Classes Here
#if !DEBUG
class EntryPoint {
static void Main(string[] args) {
new Solver().Solve();
Flush();
}
}
#endif
class PriorityQueue<T> {
private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>();
public int Count { get; private set; } = 0;
public PriorityQueue() {
_list.Add(null);
_list.Add(null);
_list.Add(null);
}
public void Push(T item, int priority) {
var itemIndex = Count++;
_list[itemIndex] = Tuple.Create(priority, item);
while (_list.Count < Count + 2)
_list.Add(null);
int parentIndex;
while ((parentIndex = GetParentIndex(itemIndex)) != -1 &&
priority > (_list[parentIndex]?.Item1 ?? int.MaxValue)) {
Swap(itemIndex, parentIndex);
itemIndex = parentIndex;
}
}
private int GetParentIndex(int index) {
if (index == 0)
return -1;
return ((index + 1) >> 1) - 1;
}
private Tuple<int, int> GetChildrenIndex(int index) {
var item2 = (index + 1) << 1;
var item1 = item2 - 1;
return item2 >= _list.Count ? null : Tuple.Create(item1, item2);
}
public T Pop() {
if (_list.Count <= 0 || _list[0] == null)
throw new IndexOutOfRangeException();
var item = _list[0].Item2;
_list[0] = null;
Tuple<int, int> childrenIndex;
int index = 0;
while ((childrenIndex = GetChildrenIndex(index)) != null &&
(_list[childrenIndex.Item1] != null ||
_list[childrenIndex.Item2] != null)) {
if ((_list[childrenIndex.Item1]?.Item1 ?? int.MaxValue) >
(_list[childrenIndex.Item2]?.Item1 ?? int.MinValue)) {
_list[index] = _list[childrenIndex.Item1];
_list[childrenIndex.Item1] = null;
index = childrenIndex.Item1;
} else {
_list[index] = _list[childrenIndex.Item2];
_list[childrenIndex.Item2] = null;
index = childrenIndex.Item2;
}
}
Count--;
return item;
}
public T Peek() { return _list[0].Item2; }
private void Swap(int index1, int index2) {
var tmp = _list[index1];
_list[index1] = _list[index2];
_list[index2] = tmp;
}
}
struct Rational {
private long _numerator;
private long _denominator;
public long Numerator => _numerator;
public long Denominator => _denominator;
public Rational(long numerator, long denominator) {
var gcd = GCD(numerator, denominator);
_numerator = numerator / gcd;
_denominator = denominator / gcd;
}
public static Rational operator +(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator +
b._numerator * a._denominator,
a._denominator * b._denominator);
}
public static Rational operator -(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator -
b._numerator * a._denominator,
a._denominator * b._denominator);
}
public static Rational operator *(Rational a, Rational b) {
return new Rational(a._numerator * b._numerator,
a._denominator * b._denominator);
}
public static Rational operator /(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator,
a._denominator * b._numerator);
}
public static explicit operator Rational(int i) { return new Rational(i, 1); }
public static explicit operator Rational(long l) {
return new Rational(l, 1);
}
public static explicit operator Rational(double d) {
long denominator = 1;
while (d % 1 != 0) {
denominator *= 2;
d *= 2;
}
return new Rational((long)d, denominator);
}
public static explicit operator Rational(float f) {
long denominator = 1;
while (f % 1 != 0) {
denominator *= 2;
f *= 2;
}
return new Rational((long)f, denominator);
}
}
struct ModInt {
public long Value { get; }
public static long Mod { get; set; } = 1000000000L + 7;
public ModInt(long l) {
long value = l % Mod;
while (value < 0)
value += Mod;
Value = value % Mod;
}
public static implicit operator long(ModInt m) { return m.Value; }
public static explicit operator ModInt(long l) { return new ModInt(l); }
public static ModInt operator +(ModInt a, ModInt b) {
return new ModInt(a.Value + b.Value);
}
public static ModInt operator -(ModInt a, ModInt b) {
return new ModInt(a.Value - b.Value);
}
public static ModInt operator *(ModInt a, ModInt b) {
return new ModInt(a.Value * b.Value);
}
public static ModInt operator /(ModInt a, ModInt b) {
return new ModInt(a * b.Inverse());
}
public override string ToString() { return Value.ToString(); }
}
static class ModIntMath {
public static ModInt Pow(this ModInt a, ModInt b) {
var pow = b.Value;
var m = a;
ModInt ans = new ModInt(1);
while (pow != 0) {
if ((pow & 1) == 1) {
ans *= m;
}
pow >>= 1;
m *= m;
}
return ans;
}
public static ModInt Inverse(this ModInt m) {
return m.Pow((ModInt)(ModInt.Mod - 2));
}
}
class UnionFind {
private readonly int[] _array;
public UnionFind(int N) {
_array = new int[N];
for (int i = 0; i < N; i++) {
_array[i] = i;
}
}
public int GetRootNode(int n) {
if (_array[n] == n)
return n;
return _array[n] = GetRootNode(_array[n]);
}
public void UnionGroup(int a, int b) {
var rootA = GetRootNode(a);
var rootB = GetRootNode(b);
if (rootA == rootB)
return;
_array[rootA] = rootB;
}
public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b);
public bool IsRoot(int n) => _array[n] == n;
}
namespace Extensions {
public class ConsoleInputExtension {
private static readonly ConsoleInputExtension _cin =
new ConsoleInputExtension();
public static ConsoleInputExtension Cin => _cin;
private static readonly Queue<string> _inputQueue = new Queue<string>();
private ConsoleInputExtension() {}
public static implicit operator string(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return _inputQueue.Dequeue();
}
public static implicit operator int(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return int.Parse(_inputQueue.Dequeue());
}
public static implicit operator long(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return long.Parse(_inputQueue.Dequeue());
}
public static implicit operator float(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return float.Parse(_inputQueue.Dequeue());
}
public static implicit operator double(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return double.Parse(_inputQueue.Dequeue());
}
}
public static class ConsoleOutputExtension {
private static StringBuilder _builder = new StringBuilder();
public static void Cout(object o) { _builder.Append(o); }
public static void CoutF(object o) {
_builder.Append(o);
Flush();
}
public static void Coutln(object o) {
_builder.Append(o);
_builder.Append('\n');
}
public static void Coutln() { _builder.Append('\n'); }
public static void CoutlnF(object o) {
_builder.Append(o);
_builder.Append('\n');
Flush();
}
public static void Flush() {
Console.Write(_builder.ToString());
_builder.Clear();
}
}
public static class MathExtension {
//最小公倍数
public static int LCM(int num1, int num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
public static long LCM(long num1, long num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
//最大公約数
public static int GCD(int num1, int num2) {
int a = Math.Max(num1, num2);
int b = Math.Min(num1, num2);
int mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
public static long GCD(long num1, long num2) {
long a = Math.Max(num1, num2);
long b = Math.Min(num1, num2);
long mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
}
public 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);
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 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, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 2,330
| 19
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace A {
class StartingPoint {
static void Main(string[] args) {
if (args?.Any() == true) {
var assembly = Assembly.GetEntryAssembly();
var resourceName = "AtCoderCSharp.In.txt";
var stream = assembly.GetManifestResourceStream(resourceName);
var streamReader = new StreamReader(stream, Encoding.UTF8);
var str = streamReader.ReadToEnd();
var textReader = new StringReader(str);
Console.SetIn(textReader);
}
try {
foreach (var s in new Program().Solve()) {
Console.WriteLine(s);
}
} catch (Exception e) {
Console.WriteLine(e);
if (args?.Any() != true)
throw e;
}
if (args?.Any() == true)
Console.ReadKey();
}
}
class Program {
public List<int> ScanInts(int count) =>
Enumerable.Range(0, count).Select(_ => ScanInt).ToList();
public List<int> ScanInts(long count) => ScanInts((int)count);
public List<long>
ScanLongs(int count) => Enumerable.Range(0, count).Select(_ => Scan).ToList();
public List<long> ScanLongs(long count) => ScanLongs((int)count);
public int ScanInt => int.Parse(Str);
public long Scan => long.Parse(Str);
public double ScanDouble => (double)Scan;
StringBuilder sb = new StringBuilder();
public string Str => ScanStr();
public string ScanStr() {
sb.Clear();
int r = 0;
bool? b = null;
do {
r = Console.Read();
b = IsBreak(r);
} while (b == true);
if (b == null)
throw new Exception("input error: unexpected end of stream");
do {
sb.Append((char)r);
r = Console.Read();
b = IsBreak(r);
} while (b == false);
return sb.ToString();
}
bool? IsBreak(int c) {
switch (c) {
case -1:
return null;
case (int)' ':
case (int)'\n':
case (int)'\r':
return true;
default:
return false;
}
}
public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count);
public IEnumerable<int> Loop(int from,
int to) => Enumerable.Range(from, to - from + 1);
public IEnumerable<long> Loop(long count) => Loop(0, count - 1);
public IEnumerable<long> Loop(long from, long to) {
for (long i = from; i <= to; i++)
yield return i;
}
public string YesNo(bool isYes) => isYes ? "Yes" : "No";
public HashSet<T> ToHashSet<T>(IEnumerable<T> ts) => new HashSet<T>(ts);
struct Mint {
public static long Divider {
set { divider = value; }
}
private static long divider = 1000000007;
public static void Set998244353() { divider = 998244353; }
public long Value { get; }
public Mint(long value) { this.Value = value; }
public static Mint
operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider);
public static Mint operator -(Mint a, Mint b) {
var t = (a.Value - b.Value) % divider;
if (t < 0)
t += divider;
return new Mint(t);
}
public static Mint
operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider);
public static Mint operator /(Mint a, Mint b) =>
new Mint((a.Value * InvImpl(b.Value)) % divider);
public Mint Pow(long p) => new Mint(PowImpl(Value, p));
private static long PowImpl(long a, long p) {
if (p == 0)
return 1L;
if (p == 1)
return a;
var halfP = p / 2;
var halfPowered = PowImpl(a, halfP);
var powered = halfPowered * halfPowered % divider;
return p % 2 == 0 ? powered : powered * a % divider;
}
public static Mint Inv(long a) => new Mint(InvImpl(a));
private static readonly Dictionary<long, long> invCache =
new Dictionary<long, long>();
private static long InvImpl(long a) {
long cache = 0L;
if (invCache.TryGetValue(a, out cache))
return cache;
var result = PowImpl(a, divider - 2);
invCache.Add(a, result);
return result;
}
public static Mint Fac(long a) => new Mint(FacImpl(a));
private static readonly List<long> facCache = new List<long>() { 1L };
private static long FacImpl(long a) {
if (a >= divider)
return 0;
if (a < facCache.Count)
return facCache[(int)a];
var val = facCache.Last();
var start = facCache.Count;
for (int i = start; i <= a; i++) {
val = (val * i) % divider;
facCache.Add(val);
}
return val;
}
public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r));
private static long PermImpl(long n, long r) {
if (n < r)
return 0L;
if (r <= 0)
return 1L;
var nn = FacImpl(n);
var nr = FacImpl(n - r);
return (nn * InvImpl(nr)) % divider;
}
public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r));
private static long CombImpl(long n, long r) {
if (n < r)
return 0L;
if (n == r)
return 1L;
var nn = FacImpl(n);
var nr = FacImpl(n - r);
var rr = FacImpl(r);
var nndnr = (nn * InvImpl(nr)) % divider;
return (nndnr * InvImpl(rr)) % divider;
}
}
public IEnumerable<string> Solve() {
var x = Scan;
var y = Scan;
if ((x + y) % 3 != 0) {
yield return "0";
yield break;
}
var n = (x + y) / 3;
var k1 = (x * 2 - y) / 3;
var k2 = (y * 2 - x) / 3;
Mint res = Mint.Comb(n, k1);
yield return res.Value.ToString();
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace A {
class StartingPoint {
static void Main(string[] args) {
if (args?.Any() == true) {
var assembly = Assembly.GetEntryAssembly();
var resourceName = "AtCoderCSharp.In.txt";
var stream = assembly.GetManifestResourceStream(resourceName);
var streamReader = new StreamReader(stream, Encoding.UTF8);
var str = streamReader.ReadToEnd();
var textReader = new StringReader(str);
Console.SetIn(textReader);
}
try {
foreach (var s in new Program().Solve()) {
Console.WriteLine(s);
}
} catch (Exception e) {
Console.WriteLine(e);
if (args?.Any() != true)
throw e;
}
if (args?.Any() == true)
Console.ReadKey();
}
}
class Program {
public List<int> ScanInts(int count) =>
Enumerable.Range(0, count).Select(_ => ScanInt).ToList();
public List<int> ScanInts(long count) => ScanInts((int)count);
public List<long>
ScanLongs(int count) => Enumerable.Range(0, count).Select(_ => Scan).ToList();
public List<long> ScanLongs(long count) => ScanLongs((int)count);
public int ScanInt => int.Parse(Str);
public long Scan => long.Parse(Str);
public double ScanDouble => (double)Scan;
StringBuilder sb = new StringBuilder();
public string Str => ScanStr();
public string ScanStr() {
sb.Clear();
int r = 0;
bool? b = null;
do {
r = Console.Read();
b = IsBreak(r);
} while (b == true);
if (b == null)
throw new Exception("input error: unexpected end of stream");
do {
sb.Append((char)r);
r = Console.Read();
b = IsBreak(r);
} while (b == false);
return sb.ToString();
}
bool? IsBreak(int c) {
switch (c) {
case -1:
return null;
case (int)' ':
case (int)'\n':
case (int)'\r':
return true;
default:
return false;
}
}
public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count);
public IEnumerable<int> Loop(int from,
int to) => Enumerable.Range(from, to - from + 1);
public IEnumerable<long> Loop(long count) => Loop(0, count - 1);
public IEnumerable<long> Loop(long from, long to) {
for (long i = from; i <= to; i++)
yield return i;
}
public string YesNo(bool isYes) => isYes ? "Yes" : "No";
public HashSet<T> ToHashSet<T>(IEnumerable<T> ts) => new HashSet<T>(ts);
struct Mint {
public static long Divider {
set { divider = value; }
}
private static long divider = 1000000007;
public static void Set998244353() { divider = 998244353; }
public long Value { get; }
public Mint(long value) { this.Value = value; }
public static Mint
operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider);
public static Mint operator -(Mint a, Mint b) {
var t = (a.Value - b.Value) % divider;
if (t < 0)
t += divider;
return new Mint(t);
}
public static Mint
operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider);
public static Mint operator /(Mint a, Mint b) =>
new Mint((a.Value * InvImpl(b.Value)) % divider);
public Mint Pow(long p) => new Mint(PowImpl(Value, p));
private static long PowImpl(long a, long p) {
if (p == 0)
return 1L;
if (p == 1)
return a;
var halfP = p / 2;
var halfPowered = PowImpl(a, halfP);
var powered = halfPowered * halfPowered % divider;
return p % 2 == 0 ? powered : powered * a % divider;
}
public static Mint Inv(long a) => new Mint(InvImpl(a));
private static readonly Dictionary<long, long> invCache =
new Dictionary<long, long>();
private static long InvImpl(long a) {
long cache = 0L;
if (invCache.TryGetValue(a, out cache))
return cache;
var result = PowImpl(a, divider - 2);
invCache.Add(a, result);
return result;
}
public static Mint Fac(long a) => new Mint(FacImpl(a));
private static readonly List<long> facCache = new List<long>() { 1L };
private static long FacImpl(long a) {
if (a >= divider)
return 0;
if (a < facCache.Count)
return facCache[(int)a];
var val = facCache.Last();
var start = facCache.Count;
for (int i = start; i <= a; i++) {
val = (val * i) % divider;
facCache.Add(val);
}
return val;
}
public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r));
private static long PermImpl(long n, long r) {
if (n < r)
return 0L;
if (r <= 0)
return 1L;
var nn = FacImpl(n);
var nr = FacImpl(n - r);
return (nn * InvImpl(nr)) % divider;
}
public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r));
private static long CombImpl(long n, long r) {
if (n < r)
return 0L;
if (n == r)
return 1L;
var nn = FacImpl(n);
var nr = FacImpl(n - r);
var rr = FacImpl(r);
var nndnr = (nn * InvImpl(nr)) % divider;
return (nndnr * InvImpl(rr)) % divider;
}
}
public IEnumerable<string> Solve() {
var x = Scan;
var y = Scan;
if ((x + y) % 3 != 0) {
yield return "0";
yield break;
}
var n = (x + y) / 3;
var k1 = (x * 2 - y) / 3;
var k2 = (y * 2 - x) / 3;
if (k1 < 0 || k2 < 0) {
yield return "0";
yield break;
}
Mint res = Mint.Comb(n, k1);
yield return res.Value.ToString();
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 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, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 285, 0, 286], ["+", 8, 196, 0, 57, 64, 196, 0, 285, 0, 38], ["+", 0, 57, 64, 196, 0, 285, 0, 5, 0, 62], ["+", 0, 57, 64, 196, 0, 285, 0, 5, 0, 222], ["+", 8, 196, 0, 57, 64, 196, 0, 285, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 285, 0, 94], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 1,447
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace AtCoder {
class Modular {
private const int M = 1000000007;
private long value;
public Modular(long value) { this.value = value; }
public static implicit operator Modular(long a) {
var m = a % M;
return new Modular((m < 0) ? m + M : m);
}
public static Modular operator +(Modular a, Modular b) {
return a.value + b.value;
}
public static Modular operator -(Modular a, Modular b) {
return a.value - b.value;
}
public static Modular operator *(Modular a, Modular b) {
return a.value * b.value;
}
private static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b) {
return a * Pow(b, M - 2);
}
private static readonly List<int> facs = new List<int> { 1 };
private static Modular Fac(int n) {
for (int i = facs.Count; i <= n; ++i) {
facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
}
return facs[n];
}
public static Modular Ncr(int n, int r) {
return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a) { return (int)a.value; }
}
class Program {
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
static int Solve(int X, int Y) {
if ((X + Y) % 3 == 0 && (Y <= X * 2 || X <= Y * 2)) {
int n = (X + Y) / 3;
int r = X - n;
return (int)Modular.Ncr(n, r);
}
return 0;
}
static void Main(string[] args) {
var V = ReadInts();
Console.WriteLine(Solve(V[0], V[1]));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace AtCoder {
class Modular {
private const int M = 1000000007;
private long value;
public Modular(long value) { this.value = value; }
public static implicit operator Modular(long a) {
var m = a % M;
return new Modular((m < 0) ? m + M : m);
}
public static Modular operator +(Modular a, Modular b) {
return a.value + b.value;
}
public static Modular operator -(Modular a, Modular b) {
return a.value - b.value;
}
public static Modular operator *(Modular a, Modular b) {
return a.value * b.value;
}
private static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b) {
return a * Pow(b, M - 2);
}
private static readonly List<int> facs = new List<int> { 1 };
private static Modular Fac(int n) {
for (int i = facs.Count; i <= n; ++i) {
facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
}
return facs[n];
}
public static Modular Ncr(int n, int r) {
return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a) { return (int)a.value; }
}
class Program {
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
static int Solve(int X, int Y) {
if ((X + Y) % 3 == 0) {
int n = (X + Y) / 3;
int r = X - n;
return (0 <= r && r <= n) ? (int)Modular.Ncr(n, r) : 0;
}
return 0;
}
static void Main(string[] args) {
var V = ReadInts();
Console.WriteLine(Solve(V[0], V[1]));
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 17, 19], ["-", 12, 23, 0, 16, 31, 16, 12, 16, 31, 22], ["-", 12, 23, 0, 16, 31, 16, 12, 16, 17, 48], ["-", 12, 23, 0, 16, 31, 16, 12, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 17, 106], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 17, 19], ["-", 12, 23, 0, 16, 12, 16, 12, 16, 31, 22], ["-", 12, 23, 0, 16, 12, 16, 12, 16, 17, 48], ["-", 12, 23, 0, 16, 12, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["+", 64, 196, 0, 37, 0, 41, 15, 23, 0, 24], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 31, 203], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 17, 19], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 37, 0, 41, 15, 23, 0, 16, 17, 98], ["+", 0, 41, 15, 23, 0, 16, 12, 16, 31, 22], ["+", 0, 41, 15, 23, 0, 16, 12, 16, 17, 19], ["+", 0, 41, 15, 23, 0, 16, 12, 16, 12, 22], ["+", 64, 196, 0, 37, 0, 41, 15, 23, 0, 25], ["+", 0, 57, 64, 196, 0, 37, 0, 41, 0, 101], ["+", 0, 57, 64, 196, 0, 37, 0, 41, 0, 102], ["+", 0, 57, 64, 196, 0, 37, 0, 41, 75, 203]]
| 8
| 659
| 26
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;
public class D {
public static void Main() => (new Solver()).Solve();
}
public class Solver {
public void Solve() {
long mod = (long)(1e9 + 7);
long X = GetLong();
long Y = GetLong();
if ((X + Y) % 3 != 0 || (2 * X - Y) % 3 != 0 || (2 * Y - X) % 3 != 0) {
WriteLine(0);
return;
}
long a = (2 * Y - X) / 3;
long b = (2 * X - Y) / 3;
var mct = new ModCombTable(2 * (int)1e6 + 1, mod);
WriteLine(mct.ModComb(a + b, a));
}
}
public class ModCombTable {
private long[] f = null;
private long[] fInv = null;
private long mod;
public ModCombTable(int N, long m) {
mod = m;
// calc factorial
f = new long[N + 1];
f[0] = 1;
for (int i = 1; i <= N; i++)
f[i] = (f[i - 1] * i) % mod;
// calc factorial inverse
fInv = new long[N + 1];
fInv[N] = ModInv(f[N]);
for (int i = N; i > 0; i--)
fInv[i - 1] = (fInv[i] * i) % mod;
}
public long ModComb(long n, long k) {
if (n < 0 || n < k)
return 0;
return (((f[n] * fInv[k]) % mod) * fInv[n - k]) % mod;
}
public long ModInv(long x) { return ModPow(x, mod - 2); }
public long ModPow(long x, long n) {
long res = 1;
while (n > 0) {
if ((n & 1) == 1)
res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() => int.Parse(getArg());
public static long GetLong() => long.Parse(getArg());
public static double GetDouble() => double.Parse(getArg());
public static string GetString() => getArg();
public static char GetChar() => getArg()[0];
public static int[] GetInts(int N) =>
Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
public static long[] GetLongs(int N) =>
Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
public static double[] GetDoubles(int N) =>
Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
public static string[] GetStrings(int N) =>
Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}
public static class MyUtil {
public static void chmax<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) < 0)
x = y;
}
public static void chmin<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) > 0)
x = y;
}
public static void swap<T>(ref T x, ref T y) {
T tmp = x;
x = y;
y = tmp;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;
public class D {
public static void Main() => (new Solver()).Solve();
}
public class Solver {
public void Solve() {
long mod = (long)(1e9 + 7);
long X = GetLong();
long Y = GetLong();
if ((X + Y) % 3 != 0 || (2 * X - Y) % 3 != 0 || (2 * Y - X) % 3 != 0) {
WriteLine(0);
return;
}
long a = (2 * Y - X) / 3;
long b = (2 * X - Y) / 3;
if (a < 0 || b < 0) {
Console.WriteLine(0);
return;
}
var mct = new ModCombTable(2 * (int)1e6 + 1, mod);
WriteLine(mct.ModComb(a + b, a));
}
}
public class ModCombTable {
private long[] f = null;
private long[] fInv = null;
private long mod;
public ModCombTable(int N, long m) {
mod = m;
// calc factorial
f = new long[N + 1];
f[0] = 1;
for (int i = 1; i <= N; i++)
f[i] = (f[i - 1] * i) % mod;
// calc factorial inverse
fInv = new long[N + 1];
fInv[N] = ModInv(f[N]);
for (int i = N; i > 0; i--)
fInv[i - 1] = (fInv[i] * i) % mod;
}
public long ModComb(long n, long k) {
if (n < 0 || n < k)
return 0;
return (((f[n] * fInv[k]) % mod) * fInv[n - k]) % mod;
}
public long ModInv(long x) { return ModPow(x, mod - 2); }
public long ModPow(long x, long n) {
long res = 1;
while (n > 0) {
if ((n & 1) == 1)
res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() => int.Parse(getArg());
public static long GetLong() => long.Parse(getArg());
public static double GetDouble() => double.Parse(getArg());
public static string GetString() => getArg();
public static char GetChar() => getArg()[0];
public static int[] GetInts(int N) =>
Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
public static long[] GetLongs(int N) =>
Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
public static double[] GetDoubles(int N) =>
Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
public static string[] GetStrings(int N) =>
Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}
public static class MyUtil {
public static void chmax<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) < 0)
x = y;
}
public static void chmin<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) > 0)
x = y;
}
public static void swap<T>(ref T x, ref T y) {
T tmp = x;
x = y;
y = tmp;
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 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, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 890
| 21
|
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
public static class P {
public static void Main() {
var xy = Console.ReadLine().Split().Select(int.Parse).ToArray();
var x = xy[0];
var y = xy[1];
if ((x + y) % 3 != 0) {
Console.WriteLine(0);
return;
}
var moves = (x + y) / 3;
var xCount = x - moves;
var yCount = y - moves;
Console.WriteLine(Factorial(moves) /
(Factorial(xCount) * Factorial(yCount)));
}
static List<ModInt> factorialMemo = new List<ModInt>() { 1 };
static ModInt Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
}
struct ModInt {
const int MOD = 1000000007;
const long POSITIVIZER = ((long)MOD) << 31;
long Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ModInt(long data) {
if ((Data = data % MOD) < 0)
Data += MOD;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt modInt) => modInt.Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long val) => new ModInt(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, int b) => new ModInt() {
Data = (a.Data + b + POSITIVIZER) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, long b) => new ModInt(a.Data + b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= MOD ? res - MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, int b) => new ModInt() {
Data = (a.Data - b + POSITIVIZER) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, long b) => new ModInt(a.Data - b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, long b) => a * new ModInt(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * GetInverse(b) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => Data.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GetInverse(long a) {
long div, p = MOD, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + MOD;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + MOD;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
public static class P {
public static void Main() {
var xy = Console.ReadLine().Split().Select(int.Parse).ToArray();
var x = xy[0];
var y = xy[1];
if ((x + y) % 3 != 0) {
Console.WriteLine(0);
return;
}
var moves = (x + y) / 3;
if (x < moves || y < moves) {
Console.WriteLine(0);
return;
}
var xCount = x - moves;
var yCount = y - moves;
Console.WriteLine(Factorial(moves) /
(Factorial(xCount) * Factorial(yCount)));
}
static List<ModInt> factorialMemo = new List<ModInt>() { 1 };
static ModInt Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
}
struct ModInt {
const int MOD = 1000000007;
const long POSITIVIZER = ((long)MOD) << 31;
long Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ModInt(long data) {
if ((Data = data % MOD) < 0)
Data += MOD;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt modInt) => modInt.Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long val) => new ModInt(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, int b) => new ModInt() {
Data = (a.Data + b + POSITIVIZER) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, long b) => new ModInt(a.Data + b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= MOD ? res - MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, int b) => new ModInt() {
Data = (a.Data - b + POSITIVIZER) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, long b) => new ModInt(a.Data - b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, long b) => a * new ModInt(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * GetInverse(b) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => Data.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GetInverse(long a) {
long div, p = MOD, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + MOD;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + MOD;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 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, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 887
| 21
|
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.IO;
using System.Text;
using N = System.Int64;
public class Solver {
public void Solve() {
N x = rl, y = rl;
if ((2 * x - y) % 3 != 0 || (2 * y - x) % 3 != 0) {
Write(0);
return;
}
N a = (2 * y - x) / 3, b = (2 * x - y) / 3;
N s = a + b;
N[] fac = new N[s + 1];
fac[0] = 1;
for (N i = 0; i < s; i++) {
fac[i + 1] = (fac[i] * (i + 1)) % mod;
}
N[] rfac = new N[s + 1];
rfac[s] = Reverse(fac[s]);
for (N i = s; i > 0; i--) {
rfac[i - 1] = (rfac[i] * i) % mod;
}
Write(Mul(fac[s], rfac[a], rfac[s - a]));
}
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 StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
public Algorithm alg = new Algorithm();
private const N mod = 1000000007;
N Reverse(N n) { return Pow(n, mod - 2); }
N Mul(params N[] n) {
N p = n[0];
for (N i = 1; i < n.Length; i++) {
p = (p * n[i]) % mod;
}
return p;
}
N Pow(N n, N p) {
N t = n, q = 1;
while (p > 0) {
if (p % 2 == 1) {
q = (q * t) % mod;
}
t = (t * t) % mod;
p >>= 1;
}
return q;
}
N PowUpper(N n, N b) {
N p = 1;
while (p <= n) {
p *= b;
}
return p;
}
N Sign(N n) { return n == 0 ? 0 : n > 0 ? 1 : -1; }
N Abs(N n) { return (n > 0) ? n : -n; }
N Gcd(params N[] n) {
N p = n[0];
for (N i = 1; i < n.Length; i++) {
p = Gcd(p, n[i]);
}
return p;
}
N Gcd(N a, N b) { return (a == 0) ? b : Gcd(b % a, a); }
N Lcm(params N[] n) {
N p = n[0];
for (N i = 1; i < n.Length; i++) {
p = Lcm(p, n[i]);
}
return p;
}
N Lcm(N a, N b) { return (a / Gcd(a, b) * b) % mod; }
void Write<T>(T t) { Console.WriteLine(t.ToString()); }
void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
}
static class Program {
static public void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var solver = new Solver();
solver.Solve();
Console.Out.Flush();
}
}
public class Algorithm {
public int[] ZAlgorithm(string s) {
int[] p = new int[s.Length];
p[0] = s.Length;
int i = 1, j = 0;
while (i < s.Length) {
while (i + j < s.Length && s[j] == s[i + j])
++j;
p[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < s.Length && k + p[k] < j) {
p[i + k] = p[k];
++k;
}
i += k;
j -= k;
}
return p;
}
public List<int> SieveOfEratosthenes(int n) {
List<int> l = new List<int>();
if (n >= 2) {
l.Add(2);
}
bool[] t = new bool[(n - 1) / 2];
for (int p = 3; p <= n; p += 2) {
if (!t[(p - 3) / 2]) {
l.Add(p);
for (int q = p * p; q <= n; q += p) {
t[(q - 3) / 2] = true;
}
}
}
return l;
}
public Dictionary<int, int> PrimeFactor(int n, List<int> primetable) {
Dictionary<int, int> d = new Dictionary<int, int>();
int t = 0;
foreach (int i in primetable) {
if (n % i == 0) {
while (n % 2 == 0) {
n /= i;
t++;
}
d.Add(i, t);
}
}
if (n > 1) {
d.Add(n, 1);
}
return d;
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(IComparer<T> comparer) {
_heap = new T[128];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int type = 0) {
_heap = new T[128];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
if (_count > _heap.Length) {
var newheap = new T[_heap.Length * 2];
for (int n = 0; n < _heap.Length; n++)
newheap[n] = _heap[n];
_heap = newheap;
}
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public 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 int Integer() { return (int)Long(); }
public double Double() { return double.Parse(Scan()); }
}
|
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.IO;
using System.Text;
using N = System.Int64;
public class Solver {
public void Solve() {
N x = rl, y = rl;
if ((2 * x - y) % 3 != 0 || (2 * y - x) % 3 != 0) {
Write(0);
return;
}
N a = (2 * y - x) / 3, b = (2 * x - y) / 3;
if (a < 0 || b < 0) {
Write(0);
return;
}
N s = a + b;
N[] fac = new N[s + 1];
fac[0] = 1;
for (N i = 0; i < s; i++) {
fac[i + 1] = (fac[i] * (i + 1)) % mod;
}
N[] rfac = new N[s + 1];
rfac[s] = Reverse(fac[s]);
for (N i = s; i > 0; i--) {
rfac[i - 1] = (rfac[i] * i) % mod;
}
Write(Mul(fac[s], rfac[a], rfac[s - a]));
}
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 StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
public Algorithm alg = new Algorithm();
private const N mod = 1000000007;
N Reverse(N n) { return Pow(n, mod - 2); }
N Mul(params N[] n) {
N p = n[0];
for (N i = 1; i < n.Length; i++) {
p = (p * n[i]) % mod;
}
return p;
}
N Pow(N n, N p) {
N t = n, q = 1;
while (p > 0) {
if (p % 2 == 1) {
q = (q * t) % mod;
}
t = (t * t) % mod;
p >>= 1;
}
return q;
}
N PowUpper(N n, N b) {
N p = 1;
while (p <= n) {
p *= b;
}
return p;
}
N Sign(N n) { return n == 0 ? 0 : n > 0 ? 1 : -1; }
N Abs(N n) { return (n > 0) ? n : -n; }
N Gcd(params N[] n) {
N p = n[0];
for (N i = 1; i < n.Length; i++) {
p = Gcd(p, n[i]);
}
return p;
}
N Gcd(N a, N b) { return (a == 0) ? b : Gcd(b % a, a); }
N Lcm(params N[] n) {
N p = n[0];
for (N i = 1; i < n.Length; i++) {
p = Lcm(p, n[i]);
}
return p;
}
N Lcm(N a, N b) { return (a / Gcd(a, b) * b) % mod; }
void Write<T>(T t) { Console.WriteLine(t.ToString()); }
void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
}
static class Program {
static public void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var solver = new Solver();
solver.Solve();
Console.Out.Flush();
}
}
public class Algorithm {
public int[] ZAlgorithm(string s) {
int[] p = new int[s.Length];
p[0] = s.Length;
int i = 1, j = 0;
while (i < s.Length) {
while (i + j < s.Length && s[j] == s[i + j])
++j;
p[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < s.Length && k + p[k] < j) {
p[i + k] = p[k];
++k;
}
i += k;
j -= k;
}
return p;
}
public List<int> SieveOfEratosthenes(int n) {
List<int> l = new List<int>();
if (n >= 2) {
l.Add(2);
}
bool[] t = new bool[(n - 1) / 2];
for (int p = 3; p <= n; p += 2) {
if (!t[(p - 3) / 2]) {
l.Add(p);
for (int q = p * p; q <= n; q += p) {
t[(q - 3) / 2] = true;
}
}
}
return l;
}
public Dictionary<int, int> PrimeFactor(int n, List<int> primetable) {
Dictionary<int, int> d = new Dictionary<int, int>();
int t = 0;
foreach (int i in primetable) {
if (n % i == 0) {
while (n % 2 == 0) {
n /= i;
t++;
}
d.Add(i, t);
}
}
if (n > 1) {
d.Add(n, 1);
}
return d;
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(IComparer<T> comparer) {
_heap = new T[128];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int type = 0) {
_heap = new T[128];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
if (_count > _heap.Length) {
var newheap = new T[_heap.Length * 2];
for (int n = 0; n < _heap.Length; n++)
newheap[n] = _heap[n];
_heap = newheap;
}
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public 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 int Integer() { return (int)Long(); }
public double Double() { return double.Parse(Scan()); }
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 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, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 2,230
| 19
|
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() {
checked {
var N = sc.ReadInt();
var T = sc.ReadInt();
var AB = sc.ReadTupArray(N);
var dp = new long[N + 1, T + 1];
for (int i = 0; i < N; i++) {
for (int j = 0; j < T + 1; j++) {
dp[i + 1, j] = Math.Max(dp[i + 1, j], dp[i, j]);
if (j < T) {
var nj = Math.Min(T, j + AB[i].Item1);
dp[i + 1, nj] = Math.Max(dp[i + 1, nj], dp[i, j] + AB[i].Item2);
}
}
}
var ans = dp[N, T];
Console.WriteLine(ans);
}
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public 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 T = sc.ReadInt();
var AB = sc.ReadTupArray(N).OrderBy(ab => ab.Item1).ToArray();
var dp = new long[N + 1, T + 1];
for (int i = 0; i < N; i++) {
for (int j = 0; j < T + 1; j++) {
dp[i + 1, j] = Math.Max(dp[i + 1, j], dp[i, j]);
if (j < T) {
var nj = Math.Min(T, j + AB[i].Item1);
dp[i + 1, nj] = Math.Max(dp[i + 1, nj], dp[i, j] + AB[i].Item2);
}
}
}
var ans = dp[N, T];
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public 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;
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 287, 0, 292], ["-", 0, 195, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 287, 0, 196, 0, 46]]
| 8
| 1,241
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var waaaa = new waaaa();
waaaa.Solve();
}
}
public class waaaa {
const int MOD = 1000000007;
const long INF = 1 << 61;
const int MOD2 = 998244353;
Scaner cin = new Scaner();
write cout = new write();
Math2 mmath = new Math2();
public void Solve() {
mmath.FactoricalModSet(1000000);
//ここから
var o = cin.IntM;
var N = o[0];
var T = o[1];
int[] A = new int[N];
int[] B = new int[N];
for (int i = 0; i < N; ++i) {
o = cin.IntM;
A[i] = o[0];
B[i] = o[1];
}
var DPl = new int[N + 1, T];
var DPr = new int[N + 1, T];
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
DPl[i + 1, j] = DPl[i, j];
if (j >= A[i]) {
DPl[i + 1, j] = Math.Max(DPl[i + 1, j], DPl[i, j - A[i]] + B[i]);
}
}
}
for (int i = N - 1; i >= 0; --i) {
for (int j = 0; j < N; ++j) {
DPr[i, j] = DPr[i + 1, j];
if (j >= A[i]) {
DPr[i, j] = Math.Max(DPr[i, j], DPr[i + 1, j - A[i]] + B[i]);
}
}
}
int ans = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < T; ++j) {
ans = Math.Max(ans, DPl[i, j] + DPr[i + 1, T - 1 - j] + B[i]);
}
}
cout.wri(ans);
}
public static bool NextPermutation<T>(T[] array, int start, int length)
where T : IComparable {
int end = start + length - 1;
// 範囲が狭すぎる
if (end <= start)
return false;
int last = end;
while (true) {
int pos = last--;
if (array[last].CompareTo(array[pos]) < 0) {
int i;
for (i = end + 1; array[last].CompareTo(array[--i]) >= 0;) {
}
T tmp = array[last];
array[last] = array[i];
array[i] = tmp;
Array.Reverse(array, pos, end - pos + 1);
return true;
}
if (last == start) // 最後の順列
{
Array.Reverse(array, start, end - start);
return false;
}
}
// ここに来ることはない
throw new Exception("NextPermutation: Fatal error");
}
}
// b-aで降順
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
public class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
// Nまでの階乗をセットしておく
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = pow(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
// nCr 引数:n r (mod)
public long nCr(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
//階乗(O(logN)) 引数:底x n乗 (MOD)
public long pow(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
//最大公約数 引数:整数x,y
public long GCD(long x, long y) {
while (y != 0) {
var r = x % y;
x = y;
y = r;
}
return x;
}
//最小公倍数 引数:整数x,y
public long LCM(long x, long y) { return x * y / GCD(x, y); }
//素因数分解 引数:整数N
public Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> PrimeFactorization2(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
namespace CompLib.Algorithms {
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrM => Str.Split(' ');
public long[] LongM => StrM.Select(long.Parse).ToArray();
public int[] IntM => StrM.Select(int.Parse).ToArray();
public char[] CharM => Str.ToArray();
public long Long1 => LongM[0];
public int Int1 => IntM[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var waaaa = new waaaa();
waaaa.Solve();
}
}
public class waaaa {
const int MOD = 1000000007;
const long INF = 1 << 61;
const int MOD2 = 998244353;
Scaner cin = new Scaner();
write cout = new write();
Math2 mmath = new Math2();
public void Solve() {
mmath.FactoricalModSet(1000000);
//ここから
var o = cin.IntM;
var N = o[0];
var T = o[1];
int[] A = new int[N];
int[] B = new int[N];
for (int i = 0; i < N; ++i) {
o = cin.IntM;
A[i] = o[0];
B[i] = o[1];
}
var DPl = new int[N + 1, T];
var DPr = new int[N + 1, T];
for (int i = 0; i < N; ++i) {
for (int j = 0; j < T; ++j) {
DPl[i + 1, j] = DPl[i, j];
if (j >= A[i]) {
DPl[i + 1, j] = Math.Max(DPl[i + 1, j], DPl[i, j - A[i]] + B[i]);
}
}
}
for (int i = N - 1; i >= 0; --i) {
for (int j = 0; j < T; ++j) {
DPr[i, j] = DPr[i + 1, j];
if (j >= A[i]) {
DPr[i, j] = Math.Max(DPr[i, j], DPr[i + 1, j - A[i]] + B[i]);
}
}
}
int ans = DPl[N, T - 1];
for (int i = 0; i < N; ++i) {
for (int j = 0; j < T; ++j) {
ans = Math.Max(ans, DPl[i, j] + DPr[i + 1, T - 1 - j] + B[i]);
}
}
cout.wri(ans);
}
public static bool NextPermutation<T>(T[] array, int start, int length)
where T : IComparable {
int end = start + length - 1;
// 範囲が狭すぎる
if (end <= start)
return false;
int last = end;
while (true) {
int pos = last--;
if (array[last].CompareTo(array[pos]) < 0) {
int i;
for (i = end + 1; array[last].CompareTo(array[--i]) >= 0;) {
}
T tmp = array[last];
array[last] = array[i];
array[i] = tmp;
Array.Reverse(array, pos, end - pos + 1);
return true;
}
if (last == start) // 最後の順列
{
Array.Reverse(array, start, end - start);
return false;
}
}
// ここに来ることはない
throw new Exception("NextPermutation: Fatal error");
}
}
// b-aで降順
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
public class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
// Nまでの階乗をセットしておく
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = pow(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
// nCr 引数:n r (mod)
public long nCr(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
//階乗(O(logN)) 引数:底x n乗 (MOD)
public long pow(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
//最大公約数 引数:整数x,y
public long GCD(long x, long y) {
while (y != 0) {
var r = x % y;
x = y;
y = r;
}
return x;
}
//最小公倍数 引数:整数x,y
public long LCM(long x, long y) { return x * y / GCD(x, y); }
//素因数分解 引数:整数N
public Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> PrimeFactorization2(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
namespace CompLib.Algorithms {
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrM => Str.Split(' ');
public long[] LongM => StrM.Select(long.Parse).ToArray();
public int[] IntM => StrM.Select(int.Parse).ToArray();
public char[] CharM => Str.ToArray();
public long Long1 => LongM[0];
public int Int1 => IntM[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 21], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73]]
| 8
| 2,015
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;
public class Prog {
public static void Solve() {
int N = NextInt(), T = NextInt();
Tuple<int, int>[] tp = new Tuple<int, int>[N];
for (int i = 0; i < N; i++) {
int A = NextInt(), B = NextInt();
tp[i] = new Tuple<int, int>(A, B);
}
var v = tp.OrderBy(x => x.Item1);
int[] dp = Enumerable.Repeat(-INF, 6010).ToArray();
dp[0] = 0;
foreach (var e in v) {
// Time
for (int x = T - 1; x >= 0; x--) {
if (dp[x] != -INF) {
if (x + e.Item1 <= T) {
dp[x + e.Item1] = Math.Max(dp[x + e.Item1], dp[x] + e.Item2);
} else {
dp[T] = Math.Max(dp[T], dp[x] + e.Item2);
}
// dp[x + e.Item1] = Math.Max(dp[x + e.Item1], dp[x] + e.Item2);
}
}
}
int ans = 0;
// for (int i = T; i >= 0; i--) { ans = Math.Max(ans, dp[i]);
// Console.WriteLine(i + " : " +dp[i]); }
Console.WriteLine(ans);
}
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
return;
}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
public long Abs(long a, long b) => Math.Abs(a - b);
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;
public class Prog {
public static void Solve() {
int N = NextInt(), T = NextInt();
Tuple<int, int>[] tp = new Tuple<int, int>[N];
for (int i = 0; i < N; i++) {
int A = NextInt(), B = NextInt();
tp[i] = new Tuple<int, int>(A, B);
}
var v = tp.OrderBy(x => x.Item1);
int[] dp = Enumerable.Repeat(-INF, 6010).ToArray();
dp[0] = 0;
foreach (var e in v) {
// Time
for (int x = T - 1; x >= 0; x--) {
if (dp[x] != -INF) {
if (x + e.Item1 <= T) {
dp[x + e.Item1] = Math.Max(dp[x + e.Item1], dp[x] + e.Item2);
} else {
dp[T] = Math.Max(dp[T], dp[x] + e.Item2);
}
// dp[x + e.Item1] = Math.Max(dp[x + e.Item1], dp[x] + e.Item2);
}
}
}
int ans = 0;
for (int i = T; i >= 0; i--) {
ans = Math.Max(ans, dp[i]);
// Console.WriteLine(i + " : " + dp[i]);
}
Console.WriteLine(ans);
}
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
return;
}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
public long Abs(long a, long b) => Math.Abs(a - b);
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 657
| 30
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
using ll = System.Int64;
public class Contest {
static void Swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static void Swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
Swap1(ref a, ref b);
} // b の方が小さければ交換
static bool Chmin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
} // b の方が小さければ a を更新
static bool Chmax<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
} // b の方が大きければ a を更新
static T[][] InitMat<T>(long len1, long len2, T val) {
T[][] m = new T[len1][];
for (int i = 0; i < m.Length; i++)
m[i] = Enumerable.Repeat(val, (int)len2).ToArray();
return m;
}
static T[][][] InitMat<T>(long len1, long len2, long len3, T val) {
T[][][] m = new T[len1][][];
for (int i = 0; i < m.Length; i++)
m[i] = InitMat(len2, len3, val);
return m;
}
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public static void Main() { Solve_E(); }
public static void Solve_A() {
ll n;
MyIO.ReadMulti(out n);
ll ans = n * n;
MyIO.WriteMulti(ans);
}
public static void Solve_B() {
ll n;
MyIO.ReadMulti(out n);
string s;
MyIO.ReadMulti(out s);
string ans = "No";
if (n % 2 == 0) {
string a = s.Substring(0, (int)(n / 2));
string b = s.Substring((int)(n / 2), (int)(n / 2));
if (a == b)
ans = "Yes";
}
MyIO.WriteMulti(ans);
}
public static void Solve_C() {
ll n;
MyIO.ReadMulti(out n);
VT<ll, ll>[] xyl;
MyIO.ReadLines(n, out xyl);
ll[][] dist = InitMat(n, n, 0L);
double sum = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
sum += Math.Sqrt(
(xyl[i].Item1 - xyl[j].Item1) * (xyl[i].Item1 - xyl[j].Item1) +
(xyl[i].Item2 - xyl[j].Item2) * (xyl[i].Item2 - xyl[j].Item2));
}
}
double ans = (double)sum / (double)n;
MyIO.WriteMulti(ans);
}
public static void Solve_D() {
ll x, y;
MyIO.ReadMulti(out x, out y);
MyIO.WriteMulti(0);
}
public static void Solve_E() {
ll n, t;
MyIO.ReadMulti(out n, out t);
VT<ll, ll>[] abl;
MyIO.ReadLines(n, out abl);
Array.Sort(abl, (x, y) => (int)(x.Item2 - y.Item2));
ll[][] dp = InitMat(n + 1, t + 1, 0L);
ll ans = 0;
for (ll i = 1; i < n; i++) {
for (ll j = 0; j < t; j++) {
dp[i][j] =
Math.Max(dp[i - 1][j],
((0 <= j - abl[i - 1].Item1)
? (dp[i - 1][j - abl[i - 1].Item1] + abl[i - 1].Item2)
: 0));
}
}
for (ll j = 0; j < t; j++) {
Chmax(ref ans, dp[n - 1][j] + abl[n - 1].Item2);
}
MyIO.WriteMulti(ans);
}
public static void Solve_F() {}
}
#region MyIO
public struct VT<T, U> {
public T Item1;
public U Item2;
public VT(T a, U b) {
Item1 = a;
Item2 = b;
}
}
public struct VT<T, U, V> {
public T Item1;
public U Item2;
public V Item3;
public VT(T a, U b, V c) {
Item1 = a;
Item2 = b;
Item3 = c;
}
}
public struct VT<T, U, V, W> {
public T Item1;
public U Item2;
public V Item3;
public W Item4;
public VT(T a, U b, V c, W d) {
Item1 = a;
Item2 = b;
Item3 = c;
Item4 = d;
}
}
public class Printer : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Printer(System.IO.Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(System.IO.Stream stream, Encoding encoding)
: base(stream, encoding) {}
}
public static class MyIO {
private static char[] splitter = new char[] { ' ' };
private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
private static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] ReadMulti<T>(out T a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(ar[0]);
return ar;
}
public static string[] ReadMulti<T, U>(out T a, out U b) {
var ar = ReadMulti<T>(out a);
b = cv<U>(ar[1]);
return ar;
}
public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
var ar = ReadMulti<T, U>(out a, out b);
c = cv<V>(ar[2]);
return ar;
}
public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c,
out W d) {
var ar = ReadMulti<T, U, V>(out a, out b, out c);
d = cv<W>(ar[3]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c,
out W d, out X e) {
var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(ar[4]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e,
out Y f) {
var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(ar[5]);
return ar;
}
public static string[] ReadArray<T>(out T[] a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = ar.Select(cv<T>).ToArray();
return ar;
}
public static string[][] ReadLines<T>(long n, out T[] a) {
a = new T[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadMulti(out a[i]);
return arr;
}
public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) {
a = new VT<T, U>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
arr[i] = ReadMulti(out o, out p);
a[i] = new VT<T, U>(o, p);
}
return arr;
}
public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) {
a = new VT<T, U, V>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
arr[i] = ReadMulti(out o, out p, out q);
a[i] = new VT<T, U, V>(o, p, q);
}
return arr;
}
public static string[][] ReadLines<T, U, V, W>(long n,
out VT<T, U, V, W>[] a) {
a = new VT<T, U, V, W>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
arr[i] = ReadMulti(out o, out p, out q, out r);
a[i] = new VT<T, U, V, W>(o, p, q, r);
}
return arr;
}
public static string[][] ReadMatrix<T>(long n, out T[][] a) {
a = new T[n][];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadArray(out a[i]);
return arr;
}
private static void wwp(Action act) {
var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}"
: "{0}";
public static void WriteMulti(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length; i++) {
string fs = wfm(a[i].GetType()) +
((i < a.Length - 1) ? " " : Environment.NewLine);
Console.Write(fs, a[i]);
}
});
}
public static void WriteArray<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T));
string fs1 = fs + " ";
string fs2 = fs + Environment.NewLine;
for (int i = 0; i < a.Length; i++)
Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]);
});
}
public static void WriteLines<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T)) + Environment.NewLine;
foreach (T x in a)
Console.Write(fs, x);
});
}
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
using ll = System.Int64;
public class Contest {
static void Swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static void Swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
Swap1(ref a, ref b);
} // b の方が小さければ交換
static bool Chmin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
} // b の方が小さければ a を更新
static bool Chmax<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
} // b の方が大きければ a を更新
static T[][] InitMat<T>(long len1, long len2, T val) {
T[][] m = new T[len1][];
for (int i = 0; i < m.Length; i++)
m[i] = Enumerable.Repeat(val, (int)len2).ToArray();
return m;
}
static T[][][] InitMat<T>(long len1, long len2, long len3, T val) {
T[][][] m = new T[len1][][];
for (int i = 0; i < m.Length; i++)
m[i] = InitMat(len2, len3, val);
return m;
}
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public static void Main() { Solve_E(); }
public static void Solve_A() {
ll n;
MyIO.ReadMulti(out n);
ll ans = n * n;
MyIO.WriteMulti(ans);
}
public static void Solve_B() {
ll n;
MyIO.ReadMulti(out n);
string s;
MyIO.ReadMulti(out s);
string ans = "No";
if (n % 2 == 0) {
string a = s.Substring(0, (int)(n / 2));
string b = s.Substring((int)(n / 2), (int)(n / 2));
if (a == b)
ans = "Yes";
}
MyIO.WriteMulti(ans);
}
public static void Solve_C() {
ll n;
MyIO.ReadMulti(out n);
VT<ll, ll>[] xyl;
MyIO.ReadLines(n, out xyl);
ll[][] dist = InitMat(n, n, 0L);
double sum = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
sum += Math.Sqrt(
(xyl[i].Item1 - xyl[j].Item1) * (xyl[i].Item1 - xyl[j].Item1) +
(xyl[i].Item2 - xyl[j].Item2) * (xyl[i].Item2 - xyl[j].Item2));
}
}
double ans = (double)sum / (double)n;
MyIO.WriteMulti(ans);
}
public static void Solve_D() {
ll x, y;
MyIO.ReadMulti(out x, out y);
MyIO.WriteMulti(0);
}
public static void Solve_E() {
ll n, t;
MyIO.ReadMulti(out n, out t);
VT<ll, ll>[] abl;
MyIO.ReadLines(n, out abl);
Array.Sort(abl, (x, y) => (int)(x.Item1 - y.Item1));
ll[][] dp = InitMat(n + 1, t + 1, 0L);
for (ll i = 1; i < n; i++) {
for (ll j = 0; j < t; j++) {
dp[i][j] =
Math.Max(dp[i - 1][j],
((0 <= j - abl[i - 1].Item1)
? (dp[i - 1][j - abl[i - 1].Item1] + abl[i - 1].Item2)
: 0));
}
}
ll ans = 0;
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < t; j++) {
Chmax(ref ans, dp[i][j] + abl[i].Item2);
}
}
MyIO.WriteMulti(ans);
}
public static void Solve_F() {}
}
#region MyIO
public struct VT<T, U> {
public T Item1;
public U Item2;
public VT(T a, U b) {
Item1 = a;
Item2 = b;
}
}
public struct VT<T, U, V> {
public T Item1;
public U Item2;
public V Item3;
public VT(T a, U b, V c) {
Item1 = a;
Item2 = b;
Item3 = c;
}
}
public struct VT<T, U, V, W> {
public T Item1;
public U Item2;
public V Item3;
public W Item4;
public VT(T a, U b, V c, W d) {
Item1 = a;
Item2 = b;
Item3 = c;
Item4 = d;
}
}
public class Printer : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Printer(System.IO.Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(System.IO.Stream stream, Encoding encoding)
: base(stream, encoding) {}
}
public static class MyIO {
private static char[] splitter = new char[] { ' ' };
private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
private static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] ReadMulti<T>(out T a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(ar[0]);
return ar;
}
public static string[] ReadMulti<T, U>(out T a, out U b) {
var ar = ReadMulti<T>(out a);
b = cv<U>(ar[1]);
return ar;
}
public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
var ar = ReadMulti<T, U>(out a, out b);
c = cv<V>(ar[2]);
return ar;
}
public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c,
out W d) {
var ar = ReadMulti<T, U, V>(out a, out b, out c);
d = cv<W>(ar[3]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c,
out W d, out X e) {
var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(ar[4]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e,
out Y f) {
var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(ar[5]);
return ar;
}
public static string[] ReadArray<T>(out T[] a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = ar.Select(cv<T>).ToArray();
return ar;
}
public static string[][] ReadLines<T>(long n, out T[] a) {
a = new T[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadMulti(out a[i]);
return arr;
}
public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) {
a = new VT<T, U>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
arr[i] = ReadMulti(out o, out p);
a[i] = new VT<T, U>(o, p);
}
return arr;
}
public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) {
a = new VT<T, U, V>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
arr[i] = ReadMulti(out o, out p, out q);
a[i] = new VT<T, U, V>(o, p, q);
}
return arr;
}
public static string[][] ReadLines<T, U, V, W>(long n,
out VT<T, U, V, W>[] a) {
a = new VT<T, U, V, W>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
arr[i] = ReadMulti(out o, out p, out q, out r);
a[i] = new VT<T, U, V, W>(o, p, q, r);
}
return arr;
}
public static string[][] ReadMatrix<T>(long n, out T[][] a) {
a = new T[n][];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadArray(out a[i]);
return arr;
}
private static void wwp(Action act) {
var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}"
: "{0}";
public static void WriteMulti(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length; i++) {
string fs = wfm(a[i].GetType()) +
((i < a.Length - 1) ? " " : Environment.NewLine);
Console.Write(fs, a[i]);
}
});
}
public static void WriteArray<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T));
string fs1 = fs + " ";
string fs2 = fs + Environment.NewLine;
for (int i = 0; i < a.Length; i++)
Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]);
});
}
public static void WriteLines<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T)) + Environment.NewLine;
foreach (T x in a)
Console.Write(fs, x);
});
}
}
#endregion
|
[["-", 8, 74, 51, 23, 0, 16, 31, 214, 141, 22], ["+", 8, 74, 51, 23, 0, 16, 31, 214, 141, 22], ["-", 8, 74, 51, 23, 0, 16, 12, 214, 141, 22], ["+", 8, 74, 51, 23, 0, 16, 12, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 2,768
| 38
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
int N = int.Parse(str[0]);
int T = int.Parse(str[1]);
long[][] A = new long [N][];
for (var i = 0; i < N; i++) {
string[] str2 = Console.ReadLine().Split();
A[i] = new long[2] { long.Parse(str2[0]), long.Parse(str2[1]) };
}
long[,] D = new long[N + 1, T + 1];
for (var i = 1; i <= T; i++) {
D[0, i] = D[0, i - 1];
for (var j = 1; j <= N; j++) {
D[j, i] = Math.Max(D[j, i - 1], D[j - 1, i]);
if (i - A[j - 1][0] >= 0) {
if (D[j - 1, i - A[j - 1][0]] + A[j - 1][1] > D[j, i]) {
D[j, i] = D[j - 1, i - A[j - 1][0]] + A[j - 1][1];
}
}
}
}
long max = D[N, T];
for (var i = 0; i <= N; i++) {
long max2 = 0;
for (var j = i; j < N; j++) {
max2 = Math.Max(max2, A[j][1]);
}
max = Math.Max(max, D[i, T - 1] + max2);
}
Console.WriteLine(max);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
int N = int.Parse(str[0]);
int T = int.Parse(str[1]);
long[][] A = new long [N][];
for (var i = 0; i < N; i++) {
string[] str2 = Console.ReadLine().Split();
A[i] = new long[2] { long.Parse(str2[0]), long.Parse(str2[1]) };
}
Array.Sort(A, (x, y) => x[0].CompareTo(y[0]));
long[,] D = new long[N + 1, T + 1];
for (var i = 1; i <= T; i++) {
D[0, i] = D[0, i - 1];
for (var j = 1; j <= N; j++) {
D[j, i] = Math.Max(D[j, i - 1], D[j - 1, i]);
if (i - A[j - 1][0] >= 0) {
if (D[j - 1, i - A[j - 1][0]] + A[j - 1][1] > D[j, i]) {
D[j, i] = D[j - 1, i - A[j - 1][0]] + A[j - 1][1];
}
}
}
}
long max = D[N, T];
for (var i = 0; i <= N; i++) {
long max2 = 0;
for (var j = i; j < N; j++) {
max2 = Math.Max(max2, A[j][1]);
}
max = Math.Max(max, D[i, T - 1] + max2);
}
Console.WriteLine(max);
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 24], ["+", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 21], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 218, 8, 213, 63, 214, 205, 204, 205, 22], ["+", 8, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 8, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 24], ["+", 8, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 425
| 26
|
using System;
namespace E {
class Program {
static void Main(string[] args) {
var NT = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var N = NT[0];
var T = NT[1];
var A = new int[N + 1];
var B = new int[N + 1];
for (int i = 1; i < N + 1; i++) {
var AB = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
A[i] = AB[0];
B[i] = AB[1];
}
var DP = new int[N + 1, T, 2];
for (int i = 1; i < N + 1; i++) {
for (int j = 1; j < T; j++) {
if (j >= A[i]) {
DP[i, j, 0] =
Math.Max(DP[i - 1, j - A[i], 0] + B[i], DP[i - 1, j, 0]);
DP[i, j, 1] =
Math.Max(DP[i - 1, j - A[i], 1] + B[i], DP[i - 1, j, 1]);
} else
DP[i, j, 0] = DP[i - 1, j, 0];
DP[i, j, 1] = Math.Max(DP[i - 1, j, 0] + B[i], DP[i, j, 1]);
}
}
Console.WriteLine(DP[N, T - 1, 1]);
}
}
}
|
using System;
namespace E {
class Program {
static void Main(string[] args) {
var NT = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var N = NT[0];
var T = NT[1];
var A = new int[N + 1];
var B = new int[N + 1];
for (int i = 1; i < N + 1; i++) {
var AB = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
A[i] = AB[0];
B[i] = AB[1];
}
var DP = new int[N + 1, T, 2];
for (int i = 1; i < N + 1; i++) {
for (int j = 1; j < T; j++) {
if (j >= A[i]) {
DP[i, j, 0] =
Math.Max(DP[i - 1, j - A[i], 0] + B[i], DP[i - 1, j, 0]);
DP[i, j, 1] =
Math.Max(DP[i - 1, j - A[i], 1] + B[i], DP[i - 1, j, 1]);
} else {
DP[i, j, 0] = DP[i - 1, j, 0];
DP[i, j, 1] = DP[i - 1, j, 1];
}
DP[i, j, 1] = Math.Max(DP[i - 1, j, 0] + B[i], DP[i, j, 1]);
}
}
Console.WriteLine(DP[N, T - 1, 1]);
}
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 21], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 376
| 22
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public class Dish {
public int Time { get; set; }
public int Yammy { get; set; }
}
public static void Main(string[] args) {
var p = Input().ToInt();
var n = p[0];
var t = p[1];
var dishes = new Dish[n];
int maxtime = 0;
for (int i = 0; i < n; i++) {
p = Input().ToInt();
dishes[i] = new Dish() { Time = p[0], Yammy = p[1] };
maxtime = Math.Max(p[0], maxtime);
}
// i個目までの料理をj分未満の時間でとれるおいしさの最大
var dp = new long[n + 1, t + 3000];
for (int i = 0; i < n; i++) {
for (int j = 0; j < t + 3000; j++) {
var d = dishes[i];
if (j < t) {
if (j + d.Time < t + 3000) {
dp[i + 1, j + d.Time] = Math.Max(dp[i, j], dp[i, j] + d.Yammy);
}
}
dp[i + 1, j] = Math.Max(dp[i, j], dp[i + 1, j]);
}
}
long max = 0;
for (int j = t + 2999; j >= 0; j--) {
max = Math.Max(max, dp[n, j]);
}
Console.WriteLine(max);
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(' '); }
public static int Clamp(int val, int max, int min = 0) {
return Math.Min(max, Math.Max(min, val));
}
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str) {
var r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt();
return r;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public class Dish {
public int Time { get; set; }
public int Yammy { get; set; }
}
public static void Main(string[] args) {
var p = Input().ToInt();
var n = p[0];
var t = p[1];
var dishes = new Dish[n];
for (int i = 0; i < n; i++) {
p = Input().ToInt();
dishes[i] = new Dish() { Time = p[0], Yammy = p[1] };
}
Array.Sort(dishes, (u, v) => u.Time - v.Time);
// i個目までの料理をj分未満の時間でとれるおいしさの最大
var dp = new long[n + 1, t + 3001];
for (int i = 0; i < n; i++) {
for (int j = 0; j < t + 3000; j++) {
var d = dishes[i];
if (j < t && j + d.Time <= t + 3000) {
dp[i + 1, j + d.Time] = Math.Max(dp[i, j], dp[i, j] + d.Yammy);
}
dp[i + 1, j] = Math.Max(dp[i, j], dp[i + 1, j]);
}
}
long max = 0;
for (int j = t + 3000; j >= 0; j--) {
max = Math.Max(max, dp[n, j]);
}
Console.WriteLine(max);
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(' '); }
public static int Clamp(int val, int max, int min = 0) {
return Math.Min(max, Math.Max(min, val));
}
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str) {
var r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt();
return r;
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 24], ["+", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 33], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 590
| 44
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;
namespace Program {
public static class ABC145E {
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var T = NN;
var AB = Repeat(0, N).Select(_ => new { A = NN, B = NN }).ToArray();
var dp = new long[N + 1, T + 1];
for (var i = 1; i <= N; i++) {
for (var j = 0; j <= T; j++) {
if (j == 0)
dp[i, j] = dp[i - 1, j];
else if (j - AB[i - 1].A < 0)
dp[i, j] = Max(dp[i - 1, j], dp[i, j - 1]);
else
dp[i, j] = Max(dp[i - 1, j - AB[i - 1].A] + AB[i - 1].B,
Max(dp[i, j - 1], dp[i - 1, j]));
}
for (var j = 1; j <= AB[i - 1].A; j++) {
if (T - j < 0)
continue;
dp[i, T] =
Max(Max(dp[i - 1, T], dp[i - 1, T - j] + AB[i - 1].B), dp[i, T]);
}
}
Console.WriteLine(dp[N, T]);
}
static class Console_ {
static Queue<string> param = new Queue<string>();
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {
base.AutoFlush = false;
}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {
base.AutoFlush = false;
}
}
static public void Main(string[] args) {
if (args.Length == 0) {
Console.SetOut(new Printer(Console.OpenStandardOutput()));
}
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
Console.Out.Flush();
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) {
Func<TR> t = () => default(TR);
return t = () => f(t);
}
static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) {
Func<T1, TR> t = x1 => default(TR);
return t = x1 => f(x1, t);
}
static Func<T1, T2, TR>
Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) {
Func<T1, T2, TR> t = (x1, x2) => default(TR);
return t = (x1, x2) => f(x1, x2, t);
}
static Func<T1, T2, T3, TR>
Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) {
Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR);
return t = (x1, x2, x3) => f(x1, x2, x3, t);
}
static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>(
Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) {
Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR);
return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t);
}
}
}
namespace Library {}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;
namespace Program {
public static class ABC145E {
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var T = NN;
var AB = Repeat(0, N)
.Select(_ => new { A = NN, B = NN })
.OrderByRand()
.OrderBy(e => e.A)
.ToArray();
var dp = new long[N + 1, T + 1];
for (var i = 1; i <= N; i++) {
for (var j = 1; j <= T; j++) {
if (j - AB[i - 1].A < 0)
dp[i, j] = Max(dp[i - 1, j], dp[i, j - 1]);
else
dp[i, j] = Max(dp[i - 1, j - AB[i - 1].A] + AB[i - 1].B,
Max(dp[i, j - 1], dp[i - 1, j]));
}
for (var j = 1; j <= AB[i - 1].A; j++) {
if (T - j < 0)
continue;
dp[i, T] =
Max(Max(dp[i - 1, T], dp[i - 1, T - j] + AB[i - 1].B), dp[i, T]);
}
}
Console.WriteLine(dp[N, T]);
}
static class Console_ {
static Queue<string> param = new Queue<string>();
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {
base.AutoFlush = false;
}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {
base.AutoFlush = false;
}
}
static public void Main(string[] args) {
if (args.Length == 0) {
Console.SetOut(new Printer(Console.OpenStandardOutput()));
}
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
Console.Out.Flush();
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) {
Func<TR> t = () => default(TR);
return t = () => f(t);
}
static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) {
Func<T1, TR> t = x1 => default(TR);
return t = x1 => f(x1, t);
}
static Func<T1, T2, TR>
Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) {
Func<T1, T2, TR> t = (x1, x2) => default(TR);
return t = (x1, x2) => f(x1, x2, t);
}
static Func<T1, T2, T3, TR>
Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) {
Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR);
return t = (x1, x2, x3) => f(x1, x2, x3, t);
}
static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>(
Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) {
Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR);
return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t);
}
}
}
namespace Library {}
|
[["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 1, 0, 11, 31, 204, 205, 22], ["-", 64, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 64, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["-", 64, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 1, 0, 11, 12, 204, 205, 22], ["-", 64, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 64, 1, 0, 11, 12, 204, 206, 207, 0, 21], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 64, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
| 8
| 1,378
| 38
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Contest {
class Program {
static void Main(string[] args) { ABC145.F(); }
class ABC145 {
public static void A() {
var R = Read.Int();
Console.WriteLine(R * R);
}
public static void B() {
var N = Read.Int();
var S = Read.Str();
Console.WriteLine(N % 2 == 0 && S.Substring(0, N / 2) ==
S.Substring(N / 2, N / 2)
? "Yes"
: "No");
}
public static void C() {
var N = Read.Int();
var XY = Read.TupleInt(N);
double sum = 0;
for (int i = 0; i < N; ++i) {
var x1 = XY[i].Item1;
var y1 = XY[i].Item2;
for (int j = i + 1; j < N; ++j) {
var x2 = XY[j].Item1;
var y2 = XY[j].Item2;
sum += Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
}
Console.WriteLine(sum / N * 2);
}
public static void D() {
var X = Read.Int();
var Y = Read.Int();
if ((X + Y) % 3 != 0) {
Console.WriteLine(0);
return;
}
var a = X - (X + Y) / 3;
var b = Y - (X + Y) / 3;
Console.WriteLine(Util.Combin(a + b, 1000000007)(a + b, a));
}
public static void E() {
var N = Read.Int();
var T = Read.Int();
var AB = Read.TupleInt(N);
AB = AB.OrderBy(x => x.Item1).ToArray();
var dp = new int[N + 1, T];
for (int n = 0; n < N; ++n) {
var A = AB[n].Item1;
var B = AB[n].Item2;
for (int t = 0; t < T; ++t) {
if (t >= A) {
dp[n + 1, t] = Math.Max(dp[n, t], dp[n, t - A] + B);
} else {
dp[n + 1, t] = dp[n, t];
}
}
}
int max = 0;
int maxB = 0;
for (int n = N; n > 0; --n) {
max = Math.Max(max, dp[n, T - 1] + maxB);
maxB = Math.Max(maxB, AB[n - 1].Item2);
}
Console.WriteLine(max);
}
public static void F() {
var N = Read.Int();
var K = Read.Int();
var H = Read.LongN();
var Freq = Util.Frequency(H);
if (Freq.Values.Max() + K >= N) {
Console.WriteLine(0);
return;
}
H = new long[] { 0 }.Concat(H).ToArray();
var dp = new long[N + 1, N - K + 1];
for (int len = 0; len <= N - K; ++len) {
dp[0, len] = len == 0 ? 0 : (long)1e18;
}
for (int n = 1; n <= N; ++n) {
dp[n, 0] = (long)1e18;
var h = H[n];
for (int len = 1; len <= N - K; ++len) {
long min = (long)1e18;
for (int prev = 0; prev < n; ++prev) {
min = Math.Min(min, dp[prev, len - 1] + Math.Max(0, h - H[prev]));
}
dp[n, len] = min;
}
}
Console.WriteLine(Enumerable.Range(1, N).Select(n => dp[n, N - K]).Min());
}
}
class Util {
public static Dictionary<T, int> Frequency<T>(T[] array) {
var dict = new Dictionary<T, int>();
foreach (var a in array) {
if (!dict.ContainsKey(a)) {
dict.Add(a, 0);
}
dict[a]++;
}
return dict;
}
public static long Inverse(long a, long p) {
long b = p, c = 1, d = 0, e = 0, f = 0;
while (b != 0) {
e = a / b;
f = b;
b = a - e * b;
a = f;
f = d;
d = c - e * d;
c = f;
}
c %= p;
return c + (c < 0 ? p : 0);
}
public static long[] Facts(int n, long p) {
var facts = new long[n + 1];
facts[0] = 1;
for (int i = 1; i <= n; ++i) {
facts[i] = (i * facts[i - 1]) % p;
}
return facts;
}
public static Func<int, int, long> Combin(int n, long P) {
var fact = Facts(n, P);
var inv = fact.Select(x => Inverse(x, P)).ToArray();
return (N, M) => {
if (N < 0 || N < M || M < 0) {
return 0;
}
return (((fact[N] * inv[M]) % P) * inv[N - M]) % P;
};
}
}
static class Read {
static Queue<string> queue = new Queue<string>();
static void Enqueue() {
var ss = Console.ReadLine().Split(' ');
foreach (var s in ss) {
queue.Enqueue(s);
}
}
public static int Int() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt32(queue.Dequeue());
}
public static long Long() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt64(queue.Dequeue());
}
public static string Str() {
if (queue.Count == 0) {
Enqueue();
}
return queue.Dequeue();
}
public static int[] IntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
public static long[] LongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
public static string[] StrN() { return Console.ReadLine().Split(' '); }
public static Tuple<int, int>[] TupleInt(int n) {
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; ++i) {
var ab = Read.IntN();
list.Add(new Tuple<int, int>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<long, long>[] TupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<string, string>[] TupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = Read.StrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<double, double>[] TupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
public static long[,] LongMatrix(int r, int c) {
var mat = new long[r, c];
for (int i = 0; i < r; ++i) {
var x = Read.LongN();
for (int j = 0; j < c; ++j) {
mat[i, j] = x[j];
}
}
return mat;
}
public static Dictionary<int, HashSet<int>>
AdjacencyList(int N, int M, bool isDirectional = false) {
Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new HashSet<int>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
dict[ab[0]].Add(ab[1]);
if (!isDirectional) {
dict[ab[1]].Add(ab[0]);
}
}
return dict;
}
public static Dictionary<int, Dictionary<int, long>>
AdjacencyListWithWeight(int N, int M) {
Dictionary<int, Dictionary<int, long>> dict =
new Dictionary<int, Dictionary<int, long>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new Dictionary<int, long>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
dict[ab[0]].Add(ab[1], ab[2]);
dict[ab[1]].Add(ab[0], ab[2]);
}
return dict;
}
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Contest {
class Program {
static void Main(string[] args) { ABC145.F(); }
class ABC145 {
public static void A() {
var R = Read.Int();
Console.WriteLine(R * R);
}
public static void B() {
var N = Read.Int();
var S = Read.Str();
Console.WriteLine(N % 2 == 0 && S.Substring(0, N / 2) ==
S.Substring(N / 2, N / 2)
? "Yes"
: "No");
}
public static void C() {
var N = Read.Int();
var XY = Read.TupleInt(N);
double sum = 0;
for (int i = 0; i < N; ++i) {
var x1 = XY[i].Item1;
var y1 = XY[i].Item2;
for (int j = i + 1; j < N; ++j) {
var x2 = XY[j].Item1;
var y2 = XY[j].Item2;
sum += Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
}
Console.WriteLine(sum / N * 2);
}
public static void D() {
var X = Read.Int();
var Y = Read.Int();
if ((X + Y) % 3 != 0) {
Console.WriteLine(0);
return;
}
var a = X - (X + Y) / 3;
var b = Y - (X + Y) / 3;
Console.WriteLine(Util.Combin(a + b, 1000000007)(a + b, a));
}
public static void E() {
var N = Read.Int();
var T = Read.Int();
var AB = Read.TupleInt(N);
AB = AB.OrderBy(x => x.Item1).ToArray();
var dp = new int[N + 1, T];
for (int n = 0; n < N; ++n) {
var A = AB[n].Item1;
var B = AB[n].Item2;
for (int t = 0; t < T; ++t) {
if (t >= A) {
dp[n + 1, t] = Math.Max(dp[n, t], dp[n, t - A] + B);
} else {
dp[n + 1, t] = dp[n, t];
}
}
}
int max = 0;
int maxB = 0;
for (int n = N; n > 0; --n) {
max = Math.Max(max, dp[n, T - 1] + maxB);
maxB = Math.Max(maxB, AB[n - 1].Item2);
}
Console.WriteLine(max);
}
public static void F() {
var N = Read.Int();
var K = Read.Int();
var H = Read.LongN();
var Freq = Util.Frequency(H);
if (N == K) {
Console.WriteLine(0);
return;
}
H = new long[] { 0 }.Concat(H).ToArray();
var dp = new long[N + 1, N - K + 1];
for (int len = 0; len <= N - K; ++len) {
dp[0, len] = len == 0 ? 0 : (long)1e18;
}
for (int n = 1; n <= N; ++n) {
dp[n, 0] = (long)1e18;
var h = H[n];
for (int len = 1; len <= N - K; ++len) {
long min = (long)1e18;
for (int prev = 0; prev < n; ++prev) {
min = Math.Min(min, dp[prev, len - 1] + Math.Max(0, h - H[prev]));
}
dp[n, len] = min;
}
}
Console.WriteLine(Enumerable.Range(1, N).Select(n => dp[n, N - K]).Min());
}
}
class Util {
public static Dictionary<T, int> Frequency<T>(T[] array) {
var dict = new Dictionary<T, int>();
foreach (var a in array) {
if (!dict.ContainsKey(a)) {
dict.Add(a, 0);
}
dict[a]++;
}
return dict;
}
public static long Inverse(long a, long p) {
long b = p, c = 1, d = 0, e = 0, f = 0;
while (b != 0) {
e = a / b;
f = b;
b = a - e * b;
a = f;
f = d;
d = c - e * d;
c = f;
}
c %= p;
return c + (c < 0 ? p : 0);
}
public static long[] Facts(int n, long p) {
var facts = new long[n + 1];
facts[0] = 1;
for (int i = 1; i <= n; ++i) {
facts[i] = (i * facts[i - 1]) % p;
}
return facts;
}
public static Func<int, int, long> Combin(int n, long P) {
var fact = Facts(n, P);
var inv = fact.Select(x => Inverse(x, P)).ToArray();
return (N, M) => {
if (N < 0 || N < M || M < 0) {
return 0;
}
return (((fact[N] * inv[M]) % P) * inv[N - M]) % P;
};
}
}
static class Read {
static Queue<string> queue = new Queue<string>();
static void Enqueue() {
var ss = Console.ReadLine().Split(' ');
foreach (var s in ss) {
queue.Enqueue(s);
}
}
public static int Int() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt32(queue.Dequeue());
}
public static long Long() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt64(queue.Dequeue());
}
public static string Str() {
if (queue.Count == 0) {
Enqueue();
}
return queue.Dequeue();
}
public static int[] IntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
public static long[] LongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
public static string[] StrN() { return Console.ReadLine().Split(' '); }
public static Tuple<int, int>[] TupleInt(int n) {
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; ++i) {
var ab = Read.IntN();
list.Add(new Tuple<int, int>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<long, long>[] TupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<string, string>[] TupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = Read.StrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<double, double>[] TupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
public static long[,] LongMatrix(int r, int c) {
var mat = new long[r, c];
for (int i = 0; i < r; ++i) {
var x = Read.LongN();
for (int j = 0; j < c; ++j) {
mat[i, j] = x[j];
}
}
return mat;
}
public static Dictionary<int, HashSet<int>>
AdjacencyList(int N, int M, bool isDirectional = false) {
Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new HashSet<int>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
dict[ab[0]].Add(ab[1]);
if (!isDirectional) {
dict[ab[1]].Add(ab[0]);
}
}
return dict;
}
public static Dictionary<int, Dictionary<int, long>>
AdjacencyListWithWeight(int N, int M) {
Dictionary<int, Dictionary<int, long>> dict =
new Dictionary<int, Dictionary<int, long>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new Dictionary<int, long>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
dict[ab[0]].Add(ab[1], ab[2]);
dict[ab[1]].Add(ab[0], ab[2]);
}
return dict;
}
}
}
}
|
[["-", 31, 16, 31, 213, 63, 214, 205, 214, 205, 22], ["-", 31, 16, 31, 213, 63, 214, 205, 214, 0, 131], ["-", 31, 16, 31, 213, 63, 214, 205, 214, 141, 22], ["-", 15, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["-", 15, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["-", 15, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["-", 15, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
| 8
| 2,310
| 12
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var n = cin.nextLong();
if (n % 2 == 0) {
Console.WriteLine(((n) / 2) / 2);
} else {
Console.WriteLine(((n) / 2));
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var n = cin.nextLong();
n--;
Console.WriteLine(((n) / 2));
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["-", 0, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["-", 0, 16, 31, 23, 0, 16, 31, 23, 0, 22], ["-", 0, 16, 31, 23, 0, 16, 31, 23, 0, 25], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 85], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 1, 0, 223, 0, 68], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 589
| 27
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace abc144 {
class Program {
static void Main(string[] args) {
// Console.SetIn(new StreamReader("input.txt"));
solve_abc144B();
}
public static void solve_abc144C() {}
public static void solve_abc144B() {
int n = Convert.ToInt32(Console.ReadLine());
bool ok = false;
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
if (i * j == n) {
Console.WriteLine("Yes");
ok = true;
break;
}
if (ok) {
break;
}
}
}
if (!ok) {
Console.WriteLine("No");
}
}
public static void solve_abc144A() {
int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int a = ab[0];
int b = ab[1];
Console.WriteLine(a < 10 && b < 10 ? a * b : -1);
}
/*
BinarySearchIterativeLeft
*/
public static int binarySearchIterativeLeft(long[] haystack, long needle) {
int left = -1;
int right = haystack.Length;
while (left < right - 1) {
int middle = left + (right - left) / 2;
if (haystack[middle] < needle) {
left = middle;
} else {
right = middle;
}
}
return right;
}
public static int binSearch(int[] haystack, int needle) {
int l = -1;
int r = haystack.Length;
while (l < r - 1) {
int mid = (r + l) / 2;
if (haystack[mid] <= needle) {
l = mid;
} else {
r = mid;
}
}
return r;
}
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace abc144 {
class Program {
static void Main(string[] args) {
// Console.SetIn(new StreamReader("input.txt"));
solve_abc144B();
}
public static void solve_abc144C() {}
public static void solve_abc144B() {
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
if (i * j == n) {
Console.WriteLine("Yes");
return;
}
}
}
Console.WriteLine("No");
}
public static void solve_abc144A() {
int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int a = ab[0];
int b = ab[1];
Console.WriteLine(a < 10 && b < 10 ? a * b : -1);
}
/*
BinarySearchIterativeLeft
*/
public static int binarySearchIterativeLeft(long[] haystack, long needle) {
int left = -1;
int right = haystack.Length;
while (left < right - 1) {
int middle = left + (right - left) / 2;
if (haystack[middle] < needle) {
left = middle;
} else {
right = middle;
}
}
return right;
}
public static int binSearch(int[] haystack, int needle) {
int l = -1;
int r = haystack.Length;
while (l < r - 1) {
int mid = (r + l) / 2;
if (haystack[mid] <= needle) {
l = mid;
} else {
r = mid;
}
}
return r;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 15, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 241, 0, 111], ["-", 0, 195, 8, 196, 0, 57, 15, 241, 0, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 384
| 26
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1 {
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
public class Class1 {
static void Main(string[] args) {
// string[] s = Console.ReadLine().Split(' ');
int a = Int32.Parse(Console.ReadLine());
// int b = Int32.Parse(s[1]);
if (a > 81) {
Console.WriteLine("No");
return;
}
for (int i = 1; i < 10; i++) {
if (a % i == 0) {
Console.WriteLine("Yes");
return;
}
}
Console.WriteLine("No");
}
static int rec(int[] n, int i, int j, int x) {
if (i + 1 == j) {
return Math.Min(n[j], x);
}
return rec(n, i + 1, j, n[i]) + rec(n, i, j - 1, n[j]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1 {
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
public class Class1 {
static void Main(string[] args) {
// string[] s = Console.ReadLine().Split(' ');
int a = Int32.Parse(Console.ReadLine());
// int b = Int32.Parse(s[1]);
if (a > 81) {
Console.WriteLine("No");
return;
}
for (int i = 1; i < 10; i++) {
if ((a % i == 0) && a / i < 10) {
Console.WriteLine("Yes");
return;
}
}
Console.WriteLine("No");
}
static int rec(int[] n, int i, int j, int x) {
if (i + 1 == j) {
return Math.Min(n[j], x);
}
return rec(n, i + 1, j, n[i]) + rec(n, i, j - 1, n[j]);
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 85], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 229
| 8
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Convert;
using static System.Console;
using static System.Math;
namespace AtCorder {
class Program {
static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var N = cin.ReadInt;
for (int i = 2; i <= 9; i++) {
if (N % i == 0 && N / i <= 9) {
WriteLine("Yes");
return;
}
}
WriteLine("No");
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Convert;
using static System.Console;
using static System.Math;
namespace AtCorder {
class Program {
static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var N = cin.ReadInt;
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
if (i * j == N) {
WriteLine("Yes");
return;
}
}
}
WriteLine("No");
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 24], ["+", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 85], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 483
| 28
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// ReSharper disable PossibleNullReferenceException
// ReSharper disable AssignNullToNotNullAttribute
namespace ProCon {
class Program {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
var divMaxCandidate = (long)Math.Sqrt(n) + 1;
long divMax = n % 2 == 0 ? 2 : 1;
for (long i = 3; i < divMaxCandidate; i += 2) {
if (n % i == 0)
divMax = i;
}
var d = n / divMax;
Console.WriteLine(d + divMax - 2);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// ReSharper disable PossibleNullReferenceException
// ReSharper disable AssignNullToNotNullAttribute
namespace ProCon {
class Program {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
var divMaxCandidate = (long)Math.Sqrt(n) + 1;
long divMax = 0;
for (long i = 1; i < divMaxCandidate; i++) {
if (n % i == 0)
divMax = i;
}
var d = n / divMax;
Console.WriteLine(d + divMax - 2);
}
}
}
|
[["-", 0, 212, 0, 41, 15, 16, 31, 16, 31, 22], ["-", 0, 212, 0, 41, 15, 16, 31, 16, 17, 109], ["-", 0, 212, 0, 41, 15, 16, 31, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 41, 15, 16, 17, 60], ["-", 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], ["-", 0, 198, 0, 200, 0, 212, 0, 41, 75, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["-", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29]]
| 8
| 137
| 13
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AtCoder.C {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var N = ReadLong();
if (IsPrime(N))
return N - 1;
throw new Exception();
var sqrt = Math.Sqrt(N);
for (var i = (long)Math.Ceiling(sqrt); i < N; i++) {
if (N % i == 0) {
return i + N / i - 2;
}
}
throw new Exception();
}
#region Console
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
public static bool IsPrime(long n) {
if (n == 0 || n == 1)
return false;
for (long i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AtCoder.C {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var N = ReadLong();
if (IsPrime(N))
return N - 1;
var sqrt = Math.Sqrt(N);
for (var i = (long)Math.Floor(sqrt); i > 0; i--) {
if (N % i == 0) {
return i + N / i - 2;
}
}
throw new Exception();
}
#region Console
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
public static bool IsPrime(long n) {
if (n == 0 || n == 1)
return false;
for (long i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 293, 0, 294], ["-", 0, 195, 8, 196, 0, 293, 0, 230, 0, 228], ["-", 0, 195, 8, 196, 0, 293, 0, 230, 39, 22], ["-", 8, 196, 0, 293, 0, 230, 3, 4, 0, 24], ["-", 8, 196, 0, 293, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 293, 0, 35], ["-", 0, 212, 0, 74, 51, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
| 8
| 317
| 14
|
using System;
class Atcoder_Templete {
static void Main(string[] args) {
string input_string = Console.ReadLine();
long input_int = long.Parse(input_string);
decimal rootOfInputDouble = (decimal)Math.Sqrt(input_int);
long result = 0;
long niceX = 0;
long niceY = 0;
long rootOfInputInt = (long)rootOfInputDouble;
if (rootOfInputDouble - rootOfInputInt == 0) {
result = 2 * (rootOfInputInt - 1);
} else {
for (long i = rootOfInputInt - 1; i < rootOfInputInt; i--) {
if (input_int % i == 0) {
niceX = i;
niceY = input_int / i;
break;
}
}
result = niceX + niceY - 2;
}
//出力
Console.WriteLine(result);
}
}
|
using System;
class Atcoder_Templete {
static void Main(string[] args) {
string input_string = Console.ReadLine();
long input_int = long.Parse(input_string);
decimal rootOfInputDouble = (decimal)Math.Sqrt(input_int);
long result = 0;
long niceX = 0;
long niceY = 0;
long rootOfInputInt = (long)rootOfInputDouble;
for (long i = rootOfInputInt; 0 < i; i--) {
if (input_int % i == 0) {
niceX = i;
niceY = input_int / i;
break;
}
}
result = niceX + niceY - 2;
//出力
Console.WriteLine(result);
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 57, 75, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 203], ["-", 0, 57, 75, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 152
| 29
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
// var s = Console.ReadLine();
// var n = int.Parse(Console.ReadLine());
double[] abx = Console.ReadLine().Split().Select(double.Parse).ToArray();
var a = abx[0];
var b = abx[1];
var x = abx[2];
double c = 2 * x / (a * b);
double radian = Math.Atan(b / c);
double ans = radian * 180 / Math.PI;
if (c * c > a * a + b * b) {
c = (2 * a * a * b - 2 * x) / (a * a);
radian = Math.Atan(c / a);
ans = radian * 180 / Math.PI;
}
// 出力
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
// var s = Console.ReadLine();
// var n = int.Parse(Console.ReadLine());
double[] abx = Console.ReadLine().Split().Select(double.Parse).ToArray();
var a = abx[0];
var b = abx[1];
var x = abx[2];
double c = 2 * x / (a * b);
double radian = Math.Atan(b / c);
double ans = radian * 180 / Math.PI;
if (x / a > a * b / 2) {
c = (2 * a * a * b - 2 * x) / (a * a);
radian = Math.Atan(c / a);
ans = radian * 180 / Math.PI;
}
// 出力
Console.WriteLine(ans);
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 85], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 48], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 196
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
const int MOD = 1000000007;
const long INF = 1 << 61;
static void Main(string[] args) { Solve(); }
static void Solve() {
Scaner cin = new Scaner();
write cout = new write();
Math2 mmath = new Math2();
//ここから
var o = cin.IntM;
double a = o[0];
double b = o[1];
double x = o[2];
double c = 2 * x / a * a - b;
double d = 2 * a / b * x;
if (2 * x > a * a * b) {
double ans = Math.Atan((b - c) / a);
cout.wri(ans * 180 / Math.PI);
} else {
double ans = Math.Atan(d / b);
cout.wri(ans * 180 / Math.PI);
}
}
}
// b-aで降順
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
public class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
// Nまでの階乗をセットしておく
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = pow(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
// nCr 引数:n r (mod)
public long nCr(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
//階乗(O(logN)) 引数:底x n乗 (MOD)
public long pow(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
//最大公約数 引数:整数x,y
public long GCD(long x, long y) {
while (y != 0) {
var r = x % y;
x = y;
y = r;
}
return x;
}
//最小公倍数 引数:整数x,y
public long LCM(long x, long y) { return x * y / GCD(x, y); }
//素因数分解 引数:整数N
public Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> PrimeFactorization2(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
namespace CompLib.Algorithms {
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrM => Str.Split(' ');
public long[] LongM => StrM.Select(long.Parse).ToArray();
public int[] IntM => StrM.Select(int.Parse).ToArray();
public char[] CharM => Str.ToArray();
public long Long1 => LongM[0];
public int Int1 => IntM[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
const int MOD = 1000000007;
const long INF = 1 << 61;
static void Main(string[] args) { Solve(); }
static void Solve() {
Scaner cin = new Scaner();
write cout = new write();
Math2 mmath = new Math2();
//ここから
var o = cin.IntM;
double a = (double)o[0];
double b = (double)o[1];
double x = (double)o[2];
double S = x / a;
double c = 2 * x / a / a - b;
double d = 2 * x / b / a;
if (2 * x > a * a * b) {
double ans = Math.Atan2((b - c), a);
cout.wri(ans * 180 / Math.PI);
} else {
double ans = Math.Atan2(b, d);
cout.wri(ans * 180 / Math.PI);
}
}
}
// b-aで降順
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
public class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
// Nまでの階乗をセットしておく
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = pow(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
// nCr 引数:n r (mod)
public long nCr(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
//階乗(O(logN)) 引数:底x n乗 (MOD)
public long pow(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
//最大公約数 引数:整数x,y
public long GCD(long x, long y) {
while (y != 0) {
var r = x % y;
x = y;
y = r;
}
return x;
}
//最小公倍数 引数:整数x,y
public long LCM(long x, long y) { return x * y / GCD(x, y); }
//素因数分解 引数:整数N
public Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> PrimeFactorization2(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
namespace CompLib.Algorithms {
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrM => Str.Split(' ');
public long[] LongM => StrM.Select(long.Parse).ToArray();
public int[] IntM => StrM.Select(int.Parse).ToArray();
public char[] CharM => Str.ToArray();
public long Long1 => LongM[0];
public int Int1 => IntM[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 85], ["-", 0, 212, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 212, 0, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 1,536
| 34
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
class Program {
static void Main(string[] args) {
//入力を受け取る
var ABX =
Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray();
double a = ABX[0];
double b = ABX[1];
double X = ABX[2];
double capa = a * a * b;
double ans = 0D;
if (capa / 2 <= X) {
double tmp = a * a * a;
double hiki = 2 * (a * a * b - X) / (tmp);
Console.WriteLine(hiki);
ans = (double)Math.Atan(hiki);
} else {
ans = (double)Math.Atan((a * b * b) / (2 * X));
// Console.WriteLine(ans);
}
ans = ans * 180 / ((double)Math.PI);
string res = ans.ToString("F10");
Console.WriteLine(ans);
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
class Program {
static void Main(string[] args) {
//入力を受け取る
var ABX =
Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray();
double a = ABX[0];
double b = ABX[1];
double X = ABX[2];
double capa = a * a * b;
double ans = 0D;
if (capa / 2 <= X) {
double tmp = a * a * a;
double hiki = 2 * (a * a * b - X) / (tmp);
// Console.WriteLine(hiki);
ans = (double)Math.Atan(hiki);
} else {
ans = (double)Math.Atan((a * b * b) / (2 * X));
// Console.WriteLine(ans);
}
ans = ans * 180 / ((double)Math.PI);
string res = ans.ToString("F10");
Console.WriteLine(ans);
}
}
|
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 234
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProblemD {
class Program {
static void Main(string[] args) {
var read =
Console.ReadLine().Split(' ').Select(x_ => int.Parse(x_)).ToArray();
var a = (double)read[0];
var b = (double)read[1];
var x = (double)read[2];
var c = Math.Sqrt(2 * x / b);
if (c <= a)
Console.WriteLine(GetDegree(Math.Atan(b / c)));
else {
var d = (2 * x - a * a * b) / (a * a);
Console.WriteLine(GetDegree(Math.Atan((b - d) / a)));
}
}
static double GetDegree(double radian) { return radian * 180 / Math.PI; }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProblemD {
class Program {
static void Main(string[] args) {
var read =
Console.ReadLine().Split(' ').Select(x_ => int.Parse(x_)).ToArray();
var a = (double)read[0];
var b = (double)read[1];
var x = (double)read[2];
double ret;
var c = 2 * x / b / a;
if (c <= a) {
ret = GetDegree(Math.Atan(b / c));
Console.WriteLine(ret);
} else {
var d = (2 * x - a * a * b) / (a * a);
Console.WriteLine(GetDegree(Math.Atan((b - d) / a)));
}
}
static double GetDegree(double radian) { return radian * 180 / Math.PI; }
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["-", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["-", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 211
| 24
|
namespace AtCoder.ABC.D144 {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.IO;
using AtCoder.ABC.IO;
public class Quest {
public object Solve(Parser parser) {
int a = parser.Integer();
int b = parser.Integer();
int x = parser.Integer();
double theta1 = Math.Atan(2 * (a * a * b - x) / (double)(a * a * a));
double theta2 = Math.Atan(b * b * a / (double)(2 * x));
var x1 = a * a * (2 * b - a * Math.Tan(theta1)) / 2;
var x2 = a * b / Math.Tan(theta2) / 2;
// System.Console.WriteLine(theta1 * 180 / Math.PI);
// System.Console.WriteLine(theta2 * 180 / Math.PI);
// System.Console.WriteLine(x1 - x);
// System.Console.WriteLine(x2 - x);
return theta1 < 1 ? theta1 * 180 / Math.PI : theta2 * 180 / Math.PI;
}
}
static class Program {
static void Main(string[] args) {
var i = new Parser(Console.OpenStandardInput());
var o = new Printer(Console.OpenStandardOutput());
var got = new Quest().Solve(i);
o.WriteLine(got);
o.Flush();
}
}
}
namespace AtCoder.ABC.IO {
#region IO
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
public class Parser {
public Parser(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof;
public bool IsEndOfStream {
get { return isEof; }
}
public IEnumerable<Parser> Take(int n) {
return Enumerable.Range(1, n).Select(_ => this);
}
private byte read() {
if (isEof)
return 0;
if (ptr < len)
return buf[ptr++];
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) > 0)
return buf[ptr++];
isEof = true;
return 0;
}
public char Char() {
byte b;
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 = (char)read())
if (b == 0)
break;
else if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() {
if (isEof)
return long.MinValue;
long ret = 0;
byte b;
var ng = false;
do
b = read();
while (b != 0 && b != '-' && (b < '0' || '9' < b));
if (b == 0)
return long.MinValue;
if (b == '-') {
ng = true;
b = read();
}
for (;; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
public double Double() {
var s = Scan();
return s != "" ? double.Parse(s, CultureInfo.InvariantCulture)
: double.NaN;
}
static T[] enumerate<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f();
return a;
}
public char[] Char(int n) { return enumerate(n, Char); }
public string[] Scan(int n) { return enumerate(n, Scan); }
public double[] Double(int n) { return enumerate(n, Double); }
public int[] Integer(int n) { return enumerate(n, Integer); }
public long[] Long(int n) { return enumerate(n, Long); }
}
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {}
public void Write<T>(string format, T[] source) {
base.Write(format, source.OfType<object>().ToArray());
}
public void WriteLine<T>(string format, T[] source) {
base.WriteLine(format, source.OfType<object>().ToArray());
}
}
#endregion
}
|
namespace AtCoder.ABC.D144 {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.IO;
using AtCoder.ABC.IO;
public class Quest {
public object Solve(Parser parser) {
int a = parser.Integer();
int b = parser.Integer();
int x = parser.Integer();
double theta1 = Math.Atan(2 * (a * a * b - x) / (double)(a * a * a));
double theta2 = Math.Atan(b * b * a / (double)(2 * x));
var x1 = a * a * (2 * b - a * Math.Tan(theta1)) / 2;
var x2 = a * b / Math.Tan(theta2) / 2;
if (a * a * b / 2.0 <= x) {
return theta1 * 180 / Math.PI;
} else {
return theta2 * 180 / Math.PI;
}
}
}
static class Program {
static void Main(string[] args) {
var i = new Parser(Console.OpenStandardInput());
var o = new Printer(Console.OpenStandardOutput());
var got = new Quest().Solve(i);
o.WriteLine(got);
o.Flush();
}
}
}
namespace AtCoder.ABC.IO {
#region IO
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
public class Parser {
public Parser(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof;
public bool IsEndOfStream {
get { return isEof; }
}
public IEnumerable<Parser> Take(int n) {
return Enumerable.Range(1, n).Select(_ => this);
}
private byte read() {
if (isEof)
return 0;
if (ptr < len)
return buf[ptr++];
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) > 0)
return buf[ptr++];
isEof = true;
return 0;
}
public char Char() {
byte b;
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 = (char)read())
if (b == 0)
break;
else if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() {
if (isEof)
return long.MinValue;
long ret = 0;
byte b;
var ng = false;
do
b = read();
while (b != 0 && b != '-' && (b < '0' || '9' < b));
if (b == 0)
return long.MinValue;
if (b == '-') {
ng = true;
b = read();
}
for (;; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
public double Double() {
var s = Scan();
return s != "" ? double.Parse(s, CultureInfo.InvariantCulture)
: double.NaN;
}
static T[] enumerate<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f();
return a;
}
public char[] Char(int n) { return enumerate(n, Char); }
public string[] Scan(int n) { return enumerate(n, Scan); }
public double[] Double(int n) { return enumerate(n, Double); }
public int[] Integer(int n) { return enumerate(n, Integer); }
public long[] Long(int n) { return enumerate(n, Long); }
}
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {}
public void Write<T>(string format, T[] source) {
base.Write(format, source.OfType<object>().ToArray());
}
public void WriteLine<T>(string format, T[] source) {
base.WriteLine(format, source.OfType<object>().ToArray());
}
}
#endregion
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 48], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 250], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 37, 0, 41, 15, 16, 17, 18], ["-", 8, 196, 0, 37, 0, 41, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 37, 0, 41, 0, 101], ["-", 0, 37, 0, 41, 64, 16, 31, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 37, 0, 41, 0, 102], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 1,106
| 24
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
double a = double.Parse(input[0]);
double b = double.Parse(input[1]);
double x = double.Parse(input[2]);
double theta = 0;
double degree = 0;
if ((x / (a * a)) > (b / 2)) {
theta = Math.Atan((2 * (b - (x / (a * a)))) / a);
Console.WriteLine(theta);
} else {
theta = Math.Atan(b / ((2 * x) / (a * b)));
Console.WriteLine(theta);
}
degree = (theta / 3.14159265358979d) * 180.000000d;
Console.WriteLine(degree);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
double a = double.Parse(input[0]);
double b = double.Parse(input[1]);
double x = double.Parse(input[2]);
double theta = 0;
double degree = 0;
if ((x / (a * a)) > (b / 2)) {
theta = Math.Atan((2 * (b - (x / (a * a)))) / a);
} else {
theta = Math.Atan(b / ((2 * x) / (a * b)));
}
degree = (theta / 3.14159265358979d) * 180.000000d;
Console.WriteLine(degree);
}
}
|
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 16, 12, 23, 0, 16, 12, 23, 0, 25], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
| 8
| 196
| 14
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
double A = double.Parse(str[0]);
double B = double.Parse(str[1]);
double X = double.Parse(str[2]);
double N = 0;
if (X < A * A * B / 2) {
N = 90 - Math.Atan((X / Math.Max(A, B) / B * 2) / (A)) / Math.PI * 180;
} else {
X = A * A * B - X;
N = Math.Atan((X / Math.Max(A, B) / A * 2) / (A)) / Math.PI * 180;
}
Console.WriteLine(N);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
double A = double.Parse(str[0]);
double B = double.Parse(str[1]);
double X = double.Parse(str[2]);
double N = 0;
if (X < A * A * B / 2) {
N = 90 - Math.Atan((X / B / B * 2) / (A)) / Math.PI * 180;
} else {
X = A * A * B - X;
N = Math.Atan((X / A / A * 2) / (A)) / Math.PI * 180;
}
Console.WriteLine(N);
}
}
|
[["-", 31, 16, 31, 16, 12, 213, 63, 214, 205, 22], ["-", 31, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["-", 31, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["-", 31, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["-", 31, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 31, 16, 31, 16, 12, 213, 3, 4, 0, 21], ["-", 31, 16, 31, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 188
| 14
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = (int)1e9 + 7;
static void Main() {
Sc sc = new Sc();
var s = sc.Da;
s[2] /= s[0];
if (s[2] <= s[0] * s[1] / 2) {
Console.WriteLine(
"{0}", Gp4((s[2] * 2) / s[1], s[1], 0, 0, (s[2] * 2) / s[1], 0));
} else {
s[2] = s[0] * s[1] - s[2];
Console.WriteLine(
"{0}", 90 - Gp4((s[2] * 2) / s[0], s[0], 0, 0, (s[2] * 2) / s[0], 0));
}
}
static double Gp4(double ax, double ay, double bx, double by, double cx,
double cy) {
double a1 = ax - bx, a2 = ay - by, c1 = cx - bx, c2 = cy - by;
return Math.Acos((a1 * c1 + a2 * c2) /
Math.Sqrt((a1 * a1 + a2 * a2) * (c1 * c1 + c2 * c2))) *
180 / Math.PI;
}
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(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(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
int.Parse);
}
public int[] Ia3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
long.Parse);
}
public long[] La3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
long.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = (int)1e9 + 7;
static void Main() {
Sc sc = new Sc();
var s = sc.Da;
s[2] /= s[0];
if (s[0] * s[1] == s[2]) {
Console.WriteLine("{0}", 0);
} else if (s[2] <= s[0] * s[1] / 2) {
Console.WriteLine(
"{0}", Gp4((s[2] * 2) / s[1], s[1], 0, 0, (s[2] * 2) / s[1], 0));
} else {
s[2] = s[0] * s[1] - s[2];
Console.WriteLine(
"{0}", 90 - Gp4((s[2] * 2) / s[0], s[0], 0, 0, (s[2] * 2) / s[0], 0));
}
}
static double Gp4(double ax, double ay, double bx, double by, double cx,
double cy) {
double a1 = ax - bx, a2 = ay - by, c1 = cx - bx, c2 = cy - by;
return Math.Acos((a1 * c1 + a2 * c2) /
Math.Sqrt((a1 * a1 + a2 * a2) * (c1 * c1 + c2 * c2))) *
180 / Math.PI;
}
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(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(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
int.Parse);
}
public int[] Ia3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
long.Parse);
}
public long[] La3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
long.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
[["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 204, 205, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 1,136
| 31
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC144E {
class Program {
static void Main(string[] args) {
var N = RLong;
var K = RLong;
var A = RLongs.OrderBy(x => x).ToArray();
var F = RLongs.OrderByDescending(x => x).ToArray();
// チームの成績
long l = -1;
long r = long.MaxValue / 2;
while (r - l > 1) {
long mid = l + (r - l) / 2;
long k = 0;
for (int i = 0; i < N; i++) {
k += A[i] - mid / F[i];
}
if (k <= K)
r = mid;
else
l = mid;
}
Console.WriteLine(r);
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//以下未テスト
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; }
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a % mod, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
static class Debug {
static public void Draw2D<T>(T[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
string[,] map2 = new string[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0.ToString();
else if (i == 0)
map2[i, j] = (j - 1).ToString();
else if (j == 0)
map2[i, j] = (i - 1).ToString();
else
map2[i, j] = map[i - 1, j - 1].ToString();
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j].Last());
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
public static void Draw1D<T>(T[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
}
}
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC144E {
class Program {
static void Main(string[] args) {
var N = RLong;
var K = RLong;
var A = RLongs.OrderBy(x => x).ToArray();
var F = RLongs.OrderByDescending(x => x).ToArray();
// チームの成績
long l = -1;
long r = long.MaxValue / 2;
while (r - l > 1) {
long mid = l + (r - l) / 2;
long k = 0;
for (int i = 0; i < N; i++) {
k += Math.Max(0, A[i] - mid / F[i]);
}
if (k <= K)
r = mid;
else
l = mid;
}
Console.WriteLine(r);
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//以下未テスト
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; }
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a % mod, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
static class Debug {
static public void Draw2D<T>(T[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
string[,] map2 = new string[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0.ToString();
else if (i == 0)
map2[i, j] = (j - 1).ToString();
else if (j == 0)
map2[i, j] = (i - 1).ToString();
else
map2[i, j] = map[i - 1, j - 1].ToString();
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j].Last());
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
public static void Draw1D<T>(T[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
}
}
|
[["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
| 8
| 1,247
| 7
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var N = sc.ReadInt();
var K = sc.ReadLong();
var A = sc.ReadLongArray(N);
var F = sc.ReadLongArray(N);
Array.Sort(A);
Array.Sort(F);
Array.Reverse(F);
Console.WriteLine(string.Join(" ", A));
Console.WriteLine(string.Join(" ", F));
var Mx = new Tuple<long, long, long>[N];
for (int i = 0; i < N; i++) {
Mx[i] = Tuple.Create(A[i] * F[i], A[i], F[i]);
}
Array.Sort(Mx);
Array.Reverse(Mx);
// 最大値をXにするときの最小コストを二分探索で求める
var l = -1L;
var r = Mx[0].Item1;
while (r - l > 1) {
var mid = l + (r - l) / 2;
var ok = true;
var rem = K;
for (int i = 0; i < N; i++) {
var cost = Mx[i].Item1;
var a = Mx[i].Item2;
var f = Mx[i].Item3;
if (cost <= mid)
continue;
var d = cost - mid;
var ma = Math.Min(a, (d + (f - 1)) / f);
var ncost = f * (a - ma);
rem -= ma;
if (ncost > cost || rem < 0) {
ok = false;
break;
}
}
if (ok)
r = mid;
else
l = mid;
}
var ans = r;
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var N = sc.ReadInt();
var K = sc.ReadLong();
var A = sc.ReadLongArray(N);
var F = sc.ReadLongArray(N);
Array.Sort(A);
Array.Sort(F);
Array.Reverse(F);
var Mx = new Tuple<long, long, long>[N];
for (int i = 0; i < N; i++) {
Mx[i] = Tuple.Create(A[i] * F[i], A[i], F[i]);
}
Array.Sort(Mx);
Array.Reverse(Mx);
// 最大値をXにするときの最小コストを二分探索で求める
var l = -1L;
var r = Mx[0].Item1;
while (r - l > 1) {
var mid = l + (r - l) / 2;
var ok = true;
var rem = K;
for (int i = 0; i < N; i++) {
var cost = Mx[i].Item1;
var a = Mx[i].Item2;
var f = Mx[i].Item3;
if (cost <= mid)
continue;
var d = cost - mid;
var ma = Math.Min(a, (d + (f - 1)) / f);
var ncost = f * (a - ma);
rem -= ma;
if (ncost > cost || rem < 0) {
ok = false;
break;
}
}
if (ok)
r = mid;
else
l = mid;
}
var ans = r;
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public 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;
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 1,413
| 32
|
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 : IComparable {
public int x;
public int y;
public int id = 0;
public Pair(int X, int Y, int Id) {
x = X;
y = Y;
id = Id;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return y.CompareTo(kore.y);
}
}
class Program {
public static Mlong[] combs;
static void Main(string[] args) {
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
int n = scan.Integer();
long k = scan.Long();
long[] a = scan.Long(n);
long[] f = scan.Long(n);
Array.Sort(a);
Array.Sort(f);
Array.Reverse(a);
long ng = -1;
long ok = (long)Math.Pow(10, 12);
while (Math.Abs(ok - ng) > 1) {
long mid = (ok + ng) / 2;
if (mid == -1) {
break;
}
long count = 0;
bool yes = false;
for (int i = 0; i < n; i++) {
long togo = mid / f[i];
count += a[i] - togo;
if (count > k) {
yes = true;
break;
}
}
if (!yes) {
ok = mid;
} else {
ng = mid;
}
}
Console.WriteLine(ok);
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static bool isOK(int index, int key, int[] moto) {
return moto[index] >= key;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
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 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 long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static long[] SoinsuBunkai(long num) {
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1) {
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps) {
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。
n = DivideWith(n, i + p, primes);
if (n == 1)
break;
}
i += 30;
}
return primes.ToArray();
}
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
}
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 Mlong[] MLong(int n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(int h, int w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(int n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
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 : IComparable {
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); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
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); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public 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 : IComparable {
public int x;
public int y;
public int id = 0;
public Pair(int X, int Y, int Id) {
x = X;
y = Y;
id = Id;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return y.CompareTo(kore.y);
}
}
class Program {
public static Mlong[] combs;
static void Main(string[] args) {
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
int n = scan.Integer();
long k = scan.Long();
long[] a = scan.Long(n);
long[] f = scan.Long(n);
Array.Sort(a);
Array.Sort(f);
Array.Reverse(a);
long ng = -1;
long ok = (long)Math.Pow(10, 12);
while (Math.Abs(ok - ng) > 1) {
long mid = (ok + ng) / 2;
if (mid == -1) {
break;
}
long count = 0;
bool yes = false;
for (int i = 0; i < n; i++) {
long togo = mid / f[i];
count += Math.Max(0, a[i] - togo);
if (count > k) {
yes = true;
break;
}
}
if (!yes) {
ok = mid;
} else {
ng = mid;
}
}
Console.WriteLine(ok);
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static bool isOK(int index, int key, int[] moto) {
return moto[index] >= key;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
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 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 long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static long[] SoinsuBunkai(long num) {
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1) {
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps) {
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。
n = DivideWith(n, i + p, primes);
if (n == 1)
break;
}
i += 30;
}
return primes.ToArray();
}
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
}
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 Mlong[] MLong(int n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(int h, int w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(int n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
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 : IComparable {
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); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
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); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public 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, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
| 8
| 6,777
| 7
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
partial class Program {
static long mod = 1000000007;
static void Swap<T>(ref T a, ref T b) {
T temp = a;
a = b;
b = temp;
}
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
Solve();
Console.Out.Flush();
Console.ReadKey();
}
//ここから
static int N;
static long K;
static long[] A;
static long[] F;
static Pair[] score;
static void Solve() {
Multi(out N, out K);
A = GetLongArray().OrderBy(o => o).ToArray();
F = GetLongArray().OrderByDescending(o => o).ToArray();
score = Enumerable.Range(0, N)
.Select(s => new Pair(F[s], A[s] * F[s]))
.ToArray();
long ans = BinarySearch();
Console.WriteLine(ans);
}
static long BinarySearch() {
long ok = (long)Math.Pow(10, 18);
long ng = -1;
while (Math.Abs(ok - ng) > 1) {
var mid = (ok + ng) / 2;
if (IsOK(mid))
ok = mid;
else
ng = mid;
}
return ok;
}
static bool IsOK(long key) {
return score.Select(s => (s.Value - key + s.Key - 1) / s.Key).Sum() <= K;
}
}
class Pair {
public Pair(long key, long value) {
Key = key;
Value = value;
}
public long Key { get; set; }
public long Value { get; set; }
}
//拡張メソッド
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static string yesno(this bool b) { return b ? "yes" : "no"; }
public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
}
partial class Program {
static public string GetStr() { return Console.ReadLine().Trim(); }
static public char GetChar() { return Console.ReadLine().Trim()[0]; }
static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
static public double GetDouble() {
return double.Parse(Console.ReadLine().Trim());
}
static public string[] GetStrArray() {
return Console.ReadLine().Trim().Split(' ');
}
static public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
static public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
static public T[][] CreateJaggedArray<T>(int H, int W, T value) {
return Enumerable.Repeat(0, H)
.Select(s => Enumerable.Repeat(value, W).ToArray())
.ToArray();
}
static public int[][] GetIntJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetIntArray().ToArray())
.ToArray();
}
static public long[][] GetLongJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetLongArray().ToArray())
.ToArray();
}
static public char[][] GetCharJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetStr().ToCharArray())
.ToArray();
}
static public double[][] GetDoubleJaggedArray(int N) {
return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray();
}
static public void WriteObjects<T>(IReadOnlyCollection<T> values) {
var array = values.ToArray();
var num = array.Length;
if (num == 0)
return;
Console.Write(array[0]);
for (int i = 1; i < num; i++) {
Console.Write(" " + array[i]);
}
Console.WriteLine();
}
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, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d,
out X e, out Y f) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
f = cv<Y>(ar[5]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
partial class Program {
static long mod = 1000000007;
static void Swap<T>(ref T a, ref T b) {
T temp = a;
a = b;
b = temp;
}
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
Solve();
Console.Out.Flush();
Console.ReadKey();
}
//ここから
static int N;
static long K;
static long[] A;
static long[] F;
static Pair[] score;
static void Solve() {
Multi(out N, out K);
A = GetLongArray().OrderBy(o => o).ToArray();
F = GetLongArray().OrderByDescending(o => o).ToArray();
score = Enumerable.Range(0, N)
.Select(s => new Pair(F[s], A[s] * F[s]))
.ToArray();
long ans = BinarySearch();
Console.WriteLine(ans);
}
static long BinarySearch() {
long ok = (long)Math.Pow(10, 18);
long ng = -1;
while (Math.Abs(ok - ng) > 1) {
var mid = (ok + ng) / 2;
if (IsOK(mid))
ok = mid;
else
ng = mid;
}
return ok;
}
static bool IsOK(long key) {
return score.Select(s => (Math.Max(s.Value - key + s.Key - 1, 0)) / s.Key)
.Sum() <= K;
}
}
class Pair {
public Pair(long key, long value) {
Key = key;
Value = value;
}
public long Key { get; set; }
public long Value { get; set; }
}
//拡張メソッド
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static string yesno(this bool b) { return b ? "yes" : "no"; }
public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
}
partial class Program {
static public string GetStr() { return Console.ReadLine().Trim(); }
static public char GetChar() { return Console.ReadLine().Trim()[0]; }
static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
static public double GetDouble() {
return double.Parse(Console.ReadLine().Trim());
}
static public string[] GetStrArray() {
return Console.ReadLine().Trim().Split(' ');
}
static public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
static public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
static public T[][] CreateJaggedArray<T>(int H, int W, T value) {
return Enumerable.Repeat(0, H)
.Select(s => Enumerable.Repeat(value, W).ToArray())
.ToArray();
}
static public int[][] GetIntJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetIntArray().ToArray())
.ToArray();
}
static public long[][] GetLongJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetLongArray().ToArray())
.ToArray();
}
static public char[][] GetCharJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetStr().ToCharArray())
.ToArray();
}
static public double[][] GetDoubleJaggedArray(int N) {
return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray();
}
static public void WriteObjects<T>(IReadOnlyCollection<T> values) {
var array = values.ToArray();
var num = array.Length;
if (num == 0)
return;
Console.Write(array[0]);
for (int i = 1; i < num; i++) {
Console.Write(" " + array[i]);
}
Console.WriteLine();
}
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, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d,
out X e, out Y f) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
f = cv<Y>(ar[5]);
}
}
}
|
[["+", 8, 16, 31, 23, 0, 213, 63, 214, 205, 22], ["+", 8, 16, 31, 23, 0, 213, 63, 214, 0, 131], ["+", 8, 16, 31, 23, 0, 213, 63, 214, 141, 22], ["+", 8, 16, 31, 23, 0, 213, 3, 4, 0, 24], ["+", 8, 16, 31, 23, 0, 213, 3, 4, 0, 21], ["+", 31, 23, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 16, 31, 23, 0, 213, 3, 4, 0, 25]]
| 8
| 1,762
| 7
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
class Program {
static long max = 10000000000;
static long K;
static long N;
static long[] A;
static long[] F;
static void Main(string[] args) {
var NK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
N = NK[0];
K = NK[1];
A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
F = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
Array.Sort(A);
Array.Sort(F);
Array.Reverse(F);
for (int i = 0; i < N; i++) {
var asign = new Asign(A[i], F[i]);
}
long ng = 0;
long ok = (long)Math.Pow(10, 12);
while (ok - ng > 1) {
long mid = (ok + ng) / 2;
// mid以下に最大値をすることが可能かどうか
if (check(mid)) {
ok = mid;
} else {
ng = mid;
}
}
Console.WriteLine(ok - 1);
}
static bool check(long mid) {
//必要な修行回数
long count = 0;
for (int i = 0; i < N; i++) {
var tmp = A[i] * F[i];
if (tmp > mid) {
count += (tmp - mid) / F[i] + 1;
}
}
return count <= K;
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public struct Asign : IComparable<Asign> {
public long cost;
public long meel;
public Asign(long vec1, long vec2) {
cost = vec1;
meel = vec2;
}
public static long Cost(Asign vec) { return vec.cost * vec.meel; }
public int CompareTo(Asign othervec) {
return Cost(this).CompareTo(Cost(othervec));
}
}
class UnionFind
{
// 親要素のインデックスを保持する
// 親要素が存在しない(自身がルートである)とき、マイナスでグループの要素数を持つ
public long[] Parents { get; set; }
public UnionFind(long n)
{
this.Parents = new long[n];
for (int i = 0; i < n; i++)
{
// 初期状態ではそれぞれが別のグループ(ルートは自分自身)
// ルートなのでマイナスで要素数(1個)を保持する
this.Parents[i] = -1;
}
}
// 要素xのルート要素はどれか
public long Find(long x)
{
// 親がマイナスの場合は自分自身がルート
if (this.Parents[x] < 0)
return x;
// ルートが見つかるまで再帰的に探す
// 見つかったルートにつなぎかえる
this.Parents[x] = Find(this.Parents[x]);
return this.Parents[x];
}
// 要素xの属するグループの要素数を取得する
public long Size(long x)
{
// ルート要素を取得して、サイズを取得して返す
return -this.Parents[this.Find(x)];
}
// 要素x, yが同じグループかどうか判定する
public bool Same(long x, long y)
{
return this.Find(x) == this.Find(y);
}
// 要素x, yが属するグループを同じグループにまとめる
public bool Union(long x, long y)
{
// x, y のルート
x = this.Find(x);
y = this.Find(y);
// すでに同じグループの場合処理しない
if (x == y)
return false;
// 要素数が少ないグループを多いほうに書き換えたい
if (this.Size(x) < this.Size(y))
{
var tmp = x;
x = y;
y = tmp;
}
// まとめる先のグループの要素数を更新
this.Parents[x] += this.Parents[y];
// まとめられるグループのルートの親を書き換え
this.Parents[y] = x;
return true;
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
class Program {
static long max = 10000000000;
static long K;
static long N;
static long[] A;
static long[] F;
static void Main(string[] args) {
var NK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
N = NK[0];
K = NK[1];
A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
F = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
Array.Sort(A);
Array.Sort(F);
Array.Reverse(F);
for (int i = 0; i < N; i++) {
var asign = new Asign(A[i], F[i]);
}
check(0);
long ng = 0;
long ok = (long)Math.Pow(10, 12);
while (ok - ng >= 1) {
long mid = (ok + ng) / 2;
// mid以下に最大値をすることが可能かどうか
if (check(mid)) {
ok = mid;
} else {
ng = mid + 1;
}
}
Console.WriteLine(ok);
}
static bool check(long mid) {
//必要な修行回数
long count = 0;
for (int i = 0; i < N; i++) {
var tmp = A[i] * F[i];
if (tmp > mid) {
count += (tmp - mid - 1) / F[i] + 1;
}
}
return count <= K;
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public struct Asign : IComparable<Asign> {
public long cost;
public long meel;
public Asign(long vec1, long vec2) {
cost = vec1;
meel = vec2;
}
public static long Cost(Asign vec) { return vec.cost * vec.meel; }
public int CompareTo(Asign othervec) {
return Cost(this).CompareTo(Cost(othervec));
}
}
class UnionFind
{
// 親要素のインデックスを保持する
// 親要素が存在しない(自身がルートである)とき、マイナスでグループの要素数を持つ
public long[] Parents { get; set; }
public UnionFind(long n)
{
this.Parents = new long[n];
for (int i = 0; i < n; i++)
{
// 初期状態ではそれぞれが別のグループ(ルートは自分自身)
// ルートなのでマイナスで要素数(1個)を保持する
this.Parents[i] = -1;
}
}
// 要素xのルート要素はどれか
public long Find(long x)
{
// 親がマイナスの場合は自分自身がルート
if (this.Parents[x] < 0)
return x;
// ルートが見つかるまで再帰的に探す
// 見つかったルートにつなぎかえる
this.Parents[x] = Find(this.Parents[x]);
return this.Parents[x];
}
// 要素xの属するグループの要素数を取得する
public long Size(long x)
{
// ルート要素を取得して、サイズを取得して返す
return -this.Parents[this.Find(x)];
}
// 要素x, yが同じグループかどうか判定する
public bool Same(long x, long y)
{
return this.Find(x) == this.Find(y);
}
// 要素x, yが属するグループを同じグループにまとめる
public bool Union(long x, long y)
{
// x, y のルート
x = this.Find(x);
y = this.Find(y);
// すでに同じグループの場合処理しない
if (x == y)
return false;
// 要素数が少ないグループを多いほうに書き換えたい
if (this.Size(x) < this.Size(y))
{
var tmp = x;
x = y;
y = tmp;
}
// まとめる先のグループの要素数を更新
this.Parents[x] += this.Parents[y];
// まとめられるグループのルートの親を書き換え
this.Parents[y] = x;
return true;
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 12, 203]]
| 8
| 1,176
| 13
|
using System;
namespace _153232 {
class Program {
static void Main(string[] args) {
string N = Console.ReadLine();
double n = int.Parse(N);
double a = -1;
if (n == 1) {
a = 1;
} else if (n % 2 == 0) {
a = 0.5;
} else {
a = (n + 1) / 2 / ((n - 1) / 2);
}
Console.WriteLine(a);
}
}
}
|
using System;
namespace _153232 {
class Program {
static void Main(string[] args) {
string N = Console.ReadLine();
double n = int.Parse(N);
double a = -1;
if (n == 1) {
a = 1;
} else if (n % 2 == 0) {
a = 0.5;
} else {
a = (n + 1) / 2 / n;
}
Console.WriteLine(a);
}
}
}
|
[["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["-", 12, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["-", 12, 23, 0, 16, 31, 23, 0, 16, 17, 33], ["-", 12, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 12, 16, 12, 23, 0, 16, 31, 23, 0, 25], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 17, 85], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
| 8
| 104
| 8
|
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();
if (n % 2 == 0) {
Cout(1 / 2);
} else {
Cout((n / 2) / ((n / 2) + 1));
}
Cin();
}
static int loop(int num, int max) {
if (num > max) {
return 0;
} else if (num < 0) {
return max;
} else {
return num;
}
}
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 MOD10E9 = (1000000000 + 7);
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();
}
static void CoutAr<Type>(IEnumerable<Type> types) {
string text = string.Join(" ", types);
WriteLine(text);
}
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();
if (n % 2 == 0) {
Cout(n / 2.0 / n);
} else {
Cout(((n / 2 + 1) / (double)n));
}
Cin();
}
static int loop(int num, int max) {
if (num > max) {
return 0;
} else if (num < 0) {
return max;
} else {
return num;
}
}
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 MOD10E9 = (1000000000 + 7);
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();
}
static void CoutAr<Type>(IEnumerable<Type> types) {
string text = string.Join(" ", types);
WriteLine(text);
}
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, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 250], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 28, 0, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 23, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["-", 12, 23, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 12, 23, 0, 16, 31, 23, 0, 16, 17, 85], ["-", 12, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 23, 0, 16, 12, 74, 39, 199], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 23, 0, 16, 12, 74, 51, 22]]
| 8
| 765
| 17
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace MyProject {
class Program {
static void Main(string[] args) {
#if Local
var sw = new Stopwatch();
sw.Start();
Console.SetIn(new StreamReader("input.in"));
#endif
var solver = new Solver();
solver.Solve();
#if Local
Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
}
}
class Solver {
public void Solve() {
var N = int.Parse(Console.ReadLine());
Console.WriteLine(string.Join(
" ",
Console.ReadLine()
.Split()
.Select((elem, index) => new { Number = index + 1, Elem = elem })
.OrderBy(elem => elem.Elem)
.Select(elem => elem.Number)));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace MyProject {
class Program {
static void Main(string[] args) {
#if Local
var sw = new Stopwatch();
sw.Start();
Console.SetIn(new StreamReader("input.in"));
#endif
var solver = new Solver();
solver.Solve();
#if Local
Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
}
}
class Solver {
public void Solve() {
var N = int.Parse(Console.ReadLine());
var numbers = Console.ReadLine()
.Split()
.Select((elem, index) => new { Number = index + 1,
Count = int.Parse(elem) })
.OrderBy(elem => elem.Count)
.Select(elem => elem.Number);
Console.WriteLine(string.Join(" ", numbers));
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 28, 0, 218, 8, 312, 0, 313, 0, 22], ["+", 0, 28, 0, 218, 8, 312, 0, 313, 0, 22], ["+", 0, 218, 8, 312, 0, 213, 63, 214, 205, 199], ["+", 0, 218, 8, 312, 0, 213, 63, 214, 0, 131], ["+", 0, 218, 8, 312, 0, 213, 63, 214, 141, 22], ["+", 0, 218, 8, 312, 0, 213, 3, 4, 0, 24], ["+", 0, 218, 8, 312, 0, 213, 3, 4, 0, 25], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 198
| 38
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
var X = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var pair = new Dictionary<int, int>();
for (int i = 0; i < N; i++) {
pair.Add(i + 1, X[i]);
}
// Valueの値によってソートする
var pair_new = pair.OrderBy(x => x.Value);
Console.WriteLine(pair_new);
var r = new List<int>();
// string ans = "";
foreach (var v in pair_new) {
r.Add(v.Key);
}
Console.WriteLine(string.Join(" ", r));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
var X = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var pair = new Dictionary<int, int>();
for (int i = 0; i < N; i++) {
pair.Add(i + 1, X[i]);
}
// Valueの値によってソートする
var pair_new = pair.OrderBy(x => x.Value);
// Console.WriteLine(pair_new);
var r = new List<int>();
// string ans = "";
foreach (var v in pair_new) {
r.Add(v.Key);
}
Console.WriteLine(string.Join(" ", r));
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 203
| 7
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
class Program {
static Dictionary<int, int> Query;
static int H;
static int[] A;
static void Main(string[] args) {
//入力を受け取る
int N = int.Parse(Console.ReadLine());
A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int[] result = new int[N];
for (int i = 0; i < N; i++) {
result[i] = A[i];
}
Console.WriteLine(String.Join(" ", result));
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
class Program {
static Dictionary<int, int> Query;
static int H;
static int[] A;
static void Main(string[] args) {
//入力を受け取る
int N = int.Parse(Console.ReadLine());
A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int[] result = new int[N];
for (int i = 0; i < N; i++) {
result[A[i] - 1] = i + 1;
}
Console.WriteLine(String.Join(" ", result));
}
}
|
[["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 162
| 10
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
static void Main(string[] args) {
var r = ReadSplit();
var a = r[0].ToLong();
var b = r[1].ToLong();
long now = Gcd(a, b);
long i = 2;
long ans = 1;
var l = new List<long>();
while (i * i <= now) {
if (now % i == 0) {
if (!l.Any(x => x == i)) {
ans += 1;
l.Add(i);
}
now /= i;
continue;
} else {
i++;
}
}
if (now != 1)
ans++;
WriteRead(ans);
}
public static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
}
}
public static class Extentions {
public static int ToInt32(this object obj) {
return int.Parse(obj.ToString());
}
public static long ToLong(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal ToDecimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double ToDouble(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value))
{
return value;
}
return new T2();
}
}
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
static void Main(string[] args) {
var r = ReadSplit();
var a = r[0].ToLong();
var b = r[1].ToLong();
long now = Gcd(a, b);
long i = 2;
long ans = 1;
while (i * i <= now) {
if (now % i == 0) {
ans += 1;
while (now % i == 0) {
now /= i;
}
continue;
} else {
i++;
}
}
if (now != 1)
ans++;
WriteRead(ans);
}
public static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
}
}
public static class Extentions {
public static int ToInt32(this object obj) {
return int.Parse(obj.ToString());
}
public static long ToLong(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal ToDecimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double ToDouble(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value))
{
return value;
}
return new T2();
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["-", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 18], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["-", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 64, 196, 0, 57, 15, 241, 0, 111], ["-", 0, 57, 15, 241, 0, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 241, 0, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 241, 0, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 241, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 60], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 52, 0, 89], ["+", 64, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 52, 15, 16, 31, 16, 17, 109], ["+", 0, 57, 64, 196, 0, 52, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 52, 15, 16, 12, 203], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 52, 8, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 52, 8, 196, 0, 46]]
| 8
| 536
| 38
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.