buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var ny = ReadInts();
var N = ny[0];
var Y = ny[1];
// iが1000円
// jが5000円
// kが10000円
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= N - 1; j++) {
var k = N - i - j;
if (k <= 0) {
k = 0;
}
if (1000 * i + 5000 * j + 10000 * k == Y) {
WriteLine($"{k} {j} {i}");
return;
}
}
}
WriteLine("-1 -1 -1");
}
private static string Read() { return ReadLine(); }
private static string[] Reads() { return (Read().Split()); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var ny = ReadInts();
var N = ny[0];
var Y = ny[1];
// iが1000円
// jが5000円
// kが10000円
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= N - i; j++) {
var k = N - i - j;
if (1000 * i + 5000 * j + 10000 * k == Y) {
WriteLine($"{k} {j} {i}");
return;
}
}
}
WriteLine("-1 -1 -1");
}
private static string Read() { return ReadLine(); }
private static string[] Reads() { return (Read().Split()); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22], ["-", 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], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 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], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 353
| 14
|
using System;
using System.Linq;
namespace abc085_c {
class Program {
static void Main(string[] args) {
int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int N = input[0];
int Y = input[1];
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= N - i; i++) {
if (i * 1000 + j * 5000 + 10000 * (N - i - j) == Y) {
Console.WriteLine($"{N - i - j} {j} {i}");
Environment.Exit(0);
}
}
}
Console.WriteLine("-1 -1 -1");
}
}
}
|
using System;
using System.Linq;
namespace abc085_c {
class Program {
static void Main(string[] args) {
int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int N = input[0];
int Y = input[1];
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= N - i; j++) {
if (i * 1000 + j * 5000 + 10000 * (N - i - j) == Y) {
Console.WriteLine($"{N - i - j} {j} {i}");
return;
}
}
}
Console.WriteLine("-1 -1 -1");
}
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 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, 37, 0, 38]]
| 8
| 169
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Contest {
class Scanner {
private string[] line = new string[0];
private int index = 0;
public string Next() {
if (line.Length <= index) {
line = Console.ReadLine().Split(' ');
index = 0;
}
var res = line[index];
index++;
return res;
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public string[] Array() {
line = Console.ReadLine().Split(' ');
index = line.Length;
return line;
}
public int[] IntArray() {
var array = Array();
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
public long[] LongArray() {
var array = Array();
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
}
struct S {
public int R, D;
}
class Program {
private int N, M;
private List<S>[] List;
private Dictionary<long, int> PoSToN;
private Dictionary<int, long> NToPos;
private HashSet<int> Hs;
private void Scan() {
var sc = new Scanner();
N = sc.NextInt();
M = sc.NextInt();
List = new List<S>[N];
for (int i = 0; i < N; i++) {
List[i] = new List<S>();
}
for (int i = 0; i < M; i++) {
int l = sc.NextInt() - 1;
int r = sc.NextInt() - 1;
int d = sc.NextInt();
List[l].Add(new S { R = r, D = d });
List[r].Add(new S { D = -d, R = l });
}
}
private bool Search(int n) {
long pos = NToPos[n];
foreach (var s in List[n]) {
// Console.WriteLine($"{n} {s.R}");
long next = pos + s.D;
int o;
if (PoSToN.TryGetValue(next, out o)) {
if (o != s.R)
return false;
}
long p;
if (NToPos.TryGetValue(s.R, out p)) {
// Console.WriteLine($"{s.R} {p}");
if (p != next)
return false;
}
if (Hs.Add(s.R)) {
NToPos[s.R] = next;
PoSToN[next] = s.R;
if (!Search(s.R))
return false;
}
}
return true;
}
public void Solve() {
Scan();
Hs = new HashSet<int>();
for (int i = 0; i < N; i++) {
if (Hs.Contains(i))
continue;
NToPos = new Dictionary<int, long>();
PoSToN = new Dictionary<long, int>();
NToPos[i] = 0;
PoSToN[0] = i;
Hs.Add(i);
if (!Search(i)) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
static void Main() => new Program().Solve();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Contest {
class Scanner {
private string[] line = new string[0];
private int index = 0;
public string Next() {
if (line.Length <= index) {
line = Console.ReadLine().Split(' ');
index = 0;
}
var res = line[index];
index++;
return res;
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public string[] Array() {
line = Console.ReadLine().Split(' ');
index = line.Length;
return line;
}
public int[] IntArray() {
var array = Array();
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
public long[] LongArray() {
var array = Array();
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
}
struct S {
public int R, D;
}
class Program {
private int N, M;
private List<S>[] List;
private Dictionary<long, int> PoSToN;
private Dictionary<int, long> NToPos;
private HashSet<int> Hs;
private void Scan() {
var sc = new Scanner();
N = sc.NextInt();
M = sc.NextInt();
List = new List<S>[N];
for (int i = 0; i < N; i++) {
List[i] = new List<S>();
}
for (int i = 0; i < M; i++) {
int l = sc.NextInt() - 1;
int r = sc.NextInt() - 1;
int d = sc.NextInt();
List[l].Add(new S { R = r, D = d });
List[r].Add(new S { D = -d, R = l });
}
}
private bool Search(int n) {
long pos = NToPos[n];
foreach (var s in List[n]) {
// Console.WriteLine($"{n} {s.R}");
long next = pos + s.D;
int o;
long p;
if (NToPos.TryGetValue(s.R, out p)) {
// Console.WriteLine($"{s.R} {p}");
if (p != next)
return false;
}
if (Hs.Add(s.R)) {
NToPos[s.R] = next;
PoSToN[next] = s.R;
if (!Search(s.R))
return false;
}
}
return true;
}
public void Solve() {
Scan();
Hs = new HashSet<int>();
for (int i = 0; i < N; i++) {
if (Hs.Contains(i))
continue;
NToPos = new Dictionary<int, long>();
PoSToN = new Dictionary<long, int>();
NToPos[i] = 0;
PoSToN[0] = i;
Hs.Add(i);
if (!Search(i)) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
static void Main() => new Program().Solve();
}
}
|
[["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["-", 0, 57, 15, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 57, 15, 213, 3, 4, 0, 21], ["-", 0, 57, 15, 213, 3, 4, 0, 28, 0, 268], ["-", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["-", 0, 210, 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, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 79], ["-", 64, 196, 0, 57, 15, 16, 12, 214, 205, 22], ["-", 64, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["-", 64, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 196, 0, 57, 64, 37, 0, 38], ["-", 64, 196, 0, 57, 64, 37, 0, 211, 0, 147], ["-", 0, 57, 64, 196, 0, 57, 64, 37, 0, 35], ["-", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 783
| 25
|
using System;
using System.Collections.Generic;
using System.Linq;
public class HelloWorld {
static public void Main() {
var input = Console.ReadLine().Split(' ');
var n = int.Parse(input[0]);
var y = int.Parse(input[1]);
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
for (int k = 0; k <= n - i - j; k++) {
if (10000 * i + 5000 * j + 1000 * k == y) {
Console.WriteLine(string.Format("{0} {1} {2}", i, j, k));
return;
}
}
}
}
Console.WriteLine("-1 -1 -1");
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class HelloWorld {
static public void Main() {
var input = Console.ReadLine().Split(' ');
var n = int.Parse(input[0]);
var y = int.Parse(input[1]);
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
for (int k = 0; k <= n - i - j; k++) {
if (10000 * i + 5000 * j + 1000 * k == y && i + j + k == n) {
Console.WriteLine(string.Format("{0} {1} {2}", i, j, k));
return;
}
}
}
}
Console.WriteLine("-1 -1 -1");
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 17, 72], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 173
| 8
|
using System;
using System.Linq;
namespace ABC085 {
class C {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
long N = int.Parse(input[0]);
long Y = int.Parse(input[1]);
long sum = 0;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= N - i; j++) {
sum += 10000 * i + 5000 * j + 1000 * (N - i - j);
if (sum == Y) {
Console.WriteLine(sum);
Console.WriteLine(i + " " + j + " " + (N - i - j));
return;
}
sum = 0;
}
}
Console.WriteLine("-1" + " " + "-1" + " " + "-1");
}
}
}
|
using System;
using System.Linq;
namespace ABC085 {
class C {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
long N = int.Parse(input[0]);
long Y = int.Parse(input[1]);
long sum = 0;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= N - i; j++) {
sum += 10000 * i + 5000 * j + 1000 * (N - i - j);
if (sum == Y) {
Console.WriteLine(i + " " + j + " " + (N - i - j));
return;
}
sum = 0;
}
}
Console.WriteLine("-1" + " " + "-1" + " " + "-1");
}
}
}
|
[["-", 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], ["-", 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]]
| 8
| 201
| 7
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace myapp {
class AtCoder_abc085_c {
private const int M10000 = 10000;
private const int M5000 = 5000;
private const int M1000 = 1000;
public static void Main() {
IReadOnlyList<int> lineString =
Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToList();
int totalCount = lineString[0];
int totalAmount = lineString[1];
for (int count10000 = 0; count10000 <= totalCount; count10000++) {
for (int count5000 = totalCount - count10000; count5000 >= 0;
count5000--) {
if ((M10000 * count10000) + (M5000 * count5000) +
(M1000 * (totalCount - count10000 - count5000)) ==
totalAmount) {
Console.WriteLine(
$"{count10000} {count5000} {totalCount - count10000 - count5000}");
return;
}
}
}
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace myapp {
class AtCoder_abc085_c {
private const int M10000 = 10000;
private const int M5000 = 5000;
private const int M1000 = 1000;
public static void Main() {
IReadOnlyList<int> lineString =
Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToList();
int totalCount = lineString[0];
int totalAmount = lineString[1];
for (int count10000 = 0; count10000 <= totalCount; count10000++) {
for (int count5000 = totalCount - count10000; count5000 >= 0;
count5000--) {
if ((M10000 * count10000) + (M5000 * count5000) +
(M1000 * (totalCount - count10000 - count5000)) ==
totalAmount) {
Console.WriteLine(
$"{count10000} {count5000} {totalCount - count10000 - count5000}");
return;
}
}
}
Console.WriteLine("-1 -1 -1");
return;
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 35]]
| 8
| 192
| 11
|
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Z {
static void Main() => new K();
}
class K {
const long MOD = 1000000007;
static int[] G => ReadLine().Split().Select(int.Parse).ToArray();
int N;
long ans, D;
long[] ds, cs, ct;
bool[] done;
List<E>[] g;
public K() {
var I = G;
N = I[0];
var M = I[1];
I = G;
var s = I[0] - 1;
var t = I[1] - 1;
g = new List<E>[N];
for (var i = 0; i < N; i++)
g[i] = new List<E>();
for (var i = 0; i < M; i++) {
I = G;
int a = I[0] - 1, b = I[1] - 1, c = I[2];
g[a].Add(new E(b, c));
g[b].Add(new E(a, c));
}
ds = DijkstraFrom(s);
cs = Count(s, ds);
ct = Count(t, DijkstraFrom(t));
done = new bool[N];
ans = cs[t] * cs[t] % MOD;
D = ds[t];
DFS(t);
WriteLine((ans %= MOD) < 0 ? ans + MOD : ans);
}
long S(long x) => x * x % MOD;
void DFS(int u) {
if (done[u])
return;
done[u] = true;
if (2 * ds[u] == D)
ans -= S(cs[u] * ct[u] % MOD);
foreach (var e in g[u])
if (ds[e.V] + e.D == ds[u]) {
if (2 * ds[u] > D && 2 * ds[e.V] < D)
ans -= S(ct[u] * cs[e.V] % MOD);
DFS(e.V);
}
}
long[] Count(int u, long[] d) {
var t = new List<E>();
for (var i = 0; i < N; i++)
t.Add(new E(i, d[i]));
t.Sort();
var c = new long[N];
c[u] = 1;
foreach (var v in t.Select(hoge => hoge.V))
foreach (var e in g[v])
if (d[e.V] + e.D == d[v])
c[v] = (c[v] + c[e.V]) % MOD;
return c;
}
long[] DijkstraFrom(int u) {
var d = new long[N];
for (var v = 0; v < N; v++)
d[v] = 4011686018427387913L;
var queue = new PriorityQueue();
d[u] = 0;
queue.Enqueue(new E(u, 0));
while (queue.Count > 0) {
var p = queue.Dequeue();
var v = p.V;
if (d[v] < p.D)
continue;
foreach (var e in g[v]) {
var t = d[v] + e.D;
if (d[e.V] > t)
queue.Enqueue(new E(e.V, d[e.V] = t));
}
}
return d;
}
}
struct E {
public readonly int V;
public readonly long D;
public E(int v, long d) {
V = v;
D = d;
}
public int CompareTo(E e) => D.CompareTo(e.D);
}
class PriorityQueue {
readonly List<E> a = new List<E>();
public int Count { get; private set; } = 0;
public void Enqueue(E x) {
var i = Count++;
a.Add(x);
while (i > 0) {
var p = (i - 1) / 2;
if (a[p].CompareTo(x) <= 0)
break;
a[i] = a[p];
i = p;
}
a[i] = x;
}
public E Dequeue() {
var v = a[0];
var x = a[--Count];
a.RemoveAt(Count);
if (Count == 0)
return v;
var i = 0;
while (i * 2 + 1 < Count) {
var l = 2 * i + 1;
var r = 2 * i + 2;
if (r < Count && a[r].CompareTo(a[l]) < 0)
l = r;
if (a[l].CompareTo(x) >= 0)
break;
a[i] = a[l];
i = l;
}
a[i] = x;
return v;
}
public E Peek() => a[0];
}
|
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Z {
static void Main() => new K();
}
class K {
const long MOD = 1000000007;
static int[] G => ReadLine().Split().Select(int.Parse).ToArray();
int N;
long ans, D;
long[] ds, cs, ct;
bool[] done;
List<E>[] g;
public K() {
var I = G;
N = I[0];
var M = I[1];
I = G;
var s = I[0] - 1;
var t = I[1] - 1;
g = new List<E>[N];
for (var i = 0; i < N; i++)
g[i] = new List<E>();
for (var i = 0; i < M; i++) {
I = G;
int a = I[0] - 1, b = I[1] - 1, c = I[2];
g[a].Add(new E(b, c));
g[b].Add(new E(a, c));
}
ds = DijkstraFrom(s);
cs = Count(s, ds);
ct = Count(t, DijkstraFrom(t));
done = new bool[N];
ans = cs[t] * cs[t] % MOD;
D = ds[t];
DFS(t);
WriteLine((ans %= MOD) < 0 ? ans + MOD : ans);
}
long S(long x) => x * x % MOD;
void DFS(int u) {
if (done[u])
return;
done[u] = true;
if (2 * ds[u] == D)
ans -= S(cs[u] * ct[u] % MOD);
foreach (var e in g[u])
if (ds[e.V] + e.D == ds[u]) {
if (2 * ds[u] > D && 2 * ds[e.V] < D)
ans -= S(ct[u] * cs[e.V] % MOD);
DFS(e.V);
}
}
long[] Count(int u, long[] d) {
var t = new PriorityQueue();
for (var i = 0; i < N; i++)
t.Enqueue(new E(i, d[i]));
t.Dequeue();
var c = new long[N];
c[u] = 1;
while (t.Count > 0) {
var v = t.Dequeue().V;
foreach (var e in g[v])
if (d[e.V] + e.D == d[v])
c[v] = (c[v] + c[e.V]) % MOD;
}
return c;
}
long[] DijkstraFrom(int u) {
var d = new long[N];
for (var v = 0; v < N; v++)
d[v] = 4011686018427387913L;
var queue = new PriorityQueue();
d[u] = 0;
queue.Enqueue(new E(u, 0));
while (queue.Count > 0) {
var p = queue.Dequeue();
var v = p.V;
if (d[v] < p.D)
continue;
foreach (var e in g[v]) {
var t = d[v] + e.D;
if (d[e.V] > t)
queue.Enqueue(new E(e.V, d[e.V] = t));
}
}
return d;
}
}
struct E {
public readonly int V;
public readonly long D;
public E(int v, long d) {
V = v;
D = d;
}
public int CompareTo(E e) => D.CompareTo(e.D);
}
class PriorityQueue {
readonly List<E> a = new List<E>();
public int Count { get; private set; } = 0;
public void Enqueue(E x) {
var i = Count++;
a.Add(x);
while (i > 0) {
var p = (i - 1) / 2;
if (a[p].CompareTo(x) <= 0)
break;
a[i] = a[p];
i = p;
}
a[i] = x;
}
public E Dequeue() {
var v = a[0];
var x = a[--Count];
a.RemoveAt(Count);
if (Count == 0)
return v;
var i = 0;
while (i * 2 + 1 < Count) {
var l = 2 * i + 1;
var r = 2 * i + 2;
if (r < Count && a[r].CompareTo(a[l]) < 0)
l = r;
if (a[l].CompareTo(x) >= 0)
break;
a[i] = a[l];
i = l;
}
a[i] = x;
return v;
}
public E Peek() => a[0];
}
|
[["-", 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, 22], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 39, 22], ["-", 0, 7, 8, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 7, 8, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 8, 196, 0, 52, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 52, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 214, 205, 213, 63, 214, 141, 22], ["-", 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], ["+", 0, 212, 0, 214, 205, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 210, 12, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 25], ["+", 8, 196, 0, 52, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46]]
| 8
| 1,110
| 30
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
public Solve() {}
StringBuilder sb;
ReadData re;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
re = new ReadData();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
int S = re.i();
long[] sum = new long[100000000];
for (int i = 1; i < 100000000; i++) {
if (i < 10) {
sum[i] = sum[i - 1] + 1;
} else if (i < 100) {
sum[i] = sum[i - 1] + 2;
} else if (i < 1000) {
sum[i] = sum[i - 1] + 3;
} else if (i < 10000) {
sum[i] = sum[i - 1] + 4;
} else if (i < 100000) {
sum[i] = sum[i - 1] + 5;
} else if (i < 1000000) {
sum[i] = sum[i - 1] + 6;
} else if (i < 10000000) {
sum[i] = sum[i - 1] + 7;
} else {
sum[i] = sum[i - 1] + 8;
}
}
long count = 0;
{
int f = 0;
int t = 0;
while (t < 100000000) {
while (sum[t] > sum[f] + S) {
f++;
}
if (sum[t] == sum[f] + S) {
count++;
}
t++;
}
}
for (int i = 1;; i++) {
int min = S / i;
int max = S % i == 0 ? min : min + 1;
if (max <= 8) {
break;
}
if (min == max) {
long c = (10 * Define.mod + 9 * pow(min - 1));
c = c - i + 1;
count = (count + c) % Define.mod;
} else {
count = (count + 1) % Define.mod;
}
}
sb.Append(count + "\n");
}
long pow(long R) {
if (R == 0) {
return 1;
} else if (R % 2 == 0) {
long sq = pow(R / 2);
return sq * sq % Define.mod;
} else {
return pow(R - 1) * 10 % Define.mod;
}
}
}
class ReadData {
string[] str;
int counter;
public ReadData() { counter = 0; }
public string s() {
if (counter == 0) {
str = Console.ReadLine().Split(' ');
counter = str.Length;
}
counter--;
return str[str.Length - counter - 1];
}
public int i() { return int.Parse(s()); }
public long l() { return long.Parse(s()); }
public double d() { return double.Parse(s()); }
public int[] ia(int N) {
int[] ans = new int[N];
for (int j = 0; j < N; j++) {
ans[j] = i();
}
return ans;
}
public int[] ia() {
str = Console.ReadLine().Split(' ');
counter = 0;
int[] ans = new int[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = int.Parse(str[j]);
}
return ans;
}
public long[] la(int N) {
long[] ans = new long[N];
for (int j = 0; j < N; j++) {
ans[j] = l();
}
return ans;
}
public long[] la() {
str = Console.ReadLine().Split(' ');
counter = 0;
long[] ans = new long[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = long.Parse(str[j]);
}
return ans;
}
public double[] da(int N) {
double[] ans = new double[N];
for (int j = 0; j < N; j++) {
ans[j] = d();
}
return ans;
}
public double[] da() {
str = Console.ReadLine().Split(' ');
counter = 0;
double[] ans = new double[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = double.Parse(str[j]);
}
return ans;
}
public List<int>[] g(int N, int[] f, int[] t) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < f.Length; j++) {
ans[f[j]].Add(t[j]);
ans[t[j]].Add(f[j]);
}
return ans;
}
public List<int>[] g(int N, int M) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
public List<int>[] g() {
int N = i();
int M = i();
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
}
public static class Define { public const long mod = 1000000007; }
public static class Debug {
public static void Print(double[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(double[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(double[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(long[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(long[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(long[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(int[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(int[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(int[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
public Solve() {}
StringBuilder sb;
ReadData re;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
re = new ReadData();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
int S = re.i();
uint[] sum = new uint[23000000];
for (int i = 1; i < 23000000; i++) {
if (i < 10) {
sum[i] = sum[i - 1] + 1;
} else if (i < 100) {
sum[i] = sum[i - 1] + 2;
} else if (i < 1000) {
sum[i] = sum[i - 1] + 3;
} else if (i < 10000) {
sum[i] = sum[i - 1] + 4;
} else if (i < 100000) {
sum[i] = sum[i - 1] + 5;
} else if (i < 1000000) {
sum[i] = sum[i - 1] + 6;
} else if (i < 10000000) {
sum[i] = sum[i - 1] + 7;
} else {
sum[i] = sum[i - 1] + 8;
}
}
long count = 0;
{
int f = 0;
int t = 0;
while (true) {
while (sum[t] > sum[f] + S) {
f++;
}
if (f >= 9999999) {
break;
}
if (sum[t] == sum[f] + S) {
count++;
}
t++;
}
}
for (int i = 1;; i++) {
int min = S / i;
int max = S % i == 0 ? min : min + 1;
if (min <= 7) {
break;
}
if (min == max) {
long c = (10 * Define.mod + 9 * pow(min - 1));
c = c - i + 1;
count = (count + c) % Define.mod;
} else {
count++;
}
}
count %= Define.mod;
sb.Append(count + "\n");
}
long pow(long R) {
if (R == 0) {
return 1;
} else if (R % 2 == 0) {
long sq = pow(R / 2);
return sq * sq % Define.mod;
} else {
return pow(R - 1) * 10 % Define.mod;
}
}
}
class ReadData {
string[] str;
int counter;
public ReadData() { counter = 0; }
public string s() {
if (counter == 0) {
str = Console.ReadLine().Split(' ');
counter = str.Length;
}
counter--;
return str[str.Length - counter - 1];
}
public int i() { return int.Parse(s()); }
public long l() { return long.Parse(s()); }
public double d() { return double.Parse(s()); }
public int[] ia(int N) {
int[] ans = new int[N];
for (int j = 0; j < N; j++) {
ans[j] = i();
}
return ans;
}
public int[] ia() {
str = Console.ReadLine().Split(' ');
counter = 0;
int[] ans = new int[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = int.Parse(str[j]);
}
return ans;
}
public long[] la(int N) {
long[] ans = new long[N];
for (int j = 0; j < N; j++) {
ans[j] = l();
}
return ans;
}
public long[] la() {
str = Console.ReadLine().Split(' ');
counter = 0;
long[] ans = new long[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = long.Parse(str[j]);
}
return ans;
}
public double[] da(int N) {
double[] ans = new double[N];
for (int j = 0; j < N; j++) {
ans[j] = d();
}
return ans;
}
public double[] da() {
str = Console.ReadLine().Split(' ');
counter = 0;
double[] ans = new double[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = double.Parse(str[j]);
}
return ans;
}
public List<int>[] g(int N, int[] f, int[] t) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < f.Length; j++) {
ans[f[j]].Add(t[j]);
ans[t[j]].Add(f[j]);
}
return ans;
}
public List<int>[] g(int N, int M) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
public List<int>[] g() {
int N = i();
int M = i();
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
}
public static class Define { public const long mod = 1000000007; }
public static class Debug {
public static void Print(double[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(double[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(double[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(long[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(long[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(long[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(int[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(int[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(int[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 8, 196, 0, 196, 0, 52, 15, 16, 31, 22], ["-", 8, 196, 0, 196, 0, 52, 15, 16, 17, 18], ["-", 8, 196, 0, 196, 0, 52, 15, 16, 12, 203], ["+", 8, 196, 0, 196, 0, 52, 15, 211, 0, 146], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 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, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["+", 0, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 2,129
| 39
|
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
class Solver {
const int M = 999999;
const int MOD = 1000000007;
public long exp(long x, long t) {
if (t == 0)
return 1;
long ret = exp(x, t >> 1);
ret = ret * ret % MOD;
if ((t & 1) == 1)
ret = ret * x % MOD;
return ret;
}
public int f(int x) {
if (x <= 9)
return 1;
if (x <= 99)
return 2;
if (x <= 999)
return 3;
if (x <= 9999)
return 4;
if (x <= 99999)
return 5;
if (x <= 999999)
return 6;
return 7;
}
public void solve() {
int n = cin.readInt();
long ans = 0;
for (int i = 1, r = 1, sum = 0; i <= M; i++) {
while (sum < n && r <= M) {
sum += f(r);
r++;
}
if (sum < n) {
if ((n - sum) % 7 == 0)
ans++;
} else {
if (sum == n)
ans++;
}
sum -= f(i);
}
List<int> fac = new List<int>();
for (int i = 1; i * i <= n; i++) {
if (n % i != 0)
continue;
fac.Add(i);
if (n / i != i)
fac.Add(n / i);
}
foreach (int x in fac) {
if (x < 7)
continue;
ans += (exp(10, x - 1) * 9) - (n / x - 1) + MOD;
ans %= MOD;
}
{
int r = n / 7;
ans += r;
ans %= MOD;
foreach (int x in fac) {
if (x < 7)
continue;
if (x <= r) {
ans += MOD - 1;
ans %= MOD;
}
}
}
ans = (ans % MOD + MOD) % MOD;
Console.Out.WriteLine(ans);
}
public Istream cin = new Istream(Console.OpenStandardInput());
static public void swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
}
#region Istream
class Istream {
public Istream(Stream _ins) { ins = _ins; }
const int BUF_SZ = 1024;
private Stream ins;
private byte[] buf = new byte[BUF_SZ];
private int len, ptr;
private byte readByte() {
if (ptr >= len) {
ptr = 0;
len = ins.Read(buf, 0, BUF_SZ);
if (len == 0)
return 0;
}
return buf[ptr++];
}
public char nextChar() {
byte b;
do
b = readByte();
while (b < 33 && 126 < b);
return (char)b;
}
public string read() {
var sb = new StringBuilder();
for (char c = nextChar(); (33 <= c && c <= 126); c = (char)readByte())
sb.Append(c);
return sb.ToString();
}
public string readLine() {
var sb = new StringBuilder();
for (char c = nextChar(); (c != '\n' && c != 0); c = (char)readByte())
sb.Append(c);
return sb.ToString();
}
public long readLong() { return long.Parse(read()); }
public int readInt() { return int.Parse(read()); }
public double readDouble() { return double.Parse(read()); }
}
#endregion
#region Main
class ReSha {
static void Main() { new Solver().solve(); }
}
#endregion
|
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
class Solver {
const int M = 9999999;
const int MOD = 1000000007;
public long exp(long x, long t) {
if (t == 0)
return 1;
long ret = exp(x, t >> 1);
ret = ret * ret % MOD;
if ((t & 1) == 1)
ret = ret * x % MOD;
return ret;
}
public int f(int x) {
if (x <= 9)
return 1;
if (x <= 99)
return 2;
if (x <= 999)
return 3;
if (x <= 9999)
return 4;
if (x <= 99999)
return 5;
if (x <= 999999)
return 6;
if (x <= 9999999)
return 7;
return 8;
}
public void solve() {
int n = cin.readInt();
long ans = 0;
for (int i = 1, r = 1, sum = 0; i <= M; i++) {
while (sum < n && r <= M) {
sum += f(r);
r++;
}
if (sum < n) {
if ((n - sum) % 8 == 0)
ans++;
} else {
if (sum == n)
ans++;
}
sum -= f(i);
}
List<int> fac = new List<int>();
for (int i = 1; i * i <= n; i++) {
if (n % i != 0)
continue;
fac.Add(i);
if (n / i != i)
fac.Add(n / i);
}
foreach (int x in fac) {
if (x < 8)
continue;
ans += (exp(10, x - 1) * 9) - (n / x - 1) + MOD;
ans %= MOD;
}
{
int r = n / 8;
ans += r;
ans %= MOD;
foreach (int x in fac) {
if (x < 8)
continue;
if (n / x <= r) {
ans += MOD - 1;
ans %= MOD;
}
}
}
ans = (ans % MOD + MOD) % MOD;
Console.Out.WriteLine(ans);
}
public Istream cin = new Istream(Console.OpenStandardInput());
static public void swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
}
#region Istream
class Istream {
public Istream(Stream _ins) { ins = _ins; }
const int BUF_SZ = 1024;
private Stream ins;
private byte[] buf = new byte[BUF_SZ];
private int len, ptr;
private byte readByte() {
if (ptr >= len) {
ptr = 0;
len = ins.Read(buf, 0, BUF_SZ);
if (len == 0)
return 0;
}
return buf[ptr++];
}
public char nextChar() {
byte b;
do
b = readByte();
while (b < 33 && 126 < b);
return (char)b;
}
public string read() {
var sb = new StringBuilder();
for (char c = nextChar(); (33 <= c && c <= 126); c = (char)readByte())
sb.Append(c);
return sb.ToString();
}
public string readLine() {
var sb = new StringBuilder();
for (char c = nextChar(); (c != '\n' && c != 0); c = (char)readByte())
sb.Append(c);
return sb.ToString();
}
public long readLong() { return long.Parse(read()); }
public int readInt() { return int.Parse(read()); }
public double readDouble() { return double.Parse(read()); }
}
#endregion
#region Main
class ReSha {
static void Main() { new Solver().solve(); }
}
#endregion
|
[["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 35], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 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, 85]]
| 8
| 826
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder01 {
class Program {
static void Main(string[] args) {
var a = int.Parse(args[0]);
var b = int.Parse(args[1]);
if (a * b % 2 == 0) {
Console.Write("Even");
} else {
Console.Write("Odd");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder01 {
class Program {
static void Main(string[] args) {
var inp = Console.ReadLine();
args = inp.Split(' ');
var a = int.Parse(args[0]);
var b = int.Parse(args[1]);
if (a * b % 2 == 0) {
Console.Write("Even");
} else {
Console.Write("Odd");
}
}
}
}
|
[["+", 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, 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], ["+", 12, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 12, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217]]
| 8
| 105
| 20
|
using System;
namespace ChokudaiScanner {
class MainClass {
static void Main() {
Scanner cin = new Scanner();
int a = cin.NextInt();
int b = cin.NextInt();
if ((a * b) / 2 == 0) {
Console.WriteLine("Even");
} else {
Console.WriteLine("Odd");
}
}
}
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 string[] ArrayNext(int N) {
string[] Array = new string[N];
for (int i = 0; i < N; i++) {
Array[i] = Next();
}
return Array;
}
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();
int a = cin.NextInt();
int b = cin.NextInt();
long c = a * b;
if (c % 2 == 0) {
Console.WriteLine("Even");
} else {
Console.WriteLine("Odd");
}
}
}
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 string[] ArrayNext(int N) {
string[] Array = new string[N];
for (int i = 0; i < N; i++) {
Array[i] = Next();
}
return Array;
}
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;
}
}
}
|
[["-", 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, 23, 0, 24], ["+", 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, 57, 15, 16, 31, 16, 31, 23, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 85], ["+", 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
| 479
| 13
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split();
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
if (a * b % 2 == 0)
Console.WriteLine("Odd");
else
Console.WriteLine("Even");
}
}
|
using System;
class Program {
public static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int a = int.Parse(str[0]);
int b = int.Parse(str[1]);
if (a * b % 2 == 0)
Console.WriteLine("Even");
else
Console.WriteLine("Odd");
}
}
|
[["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 259], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 88
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC086A {
class Program {
static void Main(string[] args) {
int a, b;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
if (a % 2 == 0 && b % 2 == 0)
Console.WriteLine("Even");
else
Console.WriteLine("Odd");
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC086A {
class Program {
static void Main(string[] args) {
int a, b, c;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
c = a * b;
if (c % 2 == 0)
Console.WriteLine("Even");
else
Console.WriteLine("Odd");
Console.ReadKey();
}
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 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, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 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, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 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
| 130
| 16
|
using System;
class Program {
static void Main(String[] arg) {
//出力用の文字列
String ret;
// 整数の取得
String[] nums = Console.ReadLine().Split(' ');
int a = int.Parse(nums[0]);
int b = int.Parse(nums[1]);
// 積の演算
int product = a * b;
if (product % 2 == 0) {
ret = "even";
} else {
ret = "odd";
}
Console.WriteLine(ret);
}
}
|
using System;
class Program {
const String even = "Even";
const String odd = "Odd";
static void Main(String[] arg) {
//出力用の文字列
String ret;
// 整数の取得
String[] nums = Console.ReadLine().Split(' ');
int a = int.Parse(nums[0]);
int b = int.Parse(nums[1]);
// 積の演算
int product = a * b;
//
if (product % 2 == 0) {
ret = even;
} else {
ret = odd;
}
Console.WriteLine(ret);
}
}
|
[["+", 0, 235, 8, 201, 0, 124, 0, 251, 0, 154], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 22], ["+", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 62], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 208, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 62], ["-", 75, 196, 0, 1, 0, 11, 12, 5, 0, 62]]
| 8
| 107
| 4
|
using System;
namespace Beginner086_A {
class Program {
static void Main(string[] args) {
int a, b;
a = int.Parse(args[0]);
b = int.Parse(args[1]);
int hoge = a * b;
if (hoge % 2 == 0) {
Console.Write("Even");
} else {
Console.Write("Odd");
}
}
}
}
|
using System;
namespace Beginner086_A {
class Program {
static void Main(string[] args) {
int a, b;
args = Console.ReadLine().Split(' ');
a = int.Parse(args[0]);
b = int.Parse(args[1]);
int hoge = a * b;
if (hoge % 2 == 0) {
Console.Write("Even");
} else {
Console.Write("Odd");
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 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], ["+", 12, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 12, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 89
| 15
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static ABC086B.Input;
namespace ABC086B {
static class Input {
/// <summary>
/// 1行の入力をTに応じてリストに変換する関数を返す
/// </summary>
static Func<string, List<T>>
Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToList();
/// <summary>
/// 1行の入力をTに応じて変換する関数を返す
/// </summary>
static Func<string, T> Convert<T>() {
Type t = typeof(T);
if (t == typeof(string))
return _ => (T)(object)_;
if (t == typeof(int))
return _ => (T)(object) int.Parse(_);
if (t == typeof(long))
return _ => (T)(object) long.Parse(_);
if (t == typeof(double))
return _ => (T)(object) double.Parse(_);
if (t == typeof(List<string>))
return _ => (T)(object)Cast<string>()(_);
if (t == typeof(List<int>))
return _ => (T)(object)Cast<int>()(_);
if (t == typeof(List<long>))
return _ => (T)(object)Cast<long>()(_);
if (t == typeof(List<double>))
return _ => (T)(object)Cast<double>()(_);
throw new NotSupportedException(t + "is not supported.");
}
static string String() => Console.ReadLine();
static List<string>
String(long rowNumber) => new bool [rowNumber].Select(_ => String()).ToList();
/// <summary>
/// 1行の値の入力
/// </summary>
public static void @in<T>(out T a) => a = Convert<List<T>>()(String())[0];
public static void @in<T>(out T a1, out T a2) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
}
public static void @in<T>(out T a1, out T a2, out T a3) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
}
public static void @in<T>(out T a1, out T a2, out T a3, out T a4) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
a4 = v[3];
}
public static void @in<T>(out T a1, out T a2, out T a3, out T a4, out T a5) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
a4 = v[3];
a5 = v[4];
}
public static void
@in<T>(out T a1, out T a2, out T a3, out T a4, out T a5, out T a6) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
a4 = v[3];
a5 = v[4];
a6 = v[5];
}
/// <summary>
/// 複数行の値の入力
/// </summary>
public static void @in<T>(long rowNumber, out List<T> l) => l =
String(rowNumber).Select(Convert<T>()).ToList();
public static void @in<T>(long rowNumber, out List<T> l1, out List<T> l2) {
l1 = new List<T>();
l2 = new List<T>();
foreach (List<T> l in String(rowNumber).Select(Convert<List<T>>())) {
l1.Add(l[0]);
l2.Add(l[1]);
}
}
public static void
@in<T>(long rowNumber, out List<T> l1, out List<T> l2, out List<T> l3) {
l1 = new List<T>();
l2 = new List<T>();
l3 = new List<T>();
foreach (List<T> l in String(rowNumber).Select(Convert<List<T>>())) {
l1.Add(l[0]);
l2.Add(l[1]);
l3.Add(l[2]);
}
}
public static void @in<T>(long rowNumber, out List<T> l1, out List<T> l2,
out List<T> l3, out List<T> l4) {
l1 = new List<T>();
l2 = new List<T>();
l3 = new List<T>();
l4 = new List<T>();
foreach (List<T> l in String(rowNumber).Select(Convert<List<T>>())) {
l1.Add(l[0]);
l2.Add(l[1]);
l3.Add(l[2]);
l4.Add(l[3]);
}
}
/// <summary>
/// 1行に書かれた複数の値の入力
/// </summary>
public static void
@in<T>(out List<T> lArr) => lArr = Convert<List<T>>()(String());
/// <summary>
/// h行の行列の入力
/// </summary>
public static void @in<T>(long h, out List<List<T>> map) => map =
String(h).Select(Convert<List<T>>()).ToList();
}
class Program {
public static void Main(string[] args) {
StreamWriter streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(streamWriter);
new Solver().Solve();
Console.Out.Flush();
}
public static void Debug() { new Solver().Solve(); }
}
class Solver {
private string A;
private string B;
public void Solve() {
long l = long.Parse(A + B);
for (int i = 0; i < 10000; i++) {
if (i * i == l) {
Console.WriteLine("Yes");
return;
}
}
Console.WriteLine("No");
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static ABC086B.Input;
namespace ABC086B {
static class Input {
/// <summary>
/// 1行の入力をTに応じてリストに変換する関数を返す
/// </summary>
static Func<string, List<T>>
Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToList();
/// <summary>
/// 1行の入力をTに応じて変換する関数を返す
/// </summary>
static Func<string, T> Convert<T>() {
Type t = typeof(T);
if (t == typeof(string))
return _ => (T)(object)_;
if (t == typeof(int))
return _ => (T)(object) int.Parse(_);
if (t == typeof(long))
return _ => (T)(object) long.Parse(_);
if (t == typeof(double))
return _ => (T)(object) double.Parse(_);
if (t == typeof(List<string>))
return _ => (T)(object)Cast<string>()(_);
if (t == typeof(List<int>))
return _ => (T)(object)Cast<int>()(_);
if (t == typeof(List<long>))
return _ => (T)(object)Cast<long>()(_);
if (t == typeof(List<double>))
return _ => (T)(object)Cast<double>()(_);
throw new NotSupportedException(t + "is not supported.");
}
static string String() => Console.ReadLine();
static List<string>
String(long rowNumber) => new bool [rowNumber].Select(_ => String()).ToList();
/// <summary>
/// 1行の値の入力
/// </summary>
public static void @in<T>(out T a) => a = Convert<List<T>>()(String())[0];
public static void @in<T>(out T a1, out T a2) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
}
public static void @in<T>(out T a1, out T a2, out T a3) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
}
public static void @in<T>(out T a1, out T a2, out T a3, out T a4) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
a4 = v[3];
}
public static void @in<T>(out T a1, out T a2, out T a3, out T a4, out T a5) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
a4 = v[3];
a5 = v[4];
}
public static void
@in<T>(out T a1, out T a2, out T a3, out T a4, out T a5, out T a6) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
a4 = v[3];
a5 = v[4];
a6 = v[5];
}
/// <summary>
/// 複数行の値の入力
/// </summary>
public static void @in<T>(long rowNumber, out List<T> l) => l =
String(rowNumber).Select(Convert<T>()).ToList();
public static void @in<T>(long rowNumber, out List<T> l1, out List<T> l2) {
l1 = new List<T>();
l2 = new List<T>();
foreach (List<T> l in String(rowNumber).Select(Convert<List<T>>())) {
l1.Add(l[0]);
l2.Add(l[1]);
}
}
public static void
@in<T>(long rowNumber, out List<T> l1, out List<T> l2, out List<T> l3) {
l1 = new List<T>();
l2 = new List<T>();
l3 = new List<T>();
foreach (List<T> l in String(rowNumber).Select(Convert<List<T>>())) {
l1.Add(l[0]);
l2.Add(l[1]);
l3.Add(l[2]);
}
}
public static void @in<T>(long rowNumber, out List<T> l1, out List<T> l2,
out List<T> l3, out List<T> l4) {
l1 = new List<T>();
l2 = new List<T>();
l3 = new List<T>();
l4 = new List<T>();
foreach (List<T> l in String(rowNumber).Select(Convert<List<T>>())) {
l1.Add(l[0]);
l2.Add(l[1]);
l3.Add(l[2]);
l4.Add(l[3]);
}
}
/// <summary>
/// 1行に書かれた複数の値の入力
/// </summary>
public static void
@in<T>(out List<T> lArr) => lArr = Convert<List<T>>()(String());
/// <summary>
/// h行の行列の入力
/// </summary>
public static void @in<T>(long h, out List<List<T>> map) => map =
String(h).Select(Convert<List<T>>()).ToList();
}
class Program {
public static void Main(string[] args) {
StreamWriter streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(streamWriter);
new Solver().Solve();
Console.Out.Flush();
}
public static void Debug() { new Solver().Solve(); }
}
class Solver {
private string A;
private string B;
public void Solve() {
@in(out A, out B);
long l = long.Parse(A + B);
for (int i = 0; i < 10000; i++) {
if (i * i == l) {
Console.WriteLine("Yes");
return;
}
}
Console.WriteLine("No");
}
}
}
|
[["+", 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, 268], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 1,420
| 9
|
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using static System.Console;
using static Program.Input;
using static Program.MyMath;
using static Program.Const;
namespace Program {
static class Const {
public static string alp = "abcdefghijklmnopqrstuvwxyz";
public static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const long MOD = 1000000007;
public static int INF = int.MaxValue;
public static long INFL = long.MaxValue;
}
class Program {
static void Main() {
int n, m;
InputLine(out n, out m);
var num = 100 * n + m;
WriteLine(Solve(num) ? "Yes" : "No");
}
static bool Solve(int num) {
int p = 1;
while (true) {
if (p * p == num)
return true;
if (p * p > num)
return false;
p++;
}
}
public class PriorityQueue {
private int[] heap;
private int sz = 0;
public PriorityQueue(int size) { heap = new int[size]; }
public void Enqueue(int x) {
var i = sz++;
while (i > 0) {
var p = (i - 1) / 2;
if (heap[p] >= x)
break;
heap[i] = heap[p];
i = p;
}
heap[i] = x;
}
public int Dequeue() {
int ret = heap[0];
int x = heap[--sz];
int i = 0;
while (i * 2 + 1 < sz) {
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < sz && b < a)
a = b;
if (heap[a] <= x)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
return ret;
}
}
}
static class Input {
public static void InputLine(out int a, out int b) {
var arr = ScanIntArray();
a = arr[0];
b = arr[1];
}
public static void InputLine(out int a, out int b, out int c) {
var arr = ScanIntArray();
a = arr[0];
b = arr[1];
c = arr[2];
}
public static void InputLine(out long a, out long b) {
var arr = ScanLongArray();
a = arr[0];
b = arr[1];
}
public static void InputLine(out long a, out long b, out long c) {
var arr = ScanLongArray();
a = arr[0];
b = arr[1];
c = arr[2];
}
public static void InputLine(out string a, out string b) {
var arr = ScanStrArray();
a = arr[0];
b = arr[1];
}
public static void InputLine(out string a, out string b, out string c) {
var arr = ScanStrArray();
a = arr[0];
b = arr[1];
c = arr[2];
}
static public int ScanInt() { return int.Parse(ReadLine()); }
static public long ScanLong() { return long.Parse(ReadLine()); }
static public double ScanDouble() { return double.Parse(ReadLine()); }
static public int[] ScanIntArray() {
return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
static public long[] ScanLongArray() {
return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
static public double[] ScanDoubleArray() {
return ReadLine().Split().Select(x => double.Parse(x)).ToArray();
}
static public string ScanStr() { return ReadLine(); }
static public string[] ScanStrArray() { return ScanStr().Split(); }
static public string RegaxReplace(this string arg1, string pattern,
string replacement) {
return Regex.Replace(arg1, pattern, replacement);
}
static public string Join<T>(this IEnumerable<T> source, string separator) {
return string.Join(separator, source);
}
static public void Sort(this string[] array) {
Array.Sort(array, StringComparer.OrdinalIgnoreCase);
}
static public void StringSort(this List<string> list) {
list.Sort(StringComparer.OrdinalIgnoreCase);
}
public static Dictionary<char, int> alpToIdx =
Enumerable.Range(0, alp.Length).ToDictionary(_ => alp[_], _ => _);
public static Dictionary<char, int> AlpToIdx =
Enumerable.Range(0, Alp.Length).ToDictionary(_ => Alp[_], _ => _);
}
static class MyMath {
static public int CountBit(this long a) {
if (a == 0)
return 0;
int c = 1;
for (; a > 1; a /= 2)
if (a % 2 == 1)
c++;
return c;
}
static public int Floor2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public long Floor2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public int Ceiling2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N;
}
static public long Ceiling2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N;
}
static public long[] CumSum(this long[] a) {
var res = new long[a.Length];
long s = 0;
for (int i = 0; i < a.Length; i++)
res[i] = (s += a[i]);
return res;
}
static public IEnumerable<int> PrimeFactors(this int n) {
int tmp = n;
for (int i = 2; i * i <= n; i++) {
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
}
if (tmp != 1)
yield return tmp;
}
static public IEnumerable<long> PrimeFactors(this long n) {
var tmp = n;
for (long i = 2; i * i <= n; i++) {
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
}
if (tmp != 1)
yield return tmp;
}
static public int Digit(this int n, int d) {
if (d < 0)
return 0;
return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d);
}
static public int Length(this int n) {
if (n < 0)
return 0;
return (int)Math.Log10(n) + 1;
}
static public int Top(this int n) { return n.Digit(n.Length() - 1); }
public static bool isPrime(this int p) {
if (p <= 1)
return false;
for (int i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static bool isPrime(this long p) {
if (p <= 1)
return false;
for (long i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static int GCD(int a, int b) {
Func<int, int, int> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static long GCD(long a, long b) {
Func<long, long, long> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
var d = extGCD(b, a % b, ref y, ref x);
y -= a / b * x;
return d;
}
public static int LCM(int a, int b) { return a * b / GCD(a, b); }
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
public static long Inv(this long a, long m = MOD) {
long b = m, u = 1, v = 0;
while (b != 0) {
long t = a / b;
a -= t * b;
swap(ref a, ref b);
u -= t * v;
swap(ref u, ref v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
private static void swap(ref long a, ref long b) {
var t = a;
a = b;
b = t;
}
public static long ModPow(long a, long n, long m = MOD) {
long res = 1;
while (n > 0) {
if (n % 2 == 1)
res = (res * a) % m;
a = (a * a) % m;
n >>= 1;
}
return res;
}
}
}
|
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using static System.Console;
using static Program.Input;
using static Program.MyMath;
using static Program.Const;
namespace Program {
static class Const {
public static string alp = "abcdefghijklmnopqrstuvwxyz";
public static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const long MOD = 1000000007;
public static int INF = int.MaxValue;
public static long INFL = long.MaxValue;
}
class Program {
static void Main() {
var num = int.Parse(ScanStrArray().Join(""));
WriteLine(Solve(num) ? "Yes" : "No");
}
static bool Solve(int num) {
int p = 1;
while (true) {
if (p * p == num)
return true;
if (p * p > num)
return false;
p++;
}
}
public class PriorityQueue {
private int[] heap;
private int sz = 0;
public PriorityQueue(int size) { heap = new int[size]; }
public void Enqueue(int x) {
var i = sz++;
while (i > 0) {
var p = (i - 1) / 2;
if (heap[p] >= x)
break;
heap[i] = heap[p];
i = p;
}
heap[i] = x;
}
public int Dequeue() {
int ret = heap[0];
int x = heap[--sz];
int i = 0;
while (i * 2 + 1 < sz) {
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < sz && b < a)
a = b;
if (heap[a] <= x)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
return ret;
}
}
}
static class Input {
public static void InputLine(out int a, out int b) {
var arr = ScanIntArray();
a = arr[0];
b = arr[1];
}
public static void InputLine(out int a, out int b, out int c) {
var arr = ScanIntArray();
a = arr[0];
b = arr[1];
c = arr[2];
}
public static void InputLine(out long a, out long b) {
var arr = ScanLongArray();
a = arr[0];
b = arr[1];
}
public static void InputLine(out long a, out long b, out long c) {
var arr = ScanLongArray();
a = arr[0];
b = arr[1];
c = arr[2];
}
public static void InputLine(out string a, out string b) {
var arr = ScanStrArray();
a = arr[0];
b = arr[1];
}
public static void InputLine(out string a, out string b, out string c) {
var arr = ScanStrArray();
a = arr[0];
b = arr[1];
c = arr[2];
}
static public int ScanInt() { return int.Parse(ReadLine()); }
static public long ScanLong() { return long.Parse(ReadLine()); }
static public double ScanDouble() { return double.Parse(ReadLine()); }
static public int[] ScanIntArray() {
return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
static public long[] ScanLongArray() {
return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
static public double[] ScanDoubleArray() {
return ReadLine().Split().Select(x => double.Parse(x)).ToArray();
}
static public string ScanStr() { return ReadLine(); }
static public string[] ScanStrArray() { return ScanStr().Split(); }
static public string RegaxReplace(this string arg1, string pattern,
string replacement) {
return Regex.Replace(arg1, pattern, replacement);
}
static public string Join<T>(this IEnumerable<T> source, string separator) {
return string.Join(separator, source);
}
static public void Sort(this string[] array) {
Array.Sort(array, StringComparer.OrdinalIgnoreCase);
}
static public void StringSort(this List<string> list) {
list.Sort(StringComparer.OrdinalIgnoreCase);
}
public static Dictionary<char, int> alpToIdx =
Enumerable.Range(0, alp.Length).ToDictionary(_ => alp[_], _ => _);
public static Dictionary<char, int> AlpToIdx =
Enumerable.Range(0, Alp.Length).ToDictionary(_ => Alp[_], _ => _);
}
static class MyMath {
static public int CountBit(this long a) {
if (a == 0)
return 0;
int c = 1;
for (; a > 1; a /= 2)
if (a % 2 == 1)
c++;
return c;
}
static public int Floor2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public long Floor2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N / 2;
}
static public int Ceiling2(this int a) {
int N = 1;
while (N < a)
N *= 2;
return N;
}
static public long Ceiling2(this long a) {
long N = 1;
while (N < a)
N *= 2;
return N;
}
static public long[] CumSum(this long[] a) {
var res = new long[a.Length];
long s = 0;
for (int i = 0; i < a.Length; i++)
res[i] = (s += a[i]);
return res;
}
static public IEnumerable<int> PrimeFactors(this int n) {
int tmp = n;
for (int i = 2; i * i <= n; i++) {
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
}
if (tmp != 1)
yield return tmp;
}
static public IEnumerable<long> PrimeFactors(this long n) {
var tmp = n;
for (long i = 2; i * i <= n; i++) {
while (tmp % i == 0) {
tmp /= i;
yield return i;
}
}
if (tmp != 1)
yield return tmp;
}
static public int Digit(this int n, int d) {
if (d < 0)
return 0;
return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d);
}
static public int Length(this int n) {
if (n < 0)
return 0;
return (int)Math.Log10(n) + 1;
}
static public int Top(this int n) { return n.Digit(n.Length() - 1); }
public static bool isPrime(this int p) {
if (p <= 1)
return false;
for (int i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static bool isPrime(this long p) {
if (p <= 1)
return false;
for (long i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return true;
}
public static int GCD(int a, int b) {
Func<int, int, int> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static long GCD(long a, long b) {
Func<long, long, long> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
var d = extGCD(b, a % b, ref y, ref x);
y -= a / b * x;
return d;
}
public static int LCM(int a, int b) { return a * b / GCD(a, b); }
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
public static long Inv(this long a, long m = MOD) {
long b = m, u = 1, v = 0;
while (b != 0) {
long t = a / b;
a -= t * b;
swap(ref a, ref b);
u -= t * v;
swap(ref u, ref v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
private static void swap(ref long a, ref long b) {
var t = a;
a = b;
b = t;
}
public static long ModPow(long a, long n, long m = MOD) {
long res = 1;
while (n > 0) {
if (n % 2 == 1)
res = (res * a) % m;
a = (a * a) % m;
n >>= 1;
}
return res;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 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, 268], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 31, 203], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 63, 214, 205, 213, 63, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 2,040
| 33
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
Console.ReadLine();
var ngo = new List<int>(Console.ReadLine()
.Split()
.Select(select => int.Parse(select))
.ToArray());
ngo.Sort();
int a = 0, b = 0;
for (int i = 0; i < ngo.Count; i += 2)
a += ngo[i];
for (int i = 1; i < ngo.Count; i += 2)
b += ngo[i];
Console.WriteLine(a - b);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
Console.ReadLine();
var ngo = new List<int>(Console.ReadLine()
.Split()
.Select(select => int.Parse(select))
.ToArray());
ngo.Sort((aa, bb) => bb - aa);
int a = 0, b = 0;
for (int i = 0; i < ngo.Count; i += 2)
a += ngo[i];
for (int i = 1; i < ngo.Count; i += 2)
b += ngo[i];
Console.WriteLine(a - b);
}
}
}
|
[["+", 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], ["+", 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, 33], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
| 8
| 148
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2 {
class Program2 {
static void Main(string[] args) {
int a, c, d;
List<int> intlist = new List<int>();
int alice = 0;
int bob = 0;
/*
string[] a = Console.ReadLine().Split(' ');
long b = long.Parse(a[0]);
long c = long.Parse(a[1]);
long d;
*/
a = int.Parse(Console.ReadLine());
// b = int.Parse(Console.ReadLine());
string[] b = Console.ReadLine().Split(' ');
for (int i = 0; i < b.Length; i++) {
intlist.Add(int.Parse(b[i]));
}
intlist.Sort();
intlist.Reverse();
for (int i = 0; i < intlist.Count / 2 + 1; i += 2) {
alice += intlist[i];
if (i + 1 < intlist.Count)
bob += intlist[i + 1];
}
c = alice - bob;
Console.Write(c);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2 {
class Program2 {
static void Main(string[] args) {
int a, c, d;
c = 0;
List<int> intlist = new List<int>();
int alice = 0;
int bob = 0;
/*
string[] a = Console.ReadLine().Split(' ');
long b = long.Parse(a[0]);
long c = long.Parse(a[1]);
long d;
*/
a = int.Parse(Console.ReadLine());
// b = int.Parse(Console.ReadLine());
string[] b = Console.ReadLine().Split(' ');
for (int i = 0; i < b.Length; i++) {
intlist.Add(int.Parse(b[i]));
}
intlist.Sort();
intlist.Reverse();
for (int i = 0; i < intlist.Count; i += 1) {
if (i % 2 == 0) {
alice += intlist[i];
} else
bob += intlist[i];
}
c = alice - bob;
Console.Write(c);
}
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 15, 16, 12, 16, 31, 16, 17, 85], ["-", 0, 7, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 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, 121], ["-", 8, 196, 0, 7, 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, 72], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 217
| 31
|
using System;
namespace AtCoderConsole {
class Program {
static void Main(string[] args) {
string[] input = new string[3];
int[,] matrix = new int[3, 3];
// 標準入力から1行ずつ取得
for (int i = 0; i < 3; i++) {
input[i] = Console.ReadLine();
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
matrix[i, j] = int.Parse(input[i].Split(' ')[j]);
}
}
int[] a = new int[3];
int[] b = new int[3];
// a0を0として考える
a[0] = 0;
b[0] = matrix[0, 0];
b[1] = matrix[0, 1];
b[2] = matrix[0, 2];
a[1] = matrix[1, 0];
a[2] = matrix[2, 0];
if (b[0] + a[0] == matrix[0, 0] && b[0] + a[1] == matrix[1, 0] &&
b[0] + a[2] == matrix[2, 0] && b[1] + a[0] == matrix[0, 1] &&
b[1] + a[1] == matrix[1, 1] && b[1] + a[2] == matrix[2, 1] &&
b[2] + a[0] == matrix[0, 2] && b[2] + a[1] == matrix[1, 2] &&
b[2] + a[2] == matrix[2, 2]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
namespace AtCoderConsole {
class Program {
static void Main(string[] args) {
string[] input = new string[3];
int[,] matrix = new int[3, 3];
// 標準入力から1行ずつ取得
for (int i = 0; i < 3; i++) {
input[i] = Console.ReadLine();
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
matrix[i, j] = int.Parse(input[i].Split(' ')[j]);
}
}
int[] a = new int[3];
int[] b = new int[3];
// a0を0として考える
a[0] = 0;
b[0] = matrix[0, 0];
b[1] = matrix[0, 1];
b[2] = matrix[0, 2];
a[1] = matrix[1, 0] - b[0];
a[2] = matrix[2, 0] - b[0];
if (b[0] + a[0] == matrix[0, 0] && b[0] + a[1] == matrix[1, 0] &&
b[0] + a[2] == matrix[2, 0] && b[1] + a[0] == matrix[0, 1] &&
b[1] + a[1] == matrix[1, 1] && b[1] + a[2] == matrix[2, 1] &&
b[2] + a[0] == matrix[0, 2] && b[2] + a[1] == matrix[1, 2] &&
b[2] + a[2] == matrix[2, 2]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73]]
| 8
| 402
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<long> Slist() {
return ReadLine().Split().Select(long.Parse).ToList();
}
static long Mod = (long)1e9 + 7;
static void Main(string[] args) {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
var HW = Sarray();
var H = HW[0];
var W = HW[1];
var ban = new string[H + 2];
ban[0] = ban[H + 1] = new string('#', (int)W + 2);
var siroMasu = 0L;
for (var h = 1; h <= H; ++h) {
ban[h] = "#" + ReadLine() + "#";
siroMasu += ban[h].Count(b => b == '.');
}
var dh = new long[] { 0, -1, 1, 0 };
var dw = new long[] { -1, 0, 0, 1 };
var dst = Enumerable.Range(0, (int)H + 2)
.Select(_ => Enumerable.Repeat(-1L, (int)W + 2).ToArray())
.ToArray();
var q = new Queue<Tuple<long, long, long>>(); // h,w,dst
q.Enqueue(Tuple.Create(1L, 1L, 0L)); // h,w
while (q.Any()) {
var p = q.Dequeue();
var nowH = p.Item1;
var nowW = p.Item2;
var nowD = p.Item3;
if (-1 != dst[nowH][nowW] || '#' == ban[nowH][(int)nowW])
continue;
dst[nowH][nowW] = nowD;
for (var i = 0; i < 4; ++i)
q.Enqueue(Tuple.Create(nowH + dh[i], nowW + dw[i], nowD + 1));
}
var ans = siroMasu - (dst[H][W] + 1);
WriteLine(ans);
// Out.Flush();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<long> Slist() {
return ReadLine().Split().Select(long.Parse).ToList();
}
static long Mod = (long)1e9 + 7;
static void Main(string[] args) {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
var HW = Sarray();
var H = HW[0];
var W = HW[1];
var ban = new string[H + 2];
ban[0] = ban[H + 1] = new string('#', (int)W + 2);
var siroMasu = 0L;
for (var h = 1; h <= H; ++h) {
ban[h] = "#" + ReadLine() + "#";
siroMasu += ban[h].Count(b => b == '.');
}
var dh = new long[] { 0, -1, 1, 0 };
var dw = new long[] { -1, 0, 0, 1 };
var dst = Enumerable.Range(0, (int)H + 2)
.Select(_ => Enumerable.Repeat(-1L, (int)W + 2).ToArray())
.ToArray();
var q = new Queue<Tuple<long, long, long>>(); // h,w,dst
q.Enqueue(Tuple.Create(1L, 1L, 0L)); // h,w
while (q.Any()) {
var p = q.Dequeue();
var nowH = p.Item1;
var nowW = p.Item2;
var nowD = p.Item3;
if (-1 != dst[nowH][nowW] || '#' == ban[nowH][(int)nowW])
continue;
dst[nowH][nowW] = nowD;
for (var i = 0; i < 4; ++i)
q.Enqueue(Tuple.Create(nowH + dh[i], nowW + dw[i], nowD + 1));
}
var ans = siroMasu - (dst[H][W] + 1);
if (dst[H][W] == -1)
ans = -1;
WriteLine(ans);
// Out.Flush();
}
}
}
|
[["+", 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, 204, 205, 204, 205, 22], ["+", 15, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 241, 0, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 241, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 508
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Program {
static public void Main() {
var s = new Sol();
// s.Solve1();
// s.Solve2();
s.Solve3();
s.Solve4();
s.Solve5();
s.Solve6();
}
}
public class Sol {
// ABC 007 C 幅優先探索
// https://atcoder.jp/contests/abc007/tasks/abc007_3
// public void Solve1()
//{
// int[] In = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
// int r = In[0];
// int c = In[1];
// int[] In2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
// int sy = In2[0];
// int sx = In2[1];
// sy--;sx--;
// int[] In3 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
// int gy = In3[0];
// int gx = In3[1];
// gy--;gx--;
// var C = new char[r, c];
// for(int i = 0; i < r; i++)
// {
// string s = Console.ReadLine();
// for(int j = 0; j < c; j++)
// {
// C[i, j] = s[j];
// }
// }
// var que = new Queue<Pair>();
// que.Enqueue(new Pair(sy, sx));
// var dis = new int[r, c];
// for(int i = 0; i < r; i++)
// {
// for(int j = 0; j < c; j++)
// {
// dis[i, j] = -1;
// }
// }
// dis[sy, sx] = 0;
// while (que.Count > 0)
// {
// Pair p = que.Dequeue();
// //Console.WriteLine($"{p.y} {p.x}");
// if (p.y == gy && p.x == gx)
// {
// Console.WriteLine(dis[p.y, p.x]);
// break;
// }
// for (int i=0; i < 4; i++)
// {
// int ny = p.y + dy[i];
// int nx = p.x + dx[i];
// if (ny < 0 || r <= ny || nx < 0 || c <= nx || C[ny,nx]=='#' ||
// dis[ny,nx]!=-1) continue; dis[ny, nx] = dis[p.y, p.x] + 1;
// que.Enqueue(new Pair(ny, nx));
// }
// }
//}
// public struct Pair
//{
// public int y,x;
// public Pair(int y, int x)
// {
// this.x = x;
// this.y = y;
// }
//}
public static int[] dx = new int[] { 1, 0, -1, 0 };
public static int[] dy = new int[] { 0, 1, 0, -1 };
// JOI 2010 予選E チーズ
// https://atcoder.jp/contests/joi2011yo/tasks/joi2011yo_e
public void Solve2() {
int[] In = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int h = In[0];
int w = In[1];
int n = In[2];
var C = new char[h, w];
for (int i = 0; i < h; i++) {
string s = Console.ReadLine();
for (int j = 0; j < w; j++) {
C[i, j] = s[j];
}
}
var dis = new int[h, w];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
dis[i, j] = -1;
var que = new Queue<Pair>();
// Sを探す
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
if (C[i, j] == 'S') {
que.Enqueue(new Pair(i, j));
C[i, j] = '.';
dis[i, j] = 0;
}
int HP = 1;
int ans = 0;
while (que.Count > 0 && n > 0) {
var p = que.Dequeue();
// Console.WriteLine($"{p.x} {p.y}");
char m = C[p.x, p.y];
if ('1' <= m && m <= '9' && int.Parse(m.ToString()) <= HP) {
// Console.WriteLine("!");
ans += dis[p.x, p.y];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
dis[i, j] = -1;
C[p.x, p.y] = '.';
dis[p.x, p.y] = 0;
n--;
HP++;
que.Clear();
que.Enqueue(p);
continue;
}
for (int i = 0; i < 4; i++) {
int nx = p.x + dx[i];
int ny = p.y + dy[i];
if (nx < 0 || h <= nx || ny < 0 || w <= ny || C[nx, ny] == 'X' ||
dis[nx, ny] != -1)
continue;
dis[nx, ny] = dis[p.x, p.y] + 1;
que.Enqueue(new Pair(nx, ny));
}
}
Console.WriteLine(ans);
}
public struct Pair {
public int x, y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
// ABC 088 D grid Repainting
// https://atcoder.jp/contests/abc088/tasks/abc088_d
public void Solve3() {
int[] In = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int h = In[0];
int w = In[1];
var C = new char[h, w];
int wcnt = 0;
for (int i = 0; i < h; i++) {
string s = Console.ReadLine();
for (int j = 0; j < w; j++) {
C[i, j] = s[j];
if (s[j] == '.')
wcnt++;
}
}
var dis = new int[h, w];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
dis[i, j] = -1;
var que = new Queue<Pair>();
que.Enqueue(new Pair(0, 0));
dis[0, 0] = 0;
int min = 1001001001;
while (que.Count > 0) {
Pair p = que.Dequeue();
if (p.x == h - 1 && p.y == w - 1) {
min = dis[p.x, p.y];
break;
}
for (int i = 0; i < 4; i++) {
int nx = p.x + dx[i];
int ny = p.y + dy[i];
if (nx < 0 || h <= nx || ny < 0 || w <= ny || C[nx, ny] == '#' ||
dis[nx, ny] != -1)
continue;
dis[nx, ny] = dis[p.x, p.y] + 1;
que.Enqueue(new Pair(nx, ny));
}
}
Console.WriteLine(wcnt - min - 1);
}
// A
//
public void Solve4() {}
//
//
public void Solve5() {}
//
//
public void Solve6() {}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Program {
static public void Main() {
var s = new Sol();
// s.Solve1();
// s.Solve2();
s.Solve3();
s.Solve4();
s.Solve5();
s.Solve6();
}
}
public class Sol {
// ABC 007 C 幅優先探索
// https://atcoder.jp/contests/abc007/tasks/abc007_3
// public void Solve1()
//{
// int[] In = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
// int r = In[0];
// int c = In[1];
// int[] In2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
// int sy = In2[0];
// int sx = In2[1];
// sy--;sx--;
// int[] In3 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
// int gy = In3[0];
// int gx = In3[1];
// gy--;gx--;
// var C = new char[r, c];
// for(int i = 0; i < r; i++)
// {
// string s = Console.ReadLine();
// for(int j = 0; j < c; j++)
// {
// C[i, j] = s[j];
// }
// }
// var que = new Queue<Pair>();
// que.Enqueue(new Pair(sy, sx));
// var dis = new int[r, c];
// for(int i = 0; i < r; i++)
// {
// for(int j = 0; j < c; j++)
// {
// dis[i, j] = -1;
// }
// }
// dis[sy, sx] = 0;
// while (que.Count > 0)
// {
// Pair p = que.Dequeue();
// //Console.WriteLine($"{p.y} {p.x}");
// if (p.y == gy && p.x == gx)
// {
// Console.WriteLine(dis[p.y, p.x]);
// break;
// }
// for (int i=0; i < 4; i++)
// {
// int ny = p.y + dy[i];
// int nx = p.x + dx[i];
// if (ny < 0 || r <= ny || nx < 0 || c <= nx || C[ny,nx]=='#' ||
// dis[ny,nx]!=-1) continue; dis[ny, nx] = dis[p.y, p.x] + 1;
// que.Enqueue(new Pair(ny, nx));
// }
// }
//}
// public struct Pair
//{
// public int y,x;
// public Pair(int y, int x)
// {
// this.x = x;
// this.y = y;
// }
//}
public static int[] dx = new int[] { 1, 0, -1, 0 };
public static int[] dy = new int[] { 0, 1, 0, -1 };
// JOI 2010 予選E チーズ
// https://atcoder.jp/contests/joi2011yo/tasks/joi2011yo_e
public void Solve2() {
int[] In = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int h = In[0];
int w = In[1];
int n = In[2];
var C = new char[h, w];
for (int i = 0; i < h; i++) {
string s = Console.ReadLine();
for (int j = 0; j < w; j++) {
C[i, j] = s[j];
}
}
var dis = new int[h, w];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
dis[i, j] = -1;
var que = new Queue<Pair>();
// Sを探す
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
if (C[i, j] == 'S') {
que.Enqueue(new Pair(i, j));
C[i, j] = '.';
dis[i, j] = 0;
}
int HP = 1;
int ans = 0;
while (que.Count > 0 && n > 0) {
var p = que.Dequeue();
// Console.WriteLine($"{p.x} {p.y}");
char m = C[p.x, p.y];
if ('1' <= m && m <= '9' && int.Parse(m.ToString()) <= HP) {
// Console.WriteLine("!");
ans += dis[p.x, p.y];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
dis[i, j] = -1;
C[p.x, p.y] = '.';
dis[p.x, p.y] = 0;
n--;
HP++;
que.Clear();
que.Enqueue(p);
continue;
}
for (int i = 0; i < 4; i++) {
int nx = p.x + dx[i];
int ny = p.y + dy[i];
if (nx < 0 || h <= nx || ny < 0 || w <= ny || C[nx, ny] == 'X' ||
dis[nx, ny] != -1)
continue;
dis[nx, ny] = dis[p.x, p.y] + 1;
que.Enqueue(new Pair(nx, ny));
}
}
Console.WriteLine(ans);
}
public struct Pair {
public int x, y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
// ABC 088 D grid Repainting
// https://atcoder.jp/contests/abc088/tasks/abc088_d
public void Solve3() {
int[] In = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int h = In[0];
int w = In[1];
var C = new char[h, w];
int wcnt = 0;
for (int i = 0; i < h; i++) {
string s = Console.ReadLine();
for (int j = 0; j < w; j++) {
C[i, j] = s[j];
if (s[j] == '.')
wcnt++;
}
}
var dis = new int[h, w];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
dis[i, j] = -1;
var que = new Queue<Pair>();
que.Enqueue(new Pair(0, 0));
dis[0, 0] = 0;
int INF = 1001001001;
int min = INF;
while (que.Count > 0) {
Pair p = que.Dequeue();
if (p.x == h - 1 && p.y == w - 1) {
min = dis[p.x, p.y];
break;
}
for (int i = 0; i < 4; i++) {
int nx = p.x + dx[i];
int ny = p.y + dy[i];
if (nx < 0 || h <= nx || ny < 0 || w <= ny || C[nx, ny] == '#' ||
dis[nx, ny] != -1)
continue;
dis[nx, ny] = dis[p.x, p.y] + 1;
que.Enqueue(new Pair(nx, ny));
}
}
if (min == INF) {
Console.WriteLine(-1);
} else
Console.WriteLine(wcnt - min - 1);
}
// A
//
public void Solve4() {}
//
//
public void Solve5() {}
//
//
public void Solve6() {}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 52, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 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, 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, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
| 8
| 1,200
| 24
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Solve {
static public int mod = 1000000007;
static public string al = "abcdefghijklmnopqrstuvwxyz";
public static void Main() {
// 方針
//
var tn = inta();
var t = tn[0];
var y = tn[1];
var map = new char[t, y];
var count = 0;
for (int i = 0; i < t; i++) {
var s = rstr();
for (int j = 0; j < y; j++) {
map[i, j] = s[j];
if (map[i, j] == '.')
count++;
}
}
var queue = new Queue<int>();
queue.Enqueue(0);
queue.Enqueue(0);
var countmap = new int[t, y];
for (int i = 0; i < t; i++) {
for (int j = 0; j < y; j++) {
countmap[i, j] = 1000000000;
}
}
countmap[0, 0] = 1;
var passed = new bool[t, y];
var movet = new int[] { 1, 0, -1, 0 };
var movey = new int[] { 0, 1, 0, -1 };
while (queue.Count > 0) {
var det = queue.Dequeue();
var dey = queue.Dequeue();
if (passed[det, dey])
continue;
passed[det, dey] = true;
for (int i = 0; i < 4; i++) {
var nextt = det + movet[i];
var nexty = dey + movey[i];
if (!(0 <= nextt && nextt < t && 0 <= nexty && nexty < y))
continue;
if (map[nextt, nexty] == '#')
continue;
countmap[nextt, nexty] =
Min(countmap[nextt, nexty], countmap[det, dey] + 1);
queue.Enqueue(nextt);
queue.Enqueue(nexty);
}
}
WriteLine(count - countmap[t - 1, y - 1]);
}
public static void swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}
static void charswap(ref char a, ref char b) {
char temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
if (n < r)
return 0;
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
static int square2(int a, int b) {
long output = 1;
var list = new List<long>();
int sh = 1;
long n = a;
list.Add(a);
while (sh < b) {
sh *= 2;
n = n * n % mod;
list.Add(n);
}
for (int i = list.Count - 1; i >= 0; i--) {
if (b > sh) {
b -= sh;
sh /= 2;
output = output * list[i] % mod;
}
}
return (int)output;
}
//各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = double.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
static void WriteArray(int[,] a, int b, int c) {
for (int i = 0; i < b; i++) {
for (int j = 0; j < c; j++) {
if (j != 0)
Write(" ");
Write(a[i, j]);
}
WriteLine();
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Solve {
static public int mod = 1000000007;
static public string al = "abcdefghijklmnopqrstuvwxyz";
public static void Main() {
// 方針
//
var tn = inta();
var t = tn[0];
var y = tn[1];
var map = new char[t, y];
var count = 0;
for (int i = 0; i < t; i++) {
var s = rstr();
for (int j = 0; j < y; j++) {
map[i, j] = s[j];
if (map[i, j] == '.')
count++;
}
}
var queue = new Queue<int>();
queue.Enqueue(0);
queue.Enqueue(0);
var countmap = new int[t, y];
for (int i = 0; i < t; i++) {
for (int j = 0; j < y; j++) {
countmap[i, j] = 1000000001;
}
}
countmap[0, 0] = 1;
var passed = new bool[t, y];
var movet = new int[] { 1, 0, -1, 0 };
var movey = new int[] { 0, 1, 0, -1 };
while (queue.Count > 0) {
var det = queue.Dequeue();
var dey = queue.Dequeue();
if (passed[det, dey])
continue;
passed[det, dey] = true;
for (int i = 0; i < 4; i++) {
var nextt = det + movet[i];
var nexty = dey + movey[i];
if (!(0 <= nextt && nextt < t && 0 <= nexty && nexty < y))
continue;
if (map[nextt, nexty] == '#')
continue;
countmap[nextt, nexty] =
Min(countmap[nextt, nexty], countmap[det, dey] + 1);
queue.Enqueue(nextt);
queue.Enqueue(nexty);
}
}
if (countmap[t - 1, y - 1] > 1000000000) {
WriteLine(-1);
} else {
WriteLine(count - countmap[t - 1, y - 1]);
}
}
public static void swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}
static void charswap(ref char a, ref char b) {
char temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
if (n < r)
return 0;
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
static int square2(int a, int b) {
long output = 1;
var list = new List<long>();
int sh = 1;
long n = a;
list.Add(a);
while (sh < b) {
sh *= 2;
n = n * n % mod;
list.Add(n);
}
for (int i = list.Count - 1; i >= 0; i--) {
if (b > sh) {
b -= sh;
sh /= 2;
output = output * list[i] % mod;
}
}
return (int)output;
}
//各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = double.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
static void WriteArray(int[,] a, int b, int c) {
for (int i = 0; i < b; i++) {
for (int j = 0; j < c; j++) {
if (j != 0)
Write(" ");
Write(a[i, j]);
}
WriteLine();
}
}
}
|
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 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, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 21], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 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
| 1,487
| 28
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace D {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var HW = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
var H = HW[0];
var W = HW[1];
var answer = H * W;
var grid = new bool [H][];
for (var i = 0; i < H; i++) {
grid[i] = new bool[W];
var s = Console.ReadLine();
for (var j = 0; j < s.Length; j++) {
grid[i][j] = s[j] == '.';
if (!grid[i][j])
answer--;
}
}
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(0, 0));
var depths = new int [H][]
.Select(x => x = Enumerable.Repeat(-1, W).ToArray())
.ToArray();
depths[0][0] = 0;
while (queue.Any()) {
var current = queue.Dequeue();
var x = current.Item1;
var y = current.Item2;
var nextDir = new List<Tuple<int, int>>();
if (x > 0 && grid[y][x - 1])
nextDir.Add(new Tuple<int, int>(x - 1, y));
if (x < W - 1 && grid[y][x + 1])
nextDir.Add(new Tuple<int, int>(x + 1, y));
if (y > 0 && grid[y - 1][x])
nextDir.Add(new Tuple<int, int>(x, y - 1));
if (y < H - 1 && grid[y + 1][x])
nextDir.Add(new Tuple<int, int>(x, y + 1));
foreach (var next in nextDir) {
var nx = next.Item1;
var ny = next.Item2;
if (depths[ny][nx] != -1)
continue;
depths[ny][nx] = depths[y][x] + 1;
queue.Enqueue(next);
}
}
answer -= depths[H - 1][W - 1] + 1;
Console.WriteLine(answer);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace D {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var HW = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
var H = HW[0];
var W = HW[1];
var answer = H * W;
var grid = new bool [H][];
for (var i = 0; i < H; i++) {
grid[i] = new bool[W];
var s = Console.ReadLine();
for (var j = 0; j < s.Length; j++) {
grid[i][j] = s[j] == '.';
if (!grid[i][j])
answer--;
}
}
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(0, 0));
var depths = new int [H][]
.Select(x => x = Enumerable.Repeat(-1, W).ToArray())
.ToArray();
depths[0][0] = 0;
while (queue.Any()) {
var current = queue.Dequeue();
var x = current.Item1;
var y = current.Item2;
var nextDir = new List<Tuple<int, int>>();
if (x > 0 && grid[y][x - 1])
nextDir.Add(new Tuple<int, int>(x - 1, y));
if (x < W - 1 && grid[y][x + 1])
nextDir.Add(new Tuple<int, int>(x + 1, y));
if (y > 0 && grid[y - 1][x])
nextDir.Add(new Tuple<int, int>(x, y - 1));
if (y < H - 1 && grid[y + 1][x])
nextDir.Add(new Tuple<int, int>(x, y + 1));
foreach (var next in nextDir) {
var nx = next.Item1;
var ny = next.Item2;
if (depths[ny][nx] != -1)
continue;
depths[ny][nx] = depths[y][x] + 1;
queue.Enqueue(next);
}
}
if (depths[H - 1][W - 1] == -1) {
Console.WriteLine(-1);
return;
}
answer -= depths[H - 1][W - 1] + 1;
Console.WriteLine(answer);
}
}
}
|
[["+", 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, 204, 205, 204, 205, 22], ["+", 15, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 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], ["+", 15, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 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, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 603
| 29
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC088D {
class Program {
static void Main(string[] args) {
int whiteCount = 0;
var HW = ReadInt();
int H = HW[0];
int W = HW[1];
char[,] map = new char[H + 2, W + 2];
int[,] d = new int[H + 2, W + 2];
d[1, 1] = 1;
for (int i = 0; i < H; i++) {
var input = Console.ReadLine();
for (int j = 0; j < W; j++) {
map[i + 1, j + 1] = input[j];
if (input[j] == '.')
whiteCount++;
}
}
int[] dx = new int[] { 0, 1, 0, -1 };
int[] dy = new int[] { -1, 0, 1, 0 };
Queue<int> queX = new Queue<int>();
Queue<int> queY = new Queue<int>();
queX.Enqueue(1);
queY.Enqueue(1);
while (queX.Count > 0) {
int x = queX.Dequeue();
int y = queY.Dequeue();
if (map[y, x] == '#')
continue;
map[y, x] = '#';
for (int i = 0; i < 4; i++) {
if (map[y + dy[i], x + dx[i]] == '.') {
queX.Enqueue(x + dx[i]);
queY.Enqueue(y + dy[i]);
d[y + dy[i], x + dx[i]] = d[y, x] + 1;
}
}
}
int ans = whiteCount - d[H, W];
Console.WriteLine(ans);
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;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC088D {
class Program {
static void Main(string[] args) {
int whiteCount = 0;
var HW = ReadInt();
int H = HW[0];
int W = HW[1];
char[,] map = new char[H + 2, W + 2];
int[,] d = new int[H + 2, W + 2];
d[1, 1] = 1;
for (int i = 0; i < H; i++) {
var input = Console.ReadLine();
for (int j = 0; j < W; j++) {
map[i + 1, j + 1] = input[j];
if (input[j] == '.')
whiteCount++;
}
}
int[] dx = new int[] { 0, 1, 0, -1 };
int[] dy = new int[] { -1, 0, 1, 0 };
Queue<int> queX = new Queue<int>();
Queue<int> queY = new Queue<int>();
queX.Enqueue(1);
queY.Enqueue(1);
while (queX.Count > 0) {
int x = queX.Dequeue();
int y = queY.Dequeue();
if (map[y, x] == '#')
continue;
map[y, x] = '#';
for (int i = 0; i < 4; i++) {
if (map[y + dy[i], x + dx[i]] == '.') {
queX.Enqueue(x + dx[i]);
queY.Enqueue(y + dy[i]);
d[y + dy[i], x + dx[i]] = d[y, x] + 1;
}
}
}
int ans = whiteCount - d[H, W];
if (d[H, W] == 0)
ans = -1;
Console.WriteLine(ans);
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;
}
}
}
|
[["+", 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, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 21], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 241, 0, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 241, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 506
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class236 {
static int[] dy = new int[4] { 0, 1, 0, -1 };
static int[] dx = new int[4] { 1, 0, -1, 0 };
static void Main() {
var HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
int H = HW[0], W = HW[1];
var map = new bool[H, W];
for (int i = 0; i < H; i++) {
var r = Console.ReadLine();
for (int j = 0; j < W; j++) {
if (r[j] == '#')
map[i, j] = true;
}
}
var que = new Queue<Tuple<int, int, int>>();
que.Enqueue(Tuple.Create(0, 0, 1));
var frag = new bool[H, W];
frag[0, 0] = true;
while (que.Count > 0) {
var p = que.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = p.Item1 + dy[i], nx = p.Item2 + dx[i];
int nc = p.Item3 + 1;
if (0 <= ny && ny < H && 0 <= nx && nx < W) {
if (!frag[ny, nx] && !map[ny, nx]) {
frag[ny, nx] = true;
que.Enqueue(Tuple.Create(ny, nx, nc));
if (ny == H - 1 && nx == W - 1)
goto brk;
}
}
}
}
brk:;
if (frag[H - 1, W - 1]) {
var p = que.Last();
int count1 = 0;
int count2 = p.Item3;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
if (map[i, j])
count1++;
Console.WriteLine(map.Length - count1 - count2);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class236 {
static int[] dy = new int[4] { 0, 1, 0, -1 };
static int[] dx = new int[4] { 1, 0, -1, 0 };
static void Main() {
var HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
int H = HW[0], W = HW[1];
var map = new bool[H, W];
for (int i = 0; i < H; i++) {
var r = Console.ReadLine();
for (int j = 0; j < W; j++) {
if (r[j] == '#')
map[i, j] = true;
}
}
var que = new Queue<Tuple<int, int, int>>();
que.Enqueue(Tuple.Create(0, 0, 1));
var frag = new bool[H, W];
frag[0, 0] = true;
while (que.Count > 0) {
var p = que.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = p.Item1 + dy[i], nx = p.Item2 + dx[i];
int nc = p.Item3 + 1;
if (0 <= ny && ny < H && 0 <= nx && nx < W) {
if (!frag[ny, nx] && !map[ny, nx]) {
frag[ny, nx] = true;
que.Enqueue(Tuple.Create(ny, nx, nc));
if (ny == H - 1 && nx == W - 1)
goto brk;
}
}
}
}
brk:;
if (frag[H - 1, W - 1]) {
var p = que.Last();
int count1 = 0;
int count2 = p.Item3;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
if (map[i, j])
count1++;
Console.WriteLine(map.Length - count1 - count2);
} else
Console.WriteLine("-1");
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 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], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 75, 1, 0, 35]]
| 8
| 492
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class88 {
static char[,] map = new char[50, 50];
static bool[,] frag = new bool[50, 50];
static int[] dx = new int[4] { 1, 0, -1, 0 };
static int[] dy = new int[4] { 0, 1, 0, -1 };
static void Main() {
var HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
int count = 0;
for (int i = 0; i < HW[0]; i++) {
var r = Console.ReadLine();
for (int j = 0; j < HW[1]; j++) {
map[i, j] = r[j];
if (r[j] == '#')
count++;
}
}
var que = new Queue<Tuple<int, int, int>>();
que.Enqueue(Tuple.Create(0, 0, 0));
bool found = false;
while (que.Count > 0) {
var p = que.Dequeue();
for (int i = 0; i < 4; i++) {
var t = Tuple.Create(p.Item1 + dy[i], p.Item2 + dx[i], p.Item3 + 1);
if (0 <= t.Item1 && t.Item1 < HW[0] && 0 <= t.Item2 && t.Item2 < HW[1])
if (map[t.Item1, t.Item2] != '#' && !frag[t.Item1, t.Item2]) {
que.Enqueue(t);
frag[t.Item1, t.Item2] = true;
if (t.Item1 == HW[0] - 1 && t.Item2 == HW[1] - 1) {
found = true;
break;
}
}
}
if (found)
break;
}
if (!found) {
Console.WriteLine(-1);
return;
}
var m = que.Dequeue().Item3;
Console.WriteLine(HW[1] * HW[0] - count - (m + 2));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class88 {
static char[,] map = new char[50, 50];
static bool[,] frag = new bool[50, 50];
static int[] dx = new int[4] { 1, 0, -1, 0 };
static int[] dy = new int[4] { 0, 1, 0, -1 };
static void Main() {
var HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
int count = 0;
for (int i = 0; i < HW[0]; i++) {
var r = Console.ReadLine();
for (int j = 0; j < HW[1]; j++) {
map[i, j] = r[j];
if (r[j] == '#')
count++;
}
}
var que = new Queue<Tuple<int, int, int>>();
que.Enqueue(Tuple.Create(0, 0, 0));
bool found = false;
while (que.Count > 0) {
var p = que.Dequeue();
for (int i = 0; i < 4; i++) {
var t = Tuple.Create(p.Item1 + dy[i], p.Item2 + dx[i], p.Item3 + 1);
if (0 <= t.Item1 && t.Item1 < HW[0] && 0 <= t.Item2 && t.Item2 < HW[1])
if (map[t.Item1, t.Item2] != '#' && !frag[t.Item1, t.Item2]) {
que.Enqueue(t);
frag[t.Item1, t.Item2] = true;
if (t.Item1 == HW[0] - 1 && t.Item2 == HW[1] - 1) {
found = true;
break;
}
}
}
if (found)
break;
}
if (!found) {
Console.WriteLine(-1);
return;
}
var m = que.Last().Item3;
Console.WriteLine(HW[1] * HW[0] - 1 - count - m);
}
}
}
|
[["-", 0, 212, 0, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
| 8
| 496
| 8
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var dx = new int[] { 1, 0, -1, 0 };
var dy = new int[] { 0, 1, 0, -1 };
var o = Ints;
var H = o[0];
var W = o[1];
var s = Enumerable.Range(0, H).Select(_ => Chars).ToArray();
int bcnt = s.Sum(x => x.Count(y => y == '#'));
var dist = new int [H][];
dist = Enumerable.Range(0, H).Select(_ => new int[W]).ToArray();
var q = new Queue<Tuple<int, int>>();
q.Enqueue(new Tuple<int, int>(0, 0));
while (q.Count > 0) {
var p = q.Dequeue();
for (int i = 0; i < 4; ++i) {
var nx = p.Item1 + dx[i];
var ny = p.Item2 + dy[i];
if (nx < 0 || nx >= H || ny < 0 || ny >= W)
continue;
if (dist[nx][ny] != 0)
continue;
if (s[nx][ny] == '#')
continue;
else
q.Enqueue(new Tuple<int, int>(nx, ny));
dist[nx][ny] = dist[p.Item1][p.Item2] + 1;
}
}
Write(H * W - bcnt - dist[H - 1][W - 1] - 1);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const int MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Pow(long i, long N, long MOD = 1000000007) // i^N
{
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
N >>= 1;
}
return res;
}
public static long GCD(long i, long N) {
if (i > N)
Swap(ref i, ref N);
if (i == 0)
return N;
while (N != 0) {
var r = i % N;
i = N;
N = r;
}
return i;
}
public static long LCM(long i, long N) => i * N / GCD(i, N);
public static long Comb(long N, long R, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = N; i >= N - R + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long N, long R) {
long Nume = 1;
long Deno = 1;
if (R > N - R)
Swap(ref N, ref R);
for (long i = 1; i <= R; ++i) {
Deno *= i;
Nume *= N - i + 1;
}
return Deno / Nume;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] HorizontalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Horizontalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var dx = new int[] { 1, 0, -1, 0 };
var dy = new int[] { 0, 1, 0, -1 };
var o = Ints;
var H = o[0];
var W = o[1];
var s = Enumerable.Range(0, H).Select(_ => Chars).ToArray();
int bcnt = s.Sum(x => x.Count(y => y == '#'));
var dist = new int [H][];
dist = Enumerable.Range(0, H).Select(_ => new int[W]).ToArray();
var q = new Queue<Tuple<int, int>>();
q.Enqueue(new Tuple<int, int>(0, 0));
while (q.Count > 0) {
var p = q.Dequeue();
for (int i = 0; i < 4; ++i) {
var nx = p.Item1 + dx[i];
var ny = p.Item2 + dy[i];
if (nx < 0 || nx >= H || ny < 0 || ny >= W)
continue;
if (dist[nx][ny] != 0)
continue;
if (s[nx][ny] == '#')
continue;
else
q.Enqueue(new Tuple<int, int>(nx, ny));
dist[nx][ny] = dist[p.Item1][p.Item2] + 1;
}
}
if (dist[H - 1][W - 1] == 0)
Write(-1);
else
Write(H * W - bcnt - dist[H - 1][W - 1] - 1);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const int MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Pow(long i, long N, long MOD = 1000000007) // i^N
{
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
N >>= 1;
}
return res;
}
public static long GCD(long i, long N) {
if (i > N)
Swap(ref i, ref N);
if (i == 0)
return N;
while (N != 0) {
var r = i % N;
i = N;
N = r;
}
return i;
}
public static long LCM(long i, long N) => i * N / GCD(i, N);
public static long Comb(long N, long R, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = N; i >= N - R + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long N, long R) {
long Nume = 1;
long Deno = 1;
if (R > N - R)
Swap(ref N, ref R);
for (long i = 1; i <= R; ++i) {
Deno *= i;
Nume *= N - i + 1;
}
return Deno / Nume;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] HorizontalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Horizontalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
[["+", 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, 204, 205, 204, 205, 22], ["+", 15, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 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], ["+", 15, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 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], ["+", 8, 196, 0, 57, 75, 1, 0, 213, 63, 22]]
| 8
| 1,207
| 23
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static _20200331.Abc088_D.Cin;
using static _20200331.Abc088_D.Util;
using Pair = _20200331.Abc088_D.VTuple<long, long>;
using Graph =
System.Collections.Generic.List<System.Collections.Generic.List<long>>;
using System.Text;
namespace _20200331 {
public class Abc088_D {
public static void Main(string[] args) {
int H = ri;
int W = ri;
char[,] map = new char[H, W];
for (int i = 0; i < H; i++) {
string tmp = rs;
for (int j = 0; j < W; j++) {
map[i, j] = tmp[j];
}
}
// BFSどう書くんだっけ
bool[,] gone = new bool[H, W];
Queue<VTuple<int, int, int>> que = new Queue<VTuple<int, int, int>>();
que.Enqueue(new VTuple<int, int, int>(0, 0, 0));
int distance = 0;
while (que.Any()) {
var p = que.Dequeue();
var x = p.Item1;
var y = p.Item2;
var depth = p.Item3;
if (gone[x, y])
continue;
gone[x, y] = true;
if (x == H - 1 && y == W - 1) {
distance = depth - 1;
break;
}
for (int i = 0; i < 4; i++) {
var nx = x + DXY4[i];
var ny = y + DXY4[i + 1];
if (0 <= nx && nx < H && 0 <= ny && ny < W && !gone[nx, ny] &&
map[nx, ny] != '#') {
que.Enqueue(new VTuple<int, int, int>(nx, ny, depth + 1));
}
}
}
int blackCnt = 0;
foreach (var c in map) {
if (c == '#')
blackCnt++;
}
int ans = H * W - 2 - distance - blackCnt;
Console.WriteLine(ans);
}
public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> {
public static readonly long MOD = (long)1e9 + 7;
public long Value;
public Mint(long a) {
Value = a % MOD;
if (Value < 0)
Value += MOD;
}
static Mint i(long a) { return new Mint() { Value = a }; }
public static Mint operator +(Mint a, Mint b) {
long c = a.Value + b.Value;
if (c > MOD)
c -= MOD;
return i(c);
}
public static Mint operator -(Mint a, Mint b) {
long c = a.Value - b.Value;
if (c < 0)
c += MOD;
return i(c);
}
public static Mint operator *(Mint a, Mint b) {
long c = a.Value * b.Value;
if (c > MOD)
c %= MOD;
return i(c);
}
public static Mint operator /(Mint a, Mint b) { return a * Inv(b); }
public override bool Equals(object a) {
return a is Mint && Value == ((Mint)a).Value;
}
public override int GetHashCode() { return Value.GetHashCode(); }
public static implicit operator Mint(long a) { return new Mint(a); }
public static explicit operator long(Mint a) { return a.Value; }
public static Mint Pow(Mint a, long b) {
if (b == 0)
return new Mint(1);
Mint c = Pow(a, b >> 1);
c *= c;
if ((b & 1) == 1)
c *= a;
return c;
}
public static Mint Inv(Mint a) {
long b = a.Value;
long c = MOD;
long d = 1;
long e = 0;
while (c != 0) {
long f = b / c;
long g = e;
e = d - f * e;
d = g;
long h = b;
b = c;
c = h - (f * c);
}
return new Mint(d);
}
public bool Equals(Mint a) { return Value == a.Value; }
public int CompareTo(Mint a) {
return Comparer<long>.Default.Compare(Value, a.Value);
}
}
public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>,
System.IEquatable<VTuple<T1, T2>> {
public T1 Item1;
public T2 Item2;
public T1 First {
get { return Item1; }
}
public T2 Second {
get { return Item2; }
}
public VTuple(T1 a, T2 b) {
Item1 = a;
Item2 = b;
}
public override bool Equals(object a) {
return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a);
}
public override int GetHashCode() {
int a = Item1 != null ? Item1.GetHashCode() : 0;
int b = Item2 != null ? Item2.GetHashCode() : 0;
return HashHelpers.CombineHashCodes(a, b);
}
public bool Equals(VTuple<T1, T2> a) {
return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) &&
EqualityComparer<T2>.Default.Equals(Item2, a.Item2);
}
public int CompareTo(VTuple<T1, T2> a) {
int b = Comparer<T1>.Default.Compare(Item1, a.Item1);
if (b != 0)
return b;
return Comparer<T2>.Default.Compare(Item2, a.Item2);
}
}
public struct VTuple<T1, T2, T3> : System.IComparable<VTuple<T1, T2, T3>>,
System.IEquatable<VTuple<T1, T2, T3>> {
public T1 Item1;
public T2 Item2;
public T3 Item3;
public VTuple(T1 a, T2 b, T3 c) {
Item1 = a;
Item2 = b;
Item3 = c;
}
public override bool Equals(object a) {
return a is VTuple<T1, T2, T3> && Equals((VTuple<T1, T2, T3>)a);
}
public override int GetHashCode() {
int a = Item1 != null ? Item1.GetHashCode() : 0;
int b = Item2 != null ? Item2.GetHashCode() : 0;
int c = Item3 != null ? Item3.GetHashCode() : 0;
return HashHelpers.CombineHashCodes(a, b, c);
}
public bool Equals(VTuple<T1, T2, T3> a) {
return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) &&
EqualityComparer<T2>.Default.Equals(Item2, a.Item2) &&
EqualityComparer<T3>.Default.Equals(Item3, a.Item3);
}
public int CompareTo(VTuple<T1, T2, T3> a) {
int b = Comparer<T1>.Default.Compare(Item1, a.Item1);
if (b != 0)
return b;
b = Comparer<T2>.Default.Compare(Item2, a.Item2);
if (b != 0)
return b;
return Comparer<T3>.Default.Compare(Item3, a.Item3);
}
}
public struct VTuple<T1, T2, T3, T4>
: System.IComparable<VTuple<T1, T2, T3, T4>>,
System.IEquatable<VTuple<T1, T2, T3, T4>> {
public T1 Item1;
public T2 Item2;
public T3 Item3;
public T4 Item4;
public VTuple(T1 a, T2 b, T3 c, T4 d) {
Item1 = a;
Item2 = b;
Item3 = c;
Item4 = d;
}
public override bool Equals(object a) {
return a is VTuple<T1, T2, T3, T4> && Equals((VTuple<T1, T2, T3, T4>)a);
}
public override int GetHashCode() {
int a = Item1 != null ? Item1.GetHashCode() : 0;
int b = Item2 != null ? Item2.GetHashCode() : 0;
int c = Item3 != null ? Item3.GetHashCode() : 0;
int d = Item3 != null ? Item4.GetHashCode() : 0;
return HashHelpers.CombineHashCodes(a, b, c, d);
}
public bool Equals(VTuple<T1, T2, T3, T4> a) {
return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) &&
EqualityComparer<T2>.Default.Equals(Item2, a.Item2) &&
EqualityComparer<T3>.Default.Equals(Item3, a.Item3) &&
EqualityComparer<T4>.Default.Equals(Item4, a.Item4);
}
public int CompareTo(VTuple<T1, T2, T3, T4> a) {
int b = Comparer<T1>.Default.Compare(Item1, a.Item1);
if (b != 0)
return b;
b = Comparer<T2>.Default.Compare(Item2, a.Item2);
if (b != 0)
return b;
b = Comparer<T3>.Default.Compare(Item3, a.Item3);
if (b != 0)
return b;
return Comparer<T4>.Default.Compare(Item4, a.Item4);
}
}
public static class HashHelpers {
public static readonly int RandomSeed =
new System.Random().Next(int.MinValue, int.MaxValue);
public static int Combine(int a, int b) {
uint c = ((uint)a << 5) | ((uint)a >> 27);
return ((int)c + a) ^ b;
}
public static int CombineHashCodes(int a, int b) {
return Combine(Combine(RandomSeed, a), b);
}
public static int CombineHashCodes(int a, int b, int c) {
return Combine(CombineHashCodes(a, b), c);
}
public static int CombineHashCodes(int a, int b, int c, int d) {
return Combine(CombineHashCodes(a, b, c), d);
}
}
public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> {
V i;
static Func<V> j =
System.Linq.Expressions.Expression
.Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V)))
.Compile();
public HashMap() {}
public HashMap(V a) { i = a; }
new public V this[K a] { get { V b;
if (TryGetValue(a, out b))
return b;
else
return base[a] = i != null ? i : j();
}
set { base[a] = value; }
}
}
public static class Util {
public static readonly long INF = (long)1e17;
public readonly static long MOD = (long)1e9 + 7;
public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 };
public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 };
public static void DontAutoFlush() {
var a = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(a);
}
public static void Flush() { Console.Out.Flush(); }
public static T[] Sort<T>(T[] a) {
Array.Sort<T>(a);
return a;
}
public static T[] SortDecend<T>(T[] a) {
Array.Sort<T>(a);
Array.Reverse(a);
return a;
}
public static void Swap<T>(ref T a, ref T b) {
T c = a;
a = b;
b = c;
}
public static long GCD(long a, long b) {
while (b != 0) {
long c = a;
a = b;
b = c % b;
}
return a;
}
public static long LCM(long a, long b) {
if (a == 0 || b == 0)
return 0;
return a * b / GCD(a, b);
}
public static void ChMax(ref long a, long b) {
if (a < b)
a = b;
}
public static void ChMin(ref long a, long b) {
if (a > b)
a = b;
}
public static void ChMax(ref int a, int b) {
if (a < b)
a = b;
}
public static void ChMin(ref int a, int b) {
if (a > b)
a = b;
}
public static void FillArray<T>(T[] a, T b) {
int c = a.Length;
for (int d = 0; d < c; d++)
a[d] = b;
}
public static void FillArray<T>(T[,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
for (int e = 0; e < c; e++)
for (int f = 0; f < d; f++) {
a[e, f] = b;
}
}
public static void FillArray<T>(T[,,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
int e = a.GetLength(2);
for (int f = 0; f < c; f++)
for (int g = 0; g < d; g++) {
for (int h = 0; h < e; h++) {
a[f, g, h] = b;
}
}
}
public static long[] Accumulate(long[] a) {
long[] b = new long[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
public static double[] Accumulate(double[] a) {
double[] b = new double[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
}
public static class Cin {
public static int ri {
get { return ReadInt(); }
}
public static int[] ria {
get { return ReadIntArray(); }
}
public static long rl {
get { return ReadLong(); }
}
public static long[] rla {
get { return ReadLongArray(); }
}
public static double rd {
get { return ReadDouble(); }
}
public static double[] rda {
get { return ReadDoubleArray(); }
}
public static string rs {
get { return ReadString(); }
}
public static string[] rsa {
get { return ReadStringArray(); }
}
public static int ReadInt() { return int.Parse(i()); }
public static long ReadLong() { return long.Parse(i()); }
public static double ReadDouble() { return double.Parse(i()); }
public static string ReadString() { return i(); }
public static int[] ReadIntArray() {
g = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
public static long[] ReadLongArray() {
g = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
public static double[] ReadDoubleArray() {
g = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
}
public static string[] ReadStringArray() {
g = null;
return Console.ReadLine().Split(' ');
}
public static void ReadCol(out long[] a, long b) {
a = new long[b];
for (int c = 0; c < b; c++)
a[c] = ReadLong();
}
public static void ReadCols(out long[] a, out long[] b, long c) {
a = new long[c];
b = new long[c];
for (int d = 0; d < c; d++) {
a[d] = ReadLong();
b[d] = ReadLong();
}
}
public static void ReadCols(out long[] a, out long[] b, out long[] c,
long d) {
a = new long[d];
b = new long[d];
c = new long[d];
for (int e = 0; e < d; e++) {
a[e] = ReadLong();
b[e] = ReadLong();
c[e] = ReadLong();
}
}
public static int[,] ReadIntTable(int a, int b) {
g = null;
int[,] c = new int[a, b];
for (int d = 0; d < a; d++)
for (int e = 0; e < b; e++) {
c[d, e] = ReadInt();
}
return c;
}
public static long[,] ReadLongTable(long a, long b) {
g = null;
long[,] c = new long[a, b];
for (int d = 0; d < a; d++)
for (int e = 0; e < b; e++) {
c[d, e] = ReadLong();
}
return c;
}
public static char[,] ReadCharTable(int a, int b) {
g = null;
char[,] c = new char[a, b];
for (int d = 0; d < a; d++) {
var e = ReadString();
for (int f = 0; f < b; f++)
c[d, f] = e[f];
}
return c;
}
static string[] g;
static int h;
static string i() {
if (g == null || g.Length <= h) {
g = Console.ReadLine().Split(' ');
h = 0;
}
return g[h++];
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static _20200331.Abc088_D.Cin;
using static _20200331.Abc088_D.Util;
using Pair = _20200331.Abc088_D.VTuple<long, long>;
using Graph =
System.Collections.Generic.List<System.Collections.Generic.List<long>>;
using System.Text;
namespace _20200331 {
public class Abc088_D {
public static void Main(string[] args) {
int H = ri;
int W = ri;
char[,] map = new char[H, W];
for (int i = 0; i < H; i++) {
string tmp = rs;
for (int j = 0; j < W; j++) {
map[i, j] = tmp[j];
}
}
// BFSどう書くんだっけ
bool[,] gone = new bool[H, W];
Queue<VTuple<int, int, int>> que = new Queue<VTuple<int, int, int>>();
que.Enqueue(new VTuple<int, int, int>(0, 0, 0));
int distance = -1;
while (que.Any()) {
var p = que.Dequeue();
var x = p.Item1;
var y = p.Item2;
var depth = p.Item3;
if (gone[x, y])
continue;
gone[x, y] = true;
if (x == H - 1 && y == W - 1) {
distance = depth - 1;
break;
}
for (int i = 0; i < 4; i++) {
var nx = x + DXY4[i];
var ny = y + DXY4[i + 1];
if (0 <= nx && nx < H && 0 <= ny && ny < W && !gone[nx, ny] &&
map[nx, ny] != '#') {
que.Enqueue(new VTuple<int, int, int>(nx, ny, depth + 1));
}
}
}
if (distance == -1) {
Console.WriteLine(distance);
return;
}
int blackCnt = 0;
foreach (var c in map) {
if (c == '#')
blackCnt++;
}
int ans = H * W - 2 - distance - blackCnt;
Console.WriteLine(ans);
}
public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> {
public static readonly long MOD = (long)1e9 + 7;
public long Value;
public Mint(long a) {
Value = a % MOD;
if (Value < 0)
Value += MOD;
}
static Mint i(long a) { return new Mint() { Value = a }; }
public static Mint operator +(Mint a, Mint b) {
long c = a.Value + b.Value;
if (c > MOD)
c -= MOD;
return i(c);
}
public static Mint operator -(Mint a, Mint b) {
long c = a.Value - b.Value;
if (c < 0)
c += MOD;
return i(c);
}
public static Mint operator *(Mint a, Mint b) {
long c = a.Value * b.Value;
if (c > MOD)
c %= MOD;
return i(c);
}
public static Mint operator /(Mint a, Mint b) { return a * Inv(b); }
public override bool Equals(object a) {
return a is Mint && Value == ((Mint)a).Value;
}
public override int GetHashCode() { return Value.GetHashCode(); }
public static implicit operator Mint(long a) { return new Mint(a); }
public static explicit operator long(Mint a) { return a.Value; }
public static Mint Pow(Mint a, long b) {
if (b == 0)
return new Mint(1);
Mint c = Pow(a, b >> 1);
c *= c;
if ((b & 1) == 1)
c *= a;
return c;
}
public static Mint Inv(Mint a) {
long b = a.Value;
long c = MOD;
long d = 1;
long e = 0;
while (c != 0) {
long f = b / c;
long g = e;
e = d - f * e;
d = g;
long h = b;
b = c;
c = h - (f * c);
}
return new Mint(d);
}
public bool Equals(Mint a) { return Value == a.Value; }
public int CompareTo(Mint a) {
return Comparer<long>.Default.Compare(Value, a.Value);
}
}
public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>,
System.IEquatable<VTuple<T1, T2>> {
public T1 Item1;
public T2 Item2;
public T1 First {
get { return Item1; }
}
public T2 Second {
get { return Item2; }
}
public VTuple(T1 a, T2 b) {
Item1 = a;
Item2 = b;
}
public override bool Equals(object a) {
return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a);
}
public override int GetHashCode() {
int a = Item1 != null ? Item1.GetHashCode() : 0;
int b = Item2 != null ? Item2.GetHashCode() : 0;
return HashHelpers.CombineHashCodes(a, b);
}
public bool Equals(VTuple<T1, T2> a) {
return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) &&
EqualityComparer<T2>.Default.Equals(Item2, a.Item2);
}
public int CompareTo(VTuple<T1, T2> a) {
int b = Comparer<T1>.Default.Compare(Item1, a.Item1);
if (b != 0)
return b;
return Comparer<T2>.Default.Compare(Item2, a.Item2);
}
}
public struct VTuple<T1, T2, T3> : System.IComparable<VTuple<T1, T2, T3>>,
System.IEquatable<VTuple<T1, T2, T3>> {
public T1 Item1;
public T2 Item2;
public T3 Item3;
public VTuple(T1 a, T2 b, T3 c) {
Item1 = a;
Item2 = b;
Item3 = c;
}
public override bool Equals(object a) {
return a is VTuple<T1, T2, T3> && Equals((VTuple<T1, T2, T3>)a);
}
public override int GetHashCode() {
int a = Item1 != null ? Item1.GetHashCode() : 0;
int b = Item2 != null ? Item2.GetHashCode() : 0;
int c = Item3 != null ? Item3.GetHashCode() : 0;
return HashHelpers.CombineHashCodes(a, b, c);
}
public bool Equals(VTuple<T1, T2, T3> a) {
return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) &&
EqualityComparer<T2>.Default.Equals(Item2, a.Item2) &&
EqualityComparer<T3>.Default.Equals(Item3, a.Item3);
}
public int CompareTo(VTuple<T1, T2, T3> a) {
int b = Comparer<T1>.Default.Compare(Item1, a.Item1);
if (b != 0)
return b;
b = Comparer<T2>.Default.Compare(Item2, a.Item2);
if (b != 0)
return b;
return Comparer<T3>.Default.Compare(Item3, a.Item3);
}
}
public struct VTuple<T1, T2, T3, T4>
: System.IComparable<VTuple<T1, T2, T3, T4>>,
System.IEquatable<VTuple<T1, T2, T3, T4>> {
public T1 Item1;
public T2 Item2;
public T3 Item3;
public T4 Item4;
public VTuple(T1 a, T2 b, T3 c, T4 d) {
Item1 = a;
Item2 = b;
Item3 = c;
Item4 = d;
}
public override bool Equals(object a) {
return a is VTuple<T1, T2, T3, T4> && Equals((VTuple<T1, T2, T3, T4>)a);
}
public override int GetHashCode() {
int a = Item1 != null ? Item1.GetHashCode() : 0;
int b = Item2 != null ? Item2.GetHashCode() : 0;
int c = Item3 != null ? Item3.GetHashCode() : 0;
int d = Item3 != null ? Item4.GetHashCode() : 0;
return HashHelpers.CombineHashCodes(a, b, c, d);
}
public bool Equals(VTuple<T1, T2, T3, T4> a) {
return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) &&
EqualityComparer<T2>.Default.Equals(Item2, a.Item2) &&
EqualityComparer<T3>.Default.Equals(Item3, a.Item3) &&
EqualityComparer<T4>.Default.Equals(Item4, a.Item4);
}
public int CompareTo(VTuple<T1, T2, T3, T4> a) {
int b = Comparer<T1>.Default.Compare(Item1, a.Item1);
if (b != 0)
return b;
b = Comparer<T2>.Default.Compare(Item2, a.Item2);
if (b != 0)
return b;
b = Comparer<T3>.Default.Compare(Item3, a.Item3);
if (b != 0)
return b;
return Comparer<T4>.Default.Compare(Item4, a.Item4);
}
}
public static class HashHelpers {
public static readonly int RandomSeed =
new System.Random().Next(int.MinValue, int.MaxValue);
public static int Combine(int a, int b) {
uint c = ((uint)a << 5) | ((uint)a >> 27);
return ((int)c + a) ^ b;
}
public static int CombineHashCodes(int a, int b) {
return Combine(Combine(RandomSeed, a), b);
}
public static int CombineHashCodes(int a, int b, int c) {
return Combine(CombineHashCodes(a, b), c);
}
public static int CombineHashCodes(int a, int b, int c, int d) {
return Combine(CombineHashCodes(a, b, c), d);
}
}
public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> {
V i;
static Func<V> j =
System.Linq.Expressions.Expression
.Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V)))
.Compile();
public HashMap() {}
public HashMap(V a) { i = a; }
new public V this[K a] { get { V b;
if (TryGetValue(a, out b))
return b;
else
return base[a] = i != null ? i : j();
}
set { base[a] = value; }
}
}
public static class Util {
public static readonly long INF = (long)1e17;
public readonly static long MOD = (long)1e9 + 7;
public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 };
public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 };
public static void DontAutoFlush() {
var a = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(a);
}
public static void Flush() { Console.Out.Flush(); }
public static T[] Sort<T>(T[] a) {
Array.Sort<T>(a);
return a;
}
public static T[] SortDecend<T>(T[] a) {
Array.Sort<T>(a);
Array.Reverse(a);
return a;
}
public static void Swap<T>(ref T a, ref T b) {
T c = a;
a = b;
b = c;
}
public static long GCD(long a, long b) {
while (b != 0) {
long c = a;
a = b;
b = c % b;
}
return a;
}
public static long LCM(long a, long b) {
if (a == 0 || b == 0)
return 0;
return a * b / GCD(a, b);
}
public static void ChMax(ref long a, long b) {
if (a < b)
a = b;
}
public static void ChMin(ref long a, long b) {
if (a > b)
a = b;
}
public static void ChMax(ref int a, int b) {
if (a < b)
a = b;
}
public static void ChMin(ref int a, int b) {
if (a > b)
a = b;
}
public static void FillArray<T>(T[] a, T b) {
int c = a.Length;
for (int d = 0; d < c; d++)
a[d] = b;
}
public static void FillArray<T>(T[,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
for (int e = 0; e < c; e++)
for (int f = 0; f < d; f++) {
a[e, f] = b;
}
}
public static void FillArray<T>(T[,,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
int e = a.GetLength(2);
for (int f = 0; f < c; f++)
for (int g = 0; g < d; g++) {
for (int h = 0; h < e; h++) {
a[f, g, h] = b;
}
}
}
public static long[] Accumulate(long[] a) {
long[] b = new long[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
public static double[] Accumulate(double[] a) {
double[] b = new double[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
}
public static class Cin {
public static int ri {
get { return ReadInt(); }
}
public static int[] ria {
get { return ReadIntArray(); }
}
public static long rl {
get { return ReadLong(); }
}
public static long[] rla {
get { return ReadLongArray(); }
}
public static double rd {
get { return ReadDouble(); }
}
public static double[] rda {
get { return ReadDoubleArray(); }
}
public static string rs {
get { return ReadString(); }
}
public static string[] rsa {
get { return ReadStringArray(); }
}
public static int ReadInt() { return int.Parse(i()); }
public static long ReadLong() { return long.Parse(i()); }
public static double ReadDouble() { return double.Parse(i()); }
public static string ReadString() { return i(); }
public static int[] ReadIntArray() {
g = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
public static long[] ReadLongArray() {
g = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
public static double[] ReadDoubleArray() {
g = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
}
public static string[] ReadStringArray() {
g = null;
return Console.ReadLine().Split(' ');
}
public static void ReadCol(out long[] a, long b) {
a = new long[b];
for (int c = 0; c < b; c++)
a[c] = ReadLong();
}
public static void ReadCols(out long[] a, out long[] b, long c) {
a = new long[c];
b = new long[c];
for (int d = 0; d < c; d++) {
a[d] = ReadLong();
b[d] = ReadLong();
}
}
public static void ReadCols(out long[] a, out long[] b, out long[] c,
long d) {
a = new long[d];
b = new long[d];
c = new long[d];
for (int e = 0; e < d; e++) {
a[e] = ReadLong();
b[e] = ReadLong();
c[e] = ReadLong();
}
}
public static int[,] ReadIntTable(int a, int b) {
g = null;
int[,] c = new int[a, b];
for (int d = 0; d < a; d++)
for (int e = 0; e < b; e++) {
c[d, e] = ReadInt();
}
return c;
}
public static long[,] ReadLongTable(long a, long b) {
g = null;
long[,] c = new long[a, b];
for (int d = 0; d < a; d++)
for (int e = 0; e < b; e++) {
c[d, e] = ReadLong();
}
return c;
}
public static char[,] ReadCharTable(int a, int b) {
g = null;
char[,] c = new char[a, b];
for (int d = 0; d < a; d++) {
var e = ReadString();
for (int f = 0; f < b; f++)
c[d, f] = e[f];
}
return c;
}
static string[] g;
static int h;
static string i() {
if (g == null || g.Length <= h) {
g = Console.ReadLine().Split(' ');
h = 0;
}
return g[h++];
}
}
}
}
|
[["-", 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, 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], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 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, 22], ["+", 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]]
| 8
| 3,906
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5 {
class Program {
static int[,] cost;
static int H;
static int W;
static int[,] s;
static void Main(string[] args) {
var S = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
H = S[0];
W = S[1];
//スタートから(x, y)までの最短距離
cost = new int[H, W];
//全ての白マスの数の合計
int white = 0;
//解答
int ans = -1;
//全ての要素を-1にする
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cost[i, j] = -1;
}
}
//全ての点の情報を記憶しておく
s = new int[H, W];
for (int i = 0; i < H; i++) {
string X = Console.ReadLine();
for (int j = 0; j < W; j++) {
s[i, j] = X[j];
if (X[j] == '.') {
white++; //ここで白マスをカウント
}
}
}
//最短距離
int min_cost = bfs();
//出力
if (min_cost == -1) {
ans = -1;
} else {
ans = white - (min_cost + 1);
}
Console.WriteLine(ans);
}
static int bfs() {
//移動可能なマスをループで簡単に列挙
int[] dx = { 0, 1, 0, -1 };
int[] dy = { 1, 0, -1, 0 };
//座標をpair(y, x)でもってqueueに入れる
Queue<Tuple<int, int>> que = null;
//スタートは(0, 0)
Tuple<int, int> inQueue = Tuple.Create(0, 0);
que.Enqueue(inQueue);
cost[0, 0] = 0;
//キューが空になるまで繰り返す
while (que.Count != 0) {
Tuple<int, int> p = que.Peek();
que.Dequeue();
//ゴールに到達したらcostを返す
if (p == Tuple.Create(H - 1, W - 1)) {
return cost[p.Item1, p.Item2];
}
//今の地点から、4方向に向かって調査する
for (int i = 0; i < 4; i++) {
//次のx座標とy座標
int ny = p.Item1 + dy[i];
int nx = p.Item2 + dx[i];
//エリア外に行ったら、次のループに入る
if (nx < 0 || ny < 0 || nx >= W || ny >= W) {
continue;
}
//壁にぶち当たったら、次のループに入る
if (s[ny, nx] == '#') {
continue;
}
//すでに探索済みだったら、次のループに入る
if (cost[ny, nx] != -1) {
continue;
}
cost[ny, nx] = cost[p.Item1, p.Item2] + 1;
Tuple<int, int> inQ = Tuple.Create(ny, nx);
que.Enqueue(inQ);
}
}
return -1;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5 {
class Program {
//スタートから(x, y)までの最短距離
static int[,] cost;
static int H;
static int W;
static int[,] s;
static void Main(string[] args) {
var S = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
H = S[0];
W = S[1];
cost = new int[H, W];
//全ての白マスの数の合計
int white = 0;
//解答
int ans = -1;
//全ての要素を-1にする
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cost[i, j] = -1;
}
}
//全ての点の情報を記憶しておく
s = new int[H, W];
for (int i = 0; i < H; i++) {
string X = Console.ReadLine();
for (int j = 0; j < W; j++) {
s[i, j] = X[j];
if (X[j] == '.') {
white++; //ここで白マスをカウント
}
}
}
//最短距離
int min_cost = bfs();
//出力
if (min_cost == -1) {
ans = -1;
} else {
ans = white - (min_cost + 1);
}
Console.WriteLine(ans);
}
static int bfs() {
//移動可能なマスをループで簡単に列挙
int[] dx = { 0, 1, 0, -1 };
int[] dy = { 1, 0, -1, 0 };
//座標をpair(y, x)でもってqueueに入れる
Queue<Tuple<int, int>> que = new Queue<Tuple<int, int>>();
//スタートは(0, 0)
Tuple<int, int> inQueue = Tuple.Create(0, 0);
que.Enqueue(inQueue);
cost[0, 0] = 0;
//キューが空になるまで繰り返す
while (que.Count != 0) {
Tuple<int, int> p = que.Peek();
que.Dequeue();
//ゴールに到達したらcostを返す
if (p.Item1 == H - 1 && p.Item2 == W - 1) {
return cost[p.Item1, p.Item2];
}
//今の地点から、4方向に向かって調査する
for (int i = 0; i < 4; i++) {
//次のx座標とy座標
int ny = p.Item1 + dy[i];
int nx = p.Item2 + dx[i];
//エリア外に行ったら、次のループに入る
if (nx < 0 || ny < 0 || nx >= W || ny >= H) {
continue;
}
//壁にぶち当たったら、次のループに入る
if (s[ny, nx] == '#') {
continue;
}
//すでに探索済みだったら、次のループに入る
if (cost[ny, nx] != -1) {
continue;
}
cost[ny, nx] = cost[p.Item1, p.Item2] + 1;
Tuple<int, int> inQ = Tuple.Create(ny, nx);
que.Enqueue(inQ);
}
}
return -1;
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 215], ["+", 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, 230, 39, 236, 237, 238, 0, 236, 141, 22], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 18], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 199], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 21], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 47], ["+", 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], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 21], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 604
| 28
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Competition {
class Program {
static int[] dx = { 1, 0, -1, 0 };
static int[] dy = { 0, 1, 0, -1 };
static int H, W;
static int sx, sy, gx, gy;
static string[] field = new string[55];
static long[,] d = new long[55, 55];
public static long bfs() {
Queue<Tuple<int, int>> que = new Queue<Tuple<int, int>>();
sx = sy = 0;
gx = W - 1;
gy = H - 1;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
d[i, j] = 1 << 29;
}
}
que.Enqueue(new Tuple<int, int>(sy, sx));
d[sy, sx] = 1;
while (que.Count() > 0) {
var p = que.Dequeue();
if (p.Item1 == gy && p.Item2 == gx)
break;
for (int i = 0; i < 4; i++) {
var ny = p.Item1 + dy[i];
var nx = p.Item2 + dx[i];
if (nx >= 0 && nx < W && ny >= 0 && ny < H && field[ny][nx] != '#' &&
d[ny, nx] == 1 << 29) {
que.Enqueue(new Tuple<int, int>(ny, nx));
d[ny, nx] = d[p.Item1, p.Item2] + 1;
}
}
}
return d[gy, gx];
}
static void Main(string[] args) {
var hw = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
H = hw[0];
W = hw[1];
for (int i = 0; i < H; i++) {
field[i] = Console.ReadLine();
}
var path = bfs();
var black = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (field[i][j] == '#')
black++;
}
}
Console.WriteLine(H * W - black - path);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Competition {
class Program {
static int[] dx = { 1, 0, -1, 0 };
static int[] dy = { 0, 1, 0, -1 };
static int H, W;
static int sx, sy, gx, gy;
static string[] field = new string[55];
static long[,] d = new long[55, 55];
public static long bfs() {
Queue<Tuple<int, int>> que = new Queue<Tuple<int, int>>();
sx = sy = 0;
gx = W - 1;
gy = H - 1;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
d[i, j] = 1 << 29;
}
}
que.Enqueue(new Tuple<int, int>(sy, sx));
d[sy, sx] = 1;
while (que.Count() > 0) {
var p = que.Dequeue();
if (p.Item1 == gy && p.Item2 == gx)
break;
for (int i = 0; i < 4; i++) {
var ny = p.Item1 + dy[i];
var nx = p.Item2 + dx[i];
if (nx >= 0 && nx < W && ny >= 0 && ny < H && field[ny][nx] != '#' &&
d[ny, nx] == 1 << 29) {
que.Enqueue(new Tuple<int, int>(ny, nx));
d[ny, nx] = d[p.Item1, p.Item2] + 1;
}
}
}
return d[gy, gx];
}
static void Main(string[] args) {
var hw = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
H = hw[0];
W = hw[1];
for (int i = 0; i < H; i++) {
field[i] = Console.ReadLine();
}
var path = bfs();
var black = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (field[i][j] == '#')
black++;
}
}
if (path == 1 << 29)
Console.WriteLine(-1);
else
Console.WriteLine(H * W - black - path);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 151], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 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, 57, 75, 1, 0, 213, 63, 214, 205, 22]]
| 8
| 539
| 17
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public struct coordinate {
public int y;
public int x;
}
static int[,] map = new int[50, 50];
static int[,] map2 = new int[50, 50];
static Queue<coordinate> que = new Queue<coordinate>();
static int R;
static int C;
public static void Main() {
string[] str = Console.ReadLine().Split(' ');
R = int.Parse(str[0]);
C = int.Parse(str[1]);
// str = Console.ReadLine().Split(' ');
var s = new coordinate();
s.y = 0; // int.Parse(str[0]) - 1;
s.x = 0; // int.Parse(str[1]) - 1;
// str = Console.ReadLine().Split(' ');
var g = new coordinate();
g.y = R - 1; // int.Parse(str[0]) - 1;
g.x = C - 1; // int.Parse(str[1]) - 1;
string str2 = "";
int whiteCount = 0;
for (int i = 0; i < R; i++) {
str2 = Console.ReadLine();
for (int j = 0; j < C; j++) {
if (str2[j] == '#')
map[i, j] = 1;
else {
map[i, j] = 0;
whiteCount++;
}
}
}
que.Enqueue(s);
while (que.Count() != 0) {
widthSearch(que.Dequeue());
}
Console.WriteLine(whiteCount - map2[g.y, g.x] - 1);
return;
}
public static void widthSearch(coordinate point) {
var nextPoint = new coordinate();
nextPoint.y = point.y + 1;
nextPoint.x = point.x;
check(point, nextPoint);
nextPoint.y = point.y - 1;
nextPoint.x = point.x;
check(point, nextPoint);
nextPoint.y = point.y;
nextPoint.x = point.x + 1;
check(point, nextPoint);
nextPoint.y = point.y;
nextPoint.x = point.x - 1;
check(point, nextPoint);
return;
}
public static void check(coordinate point, coordinate nextPoint) {
if (nextPoint.y < 0 || nextPoint.y >= R || nextPoint.x < 0 ||
nextPoint.x >= C) {
return;
}
if (map[nextPoint.y, nextPoint.x] == 0 &&
map2[nextPoint.y, nextPoint.x] == 0) {
map2[nextPoint.y, nextPoint.x] = map2[point.y, point.x] + 1;
que.Enqueue(nextPoint);
}
return;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public struct coordinate {
public int y;
public int x;
}
static int[,] map = new int[50, 50];
static int[,] map2 = new int[50, 50];
static Queue<coordinate> que = new Queue<coordinate>();
static int R;
static int C;
public static void Main() {
string[] str = Console.ReadLine().Split(' ');
R = int.Parse(str[0]);
C = int.Parse(str[1]);
// str = Console.ReadLine().Split(' ');
var s = new coordinate();
s.y = 0; // int.Parse(str[0]) - 1;
s.x = 0; // int.Parse(str[1]) - 1;
// str = Console.ReadLine().Split(' ');
var g = new coordinate();
g.y = R - 1; // int.Parse(str[0]) - 1;
g.x = C - 1; // int.Parse(str[1]) - 1;
string str2 = "";
int whiteCount = 0;
for (int i = 0; i < R; i++) {
str2 = Console.ReadLine();
for (int j = 0; j < C; j++) {
if (str2[j] == '#')
map[i, j] = 1;
else {
map[i, j] = 0;
whiteCount++;
}
}
}
que.Enqueue(s);
while (que.Count() != 0) {
widthSearch(que.Dequeue());
}
if (map2[g.y, g.x] != 0)
Console.WriteLine(whiteCount - map2[g.y, g.x] - 1);
else
Console.WriteLine("-1");
return;
}
public static void widthSearch(coordinate point) {
var nextPoint = new coordinate();
nextPoint.y = point.y + 1;
nextPoint.x = point.x;
check(point, nextPoint);
nextPoint.y = point.y - 1;
nextPoint.x = point.x;
check(point, nextPoint);
nextPoint.y = point.y;
nextPoint.x = point.x + 1;
check(point, nextPoint);
nextPoint.y = point.y;
nextPoint.x = point.x - 1;
check(point, nextPoint);
return;
}
public static void check(coordinate point, coordinate nextPoint) {
if (nextPoint.y < 0 || nextPoint.y >= R || nextPoint.x < 0 ||
nextPoint.x >= C) {
return;
}
if (map[nextPoint.y, nextPoint.x] == 0 &&
map2[nextPoint.y, nextPoint.x] == 0) {
map2[nextPoint.y, nextPoint.x] = map2[point.y, point.x] + 1;
que.Enqueue(nextPoint);
}
return;
}
}
|
[["+", 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, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 205, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 0, 131], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 21], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 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, 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, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 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]]
| 8
| 548
| 25
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1 {
class Program {
public static int[,] map = null;
public static int[,] marker = null;
public static int N = 0;
public static int W = 0;
public static int H = 0;
public static bool ret = false;
public static int count = 0;
public static List<Point> que = new List<Point>();
// チーズの硬さと座標
public static Dictionary<int, Point> goal_list = new Dictionary<int, Point>();
public static List<int> goal_root = new List<int>();
static void Main(string[] args) {
var data = new List<int>();
count = 0;
var sx = 0;
var sy = 0;
var s = Console.ReadLine().Split(' ');
H = int.Parse(s[0]);
W = int.Parse(s[1]);
map = new int[W, H];
marker = new int[W, H];
// マップ読み込み
for (int y = 0; y < H; y++) {
var tmp = Console.ReadLine();
for (int x = 0; x < tmp.Length; x++) {
map[x, y] = ('#' == tmp[x]) ? 0 : 1;
// 空白マスをカウント
count += ('.' == tmp[x]) ? 1 : 0;
}
}
var ex = W - 1;
var ey = H - 1;
que.Add(new Point(sx, sy));
// -1で初期化
for (int y = 0; y < H; y++)
for (int x = 0; x < W; x++)
marker[x, y] = -1;
marker[sx, sy] = 0;
while (0 < que.Count) {
var x = que[0].X;
var y = que[0].Y;
// ゴールに到達していたら終了
if (x == ex && y == ey)
break;
AddQue(x, y);
que.RemoveAt(0);
}
// 空白マス数から最短経路の距離を引いたマスだけ塗り潰せる(始点をマイナス1)
count = count - marker[ex, ey] - 1;
// 塗り潰せない場合は-1を出力
if (count <= 0)
count = -1;
Console.WriteLine(count);
Console.Read();
}
public static void AddQue(int x, int y) {
var distance = marker[x, y];
Search(x + 1, y, distance + 1);
Search(x - 1, y, distance + 1);
Search(x, y + 1, distance + 1);
Search(x, y - 1, distance + 1);
}
public static bool Search(int x, int y, int distance) {
if (x < 0 || y < 0 || W <= x || H <= y || -1 != marker[x, y] ||
1 != map[x, y])
return false;
marker[x, y] = distance;
que.Add(new Point(x, y));
return true;
}
}
public class Point {
public int X { get; set; } = 0;
public int Y { get; set; } = 0;
public Point() {}
public Point(int x, int y) {
X = x;
Y = y;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1 {
class Program {
public static int[,] map = null;
public static int[,] marker = null;
public static int N = 0;
public static int W = 0;
public static int H = 0;
public static bool ret = false;
public static int count = 0;
public static List<Point> que = new List<Point>();
// チーズの硬さと座標
public static Dictionary<int, Point> goal_list = new Dictionary<int, Point>();
public static List<int> goal_root = new List<int>();
static void Main(string[] args) {
var data = new List<int>();
count = 0;
var sx = 0;
var sy = 0;
var s = Console.ReadLine().Split(' ');
H = int.Parse(s[0]);
W = int.Parse(s[1]);
map = new int[W, H];
marker = new int[W, H];
// マップ読み込み
for (int y = 0; y < H; y++) {
var tmp = Console.ReadLine();
for (int x = 0; x < tmp.Length; x++) {
map[x, y] = ('#' == tmp[x]) ? 0 : 1;
// 空白マスをカウント
count += ('.' == tmp[x]) ? 1 : 0;
}
}
var ex = W - 1;
var ey = H - 1;
que.Add(new Point(sx, sy));
// -1で初期化
for (int y = 0; y < H; y++)
for (int x = 0; x < W; x++)
marker[x, y] = -1;
marker[sx, sy] = 0;
var ret = false;
while (0 < que.Count) {
var x = que[0].X;
var y = que[0].Y;
// ゴールに到達していたら終了
if (x == ex && y == ey) {
ret = true;
break;
}
AddQue(x, y);
que.RemoveAt(0);
}
// 空白マス数から最短経路の距離を引いたマスだけ塗り潰せる(始点をマイナス1)
count = count - marker[ex, ey] - 1;
// 塗り潰せない場合は0を出力
if (count <= 0)
count = 0;
// そもそもゴールに到達していなかったら-1
if (!ret)
count = -1;
Console.WriteLine(count);
Console.Read();
}
public static void AddQue(int x, int y) {
var distance = marker[x, y];
Search(x + 1, y, distance + 1);
Search(x - 1, y, distance + 1);
Search(x, y + 1, distance + 1);
Search(x, y - 1, distance + 1);
}
public static bool Search(int x, int y, int distance) {
if (x < 0 || y < 0 || W <= x || H <= y || -1 != marker[x, y] ||
1 != map[x, y])
return false;
marker[x, y] = distance;
que.Add(new Point(x, y));
return true;
}
}
public class Point {
public int X { get; set; } = 0;
public int Y { get; set; } = 0;
public Point() {}
public Point(int x, int y) {
X = x;
Y = y;
}
}
}
|
[["+", 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, 211, 0, 147], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 52, 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, 211, 0, 146], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 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], ["+", 0, 195, 8, 196, 0, 57, 15, 241, 0, 111], ["+", 0, 195, 8, 196, 0, 57, 15, 241, 0, 22]]
| 8
| 704
| 20
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace ABC088D {
class Program {
static void Solve(Input input) {
var h = input.NextInt();
var w = input.NextInt();
var map = new char[h, w];
// 最初から黒のマス
var oblack = 0;
for (int i = 0; i < h; i++) {
var s = input.Next();
for (int j = 0; j < w; j++) {
map[i, j] = s[j];
if (s[j] == '#')
oblack++;
}
}
// 最短経路と始点・終点以外は塗りつぶしてよい
var sp = dfs(map, h, w);
Console.WriteLine(h * w - sp - 1 - oblack);
}
static readonly int[] dx = { 1, 0, -1, 0 };
static readonly int[] dy = { 0, 1, 0, -1 };
static int dfs(char[,] map, int h, int w) {
var cost = Utils.Create2DArray(h, w, int.MaxValue / 5);
cost[0][0] = 0;
var q = new Queue<Tuple<int, int>>();
q.Enqueue(new Tuple<int, int>(0, 0));
while (q.Any()) {
var v = q.Dequeue();
for (int i = 0; i < 4; i++) {
var nx = v.Item1 + dx[i];
var ny = v.Item2 + dy[i];
if (nx < 0 || nx >= w || ny < 0 || ny >= h)
continue;
if (map[ny, nx] == '#')
continue;
if (cost[v.Item2][v.Item1] + 1 < cost[ny][nx]) {
cost[ny][nx] = cost[v.Item2][v.Item1] + 1;
q.Enqueue(new Tuple<int, int>(nx, ny));
}
}
}
return cost[h - 1][w - 1];
}
#region Main
public static void Main(string[] args) {
// 出力が少ないときはこれをセットする方が時間かかるけれど
// その場合は出力がボトルネックになっていないので、まあ良しとする
var needsFlushOutput = true;
if (needsFlushOutput) {
// 細かく出力しないようにする
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
// 通常は引数無しで、ファイルから読み出したい場合はpath指定する
var input = new Input();
// 仮想的に標準入力をセットする
// input.SetText("");
Solve(input);
Console.Out.Flush();
}
#endregion
#region Competitive Template
#pragma warning disable CS0414
static readonly int MOD = (int)1e9 + 7;
#pragma warning restore CS0414
class Input {
// 変な改行コードがたまに混じっているので、一応セパレート指定する
// スペース単独指定の方がもちろん早い
static readonly char[] separator = { ' ', '\r', '\n' };
Queue<string> q { get; set; }
StreamReader sr;
/// <summary>
/// 特定のファイルから読み出したい場合はpath指定する
/// </summary>
/// <param name="path"></param>
public Input(string path = "") {
q = new Queue<string>();
if (string.IsNullOrEmpty(path)) {
sr = new StreamReader(Console.OpenStandardInput());
} else {
sr = new StreamReader(path);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
bool read() {
var s = sr.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public string Next() {
if (!q.Any()) {
if (!read()) {
return "";
}
}
return q.Dequeue();
}
/// <summary>
/// 指定個数queueにたまるまでenqueueし続ける
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
bool accumulate(int n) {
while (q.Count() < n) {
if (!read())
return false;
}
return true;
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
/// <summary>
/// n個の要素をparseして、それぞれにoffsetをaddした配列を返す
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="n"></param>
/// <param name="offset"></param>
/// <param name="parse"></param>
/// <param name="add"></param>
/// <returns></returns>
T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) {
if (!accumulate(n))
return null;
var a = new T[n];
for (int i = 0; i < n; i++)
a[i] = add(parse(q.Dequeue()), offset);
return a;
}
public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x);
public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse,
(x, y) => x + y);
public long[] NextLong(int n, long offset = 0) => NextT(n, offset,
long.Parse,
(x, y) => x + y);
public double[] NextDouble(int n, double offset = 0.0) =>
NextT(n, offset, double.Parse, (x, y) => x + y);
}
static class Utils {
public static void Print<T>(IEnumerable<T> ie, string sep = " ") =>
Console.WriteLine(string.Join(sep, ie));
public static void Print<T>(params T[] objs) => Print(objs);
public static T Max<T>(params T[] objs) => objs.Max();
public static T Min<T>(params T[] objs) => objs.Min();
public static void Swap<T>(ref T x, ref T y)
where T : struct {
var t = x;
x = y;
y = t;
}
public static void Swap<T>(IList<T> list, int i, int j)
where T : struct {
var t = list[i];
list[i] = list[j];
list[j] = t;
}
/// <summary>
/// vでfillされたT[d1][d2]配列を作成する
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="d1"></param>
/// <param name="d2"></param>
/// <param name="v"></param>
/// <returns></returns>
public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) {
return Enumerable.Repeat(0, d1)
.Select(_ => Enumerable.Repeat(v, d2).ToArray())
.ToArray();
}
/// <summary>
/// vでfillされたT[d1][d2][d3]配列を作成する
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="d1"></param>
/// <param name="d2"></param>
/// <param name="d3"></param>
/// <param name="v"></param>
/// <returns></returns>
public static T[][][] Create3DArray<T>(int d1, int d2, int d3,
T v = default(T)) {
return Enumerable.Repeat(0, d1)
.Select(_ => Enumerable.Repeat(0, d2)
.Select(__ => Enumerable.Repeat(v, d3).ToArray())
.ToArray())
.ToArray();
}
}
#endregion
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace ABC088D {
class Program {
static void Solve(Input input) {
var h = input.NextInt();
var w = input.NextInt();
var map = new char[h, w];
// 最初から黒のマス
var oblack = 0;
for (int i = 0; i < h; i++) {
var s = input.Next();
for (int j = 0; j < w; j++) {
map[i, j] = s[j];
if (s[j] == '#')
oblack++;
}
}
// 最短経路と始点・終点以外は塗りつぶしてよい
var sp = dfs(map, h, w);
if (sp == int.MaxValue / 5) {
Console.WriteLine(-1);
} else {
Console.WriteLine(h * w - sp - 1 - oblack);
}
}
static readonly int[] dx = { 1, 0, -1, 0 };
static readonly int[] dy = { 0, 1, 0, -1 };
static int dfs(char[,] map, int h, int w) {
var cost = Utils.Create2DArray(h, w, int.MaxValue / 5);
cost[0][0] = 0;
var q = new Queue<Tuple<int, int>>();
q.Enqueue(new Tuple<int, int>(0, 0));
while (q.Any()) {
var v = q.Dequeue();
for (int i = 0; i < 4; i++) {
var nx = v.Item1 + dx[i];
var ny = v.Item2 + dy[i];
if (nx < 0 || nx >= w || ny < 0 || ny >= h)
continue;
if (map[ny, nx] == '#')
continue;
if (cost[v.Item2][v.Item1] + 1 < cost[ny][nx]) {
cost[ny][nx] = cost[v.Item2][v.Item1] + 1;
q.Enqueue(new Tuple<int, int>(nx, ny));
}
}
}
return cost[h - 1][w - 1];
}
#region Main
public static void Main(string[] args) {
// 出力が少ないときはこれをセットする方が時間かかるけれど
// その場合は出力がボトルネックになっていないので、まあ良しとする
var needsFlushOutput = true;
if (needsFlushOutput) {
// 細かく出力しないようにする
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
// 通常は引数無しで、ファイルから読み出したい場合はpath指定する
var input = new Input();
// 仮想的に標準入力をセットする
// input.SetText("");
Solve(input);
Console.Out.Flush();
}
#endregion
#region Competitive Template
#pragma warning disable CS0414
static readonly int MOD = (int)1e9 + 7;
#pragma warning restore CS0414
class Input {
// 変な改行コードがたまに混じっているので、一応セパレート指定する
// スペース単独指定の方がもちろん早い
static readonly char[] separator = { ' ', '\r', '\n' };
Queue<string> q { get; set; }
StreamReader sr;
/// <summary>
/// 特定のファイルから読み出したい場合はpath指定する
/// </summary>
/// <param name="path"></param>
public Input(string path = "") {
q = new Queue<string>();
if (string.IsNullOrEmpty(path)) {
sr = new StreamReader(Console.OpenStandardInput());
} else {
sr = new StreamReader(path);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
bool read() {
var s = sr.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public string Next() {
if (!q.Any()) {
if (!read()) {
return "";
}
}
return q.Dequeue();
}
/// <summary>
/// 指定個数queueにたまるまでenqueueし続ける
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
bool accumulate(int n) {
while (q.Count() < n) {
if (!read())
return false;
}
return true;
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
/// <summary>
/// n個の要素をparseして、それぞれにoffsetをaddした配列を返す
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="n"></param>
/// <param name="offset"></param>
/// <param name="parse"></param>
/// <param name="add"></param>
/// <returns></returns>
T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) {
if (!accumulate(n))
return null;
var a = new T[n];
for (int i = 0; i < n; i++)
a[i] = add(parse(q.Dequeue()), offset);
return a;
}
public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x);
public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse,
(x, y) => x + y);
public long[] NextLong(int n, long offset = 0) => NextT(n, offset,
long.Parse,
(x, y) => x + y);
public double[] NextDouble(int n, double offset = 0.0) =>
NextT(n, offset, double.Parse, (x, y) => x + y);
}
static class Utils {
public static void Print<T>(IEnumerable<T> ie, string sep = " ") =>
Console.WriteLine(string.Join(sep, ie));
public static void Print<T>(params T[] objs) => Print(objs);
public static T Max<T>(params T[] objs) => objs.Max();
public static T Min<T>(params T[] objs) => objs.Min();
public static void Swap<T>(ref T x, ref T y)
where T : struct {
var t = x;
x = y;
y = t;
}
public static void Swap<T>(IList<T> list, int i, int j)
where T : struct {
var t = list[i];
list[i] = list[j];
list[j] = t;
}
/// <summary>
/// vでfillされたT[d1][d2]配列を作成する
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="d1"></param>
/// <param name="d2"></param>
/// <param name="v"></param>
/// <returns></returns>
public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) {
return Enumerable.Repeat(0, d1)
.Select(_ => Enumerable.Repeat(v, d2).ToArray())
.ToArray();
}
/// <summary>
/// vでfillされたT[d1][d2][d3]配列を作成する
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="d1"></param>
/// <param name="d2"></param>
/// <param name="d3"></param>
/// <param name="v"></param>
/// <returns></returns>
public static T[][][] Create3DArray<T>(int d1, int d2, int d3,
T v = default(T)) {
return Enumerable.Repeat(0, d1)
.Select(_ => Enumerable.Repeat(0, d2)
.Select(__ => Enumerable.Repeat(v, d3).ToArray())
.ToArray())
.ToArray();
}
}
#endregion
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 205, 199], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 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, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 1,548
| 23
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
//幅優先探索
class Program {
static List<int[]> Nexts = new List<int[]>() {
new int[2] { 0, 1 },
new int[2] { 0, -1 },
new int[2] { 1, 0 },
new int[2] { -1, 0 },
};
static List<List<BlockClass>> Maze = new List<List<BlockClass>>();
static List<BlockClass> Queue = new List<BlockClass>();
static int counter = 0;
static void Main(string[] args) {
int[] hw = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
List<BlockClass> list0 = new List<BlockClass>();
Maze.Add(list0);
for (int i = 0; i < hw[1] + 2; i++) {
BlockClass tmpBlock = new BlockClass();
list0.Add(tmpBlock);
tmpBlock.x = 0;
tmpBlock.y = i;
tmpBlock.isRoad = false;
}
for (int i = 1; i <= hw[0]; i++) {
List<BlockClass> tmpList = new List<BlockClass>();
Maze.Add(tmpList);
string line = Console.ReadLine();
line = "#" + line + "#";
for (int j = 0; j <= hw[1] + 1; j++) {
BlockClass tmpBlock = new BlockClass();
tmpList.Add(tmpBlock);
tmpBlock.x = i;
tmpBlock.y = j;
if (line[j] == '.') {
tmpBlock.isRoad = true;
counter++;
} else
tmpBlock.isRoad = false;
}
}
List<BlockClass> listlist = new List<BlockClass>();
Maze.Add(listlist);
for (int i = 0; i < hw[1] + 2; i++) {
BlockClass tmpBlock = new BlockClass();
listlist.Add(tmpBlock);
tmpBlock.x = hw[0] + 1;
tmpBlock.y = i;
tmpBlock.isRoad = false;
}
Maze[hw[0]][hw[1]].isGoal = true;
Maze[1][1].Min = 0;
Queue.Add(Maze[1][1]);
BFS(1, 1);
Console.WriteLine(counter - Maze[hw[0]][hw[1]].Min - 1);
;
//
}
static void BFS(int x, int y) {
Queue.RemoveAt(0);
foreach (int[] Next in Nexts) {
//壁ならコンテ
if (!Maze[x + Next[0]][y + Next[1]].isRoad)
continue;
//来たことあったらコンテ
if (Maze[x + Next[0]][y + Next[1]].Min != -1)
continue;
//
Maze[x + Next[0]][y + Next[1]].Min = Maze[x][y].Min + 1;
Queue.Add(Maze[x + Next[0]][y + Next[1]]);
}
if (Queue.Count == 0) {
return;
}
BFS(Queue[0].x, Queue[0].y);
}
}
public class BlockClass {
public int x;
public int y;
public int Min = -1;
public bool isRoad;
public bool isGoal;
public BlockClass() {}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
//幅優先探索
class Program {
static List<int[]> Nexts = new List<int[]>() {
new int[2] { 0, 1 },
new int[2] { 0, -1 },
new int[2] { 1, 0 },
new int[2] { -1, 0 },
};
static List<List<BlockClass>> Maze = new List<List<BlockClass>>();
static List<BlockClass> Queue = new List<BlockClass>();
static int counter = 0;
static void Main(string[] args) {
int[] hw = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
List<BlockClass> list0 = new List<BlockClass>();
Maze.Add(list0);
for (int i = 0; i < hw[1] + 2; i++) {
BlockClass tmpBlock = new BlockClass();
list0.Add(tmpBlock);
tmpBlock.x = 0;
tmpBlock.y = i;
tmpBlock.isRoad = false;
}
for (int i = 1; i <= hw[0]; i++) {
List<BlockClass> tmpList = new List<BlockClass>();
Maze.Add(tmpList);
string line = Console.ReadLine();
line = "#" + line + "#";
for (int j = 0; j <= hw[1] + 1; j++) {
BlockClass tmpBlock = new BlockClass();
tmpList.Add(tmpBlock);
tmpBlock.x = i;
tmpBlock.y = j;
if (line[j] == '.') {
tmpBlock.isRoad = true;
counter++;
} else
tmpBlock.isRoad = false;
}
}
List<BlockClass> listlist = new List<BlockClass>();
Maze.Add(listlist);
for (int i = 0; i < hw[1] + 2; i++) {
BlockClass tmpBlock = new BlockClass();
listlist.Add(tmpBlock);
tmpBlock.x = hw[0] + 1;
tmpBlock.y = i;
tmpBlock.isRoad = false;
}
Maze[hw[0]][hw[1]].isGoal = true;
Maze[1][1].Min = 0;
Queue.Add(Maze[1][1]);
BFS(1, 1);
if (Maze[hw[0]][hw[1]].Min == -1) {
Console.WriteLine(-1);
} else {
Console.WriteLine(counter - Maze[hw[0]][hw[1]].Min - 1);
}
//
}
static void BFS(int x, int y) {
Queue.RemoveAt(0);
foreach (int[] Next in Nexts) {
//壁ならコンテ
if (!Maze[x + Next[0]][y + Next[1]].isRoad)
continue;
//来たことあったらコンテ
if (Maze[x + Next[0]][y + Next[1]].Min != -1)
continue;
//
Maze[x + Next[0]][y + Next[1]].Min = Maze[x][y].Min + 1;
Queue.Add(Maze[x + Next[0]][y + Next[1]]);
}
if (Queue.Count == 0) {
return;
}
BFS(Queue[0].x, Queue[0].y);
}
}
public class BlockClass {
public int x;
public int y;
public int Min = -1;
public bool isRoad;
public bool isGoal;
public BlockClass() {}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 15, 16, 31, 214, 205, 204, 205, 204, 205, 22], ["+", 31, 214, 205, 204, 205, 204, 206, 207, 0, 70], ["+", 205, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 31, 214, 205, 204, 205, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 214, 205, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 214, 205, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 8, 201, 0, 195, 8, 196, 0, 260, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 746
| 35
|
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int Int() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long Long() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
}
class Program {
static Scanner cin = new Scanner();
struct p {
public int x, y;
public p(int X, int Y) {
x = X;
y = Y;
}
}
static void Main() {
int H = cin.Int();
int W = cin.Int();
var S = Enumerable.Repeat(0, H).Select(_ => Console.ReadLine()).ToArray();
var dx = new int[] { -1, 1, 0, 0 };
var dy = new int[] { 0, 0, -1, 1 };
var que = new Queue<p>();
var cnt = new int[H, W];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cnt[i, j] = -1;
}
}
cnt[0, 0] = 1;
que.Enqueue(new p(0, 0));
while (que.Count > 0) {
p tmp = que.Dequeue();
int nx = tmp.x;
int ny = tmp.y;
if (ny == H - 1 && nx == W - 1)
break;
for (int i = 0; i < 4; i++) {
if (0 <= ny + dy[i] && ny + dy[i] < H && 0 <= nx + dx[i] &&
nx + dx[i] < W) {
if (S[ny + dy[i]][nx + dx[i]] != '#' &&
cnt[ny + dy[i], nx + dx[i]] == -1) {
que.Enqueue(new p(nx + dx[i], ny + dy[i]));
cnt[ny + dy[i], nx + dx[i]] = cnt[ny, nx] + 1;
}
}
}
}
if (que.Count == 0) {
Console.WriteLine(-1);
return;
}
int black = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (S[i][j] == '#')
black++;
}
}
Console.WriteLine(H * W - black - cnt[H - 1, W - 1]);
Console.ReadLine();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int Int() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long Long() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
}
class Program {
static Scanner cin = new Scanner();
struct p {
public int x, y;
public p(int X, int Y) {
x = X;
y = Y;
}
}
static void Main() {
int H = cin.Int();
int W = cin.Int();
var S = Enumerable.Repeat(0, H).Select(_ => Console.ReadLine()).ToArray();
var dx = new int[] { -1, 1, 0, 0 };
var dy = new int[] { 0, 0, -1, 1 };
var que = new Queue<p>();
var cnt = new int[H, W];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cnt[i, j] = -1;
}
}
cnt[0, 0] = 1;
que.Enqueue(new p(0, 0));
while (que.Count > 0) {
p tmp = que.Dequeue();
int nx = tmp.x;
int ny = tmp.y;
if (ny == H - 1 && nx == W - 1)
break;
for (int i = 0; i < 4; i++) {
if (0 <= ny + dy[i] && ny + dy[i] < H && 0 <= nx + dx[i] &&
nx + dx[i] < W) {
if (S[ny + dy[i]][nx + dx[i]] != '#' &&
cnt[ny + dy[i], nx + dx[i]] == -1) {
que.Enqueue(new p(nx + dx[i], ny + dy[i]));
cnt[ny + dy[i], nx + dx[i]] = cnt[ny, nx] + 1;
}
}
}
}
if (cnt[H - 1, W - 1] == -1)
Console.WriteLine(-1);
else {
int black = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (S[i][j] == '#')
black++;
}
}
Console.WriteLine(H * W - black - cnt[H - 1, W - 1]);
}
Console.ReadLine();
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 21], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["-", 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, 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, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 809
| 23
|
using System;
using System.Linq;
class Procon {
public Procon() {}
static void Main(string[] agrs) { new Procon().Do(); }
Scanner cin;
public bool Check(bool[,] b, int[,] dp, int H, int W, int i, int j) {
if (i < 0 || H <= i) {
return false;
}
if (j < 0 || W <= j) {
return false;
}
if (dp[i, j] < 0) {
return false;
}
if (b[i, j] == true) {
return false;
}
return true;
}
public void Do() {
cin = new Scanner();
int H = cin.nextInt();
int W = cin.nextInt();
bool[,] b = new bool[H, W];
int cnt = 0;
for (int i = 0; i < H; i++) {
string tmp = cin.nextString();
for (int j = 0; j < W; j++) {
if (tmp[j] == '.') {
b[i, j] = false;
} else {
b[i, j] = true;
cnt++;
}
}
}
int[,] dp = new int[H, W];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
dp[i, j] = -1;
}
}
dp[0, 0] = 1;
for (int k = 0; k < H * W; k++) {
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (b[i, j]) {
continue;
}
if (Check(b, dp, H, W, i, j - 1)) {
int tmp = dp[i, j - 1] + 1;
if (tmp < dp[i, j] || dp[i, j] == -1) {
dp[i, j] = tmp;
}
}
if (Check(b, dp, H, W, i, j + 1)) {
int tmp = dp[i, j + 1] + 1;
if (tmp < dp[i, j] || dp[i, j] == -1) {
dp[i, j] = tmp;
}
}
if (Check(b, dp, H, W, i - 1, j)) {
int tmp = dp[i - 1, j] + 1;
if (tmp < dp[i, j] || dp[i, j] == -1) {
dp[i, j] = tmp;
}
}
if (Check(b, dp, H, W, i + 1, j)) {
int tmp = dp[i + 1, j] + 1;
if (tmp < dp[i, j] || dp[i, j] == -1) {
dp[i, j] = tmp;
}
}
}
}
}
Console.WriteLine(H * W - dp[H - 1, W - 1] - cnt);
}
}
class Scanner {
string[] s;
int i;
int max_i;
public Scanner() {
s = new string[0];
max_i = 0;
i = 0;
}
public string nextString() {
if (i >= s.Length) {
s = Console.ReadLine().Split(' ');
max_i = s.Length;
i = 0;
if (max_i == 0) {
return "";
}
return s[i++];
} else {
return s[i++];
}
}
public int nextInt() { return int.Parse(nextString()); }
public long nextLong() { return long.Parse(nextString()); }
public double nextDouble() { return double.Parse(nextString()); }
public string[] arrayString() { return Console.ReadLine().Split(' '); }
public int[] arrayInt() {
string[] str = Console.ReadLine().Split(' ');
int[] array = new int[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = int.Parse(str[i]);
}
return array;
}
public long[] arrayLong() {
string[] str = Console.ReadLine().Split(' ');
long[] array = new long[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = long.Parse(str[i]);
}
return array;
}
public double[] arrayDouble() {
string[] str = Console.ReadLine().Split(' ');
double[] array = new double[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = double.Parse(str[i]);
}
return array;
}
}
|
using System;
using System.Linq;
class Procon {
public Procon() {}
static void Main(string[] agrs) { new Procon().Do(); }
Scanner cin;
public bool Check(bool[,] b, int[,] dp, int H, int W, int i, int j) {
if (i < 0 || H <= i) {
return false;
}
if (j < 0 || W <= j) {
return false;
}
if (dp[i, j] < 0) {
return false;
}
if (b[i, j] == true) {
return false;
}
return true;
}
public void Do() {
cin = new Scanner();
int H = cin.nextInt();
int W = cin.nextInt();
bool[,] b = new bool[H, W];
int cnt = 0;
for (int i = 0; i < H; i++) {
string tmp = cin.nextString();
for (int j = 0; j < W; j++) {
if (tmp[j] == '.') {
b[i, j] = false;
} else {
b[i, j] = true;
cnt++;
}
}
}
int[,] dp = new int[H, W];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
dp[i, j] = -1;
}
}
dp[0, 0] = 1;
for (int k = 0; k < H * W; k++) {
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (b[i, j]) {
continue;
}
if (Check(b, dp, H, W, i, j - 1)) {
int tmp = dp[i, j - 1] + 1;
if (tmp < dp[i, j] || dp[i, j] == -1) {
dp[i, j] = tmp;
}
}
if (Check(b, dp, H, W, i, j + 1)) {
int tmp = dp[i, j + 1] + 1;
if (tmp < dp[i, j] || dp[i, j] == -1) {
dp[i, j] = tmp;
}
}
if (Check(b, dp, H, W, i - 1, j)) {
int tmp = dp[i - 1, j] + 1;
if (tmp < dp[i, j] || dp[i, j] == -1) {
dp[i, j] = tmp;
}
}
if (Check(b, dp, H, W, i + 1, j)) {
int tmp = dp[i + 1, j] + 1;
if (tmp < dp[i, j] || dp[i, j] == -1) {
dp[i, j] = tmp;
}
}
}
}
}
if (dp[H - 1, W - 1] < 0) {
Console.WriteLine(-1);
return;
}
Console.WriteLine(H * W - dp[H - 1, W - 1] - cnt);
}
}
class Scanner {
string[] s;
int i;
int max_i;
public Scanner() {
s = new string[0];
max_i = 0;
i = 0;
}
public string nextString() {
if (i >= s.Length) {
s = Console.ReadLine().Split(' ');
max_i = s.Length;
i = 0;
if (max_i == 0) {
return "";
}
return s[i++];
} else {
return s[i++];
}
}
public int nextInt() { return int.Parse(nextString()); }
public long nextLong() { return long.Parse(nextString()); }
public double nextDouble() { return double.Parse(nextString()); }
public string[] arrayString() { return Console.ReadLine().Split(' '); }
public int[] arrayInt() {
string[] str = Console.ReadLine().Split(' ');
int[] array = new int[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = int.Parse(str[i]);
}
return array;
}
public long[] arrayLong() {
string[] str = Console.ReadLine().Split(' ');
long[] array = new long[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = long.Parse(str[i]);
}
return array;
}
public double[] arrayDouble() {
string[] str = Console.ReadLine().Split(' ');
double[] array = new double[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = double.Parse(str[i]);
}
return array;
}
}
|
[["+", 8, 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, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 21], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 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, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22]]
| 8
| 1,093
| 27
|
using System;
using System.Collections.Generic;
class Program {
static long[] s;
static string[] arr;
static int[,] h;
static List<int[]> li = new List<int[]>();
static void Main() {
s = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
arr = new string[s[0]];
h = new int[s[0], s[1]];
int ans = 0;
for (int i = 0; i < s[0]; i++) {
string q = Console.ReadLine();
for (int j = 0; j < s[1]; j++) {
if (q[j] == '.') {
ans++;
} else {
h[i, j] = -1;
}
}
}
h[0, 0] = 1;
li.Add(new int[] { 0, 0 });
while (li[0][0] != s[0] - 1 || li[0][1] != s[1] - 1) {
if (li[0][0] != 0) {
fu(li[0][0] - 1, li[0][1], h[li[0][0], li[0][1]] + 1);
}
if (li[0][1] != 0) {
fu(li[0][0], li[0][1] - 1, h[li[0][0], li[0][1]] + 1);
}
if (li[0][0] != s[0] - 1) {
fu(li[0][0] + 1, li[0][1], h[li[0][0], li[0][1]] + 1);
}
if (li[0][1] != s[1] - 1) {
fu(li[0][0], li[0][1] + 1, h[li[0][0], li[0][1]] + 1);
}
li.RemoveAt(0);
}
Console.WriteLine("{0}", ans - h[s[0] - 1, s[1] - 1]);
}
static void fu(int x, int y, int p) {
if (h[x, y] == 0) {
h[x, y] = p;
li.Add(new int[] { x, y });
}
}
}
|
using System;
using System.Collections.Generic;
class Program {
static long[] s;
static int[,] h;
static List<int[]> li = new List<int[]>();
static void Main() {
s = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
h = new int[s[0], s[1]];
int ans = 0;
for (int i = 0; i < s[0]; i++) {
string q = Console.ReadLine();
for (int j = 0; j < s[1]; j++) {
if (q[j] == '.') {
ans++;
} else {
h[i, j] = -1;
}
}
}
h[0, 0] = 1;
li.Add(new int[] { 0, 0 });
while (li[0][0] != s[0] - 1 || li[0][1] != s[1] - 1) {
if (li[0][0] != 0) {
fu(li[0][0] - 1, li[0][1], h[li[0][0], li[0][1]] + 1);
}
if (li[0][1] != 0) {
fu(li[0][0], li[0][1] - 1, h[li[0][0], li[0][1]] + 1);
}
if (li[0][0] != s[0] - 1) {
fu(li[0][0] + 1, li[0][1], h[li[0][0], li[0][1]] + 1);
}
if (li[0][1] != s[1] - 1) {
fu(li[0][0], li[0][1] + 1, h[li[0][0], li[0][1]] + 1);
}
li.RemoveAt(0);
if (li.Count == 0) {
break;
}
}
Console.WriteLine("{0}", li.Count == 0 ? -1 : ans - h[s[0] - 1, s[1] - 1]);
}
static void fu(int x, int y, int p) {
if (h[x, y] == 0) {
h[x, y] = p;
li.Add(new int[] { x, y });
}
}
}
|
[["-", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["-", 0, 124, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 124, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 0, 208, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 235, 8, 201, 0, 124, 0, 251, 0, 115], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 227, 0, 228], ["-", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199], ["-", 0, 11, 12, 227, 39, 224, 225, 226, 0, 70], ["-", 12, 227, 39, 224, 225, 226, 0, 204, 205, 22], ["-", 39, 224, 225, 226, 0, 204, 206, 207, 0, 70], ["-", 225, 226, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 39, 224, 225, 226, 0, 204, 206, 207, 0, 73], ["-", 0, 11, 12, 227, 39, 224, 225, 226, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 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, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 28, 0, 41, 15, 16, 31, 214, 205, 22], ["+", 0, 28, 0, 41, 15, 16, 31, 214, 0, 131], ["+", 0, 28, 0, 41, 15, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 241, 0, 33], ["+", 3, 4, 0, 28, 0, 41, 64, 241, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102]]
| 8
| 567
| 38
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace ConsoleApplication {
class MainClass {
////////////////////////////////////////////////////////////////////////////////
int H, W;
string[] s;
struct Point {
public int Y;
public int X;
public Point(int y, int x) {
Y = y;
X = x;
}
}
int[] dy = new int[] { 0, 1, 0, -1 };
int[] dx = new int[] { 1, 0, -1, 0 };
void Solve() {
io.i(out H, out W);
io.ini(out s, H);
var que = new Queue<Point>();
que.Enqueue(new Point(0, 0));
var costs = new int[H, W];
costs.Set(-1);
costs[0, 0] = 1;
while (que.Count > 0) {
var cur = que.Dequeue();
var cy = cur.Y;
var cx = cur.X;
if (cy == H - 1 && cx == W - 1)
break;
4.REP(i => {
var ny = cy + dy[i];
var nx = cx + dx[i];
if (0 <= ny && ny < H && 0 <= nx && nx < W && costs[ny, nx] == -1 &&
s[ny][nx] == '.') {
costs[ny, nx] = costs[cy, cx] + 1;
que.Enqueue(new Point(ny, nx));
}
});
}
var minCost = costs[H - 1, W - 1];
var whiteSum = 0;
H.REP(i => W.REP(j => {
if (s[i][j] == '.')
whiteSum++;
}));
io.o(whiteSum - minCost);
}
////////////////////////////////////////////////////////////////////////////////
public static void Main() => new MainClass().Stream();
IO io = new IO();
void Stream() {
Solve();
// Test();
io.Flush();
}
void Test() {}
}
#region Default
class IO {
#region INPUT
int _buffCnt;
string[] _nextBuff;
private readonly char[] _splitCharacter = new char[] { ' ' };
private readonly StreamWriter _sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
_nextBuff = new string[0];
_buffCnt = 0;
Console.SetOut(_sw);
}
private string Next() {
if (_buffCnt < _nextBuff.Length)
return _nextBuff[_buffCnt++];
var str = Scan;
while (str == "")
str = Scan;
_nextBuff =
str.Split(_splitCharacter, StringSplitOptions.RemoveEmptyEntries);
_buffCnt = 0;
return _nextBuff[_buffCnt++];
}
private string Scan => Console.ReadLine();
private void Read<T>(out T v) => v = SuitType<T>(Next());
private T ConvertType<T, TU>(TU v) => (T)Convert.ChangeType(v, typeof(T));
private bool TypeEqual<T, TU>() => typeof(T) == typeof(TU);
private T SuitType<T>(string s) =>
TypeEqual<T, int>() ? ConvertType<T, int>(int.Parse(s))
: TypeEqual<T, long>() ? ConvertType<T, long>(long.Parse(s))
: TypeEqual<T, double>() ? ConvertType<T, double>(double.Parse(s))
: TypeEqual<T, char>() ? ConvertType<T, char>(char.Parse(s))
: ConvertType<T, string>(s);
public string String => Next();
public char Char => char.Parse(Next());
public int Int => int.Parse(Next());
public long Long => long.Parse(Next());
public double Double => double.Parse(Next());
public void Flush() => Console.Out.Flush();
private T i<T>() => SuitType<T>(String);
public void i<T>(out T v) => Read(out v);
public void i<T, TU>(out T t, out TU u) {
i(out t);
i(out u);
}
public void i<T, TU, TV>(out T t, out TU u, out TV v) {
i(out t, out u);
i(out v);
}
public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) {
i(out t, out u, out v);
i(out w);
}
public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w,
out TX x) {
i(out t, out u, out v, out w);
i(out x);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = i<T>();
}
public void ini<T, TU>(out T[] a, out TU[] b, int n) {
a = new T[n];
b = new TU[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<TU>();
}
}
public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) {
a = new T[n];
b = new TU[n];
c = new TV[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<TU>();
c[i] = i<TV>();
}
}
public void ini<T>(out T[,] a, int h, int w) {
a = new T[h, w];
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j)
a[i, j] = i<T>();
}
public void ini<T, TU>(out Tuple<T, TU>[] t, int n) {
t = new Tuple<T, TU>[n];
for (int j = 0; j < n; ++j) {
T i1;
TU i2;
i(out i1, out i2);
t[j] = Tuple.Create(i1, i2);
}
}
public void ini<T, TU, TV>(out Tuple<T, TU, TV>[] t, int n) {
t = new Tuple<T, TU, TV>[n];
for (int j = 0; j < n; ++j) {
T i1;
TU i2;
TV i3;
i(out i1, out i2, out i3);
t[j] = Tuple.Create(i1, i2, i3);
}
}
#endregion
#region OUTPUT
private void Out<T>(T v) => Console.Write(v);
private void OutLine<T>(T v) => Console.WriteLine(v);
public void o() => OutLine("");
public void o<T>(T v) => OutLine(v);
public void o<T>(params T[] a) => Array.ForEach(a, OutLine);
public void o<T>(T[,] a) {
int a0 = a.GetLength(0), a1 = a.GetLength(1);
for (int i = 0; i < a0; ++i) {
for (int j = 0; j < a1 - 1; ++j)
Out(a[i, j] + " ");
OutLine(a[i, a1 - 1]);
}
}
public void ol<T>(params T[] a) => OutLine(string.Join(" ", a));
public void YN(bool f) => OutLine(f ? "YES" : "NO");
public void Yn(bool f) => OutLine(f ? "Yes" : "No");
public void yn(bool f) => OutLine(f ? "yes" : "no");
#endregion
}
#endregion
#region MyEx
static class StringEx {
public static string Reversed(this string s) => string.Join("", s.Reverse());
public static string Repeated(this string s, int n) =>
string.Concat(Enumerable.Repeat(s, n).ToArray());
public static string toString(this char[] a) => new string(a);
public static int toInt(this string s) {
int n;
return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0;
}
public static int toInt(this char c) => toInt(c.ToString());
public static int toInt(this char[] c) => toInt(c.toString());
public static long toLong(this string s) {
long n;
return (long.TryParse(s.TrimStart('0'), out n)) ? n : 0L;
}
public static long toLong(this char c) => toLong(c.ToString());
public static long toLong(this char[] c) => toLong(c.toString());
}
static class NumericEx {
public static string
toString(this double d) => d.ToString("R", CultureInfo.InvariantCulture);
public static string Pad0<T>(this T s, int n) => s.ToString().PadLeft(n, '0');
public static string RoundUp(this double v) => Math.Ceiling(v).toString();
public static string RoundDown(this double v) => Math.Floor(v).toString();
public static string RoundOff(this double v, int n) =>
Math.Round(v, n - 1, MidpointRounding.AwayFromZero).toString();
public static bool Odd(this int v) => (v & 1) != 0;
public static bool Odd(this long v) => (v & 1) != 0;
public static void REP(this int v, Action<int> act) {
for (int i = 0; i < v; ++i)
act(i);
}
public static void REPR(this int v, Action<int> act) {
for (int i = v - 1; i >= 0; --i)
act(i);
}
}
static class ArrayEx {
public static T[] Sort<T>(this T[] a) {
Array.Sort(a);
return a;
}
public static T[] SortR<T>(this T[] a) {
Array.Reverse(a.Sort());
return a;
}
public static void Set<T>(this T[] a, T v) => a.Length.REP(i => a[i] = v);
public static void Set<T>(this T[,] a, T v) =>
a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v));
public static void Set<T>(this T[,,] a, T v) => a.GetLength(0).REP(
i => a.GetLength(1).REP(j => a.GetLength(2).REP(k => a[i, j, k] = v)));
public static int BinarySearch<T>(this T[] a, int ng, int ok,
Func<int, bool> check) {
while (Math.Abs(ok - ng) > 1) {
var mid = (ok + ng) >> 1;
if (check(mid))
ok = mid;
else
ng = mid;
}
return ok;
}
}
#endregion
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace ConsoleApplication {
class MainClass {
////////////////////////////////////////////////////////////////////////////////
int H, W;
string[] s;
struct Point {
public int Y;
public int X;
public Point(int y, int x) {
Y = y;
X = x;
}
}
int[] dy = new int[] { 0, 1, 0, -1 };
int[] dx = new int[] { 1, 0, -1, 0 };
void Solve() {
io.i(out H, out W);
io.ini(out s, H);
var que = new Queue<Point>();
que.Enqueue(new Point(0, 0));
var costs = new int[H, W];
costs.Set(-1);
costs[0, 0] = 1;
while (que.Count > 0) {
var cur = que.Dequeue();
var cy = cur.Y;
var cx = cur.X;
if (cy == H - 1 && cx == W - 1)
break;
4.REP(i => {
var ny = cy + dy[i];
var nx = cx + dx[i];
if (0 <= ny && ny < H && 0 <= nx && nx < W && costs[ny, nx] == -1 &&
s[ny][nx] == '.') {
costs[ny, nx] = costs[cy, cx] + 1;
que.Enqueue(new Point(ny, nx));
}
});
}
var minCost = costs[H - 1, W - 1];
var whiteSum = 0;
H.REP(i => W.REP(j => {
if (s[i][j] == '.')
whiteSum++;
}));
if (minCost != -1) {
io.o(whiteSum - minCost);
} else {
io.o(-1);
}
}
////////////////////////////////////////////////////////////////////////////////
public static void Main() => new MainClass().Stream();
IO io = new IO();
void Stream() {
Solve();
// Test();
io.Flush();
}
void Test() {}
}
#region Default
class IO {
#region INPUT
int _buffCnt;
string[] _nextBuff;
private readonly char[] _splitCharacter = new char[] { ' ' };
private readonly StreamWriter _sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
_nextBuff = new string[0];
_buffCnt = 0;
Console.SetOut(_sw);
}
private string Next() {
if (_buffCnt < _nextBuff.Length)
return _nextBuff[_buffCnt++];
var str = Scan;
while (str == "")
str = Scan;
_nextBuff =
str.Split(_splitCharacter, StringSplitOptions.RemoveEmptyEntries);
_buffCnt = 0;
return _nextBuff[_buffCnt++];
}
private string Scan => Console.ReadLine();
private void Read<T>(out T v) => v = SuitType<T>(Next());
private T ConvertType<T, TU>(TU v) => (T)Convert.ChangeType(v, typeof(T));
private bool TypeEqual<T, TU>() => typeof(T) == typeof(TU);
private T SuitType<T>(string s) =>
TypeEqual<T, int>() ? ConvertType<T, int>(int.Parse(s))
: TypeEqual<T, long>() ? ConvertType<T, long>(long.Parse(s))
: TypeEqual<T, double>() ? ConvertType<T, double>(double.Parse(s))
: TypeEqual<T, char>() ? ConvertType<T, char>(char.Parse(s))
: ConvertType<T, string>(s);
public string String => Next();
public char Char => char.Parse(Next());
public int Int => int.Parse(Next());
public long Long => long.Parse(Next());
public double Double => double.Parse(Next());
public void Flush() => Console.Out.Flush();
private T i<T>() => SuitType<T>(String);
public void i<T>(out T v) => Read(out v);
public void i<T, TU>(out T t, out TU u) {
i(out t);
i(out u);
}
public void i<T, TU, TV>(out T t, out TU u, out TV v) {
i(out t, out u);
i(out v);
}
public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) {
i(out t, out u, out v);
i(out w);
}
public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w,
out TX x) {
i(out t, out u, out v, out w);
i(out x);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = i<T>();
}
public void ini<T, TU>(out T[] a, out TU[] b, int n) {
a = new T[n];
b = new TU[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<TU>();
}
}
public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) {
a = new T[n];
b = new TU[n];
c = new TV[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<TU>();
c[i] = i<TV>();
}
}
public void ini<T>(out T[,] a, int h, int w) {
a = new T[h, w];
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j)
a[i, j] = i<T>();
}
public void ini<T, TU>(out Tuple<T, TU>[] t, int n) {
t = new Tuple<T, TU>[n];
for (int j = 0; j < n; ++j) {
T i1;
TU i2;
i(out i1, out i2);
t[j] = Tuple.Create(i1, i2);
}
}
public void ini<T, TU, TV>(out Tuple<T, TU, TV>[] t, int n) {
t = new Tuple<T, TU, TV>[n];
for (int j = 0; j < n; ++j) {
T i1;
TU i2;
TV i3;
i(out i1, out i2, out i3);
t[j] = Tuple.Create(i1, i2, i3);
}
}
#endregion
#region OUTPUT
private void Out<T>(T v) => Console.Write(v);
private void OutLine<T>(T v) => Console.WriteLine(v);
public void o() => OutLine("");
public void o<T>(T v) => OutLine(v);
public void o<T>(params T[] a) => Array.ForEach(a, OutLine);
public void o<T>(T[,] a) {
int a0 = a.GetLength(0), a1 = a.GetLength(1);
for (int i = 0; i < a0; ++i) {
for (int j = 0; j < a1 - 1; ++j)
Out(a[i, j] + " ");
OutLine(a[i, a1 - 1]);
}
}
public void ol<T>(params T[] a) => OutLine(string.Join(" ", a));
public void YN(bool f) => OutLine(f ? "YES" : "NO");
public void Yn(bool f) => OutLine(f ? "Yes" : "No");
public void yn(bool f) => OutLine(f ? "yes" : "no");
#endregion
}
#endregion
#region MyEx
static class StringEx {
public static string Reversed(this string s) => string.Join("", s.Reverse());
public static string Repeated(this string s, int n) =>
string.Concat(Enumerable.Repeat(s, n).ToArray());
public static string toString(this char[] a) => new string(a);
public static int toInt(this string s) {
int n;
return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0;
}
public static int toInt(this char c) => toInt(c.ToString());
public static int toInt(this char[] c) => toInt(c.toString());
public static long toLong(this string s) {
long n;
return (long.TryParse(s.TrimStart('0'), out n)) ? n : 0L;
}
public static long toLong(this char c) => toLong(c.ToString());
public static long toLong(this char[] c) => toLong(c.toString());
}
static class NumericEx {
public static string
toString(this double d) => d.ToString("R", CultureInfo.InvariantCulture);
public static string Pad0<T>(this T s, int n) => s.ToString().PadLeft(n, '0');
public static string RoundUp(this double v) => Math.Ceiling(v).toString();
public static string RoundDown(this double v) => Math.Floor(v).toString();
public static string RoundOff(this double v, int n) =>
Math.Round(v, n - 1, MidpointRounding.AwayFromZero).toString();
public static bool Odd(this int v) => (v & 1) != 0;
public static bool Odd(this long v) => (v & 1) != 0;
public static void REP(this int v, Action<int> act) {
for (int i = 0; i < v; ++i)
act(i);
}
public static void REPR(this int v, Action<int> act) {
for (int i = v - 1; i >= 0; --i)
act(i);
}
}
static class ArrayEx {
public static T[] Sort<T>(this T[] a) {
Array.Sort(a);
return a;
}
public static T[] SortR<T>(this T[] a) {
Array.Reverse(a.Sort());
return a;
}
public static void Set<T>(this T[] a, T v) => a.Length.REP(i => a[i] = v);
public static void Set<T>(this T[,] a, T v) =>
a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v));
public static void Set<T>(this T[,,] a, T v) => a.GetLength(0).REP(
i => a.GetLength(1).REP(j => a.GetLength(2).REP(k => a[i, j, k] = v)));
public static int BinarySearch<T>(this T[] a, int ng, int ok,
Func<int, bool> check) {
while (Math.Abs(ok - ng) > 1) {
var mid = (ok + ng) >> 1;
if (check(mid))
ok = mid;
else
ng = mid;
}
return ok;
}
}
#endregion
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 2,657
| 20
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.WindowsRuntime;
//using CS_Contest.Graph;
using CS_Contest.Loop;
using CS_Contest.Utils;
using static Nakov.IO.Cin;
using static CS_Contest.IO.IO;
namespace CS_Contest {
using Li = List<int>;
using LLi = List<List<int>>;
using Ll = List<long>;
using ti3 = Tuple<int, int, int>;
using ti2 = Tuple<int, int>;
internal class Program {
private static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
SetOut(sw);
new Calc().Solve();
Out.Flush();
}
public class Calc {
public void Solve() {
int H = NextInt(), W = NextInt();
var lb = new Labyrinth(H, W, '.');
var sp = lb.ShortestPath();
var cnt = lb.labyrinth.Sum(line => line.Count('.'));
(cnt-sp-1).WL();
return;
}
public class Labyrinth {
private char Road { get; set; }
private int H { get; set; }
private int W { get; set; }
public List<string> labyrinth;
public Labyrinth(int h, int w, char road) {
H = h;
W = w;
Road = road;
labyrinth = new List<string>();
for (int i = 0; i < H; i++) {
labyrinth.Add(ReadLine());
}
}
public int ShortestPath() => ShortestPath(0, 0, H - 1, W - 1);
public int ShortestPath(int sx, int sy, int gx, int gy) {
var queue = new Queue<Tuple<int, int, int>>();
var used = new bool[H, W];
var dx = new[] { 1, 0, -1, 0 };
var dy = new[] { 0, -1, 0, 1 };
queue.Enqueue(new Tuple<int, int, int>(sx, sy, 0));
used[sy, sx] = true;
var min = int.MaxValue;
while (queue.Any()) {
var v = queue.Dequeue();
for (int i = 0; i < 4; i++) {
var x = v.Item1 + dx[i];
var y = v.Item2 + dy[i];
if (y < 0 || x < 0 || y >= H || x >= W) continue;
if (labyrinth[y][x] != Road) continue;
if (x == W - 1 && y == H - 1) {
min = Min(min, v.Item3 + 1);
continue;
}
if (used[y, x]) continue;
used[y, x] = true;
queue.Enqueue(new Tuple<int, int, int>(x, y, v.Item3 + 1));
}
}
return min;
}
}
}
}
}
namespace Nakov.IO {
using System;
using System.Text;
using System.Globalization;
public static class Cin {
public static string NextToken() {
StringBuilder tokenChars = new StringBuilder();
bool tokenFinished = false;
bool skipWhiteSpaceMode = true;
while (!tokenFinished) {
int nextChar = Console.Read();
if (nextChar == -1) {
tokenFinished = true;
} else {
char ch = (char)nextChar;
if (char.IsWhiteSpace(ch)) {
if (!skipWhiteSpaceMode) {
tokenFinished = true;
if (ch == '\r' && (Environment.NewLine == "\r\n")) {
Console.Read();
}
}
} else {
skipWhiteSpaceMode = false;
tokenChars.Append(ch);
}
}
}
string token = tokenChars.ToString();
return token;
}
public static int NextInt() {
string token = Cin.NextToken();
return int.Parse(token);
}
public static long NextLong() {
string token = Cin.NextToken();
return long.Parse(token);
}
public static double NextDouble(bool acceptAnyDecimalSeparator = true) {
string token = Cin.NextToken();
if (acceptAnyDecimalSeparator) {
token = token.Replace(',', '.');
double result = double.Parse(token, CultureInfo.InvariantCulture);
return result;
} else {
double result = double.Parse(token);
return result;
}
}
public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) {
string token = Cin.NextToken();
if (acceptAnyDecimalSeparator) {
token = token.Replace(',', '.');
decimal result = decimal.Parse(token, CultureInfo.InvariantCulture);
return result;
} else {
decimal result = decimal.Parse(token);
return result;
}
}
}
}
namespace CS_Contest.Loop {
public static class Loop {
public static void REP(this int n, Action<int> act) {
for (var i = 0; i < n; i++) {
act(i);
}
}
public static void RREP(this int @n, Action<int> act) {
for (var i = n - 1; i >= 0; i--) act(i);
}
public static void REP(this long n, Action<long> act) {
for (var i = 0; i < n; i++) act(i);
}
public static void FOR(this Tuple<int, int, int> t, Action<int> action) {
for (var i = t.Item1; i < t.Item2; i += t.Item3) action(i);
}
public static void FOR(this Tuple<int, int> t, Action<int> action) =>
new Tuple<int, int, int>(t.Item1, t.Item2, 1).FOR(action);
public static void FOR(this Tuple<long, long, long> t, Action<long> action) {
for (var i = t.Item1; i < t.Item2; i += t.Item3) action(i);
}
public static void FOR(this Tuple<long, long> t, Action<long> act) =>
new Tuple<long, long, long>(t.Item1, t.Item2, 1).FOR(act);
public static void ForeachWith<T>(this IEnumerable<T> ie, Action<int, T> act) {
var i = 0;
foreach (var item in ie) {
act(i, item);
i++;
}
}
public static void Foreach<T>(this IEnumerable<T> ie, Action<T> act) {
foreach (var item in ie) {
act(item);
}
}
}
}
namespace CS_Contest.IO {
using Li = List<int>;
using Ll = List<long>;
public static class IO {
public static void WL(this object obj) => WriteLine(obj);
public static void WL(this string obj) => WriteLine(obj);
public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL());
public static Li NextIntList() => ReadLine().Split().Select(int.Parse).ToList();
public static Ll NextLongList() => ReadLine().Split().Select(long.Parse).ToList();
public static T Tee<T>(this T t, Func<T, string> formatter = null) {
if (formatter == null) formatter = arg => arg.ToString();
formatter(t).WL();
return t;
}
public static void JoinWL<T>(this IEnumerable<T> @this, string sp = " ") => @this.StringJoin(sp).WL();
public static void W(this object @this) => Write(@this);
}
}
namespace CS_Contest.Utils {
using Li = List<int>;
using Ll = List<long>;
public static class Utils {
public static List<T> Repeat<T>(Func<int, T> result, int range) =>
Enumerable.Range(0, range).Select(result).ToList();
public static bool Within(int x, int y, int lx, int ly) => !(x < 0 || x >= lx || y < 0 || y >= ly);
public static void Add<T1, T2>(this List<Tuple<T1, T2>> list, T1 t1, T2 t2) => list.Add(new Tuple<T1, T2>(t1, t2));
public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l);
public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) {
var rt = new Queue<T>();
foreach (var item in iEnumerable) {
rt.Enqueue(item);
}
return rt;
}
public static void Swap<T>(ref T x, ref T y) {
var tmp = x;
x = y;
y = tmp;
}
public static Tuple<T1, T2> AutoTuple<T1, T2>(T1 t1, T2 t2) => new Tuple<T1, T2>(t1, t2);
public static Dictionary<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) {
var dic = new Dictionary<TKey, int>();
foreach (var item in l) {
if (dic.ContainsKey(item)) dic[item]++;
else dic.Add(item, 1);
}
return dic;
}
public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target));
public static IEnumerable<T> SkipAt<T>(this IEnumerable<T> @this, int at) {
var enumerable = @this as T[] ?? @this.ToArray();
for (var i = 0; i < enumerable.Count(); i++) {
if (i == at) continue;
yield return enumerable.ElementAt(i);
}
}
}
public class Map<TKey, TValue> : Dictionary<TKey, TValue> {
public Map() : base() { }
public Map(int capacity) : base(capacity) { }
public new TValue this[TKey index] {
get {
TValue v;
return this.TryGetValue(index, out v) ? v : base[index] = default(TValue);
}
set { base[index] = value; }
}
}
public static class MyMath {
public static long GCD(long m, long n) {
long tmp;
if (m < n) { tmp = n; n = m; m = tmp; }
while (m % n != 0) {
tmp = n;
n = m % n;
m = tmp;
}
return n;
}
public static long LCM(long m, long n) => m * (n / GCD(m, n));
public static long ModValue = (long)1e9 + 7;
public static long INF = long.MaxValue;
public static long Mod(long x) => x % ModValue;
public static long DivMod(long x, long y) => Mod(x * ModPow(y, (long)(1e9 + 5)));
public static long[,] CombinationTable(int n) {
var rt = new long[n + 1, n + 1];
for (var i = 0; i <= n; i++) {
for (var j = 0; j <= i; j++) {
if (j == 0 || i == j) rt[i, j] = 1L;
else rt[i, j] = (rt[i - 1, j - 1] + rt[i - 1, j]);
}
}
return rt;
}
public static long ModPow(long x, long n) {
long tmp = 1; while (n != 0) { if (n % 2 == 1) { tmp = Mod(tmp * x); } x = Mod(x * x); n /= 2; }
return tmp;
}
public static bool IsPrime(long n) {
if (n == 2) return true;
if (n < 2 || n % 2 == 0) return false;
var i = 3;
var sq = (long)Sqrt(n);
while (i <= sq) {
if (n % i == 0) return false;
i += 2;
}
return true;
}
public static IEnumerable<int> Primes(int maxnum) {
yield return 2;
yield return 3;
var sieve = new BitArray(maxnum + 1);
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false) {
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = true;
}
for (var n = i * i + 1; n <= maxnum && n < (i + 1) * (i + 1); n++) {
if (!sieve[n])
yield return n;
}
}
}
public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1);
public static T Min<T>(params T[] a) where T : IComparable<T> => a.Min();
public static T Max<T>(params T[] a) where T : IComparable<T> => a.Max();
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.WindowsRuntime;
//using CS_Contest.Graph;
using CS_Contest.Loop;
using CS_Contest.Utils;
using static Nakov.IO.Cin;
using static CS_Contest.IO.IO;
namespace CS_Contest {
using Li = List<int>;
using LLi = List<List<int>>;
using Ll = List<long>;
using ti3 = Tuple<int, int, int>;
using ti2 = Tuple<int, int>;
internal class Program {
private static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
SetOut(sw);
new Calc().Solve();
Out.Flush();
}
public class Calc {
public void Solve() {
int H = NextInt(), W = NextInt();
var lb = new Labyrinth(H, W, '.');
var sp = lb.ShortestPath();
if (sp == int.MaxValue) {
"-1".WL();
return;
}
var cnt = lb.labyrinth.Sum(line => line.Count('.'));
(cnt-sp-1).WL();
return;
}
public class Labyrinth {
private char Road { get; set; }
private int H { get; set; }
private int W { get; set; }
public List<string> labyrinth;
public Labyrinth(int h, int w, char road) {
H = h;
W = w;
Road = road;
labyrinth = new List<string>();
for (int i = 0; i < H; i++) {
labyrinth.Add(ReadLine());
}
}
public int ShortestPath() => ShortestPath(0, 0, H - 1, W - 1);
public int ShortestPath(int sx, int sy, int gx, int gy) {
var queue = new Queue<Tuple<int, int, int>>();
var used = new bool[H, W];
var dx = new[] { 1, 0, -1, 0 };
var dy = new[] { 0, -1, 0, 1 };
queue.Enqueue(new Tuple<int, int, int>(sx, sy, 0));
used[sy, sx] = true;
var min = int.MaxValue;
while (queue.Any()) {
var v = queue.Dequeue();
for (int i = 0; i < 4; i++) {
var x = v.Item1 + dx[i];
var y = v.Item2 + dy[i];
if (y < 0 || x < 0 || y >= H || x >= W) continue;
if (labyrinth[y][x] != Road) continue;
if (x == W - 1 && y == H - 1) {
min = Min(min, v.Item3 + 1);
continue;
}
if (used[y, x]) continue;
used[y, x] = true;
queue.Enqueue(new Tuple<int, int, int>(x, y, v.Item3 + 1));
}
}
return min;
}
}
}
}
}
namespace Nakov.IO {
using System;
using System.Text;
using System.Globalization;
public static class Cin {
public static string NextToken() {
StringBuilder tokenChars = new StringBuilder();
bool tokenFinished = false;
bool skipWhiteSpaceMode = true;
while (!tokenFinished) {
int nextChar = Console.Read();
if (nextChar == -1) {
tokenFinished = true;
} else {
char ch = (char)nextChar;
if (char.IsWhiteSpace(ch)) {
if (!skipWhiteSpaceMode) {
tokenFinished = true;
if (ch == '\r' && (Environment.NewLine == "\r\n")) {
Console.Read();
}
}
} else {
skipWhiteSpaceMode = false;
tokenChars.Append(ch);
}
}
}
string token = tokenChars.ToString();
return token;
}
public static int NextInt() {
string token = Cin.NextToken();
return int.Parse(token);
}
public static long NextLong() {
string token = Cin.NextToken();
return long.Parse(token);
}
public static double NextDouble(bool acceptAnyDecimalSeparator = true) {
string token = Cin.NextToken();
if (acceptAnyDecimalSeparator) {
token = token.Replace(',', '.');
double result = double.Parse(token, CultureInfo.InvariantCulture);
return result;
} else {
double result = double.Parse(token);
return result;
}
}
public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) {
string token = Cin.NextToken();
if (acceptAnyDecimalSeparator) {
token = token.Replace(',', '.');
decimal result = decimal.Parse(token, CultureInfo.InvariantCulture);
return result;
} else {
decimal result = decimal.Parse(token);
return result;
}
}
}
}
namespace CS_Contest.Loop {
public static class Loop {
public static void REP(this int n, Action<int> act) {
for (var i = 0; i < n; i++) {
act(i);
}
}
public static void RREP(this int @n, Action<int> act) {
for (var i = n - 1; i >= 0; i--) act(i);
}
public static void REP(this long n, Action<long> act) {
for (var i = 0; i < n; i++) act(i);
}
public static void FOR(this Tuple<int, int, int> t, Action<int> action) {
for (var i = t.Item1; i < t.Item2; i += t.Item3) action(i);
}
public static void FOR(this Tuple<int, int> t, Action<int> action) =>
new Tuple<int, int, int>(t.Item1, t.Item2, 1).FOR(action);
public static void FOR(this Tuple<long, long, long> t, Action<long> action) {
for (var i = t.Item1; i < t.Item2; i += t.Item3) action(i);
}
public static void FOR(this Tuple<long, long> t, Action<long> act) =>
new Tuple<long, long, long>(t.Item1, t.Item2, 1).FOR(act);
public static void ForeachWith<T>(this IEnumerable<T> ie, Action<int, T> act) {
var i = 0;
foreach (var item in ie) {
act(i, item);
i++;
}
}
public static void Foreach<T>(this IEnumerable<T> ie, Action<T> act) {
foreach (var item in ie) {
act(item);
}
}
}
}
namespace CS_Contest.IO {
using Li = List<int>;
using Ll = List<long>;
public static class IO {
public static void WL(this object obj) => WriteLine(obj);
public static void WL(this string obj) => WriteLine(obj);
public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL());
public static Li NextIntList() => ReadLine().Split().Select(int.Parse).ToList();
public static Ll NextLongList() => ReadLine().Split().Select(long.Parse).ToList();
public static T Tee<T>(this T t, Func<T, string> formatter = null) {
if (formatter == null) formatter = arg => arg.ToString();
formatter(t).WL();
return t;
}
public static void JoinWL<T>(this IEnumerable<T> @this, string sp = " ") => @this.StringJoin(sp).WL();
public static void W(this object @this) => Write(@this);
}
}
namespace CS_Contest.Utils {
using Li = List<int>;
using Ll = List<long>;
public static class Utils {
public static List<T> Repeat<T>(Func<int, T> result, int range) =>
Enumerable.Range(0, range).Select(result).ToList();
public static bool Within(int x, int y, int lx, int ly) => !(x < 0 || x >= lx || y < 0 || y >= ly);
public static void Add<T1, T2>(this List<Tuple<T1, T2>> list, T1 t1, T2 t2) => list.Add(new Tuple<T1, T2>(t1, t2));
public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l);
public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) {
var rt = new Queue<T>();
foreach (var item in iEnumerable) {
rt.Enqueue(item);
}
return rt;
}
public static void Swap<T>(ref T x, ref T y) {
var tmp = x;
x = y;
y = tmp;
}
public static Tuple<T1, T2> AutoTuple<T1, T2>(T1 t1, T2 t2) => new Tuple<T1, T2>(t1, t2);
public static Dictionary<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) {
var dic = new Dictionary<TKey, int>();
foreach (var item in l) {
if (dic.ContainsKey(item)) dic[item]++;
else dic.Add(item, 1);
}
return dic;
}
public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target));
public static IEnumerable<T> SkipAt<T>(this IEnumerable<T> @this, int at) {
var enumerable = @this as T[] ?? @this.ToArray();
for (var i = 0; i < enumerable.Count(); i++) {
if (i == at) continue;
yield return enumerable.ElementAt(i);
}
}
}
public class Map<TKey, TValue> : Dictionary<TKey, TValue> {
public Map() : base() { }
public Map(int capacity) : base(capacity) { }
public new TValue this[TKey index] {
get {
TValue v;
return this.TryGetValue(index, out v) ? v : base[index] = default(TValue);
}
set { base[index] = value; }
}
}
public static class MyMath {
public static long GCD(long m, long n) {
long tmp;
if (m < n) { tmp = n; n = m; m = tmp; }
while (m % n != 0) {
tmp = n;
n = m % n;
m = tmp;
}
return n;
}
public static long LCM(long m, long n) => m * (n / GCD(m, n));
public static long ModValue = (long)1e9 + 7;
public static long INF = long.MaxValue;
public static long Mod(long x) => x % ModValue;
public static long DivMod(long x, long y) => Mod(x * ModPow(y, (long)(1e9 + 5)));
public static long[,] CombinationTable(int n) {
var rt = new long[n + 1, n + 1];
for (var i = 0; i <= n; i++) {
for (var j = 0; j <= i; j++) {
if (j == 0 || i == j) rt[i, j] = 1L;
else rt[i, j] = (rt[i - 1, j - 1] + rt[i - 1, j]);
}
}
return rt;
}
public static long ModPow(long x, long n) {
long tmp = 1; while (n != 0) { if (n % 2 == 1) { tmp = Mod(tmp * x); } x = Mod(x * x); n /= 2; }
return tmp;
}
public static bool IsPrime(long n) {
if (n == 2) return true;
if (n < 2 || n % 2 == 0) return false;
var i = 3;
var sq = (long)Sqrt(n);
while (i <= sq) {
if (n % i == 0) return false;
i += 2;
}
return true;
}
public static IEnumerable<int> Primes(int maxnum) {
yield return 2;
yield return 3;
var sieve = new BitArray(maxnum + 1);
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false) {
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = true;
}
for (var n = i * i + 1; n <= maxnum && n < (i + 1) * (i + 1); n++) {
if (!sieve[n])
yield return n;
}
}
}
public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1);
public static T Min<T>(params T[] a) where T : IComparable<T> => a.Min();
public static T Max<T>(params T[] a) where T : IComparable<T> => a.Max();
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 205, 199], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 1, 0, 213, 63, 214, 205, 5, 0, 62], ["+", 0, 1, 0, 213, 63, 214, 205, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 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,907
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var p = new Program();
p.Solve();
}
enum Status {
NotVisited,
Visited,
}
char[][] graph;
int[,] shortestPath;
void Solve() {
var tmp = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
int h = tmp[0];
int w = tmp[1];
graph = new char [h][];
for (int i = 0; i < h; i++) {
graph[i] = Console.ReadLine().ToCharArray();
}
int totalWhite = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < graph[i].Length; j++) {
if (graph[i][j] == '.')
totalWhite++;
}
}
shortestPath = new int[h, w];
// for (int i = 0; i < h; i++)
//{
// for (int j = 0; j < w; j++)
// {
// shortestPath[i, j] = -1;
// }
//}
var queue = new Queue<Pos>();
queue.Enqueue(new Pos(0, 0));
shortestPath[0, 0] = 1;
while (queue.Count != 0) {
var current = queue.Dequeue();
var neighbors = new Pos[] {
new Pos(current.X - 1, current.Y),
new Pos(current.X + 1, current.Y),
new Pos(current.X, current.Y - 1),
new Pos(current.X, current.Y + 1),
};
foreach (var next in neighbors) {
if (CanMove(next)) {
if (shortestPath[next.Y, next.X] == 0) //通っていないとき
{
shortestPath[next.Y, next.X] =
shortestPath[current.Y, current.X] + 1;
queue.Enqueue(next);
}
}
}
}
int ans = shortestPath[h - 1, w - 1] == -1
? -1
: totalWhite - shortestPath[h - 1, w - 1];
Console.WriteLine(ans);
}
bool CanMove(Pos pos) {
if (pos.X < 0 || pos.Y < 0 || pos.X >= graph[0].Length ||
pos.Y >= graph.Length)
return false;
if (graph[pos.Y][pos.X] != '.')
return false;
return true;
}
class Pos {
public int X { get; set; }
public int Y { get; set; }
public Pos(int x, int y) {
X = x;
Y = y;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var p = new Program();
p.Solve();
}
enum Status {
NotVisited,
Visited,
}
char[][] graph;
int[,] shortestPath;
void Solve() {
var tmp = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
int h = tmp[0];
int w = tmp[1];
graph = new char [h][];
for (int i = 0; i < h; i++) {
graph[i] = Console.ReadLine().ToCharArray();
}
int totalWhite = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < graph[i].Length; j++) {
if (graph[i][j] == '.')
totalWhite++;
}
}
shortestPath = new int[h, w];
var queue = new Queue<Pos>();
queue.Enqueue(new Pos(0, 0));
shortestPath[0, 0] = 1;
while (queue.Count != 0) {
var current = queue.Dequeue();
var nextTiles = new Pos[] {
new Pos(current.X - 1, current.Y),
new Pos(current.X + 1, current.Y),
new Pos(current.X, current.Y - 1),
new Pos(current.X, current.Y + 1),
};
foreach (var tile in nextTiles) {
if (CanMove(tile)) {
if (shortestPath[tile.Y, tile.X] == 0) //通っていないとき
{
shortestPath[tile.Y, tile.X] =
shortestPath[current.Y, current.X] + 1;
queue.Enqueue(tile);
}
}
}
}
int ans = shortestPath[h - 1, w - 1] == 0
? -1
: totalWhite - shortestPath[h - 1, w - 1];
Console.WriteLine(ans);
}
bool CanMove(Pos pos) {
if (pos.X < 0 || pos.Y < 0 || pos.X >= graph[0].Length ||
pos.Y >= graph.Length)
return false;
if (graph[pos.Y][pos.X] != '.')
return false;
return true;
}
class Pos {
public int X { get; set; }
public int Y { get; set; }
public Pos(int x, int y) {
X = x;
Y = y;
}
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 210, 31, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 210, 31, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 210, 12, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 210, 12, 22], ["-", 0, 57, 15, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 15, 213, 3, 4, 0, 28, 0, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 214, 205, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 205, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 212, 0, 41, 15, 16, 12, 241, 0, 33], ["-", 0, 212, 0, 41, 15, 16, 12, 241, 0, 203], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203]]
| 8
| 571
| 21
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace atcoder {
class Program {
static int In => int.Parse(Console.ReadLine());
static int[] Ins => Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
static void Out(bool b) => Console.WriteLine(b ? "Yes" : "No");
static string[] map;
static int H, W;
static void Main(string[] args) {
var input = Ins;
H = input[0];
W = input[1];
map = new string[input[0]];
for (int i = 0; i < input[0]; i++) {
map[i] = Console.ReadLine();
}
Node n = new Node(new IntPoint(1, 1), 0, new IntPoint[0]);
Node ans = (Node)DijkstrasAlgorithm(n);
List<IntPoint> li = new List<IntPoint>(ans.route);
int sum = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (map[i][j] == '.') {
int id = li.IndexOf(new IntPoint(j + 1, i + 1));
if (id == -1)
sum++;
}
}
}
Console.WriteLine(sum);
}
/// <summary>
/// ダイクストラのアルゴリズム
/// </summary>
/// <param name="start"></param>
/// <param name="max">最大化問題を解く</param>
/// <returns></returns>
public static INodeEv DijkstrasAlgorithm(INodeEv start, bool max = false) {
var pque = new PriorityQueue<INodeEv>(max);
var visited = new HashSet<Node>();
pque.Push(start);
visited.Add((Node)start);
while (pque.Length != 0) {
var item = pque.Pop();
if (item.IsGoal())
return item;
foreach (var next in item.GetNext()) {
if (!visited.Contains(next)) {
visited.Add((Node)next);
pque.Push(next);
}
}
}
return null;
}
public class Node : INodeEv {
IntPoint p;
int dis;
public IntPoint[] route;
public override bool Equals(object obj) {
return this.p.X == ((Node)obj).p.X && this.p.Y == ((Node)obj).p.Y;
}
public Node(IntPoint pp, int d, IntPoint[] r) {
p = pp;
dis = d;
List<IntPoint> li = new List<IntPoint>(r);
li.Add(pp);
route = li.ToArray();
}
public int CompareTo(object obj) {
var i = dis.CompareTo(((Node)obj).dis);
if (i == 0)
return p.CompareTo(((Node)obj).p);
else
return i;
}
public override int GetHashCode() { return this.p.GetHashCode(); }
public bool Equals(INodeEv x, INodeEv y) {
return ((Node)x).p.Equals(((Node)y).p);
}
public int GetHashCode(INodeEv obj) { return p.GetHashCode(); }
public IEnumerable<INodeEv> GetNext() {
var pp = p + new IntPoint(0, 1);
if (isin(pp))
yield return new Node(pp, dis + 1, route);
pp = p + new IntPoint(0, -1);
if (isin(pp))
yield return new Node(pp, dis + 1, route);
pp = p + new IntPoint(1, 0);
if (isin(pp))
yield return new Node(pp, dis + 1, route);
pp = p + new IntPoint(-1, 0);
if (isin(pp))
yield return new Node(pp, dis + 1, route);
}
bool isin(IntPoint pos) {
return 1 <= pos.X && pos.X <= W && 1 <= pos.Y && pos.Y <= H &&
map[pos.Y - 1][pos.X - 1] != '#';
}
public bool IsGoal() { return p.X == W && p.Y == H; }
}
public interface INodeEv : IComparable, IEqualityComparer<INodeEv> {
bool IsGoal();
IEnumerable<INodeEv> GetNext();
}
}
/// <summary>
/// 優先度付きキューを提供する
/// </summary>
/// <typeparam name="T"></typeparam>
public class PriorityQueue<T>
where T : IComparable {
#region member
private List<T> list;
private bool reverse;
#endregion
#region constructor
/// <summary>
///
/// </summary>
/// <param name="isReverse">定義された順序の逆で評価する</param>
public PriorityQueue(bool isReverse = false) {
list = new List<T>();
reverse = isReverse;
}
#endregion
#region private method
private bool compare(T a, T b) { return reverse ^ a.CompareTo(b) > 0; }
private void swap(int a, int b) {
T tmp = list[a];
list[a] = list[b];
list[b] = tmp;
}
#endregion
#region public method
/// <summary>
/// 要素を追加する
/// </summary>
/// <param name="item">追加する要素</param>
public void Push(T item) {
if (Length < list.Count)
list[Length] = item;
else
list.Add(item);
var pos = Length++;
while (pos != 0) {
var parent = (pos + 1) / 2 - 1;
if (compare(list[pos], list[parent]))
break;
swap(pos, parent);
pos = parent;
}
}
/// <summary>
/// 要素を追加する
/// </summary>
/// <param name="items">追加する要素の列</param>
public void Push(IEnumerable<T> items) {
foreach (var item in items) {
Push(item);
}
}
/// <summary>
/// 値を確認する
/// </summary>
/// <returns></returns>
public T Peek() { return list[0]; }
/// <summary>
/// 値を取り出す
/// </summary>
/// <returns></returns>
public T Pop() {
var ret = Peek();
var pos = 0;
list[0] = list[--Length];
while (2 * pos + 1 < Length) {
var child = 2 * pos + 1;
var child_other = 2 * pos + 2;
if (child_other < Length && compare(list[child], list[child_other])) {
child = child_other;
}
if (compare(list[child], list[pos]))
break;
swap(pos, child);
pos = child;
}
return ret;
}
/// <summary>
/// クリアする
/// </summary>
public void Clear() { list.Clear(); }
#endregion
#region property
/// <summary>
/// 要素の長さを取得する
/// </summary>
public int Length { get; private set; }
#endregion
}
public class IntPoint : IComparable, ICloneable {
#region member
public int X { get; private set; }
public int Y { get; private set; }
#endregion
#region constructor
public IntPoint(int x, int y) {
X = x;
Y = y;
}
public IntPoint() {
X = 0;
Y = 0;
}
#endregion
#region operator
public static IntPoint operator +(IntPoint a, IntPoint b) {
return new IntPoint(a.X + b.X, a.Y + b.Y);
}
public static IntPoint operator -(IntPoint a, IntPoint b) {
return new IntPoint(a.X - b.X, a.Y - b.Y);
}
public static bool operator ==(IntPoint a, IntPoint b) {
return a.X == b.X && a.Y == b.Y;
}
public static bool operator !=(IntPoint a, IntPoint b) { return !(a == b); }
public static bool operator>(IntPoint a, IntPoint b) {
if (a.X != b.X)
return a.X > b.Y;
else
return a.Y > b.Y;
}
public static bool operator >=(IntPoint a, IntPoint b) {
return a == b || (a > b);
}
public static bool operator<(IntPoint a, IntPoint b) { return !(a >= b); }
public static bool operator <=(IntPoint a, IntPoint b) { return !(a > b); }
#endregion
#region public method
/// <summary>
/// マンハッタン距離を取得する
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int GetManhattanDistance(IntPoint a, IntPoint b) {
return Math.Abs(a.X - b.X) + Math.Abs(a.Y - b.Y);
}
/// <summary>
/// ユークリッド距離を取得する
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static double GetEuclideanDistance(IntPoint a, IntPoint b) {
var tmp = a - b;
return Math.Sqrt(tmp.X * tmp.X + tmp.Y * tmp.Y);
}
#endregion
#region override or implementation
public int CompareTo(object obj) {
if (X != ((IntPoint)obj).X)
return X.CompareTo(((IntPoint)obj).X);
else
return Y.CompareTo(((IntPoint)obj).Y);
}
public override bool Equals(object obj) {
return this.X == ((IntPoint)obj).X && this.Y == ((IntPoint)obj).Y;
}
public override int GetHashCode() {
return X.GetHashCode() + (Y.GetHashCode() << 1);
}
public object Clone() { return new IntPoint(X, Y); }
#endregion
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace atcoder {
class Program {
static int In => int.Parse(Console.ReadLine());
static int[] Ins => Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
static void Out(bool b) => Console.WriteLine(b ? "Yes" : "No");
static string[] map;
static int H, W;
static void Main(string[] args) {
var input = Ins;
H = input[0];
W = input[1];
map = new string[input[0]];
for (int i = 0; i < input[0]; i++) {
map[i] = Console.ReadLine();
}
Node n = new Node(new IntPoint(1, 1), 0, new IntPoint[0]);
Node ans = (Node)DijkstrasAlgorithm(n);
if (ans == null)
Console.WriteLine(-1);
else {
List<IntPoint> li = new List<IntPoint>(ans.route);
int sum = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (map[i][j] == '.') {
int id = li.IndexOf(new IntPoint(j + 1, i + 1));
if (id == -1)
sum++;
}
}
}
Console.WriteLine(sum);
}
}
/// <summary>
/// ダイクストラのアルゴリズム
/// </summary>
/// <param name="start"></param>
/// <param name="max">最大化問題を解く</param>
/// <returns></returns>
public static INodeEv DijkstrasAlgorithm(INodeEv start, bool max = false) {
var pque = new PriorityQueue<INodeEv>(max);
var visited = new HashSet<Node>();
pque.Push(start);
visited.Add((Node)start);
while (pque.Length != 0) {
var item = pque.Pop();
if (item.IsGoal())
return item;
foreach (var next in item.GetNext()) {
if (!visited.Contains(next)) {
visited.Add((Node)next);
pque.Push(next);
}
}
}
return null;
}
public class Node : INodeEv {
IntPoint p;
int dis;
public IntPoint[] route;
public override bool Equals(object obj) {
return this.p.X == ((Node)obj).p.X && this.p.Y == ((Node)obj).p.Y;
}
public Node(IntPoint pp, int d, IntPoint[] r) {
p = pp;
dis = d;
List<IntPoint> li = new List<IntPoint>(r);
li.Add(pp);
route = li.ToArray();
}
public int CompareTo(object obj) {
var i = dis.CompareTo(((Node)obj).dis);
if (i == 0)
return p.CompareTo(((Node)obj).p);
else
return i;
}
public override int GetHashCode() { return this.p.GetHashCode(); }
public bool Equals(INodeEv x, INodeEv y) {
return ((Node)x).p.Equals(((Node)y).p);
}
public int GetHashCode(INodeEv obj) { return p.GetHashCode(); }
public IEnumerable<INodeEv> GetNext() {
var pp = p + new IntPoint(0, 1);
if (isin(pp))
yield return new Node(pp, dis + 1, route);
pp = p + new IntPoint(0, -1);
if (isin(pp))
yield return new Node(pp, dis + 1, route);
pp = p + new IntPoint(1, 0);
if (isin(pp))
yield return new Node(pp, dis + 1, route);
pp = p + new IntPoint(-1, 0);
if (isin(pp))
yield return new Node(pp, dis + 1, route);
}
bool isin(IntPoint pos) {
return 1 <= pos.X && pos.X <= W && 1 <= pos.Y && pos.Y <= H &&
map[pos.Y - 1][pos.X - 1] != '#';
}
public bool IsGoal() { return p.X == W && p.Y == H; }
}
public interface INodeEv : IComparable, IEqualityComparer<INodeEv> {
bool IsGoal();
IEnumerable<INodeEv> GetNext();
}
}
/// <summary>
/// 優先度付きキューを提供する
/// </summary>
/// <typeparam name="T"></typeparam>
public class PriorityQueue<T>
where T : IComparable {
#region member
private List<T> list;
private bool reverse;
#endregion
#region constructor
/// <summary>
///
/// </summary>
/// <param name="isReverse">定義された順序の逆で評価する</param>
public PriorityQueue(bool isReverse = false) {
list = new List<T>();
reverse = isReverse;
}
#endregion
#region private method
private bool compare(T a, T b) { return reverse ^ a.CompareTo(b) > 0; }
private void swap(int a, int b) {
T tmp = list[a];
list[a] = list[b];
list[b] = tmp;
}
#endregion
#region public method
/// <summary>
/// 要素を追加する
/// </summary>
/// <param name="item">追加する要素</param>
public void Push(T item) {
if (Length < list.Count)
list[Length] = item;
else
list.Add(item);
var pos = Length++;
while (pos != 0) {
var parent = (pos + 1) / 2 - 1;
if (compare(list[pos], list[parent]))
break;
swap(pos, parent);
pos = parent;
}
}
/// <summary>
/// 要素を追加する
/// </summary>
/// <param name="items">追加する要素の列</param>
public void Push(IEnumerable<T> items) {
foreach (var item in items) {
Push(item);
}
}
/// <summary>
/// 値を確認する
/// </summary>
/// <returns></returns>
public T Peek() { return list[0]; }
/// <summary>
/// 値を取り出す
/// </summary>
/// <returns></returns>
public T Pop() {
var ret = Peek();
var pos = 0;
list[0] = list[--Length];
while (2 * pos + 1 < Length) {
var child = 2 * pos + 1;
var child_other = 2 * pos + 2;
if (child_other < Length && compare(list[child], list[child_other])) {
child = child_other;
}
if (compare(list[child], list[pos]))
break;
swap(pos, child);
pos = child;
}
return ret;
}
/// <summary>
/// クリアする
/// </summary>
public void Clear() { list.Clear(); }
#endregion
#region property
/// <summary>
/// 要素の長さを取得する
/// </summary>
public int Length { get; private set; }
#endregion
}
public class IntPoint : IComparable, ICloneable {
#region member
public int X { get; private set; }
public int Y { get; private set; }
#endregion
#region constructor
public IntPoint(int x, int y) {
X = x;
Y = y;
}
public IntPoint() {
X = 0;
Y = 0;
}
#endregion
#region operator
public static IntPoint operator +(IntPoint a, IntPoint b) {
return new IntPoint(a.X + b.X, a.Y + b.Y);
}
public static IntPoint operator -(IntPoint a, IntPoint b) {
return new IntPoint(a.X - b.X, a.Y - b.Y);
}
public static bool operator ==(IntPoint a, IntPoint b) {
return a.X == b.X && a.Y == b.Y;
}
public static bool operator !=(IntPoint a, IntPoint b) { return !(a == b); }
public static bool operator>(IntPoint a, IntPoint b) {
if (a.X != b.X)
return a.X > b.Y;
else
return a.Y > b.Y;
}
public static bool operator >=(IntPoint a, IntPoint b) {
return a == b || (a > b);
}
public static bool operator<(IntPoint a, IntPoint b) { return !(a >= b); }
public static bool operator <=(IntPoint a, IntPoint b) { return !(a > b); }
#endregion
#region public method
/// <summary>
/// マンハッタン距離を取得する
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int GetManhattanDistance(IntPoint a, IntPoint b) {
return Math.Abs(a.X - b.X) + Math.Abs(a.Y - b.Y);
}
/// <summary>
/// ユークリッド距離を取得する
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static double GetEuclideanDistance(IntPoint a, IntPoint b) {
var tmp = a - b;
return Math.Sqrt(tmp.X * tmp.X + tmp.Y * tmp.Y);
}
#endregion
#region override or implementation
public int CompareTo(object obj) {
if (X != ((IntPoint)obj).X)
return X.CompareTo(((IntPoint)obj).X);
else
return Y.CompareTo(((IntPoint)obj).Y);
}
public override bool Equals(object obj) {
return this.X == ((IntPoint)obj).X && this.Y == ((IntPoint)obj).Y;
}
public override int GetHashCode() {
return X.GetHashCode() + (Y.GetHashCode() << 1);
}
public object Clone() { return new IntPoint(X, Y); }
#endregion
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 215], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 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, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 1,922
| 17
|
using System;
class Program {
static void Main(string[] args) {
string[] input =
Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得
int H = int.Parse(input[0]); //数値で受け取りたい場合は変換する
int W = int.Parse(input[1]);
string[] mapStr = new string[H];
for (int i = 0; i < H; i++) {
mapStr[i] = Console.ReadLine();
}
int[,] shortRouteMap = new int[H, W];
int blackNum = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
shortRouteMap[i, j] = -1;
if (mapStr[i].Substring(j, 1) == "#") {
blackNum++;
}
}
}
shortRouteMap[0, 0] = 0;
for (int i = 0; i < H * W; i++) {
for (int j = 0; j < H; j++) {
for (int h = 0; h < W; h++) {
int num = shortRouteMap[j, h];
if (num < 0 && mapStr[j].Substring(h, 1) == ".") {
int mawariMin = 100000;
if (j > 0) {
if (shortRouteMap[j - 1, h] >= 0 &&
shortRouteMap[j - 1, h] < mawariMin) {
mawariMin = shortRouteMap[j - 1, h];
}
}
if (j < H) {
if (shortRouteMap[j + 1, h] >= 0 &&
shortRouteMap[j + 1, h] < mawariMin) {
mawariMin = shortRouteMap[j + 1, h];
}
}
if (h > 0) {
if (shortRouteMap[j, h - 1] >= 0 &&
shortRouteMap[j, h - 1] < mawariMin) {
mawariMin = shortRouteMap[j, h - 1];
}
}
if (h < W) {
if (shortRouteMap[j, h + 1] >= 0 &&
shortRouteMap[j, h + 1] < mawariMin) {
mawariMin = shortRouteMap[j, h + 1];
}
}
if (mawariMin != 100000) {
shortRouteMap[j, h] = mawariMin + 1;
}
}
}
}
}
int answer = -1;
if (shortRouteMap[H, W] > 0) {
answer = H * W - (shortRouteMap[H, W] + 1) - blackNum;
}
// Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
// Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b,
// c);//改行付き出力
Console.WriteLine(answer.ToString());
}
}
|
using System;
class Program {
static void Main(string[] args) {
string[] input =
Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得
int H = int.Parse(input[0]); //数値で受け取りたい場合は変換する
int W = int.Parse(input[1]);
string[] mapStr = new string[H];
for (int i = 0; i < H; i++) {
mapStr[i] = Console.ReadLine();
}
int[,] shortRouteMap = new int[H, W];
int blackNum = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
shortRouteMap[i, j] = -1;
if (mapStr[i].Substring(j, 1) == "#") {
blackNum++;
}
}
}
shortRouteMap[0, 0] = 0;
for (int i = 0; i < H * W; i++) {
for (int j = 0; j < H; j++) {
for (int h = 0; h < W; h++) {
int num = shortRouteMap[j, h];
if (num < 0 && mapStr[j].Substring(h, 1) == ".") {
int mawariMin = 100000;
if (j > 0) {
if (shortRouteMap[j - 1, h] >= 0 &&
shortRouteMap[j - 1, h] < mawariMin) {
mawariMin = shortRouteMap[j - 1, h];
}
}
if (j < H - 1) {
if (shortRouteMap[j + 1, h] >= 0 &&
shortRouteMap[j + 1, h] < mawariMin) {
mawariMin = shortRouteMap[j + 1, h];
}
}
if (h > 0) {
if (shortRouteMap[j, h - 1] >= 0 &&
shortRouteMap[j, h - 1] < mawariMin) {
mawariMin = shortRouteMap[j, h - 1];
}
}
if (h < W - 1) {
if (shortRouteMap[j, h + 1] >= 0 &&
shortRouteMap[j, h + 1] < mawariMin) {
mawariMin = shortRouteMap[j, h + 1];
}
}
if (mawariMin != 100000) {
shortRouteMap[j, h] = mawariMin + 1;
}
}
}
}
}
int answer = -1;
if (shortRouteMap[H - 1, W - 1] > 0) {
answer = H * W - (shortRouteMap[H - 1, W - 1] + 1) - blackNum;
}
// Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
// Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b,
// c);//改行付き出力
Console.WriteLine(answer.ToString());
}
}
|
[["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 535
| 12
|
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[] aa = sc.LongArray();
long[] bb = sc.LongArray();
long countA = 0;
long countB = 0;
for (int i = 0; i < n; i++) {
long a = aa[i];
long b = bb[i];
if (a > b) {
countB += a - b;
} else if (b > a) {
countA += (b - a) % 2 == 0 ? b - a : b - a + 1;
}
}
string answer = countA >= 2 * countB ? "Yes" : "No";
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long n = sc.NextLong();
long[] aa = sc.LongArray();
long[] bb = sc.LongArray();
long countA = 0;
long countB = 0;
for (int i = 0; i < n; i++) {
long a = aa[i];
long b = bb[i];
if (a > b) {
countB += a - b;
} else if (b > a) {
if ((b - a) % 2 == 0) {
countA += b - a;
} else {
countA += b - a + 1;
countB++;
}
}
}
string answer = countA >= 2 * countB ? "Yes" : "No";
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 75, 57, 64, 196, 0, 57, 0, 121], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["-", 64, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["+", 0, 57, 75, 57, 64, 196, 0, 57, 0, 25], ["+", 75, 57, 64, 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], ["-", 64, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 57, 75, 57, 64, 196, 0, 57, 0, 95], ["+", 75, 57, 64, 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, 107], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 75, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 476
| 20
|
// C#練習
// 解説参照
// なぜ必要十分なのかも、2つ目の条件だけでよいのかも分からない
// intだと足りない?
using System;
using System.Linq;
public class AA {
public static void Main() {
int n = int.Parse(Console.ReadLine());
int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int[] b = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
long bai = 0;
for (int i = 0; i < n; i++) {
bai += Math.Max((b[i] - a[i] + 1) / 2, 0);
}
long abi = 0;
for (int i = 0; i < n; i++) {
abi += Math.Max(a[i] - b[i], 0);
}
long mx = b.Sum() - a.Sum();
if (mx - bai - abi >= 0) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
// C#練習
// 解説参照
// なぜ必要十分なのかも、2つ目の条件だけでよいのかも分からない
// intだと足りない?
using System;
using System.Linq;
public class AA {
public static void Main() {
int n = int.Parse(Console.ReadLine());
long[] a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
long[] b = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
long bai = 0;
for (int i = 0; i < n; i++) {
bai += Math.Max((b[i] - a[i] + 1) / 2, 0);
}
long abi = 0;
for (int i = 0; i < n; i++) {
abi += Math.Max(a[i] - b[i], 0);
}
long mx = b.Sum() - a.Sum();
if (mx >= bai & mx >= abi) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 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, 67], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 231
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
// using static System.Globalization.CultureInfo;
class Program {
static void Main(string[] args) {
var num = Add.num;
var ar1 = Add.arL;
var ar2 = Add.arL;
var dis = ar2.Sum() - ar1.Sum();
var ct = 0L;
for (var i = 0; i < num; i++) {
if (ar1[i] > ar2[i])
ct += ar1[i] - ar2[i];
else
ct += (ar2[i] - ar1[i] + 1) / 2;
}
WriteLine(ct <= dis ? "Yes" : "No");
}
}
public class Add {
public static string read => ReadLine();
public static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
public static int num => ToInt32(read);
public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
public static long numL => ToInt64(read);
public const string Alfa = "abcdefghijklmnopqrstuvwxyz";
public const int MOD = 1000000007;
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
// using static System.Globalization.CultureInfo;
class Program {
static void Main(string[] args) {
var num = Add.num;
var ar1 = Add.arL;
var ar2 = Add.arL;
var dis = ar2.Sum() - ar1.Sum();
var ct1 = 0L;
var ct2 = 0L;
for (var i = 0; i < num; i++) {
if (ar1[i] > ar2[i])
ct1 += ar1[i] - ar2[i];
else
ct2 += (ar2[i] - ar1[i] + 1) / 2;
}
WriteLine(ct1 <= dis && ct2 <= dis ? "Yes" : "No");
}
}
public class Add {
public static string read => ReadLine();
public static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
public static int num => ToInt32(read);
public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
public static long numL => ToInt64(read);
public const string Alfa = "abcdefghijklmnopqrstuvwxyz";
public const int MOD = 1000000007;
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 17, 19], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 98], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 31, 22]]
| 8
| 264
| 17
|
using System;
using System.Linq;
class Program {
public static void Main(string[] args) {
string[] s = Console.ReadLine().Split().ToArray();
int ab = int.Parse(s[0] + s[1]);
Console.WriteLine(judge(ab) ? "Yes" : "No");
}
public static bool judge(int a) {
for (int i = 1; i <= 100; i++) {
if (a / i == i)
return true;
}
return false;
}
}
|
using System;
using System.Linq;
class Program {
public static void Main(string[] args) {
string[] s = Console.ReadLine().Split().ToArray();
int ab = int.Parse(s[0] + s[1]);
Console.WriteLine(judge(ab) ? "Yes" : "No");
}
public static bool judge(int a) {
for (int i = 1; Math.Pow(i, 2) <= a; i++) {
if (a / i == i && a % i == 0)
return true;
}
return false;
}
}
|
[["+", 0, 7, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 7, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 7, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 7, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 7, 15, 16, 31, 213, 3, 4, 0, 21], ["+", 15, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 7, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 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, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 119
| 15
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _086_2 {
class Program {
static void Main(string[] args) {
string a = Console.ReadLine();
string[] str = Console.ReadLine().Split(' ');
int c = Convert.ToInt32(str[0] + str[1]);
int d = (int)Math.Sqrt(c);
int count = 0;
for (int i = 0; i <= d; ++i) {
if (c == i * i) {
count = count + 1;
}
}
if (count == 1) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _086_2 {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int c = Convert.ToInt32(str[0] + str[1]);
int d = (int)Math.Sqrt(c);
int count = 0;
for (int i = 0; i <= d; ++i) {
if (c == i * i) {
count = count + 1;
}
}
if (count == 1) {
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], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199]]
| 8
| 170
| 9
|
using System;
using System.Collections.Generic;
class TEST {
static List<int[]> testlist;
public static void Main() {
(int x, int y) nowPosition = (0, 0);
int N = int.Parse(Console.ReadLine());
testlist = new List<int[]>();
for (int i = 0; i < N; i++) {
string[] values = Console.ReadLine().Split(
new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
testlist.Add(GetStringtoInt(values));
}
for (int i = 0; i < testlist.Count; i++) {
int needTimeToMove = 0;
while (true) {
if (nowPosition.x == testlist[i][1] &&
nowPosition.y == testlist[i][2]) {
int value = GetNum(i);
if (value >= needTimeToMove && value % 2 == 0 &&
needTimeToMove % 2 == 0) {
break;
} else if (value >= needTimeToMove && value % 2 == 1 &&
needTimeToMove % 2 == 1) {
break;
} else {
Console.WriteLine("No");
return;
}
} else {
int sa = testlist[i][1] - nowPosition.x;
nowPosition.x += sa;
needTimeToMove += Math.Abs(sa);
sa = testlist[i][2] - nowPosition.y;
nowPosition.y += sa;
needTimeToMove += Math.Abs(sa);
}
}
}
Console.WriteLine("Yes");
}
static private int[] GetStringtoInt(string[] values) {
int[] values_i = new int[values.Length];
for (int i = 0; i < values.Length; i++) {
values_i[i] = int.Parse(values[i]);
}
return values_i;
}
static private int GetNum(int index) {
if (index == 0)
return 0;
return testlist[index][0] - testlist[index - 1][0];
}
}
|
using System;
using System.Collections.Generic;
class TEST {
static List<int[]> testlist;
public static void Main() {
(int x, int y) nowPosition = (0, 0);
int N = int.Parse(Console.ReadLine());
testlist = new List<int[]>();
for (int i = 0; i < N; i++) {
string[] values = Console.ReadLine().Split(
new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
testlist.Add(GetStringtoInt(values));
}
for (int i = 0; i < testlist.Count; i++) {
int needTimeToMove = 0;
while (true) {
if (nowPosition.x == testlist[i][1] &&
nowPosition.y == testlist[i][2]) {
int value = GetNum(i);
if (value >= needTimeToMove && value % 2 == 0 &&
needTimeToMove % 2 == 0)
break;
else if (value >= needTimeToMove && value % 2 == 1 &&
needTimeToMove % 2 == 1)
break;
else {
Console.WriteLine("No");
return;
}
} else {
int sa = testlist[i][1] - nowPosition.x;
nowPosition.x += sa;
needTimeToMove += Math.Abs(sa);
sa = testlist[i][2] - nowPosition.y;
nowPosition.y += sa;
needTimeToMove += Math.Abs(sa);
}
}
}
Console.WriteLine("Yes");
}
static private int[] GetStringtoInt(string[] values) {
int[] values_i = new int[values.Length];
for (int i = 0; i < values.Length; i++) {
values_i[i] = int.Parse(values[i]);
}
return values_i;
}
static private int GetNum(int index) {
if (index == 0)
return testlist[index][0];
return testlist[index][0] - testlist[index - 1][0];
}
}
|
[["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 64, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 57, 64, 37, 0, 204, 205, 204, 205, 22], ["+", 64, 37, 0, 204, 205, 204, 206, 207, 0, 70], ["+", 0, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 64, 37, 0, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 37, 0, 204, 206, 207, 0, 70], ["+", 0, 57, 64, 37, 0, 204, 206, 207, 0, 73]]
| 8
| 422
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
var txy = new List<List<int>>();
bool flag = true;
int ans = 0;
txy.Add("0 0 0".Split(' ').ToList().ConvertAll(x => int.Parse(x)));
for (int i = 0; i < n; i++) {
txy.Add(
Console.ReadLine().Split(' ').ToList().ConvertAll(x => int.Parse(x)));
}
for (int i = 0; i < n; i++) {
if ((txy[i + 1][0] - txy[i][0]) % 2 == 0) {
ans = Math.Abs(txy[i + 1][1] - txy[i][1]) +
Math.Abs(txy[i + 1][2] - txy[i][2]);
if (ans > (txy[i + 1][0] - txy[i][0])) {
flag = false;
break;
}
} else {
ans = Math.Abs(txy[i + 1][1] - txy[i][1]) +
Math.Abs(txy[i + 1][2] - txy[i][2]);
if (ans == 0 || ans > (txy[i + 1][0] - txy[i][0])) {
flag = false;
break;
}
}
}
if (flag) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
var txy = new List<List<int>>();
bool flag = true;
int ans = 0;
txy.Add("0 0 0".Split(' ').ToList().ConvertAll(x => int.Parse(x)));
for (int i = 0; i < n; i++) {
txy.Add(
Console.ReadLine().Split(' ').ToList().ConvertAll(x => int.Parse(x)));
}
for (int i = 0; i < n; i++) {
if ((txy[i + 1][0] - txy[i][0]) % 2 == 0) {
ans = Math.Abs(txy[i + 1][1] - txy[i][1]) +
Math.Abs(txy[i + 1][2] - txy[i][2]);
if (ans > (txy[i + 1][0] - txy[i][0]) || ans % 2 != 0) {
flag = false;
break;
}
} else {
ans = Math.Abs(txy[i + 1][1] - txy[i][1]) +
Math.Abs(txy[i + 1][2] - txy[i][2]);
if (ans % 2 == 0 || ans > (txy[i + 1][0] - txy[i][0])) {
flag = false;
break;
}
}
}
if (flag) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
[["+", 0, 57, 64, 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, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203]]
| 8
| 388
| 8
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static long GCM(long x, long y) {
if (x < y)
GCM(y, x);
while (y > 0) {
var z = y;
y = x % y;
x = z;
}
return x;
}
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var n = Read();
long t = 0, x = 0, y = 0;
long bx = 0, by = 0, bt = 0;
bool f = true;
for (int i = 0; i < n; i++) {
var txy = Reads();
t = txy[0];
x = txy[1];
y = txy[2];
var ff1 = t - bt >= Math.Abs(x - bx) + Math.Abs(y - by);
var ff2 = (t - bt - (Math.Abs(x - bx) + Math.Abs(y - by))) % 2 == 0;
bt = t;
bx = x;
by = y;
}
WriteLine(f ? "Yes" : "No");
Console.Out.Flush();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static long GCM(long x, long y) {
if (x < y)
GCM(y, x);
while (y > 0) {
var z = y;
y = x % y;
x = z;
}
return x;
}
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var n = Read();
long t = 0, x = 0, y = 0;
long bx = 0, by = 0, bt = 0;
bool f = true;
for (int i = 0; i < n; i++) {
var txy = Reads();
t = txy[0];
x = txy[1];
y = txy[2];
var ff = t - bt >= Math.Abs(x - bx) + Math.Abs(y - by) &&
(t - bt - (Math.Abs(x - bx) + Math.Abs(y - by))) % 2 == 0;
if (!ff)
f = false;
bt = t;
bx = x;
by = y;
}
WriteLine(f ? "Yes" : "No");
Console.Out.Flush();
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 98], ["+", 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], ["+", 0, 7, 8, 196, 0, 57, 15, 241, 0, 111], ["+", 0, 7, 8, 196, 0, 57, 15, 241, 0, 22], ["+", 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, 211, 0, 147]]
| 8
| 347
| 16
|
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
namespace ChokudaiScanner {
class MainClass {
static void Main() {
Scanner cin = new Scanner();
int N = cin.NextInt() + 1;
int[][] vs = new int [N][];
vs[0] = new int[3];
for (int i = 1; i < N; i++) {
vs[i] = cin.ArrayInt(3);
}
string ans = "Yes";
for (int i = 0; i < N; i++) {
int dt = vs[i + 1][0] - vs[i][0];
int dist =
Math.Abs(vs[i + 1][1] - vs[i][1]) + Math.Abs(vs[i + 1][2] - vs[i][2]);
if (dt < dist) {
ans = "No";
break;
}
if (dt % 2 != dist % 2) {
ans = "No";
break;
}
}
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 string[] ArrayNext(int N) {
string[] Array = new string[N];
for (int i = 0; i < N; i++) {
Array[i] = Next();
}
return Array;
}
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.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
namespace ChokudaiScanner {
class MainClass {
static void Main() {
Scanner cin = new Scanner();
int N = cin.NextInt() + 1;
int[][] vs = new int [N][];
vs[0] = new int[3];
for (int i = 1; i < N; i++) {
vs[i] = cin.ArrayInt(3);
}
string ans = "Yes";
for (int i = 1; i < vs.Length; i++) {
int dt = vs[i][0] - vs[i - 1][0];
int dist =
Math.Abs(vs[i][1] - vs[i - 1][1]) + Math.Abs(vs[i][2] - vs[i - 1][2]);
if (dt < dist) {
ans = "No";
break;
}
if (dt % 2 != dist % 2) {
ans = "No";
break;
}
}
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 string[] ArrayNext(int N) {
string[] Array = new string[N];
for (int i = 0; i < N; i++) {
Array[i] = Next();
}
return Array;
}
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], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 644
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC086C {
class Program {
static void Main(string[] args) {
int count = int.Parse(Console.ReadLine());
var points = new List<Point>();
points.Add(new Point(0, 0, 0));
for (int i = 0; i < count; i++) {
var input =
Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
points.Add(new Point(input[0], input[1], input[2]));
}
bool result = false;
for (int i = 1; i < points.Count(); i++) {
if (!points[i].IsMovable(points[i - 1])) {
result = true;
break;
}
}
Console.WriteLine(result ? "YES" : "NO");
}
}
class Point {
public Point(int time, int x, int y) {
Time = time;
X = x;
Y = y;
}
public int Time { get; }
public int X { get; }
public int Y { get; }
public bool IsMovable(Point previous) {
int dt = this.Time - previous.Time;
int movingX = this.X - previous.X;
int movingY = this.Y - previous.Y;
int moving = movingX + movingY;
if (dt == moving) {
return true;
}
if ((dt - moving) % 2 == 0) {
return true;
}
return false;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC086C {
class Program {
static void Main(string[] args) {
int count = int.Parse(Console.ReadLine());
var points = new List<Point>();
points.Add(new Point(0, 0, 0));
for (int i = 0; i < count; i++) {
var input =
Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
points.Add(new Point(input[0], input[1], input[2]));
}
bool result = true;
for (int i = 1; i < points.Count(); i++) {
if (!points[i].IsMovable(points[i - 1])) {
result = false;
break;
}
}
Console.WriteLine(result ? "Yes" : "No");
}
}
class Point {
public Point(int time, int x, int y) {
Time = time;
X = x;
Y = y;
}
public int Time { get; }
public int X { get; }
public int Y { get; }
public bool IsMovable(Point previous) {
int dt = this.Time - previous.Time;
int movingX = this.X - previous.X;
int movingY = this.Y - previous.Y;
int moving = movingX + movingY;
if (dt < moving) {
return false;
}
if (dt == moving) {
return true;
}
if (dt > moving) {
if ((dt - moving) % 2 == 0) {
return true;
}
}
return false;
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 146], ["-", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 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], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 37, 0, 211, 0, 147], ["+", 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, 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, 47], ["+", 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, 64, 196, 0, 46]]
| 8
| 340
| 27
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
// 整数の入力
//// スペース区切りの整数の入力
int N = int.Parse(Console.ReadLine());
int[] t = new int[N + 1];
int[] x = new int[N + 1];
int[] y = new int[N + 1];
t[0] = 0;
x[0] = 0;
y[0] = 0;
for (int i = 1; i < N + 1; i++) {
string[] input = Console.ReadLine().Split(' ');
t[i] = int.Parse(input[0]);
x[i] = int.Parse(input[1]);
y[i] = int.Parse(input[2]);
}
//出力
Console.WriteLine(hantei(N, t, x, y));
}
private static string hantei(int N, int[] t, int[] x, int[] y) {
for (int j = 1; j < N + 1; j++) {
int distance = Math.Abs(x[j] - x[j - 1]) + Math.Abs(y[j] - y[j - 1]);
int time = t[j] - t[j - 1];
if (distance < time && time - distance % 2 == 1) {
continue;
} else {
return "No";
}
}
return "Yes";
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
// 整数の入力
//// スペース区切りの整数の入力
int N = int.Parse(Console.ReadLine());
int[] t = new int[N + 1];
int[] x = new int[N + 1];
int[] y = new int[N + 1];
t[0] = 0;
x[0] = 0;
y[0] = 0;
for (int i = 1; i < N + 1; i++) {
string[] input = Console.ReadLine().Split(' ');
t[i] = int.Parse(input[0]);
x[i] = int.Parse(input[1]);
y[i] = int.Parse(input[2]);
}
//出力
Console.WriteLine(hantei(N, t, x, y));
}
private static string hantei(int N, int[] t, int[] x, int[] y) {
for (int j = 1; j < N + 1; j++) {
int distance = Math.Abs(x[j] - x[j - 1]) + Math.Abs(y[j] - y[j - 1]);
int time = t[j] - t[j - 1];
if (distance <= time &&
(distance == time || (time - distance) % 2 == 0)) {
continue;
} else {
return "No";
}
}
return "Yes";
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 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, 60], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 106], ["+", 0, 16, 12, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 12, 16, 31, 16, 31, 23, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
| 8
| 323
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
static void Main(string[] args) { Question.Exec(); }
}
public class Plane {
public long Time;
public long X;
public long Y;
}
public static class Question {
public static void Exec() {
long n = int.Parse(Console.ReadLine());
List<Plane> list = new List<Plane>();
var p = new Plane();
p.Time = 0;
p.X = 0;
p.Y = 0;
list.Add(p);
for (var j = 0; j < n; ++j) {
var array =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
var plane = new Plane();
plane.Time = array[0];
plane.X = array[1];
plane.Y = array[2];
list.Add(plane);
}
string answer = "Yes";
for (var j = 1; j <= n; ++j) {
long time = list[j].Time - list[j - 1].Time;
long x = list[j].X - list[j - 1].X;
long y = list[j].Y - list[j - 1].Y;
if (x + y > time) {
answer = "No";
break;
}
if ((x + y) % 2 != time % 2) {
answer = "No";
break;
}
}
Console.WriteLine($"{answer}");
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
static void Main(string[] args) { Question.Exec(); }
}
public class Plane {
public long Time;
public long X;
public long Y;
}
public static class Question {
public static void Exec() {
long n = int.Parse(Console.ReadLine());
List<Plane> list = new List<Plane>();
var p = new Plane();
p.Time = 0;
p.X = 0;
p.Y = 0;
list.Add(p);
for (var j = 0; j < n; ++j) {
var array =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
var plane = new Plane();
plane.Time = array[0];
plane.X = array[1];
plane.Y = array[2];
list.Add(plane);
}
string answer = "Yes";
for (var j = 1; j <= n; ++j) {
long time = list[j].Time - list[j - 1].Time;
long x = Math.Abs(list[j].X - list[j - 1].X);
long y = Math.Abs(list[j].Y - list[j - 1].Y);
if (x + y > time) {
answer = "No";
break;
}
if ((x + y) % 2 != time % 2) {
answer = "No";
break;
}
}
Console.WriteLine($"{answer}");
Console.ReadKey();
}
}
}
|
[["+", 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
| 366
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
var n = int.Parse(Console.ReadLine());
var ok = true;
var x = 0;
var y = 0;
for (var i = 0; i < n; ++i) {
var t = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }),
number => int.Parse(number));
var def = Math.Abs(t[1] - x) + Math.Abs(t[2] - y);
if (def > t[0]) {
ok = false;
} else if (def < t[0]) {
if ((t[0] - def) % 2 == 1) {
ok = false;
}
}
x = t[1];
y = t[2];
}
if (ok) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
//デバッグ実行での確認用。そのまま提出しても問題なし
Console.ReadKey();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
var n = int.Parse(Console.ReadLine());
var ok = true;
var time = 0;
var x = 0;
var y = 0;
for (var i = 0; i < n; ++i) {
var t = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }),
number => int.Parse(number));
var currentTime = t[0] - time;
var def = Math.Abs(t[1] - x) + Math.Abs(t[2] - y);
if (def > currentTime) {
ok = false;
} else if (def < currentTime) {
if ((currentTime - def) % 2 == 1) {
ok = false;
}
}
time = t[0];
x = t[1];
y = t[2];
}
if (ok) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
//デバッグ実行での確認用。そのまま提出しても問題なし
Console.ReadKey();
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 200, 0, 212, 0, 16, 31, 204, 205, 22], ["+", 0, 212, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 212, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 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, 7, 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], ["-", 31, 16, 31, 23, 0, 16, 31, 204, 205, 22], ["-", 31, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 229
| 37
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC086C {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var strlist = new List<string>();
for (var i = 0; i < n; i++) {
strlist.AddRange(Console.ReadLine().Split(' ').ToList());
}
var intlist = strlist.ConvertAll(int.Parse);
var timelist = new List<int>();
var xlist = new List<int>();
var ylist = new List<int>();
for (var i = 0; i < intlist.Count; i++) {
var assigner = i % 3;
switch (assigner) {
case 0:
timelist.Add(intlist[i]);
break;
case 1:
xlist.Add(intlist[i]);
break;
case 2:
ylist.Add(intlist[i]);
break;
}
}
var flag = true;
for (int i = 0; i < n; i++) {
int difft = timelist[i + 1] - timelist[i];
int diffx = xlist[i + 1] - xlist[i];
int diffy = ylist[i + 1] - ylist[i];
if (diffx + diffy > difft || (diffx + diffy) % 2 != difft % 2) {
flag = false;
break;
}
}
Console.WriteLine(flag ? "Yes" : "No");
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC086C {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var strlist = new List<string>();
for (var i = 0; i < n; i++) {
strlist.AddRange(Console.ReadLine().Split(' ').ToList());
}
var intlist = strlist.ConvertAll(int.Parse);
var timelist = new List<int>() { 0 };
var xlist = new List<int>() { 0 };
var ylist = new List<int>() { 0 };
for (var i = 0; i < intlist.Count; i++) {
var assigner = i % 3;
switch (assigner) {
case 0:
timelist.Add(intlist[i]);
break;
case 1:
xlist.Add(intlist[i]);
break;
case 2:
ylist.Add(intlist[i]);
break;
}
}
var flag = true;
for (int i = 0; i < n; i++) {
int difft = timelist[i + 1] - timelist[i];
int diffx = xlist[i + 1] - xlist[i];
int diffy = ylist[i + 1] - ylist[i];
diffx = Math.Abs(diffx);
diffy = Math.Abs(diffy);
if (diffx + diffy > difft || (diffx + diffy) % 2 != difft % 2) {
flag = false;
break;
}
}
Console.WriteLine(flag ? "Yes" : "No");
Console.ReadLine();
}
}
}
|
[["+", 0, 200, 0, 212, 0, 230, 10, 229, 0, 45], ["+", 0, 200, 0, 212, 0, 230, 10, 229, 0, 203], ["+", 0, 200, 0, 212, 0, 230, 10, 229, 0, 46], ["+", 8, 196, 0, 7, 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, 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, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 345
| 27
|
using System;
namespace AtCoder09_09 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
bool flag = true;
for (int i = 0; i < N; i++) {
string[] txy = Console.ReadLine().Split(' ');
int t = int.Parse(txy[0]);
int x = int.Parse(txy[1]);
int y = int.Parse(txy[2]);
if (t < x + y || t % 2 != (x + y) % 2) {
flag = false;
break;
}
}
if (flag) {
Console.WriteLine("Yes");
}
}
}
}
|
using System;
namespace AtCoder09_09 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
for (int i = 0; i < N; i++) {
string[] txy = Console.ReadLine().Split(' ');
int t = int.Parse(txy[0]);
int x = int.Parse(txy[1]);
int y = int.Parse(txy[2]);
if (t < x + y || t % 2 != (x + y) % 2) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
}
|
[["-", 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, 146], ["-", 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, 147], ["+", 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, 93, 0, 94], ["+", 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], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 15, 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
| 157
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using System.IO;
namespace AtCoder.ABC {
using AtCoder.ABC.IO;
public class A {
public void Solve(Parser parser, Printer printer) {
int n = parser.Integer();
var points = Enumerable.Range(1, n)
.Select(_ => parser.Integer(3))
.Select(p => new Point() {
T = p[0],
X = p[1],
Y = p[2],
})
.ToArray();
var got = Solve(points) ? "Yes" : "No";
printer.Write(got);
printer.WriteLine();
printer.Flush();
}
private bool Solve(Point[] points) {
var from = new Point();
foreach (var to in points) {
if (!CanReach(to, from)) {
return false;
}
}
return true;
}
private bool CanReach(Point from, Point to) {
int dt = to.T - from.T;
int dx = to.X - from.X;
int dy = to.Y - from.Y;
int dp = Math.Abs(dx) + Math.Abs(dy);
if (dt < dp) {
return false;
}
return dp % 2 == dt % 2;
}
public class Point {
public int T;
public int X;
public int Y;
}
}
static class Program {
static void Main(string[] args) {
var i = new Parser(Console.OpenStandardInput());
var o = new Printer(Console.OpenStandardOutput());
new A().Solve(i, o);
}
}
}
namespace AtCoder.ABC.IO {
#region IO
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; }
}
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
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using System.IO;
namespace AtCoder.ABC {
using AtCoder.ABC.IO;
public class A {
public void Solve(Parser parser, Printer printer) {
int n = parser.Integer();
var points = Enumerable.Range(1, n)
.Select(_ => parser.Integer(3))
.Select(p => new Point() {
T = p[0],
X = p[1],
Y = p[2],
})
.ToArray();
var got = Solve(points) ? "Yes" : "No";
printer.Write(got);
printer.WriteLine();
printer.Flush();
}
private bool Solve(Point[] points) {
var from = new Point();
foreach (var to in points) {
if (!CanReach(from, to)) {
return false;
}
from = to;
}
return true;
}
private bool CanReach(Point from, Point to) {
int dt = to.T - from.T;
int dx = to.X - from.X;
int dy = to.Y - from.Y;
int dp = Math.Abs(dx) + Math.Abs(dy);
if (dt < dp) {
return false;
}
return dp % 2 == dt % 2;
}
public class Point {
public int T;
public int X;
public int Y;
}
}
static class Program {
static void Main(string[] args) {
var i = new Parser(Console.OpenStandardInput());
var o = new Printer(Console.OpenStandardOutput());
new A().Solve(i, o);
}
}
}
namespace AtCoder.ABC.IO {
#region IO
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; }
}
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
}
|
[["-", 15, 241, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 57, 15, 241, 0, 213, 3, 4, 0, 21], ["+", 0, 57, 15, 241, 0, 213, 3, 4, 0, 21], ["+", 15, 241, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 22, 0, 314], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35]]
| 8
| 1,148
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder.ABC10 {
static class Program {
static void Main(string[] args) {
var q = new Quest(Console.In, Console.Out);
new C086().Solve(q);
}
}
public class C086 : ISolver {
public void Solve(Quest q) {
int n = int.Parse(q.ParseLine());
var points = Enumerable.Range(1, n)
.Select(_ => q.ParseLine(' '))
.Select(x => x.Select(s => int.Parse(s)).ToArray())
.Select(p => new Point(p[1], p[2], p[0]))
.ToArray();
foreach (var p in points) {
q.Answer(p);
}
string got = Solve(points) ? "Yes" : "No";
q.Answer(got);
}
public bool Solve(Point[] plans) {
var from = new Point(0, 0, 0);
foreach (var to in plans) {
if (!CanReach(from, to)) {
return false;
}
from = to;
}
return true;
}
private bool CanReach(Point from, Point to) {
int dt = to.T - from.T;
int dx = Math.Abs(to.X - from.X);
int dy = Math.Abs(to.Y - from.Y);
int dp = dx + dy;
if (dt < dp) {
return false;
}
return dp % 2 == dt % 2;
}
public struct Point {
public int X;
public int Y;
public int T;
public Point(int x, int y, int t) {
X = x;
Y = y;
T = t;
}
public override string ToString() { return $"{T},{X},{Y}"; }
}
}
#region
public class Quest {
private readonly System.IO.TextReader _reader;
private readonly System.IO.TextWriter _writer;
public Quest(System.IO.TextReader reader, System.IO.TextWriter writer) {
_reader = reader;
_writer = writer;
}
public void Answer(object answer) { _writer.WriteLine(answer); }
public string ParseLine() { return _reader.ReadLine(); }
public string[] ParseLine(char sep) {
return _reader.ReadLine().Split(new char[] { sep });
}
}
public interface ISolver {
void Solve(Quest q);
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder.ABC10 {
static class Program {
static void Main(string[] args) {
var q = new Quest(Console.In, Console.Out);
new C086().Solve(q);
}
}
public class C086 : ISolver {
public void Solve(Quest q) {
int n = int.Parse(q.ParseLine());
var points = Enumerable.Range(1, n)
.Select(_ => q.ParseLine(' '))
.Select(x => x.Select(s => int.Parse(s)).ToArray())
.Select(p => new Point(p[1], p[2], p[0]))
.ToArray();
string got = Solve(points) ? "Yes" : "No";
q.Answer(got);
}
public bool Solve(Point[] plans) {
var from = new Point(0, 0, 0);
foreach (var to in plans) {
if (!CanReach(from, to)) {
return false;
}
from = to;
}
return true;
}
private bool CanReach(Point from, Point to) {
int dt = to.T - from.T;
int dx = Math.Abs(to.X - from.X);
int dy = Math.Abs(to.Y - from.Y);
int dp = dx + dy;
if (dt < dp) {
return false;
}
return dp % 2 == dt % 2;
}
public struct Point {
public int X;
public int Y;
public int T;
public Point(int x, int y, int t) {
X = x;
Y = y;
T = t;
}
public override string ToString() { return $"{T},{X},{Y}"; }
}
}
#region
public class Quest {
private readonly System.IO.TextReader _reader;
private readonly System.IO.TextWriter _writer;
public Quest(System.IO.TextReader reader, System.IO.TextWriter writer) {
_reader = reader;
_writer = writer;
}
public void Answer(object answer) { _writer.WriteLine(answer); }
public string ParseLine() { return _reader.ReadLine(); }
public string[] ParseLine(char sep) {
return _reader.ReadLine().Split(new char[] { sep });
}
}
public interface ISolver {
void Solve(Quest q);
}
#endregion
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 24], ["-", 0, 195, 8, 196, 0, 210, 39, 216, 0, 217], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 25], ["-", 0, 195, 8, 196, 0, 210, 8, 196, 0, 45], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46]]
| 8
| 536
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
class Program {
static void Main() {
int N = int.Parse(Console.ReadLine());
var txyList = Enumerable.Range(0, N)
.Select(n => Console.ReadLine())
.Select(s => s.Split(' '))
.Select(arr => arr.Select(s => int.Parse(s)).ToArray())
.Select(arr => new { t = arr[0], x = arr[1], y = arr[2] })
.ToList();
bool isOK = true;
foreach (var itm in txyList.Zip(txyList.Skip(1),
(elm1, elm2) => new { elm1, elm2 })) {
var current = itm.elm1;
var next = itm.elm2;
var time = next.t - current.t;
var distance =
Math.Abs(current.x - next.x) + Math.Abs(current.y - next.y);
if (time < distance || (time - distance) % 2 != 0) {
isOK = false;
break;
}
}
Console.WriteLine(isOK ? "Yes" : "No");
}
static long calcGCD(long num1, long num2) {
if (num1 < num2) {
var tmp = num1;
num1 = num2;
num2 = tmp;
}
while (true) {
long res;
long div = Math.DivRem(num1, num2, out res);
if (res == 0) {
return num2;
} else {
num1 = num2;
num2 = res;
}
}
}
}
static class MathUtil {
public static T Max<T>(params T[] datas) { return datas.Max(); }
public static T Min<T>(params T[] datas) { return datas.Min(); }
public static IEnumerable<IEnumerable<int>> GetPermutation(int n) {
if (n == 0) {
yield return Single(0);
yield break;
}
for (int i = 0; i <= n; i++) {
foreach (var x in GetPermutation(n - 1)) {
yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
}
}
}
private static IEnumerable<int> Single(int x) { yield return x; }
public static IEnumerable<int> EnumeratePrimeNumbers() {
List<int> primes = new List<int>() { 2 };
yield return 2;
for (int i = 3; i < int.MaxValue; i++) {
bool isPrime = true;
int Sqrt = (int)Math.Sqrt(i) + 1;
foreach (var prime in primes) {
if (prime > Sqrt) {
break;
}
if (i % prime == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.Add(i);
yield return i;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
class Program {
static void Main() {
int N = int.Parse(Console.ReadLine());
var txyList = Enumerable.Range(0, N)
.Select(n => Console.ReadLine())
.Select(s => s.Split(' '))
.Select(arr => arr.Select(s => int.Parse(s)).ToArray())
.Select(arr => new { t = arr[0], x = arr[1], y = arr[2] })
.ToList();
txyList.Insert(0, new { t = 0, x = 0, y = 0 });
bool isOK = true;
foreach (var itm in txyList.Zip(txyList.Skip(1),
(elm1, elm2) => new { elm1, elm2 })) {
var current = itm.elm1;
var next = itm.elm2;
var time = next.t - current.t;
var distance =
Math.Abs(current.x - next.x) + Math.Abs(current.y - next.y);
if (time < distance || (time - distance) % 2 != 0) {
isOK = false;
break;
}
}
Console.WriteLine(isOK ? "Yes" : "No");
}
static long calcGCD(long num1, long num2) {
if (num1 < num2) {
var tmp = num1;
num1 = num2;
num2 = tmp;
}
while (true) {
long res;
long div = Math.DivRem(num1, num2, out res);
if (res == 0) {
return num2;
} else {
num1 = num2;
num2 = res;
}
}
}
}
static class MathUtil {
public static T Max<T>(params T[] datas) { return datas.Max(); }
public static T Min<T>(params T[] datas) { return datas.Min(); }
public static IEnumerable<IEnumerable<int>> GetPermutation(int n) {
if (n == 0) {
yield return Single(0);
yield break;
}
for (int i = 0; i <= n; i++) {
foreach (var x in GetPermutation(n - 1)) {
yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
}
}
}
private static IEnumerable<int> Single(int x) { yield return x; }
public static IEnumerable<int> EnumeratePrimeNumbers() {
List<int> primes = new List<int>() { 2 };
yield return 2;
for (int i = 3; i < int.MaxValue; i++) {
bool isPrime = true;
int Sqrt = (int)Math.Sqrt(i) + 1;
foreach (var prime in primes) {
if (prime > Sqrt) {
break;
}
if (i % prime == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.Add(i);
yield return i;
}
}
}
}
|
[["+", 8, 196, 0, 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, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 312, 0, 228], ["+", 0, 213, 3, 4, 0, 28, 0, 312, 0, 45], ["+", 3, 4, 0, 28, 0, 312, 0, 313, 0, 22], ["+", 3, 4, 0, 28, 0, 312, 0, 313, 0, 32], ["+", 0, 213, 3, 4, 0, 28, 0, 312, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 312, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 312, 0, 46], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 647
| 22
|
using System;
using System.Linq;
using System.Collections.Generic;
class Cmondai {
static void Main() {
var N = Int32.Parse(Console.ReadLine());
var beforeT = 0;
var beforeX = 0;
var beforeY = 0;
var ans = "No";
for (int i = 0; i < N; ++i) {
var line =
Console.ReadLine().Split(' ').Select(o => Int32.Parse(o)).ToArray();
var currentT = line[0];
var currentX = line[1];
var currentY = line[2];
var t = currentT - beforeT;
var x = Math.Abs(beforeX - currentX);
var y = Math.Abs(beforeY - currentY);
var sa = x + y;
if (t < sa)
break;
if ((sa % 2 == 0 && t % 2 == 0) || (sa % 2 == 1 && t % 2 == 1))
ans = "Yes";
else
break;
{
beforeT = currentT;
beforeX = currentX;
beforeY = currentY;
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Cmondai {
static void Main() {
var N = Int32.Parse(Console.ReadLine());
var beforeT = 0;
var beforeX = 0;
var beforeY = 0;
var ans = "Yes";
for (int i = 0; i < N; ++i) {
var line =
Console.ReadLine().Split(' ').Select(o => Int32.Parse(o)).ToArray();
var currentT = line[0];
var currentX = line[1];
var currentY = line[2];
var t = currentT - beforeT;
var x = Math.Abs(beforeX - currentX);
var y = Math.Abs(beforeY - currentY);
var sa = x + y;
if ((t < sa) || (sa % 2 == 0 && t % 2 == 1) ||
(sa % 2 == 1 && t % 2 == 0)) {
ans = "No";
break;
}
{
beforeT = currentT;
beforeX = currentX;
beforeY = currentY;
}
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["-", 15, 16, 31, 23, 0, 16, 12, 16, 12, 203], ["+", 31, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 240
| 17
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC86 {
class Program {
static void Main(string[] args) {
var solver = new Solver();
solver.Solve3();
}
}
public class Solver {
public void Solve1() {
var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
Console.WriteLine(ab[0] * ab[1] % 2 == 0 ? "Even" : "Odd");
}
public void Solve2() {
var ab = int.Parse(Console.ReadLine().Replace(" ", ""));
Console.WriteLine(Math.Sqrt(ab) - (int)Math.Sqrt(ab) == 0 ? "Yes" : "No");
}
struct Txy {
public long T;
public long X;
public long Y;
}
public void Solve3() {
var n = int.Parse(Console.ReadLine());
var txys = new List<Txy> { new Txy { T = 0, X = 0, Y = 0 } };
for (int i = 0; i < n; i++) {
var txy = Console.ReadLine().Split().Select(long.Parse).ToArray();
txys.Add(new Txy { T = txy[0], X = txy[1], Y = txy[2] });
}
for (int i = 0; i < n; i++) {
if (txys.ElementAt(i + 1).T - txys.ElementAt(i).T !=
Math.Abs(txys.ElementAt(i + 1).X - txys.ElementAt(i).X) +
Math.Abs(txys.ElementAt(i + 1).Y - txys.ElementAt(i).Y)) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC86 {
class Program {
static void Main(string[] args) {
var solver = new Solver();
solver.Solve3();
}
}
public class Solver {
public void Solve1() {
var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
Console.WriteLine(ab[0] * ab[1] % 2 == 0 ? "Even" : "Odd");
}
public void Solve2() {
var ab = int.Parse(Console.ReadLine().Replace(" ", ""));
Console.WriteLine(Math.Sqrt(ab) - (int)Math.Sqrt(ab) == 0 ? "Yes" : "No");
}
struct Txy {
public long T;
public long X;
public long Y;
}
public void Solve3() {
var n = int.Parse(Console.ReadLine());
var txys = new List<Txy> { new Txy { T = 0, X = 0, Y = 0 } };
for (int i = 0; i < n; i++) {
var txy = Console.ReadLine().Split().Select(long.Parse).ToArray();
txys.Add(new Txy { T = txy[0], X = txy[1], Y = txy[2] });
}
for (int i = 0; i < n; i++) {
var judge = txys.ElementAt(i + 1).T - txys.ElementAt(i).T -
(Math.Abs(txys.ElementAt(i + 1).X - txys.ElementAt(i).X) +
Math.Abs(txys.ElementAt(i + 1).Y - txys.ElementAt(i).Y));
if (judge >= 0 && judge % 2 == 0) {
} else {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
}
|
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 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, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 12, 213, 3, 4, 0, 25], ["+", 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, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 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, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
| 8
| 417
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
class Program {
static void Main(string[] args) {
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// var N = line1[0];
// var M = line1[1];
// var a = new long[M];
// var b = new long[M];
// int bridge = 0;
// int[,] dag = new int[N,N];
// for (int i = 0; i < M; i++)
//{
// var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// a[i] = line2[0]-1;
// b[i] = line2[1]-1;
// dag[a[i], b[i]] = 1;
// dag[b[i], a[i]] = 1;
//}
// for (int i = 0; i < M; i++)
//{
// bool[] visited = new bool[N];
// dag[a[i], b[i]] = 0;
// dag[b[i], a[i]] = 0;
// DFS(0,visited,dag);
// if (visited.Where(n => n == true).Count() != N)
// {
// bridge++;
// }
// dag[a[i], b[i]] = 1;
// dag[b[i], a[i]] = 1;
//}
// Console.WriteLine(bridge);
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// var A = line1[0];
// var B = line1[1];
// var C = line1[2];
// var D = line1[3];
// var E = line1[4];
// var F = line1[5];
// var N = int.Parse(Console.ReadLine());
// char[] mozi = new char[N];
// long[] MARCH = new long[5];
// long cnt = 0;
// for (int i = 0; i < N; i++)
//{
// mozi[i] = Console.ReadLine().ToCharArray()[0];
//}
// MARCH[0] = mozi.Where(n => n == 'M').Count();
// MARCH[1] = mozi.Where(n => n == 'A').Count();
// MARCH[2] = mozi.Where(n => n == 'R').Count();
// MARCH[3] = mozi.Where(n => n == 'C').Count();
// MARCH[4] = mozi.Where(n => n == 'H').Count();
// for (int i = 0; i < 3; i++)
//{
// for (int j = i + 1; j < 4; j++)
// {
// for (int k = j + 1; k < 5; k++)
// {
// cnt += MARCH[i] * MARCH[j] * MARCH[k];
// }
// }
//}
// Console.WriteLine(cnt);
// var N = int.Parse(Console.ReadLine());
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// int candy = 0;
// int MAX = 0;
// for (int i = 0; i < N; i++)
//{
// for (int k = 0; k <= i; k++)
// {
// candy += line1[k];
// }
// for (int j = N - 1; j >= i; j--)
// {
// candy += line2[j];
// }
// MAX = Math.Max(candy,MAX);
// candy = 0;
//}
// Console.WriteLine(MAX);
var N = int.Parse(Console.ReadLine());
List<int[]> list = new List<int[]>();
int t = 0;
int x = 0;
int y = 0;
for (int i = 0; i < N; i++) {
var txy = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
list.Add(txy);
}
foreach (var item in list) {
if (item[0] - t <= item[1] + item[2] ||
item[0] + t >= item[1] + item[2]) {
if (((item[0] - t) % 2 == 1 &&
Math.Abs(x + y - item[1] - item[2]) % 2 == 1) ||
((item[0] - t) % 2 == 0 &&
Math.Abs(x + y - item[1] - item[2]) % 2 == 0)) {
t = item[0];
x = item[1];
y = item[2];
} else {
Console.WriteLine("No");
return;
}
} else {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
public static void DFS(int v, bool[] visited, int[,] dag) {
visited[v] = true;
for (int i = 0; i < visited.Length; i++) {
if (dag[v, i] == 0)
continue;
if (visited[i])
continue;
DFS(i, visited, dag);
}
}
public static long LowerBound<T>(T[] arr, long start, long end, T value,
IComparer<T> comparer) {
long low = start;
long high = end;
long mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static long LowerBound<T>(T[] arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
public static long UpperBound<T>(T[] arr, long start, long end, T value,
IComparer<T> comparer) {
long low = start;
long high = end;
long mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static long UpperBound<T>(T[] arr, T value) {
return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
class Program {
static void Main(string[] args) {
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// var N = line1[0];
// var M = line1[1];
// var a = new long[M];
// var b = new long[M];
// int bridge = 0;
// int[,] dag = new int[N,N];
// for (int i = 0; i < M; i++)
//{
// var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// a[i] = line2[0]-1;
// b[i] = line2[1]-1;
// dag[a[i], b[i]] = 1;
// dag[b[i], a[i]] = 1;
//}
// for (int i = 0; i < M; i++)
//{
// bool[] visited = new bool[N];
// dag[a[i], b[i]] = 0;
// dag[b[i], a[i]] = 0;
// DFS(0,visited,dag);
// if (visited.Where(n => n == true).Count() != N)
// {
// bridge++;
// }
// dag[a[i], b[i]] = 1;
// dag[b[i], a[i]] = 1;
//}
// Console.WriteLine(bridge);
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// var A = line1[0];
// var B = line1[1];
// var C = line1[2];
// var D = line1[3];
// var E = line1[4];
// var F = line1[5];
// var N = int.Parse(Console.ReadLine());
// char[] mozi = new char[N];
// long[] MARCH = new long[5];
// long cnt = 0;
// for (int i = 0; i < N; i++)
//{
// mozi[i] = Console.ReadLine().ToCharArray()[0];
//}
// MARCH[0] = mozi.Where(n => n == 'M').Count();
// MARCH[1] = mozi.Where(n => n == 'A').Count();
// MARCH[2] = mozi.Where(n => n == 'R').Count();
// MARCH[3] = mozi.Where(n => n == 'C').Count();
// MARCH[4] = mozi.Where(n => n == 'H').Count();
// for (int i = 0; i < 3; i++)
//{
// for (int j = i + 1; j < 4; j++)
// {
// for (int k = j + 1; k < 5; k++)
// {
// cnt += MARCH[i] * MARCH[j] * MARCH[k];
// }
// }
//}
// Console.WriteLine(cnt);
// var N = int.Parse(Console.ReadLine());
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// int candy = 0;
// int MAX = 0;
// for (int i = 0; i < N; i++)
//{
// for (int k = 0; k <= i; k++)
// {
// candy += line1[k];
// }
// for (int j = N - 1; j >= i; j--)
// {
// candy += line2[j];
// }
// MAX = Math.Max(candy,MAX);
// candy = 0;
//}
// Console.WriteLine(MAX);
var N = int.Parse(Console.ReadLine());
List<int[]> list = new List<int[]>();
int t = 0;
int x = 0;
int y = 0;
for (int i = 0; i < N; i++) {
var txy = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
list.Add(txy);
}
foreach (var item in list) {
if (item[0] - t >= Math.Abs(item[1] + item[2] - x - y)) {
if (((item[0] - t) % 2 == 1 &&
Math.Abs(x + y - item[1] - item[2]) % 2 == 1) ||
((item[0] - t) % 2 == 0 &&
Math.Abs(x + y - item[1] - item[2]) % 2 == 0)) {
t = item[0];
x = item[1];
y = item[2];
} else {
Console.WriteLine("No");
return;
}
} else {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
public static void DFS(int v, bool[] visited, int[,] dag) {
visited[v] = true;
for (int i = 0; i < visited.Length; i++) {
if (dag[v, i] == 0)
continue;
if (visited[i])
continue;
DFS(i, visited, dag);
}
}
public static long LowerBound<T>(T[] arr, long start, long end, T value,
IComparer<T> comparer) {
long low = start;
long high = end;
long mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static long LowerBound<T>(T[] arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
public static long UpperBound<T>(T[] arr, long start, long end, T value,
IComparer<T> comparer) {
long low = start;
long high = end;
long mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static long UpperBound<T>(T[] arr, T value) {
return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 15, 16, 31, 16, 12, 16, 31, 204, 205, 22], ["-", 31, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 72], ["-", 15, 16, 31, 16, 12, 16, 12, 204, 205, 22], ["-", 31, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 15, 16, 12, 16, 31, 16, 31, 204, 205, 22], ["-", 12, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 72], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 753
| 26
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class ABC {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] t = new long[N + 1];
long[] x = new long[N + 1];
long[] y = new long[N + 1];
for (long i = 1; i <= N; i++) {
long[] n = Console.ReadLine().Split().Select(long.Parse).ToArray();
t[i] = n[0];
x[i] = n[1];
y[i] = n[2];
}
bool flag = true;
for (long i = 1; i < N; i++) {
if ((t[i] - t[i - 1] - x[i] + x[i - 1] - y[i] + y[i - 1]) % 2 != 0)
flag = false;
if (Math.Abs(x[i] - x[i - 1]) + Math.Abs(y[i] - y[i - 1]) >
t[i] - t[i - 1])
flag = false;
}
Console.WriteLine(flag ? "Yes" : "No");
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class ABC {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] t = new long[N + 1];
long[] x = new long[N + 1];
long[] y = new long[N + 1];
t[0] = 0;
x[0] = 0;
y[0] = 0;
for (long i = 1; i <= N; i++) {
long[] n = Console.ReadLine().Split().Select(long.Parse).ToArray();
t[i] = n[0];
x[i] = n[1];
y[i] = n[2];
}
bool flag = true;
for (long i = 1; i <= N; i++) {
if ((t[i] - t[i - 1] - Math.Abs(x[i] - x[i - 1]) -
Math.Abs(y[i] - y[i - 1])) %
2 !=
0)
flag = false;
if (Math.Abs(x[i] - x[i - 1]) + Math.Abs(y[i] - y[i - 1]) >
t[i] - t[i - 1])
flag = false;
}
Console.WriteLine(flag ? "Yes" : "No");
Console.ReadLine();
}
}
}
|
[["+", 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], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["-", 31, 23, 0, 16, 31, 16, 31, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 31, 23, 0, 16, 12, 213, 63, 214, 205, 22], ["+", 31, 23, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 31, 23, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 31, 23, 0, 16, 12, 213, 3, 4, 0, 24], ["-", 15, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 31, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 313
| 37
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoderProg {
class C_Traveling {
static void Main(string[] args) {
int count = int.Parse(Console.ReadLine());
int reslutCount = count;
int reslut = 0;
while (count > 0) {
string[] input = Console.ReadLine().Split(' ');
int time = int.Parse(input[0]);
int num = int.Parse(input[1]) + int.Parse(input[2]);
Console.WriteLine(num);
if ((time % 2 == num % 2) && (time >= num)) {
reslut++;
}
count--;
}
if (reslutCount == reslut) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoderProg {
class C_Traveling {
static void Main(string[] args) {
int count = int.Parse(Console.ReadLine());
int reslutCount = count;
int reslut = 0;
while (count > 0) {
string[] input = Console.ReadLine().Split(' ');
int time = int.Parse(input[0]);
int num = int.Parse(input[1]) + int.Parse(input[2]);
if ((time % 2 == num % 2) && (time >= num)) {
reslut++;
}
count--;
}
if (reslutCount == reslut) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
| 8
| 194
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C {
class questionC {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int x = 0;
int y = 0;
int t = 0;
bool ok = true;
for (int i = 0; i < N; i++) {
int[] input =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int tNext = input[0];
int xNext = input[1];
int yNext = input[2];
int xdiff = Math.Abs(xNext - x);
int ydiff = Math.Abs(yNext - y);
if (tNext < xdiff + ydiff || tNext % 2 != (xdiff + ydiff) % 2) {
ok = false;
}
t = tNext;
x = xNext;
y = yNext;
}
// Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
// Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b,
// c);//改行付き出力
if (ok) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C {
class questionC {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int x = 0;
int y = 0;
int t = 0;
bool ok = true;
for (int i = 0; i < N; i++) {
int[] input =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int tNext = input[0];
int xNext = input[1];
int yNext = input[2];
int xdiff = Math.Abs(xNext - x);
int ydiff = Math.Abs(yNext - y);
int diff = xdiff + ydiff;
int tDiff = tNext - t;
if (tDiff < diff || tDiff % 2 != diff % 2) {
ok = false;
}
t = tNext;
x = xNext;
y = yNext;
}
// Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
// Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b,
// c);//改行付き出力
if (ok) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 0, 7, 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, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 15, 16, 12, 16, 12, 16, 31, 23, 0, 24], ["-", 12, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["-", 12, 16, 12, 16, 31, 23, 0, 16, 17, 72], ["-", 12, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["-", 15, 16, 12, 16, 12, 16, 31, 23, 0, 25], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22]]
| 8
| 246
| 28
|
using System;
public class Hello {
public static void Main() {
int N = int.Parse(Console.ReadLine());
int curT = 0;
int curX = 0;
int curY = 0;
for (int i = 0; i < N; i++) {
string[] input = Console.ReadLine().Split(' ');
int nexT = int.Parse(input[0]);
int nexX = int.Parse(input[1]);
int nexY = int.Parse(input[2]);
int t = nexT - curT;
int x = Math.Abs(nexX - curX);
int y = Math.Abs(nexY - curY);
if (x + y <= t || (x + y) % 2 == t % 2) {
} else {
Console.WriteLine("No");
return;
}
curT = nexT;
curX = nexX;
curY = nexY;
}
Console.WriteLine("Yes");
}
}
|
using System;
public class Hello {
public static void Main() {
int N = int.Parse(Console.ReadLine());
int curT = 0;
int curX = 0;
int curY = 0;
for (int i = 0; i < N; i++) {
string[] input = Console.ReadLine().Split(' ');
int nexT = int.Parse(input[0]);
int nexX = int.Parse(input[1]);
int nexY = int.Parse(input[2]);
int t = nexT - curT;
int x = Math.Abs(nexX - curX);
int y = Math.Abs(nexY - curY);
int d = x + y;
if (t >= d && (t % 2 == d % 2)) {
} else {
Console.WriteLine("No");
return;
}
curT = nexT;
curX = nexX;
curY = nexY;
}
Console.WriteLine("Yes");
}
}
|
[["-", 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, 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], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 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], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["-", 15, 16, 12, 16, 31, 16, 31, 23, 0, 25], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
| 8
| 206
| 21
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program {
public void Proc() {
int[] inpt =
Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
int kibouCount = inpt[0];
CheckLen = inpt[1];
this.KibouList = new Kibou[kibouCount];
this.KibouMap = new int[CheckLen * 2, CheckLen * 2];
this.KibouCountMap = new int[CheckLen * 2, CheckLen * 2];
for (int i = 0; i < kibouCount; i++) {
Kibou newKibou = new Kibou(Reader.ReadLine());
this.KibouList[i] = newKibou;
this.KibouMap[newKibou.X, newKibou.Y]++;
}
for (int i = 0; i < KibouMap.GetLength(0); i++) {
for (int j = 0; j < KibouMap.GetLength(0); j++) {
int num = this.KibouMap[i, j];
if (i > 0) {
num += this.KibouCountMap[i - 1, j];
}
if (j > 0) {
num += this.KibouCountMap[i, j - 1];
}
if (i > 0 && j > 0) {
num -= this.KibouCountMap[i - 1, j - 1];
}
this.KibouCountMap[i, j] = num;
}
}
int ans = 0;
int maxIndex = KibouCountMap.GetLength(0) - 1;
for (int i = 0; i <= maxIndex; i++) {
for (int j = 0; j <= maxIndex; j++) {
int subAns = GetBlockCount(i, j);
int subX = i + CheckLen;
int subY = j + CheckLen;
if (subX > maxIndex) {
subX -= this.KibouCountMap.GetLength(0);
}
if (subY > maxIndex) {
subY -= this.KibouCountMap.GetLength(0);
}
subAns += GetBlockCount(subX, subY);
ans = Math.Max(subAns, ans);
}
}
Console.WriteLine(ans);
}
private int GetBlockCount(int x, int y) {
int maxIndex = KibouCountMap.GetLength(0) - 1;
int toX = x + CheckLen - 1;
int toY = y + CheckLen - 1;
int tmp =
GetItemCount(x, y, Math.Min(toX, maxIndex), Math.Min(toY, maxIndex));
if (toX > maxIndex) {
int subToX = toX - maxIndex;
int subToY = Math.Min(toY, maxIndex);
tmp += GetItemCount(0, y, subToX, subToY);
}
if (toY > maxIndex) {
tmp += GetItemCount(x, 0, Math.Min(toX, maxIndex), toY - maxIndex);
}
if (toX > maxIndex && toY > maxIndex) {
tmp += GetItemCount(0, 0, toX - maxIndex, toY - maxIndex);
}
return tmp;
}
private int GetItemCount(int fromX, int fromY, int toX, int toY) {
int ans = KibouCountMap[toX, toY];
if (fromX > 0) {
ans -= KibouCountMap[fromX - 1, toY];
}
if (fromY > 0) {
ans -= KibouCountMap[toX, fromY - 1];
}
if (fromX > 0 && fromY > 0) {
ans += KibouCountMap[fromX - 1, fromY - 1];
}
return ans;
}
private int[,] KibouMap;
private int[,] KibouCountMap;
private Kibou[] KibouList;
private class Kibou {
public long X;
public long Y;
public Kibou(string inpt) {
string[] tmp = inpt.Split(' ');
this.X = long.Parse(tmp[0]);
this.Y = long.Parse(tmp[1]);
if (tmp[2][0] == 'W') {
this.X += CheckLen;
}
this.X = this.X % (CheckLen * 2);
this.Y = this.Y % (CheckLen * 2);
if (this.X >= CheckLen && this.Y >= CheckLen) {
this.X -= CheckLen;
this.Y -= CheckLen;
}
}
}
public static int CheckLen;
public class Reader {
private static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine() {
if (IsDebug) {
if (sr == null) {
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
private static string InputText = @"
2 1000
0 0 B
0 1 W
";
}
public static void Main(string[] args) {
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program {
public void Proc() {
int[] inpt =
Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
int kibouCount = inpt[0];
CheckLen = inpt[1];
this.KibouList = new Kibou[kibouCount];
this.KibouMap = new int[CheckLen * 2, CheckLen * 2];
this.KibouCountMap = new int[CheckLen * 2, CheckLen * 2];
for (int i = 0; i < kibouCount; i++) {
Kibou newKibou = new Kibou(Reader.ReadLine());
this.KibouList[i] = newKibou;
this.KibouMap[newKibou.X, newKibou.Y]++;
}
for (int i = 0; i < KibouMap.GetLength(0); i++) {
for (int j = 0; j < KibouMap.GetLength(0); j++) {
int num = this.KibouMap[i, j];
if (i > 0) {
num += this.KibouCountMap[i - 1, j];
}
if (j > 0) {
num += this.KibouCountMap[i, j - 1];
}
if (i > 0 && j > 0) {
num -= this.KibouCountMap[i - 1, j - 1];
}
this.KibouCountMap[i, j] = num;
}
}
int ans = 0;
int maxIndex = KibouCountMap.GetLength(0) - 1;
for (int i = 0; i <= maxIndex; i++) {
for (int j = 0; j <= maxIndex; j++) {
int subAns = GetBlockCount(i, j);
int subX = i + CheckLen;
int subY = j + CheckLen;
if (subX > maxIndex) {
subX -= this.KibouCountMap.GetLength(0);
}
if (subY > maxIndex) {
subY -= this.KibouCountMap.GetLength(0);
}
subAns += GetBlockCount(subX, subY);
ans = Math.Max(subAns, ans);
}
}
Console.WriteLine(ans);
}
private int GetBlockCount(int x, int y) {
int maxIndex = KibouCountMap.GetLength(0) - 1;
int toX = x + CheckLen - 1;
int toY = y + CheckLen - 1;
int tmp =
GetItemCount(x, y, Math.Min(toX, maxIndex), Math.Min(toY, maxIndex));
if (toX > maxIndex) {
int subToX = toX - maxIndex - 1;
int subToY = Math.Min(toY, maxIndex);
tmp += GetItemCount(0, y, subToX, subToY);
}
if (toY > maxIndex) {
tmp += GetItemCount(x, 0, Math.Min(toX, maxIndex), toY - maxIndex - 1);
}
if (toX > maxIndex && toY > maxIndex) {
tmp += GetItemCount(0, 0, toX - maxIndex - 1, toY - maxIndex - 1);
}
return tmp;
}
private int GetItemCount(int fromX, int fromY, int toX, int toY) {
int ans = KibouCountMap[toX, toY];
if (fromX > 0) {
ans -= KibouCountMap[fromX - 1, toY];
}
if (fromY > 0) {
ans -= KibouCountMap[toX, fromY - 1];
}
if (fromX > 0 && fromY > 0) {
ans += KibouCountMap[fromX - 1, fromY - 1];
}
return ans;
}
private int[,] KibouMap;
private int[,] KibouCountMap;
private Kibou[] KibouList;
private class Kibou {
public long X;
public long Y;
public Kibou(string inpt) {
string[] tmp = inpt.Split(' ');
this.X = long.Parse(tmp[0]);
this.Y = long.Parse(tmp[1]);
if (tmp[2][0] == 'W') {
this.X += CheckLen;
}
this.X = this.X % (CheckLen * 2);
this.Y = this.Y % (CheckLen * 2);
if (this.X >= CheckLen && this.Y >= CheckLen) {
this.X -= CheckLen;
this.Y -= CheckLen;
}
}
}
public static int CheckLen;
public class Reader {
private static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine() {
if (IsDebug) {
if (sr == null) {
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
private static string InputText = @"
6 2
1 2 B
2 1 W
2 2 B
1 0 B
0 6 W
4 5 W
";
}
public static void Main(string[] args) {
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
| 8
| 996
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
class Solution {
static int GetSum(int[][] table, int x0, int y0, int x1, int y1) {
var maxX = Math.Max(x0, x1);
var maxY = Math.Max(y0, y1);
var minX = Math.Min(x0, x1);
var minY = Math.Min(y0, y1);
int sum = table[maxY][maxX];
if (minX > 0) {
sum -= table[maxY][minX];
}
if (minY > 0) {
sum -= table[minY][maxX];
}
if (minX > 0 && minY > 0) {
sum += table[minY][minX];
}
return sum;
}
static void Main() {
var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int n = vals[0];
int k = vals[1];
var blackCount = Enumerable.Range(0, k).Select(_ => new int[k]).ToArray();
var whiteCount = Enumerable.Range(0, k).Select(_ => new int[k]).ToArray();
for (int i = 0; i < n; i++) {
var v = Console.ReadLine().Split(' ').ToArray();
var x = int.Parse(v[0]) % (2 * k);
var y = int.Parse(v[1]) % (2 * k);
var color = v[2][0];
var isBlack = color == 'B';
if (x >= k && y >= k) {
x -= k;
y -= k;
} else if (x >= k) {
x -= k;
isBlack ^= true;
} else if (y >= k) {
y -= k;
isBlack ^= true;
}
if (isBlack) {
Console.Error.WriteLine($"({x},{y}) black");
blackCount[y][x]++;
} else {
Console.Error.WriteLine($"({x},{y}) white");
whiteCount[y][x]++;
}
}
// 右へ加算
for (int y = 0; y < k; y++) {
for (int x = 1; x < k; x++) {
blackCount[y][x] += blackCount[y][x - 1];
whiteCount[y][x] += whiteCount[y][x - 1];
}
}
// 下へ加算
for (int x = 0; x < k; x++) {
for (int y = 1; y < k; y++) {
blackCount[y][x] += blackCount[y - 1][x];
whiteCount[y][x] += whiteCount[y - 1][x];
}
}
int max = 0;
int min = int.MaxValue;
for (int x = 0; x < k; x++) {
for (int y = 0; y < k; y++) {
int satisfied = 0;
// 左上から(x-1,y-1)まで黒
if (x > 0 && y > 0) {
satisfied += GetSum(blackCount, 0, 0, x - 1, y - 1);
}
// (x,y)から右下まで黒
satisfied += GetSum(blackCount, x, y, k - 1, k - 1);
// (x,y-1)から右上まで白
if (y > 0) {
satisfied += GetSum(blackCount, x, y - 1, k - 1, 0);
}
// 左下から(x-1,y)まで白
if (x > 0) {
satisfied += GetSum(blackCount, 0, k - 1, x - 1, y);
}
max = Math.Max(max, satisfied);
min = Math.Min(min, satisfied);
}
}
max = Math.Max(max, n - min);
Console.WriteLine(max);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Solution {
static int GetSum(int[][] table, int x0, int y0, int x1, int y1) {
var maxX = Math.Max(x0, x1);
var maxY = Math.Max(y0, y1);
var minX = Math.Min(x0, x1) - 1;
var minY = Math.Min(y0, y1) - 1;
int sum = table[maxY][maxX];
if (minX >= 0) {
sum -= table[maxY][minX];
}
if (minY >= 0) {
sum -= table[minY][maxX];
}
if (minX >= 0 && minY >= 0) {
sum += table[minY][minX];
}
return sum;
}
static void Main() {
var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int n = vals[0];
int k = vals[1];
var blackCount = Enumerable.Range(0, k).Select(_ => new int[k]).ToArray();
var whiteCount = Enumerable.Range(0, k).Select(_ => new int[k]).ToArray();
for (int i = 0; i < n; i++) {
var v = Console.ReadLine().Split(' ').ToArray();
var x = int.Parse(v[0]) % (2 * k);
var y = int.Parse(v[1]) % (2 * k);
var color = v[2][0];
var isBlack = color == 'B';
if (x >= k && y >= k) {
x -= k;
y -= k;
} else if (x >= k) {
x -= k;
isBlack ^= true;
} else if (y >= k) {
y -= k;
isBlack ^= true;
}
if (isBlack) {
blackCount[y][x]++;
} else {
whiteCount[y][x]++;
}
}
// 右へ加算
for (int y = 0; y < k; y++) {
for (int x = 1; x < k; x++) {
blackCount[y][x] += blackCount[y][x - 1];
whiteCount[y][x] += whiteCount[y][x - 1];
}
}
// 下へ加算
for (int x = 0; x < k; x++) {
for (int y = 1; y < k; y++) {
blackCount[y][x] += blackCount[y - 1][x];
whiteCount[y][x] += whiteCount[y - 1][x];
}
}
int max = 0;
int min = int.MaxValue;
for (int x = 0; x < k; x++) {
for (int y = 0; y < k; y++) {
int satisfied = 0;
// 左上から(x-1,y-1)まで黒
if (x > 0 && y > 0) {
satisfied += GetSum(blackCount, 0, 0, x - 1, y - 1);
}
// (x,y)から右下まで黒
satisfied += GetSum(blackCount, x, y, k - 1, k - 1);
// (x,y-1)から右上まで白
if (y > 0) {
satisfied += GetSum(whiteCount, x, y - 1, k - 1, 0);
}
// 左下から(x-1,y)まで白
if (x > 0) {
satisfied += GetSum(whiteCount, 0, k - 1, x - 1, y);
}
max = Math.Max(max, satisfied);
min = Math.Min(min, satisfied);
}
}
max = Math.Max(max, n - min);
Console.WriteLine(max);
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["-", 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, 283, 0, 295], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 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], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 818
| 54
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class MainClass : Scanner {
static void Main() {
int K = RInt();
long[] A = RLongs();
solve(K, A);
}
static void solve(int K, long[] A) {
Array.Reverse(A);
long min = A[0];
long max = A[0] * 2 - 1;
for (int i = 1; i < K; i++) {
max = max / A[i] * A[i] + A[i] - 1;
if (min % A[i] == 0)
;
else
min = min / A[i] * A[i] + A[i];
if (min > max) {
WriteLine(-1);
return;
}
}
WriteLine($"{min} {max}");
}
}
class DebuggingTools {
public static int Random(int min, int max) {
var rand = new Random(DateTime.Now.Millisecond);
return rand.Next(min, max);
}
public static long[] RandomArray(int n, int min, int max) {
var ary = new long[n];
var rand = new Random(DateTime.Now.Millisecond);
for (int i = 0; i < n; i++) {
ary[i] = rand.Next(min, max);
}
return ary;
}
}
class Scanner {
public static int RInt() => int.Parse(Console.ReadLine());
public static long RLong() => long.Parse(Console.ReadLine());
public static string RString() => Console.ReadLine();
public static double RDouble() => double.Parse(Console.ReadLine());
public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(),
int.Parse);
public static int[] RInts(Func<string, int> func) =>
Console.ReadLine().Split().Select(func).ToArray();
public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(),
long.Parse);
public static long[] RLongs(Func<string, long> func) =>
Console.ReadLine().Split().Select(func).ToArray();
public static double[] RDoubles() =>
Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
public static double[] RDoubles(Func<string, double> func) =>
Console.ReadLine().Split().Select(func).ToArray();
public static string[] RStrings() => Console.ReadLine().Split();
// public static string[] RStrings(Func<string, string> func) =>
// Console.ReadLine().Split().Select(func).ToArray();
public static T1 ReadStream<T1>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
return r1;
}
public static (T1, T2) ReadStream<T1, T2>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
return (r1, r2);
}
public static (T1, T2, T3) ReadStream<T1, T2, T3>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
return (r1, r2, r3);
}
public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
return (r1, r2, r3, r4);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class MainClass : Scanner {
static void Main() {
int K = RInt();
long[] A = RLongs();
solve(K, A);
}
static void solve(int K, long[] A) {
Array.Reverse(A);
long min = 2;
long max = 2;
for (int i = 0; i < K; i++) {
max = max / A[i] * A[i] + A[i] - 1;
if (min % A[i] == 0)
;
else
min = (min / A[i] + 1) * A[i];
if (min > max) {
WriteLine(-1);
return;
}
}
WriteLine($"{min} {max}");
}
}
class DebuggingTools {
public static int Random(int min, int max) {
var rand = new Random(DateTime.Now.Millisecond);
return rand.Next(min, max);
}
public static long[] RandomArray(int n, int min, int max) {
var ary = new long[n];
var rand = new Random(DateTime.Now.Millisecond);
for (int i = 0; i < n; i++) {
ary[i] = rand.Next(min, max);
}
return ary;
}
}
class Scanner {
public static int RInt() => int.Parse(Console.ReadLine());
public static long RLong() => long.Parse(Console.ReadLine());
public static string RString() => Console.ReadLine();
public static double RDouble() => double.Parse(Console.ReadLine());
public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(),
int.Parse);
public static int[] RInts(Func<string, int> func) =>
Console.ReadLine().Split().Select(func).ToArray();
public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(),
long.Parse);
public static long[] RLongs(Func<string, long> func) =>
Console.ReadLine().Split().Select(func).ToArray();
public static double[] RDoubles() =>
Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
public static double[] RDoubles(Func<string, double> func) =>
Console.ReadLine().Split().Select(func).ToArray();
public static string[] RStrings() => Console.ReadLine().Split();
// public static string[] RStrings(Func<string, string> func) =>
// Console.ReadLine().Split().Select(func).ToArray();
public static T1 ReadStream<T1>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
return r1;
}
public static (T1, T2) ReadStream<T1, T2>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
return (r1, r2);
}
public static (T1, T2, T3) ReadStream<T1, T2, T3>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
return (r1, r2, r3);
}
public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
return (r1, r2, r3, r4);
}
}
|
[["-", 0, 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, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 212, 0, 16, 31, 16, 31, 204, 205, 22], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 75, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 75, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["-", 0, 11, 12, 16, 31, 16, 12, 204, 205, 22], ["-", 12, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 75, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 0, 57, 75, 1, 0, 11, 12, 16, 17, 48]]
| 8
| 938
| 23
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using CS = System.Runtime.CompilerServices;
// using System.Diagnostics;
using static System.Math;
using ll = System.Int64;
using static Contest_B.Lib_IO;
using static Contest_B.Lib_Minifunc;
namespace Contest_B {
public static class Entry {
public static void Main() {
checked {
long k;
Lib_IO.rm(out k);
ll[] a;
ra(out a);
if (a[a.Length - 1] != 2) {
wm(-1);
return;
}
ll nmin = 2;
ll nmax = 3;
for (int i = a.Length - 2; 0 <= i; i--) {
if (nmax < a[i]) {
wm(-1);
return;
}
nmin = ceil(nmin, a[i]) * a[i];
nmax = ((nmax / a[i]) + 1) * a[i] - 1;
}
Lib_IO.wm(nmin, nmax);
}
}
}
#region BaseModule
public static class Lib_Minifunc {
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
[CS.MethodImpl(256)]
public static void swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
[CS.MethodImpl(256)]
public static void swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
swap1(ref a, ref b);
} // b の方が小さければ交換
[CS.MethodImpl(256)]
public 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 を更新
[CS.MethodImpl(256)]
public 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 を更新
[CS.MethodImpl(256)]
public static bool inside(long i, long n) => (0 <= i && i < n);
[CS.MethodImpl(256)]
public static bool inside(long x, long y, long w,
long h) => (inside(x, w) && inside(y, h));
[CS.MethodImpl(256)]
public static T min<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmin(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static T max<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmax(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static long mod(long a, long m = MOD1) {
var v = a % m;
return (v < 0 ? (m < 0 ? v - m : v + m) : v);
}
[CS.MethodImpl(256)]
public static long
ceil(long a, long b) => (a % b == 0 || (a < 0 && 0 < b) || (0 < a && b < 0)
? a / b
: a / b + 1); // 整数商の切り上げ
[CS.MethodImpl(256)]
public static long round(double a) => Convert.ToInt64(a); // 四捨五入
public static string YES(bool a) => a ? "YES" : "NO";
public static string yes(bool a) => a ? "Yes" : "No";
[CS.MethodImpl(256)]
public static P<T, U> initp<T, U>(T a, U b) => new P<T, U>(a, b);
[CS.MethodImpl(256)]
public static P<T, U, V> initp<T, U, V>(T a, U b, V c) => new P<T, U, V>(a, b,
c);
[CS.MethodImpl(256)]
public static P<T, U, V, W>
initp<T, U, V, W>(T a, U b, V c, W d) => new P<T, U, V, W>(a, b, c, d);
public static T[] initc<T>(long l1)
where T : new() {
var m = new T[l1];
for (int i = 0; i < m.Length; i++)
m[i] = new T();
return m;
} // new制約は遅い
public static int[] range(long s, long c) =>
Enumerable.Range((int)s, (int)c).ToArray();
[CS.MethodImpl(256)]
public static T[] inita<T>(long l1, T v = default(T)) =>
Enumerable.Repeat(v, (int)l1).ToArray();
public static T[][] inita<T>(long l1, long l2, T v = default(T)) {
var m = new T[l1][];
for (int i = 0; i < m.Length; i++)
m[i] = inita(l2, v);
return m;
}
public static T[][][] inita<T>(long l1, long l2, long l3, T v = default(T)) {
var m = new T[l1][][];
for (int i = 0; i < m.Length; i++)
m[i] = inita(l2, l3, v);
return m;
}
public static void shift(this IList<int> l, int o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
public static void shift(this IList<long> l, long o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
[CS.MethodImpl(256)]
public static bool initd<T, U>(this IDictionary<T, U> d, T k,
U v = default(U)) {
if (d.ContainsKey(k)) {
return false;
} else {
d[k] = v;
return true;
}
}
public static void sort<T>(this T[] a, int o = 1, Comparison<T> f = null)
where T : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.CompareTo(y));
break;
case -1:
Array.Sort(a, (x, y) => y.CompareTo(x));
break;
default:
break;
}
}
public static void sort<T, U>(this P<T, U>[] a, int o,
Comparison<P<T, U>> f = null)
where T : IComparable
where U : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
default:
break;
}
}
public static void sort<T, U, V>(this P<T, U, V>[] a, int o,
Comparison<P<T, U, V>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
default:
break;
}
}
public static void sort<T, U, V, W>(this P<T, U, V, W>[] a, int o,
Comparison<P<T, U, V, W>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable
where W : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
case 4:
Array.Sort(a, (x, y) => x.D.CompareTo(y.D));
break;
case -4:
Array.Sort(a, (x, y) => y.D.CompareTo(x.D));
break;
default:
break;
}
}
}
public struct P<T, U> {
public T A;
public U B;
public P(T a, U b) {
A = a;
B = b;
}
public static implicit
operator KeyValuePair<T, U>(P<T, U> a) => new KeyValuePair<T, U>(a.A, a.B);
public static implicit
operator P<T, U>(KeyValuePair<T, U> a) => new P<T, U>(a.Key, a.Value);
}
public struct P<T, U, V> {
public T A;
public U B;
public V C;
public P(T a, U b, V c) {
A = a;
B = b;
C = c;
}
}
public struct P<T, U, V, W> {
public T A;
public U B;
public V C;
public W D;
public P(T a, U b, V c, W d) {
A = a;
B = b;
C = c;
D = d;
}
}
public static class Lib_IO {
class Prt : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Prt(System.IO.Stream s) : base(s, new UTF8Encoding(false, true)) {}
public Prt(System.IO.Stream s, Encoding e) : base(s, e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] { ' ' };
[CS.MethodImpl(256)]
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
[CS.MethodImpl(256)]
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
[CS.MethodImpl(256)]
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[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T, U>(out T a, out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T, U, V>(out T a, out U b, out V c) {
var z = rm<T, U>(out a, out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T, U, V, W>(out T a, out U b, out V c, out W d) {
var z = rm<T, U, V>(out a, out b, out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var z = rm<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<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 z = rm<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = new T[z.Length];
for (int i = 0; i < a.Length; i++)
a[i] = cv<T>(z[i]);
return z;
}
public static string[][] rl<T>(long n, out T[] a) {
a = new T[n];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T, U>(long n, out P<T, U>[] a) {
a = new P<T, U>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
y[i] = rm(out o, out p);
a[i] = new P<T, U>(o, p);
}
return y;
}
public static string[][] rl<T, U, V>(long n, out P<T, U, V>[] a) {
a = new P<T, U, V>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
y[i] = rm(out o, out p, out q);
a[i] = new P<T, U, V>(o, p, q);
}
return y;
}
public static string[][] rl<T, U, V, W>(long n, out P<T, U, V, W>[] a) {
a = new P<T, U, V, W>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
y[i] = rm(out o, out p, out q, out r);
a[i] = new P<T, U, V, W>(o, p, q, r);
}
return y;
}
public static string[][] rx<T>(long n, out T[][] a) {
a = new T[n][];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act) {
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[CS.MethodImpl(256)]
static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length - 1; i++)
Console.Write(wfm(a[i].GetType()) + " ", a[i]);
Console.WriteLine(wfm(a[a.Length - 1].GetType()), a[a.Length - 1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[] { a }, " "); }
public static void wl<T>(IList<T> a) {
wwp(() => {
var f = wfm(typeof(T));
if (a.Count == 0) {
Console.WriteLine();
} else {
foreach (T x in a)
Console.WriteLine(f, x);
}
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(() => {
var f = wfm(typeof(T));
var g = f + s;
foreach (var b in a) {
if (b.Count == 0) {
Console.WriteLine();
} else {
for (int i = 0; i < b.Count - 1; i++)
Console.Write(g, b[i]);
Console.WriteLine(f, b[b.Count - 1]);
}
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using CS = System.Runtime.CompilerServices;
// using System.Diagnostics;
using static System.Math;
using ll = System.Int64;
using static Contest_B.Lib_IO;
using static Contest_B.Lib_Minifunc;
namespace Contest_B {
public static class Entry {
public static void Main() {
checked {
long k;
Lib_IO.rm(out k);
ll[] a;
ra(out a);
if (a[a.Length - 1] != 2) {
wm(-1);
return;
}
ll nmin = 2;
ll nmax = 3;
for (int i = a.Length - 2; 0 <= i; i--) {
if (nmax < a[i]) {
wm(-1);
return;
}
nmin = ceil(nmin, a[i]) * a[i];
nmax = ((nmax / a[i]) + 1) * a[i] - 1;
if (nmin > nmax) {
wm(-1);
return;
}
}
Lib_IO.wm(nmin, nmax);
}
}
}
#region BaseModule
public static class Lib_Minifunc {
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
[CS.MethodImpl(256)]
public static void swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
[CS.MethodImpl(256)]
public static void swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
swap1(ref a, ref b);
} // b の方が小さければ交換
[CS.MethodImpl(256)]
public 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 を更新
[CS.MethodImpl(256)]
public 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 を更新
[CS.MethodImpl(256)]
public static bool inside(long i, long n) => (0 <= i && i < n);
[CS.MethodImpl(256)]
public static bool inside(long x, long y, long w,
long h) => (inside(x, w) && inside(y, h));
[CS.MethodImpl(256)]
public static T min<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmin(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static T max<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmax(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static long mod(long a, long m = MOD1) {
var v = a % m;
return (v < 0 ? (m < 0 ? v - m : v + m) : v);
}
[CS.MethodImpl(256)]
public static long
ceil(long a, long b) => (a % b == 0 || (a < 0 && 0 < b) || (0 < a && b < 0)
? a / b
: a / b + 1); // 整数商の切り上げ
[CS.MethodImpl(256)]
public static long round(double a) => Convert.ToInt64(a); // 四捨五入
public static string YES(bool a) => a ? "YES" : "NO";
public static string yes(bool a) => a ? "Yes" : "No";
[CS.MethodImpl(256)]
public static P<T, U> initp<T, U>(T a, U b) => new P<T, U>(a, b);
[CS.MethodImpl(256)]
public static P<T, U, V> initp<T, U, V>(T a, U b, V c) => new P<T, U, V>(a, b,
c);
[CS.MethodImpl(256)]
public static P<T, U, V, W>
initp<T, U, V, W>(T a, U b, V c, W d) => new P<T, U, V, W>(a, b, c, d);
public static T[] initc<T>(long l1)
where T : new() {
var m = new T[l1];
for (int i = 0; i < m.Length; i++)
m[i] = new T();
return m;
} // new制約は遅い
public static int[] range(long s, long c) =>
Enumerable.Range((int)s, (int)c).ToArray();
[CS.MethodImpl(256)]
public static T[] inita<T>(long l1, T v = default(T)) =>
Enumerable.Repeat(v, (int)l1).ToArray();
public static T[][] inita<T>(long l1, long l2, T v = default(T)) {
var m = new T[l1][];
for (int i = 0; i < m.Length; i++)
m[i] = inita(l2, v);
return m;
}
public static T[][][] inita<T>(long l1, long l2, long l3, T v = default(T)) {
var m = new T[l1][][];
for (int i = 0; i < m.Length; i++)
m[i] = inita(l2, l3, v);
return m;
}
public static void shift(this IList<int> l, int o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
public static void shift(this IList<long> l, long o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
[CS.MethodImpl(256)]
public static bool initd<T, U>(this IDictionary<T, U> d, T k,
U v = default(U)) {
if (d.ContainsKey(k)) {
return false;
} else {
d[k] = v;
return true;
}
}
public static void sort<T>(this T[] a, int o = 1, Comparison<T> f = null)
where T : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.CompareTo(y));
break;
case -1:
Array.Sort(a, (x, y) => y.CompareTo(x));
break;
default:
break;
}
}
public static void sort<T, U>(this P<T, U>[] a, int o,
Comparison<P<T, U>> f = null)
where T : IComparable
where U : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
default:
break;
}
}
public static void sort<T, U, V>(this P<T, U, V>[] a, int o,
Comparison<P<T, U, V>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
default:
break;
}
}
public static void sort<T, U, V, W>(this P<T, U, V, W>[] a, int o,
Comparison<P<T, U, V, W>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable
where W : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
case 4:
Array.Sort(a, (x, y) => x.D.CompareTo(y.D));
break;
case -4:
Array.Sort(a, (x, y) => y.D.CompareTo(x.D));
break;
default:
break;
}
}
}
public struct P<T, U> {
public T A;
public U B;
public P(T a, U b) {
A = a;
B = b;
}
public static implicit
operator KeyValuePair<T, U>(P<T, U> a) => new KeyValuePair<T, U>(a.A, a.B);
public static implicit
operator P<T, U>(KeyValuePair<T, U> a) => new P<T, U>(a.Key, a.Value);
}
public struct P<T, U, V> {
public T A;
public U B;
public V C;
public P(T a, U b, V c) {
A = a;
B = b;
C = c;
}
}
public struct P<T, U, V, W> {
public T A;
public U B;
public V C;
public W D;
public P(T a, U b, V c, W d) {
A = a;
B = b;
C = c;
D = d;
}
}
public static class Lib_IO {
class Prt : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Prt(System.IO.Stream s) : base(s, new UTF8Encoding(false, true)) {}
public Prt(System.IO.Stream s, Encoding e) : base(s, e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] { ' ' };
[CS.MethodImpl(256)]
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
[CS.MethodImpl(256)]
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
[CS.MethodImpl(256)]
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[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T, U>(out T a, out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T, U, V>(out T a, out U b, out V c) {
var z = rm<T, U>(out a, out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T, U, V, W>(out T a, out U b, out V c, out W d) {
var z = rm<T, U, V>(out a, out b, out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var z = rm<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<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 z = rm<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = new T[z.Length];
for (int i = 0; i < a.Length; i++)
a[i] = cv<T>(z[i]);
return z;
}
public static string[][] rl<T>(long n, out T[] a) {
a = new T[n];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T, U>(long n, out P<T, U>[] a) {
a = new P<T, U>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
y[i] = rm(out o, out p);
a[i] = new P<T, U>(o, p);
}
return y;
}
public static string[][] rl<T, U, V>(long n, out P<T, U, V>[] a) {
a = new P<T, U, V>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
y[i] = rm(out o, out p, out q);
a[i] = new P<T, U, V>(o, p, q);
}
return y;
}
public static string[][] rl<T, U, V, W>(long n, out P<T, U, V, W>[] a) {
a = new P<T, U, V, W>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
y[i] = rm(out o, out p, out q, out r);
a[i] = new P<T, U, V, W>(o, p, q, r);
}
return y;
}
public static string[][] rx<T>(long n, out T[][] a) {
a = new T[n][];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act) {
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[CS.MethodImpl(256)]
static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length - 1; i++)
Console.Write(wfm(a[i].GetType()) + " ", a[i]);
Console.WriteLine(wfm(a[a.Length - 1].GetType()), a[a.Length - 1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[] { a }, " "); }
public static void wl<T>(IList<T> a) {
wwp(() => {
var f = wfm(typeof(T));
if (a.Count == 0) {
Console.WriteLine();
} else {
foreach (T x in a)
Console.WriteLine(f, x);
}
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(() => {
var f = wfm(typeof(T));
var g = f + s;
foreach (var b in a) {
if (b.Count == 0) {
Console.WriteLine();
} else {
for (int i = 0; i < b.Count - 1; i++)
Console.Write(g, b[i]);
Console.WriteLine(f, b[b.Count - 1]);
}
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
[["+", 0, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 0, 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, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 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, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 287, 0, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 4,323
| 16
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace AGC020B {
class Program {
static void Main(string[] args) {
var K = RInt;
var A = RLongs;
long min = 2;
long max = 2;
for (int i = K - 1; i >= 0; i--) {
if (A[i] > max) {
Console.WriteLine(-1);
return;
}
min = min % A[i] == 0 ? min : (min / A[i] + 1) * A[i];
max = max / A[i] * A[i] + A[i] - 1;
}
Console.WriteLine(min + " " + max);
}
}
}
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, 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 AGC020B {
class Program {
static void Main(string[] args) {
var K = RInt;
var A = RLongs;
long min = 2;
long max = 2;
for (int i = K - 1; i >= 0; i--) {
if (A[i] > max) {
Console.WriteLine(-1);
return;
}
min = min % A[i] == 0 ? min : (min / A[i] + 1) * A[i];
max = max / A[i] * A[i] + A[i] - 1;
if (min > max) {
Console.WriteLine(-1);
return;
}
}
Console.WriteLine(min + " " + max);
}
}
}
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, 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
}
}
}
|
[["+", 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, 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], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 1,229
| 18
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Contest {
class Program {
static void Main(string[] args) { AGC020.B(); }
class AGC020 {
public static void A() {
var N = Read.Int();
var A = Read.Int();
var B = Read.Int();
Console.WriteLine(Math.Abs(A - B) % 2 == 0 ? "Alice" : "Borys");
}
public static void B() {
var K = Read.Int();
var A = Read.LongN();
long min = 2;
long max = 2;
for (int i = K - 1; i >= 0; --i) {
var a = A[i];
if (a > max) {
Console.WriteLine(-1);
return;
}
min = (min + a - 1) / a * a;
max = max / a * a + a - 1;
}
Console.WriteLine("{0} {1}", min, max);
}
}
class Util {}
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) {
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]);
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) { AGC020.B(); }
class AGC020 {
public static void A() {
var N = Read.Int();
var A = Read.Int();
var B = Read.Int();
Console.WriteLine(Math.Abs(A - B) % 2 == 0 ? "Alice" : "Borys");
}
public static void B() {
var K = Read.Int();
var A = Read.LongN();
long min = 2;
long max = 2;
for (int i = K - 1; i >= 0; --i) {
var a = A[i];
if (a > max) {
Console.WriteLine(-1);
return;
}
min = (min + a - 1) / a * a;
max = max / a * a + a - 1;
if (min > max) {
Console.WriteLine(-1);
return;
}
}
Console.WriteLine("{0} {1}", min, max);
}
}
class Util {}
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) {
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]);
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;
}
}
}
}
|
[["+", 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, 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], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 1,249
| 18
|
using System;
namespace AGC020_B___Ice_Rink_Game {
class Program {
static void Main(string[] args) { Console.WriteLine(solver()); }
static string solver() {
var K = int.Parse(Console.ReadLine());
var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
if (A[K - 1] != 2)
return "-1";
long max = 3;
long min = 2;
for (int i = K - 2; i >= 0; i--) {
if (A[i] > max)
return "-1";
max = max / A[i] * A[i] + A[i] - 1;
min = ((min - 1) / A[i] + 1) * A[i];
}
return $"{min} {max}";
}
}
}
|
using System;
namespace AGC020_B___Ice_Rink_Game {
class Program {
static void Main(string[] args) { Console.WriteLine(solver()); }
static string solver() {
var K = int.Parse(Console.ReadLine());
var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
if (A[K - 1] != 2)
return "-1";
long max = 3;
long min = 2;
for (int i = K - 2; i >= 0; i--) {
if (A[i] > max)
return "-1";
max = max / A[i] * A[i] + A[i] - 1;
min = ((min - 1) / A[i] + 1) * A[i];
}
return min < max ? $"{min} {max}" : "-1";
}
}
}
|
[["+", 8, 196, 0, 37, 0, 41, 15, 16, 31, 22], ["+", 8, 196, 0, 37, 0, 41, 15, 16, 17, 18], ["+", 8, 196, 0, 37, 0, 41, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 37, 0, 41, 0, 101], ["+", 8, 196, 0, 37, 0, 41, 64, 283, 0, 62], ["+", 0, 195, 8, 196, 0, 37, 0, 41, 0, 102], ["+", 8, 196, 0, 37, 0, 41, 75, 5, 0, 62], ["+", 8, 196, 0, 37, 0, 41, 75, 5, 0, 222]]
| 8
| 189
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
class Program {
const long MOD = (long)1e9 + 7;
static void Main(string[] args) {
// main ↓
bool dekiru = true;
int x = 2;
int max = x;
int min = x;
int n = ScanOneInt();
int[] k = ScanIntArray(n);
for (int i = n - 1; i >= 0; i--) {
if (min <= (min + k[i] - 1) / k[i] * k[i] &&
(min + k[i] - 1) / k[i] * k[i] <= max && min <= max / k[i] * k[i] &&
max / k[i] * k[i] <= max) {
min = (min + k[i] - 1) / k[i] * k[i];
max = max / k[i] * k[i] + k[i] - 1;
} else {
dekiru = false;
}
}
Console.WriteLine(dekiru ? (min + " " + max) : "-1");
// main↑
}
public class SegmentTree<Monoid> {
private bool debug = false;
// 0-indexed SegmentTree
public int size;
Monoid[] segTree;
Monoid unit;
public SegmentTree(int inSize, Monoid unit) {
this.unit = unit;
size = 2;
while (size < inSize)
size *= 2;
segTree = new Monoid[2 * size];
for (int i = 0; i < segTree.Length; i++) {
segTree[i] = unit;
// 単位元なので全部に代入しておけばよい
}
}
public int BinarySearch(int x) {
int high = size;
int low = 0;
int mid = (high + low) / 2;
while (low < high) {
// Console.WriteLine(low + " " + high);
Monoid cmp = NonRecursiveQuery(0, mid);
// Console.WriteLine("[ 0, " + mid + " ] -> " + cmp);
if ((dynamic)cmp >= x) {
high = mid;
} else if ((dynamic)cmp < x) {
low = mid + 1;
}
mid = (high + low) / 2;
}
return mid;
}
public void set(int iter, Monoid val) { segTree[iter + size - 1] = val; }
public Monoid GetMonoid(int index) { return segTree[index + size - 1]; }
public void add(int iter, Monoid val) {
update(iter, (dynamic)segTree[iter + size - 1] + (dynamic)val);
}
public void build() {
// 2段目より上の構築
for (int k = size - 2; k >= 0; k--) {
segTree[k] = F(segTree[2 * k + 1], segTree[2 * k + 2]);
}
}
public Monoid F(Monoid m1, Monoid m2) {
Monoid res = GCD(m1, m2);
return res;
}
public Monoid Query(int ql, int qr, int index, int nl, int nr) {
// Recursive
// [ql, qr)について考える
// index に対応する範囲 nl <= x <= nr
if (nr <= ql || qr <= nl) {
if (debug)
Console.WriteLine("Out: [l , r), [" + nl + " ," + nr + "), " +
"index: " + index + " ,unit:" + unit);
return unit;
}
if (ql <= nl && nr <= qr) {
if (debug)
Console.WriteLine("All in [l , r): [" + nl + " ," + nr + "), " +
"index: " + index + ",rangeAns:" + segTree[index]);
return segTree[index];
} else {
Monoid vl = Query(ql, qr, index * 2 + 1, nl, (nl + nr) / 2);
Monoid vr = Query(ql, qr, index * 2 + 2, (nl + nr) / 2, nr);
if (debug)
Console.WriteLine("Recursive: [l , r),+: [" + nl + ", " + nr +
"), index->" + index);
if (debug)
Console.WriteLine("(vl, vr): (" + vl + ", " + vr + ")");
return F(vl, vr);
}
}
public Monoid NonRecursiveQuery(int l, int r) {
// 区間 -> [ l , r ]
// 非再帰
int L = l + size - 1;
int R = r + size - 1;
Monoid s = unit;
while (L <= R) {
if (L % 2 == 0) {
s = F(s, segTree[L]);
L++;
}
if (R % 2 == 1) {
s = F(s, segTree[R]);
}
L /= 2;
R /= 2;
R--;
}
return s;
}
public void update(int k, Monoid x) {
k += size - 1;
segTree[k] = x;
while (true) {
k = (k - 1) / 2;
segTree[k] = F(segTree[k * 2 + 1], segTree[k * 2 + 2]);
if (k == 0) {
break;
}
}
}
public void print() {
Console.Write("Print:");
for (int i = 0; i < segTree.Length; i++) {
Console.Write(segTree[i] + " ");
}
Console.WriteLine("");
}
}
static int Nibutan(long[] array, long k) {
int low = 0;
int high = array.Length - 1;
int mid = high;
while (low < high) {
mid = (low + high) / 2;
if (array[mid] >= k) // k以上の最小index.ココを変えるだけ
{
high = mid;
} else {
low = mid + 1;
}
mid = (low + high) / 2;
}
return mid;
}
static int ScanOneInt() { return int.Parse(Console.ReadLine()); }
static long ScanOneLong() { return long.Parse(Console.ReadLine()); }
static string[] ScanStringArray(int lines) {
string[] str = new string[lines];
for (int i = 0; i < lines; i++) {
str[i] = Console.ReadLine();
}
return str;
}
static int[] ScanIntArray(int t) {
string[] str = Console.ReadLine().Split(' ');
int[] ar = new int[t];
for (int i = 0; i < t; i++) {
ar[i] = int.Parse(str[i]);
}
return ar;
}
static string[] ScanStringArrayInOneLine(int t) {
string[] str = Console.ReadLine().Split(' ');
return str;
}
static Tuple<int, int> ScanTuple() {
int[] tmp = ScanIntArray(2);
return new Tuple<int, int>(tmp[0], tmp[1] * -1);
}
static long[] ScanLongArray(int t) {
string[] str = Console.ReadLine().Split(' ');
long[] ar = new long[t];
for (int i = 0; i < t; i++) {
ar[i] = long.Parse(str[i]);
}
return ar;
}
static double[] ScanDoubleArray(int t) {
string[] str = Console.ReadLine().Split(' ');
double[] ar = new double[t];
for (int i = 0; i < t; i++) {
ar[i] = double.Parse(str[i]);
}
return ar;
}
static int[,] ScanIntSquareArray(int h, int w) {
int[,] resAr = new int[h, w];
for (int i = 0; i < h; i++) {
int[] ar = ScanIntArray(w);
for (int j = 0; j < w; j++) {
resAr[i, j] = ar[j];
}
}
return resAr;
}
static int[,] CombModMake() {
int[,] res = new int[2005, 2005];
for (int i = 0; i < 2005; i++) {
for (int j = 0; j < 2005; j++) {
if (i == 0 || i < j) {
res[i, j] = 0;
} else if (j == 0 || i == j) {
res[i, j] = 1;
} else {
res[i, j] = (res[i - 1, j] + res[i - 1, j - 1]) % (int)MOD;
}
}
}
return res;
}
// int, long両方で出来るGCDを作った
static T GCD<T>(T a, T b) {
if ((dynamic)b == 0) {
return a;
} else {
return GCD((dynamic)b, (dynamic)a % (dynamic)b);
}
}
static bool isPrime(int a) // O(sqrt N)
{
int max = (int)Math.Sqrt(a);
if (a == 1)
return false;
for (int i = 2; i <= max; i++) {
if (a % i == 0) {
return false;
}
}
return true;
}
}
public class Pair<T, U> : IComparable
where T : IComparable<T>
where U : IComparable<U> {
public T Item1;
public U Item2;
public int CompareTo(object obj) {
Pair<T, U> pair = (Pair<T, U>)obj;
return Item1.CompareTo(pair.Item1);
}
public Pair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
// 計算量: Push -> O(logN), Peek -> O(1)。Clear() -> O(logN)
// ToArray()で配列化
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(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/*
-> Item: _heap(ヒープを持つ.sizeはmaxSize)
-> Item: _type -> 0:asc(昇順), 1:desc(降順)
*/
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_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);
// typeが0なら昇順, 1なら降順にソートするCompare
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() // O(1)
{
return _count;
}
public T Peek() // O(1)
{
return _heap[0];
}
public bool Contains(T x) // O(N)なので注意
{
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (Count() > 0)
Pop();
}
public IEnumerator<T> GetEnumerator() // なにこれ
{
var ret = new List<T>();
while (Count() > 0) {
ret.Add(Pop());
}
foreach (var r in ret) {
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 GenericOperation<T> {
public GenericOperation() {
var availableT =
new Type[] { typeof(int), typeof(uint), typeof(short),
typeof(ushort), typeof(long), typeof(ulong),
typeof(byte), typeof(decimal), typeof(double) };
if (!availableT.Contains(typeof(T))) {
throw new NotSupportedException();
}
var p1 = Expression.Parameter(typeof(T));
var p2 = Expression.Parameter(typeof(T));
Add = Expression.Lambda<Func<T, T, T>>(Expression.Add(p1, p2), p1, p2)
.Compile();
Subtract =
Expression.Lambda<Func<T, T, T>>(Expression.Subtract(p1, p2), p1, p2)
.Compile();
Multiply =
Expression.Lambda<Func<T, T, T>>(Expression.Multiply(p1, p2), p1, p2)
.Compile();
Divide = Expression.Lambda<Func<T, T, T>>(Expression.Divide(p1, p2), p1, p2)
.Compile();
Modulo = Expression.Lambda<Func<T, T, T>>(Expression.Modulo(p1, p2), p1, p2)
.Compile();
Equal =
Expression.Lambda<Func<T, T, bool>>(Expression.Equal(p1, p2), p1, p2)
.Compile();
GreaterThan =
Expression
.Lambda<Func<T, T, bool>>(Expression.GreaterThan(p1, p2), p1, p2)
.Compile();
GreaterThanOrEqual = Expression
.Lambda<Func<T, T, bool>>(
Expression.GreaterThanOrEqual(p1, p2), p1, p2)
.Compile();
LessThan =
Expression.Lambda<Func<T, T, bool>>(Expression.LessThan(p1, p2), p1, p2)
.Compile();
LessThanOrEqual = Expression
.Lambda<Func<T, T, bool>>(
Expression.LessThanOrEqual(p1, p2), p1, p2)
.Compile();
}
public Func<T, T, T> Add { get; private set; }
public Func<T, T, T> Subtract { get; private set; }
public Func<T, T, T> Multiply { get; private set; }
public Func<T, T, T> Divide { get; private set; }
public Func<T, T, T> Modulo { get; private set; }
public Func<T, T, bool> Equal { get; private set; }
public Func<T, T, bool> GreaterThan { get; private set; }
public Func<T, T, bool> GreaterThanOrEqual { get; private set; }
public Func<T, T, bool> LessThan { get; private set; }
public Func<T, T, bool> LessThanOrEqual { get; private set; }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
class Program {
const long MOD = (long)1e9 + 7;
static void Main(string[] args) {
// main ↓
bool dekiru = true;
long max = 2;
long min = 2;
int n = ScanOneInt();
long[] k = ScanLongArray(n);
for (int i = n - 1; i >= 0; i--) {
if (min <= (min + k[i] - 1) / k[i] * k[i] &&
(min + k[i] - 1) / k[i] * k[i] <= max && min <= max / k[i] * k[i] &&
max / k[i] * k[i] <= max) {
min = (min + k[i] - 1) / k[i] * k[i];
max = max / k[i] * k[i] + k[i] - 1;
} else {
dekiru = false;
}
}
Console.WriteLine(dekiru ? (min + " " + max) : "-1");
// main↑
}
public class SegmentTree<Monoid> {
private bool debug = false;
// 0-indexed SegmentTree
public int size;
Monoid[] segTree;
Monoid unit;
public SegmentTree(int inSize, Monoid unit) {
this.unit = unit;
size = 2;
while (size < inSize)
size *= 2;
segTree = new Monoid[2 * size];
for (int i = 0; i < segTree.Length; i++) {
segTree[i] = unit;
// 単位元なので全部に代入しておけばよい
}
}
public int BinarySearch(int x) {
int high = size;
int low = 0;
int mid = (high + low) / 2;
while (low < high) {
// Console.WriteLine(low + " " + high);
Monoid cmp = NonRecursiveQuery(0, mid);
// Console.WriteLine("[ 0, " + mid + " ] -> " + cmp);
if ((dynamic)cmp >= x) {
high = mid;
} else if ((dynamic)cmp < x) {
low = mid + 1;
}
mid = (high + low) / 2;
}
return mid;
}
public void set(int iter, Monoid val) { segTree[iter + size - 1] = val; }
public Monoid GetMonoid(int index) { return segTree[index + size - 1]; }
public void add(int iter, Monoid val) {
update(iter, (dynamic)segTree[iter + size - 1] + (dynamic)val);
}
public void build() {
// 2段目より上の構築
for (int k = size - 2; k >= 0; k--) {
segTree[k] = F(segTree[2 * k + 1], segTree[2 * k + 2]);
}
}
public Monoid F(Monoid m1, Monoid m2) {
Monoid res = GCD(m1, m2);
return res;
}
public Monoid Query(int ql, int qr, int index, int nl, int nr) {
// Recursive
// [ql, qr)について考える
// index に対応する範囲 nl <= x <= nr
if (nr <= ql || qr <= nl) {
if (debug)
Console.WriteLine("Out: [l , r), [" + nl + " ," + nr + "), " +
"index: " + index + " ,unit:" + unit);
return unit;
}
if (ql <= nl && nr <= qr) {
if (debug)
Console.WriteLine("All in [l , r): [" + nl + " ," + nr + "), " +
"index: " + index + ",rangeAns:" + segTree[index]);
return segTree[index];
} else {
Monoid vl = Query(ql, qr, index * 2 + 1, nl, (nl + nr) / 2);
Monoid vr = Query(ql, qr, index * 2 + 2, (nl + nr) / 2, nr);
if (debug)
Console.WriteLine("Recursive: [l , r),+: [" + nl + ", " + nr +
"), index->" + index);
if (debug)
Console.WriteLine("(vl, vr): (" + vl + ", " + vr + ")");
return F(vl, vr);
}
}
public Monoid NonRecursiveQuery(int l, int r) {
// 区間 -> [ l , r ]
// 非再帰
int L = l + size - 1;
int R = r + size - 1;
Monoid s = unit;
while (L <= R) {
if (L % 2 == 0) {
s = F(s, segTree[L]);
L++;
}
if (R % 2 == 1) {
s = F(s, segTree[R]);
}
L /= 2;
R /= 2;
R--;
}
return s;
}
public void update(int k, Monoid x) {
k += size - 1;
segTree[k] = x;
while (true) {
k = (k - 1) / 2;
segTree[k] = F(segTree[k * 2 + 1], segTree[k * 2 + 2]);
if (k == 0) {
break;
}
}
}
public void print() {
Console.Write("Print:");
for (int i = 0; i < segTree.Length; i++) {
Console.Write(segTree[i] + " ");
}
Console.WriteLine("");
}
}
static int Nibutan(long[] array, long k) {
int low = 0;
int high = array.Length - 1;
int mid = high;
while (low < high) {
mid = (low + high) / 2;
if (array[mid] >= k) // k以上の最小index.ココを変えるだけ
{
high = mid;
} else {
low = mid + 1;
}
mid = (low + high) / 2;
}
return mid;
}
static int ScanOneInt() { return int.Parse(Console.ReadLine()); }
static long ScanOneLong() { return long.Parse(Console.ReadLine()); }
static string[] ScanStringArray(int lines) {
string[] str = new string[lines];
for (int i = 0; i < lines; i++) {
str[i] = Console.ReadLine();
}
return str;
}
static int[] ScanIntArray(int t) {
string[] str = Console.ReadLine().Split(' ');
int[] ar = new int[t];
for (int i = 0; i < t; i++) {
ar[i] = int.Parse(str[i]);
}
return ar;
}
static string[] ScanStringArrayInOneLine(int t) {
string[] str = Console.ReadLine().Split(' ');
return str;
}
static Tuple<int, int> ScanTuple() {
int[] tmp = ScanIntArray(2);
return new Tuple<int, int>(tmp[0], tmp[1] * -1);
}
static long[] ScanLongArray(int t) {
string[] str = Console.ReadLine().Split(' ');
long[] ar = new long[t];
for (int i = 0; i < t; i++) {
ar[i] = long.Parse(str[i]);
}
return ar;
}
static double[] ScanDoubleArray(int t) {
string[] str = Console.ReadLine().Split(' ');
double[] ar = new double[t];
for (int i = 0; i < t; i++) {
ar[i] = double.Parse(str[i]);
}
return ar;
}
static int[,] ScanIntSquareArray(int h, int w) {
int[,] resAr = new int[h, w];
for (int i = 0; i < h; i++) {
int[] ar = ScanIntArray(w);
for (int j = 0; j < w; j++) {
resAr[i, j] = ar[j];
}
}
return resAr;
}
static int[,] CombModMake() {
int[,] res = new int[2005, 2005];
for (int i = 0; i < 2005; i++) {
for (int j = 0; j < 2005; j++) {
if (i == 0 || i < j) {
res[i, j] = 0;
} else if (j == 0 || i == j) {
res[i, j] = 1;
} else {
res[i, j] = (res[i - 1, j] + res[i - 1, j - 1]) % (int)MOD;
}
}
}
return res;
}
// int, long両方で出来るGCDを作った
static T GCD<T>(T a, T b) {
if ((dynamic)b == 0) {
return a;
} else {
return GCD((dynamic)b, (dynamic)a % (dynamic)b);
}
}
static bool isPrime(int a) // O(sqrt N)
{
int max = (int)Math.Sqrt(a);
if (a == 1)
return false;
for (int i = 2; i <= max; i++) {
if (a % i == 0) {
return false;
}
}
return true;
}
}
public class Pair<T, U> : IComparable
where T : IComparable<T>
where U : IComparable<U> {
public T Item1;
public U Item2;
public int CompareTo(object obj) {
Pair<T, U> pair = (Pair<T, U>)obj;
return Item1.CompareTo(pair.Item1);
}
public Pair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
// 計算量: Push -> O(logN), Peek -> O(1)。Clear() -> O(logN)
// ToArray()で配列化
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(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/*
-> Item: _heap(ヒープを持つ.sizeはmaxSize)
-> Item: _type -> 0:asc(昇順), 1:desc(降順)
*/
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_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);
// typeが0なら昇順, 1なら降順にソートするCompare
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() // O(1)
{
return _count;
}
public T Peek() // O(1)
{
return _heap[0];
}
public bool Contains(T x) // O(N)なので注意
{
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (Count() > 0)
Pop();
}
public IEnumerator<T> GetEnumerator() // なにこれ
{
var ret = new List<T>();
while (Count() > 0) {
ret.Add(Pop());
}
foreach (var r in ret) {
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 GenericOperation<T> {
public GenericOperation() {
var availableT =
new Type[] { typeof(int), typeof(uint), typeof(short),
typeof(ushort), typeof(long), typeof(ulong),
typeof(byte), typeof(decimal), typeof(double) };
if (!availableT.Contains(typeof(T))) {
throw new NotSupportedException();
}
var p1 = Expression.Parameter(typeof(T));
var p2 = Expression.Parameter(typeof(T));
Add = Expression.Lambda<Func<T, T, T>>(Expression.Add(p1, p2), p1, p2)
.Compile();
Subtract =
Expression.Lambda<Func<T, T, T>>(Expression.Subtract(p1, p2), p1, p2)
.Compile();
Multiply =
Expression.Lambda<Func<T, T, T>>(Expression.Multiply(p1, p2), p1, p2)
.Compile();
Divide = Expression.Lambda<Func<T, T, T>>(Expression.Divide(p1, p2), p1, p2)
.Compile();
Modulo = Expression.Lambda<Func<T, T, T>>(Expression.Modulo(p1, p2), p1, p2)
.Compile();
Equal =
Expression.Lambda<Func<T, T, bool>>(Expression.Equal(p1, p2), p1, p2)
.Compile();
GreaterThan =
Expression
.Lambda<Func<T, T, bool>>(Expression.GreaterThan(p1, p2), p1, p2)
.Compile();
GreaterThanOrEqual = Expression
.Lambda<Func<T, T, bool>>(
Expression.GreaterThanOrEqual(p1, p2), p1, p2)
.Compile();
LessThan =
Expression.Lambda<Func<T, T, bool>>(Expression.LessThan(p1, p2), p1, p2)
.Compile();
LessThanOrEqual = Expression
.Lambda<Func<T, T, bool>>(
Expression.LessThanOrEqual(p1, p2), p1, p2)
.Compile();
}
public Func<T, T, T> Add { get; private set; }
public Func<T, T, T> Subtract { get; private set; }
public Func<T, T, T> Multiply { get; private set; }
public Func<T, T, T> Divide { get; private set; }
public Func<T, T, T> Modulo { get; private set; }
public Func<T, T, bool> Equal { get; private set; }
public Func<T, T, bool> GreaterThan { get; private set; }
public Func<T, T, bool> GreaterThanOrEqual { get; private set; }
public Func<T, T, bool> LessThan { get; private set; }
public Func<T, T, bool> LessThanOrEqual { get; private set; }
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 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, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22]]
| 8
| 3,164
| 17
|
using System;
using System.Collections.Generic;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
long[] s = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
string ans = "-1";
long a = 2, b = 3;
bool d = false;
if (s[n - 1] == 2) {
for (int i = n - 2; i >= 0; i--) {
if (s[i] > b) {
d = true;
break;
} else if (a % s[i] != 0) {
a = a + (s[i] - (a % s[i]));
if (a % s[i + 1] == 0) {
d = true;
break;
}
}
b += (s[i] - (b % s[i]) - 1);
if (a > b) {
d = true;
break;
}
}
if (!d) {
ans = a.ToString() + " " + b.ToString();
}
}
Console.WriteLine("{0}", ans);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
long[] s = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
string ans = "-1";
long a = 2, b = 3;
bool d = false;
if (s[n - 1] == 2) {
for (int i = n - 2; i >= 0; i--) {
if (s[i] > b) {
d = true;
break;
} else if (a % s[i] != 0) {
a = a + (s[i] - (a % s[i]));
}
b += (s[i] - (b % s[i]) - 1);
if (a > b) {
d = true;
break;
}
}
if (!d) {
ans = a.ToString() + " " + b.ToString();
}
}
Console.WriteLine("{0}", ans);
}
}
|
[["-", 0, 57, 75, 57, 64, 196, 0, 57, 0, 121], ["-", 0, 57, 75, 57, 64, 196, 0, 57, 0, 24], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["-", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["-", 15, 16, 31, 16, 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, 72], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 75, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["-", 75, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 57, 75, 57, 64, 196, 0, 57, 0, 25], ["-", 75, 57, 64, 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, 211, 0, 146], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 64, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 64, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46]]
| 8
| 253
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
class Solution {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int l = 2, r = 2;
for (int i = a.Length - 1; i >= 0; i--) {
if (r / a[i] * a[i] < l) {
Console.WriteLine(-1);
return;
}
l = (l / a[i] * a[i] == l ? l / a[i] : l / a[i] + 1) * a[i];
r = r / a[i] * a[i] + a[i] - 1;
}
Console.WriteLine($"{l} {r}");
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
class Solution {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
long l = 2, r = 2;
for (int i = a.Length - 1; i >= 0; i--) {
if (r / a[i] * a[i] < l) {
Console.WriteLine(-1);
return;
}
l = l % a[i] == 0 ? l : (l / a[i] + 1) * a[i];
r = r / a[i] * a[i] + a[i] - 1;
}
Console.WriteLine($"{l} {r}");
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 41, 15, 16, 31, 16, 31, 16, 17, 85], ["-", 15, 16, 31, 16, 31, 16, 12, 204, 205, 22], ["-", 31, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 31, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 31, 23, 0, 41, 15, 16, 31, 16, 17, 48], ["+", 0, 11, 12, 41, 15, 16, 31, 16, 17, 109], ["-", 12, 16, 31, 23, 0, 41, 15, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 12, 203], ["-", 12, 16, 31, 23, 0, 41, 64, 16, 17, 85], ["-", 31, 23, 0, 41, 64, 16, 12, 204, 205, 22], ["-", 0, 41, 64, 16, 12, 204, 206, 207, 0, 70], ["-", 64, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 41, 64, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 11, 12, 41, 75, 16, 31, 23, 0, 24]]
| 8
| 213
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Test {
class Program {
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
long[] min = new long[n];
long[] max = new long[n];
min[n - 1] = x[n - 1];
max[n - 1] = x[n - 1] * 2 - 1;
if (x[n - 1] == 2) {
bool flag = true;
for (long i = n - 1; i > 0; i--) {
if (x[i] * 2 <= x[i - 1])
flag = false;
if (min[i] / x[i - 1] == max[i] / x[i - 1])
flag = false;
min[i - 1] = ((min[i] - 1) / x[i - 1] + 1) * x[i - 1];
max[i - 1] = (max[i] / x[i - 1] + 1) * x[i - 1] - 1;
}
Console.WriteLine(flag ? min[0] + " " + max[0] : "-1");
} else {
Console.WriteLine(-1);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Test {
class Program {
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
long[] min = new long[n];
long[] max = new long[n];
min[n - 1] = x[n - 1];
max[n - 1] = x[n - 1] * 2 - 1;
if (x[n - 1] == 2) {
bool flag = true;
for (long i = n - 1; i > 0; i--) {
if ((min[i] - 1) / x[i - 1] == max[i] / x[i - 1])
flag = false;
min[i - 1] = ((min[i] - 1) / x[i - 1] + 1) * x[i - 1];
max[i - 1] = (max[i] / x[i - 1] + 1) * x[i - 1] - 1;
}
Console.WriteLine(flag ? min[0] + " " + max[0] : "-1");
} else {
Console.WriteLine(-1);
}
}
}
}
|
[["-", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 23, 0, 16, 31, 204, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["-", 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, 211, 0, 147], ["-", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 64, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 64, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73]]
| 8
| 316
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression,
System.Linq.Expressions.BinaryExpression>;
using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>;
class Program
{
static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
static Scan sc = new Scan();
const int M = 1000000007;
// const int M = 998244353;
const long LM = (long)1e18;
const double eps = 1e-11;
static readonly int[] dd = { 0, 1, 0, -1, 0 };
static void Main()
{
int k = sc.Int;
var a = sc.IntArr;
if (a[k - 1] != 2) {
DBG(-1);
return;
}
long max = 3, min = 2;
for (int i = k - 2; i >= 0 ; i--)
{
if (max < a[i]) {
DBG(-1);
return;
}
if (min < a[i]) {
min = a[i];
}
else {
min = (min + a[i] - 1) / a[i] * a[i];
}
max = max / a[i] * a[i] + a[i] - 1;
// Prt(min, max);
}
Prt(min, max);
sw.Flush();
}
static void DBG(string a) => Console.WriteLine(a);
static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
static void DBG(params object[] a) => DBG(string.Join(" ", a));
static void Prt(string a) => sw.WriteLine(a);
static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
static void Prt(params object[] a) => Prt(string.Join(" ", a));
}
class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
public T v1;
public U v2;
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2);
public override string ToString() => v1 + " " + v2;
}
static class util
{
public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]);
public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2);
public static T sqr<T>(T a) => Operator<T>.Multiply(a, a);
public static T Max<T>(params T[] a) => a.Max();
public static T Min<T>(params T[] a) => a.Min();
public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; }
public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; }
public static T[] 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;
}
}
static class Operator<T>
{
static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x");
static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y");
public static readonly Func<T, T, T> Add = Lambda(Expression.Add);
public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract);
public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply);
public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide);
public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus);
public static readonly Func<T, T> Negate = Lambda(Expression.Negate);
public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile();
public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile();
}
class Scan
{
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => Console.ReadLine().Trim();
public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U>
{ T a; U b; Multi(out a, out b); return make_pair(a, b); }
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 []{' '}, System.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]); }
public 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 = 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]); f = cv<Y>(ar[5]); }
}
static class mymath
{
public static long Mod = 1000000007;
public static bool isprime(long a) {
if (a < 2) return false;
for (long i = 2; i * i <= a; i++) if (a % i == 0) return false;
return true;
}
public static bool[] sieve(int n) {
var p = new bool[n + 1];
for (int i = 2; i <= n; i++) p[i] = true;
for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false;
return p;
}
public static List<int> getprimes(int n) {
var prs = new List<int>();
var p = sieve(n);
for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i);
return prs;
}
public static long[][] E(int n) {
var ret = new long[n][];
for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; }
return ret;
}
public static double[][] dE(int n) {
var ret = new double[n][];
for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; }
return ret;
}
public static long[][] pow(long[][] A, long n) {
if (n == 0) return E(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double[][] pow(double[][] A, long n) {
if (n == 0) return dE(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0;
for (int i = 0; i < n; i++) ret += x[i] * y[i];
return ret;
}
public static double _dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0, r = 0;
for (int i = 0; i < n; i++) {
double s = ret + (x[i] * y[i] + r);
r = (x[i] * y[i] + r) - (s - ret);
ret = s;
}
return ret;
}
public static long dot(long[] x, long[] y) {
int n = x.Length;
long ret = 0;
for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod;
return ret;
}
public static T[][] trans<T>(T[][] A) {
int n = A[0].Length, m = A.Length;
var ret = new T[n][];
for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; }
return ret;
}
public static double[] mul(double a, double[] x) {
int n = x.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i];
return ret;
}
public static long[] mul(long a, long[] x) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod;
return ret;
}
public static double[] mul(double[][] A, double[] x) {
int n = A.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static long[] mul(long[][] A, long[] x) {
int n = A.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static double[][] mul(double a, double[][] A) {
int n = A.Length;
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static long[][] mul(long a, long[][] A) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static double[][] mul(double[][] A, double[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[][] mul(long[][] A, long[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[] add(long[] x, long[] y) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod;
return ret;
}
public static long[][] add(long[][] A, long[][] B) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]);
return ret;
}
public static long pow(long a, long b) {
if (a >= Mod) return pow(a % Mod, b);
if (a == 0) return 0;
if (b == 0) return 1;
var t = pow(a, b / 2);
if ((b & 1) == 0) return t * t % Mod;
return t * t % Mod * a % Mod;
}
public static long inv(long a) => pow(a, Mod - 2);
public static long gcd(long a, long b) {
while (b > 0) { var t = a % b; a = b; b = t; } return a;
}
// a x + b y = gcd(a, b)
public static long extgcd(long a, long b, out long x, out long y) {
long g = a; x = 1; y = 0;
if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; }
return g;
}
public static long lcm(long a, long b) => a / gcd(a, b) * b;
static long[] facts;
public static long[] setfacts(int n) {
facts = new long[n + 1];
facts[0] = 1;
for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod;
return facts;
}
public static long comb(int n, int r) {
if (n < 0 || r < 0 || r > n) return 0;
if (n - r < r) r = n - r;
if (r == 0) return 1;
if (r == 1) return n;
if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod;
int[] numer = new int[r], denom = new int[r];
for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; }
for (int p = 2; p <= r; p++) {
int piv = denom[p - 1];
if (piv > 1) {
int ofst = (n - r) % p;
for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; }
}
}
long ret = 1;
for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod;
return ret;
}
public static long[][] getcombs(int n) {
var ret = new long[n + 1][];
for (int i = 0; i <= n; i++) {
ret[i] = new long[i + 1];
ret[i][0] = ret[i][i] = 1;
for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod;
}
return ret;
}
// nC0, nC2, ..., nCn
public static long[] getcomb(int n) {
var ret = new long[n + 1];
ret[0] = 1;
for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod;
return ret;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression,
System.Linq.Expressions.BinaryExpression>;
using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>;
class Program
{
static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
static Scan sc = new Scan();
const int M = 1000000007;
// const int M = 998244353;
const long LM = (long)1e18;
const double eps = 1e-11;
static readonly int[] dd = { 0, 1, 0, -1, 0 };
static void Main()
{
int k = sc.Int;
var a = sc.IntArr;
if (a[k - 1] != 2) {
DBG(-1);
return;
}
long max = 3, min = 2;
for (int i = k - 2; i >= 0 ; i--)
{
if (max < a[i]) {
DBG(-1);
return;
}
if (min < a[i]) {
min = a[i];
}
else {
min = (min + a[i] - 1) / a[i] * a[i];
}
max = max / a[i] * a[i] + a[i] - 1;
if (min > max) {
DBG(-1);
return;
}
// Prt(min, max);
}
Prt(min, max);
sw.Flush();
}
static void DBG(string a) => Console.WriteLine(a);
static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
static void DBG(params object[] a) => DBG(string.Join(" ", a));
static void Prt(string a) => sw.WriteLine(a);
static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
static void Prt(params object[] a) => Prt(string.Join(" ", a));
}
class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
public T v1;
public U v2;
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2);
public override string ToString() => v1 + " " + v2;
}
static class util
{
public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]);
public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2);
public static T sqr<T>(T a) => Operator<T>.Multiply(a, a);
public static T Max<T>(params T[] a) => a.Max();
public static T Min<T>(params T[] a) => a.Min();
public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; }
public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; }
public static T[] 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;
}
}
static class Operator<T>
{
static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x");
static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y");
public static readonly Func<T, T, T> Add = Lambda(Expression.Add);
public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract);
public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply);
public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide);
public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus);
public static readonly Func<T, T> Negate = Lambda(Expression.Negate);
public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile();
public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile();
}
class Scan
{
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => Console.ReadLine().Trim();
public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U>
{ T a; U b; Multi(out a, out b); return make_pair(a, b); }
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 []{' '}, System.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]); }
public 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 = 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]); f = cv<Y>(ar[5]); }
}
static class mymath
{
public static long Mod = 1000000007;
public static bool isprime(long a) {
if (a < 2) return false;
for (long i = 2; i * i <= a; i++) if (a % i == 0) return false;
return true;
}
public static bool[] sieve(int n) {
var p = new bool[n + 1];
for (int i = 2; i <= n; i++) p[i] = true;
for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false;
return p;
}
public static List<int> getprimes(int n) {
var prs = new List<int>();
var p = sieve(n);
for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i);
return prs;
}
public static long[][] E(int n) {
var ret = new long[n][];
for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; }
return ret;
}
public static double[][] dE(int n) {
var ret = new double[n][];
for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; }
return ret;
}
public static long[][] pow(long[][] A, long n) {
if (n == 0) return E(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double[][] pow(double[][] A, long n) {
if (n == 0) return dE(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0;
for (int i = 0; i < n; i++) ret += x[i] * y[i];
return ret;
}
public static double _dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0, r = 0;
for (int i = 0; i < n; i++) {
double s = ret + (x[i] * y[i] + r);
r = (x[i] * y[i] + r) - (s - ret);
ret = s;
}
return ret;
}
public static long dot(long[] x, long[] y) {
int n = x.Length;
long ret = 0;
for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod;
return ret;
}
public static T[][] trans<T>(T[][] A) {
int n = A[0].Length, m = A.Length;
var ret = new T[n][];
for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; }
return ret;
}
public static double[] mul(double a, double[] x) {
int n = x.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i];
return ret;
}
public static long[] mul(long a, long[] x) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod;
return ret;
}
public static double[] mul(double[][] A, double[] x) {
int n = A.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static long[] mul(long[][] A, long[] x) {
int n = A.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static double[][] mul(double a, double[][] A) {
int n = A.Length;
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static long[][] mul(long a, long[][] A) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static double[][] mul(double[][] A, double[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[][] mul(long[][] A, long[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[] add(long[] x, long[] y) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod;
return ret;
}
public static long[][] add(long[][] A, long[][] B) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]);
return ret;
}
public static long pow(long a, long b) {
if (a >= Mod) return pow(a % Mod, b);
if (a == 0) return 0;
if (b == 0) return 1;
var t = pow(a, b / 2);
if ((b & 1) == 0) return t * t % Mod;
return t * t % Mod * a % Mod;
}
public static long inv(long a) => pow(a, Mod - 2);
public static long gcd(long a, long b) {
while (b > 0) { var t = a % b; a = b; b = t; } return a;
}
// a x + b y = gcd(a, b)
public static long extgcd(long a, long b, out long x, out long y) {
long g = a; x = 1; y = 0;
if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; }
return g;
}
public static long lcm(long a, long b) => a / gcd(a, b) * b;
static long[] facts;
public static long[] setfacts(int n) {
facts = new long[n + 1];
facts[0] = 1;
for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod;
return facts;
}
public static long comb(int n, int r) {
if (n < 0 || r < 0 || r > n) return 0;
if (n - r < r) r = n - r;
if (r == 0) return 1;
if (r == 1) return n;
if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod;
int[] numer = new int[r], denom = new int[r];
for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; }
for (int p = 2; p <= r; p++) {
int piv = denom[p - 1];
if (piv > 1) {
int ofst = (n - r) % p;
for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; }
}
}
long ret = 1;
for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod;
return ret;
}
public static long[][] getcombs(int n) {
var ret = new long[n + 1][];
for (int i = 0; i <= n; i++) {
ret[i] = new long[i + 1];
ret[i][0] = ret[i][i] = 1;
for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod;
}
return ret;
}
// nC0, nC2, ..., nCn
public static long[] getcomb(int n) {
var ret = new long[n + 1];
ret[0] = 1;
for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod;
return ret;
}
}
|
[["+", 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, 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, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 4,309
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace AtCoder {
class Program {
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
static Tuple<long, long> Convert(Tuple<long, long> tuple, long a) {
if (a > tuple.Item2) {
return null;
}
long min = (tuple.Item1 + a - 1) / a * a;
long max = tuple.Item2 / a * a + a - 1;
return new Tuple<long, long>(min, max);
}
static Tuple<long, long> Solve(long[] A) {
var tuple1 = new Tuple<long, long>(2, 2);
foreach (long a in A.Reverse()) {
var tuple2 = Convert(tuple1, a);
if (tuple2 != null) {
tuple1 = tuple2;
} else {
return null;
}
}
return tuple1;
}
static void Main(string[] args) {
int K = ReadInt();
long[] A = ReadLongs();
var ans = Solve(A);
if (ans != null) {
Console.WriteLine("{0} {1}", ans.Item1, ans.Item2);
} else {
Console.WriteLine(-1);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace AtCoder {
class Program {
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
static Tuple<long, long> Convert(Tuple<long, long> tuple, long a) {
if (a > tuple.Item2) {
return null;
}
long min = (tuple.Item1 + a - 1) / a * a;
long max = tuple.Item2 / a * a;
if (min > max) {
return null;
}
return new Tuple<long, long>(min, max + a - 1);
}
static Tuple<long, long> Solve(long[] A) {
var tuple1 = new Tuple<long, long>(2, 2);
foreach (long a in A.Reverse()) {
var tuple2 = Convert(tuple1, a);
if (tuple2 != null) {
tuple1 = tuple2;
} else {
return null;
}
}
return tuple1;
}
static void Main(string[] args) {
int K = ReadInt();
long[] A = ReadLongs();
var ans = Solve(A);
if (ans != null) {
Console.WriteLine("{0} {1}", ans.Item1, ans.Item2);
} else {
Console.WriteLine(-1);
}
}
}
}
|
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 72], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 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, 47], ["+", 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, 57, 64, 196, 0, 37, 0, 215], ["+", 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, 37, 0, 38], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 230, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 230, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 419
| 19
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public static class TemplateExtension {
public static X[] MakeArray<X>(this int count, Func<int, X> func) {
var xs = new X[count];
for (var i = 0; i < count; i++) {
xs[i] = func(i);
}
return xs;
}
public static int[] Range(this int count, int start = 0) {
return count.MakeArray(i => i + start);
}
public static string Intercalate<X>(this IEnumerable<X> @this,
string separator) {
return string.Join(separator, @this);
}
public sealed class ValueIndexPair<T> : Tuple<T, int> {
public T Value {
get { return Item1; }
}
public int Index {
get { return Item2; }
}
public ValueIndexPair(T value, int index) : base(value, index) {}
}
public static IEnumerable<ValueIndexPair<X>>
Indexed<X>(this IEnumerable<X> @this) {
var i = 0;
foreach (var x in @this) {
yield return new ValueIndexPair<X>(x, i);
i++;
}
}
}
public sealed class Scanner {
private readonly TextReader _reader;
private readonly StringBuilder _sb = new StringBuilder();
/// <summary>
/// Reads next word separated by spaces.
/// </summary>
public string Word() {
_sb.Clear();
while (true) {
var r = _reader.Read();
if (r == ' ' || r == '\r' || r == '\n') {
if (r == '\r' && _reader.Peek() == '\n') {
_reader.Read();
}
// Ignore leading spaces.
if (_sb.Length == 0)
continue;
break;
} else if (r == -1) {
break;
} else {
_sb.Append((char)r);
}
}
return _sb.ToString();
}
/// <summary>
/// Reads next word as <see cref="int"/>.
/// </summary>
public int N() { return int.Parse(Word().Trim()); }
/// <summary>
/// Reads next word as <see cref="long"/>.
/// </summary>
public long L() { return long.Parse(Word()); }
/// <summary>
/// Reads next word as <see cref="double"/>.
/// </summary>
public double F() { return double.Parse(Word()); }
/// <summary>
/// Reads next line and splits it by spaces.
/// </summary>
public X[] Words<X>(Func<string, X> func) {
return _reader.ReadLine().Split(' ').Select(func).ToArray();
}
public Scanner(TextReader reader) { _reader = reader; }
}
public partial class Program {
private readonly TextReader _input;
private readonly TextWriter _output;
private readonly Scanner _scanner;
private void WriteLine(int value) { _output.WriteLine(value); }
private void WriteLine(long value) { _output.WriteLine(value); }
private void WriteLine(double value) { _output.WriteLine(value); }
private void WriteLine(char value) { _output.WriteLine(value); }
private void WriteLine(string value) { _output.WriteLine(value); }
public Program(TextReader input, TextWriter output) {
_input = input;
_output = output;
_scanner = new Scanner(input);
}
public static void Main(string[] args) {
new Program(Console.In, Console.Out).EntryPoint();
}
}
public sealed partial class Program {
int K;
int[] A;
private void G(int a, ref int l, ref int r) {
// l 以上の a の倍数のうち最小のもの
var s = ((l + a - 1) / a) * a;
// r 未満の a の倍数のうち最大のもの
var t = ((r - 1) / a) * a;
l = s;
r = t + a;
// Console.Error.WriteLine(string.Concat(l, " ", r));
}
private string Solve() {
var ps = A.Reverse().ToArray();
var l = 2;
var r = 3;
for (var i = K - 1; i >= 0; i--) {
G(A[i], ref l, ref r);
if (l >= r)
return "-1";
}
return string.Concat(l, " ", r - 1);
}
public void EntryPoint() {
var I = _scanner;
K = I.N();
A = K.MakeArray(i => I.N());
WriteLine(Solve());
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public static class TemplateExtension {
public static X[] MakeArray<X>(this int count, Func<int, X> func) {
var xs = new X[count];
for (var i = 0; i < count; i++) {
xs[i] = func(i);
}
return xs;
}
public static int[] Range(this int count, int start = 0) {
return count.MakeArray(i => i + start);
}
public static string Intercalate<X>(this IEnumerable<X> @this,
string separator) {
return string.Join(separator, @this);
}
public sealed class ValueIndexPair<T> : Tuple<T, int> {
public T Value {
get { return Item1; }
}
public int Index {
get { return Item2; }
}
public ValueIndexPair(T value, int index) : base(value, index) {}
}
public static IEnumerable<ValueIndexPair<X>>
Indexed<X>(this IEnumerable<X> @this) {
var i = 0;
foreach (var x in @this) {
yield return new ValueIndexPair<X>(x, i);
i++;
}
}
}
public sealed class Scanner {
private readonly TextReader _reader;
private readonly StringBuilder _sb = new StringBuilder();
/// <summary>
/// Reads next word separated by spaces.
/// </summary>
public string Word() {
_sb.Clear();
while (true) {
var r = _reader.Read();
if (r == ' ' || r == '\r' || r == '\n') {
if (r == '\r' && _reader.Peek() == '\n') {
_reader.Read();
}
// Ignore leading spaces.
if (_sb.Length == 0)
continue;
break;
} else if (r == -1) {
break;
} else {
_sb.Append((char)r);
}
}
return _sb.ToString();
}
/// <summary>
/// Reads next word as <see cref="int"/>.
/// </summary>
public int N() { return int.Parse(Word().Trim()); }
/// <summary>
/// Reads next word as <see cref="long"/>.
/// </summary>
public long L() { return long.Parse(Word()); }
/// <summary>
/// Reads next word as <see cref="double"/>.
/// </summary>
public double F() { return double.Parse(Word()); }
/// <summary>
/// Reads next line and splits it by spaces.
/// </summary>
public X[] Words<X>(Func<string, X> func) {
return _reader.ReadLine().Split(' ').Select(func).ToArray();
}
public Scanner(TextReader reader) { _reader = reader; }
}
public partial class Program {
private readonly TextReader _input;
private readonly TextWriter _output;
private readonly Scanner _scanner;
private void WriteLine(int value) { _output.WriteLine(value); }
private void WriteLine(long value) { _output.WriteLine(value); }
private void WriteLine(double value) { _output.WriteLine(value); }
private void WriteLine(char value) { _output.WriteLine(value); }
private void WriteLine(string value) { _output.WriteLine(value); }
public Program(TextReader input, TextWriter output) {
_input = input;
_output = output;
_scanner = new Scanner(input);
}
public static void Main(string[] args) {
new Program(Console.In, Console.Out).EntryPoint();
}
}
public sealed partial class Program {
int K;
long[] A;
private void G(long a, ref long l, ref long r) {
// l 以上の a の倍数のうち最小のもの
var s = ((l + a - 1) / a) * a;
// r 未満の a の倍数のうち最大のもの
var t = ((r - 1) / a) * a;
l = s;
r = t + a;
// Console.Error.WriteLine(string.Concat(l, " ", r));
}
private string Solve() {
var ps = A.Reverse().ToArray();
long l = 2;
long r = 3;
for (var i = K - 1; i >= 0; i--) {
G(A[i], ref l, ref r);
if (l >= r)
return "-1";
}
return string.Concat(l, " ", r - 1);
}
public void EntryPoint() {
var I = _scanner;
K = I.N();
A = K.MakeArray(i => I.L());
WriteLine(Solve());
}
}
|
[["-", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 141, 22]]
| 8
| 916
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.AGC020 {
class IceRinkGame {
public static void Main() {
var k = int.Parse(ReadLine().Trim());
var a = ReadLine().Trim().Split(' ').Select(_ => int.Parse(_)).Reverse();
int min_rest = 2, max_rest = 2;
foreach (var ar in a) {
var temp = MinChildren(ar, min_rest, max_rest);
max_rest = MaxChildren(ar, min_rest, max_rest);
min_rest = temp;
}
if (min_rest == -1)
WriteLine(-1);
else
WriteLine($"{min_rest} {max_rest}");
}
//脱落する人数は高々Ai - 1人
//突破する人数はN * Ai人
static int MinChildren(int group, int min_rest, int max_rest) {
if (min_rest == -1)
return -1;
if (min_rest % group == 0)
return min_rest;
return (min_rest / group != max_rest / group)
? group * (min_rest / group + 1)
: -1;
}
static int MaxChildren(int group, int min_rest, int max_rest) {
if (min_rest == -1)
return -1;
return max_rest / group * group + group - 1;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.AGC020 {
class IceRinkGame {
public static void Main() {
var k = int.Parse(ReadLine().Trim());
var a = ReadLine().Trim().Split(' ').Select(_ => long.Parse(_)).Reverse();
long min_rest = 2, max_rest = 2;
foreach (var ar in a) {
var temp = MinChildren(ar, min_rest, max_rest);
max_rest = MaxChildren(ar, min_rest, max_rest);
min_rest = temp;
}
if (min_rest == -1)
WriteLine(-1);
else
WriteLine($"{min_rest} {max_rest}");
}
//脱落する人数は高々Ai - 1人
//突破する人数はN * Ai人
static long MinChildren(long group, long min_rest, long max_rest) {
if (min_rest == -1)
return -1;
if (min_rest % group == 0)
return min_rest;
return (min_rest / group != max_rest / group)
? group * (min_rest / group + 1)
: -1;
}
static long MaxChildren(long group, long min_rest, long max_rest) {
if (min_rest == -1)
return -1;
return max_rest / group * group + group - 1;
}
}
}
|
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199]]
| 8
| 273
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
class Program {
static StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
static Scan sc = new Scan();
static void Main(string[] args) {
int n = sc.Int;
var a = sc.IntArr;
Array.Sort(a);
int sum = a.Sum();
int lim = sum / 2 + 1;
var dp = new Bitset(lim);
dp[0] = true;
for (int i = 0; i < n; i++)
dp = dp | dp << a[i];
for (int i = lim - 1; i >= 0; i--) {
if (dp[i]) {
Prt(sum - i);
break;
}
}
sw.Flush();
}
static void Prt(string a) => sw.WriteLine(a);
static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
static void Prt(params object[] a) => Prt(string.Join(" ", a));
}
class Scan {
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => Console.ReadLine().Trim();
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[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
}
class Bitset {
int size;
ulong[] bits;
public Bitset(int n) {
size = n;
bits = new ulong[(n + 63) / 64];
}
public Bitset(IList<bool> b) : this(b.Count) {
for (int i = 0; i < size; i++)
this[i] = b[i];
}
public void fill(bool b) {
for (int i = 0; i < bits.Length; i++)
bits[i] = b ? ulong.MaxValue : 0;
trim();
}
public bool this[int i] {
set {
if (value)
bits[i >> 6] |= 1UL << (i & 63);
else
bits[i >> 6] &= ~(1UL << (i & 63));
}
get { return (bits[i >> 6] >> (i & 63) & 1) == 1; }
}
void trim() {
if ((size & 63) > 0)
bits[bits.Length - 1] &= (1UL << (size & 63)) - 1UL;
}
public static Bitset operator &(Bitset a, Bitset b) {
var ret = new Bitset(a.size);
for (int i = 0; i < ret.bits.Length; i++)
ret.bits[i] = a.bits[i] & b.bits[i];
return ret;
}
public static Bitset operator |(Bitset a, Bitset b) {
var ret = new Bitset(a.size);
for (int i = 0; i < ret.bits.Length; i++)
ret.bits[i] = a.bits[i] | b.bits[i];
return ret;
}
public static Bitset operator ^(Bitset a, Bitset b) {
var ret = new Bitset(a.size);
for (int i = 0; i < ret.bits.Length; i++)
ret.bits[i] = a.bits[i] ^ b.bits[i];
return ret;
}
public static Bitset operator <<(Bitset a, int k) {
if (k < 0)
return a >> -k;
var ret = new Bitset(a.size);
for (int i = k >> 6; i < ret.bits.Length; i++)
ret.bits[i] =
a.bits[i - (k >> 6)] << (k & 63) |
(i > (k >> 6) ? a.bits[i - 1 - (k >> 6)] >> 64 - (k & 63) : 0);
ret.trim();
return ret;
}
public static Bitset operator>>(Bitset a, int k) {
if (k < 0)
return a << -k;
var ret = new Bitset(a.size);
for (int i = 0; i + (k >> 6) < ret.bits.Length; i++)
ret.bits[i] = a.bits[i + (k >> 6)] >> (k & 63) |
(i + (k >> 6) < ret.bits.Length - 1
? a.bits[i + 1 + (k >> 6)] << 64 - (k & 63)
: 0);
return ret;
}
public Bitset Lrotate(int k) => this << k | this >> (size - k);
public Bitset Rrotate(int k) => this >> k | this << (size - k);
public bool[] ToBoolean() {
var ret = new bool[size];
for (int i = 0; i < size; i++)
ret[i] = this[i];
return ret;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
class Program {
static StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
static Scan sc = new Scan();
static void Main(string[] args) {
int n = sc.Int;
var a = sc.IntArr;
Array.Sort(a);
int sum = a.Sum();
int lim = sum / 2 + 1;
var dp = new Bitset(lim);
dp[0] = true;
for (int i = 0; i < n; i++)
dp = dp | dp << a[i];
for (int i = lim - 1; i >= 0; i--) {
if (dp[i]) {
Prt(sum - i);
break;
}
}
sw.Flush();
}
static void Prt(string a) => sw.WriteLine(a);
static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
static void Prt(params object[] a) => Prt(string.Join(" ", a));
}
class Scan {
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => Console.ReadLine().Trim();
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[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
}
class Bitset {
int size;
ulong[] bits;
public Bitset(int n) {
size = n;
bits = new ulong[(n + 63) / 64];
}
public Bitset(IList<bool> b) : this(b.Count) {
for (int i = 0; i < size; i++)
this[i] = b[i];
}
public void fill(bool b) {
for (int i = 0; i < bits.Length; i++)
bits[i] = b ? ulong.MaxValue : 0;
trim();
}
public bool this[int i] {
set {
if (value)
bits[i >> 6] |= 1UL << (i & 63);
else
bits[i >> 6] &= ~(1UL << (i & 63));
}
get { return (bits[i >> 6] >> (i & 63) & 1) == 1; }
}
void trim() {
if ((size & 63) > 0)
bits[bits.Length - 1] &= (1UL << (size & 63)) - 1UL;
}
public static Bitset operator &(Bitset a, Bitset b) {
var ret = new Bitset(a.size);
for (int i = 0; i < ret.bits.Length; i++)
ret.bits[i] = a.bits[i] & b.bits[i];
return ret;
}
public static Bitset operator |(Bitset a, Bitset b) {
var ret = new Bitset(a.size);
for (int i = 0; i < ret.bits.Length; i++)
ret.bits[i] = a.bits[i] | b.bits[i];
return ret;
}
public static Bitset operator ^(Bitset a, Bitset b) {
var ret = new Bitset(a.size);
for (int i = 0; i < ret.bits.Length; i++)
ret.bits[i] = a.bits[i] ^ b.bits[i];
return ret;
}
public static Bitset operator <<(Bitset a, int k) {
if (k < 0)
return a >> -k;
var ret = new Bitset(a.size);
for (int i = k >> 6; i < ret.bits.Length; i++)
ret.bits[i] = a.bits[i - (k >> 6)] << (k & 63) |
(i > (k >> 6) && (k & 63) != 0
? a.bits[i - 1 - (k >> 6)] >> 64 - (k & 63)
: 0);
ret.trim();
return ret;
}
public static Bitset operator>>(Bitset a, int k) {
if (k < 0)
return a << -k;
var ret = new Bitset(a.size);
for (int i = 0; i + (k >> 6) < ret.bits.Length; i++)
ret.bits[i] = a.bits[i + (k >> 6)] >> (k & 63) |
(i + (k >> 6) < ret.bits.Length - 1 && (k & 63) != 0
? a.bits[i + 1 + (k >> 6)] << 64 - (k & 63)
: 0);
return ret;
}
public Bitset Lrotate(int k) => this << k | this >> (size - k);
public Bitset Rrotate(int k) => this >> k | this << (size - k);
public bool[] ToBoolean() {
var ret = new bool[size];
for (int i = 0; i < size; i++)
ret[i] = this[i];
return ret;
}
}
|
[["+", 12, 16, 12, 23, 0, 41, 15, 16, 17, 98], ["+", 0, 41, 15, 16, 12, 16, 31, 23, 0, 24], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 17, 67], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 41, 15, 16, 12, 16, 31, 23, 0, 25], ["+", 12, 23, 0, 41, 15, 16, 12, 16, 17, 79], ["+", 12, 23, 0, 41, 15, 16, 12, 16, 12, 203]]
| 8
| 1,172
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace A {
class Program {
static void Main(string[] args) {
var K_S = Console.ReadLine()
.Split(' ')
.Select(x => int.Parse(x.ToString()))
.ToArray();
var K = K_S[1];
var S = K_S[0];
int counter = 0;
for (int i = 0; i <= S; i++) {
for (int j = 0; j <= S - i; j++) {
for (int k = 0; k <= S - i - j; k++) {
if (i * 10000 + j * 5000 + k * 1000 == K) {
Console.WriteLine("{0} {1} {2}", i, j, k);
return;
}
}
}
}
Console.WriteLine("{0} {1} {2}", -1, -1, -1);
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace A {
class Program {
static void Main(string[] args) {
var K_S = Console.ReadLine()
.Split(' ')
.Select(x => int.Parse(x.ToString()))
.ToArray();
var K = K_S[1];
var S = K_S[0];
int counter = 0;
for (int i = 0; i <= S; i++) {
for (int j = 0; j <= S - i; j++) {
int k = S - i - j;
if (i * 10000 + j * 5000 + k * 1000 == K) {
Console.WriteLine("{0} {1} {2}", i, j, k);
Console.ReadKey();
return;
}
}
}
Console.WriteLine("{0} {1} {2}", -1, -1, -1);
Console.ReadKey();
}
}
}
|
[["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 24], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 25], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 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, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 223
| 17
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
// 解答はココに書く
var n = cin.ReadInt;
var y = cin.ReadInt;
for (var i1 = 0; i1 <= n; i1++) {
for (var i2 = 0; i2 <= n - i1; i2++) {
for (var i3 = 0; i3 <= n - i1 - i2; i3++) {
if (y == i1 * 10000 + i2 * 5000 + i3 * 1000) {
WriteLine(String.Format("{0} {1} {2}", i1, i2, i3));
return;
}
}
}
}
WriteLine("-1 -1 -1");
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
// 解答はココに書く
var n = cin.ReadInt;
var y = cin.ReadInt;
for (var i1 = 0; i1 <= n; i1++) {
for (var i2 = 0; i2 <= n - i1; i2++) {
var i3 = n - i1 - i2;
if (y == i1 * 10000 + i2 * 5000 + i3 * 1000) {
WriteLine(String.Format("{0} {1} {2}", i1, i2, i3));
return;
}
}
}
WriteLine("-1 -1 -1");
}
}
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, 7, 8, 196, 0, 7, 0, 88], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 24], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 25], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 538
| 11
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main() {
var input =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var limit = input[0];
for (int i = 0; i < limit + 1; i++) {
var tenK = 10000 * i;
for (int j = 0; j < limit - i + 1; j++) {
var fiveK = 5000 * j;
var oneK = 1000 * (limit - j);
if (tenK + fiveK + oneK == input[1]) {
Console.WriteLine($"{i} {j} {limit - j}");
return;
}
}
}
Console.WriteLine("-1 -1 -1");
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main() {
var input =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var limit = input[0];
for (int i = 0; i <= limit; i++) {
var tenK = 10000 * i;
for (int j = 0; i + j <= limit; j++) {
var fiveK = 5000 * j;
var oneK = 1000 * (limit - i - j);
if (tenK + fiveK + oneK == input[1]) {
Console.WriteLine($"{i} {j} {limit - i - j}");
return;
}
}
}
Console.WriteLine("-1 -1 -1");
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 7, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 283, 0, 284, 0, 16, 31, 16, 17, 33], ["+", 0, 283, 0, 284, 0, 16, 31, 16, 12, 22]]
| 8
| 176
| 16
|
using System;
using System.Linq;
using static System.Console;
static class Extensions {
public static int ToInt(this string str) { return int.Parse(str); }
}
class Program {
public static void Main(string[] args) {
var arr = ReadLine().Split(' ').Select(x => x.ToInt()).ToArray();
var n = arr[0];
var y = arr[1];
var flag = false;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
var k = n - i - j;
var sum = 10000 * i + 5000 * j + 1000 * k;
if (sum == y) {
flag = true;
WriteLine($"{i} {j} {k}");
break;
}
}
}
if (!flag)
WriteLine("-1 -1 -1");
}
}
|
using System;
using System.Linq;
using static System.Console;
static class Extensions {
public static int ToInt(this string str) { return int.Parse(str); }
}
class Program {
public static void Main(string[] args) {
var arr = ReadLine().Split(' ').Select(x => x.ToInt()).ToArray();
var n = arr[0];
var y = arr[1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j + i <= n; j++) {
var k = n - i - j;
var sum = 10000 * i + 5000 * j + 1000 * k;
if (sum == y) {
WriteLine($"{i} {j} {k}");
return;
}
}
}
WriteLine("-1 -1 -1");
}
}
|
[["-", 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, 211, 0, 147], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 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, 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]]
| 8
| 203
| 22
|
using System;
class Program {
static void Main(string[] args) {
int cnt1;
int cnt2;
int[] cashNum = { 0, 0, 0 };
int sum = 0;
bool bk = false;
string[] str = Console.ReadLine().Split(' ');
int num = int.Parse(str[0]);
int cash = int.Parse(str[1]);
for (cnt1 = 0; cnt1 <= num; cnt1++) {
for (cnt2 = 0; cnt2 <= (num - cnt1); cnt2++) {
sum = (10000 * cnt1) + (5000 * cnt2) + (1000 * (num - cnt1 - cnt2));
if (cash == sum) {
cashNum[0] = cnt1;
cashNum[1] = cnt2;
cashNum[2] = (num - cnt1 - cnt2);
bk = true;
}
}
if (bk) {
break;
}
}
Console.WriteLine("{0} {1} {2}", cashNum[0], cashNum[1], cashNum[2]);
}
}
|
using System;
class Program {
static void Main(string[] args) {
int cnt1;
int cnt2;
int[] cashNum = { -1, -1, -1 };
int sum = 0;
bool bk = false;
string[] str = Console.ReadLine().Split(' ');
int num = int.Parse(str[0]);
int cash = int.Parse(str[1]);
for (cnt1 = 0; cnt1 <= num; cnt1++) {
for (cnt2 = 0; cnt2 <= (num - cnt1); cnt2++) {
sum = (10000 * cnt1) + (5000 * cnt2) + (1000 * (num - cnt1 - cnt2));
if (cash == sum) {
cashNum[0] = cnt1;
cashNum[1] = cnt2;
cashNum[2] = (num - cnt1 - cnt2);
bk = true;
}
}
if (bk) {
break;
}
}
Console.WriteLine("{0} {1} {2}", cashNum[0], cashNum[1], cashNum[2]);
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 229, 0, 203], ["+", 0, 200, 0, 212, 0, 229, 0, 241, 0, 33], ["+", 0, 200, 0, 212, 0, 229, 0, 241, 0, 203]]
| 8
| 222
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace TestApp {
class Program {
static void Main(string[] args) {
var str = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var n = str[0];
var y = str[1];
Money money = null;
var lists = new List<Money>();
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
for (int k = 0; k <= n - j - k; k++) {
int a = i * 10000 + j * 5000;
if (i * 10000 + j * 5000 >= y)
break;
else if (a + 1000 * k == y) {
money = new Money() { Ichimanen = i, Gosenen = j, Senen = k };
}
}
}
}
if (money != null)
Console.WriteLine(money.Ichimanen + " " + money.Gosenen + " " +
money.Senen);
else
Console.WriteLine("-1 -1 -1");
Console.ReadLine();
}
}
class Money {
public int Gosenen = 0;
public int Ichimanen = 0;
public int Senen = 0;
public int Sum() { return Gosenen * 5000 + Ichimanen * 10000 + Senen * 1000; }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace TestApp {
class Program {
static void Main(string[] args) {
var str = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var n = str[0];
var y = str[1];
Money money = null;
var lists = new List<Money>();
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
int k = n - j - i;
int a = i * 10000 + j * 5000 + k * 1000;
if (a == y)
money = new Money() { Ichimanen = i, Gosenen = j, Senen = k };
}
}
if (money != null)
Console.WriteLine(money.Ichimanen + " " + money.Gosenen + " " +
money.Senen);
else
Console.WriteLine("-1 -1 -1");
Console.ReadLine();
}
}
class Money {
public int Gosenen = 0;
public int Ichimanen = 0;
public int Senen = 0;
public int Sum() { return Gosenen * 5000 + Ichimanen * 10000 + Senen * 1000; }
}
}
|
[["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 24], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 25], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 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], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 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, 93, 0, 94], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 72], ["-", 75, 57, 15, 16, 31, 16, 12, 16, 31, 203], ["-", 75, 57, 15, 16, 31, 16, 12, 16, 17, 48], ["-", 75, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 299
| 34
|
using System;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var N = input[0];
var Y = input[1];
JudgeMoney(N, Y);
}
static private void JudgeMoney(int N, int Y) {
for (int i = 0; i < 2000; i++) {
for (int j = 0; j < (2000 - i); j++) {
for (int k = 0; k < (2000 - i - j); k++) {
if (i + j + k != N) {
continue;
}
if (Y == (10000 * i + 5000 * j + 1000 * k)) {
Console.WriteLine($"{i} {j} {k}");
return;
}
}
}
}
Console.WriteLine("-1 -1 -1");
return;
}
}
}
|
using System;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ').Select(Int64.Parse).ToArray();
var N = input[0];
var Y = input[1];
JudgeMoney(N, Y);
}
static private void JudgeMoney(Int64 N, Int64 Y) {
for (Int64 i = 0; i <= N; i++) {
for (Int64 j = 0; j <= (2000 - i); j++) {
for (Int64 k = 0; k <= (2000 - i - j); k++) {
if (i + j + k != N) {
continue;
}
if (Y == (10000 * i + 5000 * j + 1000 * k)) {
Console.WriteLine($"{i} {j} {k}");
return;
}
}
}
}
Console.WriteLine("-1 -1 -1");
return;
}
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 22], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 7, 10, 198, 39, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 214
| 20
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Program {
internal static void Main(string[] args) {
var inp = ReadLine().Split(' ').Select(s => long.Parse(s)).ToList();
var N = inp[0];
var Y = inp[1];
for (long i = N; i >= 0; i--) {
for (long j = N - i; j >= 0; j--) {
for (long k = N - i - j; k >= 0; k--) {
if ((10000 * i) + (5000 * j) + (1000 * k) == Y) {
WriteLine($"{i} {j} {k}");
return;
}
}
}
}
WriteLine("-1 -1 -1");
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Program {
internal static void Main(string[] args) {
var inp = ReadLine().Split(' ').Select(s => long.Parse(s)).ToList();
var N = inp[0];
var Y = inp[1];
for (long i = N; i >= 0; i--) {
for (long j = N - i; j >= 0; j--) {
long k = N - i - j;
if ((10000 * i) + (5000 * j) + (1000 * k) == Y) {
WriteLine($"{i} {j} {k}");
return;
}
}
}
WriteLine("-1 -1 -1");
}
}
|
[["-", 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, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 20], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 68], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 25], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 187
| 11
|
using System;
using System.Linq;
namespace ABC085 {
class C {
static void Main(string[] args) {
var NY = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
var N = NY[0];
var Y = NY[1];
for (int i = 0; i <= N; i++)
for (int j = 0; j <= N - i; j++)
for (int k = 0; k <= N - i - j; k++)
if (10000 * i + 5000 * j + 1000 * k == Y) {
Console.WriteLine(string.Join(" ", i, j, k));
return;
}
Console.WriteLine("-1 -1 -1");
}
}
}
|
using System;
using System.Linq;
namespace ABC085 {
class C {
static void Main(string[] args) {
var NY = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
var N = NY[0];
var Y = NY[1];
for (int i = 0; i <= N; i++)
for (int j = 0; j <= N - i; j++) {
var k = N - i - j;
if (10000 * i + 5000 * j + 1000 * k == Y) {
Console.WriteLine(string.Join(" ", i, j, k));
return;
}
}
Console.WriteLine("-1 -1 -1");
}
}
}
|
[["-", 8, 196, 0, 7, 8, 7, 8, 7, 0, 88], ["-", 8, 196, 0, 7, 8, 7, 8, 7, 0, 24], ["-", 0, 7, 8, 7, 8, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 8, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 7, 8, 7, 0, 35], ["-", 0, 7, 8, 7, 8, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 7, 8, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 7, 8, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 7, 8, 7, 26, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 7, 8, 7, 0, 25], ["+", 8, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 172
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
var line = Console.ReadLine();
int n = int.Parse(line.Split(' ')[0]);
int y = int.Parse(line.Split(' ')[1]);
for (int a = 0; a <= n; a++) {
for (int b = 0; b <= n - a; b++) {
int c = n - a - b;
if (10000 * a + 5000 * b + 1000 * c == y) {
Console.WriteLine(a.ToString() + ' ' + b.ToString() + ' ' +
c.ToString());
return;
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
var line = Console.ReadLine();
int n = int.Parse(line.Split(' ')[0]);
int y = int.Parse(line.Split(' ')[1]);
for (int a = 0; a <= n; a++) {
for (int b = 0; b <= n - a; b++) {
int c = n - a - b;
if (10000 * a + 5000 * b + 1000 * c == y) {
Console.WriteLine(a.ToString() + ' ' + b.ToString() + ' ' +
c.ToString());
return;
}
}
}
Console.WriteLine("-1 -1 -1");
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 178
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression,
System.Linq.Expressions.BinaryExpression>;
using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>;
class Program
{
static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
static Scan sc = new Scan();
const int M = 1000000007;
// const int M = 998244353;
const long LM = (long)1e18;
const double eps = 1e-11;
static readonly int[] dd = { 0, 1, 0, -1, 0 };
static void Main()
{
int n, y;
sc.Multi(out n, out y);
if (n * 10000 < y || n * 1000 > y) {
DBG(-1, -1, -1);
return;
}
y -= n * 1000;
for (int i = 0; i <= n; i++)
{
if ((y - i * 9000) % 4000 == 0 && (y - i * 9000) / 4000 <= n - i) {
DBG(i, (y - i * 9000) / 4000, n - i - (y - i * 9000) / 4000);
return;
}
}
Prt(-1, -1, -1);
sw.Flush();
}
static void DBG(string a) => Console.WriteLine(a);
static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
static void DBG(params object[] a) => DBG(string.Join(" ", a));
static void Prt(string a) => sw.WriteLine(a);
static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
static void Prt(params object[] a) => Prt(string.Join(" ", a));
}
class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
public T v1;
public U v2;
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2);
public override string ToString() => v1 + " " + v2;
}
static class util
{
public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]);
public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2);
public static T sqr<T>(T a) => Operator<T>.Multiply(a, a);
public static T Max<T>(params T[] a) => a.Max();
public static T Min<T>(params T[] a) => a.Min();
public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; }
public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; }
public static T[] 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;
}
}
static class Operator<T>
{
static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x");
static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y");
public static readonly Func<T, T, T> Add = Lambda(Expression.Add);
public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract);
public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply);
public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide);
public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus);
public static readonly Func<T, T> Negate = Lambda(Expression.Negate);
public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile();
public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile();
}
class Scan
{
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => Console.ReadLine().Trim();
public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U>
{ T a; U b; Multi(out a, out b); return make_pair(a, b); }
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 []{' '}, System.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]); }
public 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 = 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]); f = cv<Y>(ar[5]); }
}
static class mymath
{
public static long Mod = 1000000007;
public static bool isprime(long a) {
if (a < 2) return false;
for (long i = 2; i * i <= a; i++) if (a % i == 0) return false;
return true;
}
public static bool[] sieve(int n) {
var p = new bool[n + 1];
for (int i = 2; i <= n; i++) p[i] = true;
for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false;
return p;
}
public static List<int> getprimes(int n) {
var prs = new List<int>();
var p = sieve(n);
for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i);
return prs;
}
public static long[][] E(int n) {
var ret = new long[n][];
for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; }
return ret;
}
public static double[][] dE(int n) {
var ret = new double[n][];
for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; }
return ret;
}
public static long[][] pow(long[][] A, long n) {
if (n == 0) return E(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double[][] pow(double[][] A, long n) {
if (n == 0) return dE(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0;
for (int i = 0; i < n; i++) ret += x[i] * y[i];
return ret;
}
public static double _dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0, r = 0;
for (int i = 0; i < n; i++) {
double s = ret + (x[i] * y[i] + r);
r = (x[i] * y[i] + r) - (s - ret);
ret = s;
}
return ret;
}
public static long dot(long[] x, long[] y) {
int n = x.Length;
long ret = 0;
for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod;
return ret;
}
public static T[][] trans<T>(T[][] A) {
int n = A[0].Length, m = A.Length;
var ret = new T[n][];
for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; }
return ret;
}
public static double[] mul(double a, double[] x) {
int n = x.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i];
return ret;
}
public static long[] mul(long a, long[] x) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod;
return ret;
}
public static double[] mul(double[][] A, double[] x) {
int n = A.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static long[] mul(long[][] A, long[] x) {
int n = A.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static double[][] mul(double a, double[][] A) {
int n = A.Length;
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static long[][] mul(long a, long[][] A) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static double[][] mul(double[][] A, double[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[][] mul(long[][] A, long[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[] add(long[] x, long[] y) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod;
return ret;
}
public static long[][] add(long[][] A, long[][] B) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]);
return ret;
}
public static long pow(long a, long b) {
if (a >= Mod) return pow(a % Mod, b);
if (a == 0) return 0;
if (b == 0) return 1;
var t = pow(a, b / 2);
if ((b & 1) == 0) return t * t % Mod;
return t * t % Mod * a % Mod;
}
public static long inv(long a) => pow(a, Mod - 2);
public static long gcd(long a, long b) {
while (b > 0) { var t = a % b; a = b; b = t; } return a;
}
// a x + b y = gcd(a, b)
public static long extgcd(long a, long b, out long x, out long y) {
long g = a; x = 1; y = 0;
if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; }
return g;
}
public static long lcm(long a, long b) => a / gcd(a, b) * b;
static long[] facts;
public static long[] setfacts(int n) {
facts = new long[n + 1];
facts[0] = 1;
for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod;
return facts;
}
public static long comb(int n, int r) {
if (n < 0 || r < 0 || r > n) return 0;
if (n - r < r) r = n - r;
if (r == 0) return 1;
if (r == 1) return n;
if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod;
int[] numer = new int[r], denom = new int[r];
for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; }
for (int p = 2; p <= r; p++) {
int piv = denom[p - 1];
if (piv > 1) {
int ofst = (n - r) % p;
for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; }
}
}
long ret = 1;
for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod;
return ret;
}
public static long[][] getcombs(int n) {
var ret = new long[n + 1][];
for (int i = 0; i <= n; i++) {
ret[i] = new long[i + 1];
ret[i][0] = ret[i][i] = 1;
for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod;
}
return ret;
}
// nC0, nC2, ..., nCn
public static long[] getcomb(int n) {
var ret = new long[n + 1];
ret[0] = 1;
for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod;
return ret;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression,
System.Linq.Expressions.BinaryExpression>;
using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>;
class Program
{
static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
static Scan sc = new Scan();
const int M = 1000000007;
// const int M = 998244353;
const long LM = (long)1e18;
const double eps = 1e-11;
static readonly int[] dd = { 0, 1, 0, -1, 0 };
static void Main()
{
int n, y;
sc.Multi(out n, out y);
if (n * 10000 < y || n * 1000 > y) {
DBG(-1, -1, -1);
return;
}
y -= n * 1000;
for (int i = 0; i <= n; i++)
{
if ((y - i * 9000) % 4000 == 0 && (y - i * 9000) / 4000 <= n - i && 0 <= (y - i * 9000) / 4000) {
DBG(i, (y - i * 9000) / 4000, n - i - (y - i * 9000) / 4000);
return;
}
}
Prt(-1, -1, -1);
sw.Flush();
}
static void DBG(string a) => Console.WriteLine(a);
static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
static void DBG(params object[] a) => DBG(string.Join(" ", a));
static void Prt(string a) => sw.WriteLine(a);
static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
static void Prt(params object[] a) => Prt(string.Join(" ", a));
}
class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
public T v1;
public U v2;
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2);
public override string ToString() => v1 + " " + v2;
}
static class util
{
public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]);
public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2);
public static T sqr<T>(T a) => Operator<T>.Multiply(a, a);
public static T Max<T>(params T[] a) => a.Max();
public static T Min<T>(params T[] a) => a.Min();
public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; }
public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; }
public static T[] 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;
}
}
static class Operator<T>
{
static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x");
static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y");
public static readonly Func<T, T, T> Add = Lambda(Expression.Add);
public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract);
public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply);
public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide);
public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus);
public static readonly Func<T, T> Negate = Lambda(Expression.Negate);
public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile();
public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile();
}
class Scan
{
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => Console.ReadLine().Trim();
public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U>
{ T a; U b; Multi(out a, out b); return make_pair(a, b); }
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 []{' '}, System.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]); }
public 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 = 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]); f = cv<Y>(ar[5]); }
}
static class mymath
{
public static long Mod = 1000000007;
public static bool isprime(long a) {
if (a < 2) return false;
for (long i = 2; i * i <= a; i++) if (a % i == 0) return false;
return true;
}
public static bool[] sieve(int n) {
var p = new bool[n + 1];
for (int i = 2; i <= n; i++) p[i] = true;
for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false;
return p;
}
public static List<int> getprimes(int n) {
var prs = new List<int>();
var p = sieve(n);
for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i);
return prs;
}
public static long[][] E(int n) {
var ret = new long[n][];
for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; }
return ret;
}
public static double[][] dE(int n) {
var ret = new double[n][];
for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; }
return ret;
}
public static long[][] pow(long[][] A, long n) {
if (n == 0) return E(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double[][] pow(double[][] A, long n) {
if (n == 0) return dE(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0;
for (int i = 0; i < n; i++) ret += x[i] * y[i];
return ret;
}
public static double _dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0, r = 0;
for (int i = 0; i < n; i++) {
double s = ret + (x[i] * y[i] + r);
r = (x[i] * y[i] + r) - (s - ret);
ret = s;
}
return ret;
}
public static long dot(long[] x, long[] y) {
int n = x.Length;
long ret = 0;
for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod;
return ret;
}
public static T[][] trans<T>(T[][] A) {
int n = A[0].Length, m = A.Length;
var ret = new T[n][];
for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; }
return ret;
}
public static double[] mul(double a, double[] x) {
int n = x.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i];
return ret;
}
public static long[] mul(long a, long[] x) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod;
return ret;
}
public static double[] mul(double[][] A, double[] x) {
int n = A.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static long[] mul(long[][] A, long[] x) {
int n = A.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static double[][] mul(double a, double[][] A) {
int n = A.Length;
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static long[][] mul(long a, long[][] A) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static double[][] mul(double[][] A, double[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[][] mul(long[][] A, long[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[] add(long[] x, long[] y) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod;
return ret;
}
public static long[][] add(long[][] A, long[][] B) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]);
return ret;
}
public static long pow(long a, long b) {
if (a >= Mod) return pow(a % Mod, b);
if (a == 0) return 0;
if (b == 0) return 1;
var t = pow(a, b / 2);
if ((b & 1) == 0) return t * t % Mod;
return t * t % Mod * a % Mod;
}
public static long inv(long a) => pow(a, Mod - 2);
public static long gcd(long a, long b) {
while (b > 0) { var t = a % b; a = b; b = t; } return a;
}
// a x + b y = gcd(a, b)
public static long extgcd(long a, long b, out long x, out long y) {
long g = a; x = 1; y = 0;
if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; }
return g;
}
public static long lcm(long a, long b) => a / gcd(a, b) * b;
static long[] facts;
public static long[] setfacts(int n) {
facts = new long[n + 1];
facts[0] = 1;
for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod;
return facts;
}
public static long comb(int n, int r) {
if (n < 0 || r < 0 || r > n) return 0;
if (n - r < r) r = n - r;
if (r == 0) return 1;
if (r == 1) return n;
if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod;
int[] numer = new int[r], denom = new int[r];
for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; }
for (int p = 2; p <= r; p++) {
int piv = denom[p - 1];
if (piv > 1) {
int ofst = (n - r) % p;
for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; }
}
}
long ret = 1;
for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod;
return ret;
}
public static long[][] getcombs(int n) {
var ret = new long[n + 1][];
for (int i = 0; i <= n; i++) {
ret[i] = new long[i + 1];
ret[i][0] = ret[i][i] = 1;
for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod;
}
return ret;
}
// nC0, nC2, ..., nCn
public static long[] getcomb(int n) {
var ret = new long[n + 1];
ret[0] = 1;
for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod;
return ret;
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 15, 16, 12, 16, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 17, 48], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 85], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25]]
| 8
| 4,296
| 12
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class hawawa {
static Printer sw =
new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
static void Main() {
Console.SetOut(sw);
solve();
Console.Out.Flush();
}
static void solve() {
Scanner scanner = new Scanner();
long n = scanner.nextInt(), y = scanner.nextInt();
for (long i = 0; i <= n; i++) {
for (long j = 0; j <= n - i; j++) {
if (1000 * i + 5000 * j + 10000 * (n - i - j) > y) {
break;
}
if (1000 * i + 5000 * j + 10000 * (n - i - j) == y) {
Console.WriteLine("{0} {1} {2}", n - i - j, j, i);
return;
}
}
}
Console.WriteLine("-1 -1 -1");
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next();
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
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) {}
}
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class hawawa {
static Printer sw =
new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
static void Main() {
Console.SetOut(sw);
solve();
Console.Out.Flush();
}
static void solve() {
Scanner scanner = new Scanner();
long n = scanner.nextInt(), y = scanner.nextInt();
for (long i = 0; i <= n; i++) {
for (long j = 0; j <= n - i; j++) {
if (1000 * i + 5000 * j + 10000 * (n - i - j) == y) {
Console.WriteLine("{0} {1} {2}", n - i - j, j, i);
return;
}
}
}
Console.WriteLine("-1 -1 -1");
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next();
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
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) {}
}
|
[["-", 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], ["-", 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], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 31, 203], ["-", 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, 72], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 31, 203], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 17, 48], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 31, 203], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 48], ["-", 15, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["-", 12, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["-", 12, 16, 12, 23, 0, 16, 31, 16, 17, 33], ["-", 12, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["-", 31, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["-", 31, 16, 12, 16, 12, 23, 0, 16, 12, 22], ["-", 15, 16, 31, 16, 12, 16, 12, 23, 0, 25]]
| 8
| 455
| 26
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace Program {
public class ABC085D {
static public void Main(string[] args) {
var N = NextInt;
var H = NextLong;
var count = 0;
var maxa = 0L;
var sum = 0L;
var bary = new long[N];
for (int i = 0; i < N; ++i) {
var a = NextLong;
var b = NextLong;
if (maxa < a)
maxa = a;
bary[i] = b;
}
Array.Sort(bary);
bary = bary.Reverse().ToArray();
foreach (var item in bary) {
sum += item;
++count;
if (sum >= H) {
Console.Write(count);
return;
}
}
Console.WriteLine(count + (H - sum - 1) / maxa + 1);
}
static class Console_ {
private static Queue<string> param = new Queue<string>();
public static int NextInt() => int.Parse(NextString());
public static long NextLong() => long.Parse(NextString());
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static int NextInt => Console_.NextInt();
static long NextLong => Console_.NextLong();
static string NextString => Console_.NextString();
static IEnumerable<int> Prime(int x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (int)(Math.Sqrt(x) / 2);
for (int i = 1; i <= max; ++i) {
if (!table[i]) {
var add = 2 * i + 1;
yield return add;
for (int j = 2 * i * (i + 1); j <= halfx; j += add) {
table[j] = true;
}
}
}
for (int i = max + 1; i <= halfx; ++i) {
if (!table[i])
yield return 2 * i + 1;
}
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace Program {
public class ABC085D {
static public void Main(string[] args) {
var N = NextInt;
var H = NextLong;
var count = 0;
var maxa = 0L;
var sum = 0L;
var bary = new long[N];
for (int i = 0; i < N; ++i) {
var a = NextLong;
var b = NextLong;
if (maxa < a)
maxa = a;
bary[i] = b;
}
Array.Sort(bary);
bary = bary.Reverse().ToArray();
foreach (var item in bary) {
if (item < maxa)
continue;
sum += item;
++count;
if (sum >= H) {
Console.Write(count);
return;
}
}
Console.WriteLine(count + (H - sum - 1) / maxa + 1);
}
static class Console_ {
private static Queue<string> param = new Queue<string>();
public static int NextInt() => int.Parse(NextString());
public static long NextLong() => long.Parse(NextString());
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static int NextInt => Console_.NextInt();
static long NextLong => Console_.NextLong();
static string NextString => Console_.NextString();
static IEnumerable<int> Prime(int x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (int)(Math.Sqrt(x) / 2);
for (int i = 1; i <= max; ++i) {
if (!table[i]) {
var add = 2 * i + 1;
yield return add;
for (int j = 2 * i * (i + 1); j <= halfx; j += add) {
table[j] = true;
}
}
}
for (int i = max + 1; i <= halfx; ++i) {
if (!table[i])
yield return 2 * i + 1;
}
}
}
}
|
[["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 210, 8, 196, 0, 57, 64, 116, 0, 35]]
| 8
| 485
| 8
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using static Math2;
using static Output;
public class CP {
public void Solve() {
Input sc = new Input();
long n, h;
long[] a, b;
sc.mul(out n, out h);
a = new long[n];
b = new long[n];
for (int i = 0; i < n; ++i) {
sc.mul(out a[i], out b[i]);
}
var aa = a.Max();
Array.Sort(b, (x, y) => (int)(y - x));
long cnt = 0;
for (int i = 0; i < n; ++i) {
if (aa >= b[i])
break;
h -= b[i];
++cnt;
}
cnt += (h + aa - 1) / aa;
Put(cnt);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const long MOD2 = 998244353;
public static long Power(long a, long b, long MOD = 1000000007) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
public static long Power2(long a, long b) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
public static long GCD(long a, long b) {
if (a == 0)
return b;
while (b > 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static long LCM(long a, long b) => (b / GCD(a, b)) * a;
public static long Comb(long n, long r, int MOD = 1000000007) {
if (r > n - r)
r = n - r;
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno = (Deno * i) % MOD;
Nume = Nume * (n - i + 1) % MOD;
}
return (Nume * inv(Deno)) % MOD;
}
public static long Comb2(long n, long r) {
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno *= i;
Nume *= n - i + 1;
}
return Nume / Deno;
}
public static long inv(long x, int MOD = 1000000007) {
return Power(x, MOD - 2, MOD);
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(string N) {
int ret = 0;
for (int i = 0; i < N.Length; ++i)
ret += N[i] - '0';
return ret;
}
public static string ConvertBase(long N, int K) {
StringBuilder ret = new StringBuilder();
while (N > 0) {
var r = N % K;
N /= K;
ret.Append(r);
}
return new string(ret.ToString().ToCharArray().Reverse().ToArray());
}
public static bool NextPermutation<T>(IList<T> lis, Comparison<T> cmp) {
int n = lis.Count;
int i = n - 1;
while (i - 1 >= 0) {
if (cmp(lis[i - 1], lis[i]) < 0)
break;
--i;
}
if (i == 0)
return false;
int j = i;
while (j + 1 < n) {
if (cmp(lis[i - 1], lis[j + 1]) > 0)
break;
++j;
}
var _q = lis[j];
lis[i - 1] = lis[j];
lis[i - 1] = _q;
int k = i;
int l = n - 1;
while (k < l) {
var _p = lis[k];
lis[l] = lis[k];
lis[l] = _p;
++k;
--l;
}
return true;
}
public static bool NextPermutation<T>(IList<T> lis) =>
NextPermutation(lis, Comparer<T>.Default.Compare);
}
public class PriorityQueue<T> {
List<T> _item;
public int Count {
get { return _item.Count; }
}
bool _isascend { get; set; }
public T Peek {
get { return _item[0]; }
}
Comparison<T> Comp;
public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null)
: this(Comparer<T>.Default.Compare, IsAscend, list) {}
public PriorityQueue(Comparison<T> cmp, bool IsAscend = true,
IEnumerable<T> list = null) {
_item = new List<T>();
_isascend = IsAscend;
this.Comp = cmp;
if (list != null) {
_item.AddRange(list);
Build();
}
}
private int Compare(int i, int j) => (_isascend ? -1 : 1) *
Comp(_item[i], _item[j]);
private void Swap(int i, int j) {
var t = _item[i];
_item[i] = _item[j];
_item[j] = t;
}
private int Parent(int i) => (i - 1) >> 1;
private int Left(int i) => (i << 1) + 1;
public T Enqueue(T val) {
int i = _item.Count;
_item.Add(val);
while (i > 0) {
int p = Parent(i);
if (Compare(i, p) > 0)
Swap(i, p);
i = p;
}
return val;
}
private void Heapify(int index) {
for (int i = index, j; (j = Left(i)) < _item.Count; i = j) {
if (j != _item.Count - 1 && Compare(j, j + 1) < 0)
j++;
if (Compare(i, j) < 0)
Swap(i, j);
}
}
public T Dequeue() {
T val = _item[0];
_item[0] = _item[_item.Count - 1];
_item.RemoveAt(_item.Count - 1);
Heapify(0);
return val;
}
private void Build() {
for (var i = (_item.Count >> 1) - 1; i >= 0; i--)
Heapify(i);
}
public bool Any() => Count > 0;
}
class Program {
static void Main(string[] args) {
var CP = new CP();
CP.Solve();
}
}
public static class Output {
public static void Put(string a) => Console.WriteLine(a);
public static void Put(params object[] i) => Put(string.Join(" ", i));
public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a));
public static void PutV<T>(IEnumerable<T> a) {
foreach (var z in a)
Put(z);
}
public static void YN(bool i) {
if (i)
Put("Yes");
else
Put("No");
}
}
public class Input {
public static string Str => Console.ReadLine();
public static bool IsTypeEqual<T, U>() => typeof(T).Equals(typeof(U));
public static T ConvertType<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
public static T Cast<T>(string s) {
if (IsTypeEqual<T, int>())
return ConvertType<T, int>(int.Parse(s));
else if (IsTypeEqual<T, long>())
return ConvertType<T, long>(long.Parse(s));
else if (IsTypeEqual<T, double>())
return ConvertType<T, double>(double.Parse(s));
else if (IsTypeEqual<T, char>())
return ConvertType<T, char>(char.Parse(s));
else
return ConvertType<T, string>(s);
}
public static T[] Castarr<T>(string[] s) {
var ret = new T[s.Length];
int i = 0;
if (IsTypeEqual<T, char>()) {
var list = new List<T>();
foreach (var t in s) {
foreach (var u in t) {
list.Add(ConvertType<T, char>(char.Parse(u.ToString())));
}
}
return list.ToArray();
}
foreach (var t in s) {
if (IsTypeEqual<T, int>())
ret[i++] = ConvertType<T, int>(int.Parse(t));
else if (IsTypeEqual<T, long>())
ret[i++] = ConvertType<T, long>(long.Parse(t));
else if (IsTypeEqual<T, double>())
ret[i++] = ConvertType<T, double>(double.Parse(t));
else
ret[i++] = ConvertType<T, string>(t);
}
return ret;
}
Queue<string> q = new Queue<string>();
void next() {
var ss = Str.Split(' ');
foreach (var item in ss)
q.Enqueue(item);
}
public T cin<T>() {
if (!q.Any())
next();
return Cast<T>(q.Dequeue());
}
public void mul<T>(out T t) { t = cin<T>(); }
public void mul<T, U>(out T t, out U u) {
t = cin<T>();
u = cin<U>();
}
public void mul<T, U, V>(out T t, out U u, out V v) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
}
public void mul<T, U, V, W>(out T t, out U u, out V v, out W w) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
}
public void mul<T, U, V, W, X>(out T t, out U u, out V v, out W w, out X x) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
x = cin<X>();
}
public void mul<T, U, V, W, X, Y>(out T t, out U u, out V v, out W w, out X x,
out Y y) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
x = cin<X>();
y = cin<Y>();
}
public void mul<T, U, V, W, X, Y, Z>(out T t, out U u, out V v, out W w,
out X x, out Y y, out Z z) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
x = cin<X>();
y = cin<Y>();
z = cin<Z>();
}
public T[] cinarr<T>() { return Castarr<T>(Str.Split(' ')); }
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using static Math2;
using static Output;
public class CP {
public void Solve() {
Input sc = new Input();
long n, h;
long[] a, b;
sc.mul(out n, out h);
a = new long[n];
b = new long[n];
for (int i = 0; i < n; ++i) {
sc.mul(out a[i], out b[i]);
}
var aa = a.Max();
Array.Sort(b, (x, y) => (int)(y - x));
long cnt = 0;
for (int i = 0; i < n; ++i) {
if (aa >= b[i])
break;
h -= b[i];
++cnt;
if (h <= 0) {
Put(cnt);
return;
}
}
cnt += (h + aa - 1) / aa;
Put(cnt);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const long MOD2 = 998244353;
public static long Power(long a, long b, long MOD = 1000000007) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
public static long Power2(long a, long b) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
public static long GCD(long a, long b) {
if (a == 0)
return b;
while (b > 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static long LCM(long a, long b) => (b / GCD(a, b)) * a;
public static long Comb(long n, long r, int MOD = 1000000007) {
if (r > n - r)
r = n - r;
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno = (Deno * i) % MOD;
Nume = Nume * (n - i + 1) % MOD;
}
return (Nume * inv(Deno)) % MOD;
}
public static long Comb2(long n, long r) {
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno *= i;
Nume *= n - i + 1;
}
return Nume / Deno;
}
public static long inv(long x, int MOD = 1000000007) {
return Power(x, MOD - 2, MOD);
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(string N) {
int ret = 0;
for (int i = 0; i < N.Length; ++i)
ret += N[i] - '0';
return ret;
}
public static string ConvertBase(long N, int K) {
StringBuilder ret = new StringBuilder();
while (N > 0) {
var r = N % K;
N /= K;
ret.Append(r);
}
return new string(ret.ToString().ToCharArray().Reverse().ToArray());
}
public static bool NextPermutation<T>(IList<T> lis, Comparison<T> cmp) {
int n = lis.Count;
int i = n - 1;
while (i - 1 >= 0) {
if (cmp(lis[i - 1], lis[i]) < 0)
break;
--i;
}
if (i == 0)
return false;
int j = i;
while (j + 1 < n) {
if (cmp(lis[i - 1], lis[j + 1]) > 0)
break;
++j;
}
var _q = lis[j];
lis[i - 1] = lis[j];
lis[i - 1] = _q;
int k = i;
int l = n - 1;
while (k < l) {
var _p = lis[k];
lis[l] = lis[k];
lis[l] = _p;
++k;
--l;
}
return true;
}
public static bool NextPermutation<T>(IList<T> lis) =>
NextPermutation(lis, Comparer<T>.Default.Compare);
}
public class PriorityQueue<T> {
List<T> _item;
public int Count {
get { return _item.Count; }
}
bool _isascend { get; set; }
public T Peek {
get { return _item[0]; }
}
Comparison<T> Comp;
public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null)
: this(Comparer<T>.Default.Compare, IsAscend, list) {}
public PriorityQueue(Comparison<T> cmp, bool IsAscend = true,
IEnumerable<T> list = null) {
_item = new List<T>();
_isascend = IsAscend;
this.Comp = cmp;
if (list != null) {
_item.AddRange(list);
Build();
}
}
private int Compare(int i, int j) => (_isascend ? -1 : 1) *
Comp(_item[i], _item[j]);
private void Swap(int i, int j) {
var t = _item[i];
_item[i] = _item[j];
_item[j] = t;
}
private int Parent(int i) => (i - 1) >> 1;
private int Left(int i) => (i << 1) + 1;
public T Enqueue(T val) {
int i = _item.Count;
_item.Add(val);
while (i > 0) {
int p = Parent(i);
if (Compare(i, p) > 0)
Swap(i, p);
i = p;
}
return val;
}
private void Heapify(int index) {
for (int i = index, j; (j = Left(i)) < _item.Count; i = j) {
if (j != _item.Count - 1 && Compare(j, j + 1) < 0)
j++;
if (Compare(i, j) < 0)
Swap(i, j);
}
}
public T Dequeue() {
T val = _item[0];
_item[0] = _item[_item.Count - 1];
_item.RemoveAt(_item.Count - 1);
Heapify(0);
return val;
}
private void Build() {
for (var i = (_item.Count >> 1) - 1; i >= 0; i--)
Heapify(i);
}
public bool Any() => Count > 0;
}
class Program {
static void Main(string[] args) {
var CP = new CP();
CP.Solve();
}
}
public static class Output {
public static void Put(string a) => Console.WriteLine(a);
public static void Put(params object[] i) => Put(string.Join(" ", i));
public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a));
public static void PutV<T>(IEnumerable<T> a) {
foreach (var z in a)
Put(z);
}
public static void YN(bool i) {
if (i)
Put("Yes");
else
Put("No");
}
}
public class Input {
public static string Str => Console.ReadLine();
public static bool IsTypeEqual<T, U>() => typeof(T).Equals(typeof(U));
public static T ConvertType<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
public static T Cast<T>(string s) {
if (IsTypeEqual<T, int>())
return ConvertType<T, int>(int.Parse(s));
else if (IsTypeEqual<T, long>())
return ConvertType<T, long>(long.Parse(s));
else if (IsTypeEqual<T, double>())
return ConvertType<T, double>(double.Parse(s));
else if (IsTypeEqual<T, char>())
return ConvertType<T, char>(char.Parse(s));
else
return ConvertType<T, string>(s);
}
public static T[] Castarr<T>(string[] s) {
var ret = new T[s.Length];
int i = 0;
if (IsTypeEqual<T, char>()) {
var list = new List<T>();
foreach (var t in s) {
foreach (var u in t) {
list.Add(ConvertType<T, char>(char.Parse(u.ToString())));
}
}
return list.ToArray();
}
foreach (var t in s) {
if (IsTypeEqual<T, int>())
ret[i++] = ConvertType<T, int>(int.Parse(t));
else if (IsTypeEqual<T, long>())
ret[i++] = ConvertType<T, long>(long.Parse(t));
else if (IsTypeEqual<T, double>())
ret[i++] = ConvertType<T, double>(double.Parse(t));
else
ret[i++] = ConvertType<T, string>(t);
}
return ret;
}
Queue<string> q = new Queue<string>();
void next() {
var ss = Str.Split(' ');
foreach (var item in ss)
q.Enqueue(item);
}
public T cin<T>() {
if (!q.Any())
next();
return Cast<T>(q.Dequeue());
}
public void mul<T>(out T t) { t = cin<T>(); }
public void mul<T, U>(out T t, out U u) {
t = cin<T>();
u = cin<U>();
}
public void mul<T, U, V>(out T t, out U u, out V v) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
}
public void mul<T, U, V, W>(out T t, out U u, out V v, out W w) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
}
public void mul<T, U, V, W, X>(out T t, out U u, out V v, out W w, out X x) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
x = cin<X>();
}
public void mul<T, U, V, W, X, Y>(out T t, out U u, out V v, out W w, out X x,
out Y y) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
x = cin<X>();
y = cin<Y>();
}
public void mul<T, U, V, W, X, Y, Z>(out T t, out U u, out V v, out W w,
out X x, out Y y, out Z z) {
t = cin<T>();
u = cin<U>();
v = cin<V>();
w = cin<W>();
x = cin<X>();
y = cin<Y>();
z = cin<Z>();
}
public T[] cinarr<T>() { return Castarr<T>(Str.Split(' ')); }
}
|
[["+", 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, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 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, 22], ["+", 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, 7, 8, 196, 0, 46]]
| 8
| 2,748
| 15
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static ABC085D.Input;
using static System.Math;
namespace ABC085D {
class Input {
private static String String() => Console.ReadLine();
private static IEnumerable<string> Split() => String().Split(' ');
private static long[] Long() => Split().Select(long.Parse).ToArray();
/// <summary>
/// 1行の文字列の入力
/// </summary>
public static void @in(out string s) => s = String();
/// <summary>
/// 複数行の文字列の入力
/// </summary>
public static void @in(long rowNumber, out string[] s) {
s = new String[rowNumber];
for (long i = 0; i < rowNumber; i++)
@in(out s[i]);
}
/// <summary>
/// 1行に書かれた1つの整数の入力
/// </summary>
public static void @in(out int i) { i = int.Parse(String()); }
/// <summary>
/// 1行に書かれた1つの整数の入力
/// </summary>
public static void @in(out long a) => a = Long()[0];
/// <summary>
/// 1行に書かれた2つの整数の入力
/// </summary>
public static void @in(out long a, out long b) {
long[] lArr = Long();
a = lArr[0];
b = lArr[1];
}
/// <summary>
/// 1行に書かれた3つの整数の入力
/// </summary>
public static void @in(out long a, out long b, out long c) {
long[] lArr = Long();
a = lArr[0];
b = lArr[1];
c = lArr[2];
}
/// <summary>
/// 1行に書かれた4つの整数の入力
/// </summary>
public static void @in(out long a, out long b, out long c, out long d) {
long[] lArr = Long();
a = lArr[0];
b = lArr[1];
c = lArr[2];
d = lArr[3];
}
/// <summary>
/// 1行に書かれた5つの整数の入力
/// </summary>
public static void
@in(out long a, out long b, out long c, out long d, out long e) {
long[] lArr = Long();
a = lArr[0];
b = lArr[1];
c = lArr[2];
d = lArr[3];
e = lArr[4];
}
/// <summary>
/// 1行に書かれた複数の整数列の入力
/// </summary>
public static void @in(out long[] lArr) => lArr = Long();
/// <summary>
/// rowNumber行に書かれた1つの整数列の入力
/// </summary>
public static void @in(long rowNumber, out long[] lArr) {
lArr = new long[rowNumber];
for (long i = 0; i < rowNumber; i++)
@in(out lArr[i]);
}
/// <summary>
/// rowNumber行に書かれた2つの整数列の入力
/// </summary>
public static void @in(long rowNumber, out long[] a, out long[] b) {
a = new long[rowNumber];
b = new long[rowNumber];
for (int i = 0; i < rowNumber; i++)
@in(out a[i], out b[i]);
}
/// <summary>
/// rowNumber行に書かれた3つの整数列の入力
/// </summary>
public static void
@in(long rowNumber, out long[] a, out long[] b, out long[] c) {
a = new long[rowNumber];
b = new long[rowNumber];
c = new long[rowNumber];
for (int i = 0; i < rowNumber; i++)
@in(out a[i], out b[i], out c[i]);
}
/// <summary>
/// rowNumber行に書かれた4つの整数列の入力
/// </summary>
public static void @in(long rowNumber, out long[] a, out long[] b,
out long[] c, out long[] d) {
a = new long[rowNumber];
b = new long[rowNumber];
c = new long[rowNumber];
d = new long[rowNumber];
for (int i = 0; i < rowNumber; i++)
@in(out a[i], out b[i], out c[i], out d[i]);
}
/// <summary>
/// h行w列の整数の行列の入力
/// </summary>
public static void @in(long h, long w, out long[][] a) {
a = new long [h][];
for (long i = 0; i < h; i++)
@in(out a[i]);
}
/// <summary>
/// 1行に書かれた1つの小数の入力
/// </summary>
public static void @in(out double d) => d = double.Parse(String());
/// <summary>
/// 1行に書かれた小数の配列の入力
/// </summary>
public static void
@in(out double[] dArr) => dArr = Split().Select(double.Parse).ToArray();
}
class Program {
public static void Main(string[] args) {
StreamWriter streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(streamWriter);
new Solver().Solve();
Console.Out.Flush();
}
public static void Debug() { new Solver().Solve(); }
}
class Solver {
private long N;
private long H;
private long[] A;
private long[] B;
public void Solve() {
@in(out N, out H);
@in(N, out A, out B);
long inf = A.Max();
Array.Sort(B);
Array.Reverse(B);
long ans = 0;
long sum = 0;
for (int i = 0; i < N; i++) {
if (B[i] <= inf) {
ans += (H - sum + inf - 1) / inf;
sum += (H - sum + inf - 1) / inf * inf;
break;
}
ans++;
sum += B[i];
}
if (sum < H) {
ans += (H - sum + inf - 1) / inf;
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static ABC085D.Input;
using static System.Math;
namespace ABC085D {
class Input {
private static String String() => Console.ReadLine();
private static IEnumerable<string> Split() => String().Split(' ');
private static long[] Long() => Split().Select(long.Parse).ToArray();
/// <summary>
/// 1行の文字列の入力
/// </summary>
public static void @in(out string s) => s = String();
/// <summary>
/// 複数行の文字列の入力
/// </summary>
public static void @in(long rowNumber, out string[] s) {
s = new String[rowNumber];
for (long i = 0; i < rowNumber; i++)
@in(out s[i]);
}
/// <summary>
/// 1行に書かれた1つの整数の入力
/// </summary>
public static void @in(out int i) { i = int.Parse(String()); }
/// <summary>
/// 1行に書かれた1つの整数の入力
/// </summary>
public static void @in(out long a) => a = Long()[0];
/// <summary>
/// 1行に書かれた2つの整数の入力
/// </summary>
public static void @in(out long a, out long b) {
long[] lArr = Long();
a = lArr[0];
b = lArr[1];
}
/// <summary>
/// 1行に書かれた3つの整数の入力
/// </summary>
public static void @in(out long a, out long b, out long c) {
long[] lArr = Long();
a = lArr[0];
b = lArr[1];
c = lArr[2];
}
/// <summary>
/// 1行に書かれた4つの整数の入力
/// </summary>
public static void @in(out long a, out long b, out long c, out long d) {
long[] lArr = Long();
a = lArr[0];
b = lArr[1];
c = lArr[2];
d = lArr[3];
}
/// <summary>
/// 1行に書かれた5つの整数の入力
/// </summary>
public static void
@in(out long a, out long b, out long c, out long d, out long e) {
long[] lArr = Long();
a = lArr[0];
b = lArr[1];
c = lArr[2];
d = lArr[3];
e = lArr[4];
}
/// <summary>
/// 1行に書かれた複数の整数列の入力
/// </summary>
public static void @in(out long[] lArr) => lArr = Long();
/// <summary>
/// rowNumber行に書かれた1つの整数列の入力
/// </summary>
public static void @in(long rowNumber, out long[] lArr) {
lArr = new long[rowNumber];
for (long i = 0; i < rowNumber; i++)
@in(out lArr[i]);
}
/// <summary>
/// rowNumber行に書かれた2つの整数列の入力
/// </summary>
public static void @in(long rowNumber, out long[] a, out long[] b) {
a = new long[rowNumber];
b = new long[rowNumber];
for (int i = 0; i < rowNumber; i++)
@in(out a[i], out b[i]);
}
/// <summary>
/// rowNumber行に書かれた3つの整数列の入力
/// </summary>
public static void
@in(long rowNumber, out long[] a, out long[] b, out long[] c) {
a = new long[rowNumber];
b = new long[rowNumber];
c = new long[rowNumber];
for (int i = 0; i < rowNumber; i++)
@in(out a[i], out b[i], out c[i]);
}
/// <summary>
/// rowNumber行に書かれた4つの整数列の入力
/// </summary>
public static void @in(long rowNumber, out long[] a, out long[] b,
out long[] c, out long[] d) {
a = new long[rowNumber];
b = new long[rowNumber];
c = new long[rowNumber];
d = new long[rowNumber];
for (int i = 0; i < rowNumber; i++)
@in(out a[i], out b[i], out c[i], out d[i]);
}
/// <summary>
/// h行w列の整数の行列の入力
/// </summary>
public static void @in(long h, long w, out long[][] a) {
a = new long [h][];
for (long i = 0; i < h; i++)
@in(out a[i]);
}
/// <summary>
/// 1行に書かれた1つの小数の入力
/// </summary>
public static void @in(out double d) => d = double.Parse(String());
/// <summary>
/// 1行に書かれた小数の配列の入力
/// </summary>
public static void
@in(out double[] dArr) => dArr = Split().Select(double.Parse).ToArray();
}
class Program {
public static void Main(string[] args) {
StreamWriter streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(streamWriter);
new Solver().Solve();
Console.Out.Flush();
}
public static void Debug() { new Solver().Solve(); }
}
class Solver {
private long N;
private long H;
private long[] A;
private long[] B;
public void Solve() {
@in(out N, out H);
@in(N, out A, out B);
long inf = A.Max();
Array.Sort(B);
Array.Reverse(B);
long ans = 0;
long sum = 0;
for (int i = 0; i < N; i++) {
if (sum >= H) {
break;
}
if (B[i] <= inf) {
ans += (H - sum + inf - 1) / inf;
sum = H;
break;
}
ans++;
sum += B[i];
}
if (sum < H) {
ans += (H - sum + inf - 1) / inf;
}
Console.WriteLine(ans);
}
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 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], ["+", 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], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 11, 12, 16, 31, 16, 31, 23, 0, 24], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 31, 23, 0, 16, 31, 16, 31, 16, 17, 33], ["-", 31, 23, 0, 16, 31, 16, 31, 16, 12, 22], ["-", 31, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["-", 31, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 11, 12, 16, 31, 16, 31, 23, 0, 25], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 85], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 1,155
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;
namespace kyoupuro {
class MainClass {
public static void Main() {
var N = NextInt();
var H = NextLong();
long maxA = 0;
var b = new List<int>();
for (int i = 0; i < N; i++) {
maxA = Math.Max(maxA, NextLong());
b.Add(NextInt());
}
b.Sort((x, y) => y - x);
var count = 0;
for (; count < N && b[count] > maxA && H > 0; count++) {
H -= b[count];
}
Console.WriteLine(count + Math.Ceiling((decimal)H / maxA));
}
}
class MyMath {
static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); }
}
class Input {
static IEnumerator<string> enumerator =
new string[] {}.AsEnumerable().GetEnumerator();
public static string Line() { return Console.ReadLine(); }
public static int NextInt() {
while (!enumerator.MoveNext()) {
enumerator = StrArr().AsEnumerable().GetEnumerator();
}
return int.Parse(enumerator.Current);
}
public static long NextLong() {
while (!enumerator.MoveNext()) {
enumerator = StrArr().AsEnumerable().GetEnumerator();
}
return long.Parse(enumerator.Current);
}
public static string[] StrArr() { return Line().Split(' '); }
public static List<int> IntList() {
return StrArr().Select(int.Parse).ToList();
}
public static List<long> LongList() {
return StrArr().Select(long.Parse).ToList();
}
public static void Skip(int line = 1) {
enumerator.Reset();
for (int i = 0; i < line; i++)
Console.ReadLine();
}
public static void Reset() { enumerator.Reset(); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;
namespace kyoupuro {
class MainClass {
public static void Main() {
var N = NextInt();
var H = NextLong();
long maxA = 0;
var b = new List<int>();
for (int i = 0; i < N; i++) {
maxA = Math.Max(maxA, NextLong());
b.Add(NextInt());
}
b.Sort((x, y) => y - x);
var count = 0;
for (; count < N && b[count] > maxA && H > 0; count++) {
H = Math.Max(H - b[count], 0);
}
Console.WriteLine(count + Math.Ceiling((decimal)H / maxA));
}
}
class MyMath {
static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); }
}
class Input {
static IEnumerator<string> enumerator =
new string[] {}.AsEnumerable().GetEnumerator();
public static string Line() { return Console.ReadLine(); }
public static int NextInt() {
while (!enumerator.MoveNext()) {
enumerator = StrArr().AsEnumerable().GetEnumerator();
}
return int.Parse(enumerator.Current);
}
public static long NextLong() {
while (!enumerator.MoveNext()) {
enumerator = StrArr().AsEnumerable().GetEnumerator();
}
return long.Parse(enumerator.Current);
}
public static string[] StrArr() { return Line().Split(' '); }
public static List<int> IntList() {
return StrArr().Select(int.Parse).ToList();
}
public static List<long> LongList() {
return StrArr().Select(long.Parse).ToList();
}
public static void Skip(int line = 1) {
enumerator.Reset();
for (int i = 0; i < line; i++)
Console.ReadLine();
}
public static void Reset() { enumerator.Reset(); }
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 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], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
| 8
| 474
| 11
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.