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.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace A {
class StartingPoint {
static void Main(string[] args) {
if (args?.Any() == true) {
var assembly = Assembly.GetEntryAssembly();
var resourceName = "AtCoderCSharp.In.txt";
var stream = assembly.GetManifestResourceStream(resourceName);
var streamReader = new StreamReader(stream, Encoding.UTF8);
var str = streamReader.ReadToEnd();
var textReader = new StringReader(str);
Console.SetIn(textReader);
}
try {
foreach (var s in new Program().Solve()) {
Console.WriteLine(s);
}
} catch (Exception e) {
Console.WriteLine(e);
if (args?.Any() != true)
throw e;
}
if (args?.Any() == true)
Console.ReadKey();
}
}
class Program {
public List<int> ScanInts(int count) =>
Enumerable.Range(0, count).Select(_ => ScanInt).ToList();
public List<int> ScanInts(long count) => ScanInts((int)count);
public List<long>
ScanLongs(int count) => Enumerable.Range(0, count).Select(_ => Scan).ToList();
public List<long> ScanLongs(long count) => ScanLongs((int)count);
public int ScanInt => int.Parse(Str);
public long Scan => long.Parse(Str);
public double ScanDouble => (double)Scan;
StringBuilder sb = new StringBuilder();
public string Str => ScanStr();
public string ScanStr() {
sb.Clear();
int r = 0;
bool? b = null;
do {
r = Console.Read();
b = IsBreak(r);
} while (b == true);
if (b == null)
throw new Exception("input error: unexpected end of stream");
do {
sb.Append((char)r);
r = Console.Read();
b = IsBreak(r);
} while (b == false);
return sb.ToString();
}
bool? IsBreak(int c) {
switch (c) {
case -1:
return null;
case (int)' ':
case (int)'\n':
case (int)'\r':
return true;
default:
return false;
}
}
public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count);
public IEnumerable<int> Loop(int from,
int to) => Enumerable.Range(from, to - from + 1);
public IEnumerable<long> Loop(long count) => Loop(0, count - 1);
public IEnumerable<long> Loop(long from, long to) {
for (long i = from; i <= to; i++)
yield return i;
}
public string YesNo(bool isYes) => isYes ? "Yes" : "No";
public HashSet<T> ToHashSet<T>(IEnumerable<T> ts) => new HashSet<T>(ts);
public IEnumerable<string> Solve() {
var h = Scan;
var w = Scan;
var res = (h * w + 1) / 2;
yield return res.ToString();
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace A {
class StartingPoint {
static void Main(string[] args) {
if (args?.Any() == true) {
var assembly = Assembly.GetEntryAssembly();
var resourceName = "AtCoderCSharp.In.txt";
var stream = assembly.GetManifestResourceStream(resourceName);
var streamReader = new StreamReader(stream, Encoding.UTF8);
var str = streamReader.ReadToEnd();
var textReader = new StringReader(str);
Console.SetIn(textReader);
}
try {
foreach (var s in new Program().Solve()) {
Console.WriteLine(s);
}
} catch (Exception e) {
Console.WriteLine(e);
if (args?.Any() != true)
throw e;
}
if (args?.Any() == true)
Console.ReadKey();
}
}
class Program {
public List<int> ScanInts(int count) =>
Enumerable.Range(0, count).Select(_ => ScanInt).ToList();
public List<int> ScanInts(long count) => ScanInts((int)count);
public List<long>
ScanLongs(int count) => Enumerable.Range(0, count).Select(_ => Scan).ToList();
public List<long> ScanLongs(long count) => ScanLongs((int)count);
public int ScanInt => int.Parse(Str);
public long Scan => long.Parse(Str);
public double ScanDouble => (double)Scan;
StringBuilder sb = new StringBuilder();
public string Str => ScanStr();
public string ScanStr() {
sb.Clear();
int r = 0;
bool? b = null;
do {
r = Console.Read();
b = IsBreak(r);
} while (b == true);
if (b == null)
throw new Exception("input error: unexpected end of stream");
do {
sb.Append((char)r);
r = Console.Read();
b = IsBreak(r);
} while (b == false);
return sb.ToString();
}
bool? IsBreak(int c) {
switch (c) {
case -1:
return null;
case (int)' ':
case (int)'\n':
case (int)'\r':
return true;
default:
return false;
}
}
public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count);
public IEnumerable<int> Loop(int from,
int to) => Enumerable.Range(from, to - from + 1);
public IEnumerable<long> Loop(long count) => Loop(0, count - 1);
public IEnumerable<long> Loop(long from, long to) {
for (long i = from; i <= to; i++)
yield return i;
}
public string YesNo(bool isYes) => isYes ? "Yes" : "No";
public HashSet<T> ToHashSet<T>(IEnumerable<T> ts) => new HashSet<T>(ts);
public IEnumerable<string> Solve() {
var h = Scan;
var w = Scan;
var res = (h * w + 1) / 2;
if (h == 1 || w == 1)
res = 1;
yield return res.ToString();
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 693
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public const long DpInf = 99999999999999;
public static void Main(string[] args) {
var p = Input();
var h = p[0].ToLong();
var w = p[1].ToLong();
var t = (h * w / 2);
if (t * 2 == h * w) {
Console.WriteLine(t);
} else {
Console.WriteLine(t + 1);
}
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(); }
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str, int offset = 0) {
var r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt() + offset;
return r;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public const long DpInf = 99999999999999;
public static void Main(string[] args) {
var p = Input();
var h = p[0].ToLong();
var w = p[1].ToLong();
var t = (h * w / 2);
if (h == 1 || w == 1) {
Console.WriteLine(1);
} else if (t * 2 == h * w) {
Console.WriteLine(t);
} else {
Console.WriteLine(t + 1);
}
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(); }
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str, int offset = 0) {
var r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt() + offset;
return r;
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24]]
| 8
| 318
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;
class Solver {
public void Solve(Scanner sc) {
int H, W;
sc.Make(out H, out W);
WriteLine(((long)H * W + 1) / 2);
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve(new Scanner());
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
public static T[] Shuffle<T>(this IList<T> A) {
T[] rt = A.ToArray();
Random rnd = new Random();
for (int i = rt.Length - 1; i >= 1; i--)
swap(ref rt[i], ref rt[rnd.Next(i + 1)]);
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
public string Str => Console.ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
public int[] ArrInt1D(int n) => Create(n, () => Int);
public long[] ArrLong1D(int n) => Create(n, () => Long);
public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
// public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1,
// v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2,
// out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3,
// T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2,
// v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2> p) {
var c = Comparer<T1>.Default.Compare(v1, p.v1);
if (c == 0)
c = Comparer<T2>.Default.Compare(v2, p.v2);
return c;
}
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public void Deconstruct(out T1 a, out T2 b) {
a = v1;
b = v2;
}
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() {}
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2, T3> p) {
var c = base.CompareTo(p);
if (c == 0)
c = Comparer<T3>.Default.Compare(v3, p.v3);
return c;
}
public override string ToString() => $"{base.ToString()} {v3.ToString()}";
public void Deconstruct(out T1 a, out T2 b, out T3 c) {
Deconstruct(out a, out b);
c = v3;
}
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;
class Solver {
public void Solve(Scanner sc) {
int H, W;
sc.Make(out H, out W);
if (H == 1 || W == 1)
Fail(1);
WriteLine(((long)H * W + 1) / 2);
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve(new Scanner());
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
public static T[] Shuffle<T>(this IList<T> A) {
T[] rt = A.ToArray();
Random rnd = new Random();
for (int i = rt.Length - 1; i >= 1; i--)
swap(ref rt[i], ref rt[rnd.Next(i + 1)]);
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
public string Str => Console.ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
public int[] ArrInt1D(int n) => Create(n, () => Int);
public long[] ArrLong1D(int n) => Create(n, () => Long);
public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
// public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1,
// v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2,
// out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3,
// T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2,
// v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2> p) {
var c = Comparer<T1>.Default.Compare(v1, p.v1);
if (c == 0)
c = Comparer<T2>.Default.Compare(v2, p.v2);
return c;
}
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public void Deconstruct(out T1 a, out T2 b) {
a = v1;
b = v2;
}
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() {}
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2, T3> p) {
var c = base.CompareTo(p);
if (c == 0)
c = Comparer<T3>.Default.Compare(v3, p.v3);
return c;
}
public override string ToString() => $"{base.ToString()} {v3.ToString()}";
public void Deconstruct(out T1 a, out T2 b, out T3 c) {
Deconstruct(out a, out b);
c = v3;
}
}
#endregion
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 213, 63, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 1,529
| 15
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using System.Numerics;
using System.Text.RegularExpressions;
using System.Runtime.Serialization.Formatters.Binary;
namespace atcorder2 {
[Serializable]
static 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 Gcd(long x, long y) {
if (x < y)
Gcd(y, x);
while (y > 0) {
var z = x;
x = y;
y = z % y;
}
return x;
}
public static long Lcm(long x, long y) { return x / Gcd(x, y) * y; }
public static bool IsLowercaseAlphabet(char target) {
return new Regex("^[a-z]+$").IsMatch(target.ToString());
}
public static T DeepCopy<T>(this T src) {
using (var memoryStream = new MemoryStream()) {
var binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(memoryStream, src);
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
return (T)binaryFormatter.Deserialize(memoryStream);
}
}
public static bool Prime(long n) {
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
for (int i = 3; i <= Math.Sqrt(n); i++) {
if (n % i == 0)
return false;
}
return true;
}
public static int UpperBound<T>(T[] a, T v) {
return UpperBound(a, v, Comparer<T>.Default);
}
public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp) {
var l = 0;
var r = a.Length - 1;
while (l <= r) {
var mid = l + (r - 1) / 2;
var res = cmp.Compare(a[mid], v);
if (res <= 0)
l = mid + 1;
else
r = mid - 1;
}
return l;
}
public static int LowerBound(long[] a, long v) {
var l = -1;
var r = a.Length;
while (r - l > 1) {
var mid = (l + r) / 2;
if (a[mid] >= v)
r = mid;
else
l = mid;
}
return r;
}
public static bool LowerBoundf(long[] a, long v) {
var l = -1;
var r = a.Length;
var f = false;
while (r - l > 1) {
var mid = (l + r) / 2;
if (a[mid] >= v) {
r = mid;
f = true;
} else
l = mid;
}
return f;
}
static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
SetOut(sw);
var q = Reads();
var a = q[0];
var b = q[1];
var c = q[2];
if (4 * a * b < (c - a - b) * (c - a - b))
WriteLine("Yes");
else
WriteLine("No");
Out.Flush();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using System.Numerics;
using System.Text.RegularExpressions;
using System.Runtime.Serialization.Formatters.Binary;
namespace atcorder2 {
[Serializable]
static 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 Gcd(long x, long y) {
if (x < y)
Gcd(y, x);
while (y > 0) {
var z = x;
x = y;
y = z % y;
}
return x;
}
public static long Lcm(long x, long y) { return x / Gcd(x, y) * y; }
public static bool IsLowercaseAlphabet(char target) {
return new Regex("^[a-z]+$").IsMatch(target.ToString());
}
public static T DeepCopy<T>(this T src) {
using (var memoryStream = new MemoryStream()) {
var binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(memoryStream, src);
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
return (T)binaryFormatter.Deserialize(memoryStream);
}
}
public static bool Prime(long n) {
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
for (int i = 3; i <= Math.Sqrt(n); i++) {
if (n % i == 0)
return false;
}
return true;
}
public static int UpperBound<T>(T[] a, T v) {
return UpperBound(a, v, Comparer<T>.Default);
}
public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp) {
var l = 0;
var r = a.Length - 1;
while (l <= r) {
var mid = l + (r - 1) / 2;
var res = cmp.Compare(a[mid], v);
if (res <= 0)
l = mid + 1;
else
r = mid - 1;
}
return l;
}
public static int LowerBound(long[] a, long v) {
var l = -1;
var r = a.Length;
while (r - l > 1) {
var mid = (l + r) / 2;
if (a[mid] >= v)
r = mid;
else
l = mid;
}
return r;
}
public static bool LowerBoundf(long[] a, long v) {
var l = -1;
var r = a.Length;
var f = false;
while (r - l > 1) {
var mid = (l + r) / 2;
if (a[mid] >= v) {
r = mid;
f = true;
} else
l = mid;
}
return f;
}
static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
SetOut(sw);
var q = Reads();
var a = q[0];
var b = q[1];
var c = q[2];
if (c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b))
WriteLine("Yes");
else
WriteLine("No");
Out.Flush();
}
}
}
|
[["+", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 33], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
| 8
| 751
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class MainClass {
static void Main() {
var r = ReadLine().Split().Select(decimal.Parse).ToArray();
var a = r[0];
var b = r[1];
var c = r[2];
if (4 * a * b <
(a * a + b * b + c * c - 2 * a * c - 2 * b * c + 2 * a * b)) {
WriteLine("Yes");
} else {
WriteLine("No");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class MainClass {
static void Main() {
var r = ReadLine().Split().Select(decimal.Parse).ToArray();
var a = r[0];
var b = r[1];
var c = r[2];
if (c - a - b < 0) {
WriteLine("No");
return;
}
if (4 * a * b <
(a * a + b * b + c * c - 2 * a * c - 2 * b * c + 2 * a * b)) {
WriteLine("Yes");
} else {
WriteLine("No");
}
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 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], ["+", 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, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24]]
| 8
| 143
| 21
|
using System;
class c {
static void Main() {
var abc = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
long a = abc[0], b = abc[1], c = abc[2];
Console.WriteLine(4 * a * b < c * c + a * a + b * b - 2 * a * c -
2 * b * c + 2 * a * b
? "Yes"
: "No");
}
}
|
using System;
class c {
static void Main() {
var abc = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
long a = abc[0], b = abc[1], c = abc[2];
Console.WriteLine(4 * a * b < c * c + a * a + b * b - 2 * a * c -
2 * b * c + 2 * a * b &&
c - a - b > 0
? "Yes"
: "No");
}
}
|
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 98], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 17, 33], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 41, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 0, 41, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 17, 47], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 12, 203]]
| 8
| 107
| 8
|
using System;
using System.Collections.Generic;
using System.IO.Pipes;
namespace cswork {
class Program {
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()); }
}
public Program() {}
static void Main(string[] args) { new Program().Omame(); }
Scanner cin;
const int MAXIN = 1024;
bool[] used = new bool[MAXIN];
int[] perm = new int[MAXIN];
List<int[]> permList = new List<int[]>();
public void Permutation(int pos, int n, int length) {
if (pos == n) {
permList.Add((int[])perm.Clone());
}
for (int i = 0; i < n; i++) {
if (!used[i]) {
perm[pos] = i;
used[i] = true;
Permutation(pos + 1, n, length);
used[i] = false;
}
}
}
void Omame() {
cin = new Scanner();
long a = cin.nextLong();
long b = cin.nextLong();
long c = cin.nextLong();
if (4 * a * b < (c - a - b) * (c - a - b)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
long Choose(long n) { return n * (n - 1) / 2; }
}
}
|
using System;
using System.Collections.Generic;
using System.IO.Pipes;
namespace cswork {
class Program {
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()); }
}
public Program() {}
static void Main(string[] args) { new Program().Omame(); }
Scanner cin;
const int MAXIN = 1024;
bool[] used = new bool[MAXIN];
int[] perm = new int[MAXIN];
List<int[]> permList = new List<int[]>();
public void Permutation(int pos, int n, int length) {
if (pos == n) {
permList.Add((int[])perm.Clone());
}
for (int i = 0; i < n; i++) {
if (!used[i]) {
perm[pos] = i;
used[i] = true;
Permutation(pos + 1, n, length);
used[i] = false;
}
}
}
void Omame() {
cin = new Scanner();
long a = cin.nextLong();
long b = cin.nextLong();
long c = cin.nextLong();
if (c - a - b < 0) {
Console.WriteLine("No");
} else {
if (4 * a * b < (c - a - b) * (c - a - b)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
long Choose(long n) { return n * (n - 1) / 2; }
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 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, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 467
| 24
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var A = sc.ReadLong();
var B = sc.ReadLong();
var C = sc.ReadLong();
// A + 2√AB + B < C
// 2√AB < C-A-B
// 4AB < (C-A-B)^2
if (4 * A * B < (C - A - B) * (C - A - B)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var A = sc.ReadLong();
var B = sc.ReadLong();
var C = sc.ReadLong();
// A + 2√AB + B < C
// 2√AB < C-A-B
// 4AB < (C-A-B)^2
if (4 * A * B < (C - A - B) * (C - A - B) && (C - A - B) > 0) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 1,132
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
checked {
var A = sc.ReadLong();
var B = sc.ReadLong();
var C = sc.ReadLong();
var x = C - A - B;
if (4 * A * B < x * x) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
checked {
var A = sc.ReadLong();
var B = sc.ReadLong();
var C = sc.ReadLong();
var x = C - A - B;
if (x <= 0) {
Console.WriteLine("No");
return;
}
if (4 * A * B < x * x) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["+", 0, 287, 0, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 287, 0, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 287, 0, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 287, 0, 196, 0, 57, 0, 25], ["+", 0, 287, 0, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 287, 0, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 287, 0, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 287, 0, 196, 0, 57, 0, 24]]
| 8
| 1,075
| 19
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
static void Main(string[] args) {
var r = Console.ReadLine().Split(' ');
var a = r[0].ToDouble();
var b = r[1].ToDouble();
var c = r[2].ToDouble();
var d = 4 * a * b;
var e = Math.Pow(c - a - b, 2);
var ans = "No";
if (d < e) {
ans = "Yes";
}
Console.WriteLine(ans);
Console.ReadLine();
}
}
}
public static class Extentions {
public static int ToInt(this object obj) { return int.Parse(obj.ToString()); }
public static decimal ToDecimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double ToDouble(this object obj) {
return double.Parse(obj.ToString());
}
}
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
static void Main(string[] args) {
var r = Console.ReadLine().Split(' ');
var a = r[0].ToDecimal();
var b = r[1].ToDecimal();
var c = r[2].ToDecimal();
var d = 4 * a * b;
var e = c - a - b;
var f = e * e;
var ans = "No";
if (e > 0 && d < f) {
ans = "Yes";
}
Console.WriteLine(ans);
Console.ReadLine();
}
}
}
public static class Extentions {
public static int ToInt(this object obj) { return int.Parse(obj.ToString()); }
public static decimal ToDecimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double ToDouble(this object obj) {
return double.Parse(obj.ToString());
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 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, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 238
| 26
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
class Solve {
public Solve() {}
public static int Main() {
new Solve().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
ulong a = cin.nextULong();
ulong b = cin.nextULong();
ulong c = cin.nextULong();
ulong l = a + b - c;
if (l <= 0) {
Console.WriteLine("No");
return;
}
ulong r = 4 * a * b;
Console.WriteLine(l * l > r ? "Yes" : "No");
}
}
class Modulo {
private const int M = 1000000007;
private readonly int[] m_facs;
public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); }
public Modulo(int n) {
m_facs = new int[n + 1];
m_facs[0] = 1;
for (int i = 1; i <= n; ++i) {
m_facs[i] = Mul(m_facs[i - 1], i);
}
}
public int Fac(int n) { return m_facs[n]; }
public int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Mul(p1, p1);
return ((m % 2) == 0) ? p2 : Mul(p2, a);
}
}
public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); }
public int Ncr(int n, int r) {
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int res = Fac(n);
res = Div(res, Fac(r));
res = Div(res, Fac(n - r));
return res;
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public ulong nextULong() { return ulong.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
class Solve {
public Solve() {}
public static int Main() {
new Solve().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
long a = cin.nextLong();
long b = cin.nextLong();
long c = cin.nextLong();
long l = c - a - b;
if (l < 0) {
Console.WriteLine("No");
return;
}
long r = 4 * a * b;
Console.WriteLine(l * l > r ? "Yes" : "No");
}
}
class Modulo {
private const int M = 1000000007;
private readonly int[] m_facs;
public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); }
public Modulo(int n) {
m_facs = new int[n + 1];
m_facs[0] = 1;
for (int i = 1; i <= n; ++i) {
m_facs[i] = Mul(m_facs[i - 1], i);
}
}
public int Fac(int n) { return m_facs[n]; }
public int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Mul(p1, p1);
return ((m % 2) == 0) ? p2 : Mul(p2, a);
}
}
public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); }
public int Ncr(int n, int r) {
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int res = Fac(n);
res = Div(res, Fac(r));
res = Div(res, Fac(n - r));
return res;
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public ulong nextULong() { return ulong.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["-", 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, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 828
| 24
|
using AtCoderBeginnerContest157.Questions;
using AtCoderBeginnerContest157.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoderBeginnerContest157.Questions {
public class QuestionB : AtCoderQuestionBase {
public override IEnumerable<object> Solve(TextReader inputStream) {
var card = new int [3][];
var opened = new bool[3, 3];
for (int i = 0; i < 3; i++) {
card[i] = inputStream.ReadIntArray();
}
var n = inputStream.ReadInt();
for (int i = 0; i < n; i++) {
var b = inputStream.ReadInt();
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (card[j][k] == b) {
opened[j, k] = true;
}
}
}
}
yield return IsBingo(opened) ? "Yes" : "No";
}
bool IsBingo(bool[,] card) {
for (int i = 0; i < 3; i++) {
if (Enumerable.Range(0, 3).All(j => card[i, j])) {
return true;
}
if (Enumerable.Range(0, 3).All(j => card[j, i])) {
return true;
}
}
if (Enumerable.Range(0, 3).All(i => card[i, i])) {
return true;
}
return false;
}
}
}
namespace AtCoderBeginnerContest157 {
class Program {
static void Main(string[] args) {
IAtCoderQuestion question = new QuestionB(); // 問題に合わせて書き換え
var answers = question.Solve(Console.In);
foreach (var answer in answers) {
Console.WriteLine(answer);
}
}
}
}
#region Base Classes
namespace AtCoderBeginnerContest157.Questions {
public interface IAtCoderQuestion {
IEnumerable<object> Solve(string input);
IEnumerable<object> Solve(TextReader inputStream);
}
public abstract class AtCoderQuestionBase : IAtCoderQuestion {
public IEnumerable<object> Solve(string input) {
var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
var reader = new StreamReader(stream, Encoding.Unicode);
return Solve(reader);
}
public abstract IEnumerable<object> Solve(TextReader inputStream);
}
}
#endregion
#region Extensions
namespace AtCoderBeginnerContest157.Extensions {
internal static class TextReaderExtensions {
internal static int
ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
internal static long
ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
internal static double
ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
internal static string
ReadString(this TextReader reader) => reader.ReadLine();
internal static int[] ReadIntArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(int.Parse).ToArray();
internal static long[] ReadLongArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(long.Parse).ToArray();
internal static double[] ReadDoubleArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(double.Parse).ToArray();
internal static string[] ReadStringArray(this TextReader reader,
char separator = ' ') =>
reader.ReadLine().Split(separator);
}
}
#endregion
|
using AtCoderBeginnerContest157.Questions;
using AtCoderBeginnerContest157.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoderBeginnerContest157.Questions {
public class QuestionB : AtCoderQuestionBase {
public override IEnumerable<object> Solve(TextReader inputStream) {
var card = new int [3][];
var opened = new bool[3, 3];
for (int i = 0; i < 3; i++) {
card[i] = inputStream.ReadIntArray();
}
var n = inputStream.ReadInt();
for (int i = 0; i < n; i++) {
var b = inputStream.ReadInt();
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (card[j][k] == b) {
opened[j, k] = true;
}
}
}
}
yield return IsBingo(opened) ? "Yes" : "No";
}
bool IsBingo(bool[,] card) {
for (int i = 0; i < 3; i++) {
if (Enumerable.Range(0, 3).All(j => card[i, j])) {
return true;
}
if (Enumerable.Range(0, 3).All(j => card[j, i])) {
return true;
}
}
if (Enumerable.Range(0, 3).All(i => card[i, i] || card[2 - i, i])) {
return true;
}
return false;
}
}
}
namespace AtCoderBeginnerContest157 {
class Program {
static void Main(string[] args) {
IAtCoderQuestion question = new QuestionB(); // 問題に合わせて書き換え
var answers = question.Solve(Console.In);
foreach (var answer in answers) {
Console.WriteLine(answer);
}
}
}
}
#region Base Classes
namespace AtCoderBeginnerContest157.Questions {
public interface IAtCoderQuestion {
IEnumerable<object> Solve(string input);
IEnumerable<object> Solve(TextReader inputStream);
}
public abstract class AtCoderQuestionBase : IAtCoderQuestion {
public IEnumerable<object> Solve(string input) {
var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
var reader = new StreamReader(stream, Encoding.Unicode);
return Solve(reader);
}
public abstract IEnumerable<object> Solve(TextReader inputStream);
}
}
#endregion
#region Extensions
namespace AtCoderBeginnerContest157.Extensions {
internal static class TextReaderExtensions {
internal static int
ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
internal static long
ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
internal static double
ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
internal static string
ReadString(this TextReader reader) => reader.ReadLine();
internal static int[] ReadIntArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(int.Parse).ToArray();
internal static long[] ReadLongArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(long.Parse).ToArray();
internal static double[] ReadDoubleArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(double.Parse).ToArray();
internal static string[] ReadStringArray(this TextReader reader,
char separator = ' ') =>
reader.ReadLine().Split(separator);
}
}
#endregion
|
[["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 106], ["+", 0, 28, 0, 218, 8, 16, 12, 204, 205, 22], ["+", 0, 218, 8, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["+", 0, 218, 8, 16, 12, 204, 206, 207, 0, 21], ["+", 8, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 218, 8, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 721
| 9
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
long[] inp = null;
long[] brd = new long[9];
bool[] bng = new bool[9];
for (int i = 0; i < 3; i++) {
inp = Console.ReadLine().Split(' ').Select(k => long.Parse(k)).ToArray();
brd[i * 3 + 0] = inp[0];
brd[i * 3 + 1] = inp[1];
brd[i * 3 + 2] = inp[2];
bng[i * 3 + 0] = false;
bng[i * 3 + 1] = false;
bng[i * 3 + 2] = false;
}
long n = long.Parse(Console.ReadLine());
for (int i = 0; i < n; i++) {
long m = long.Parse(Console.ReadLine());
for (int k = 0; k < 9; k++) {
if (brd[k] == m)
bng[k] = true;
}
}
bool yes = false;
for (int i = 0; i < 3; i++) {
if (i % 3 == 0 && bng[i] && bng[i + 1] && bng[i + 2]) {
yes = true;
}
if (bng[i] && bng[i + 3] && bng[i + 6]) {
yes = true;
}
}
if (bng[0] && bng[4] && bng[8])
yes = true;
if (bng[2] && bng[4] && bng[6])
yes = true;
Console.WriteLine(yes ? "Yes" : "No");
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
long[] inp = null;
long[] brd = new long[9];
bool[] bng = new bool[9];
for (int i = 0; i < 3; i++) {
inp = Console.ReadLine().Split(' ').Select(k => long.Parse(k)).ToArray();
brd[i * 3 + 0] = inp[0];
brd[i * 3 + 1] = inp[1];
brd[i * 3 + 2] = inp[2];
bng[i * 3 + 0] = false;
bng[i * 3 + 1] = false;
bng[i * 3 + 2] = false;
}
long n = long.Parse(Console.ReadLine());
for (int i = 0; i < n; i++) {
long m = long.Parse(Console.ReadLine());
for (int k = 0; k < 9; k++) {
if (brd[k] == m)
bng[k] = true;
}
}
bool yes = false;
for (int i = 0; i < 3; i++) {
if (bng[i * 3] && bng[i * 3 + 1] && bng[i * 3 + 2]) {
yes = true;
}
if (bng[i] && bng[i + 3] && bng[i + 6]) {
yes = true;
}
}
if (bng[0] && bng[4] && bng[8])
yes = true;
if (bng[2] && bng[4] && bng[6])
yes = true;
Console.WriteLine(yes ? "Yes" : "No");
}
}
|
[["-", 31, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["-", 31, 16, 31, 16, 31, 16, 31, 16, 17, 109], ["-", 31, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 60], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 48], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 12, 203]]
| 8
| 388
| 12
|
namespace AtCoderCS {
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;
class Program {
void Solve() {
var A = new int[3, 3];
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 3; j++) {
A[i, j] = cin.Int;
}
}
var N = cin.Int;
var b = new int[N];
for (var i = 0; i < N; i++) {
b[i] = cin.Int;
}
var set = new HashSet<int>(b);
var flag = false;
var tmp = false;
// h
for (var i = 0; i < 3; i++) {
tmp = true;
for (var j = 0; j < 3; j++) {
tmp &= set.Contains(A[i, j]);
}
flag |= tmp;
}
// v
tmp = true;
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 3; j++) {
tmp &= set.Contains(A[j, i]);
}
flag |= tmp;
}
flag |= tmp;
// \
tmp = true;
for (var i = 0; i < 3; i++) {
tmp &= set.Contains(A[i, i]);
}
flag |= tmp;
// /
tmp = true;
for (var i = 0; i < 3; i++) {
tmp &= set.Contains(A[i, 2 - i]);
}
flag |= tmp;
WriteLine(flag ? "Yes" : "No");
}
private SimpleInput cin = new SimpleInput();
private SimpleOutput cout = new SimpleOutput();
void Stream() {
Solve();
cout.Flush();
}
static void Main(string[] args) => new Program().Stream();
}
#region IO
class SimpleInput {
private string[] _nextBuffer;
private int _bufferCnt;
private readonly char[] _cs = new char[] { ' ', '"', ',' };
public SimpleInput() {
_nextBuffer = new string[0];
_bufferCnt = 0;
}
string Next() {
if (_bufferCnt < _nextBuffer.Length)
return _nextBuffer[_bufferCnt++];
var st = ReadLine();
while (st == string.Empty)
st = ReadLine();
if (st != null)
_nextBuffer = st.Split(_cs, StringSplitOptions.RemoveEmptyEntries);
_bufferCnt = 0;
return _nextBuffer[_bufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
}
class SimpleOutput {
private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
AutoFlush = true
#else
AutoFlush = false
#endif
};
public SimpleOutput() { SetOut(_sw); }
public void Flush() => Out.Flush();
}
#endregion
}
|
namespace AtCoderCS {
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;
class Program {
void Solve() {
var A = new int[3, 3];
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 3; j++) {
A[i, j] = cin.Int;
}
}
var N = cin.Int;
var b = new int[N];
for (var i = 0; i < N; i++) {
b[i] = cin.Int;
}
var set = new HashSet<int>(b);
var flag = false;
var tmp = false;
// h
for (var i = 0; i < 3; i++) {
tmp = true;
for (var j = 0; j < 3; j++) {
tmp &= set.Contains(A[i, j]);
}
flag |= tmp;
}
// v
for (var i = 0; i < 3; i++) {
tmp = true;
for (var j = 0; j < 3; j++) {
tmp &= set.Contains(A[j, i]);
}
flag |= tmp;
}
// \
tmp = true;
for (var i = 0; i < 3; i++) {
tmp &= set.Contains(A[i, i]);
}
flag |= tmp;
// /
tmp = true;
for (var i = 0; i < 3; i++) {
tmp &= set.Contains(A[i, 2 - i]);
}
flag |= tmp;
WriteLine(flag ? "Yes" : "No");
}
private SimpleInput cin = new SimpleInput();
private SimpleOutput cout = new SimpleOutput();
void Stream() {
Solve();
cout.Flush();
}
static void Main(string[] args) => new Program().Stream();
}
#region IO
class SimpleInput {
private string[] _nextBuffer;
private int _bufferCnt;
private readonly char[] _cs = new char[] { ' ', '"', ',' };
public SimpleInput() {
_nextBuffer = new string[0];
_bufferCnt = 0;
}
string Next() {
if (_bufferCnt < _nextBuffer.Length)
return _nextBuffer[_bufferCnt++];
var st = ReadLine();
while (st == string.Empty)
st = ReadLine();
if (st != null)
_nextBuffer = st.Split(_cs, StringSplitOptions.RemoveEmptyEntries);
_bufferCnt = 0;
return _nextBuffer[_bufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
}
class SimpleOutput {
private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
AutoFlush = true
#else
AutoFlush = false
#endif
};
public SimpleOutput() { SetOut(_sw); }
public void Flush() => Out.Flush();
}
#endregion
}
|
[["-", 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, 211, 0, 146], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 160], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22]]
| 8
| 664
| 12
|
using System;
namespace B___Bingo {
class Program {
static void Main(string[] args) {
var a = new string[3, 3];
for (var i = 0; i < 3; i++) {
var input = Console.ReadLine().Split();
for (var j = 0; j < 3; j++) {
a[i, j] = input[j];
}
}
var n = int.Parse(Console.ReadLine());
var b = new string[n];
for (var i = 0; i < n; i++) {
b[i] = Console.ReadLine();
for (var j = 0; j < 3; j++) {
for (var k = 0; k < 3; k++) {
if (b[i] == a[j, k]) {
a[j, k] = "0";
}
}
}
}
for (var i = 0; i < 3; i++) {
if (a[i, 0] == "0" && a[i, 1] == "0" && a[i, 2] == "0") {
Console.WriteLine("Yes");
return;
}
}
if (a[0, 0] == "0" && a[1, 1] == "0" && a[2, 2] == "0" ||
a[2, 0] == "0" && a[1, 1] == "0" && a[0, 2] == "0")
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
}
|
using System;
namespace B___Bingo {
class Program {
static void Main(string[] args) {
var a = new string[3, 3];
for (var i = 0; i < 3; i++) {
var input = Console.ReadLine().Split();
for (var j = 0; j < 3; j++) {
a[i, j] = input[j];
}
}
var n = int.Parse(Console.ReadLine());
var b = new string[n];
for (var i = 0; i < n; i++) {
b[i] = Console.ReadLine();
for (var j = 0; j < 3; j++) {
for (var k = 0; k < 3; k++) {
if (b[i] == a[j, k]) {
a[j, k] = "0";
}
}
}
}
for (var i = 0; i < 3; i++) {
if (a[i, 0] == "0" && a[i, 1] == "0" && a[i, 2] == "0" ||
a[0, i] == "0" && a[1, i] == "0" && a[2, i] == "0") {
Console.WriteLine("Yes");
return;
}
}
if (a[0, 0] == "0" && a[1, 1] == "0" && a[2, 2] == "0" ||
a[2, 0] == "0" && a[1, 1] == "0" && a[0, 2] == "0")
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 12, 16, 31, 16, 31, 16, 31, 204, 205, 22], ["+", 31, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 16, 31, 204, 206, 207, 0, 21], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 17, 60], ["+", 12, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["+", 12, 16, 31, 16, 31, 16, 12, 5, 0, 222], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 98], ["+", 12, 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, 21], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 16, 31, 16, 12, 16, 17, 60], ["+", 12, 16, 31, 16, 12, 16, 12, 5, 0, 62], ["+", 12, 16, 31, 16, 12, 16, 12, 5, 0, 222], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 98], ["+", 15, 16, 12, 16, 12, 16, 31, 204, 205, 22], ["+", 12, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 16, 31, 204, 206, 207, 0, 21], ["+", 12, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 60], ["+", 15, 16, 12, 16, 12, 16, 12, 5, 0, 62], ["+", 15, 16, 12, 16, 12, 16, 12, 5, 0, 222]]
| 8
| 350
| 33
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
namespace at_coder {
#if TEST
[TestClass]
#endif
public class Test_157_b {
#if TEST
public static void Test_Main()
#else
public static void Main()
#endif
{
var boad = new int[3, 3];
for (int i = 0; i < 3; i++) {
var ar = ReadIntArray();
boad[i, 0] = ar[0];
boad[i, 1] = ar[1];
boad[i, 2] = ar[2];
}
int N = ReadInt();
for (int i = 0; i < N; i++) {
int b = ReadInt();
SetNum(boad, b);
}
if (CheckBingo(boad)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
private static bool CheckBingo(int[,] boad) {
// 縦
for (int i = 0; i < 3; i++) {
int ngCount = 0;
for (int j = 0; j < 3; j++) {
if (boad[i, j] != 0) {
ngCount++;
}
}
if (ngCount == 0) {
return true;
}
}
// 横
for (int i = 0; i < 3; i++) {
int ngCount = 0;
for (int j = 0; j < 3; j++) {
if (boad[j, i] != 0) {
ngCount++;
}
}
if (ngCount == 0) {
return true;
}
}
// 斜め
{
int ngCount = 0;
for (int i = 0; i < 3; i++) {
if (boad[i, i] != 0) {
ngCount++;
}
}
for (int i = 0; i < 3; i++) {
if (boad[2 - i, i] != 0) {
ngCount++;
}
}
if (ngCount == 0) {
return true;
}
}
return false;
}
private static void SetNum(int[,] boad, int b) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (boad[i, j] == b) {
boad[i, j] = 0;
}
}
}
}
private static int[] ReadIntArray() {
string[] ss = Console.ReadLine().Split(
new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
int[] ar = new int[ss.Length];
for (int i = 0; i < ss.Length; i++) {
ar[i] = int.Parse(ss[i]);
}
return ar;
}
private static int ReadInt() { return int.Parse(Console.ReadLine()); }
#if TEST
#else
}
}
#endif
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
namespace at_coder {
#if TEST
[TestClass]
#endif
public class Test_157_b {
#if TEST
public static void Test_Main()
#else
public static void Main()
#endif
{
var boad = new int[3, 3];
for (int i = 0; i < 3; i++) {
var ar = ReadIntArray();
boad[i, 0] = ar[0];
boad[i, 1] = ar[1];
boad[i, 2] = ar[2];
}
int N = ReadInt();
for (int i = 0; i < N; i++) {
int b = ReadInt();
SetNum(boad, b);
}
if (CheckBingo(boad)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
private static bool CheckBingo(int[,] boad) {
// 縦
for (int i = 0; i < 3; i++) {
int ngCount = 0;
for (int j = 0; j < 3; j++) {
if (boad[i, j] != 0) {
ngCount++;
}
}
if (ngCount == 0) {
return true;
}
}
// 横
for (int i = 0; i < 3; i++) {
int ngCount = 0;
for (int j = 0; j < 3; j++) {
if (boad[j, i] != 0) {
ngCount++;
}
}
if (ngCount == 0) {
return true;
}
}
// 斜め
{
int ngCount = 0;
for (int i = 0; i < 3; i++) {
if (boad[i, i] != 0) {
ngCount++;
}
}
if (ngCount == 0) {
return true;
}
}
{
int ngCount = 0;
for (int i = 0; i < 3; i++) {
if (boad[2 - i, i] != 0) {
ngCount++;
}
}
if (ngCount == 0) {
return true;
}
}
return false;
}
private static void SetNum(int[,] boad, int b) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (boad[i, j] == b) {
boad[i, j] = 0;
}
}
}
}
private static int[] ReadIntArray() {
string[] ss = Console.ReadLine().Split(
new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
int[] ar = new int[ss.Length];
for (int i = 0; i < ss.Length; i++) {
ar[i] = int.Parse(ss[i]);
}
return ar;
}
private static int ReadInt() { return int.Parse(Console.ReadLine()); }
#if TEST
#else
}
}
#endif
|
[["+", 0, 195, 8, 196, 0, 196, 0, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 196, 0, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 37, 0, 211, 0, 146], ["+", 0, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 8, 196, 0, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 196, 0, 45], ["+", 8, 196, 0, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 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], ["+", 0, 195, 8, 196, 0, 196, 0, 197, 0, 35]]
| 8
| 623
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
List<string> row1 = Console.ReadLine().Split(' ').ToList();
List<string> row2 = Console.ReadLine().Split(' ').ToList();
List<string> row3 = Console.ReadLine().Split(' ').ToList();
List<List<string>> orgData = new List<List<string>>();
orgData.Add(row1);
orgData.Add(row2);
orgData.Add(row3);
int cnt = int.Parse(Console.ReadLine());
List<int> dataList = new List<int>();
for (int loop = 0; loop < cnt; loop++) {
dataList.Add(int.Parse(Console.ReadLine()));
}
List<List<bool>> bingo = new List<List<bool>>();
for (int loop = 0; loop < 3; loop++) {
bingo.Add(new List<bool>() { false, false, false });
}
for (int loop = 0; loop < 3; loop++) {
for (int loop2 = 0; loop2 < 3; loop2++) {
bingo[loop][loop2] = dataList.Contains(int.Parse(orgData[loop][loop2]));
}
}
bool ans = false;
//縦
for (int loop = 0; loop < 3; loop++) {
int trueCount = 0;
for (int loop2 = 0; loop2 < 3; loop2++) {
if (bingo[loop][loop2]) {
trueCount++;
}
}
if (trueCount == 3) {
ans = true;
break;
}
}
if (ans) {
Console.WriteLine("yes");
return;
}
//横
for (int loop = 0; loop < 3; loop++) {
int trueCount = 0;
for (int loop2 = 0; loop2 < 3; loop2++) {
if (bingo[loop2][loop]) {
trueCount++;
}
}
if (trueCount == 3) {
ans = true;
break;
}
}
if (ans) {
Console.WriteLine("yes");
return;
}
//斜め
ans = bingo[0][0] && bingo[1][1] && bingo[2][2];
if (ans) {
Console.WriteLine("yes");
return;
}
ans = bingo[2][0] && bingo[1][1] && bingo[0][2];
if (ans) {
Console.WriteLine("yes");
Console.ReadLine();
return;
}
Console.WriteLine("no");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
List<string> row1 = Console.ReadLine().Split(' ').ToList();
List<string> row2 = Console.ReadLine().Split(' ').ToList();
List<string> row3 = Console.ReadLine().Split(' ').ToList();
List<List<string>> orgData = new List<List<string>>();
orgData.Add(row1);
orgData.Add(row2);
orgData.Add(row3);
int cnt = int.Parse(Console.ReadLine());
List<int> dataList = new List<int>();
for (int loop = 0; loop < cnt; loop++) {
dataList.Add(int.Parse(Console.ReadLine()));
}
List<List<bool>> bingo = new List<List<bool>>();
for (int loop = 0; loop < 3; loop++) {
bingo.Add(new List<bool>() { false, false, false });
}
for (int loop = 0; loop < 3; loop++) {
for (int loop2 = 0; loop2 < 3; loop2++) {
bingo[loop][loop2] = dataList.Contains(int.Parse(orgData[loop][loop2]));
}
}
bool ans = false;
//縦
for (int loop = 0; loop < 3; loop++) {
int trueCount = 0;
for (int loop2 = 0; loop2 < 3; loop2++) {
if (bingo[loop][loop2]) {
trueCount++;
}
}
if (trueCount == 3) {
ans = true;
break;
}
}
if (ans) {
Console.WriteLine("Yes");
Console.ReadLine();
return;
}
//横
for (int loop = 0; loop < 3; loop++) {
int trueCount = 0;
for (int loop2 = 0; loop2 < 3; loop2++) {
if (bingo[loop2][loop]) {
trueCount++;
}
}
if (trueCount == 3) {
ans = true;
break;
}
}
if (ans) {
Console.WriteLine("Yes");
Console.ReadLine();
return;
}
//斜め
ans = bingo[0][0] && bingo[1][1] && bingo[2][2];
if (ans) {
Console.WriteLine("Yes");
Console.ReadLine();
return;
}
ans = bingo[2][0] && bingo[1][1] && bingo[0][2];
if (ans) {
Console.WriteLine("Yes");
Console.ReadLine();
return;
}
Console.WriteLine("No");
Console.ReadLine();
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 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, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
| 8
| 605
| 34
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var seat = new int[3, 3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
seat[i, j] = cin.nextInt();
}
}
var n = cin.nextInt();
var list = cin.ArrayInt(n);
var ss = new bool[3, 3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (list.Contains(seat[i, j])) {
ss[i, j] = true;
}
}
}
Console.WriteLine(bingo(ss) ? "Yes" : "No");
}
bool bingo(bool[,] ss) {
for (int i = 0; i < 3; i++) {
var f = true;
for (int j = 0; j < 3; j++) {
if (ss[i, j] == false)
f = false;
if (f)
return true;
}
}
for (int i = 0; i < 3; i++) {
var f = true;
for (int j = 0; j < 3; j++) {
if (ss[j, i] == false)
f = false;
if (f)
return true;
}
}
if (ss[0, 0] == true && ss[1, 1] == true && ss[2, 2])
return true;
if (ss[2, 0] == true && ss[1, 1] == true && ss[0, 2])
return true;
return false;
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var seat = new int[3, 3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
seat[i, j] = cin.nextInt();
}
}
var n = cin.nextInt();
var list = cin.ArrayInt(n);
var ss = new bool[3, 3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (list.Contains(seat[i, j])) {
ss[i, j] = true;
}
}
}
Console.WriteLine(bingo(ss) ? "Yes" : "No");
}
bool bingo(bool[,] ss) {
for (int i = 0; i < 3; i++) {
var f = true;
for (int j = 0; j < 3; j++) {
if (ss[i, j] == false)
f = false;
}
if (f)
return true;
}
for (int i = 0; i < 3; i++) {
var f = true;
for (int j = 0; j < 3; j++) {
if (ss[j, i] == false)
f = false;
}
if (f)
return true;
}
if (ss[0, 0] == true && ss[1, 1] == true && ss[2, 2])
return true;
if (ss[0, 2] == true && ss[1, 1] == true && ss[2, 0])
return true;
return false;
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
[["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 16, 31, 16, 31, 204, 206, 207, 0, 21], ["+", 31, 16, 31, 16, 31, 204, 206, 207, 0, 21], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 21], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 21], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 892
| 12
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
partial class Program {
static long mod = 1000000007;
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
Solve();
Console.Out.Flush();
Console.ReadKey();
}
///ここから
static int N;
static int M;
static void Solve() {
var ans = Ans();
Console.WriteLine(ans);
}
static int Ans() {
Multi(out N, out M);
var pair = Enumerable.Repeat(0, M)
.Select(s => GetIntArray())
.Select(s => new { s = s[0], c = s[1] })
.ToArray();
if (pair.Select(p => p.s).Distinct().Count() != pair.Distinct().Count())
return -1; // sが一緒でcが異なるものを除外
if (pair.Any(p => p.s == 1 && p.c == 0))
return -1; //先頭が0なら無理
var ans = Enumerable.Repeat('0', N).ToArray();
ans[0] = '1';
pair.ToList().ForEach(p => ans[p.s - 1] = p.c.ToString()[0]);
return int.Parse(new string(ans));
}
}
//拡張メソッド
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static string yesno(this bool b) { return b ? "yes" : "no"; }
public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
}
partial class Program {
static public string GetStr() { return Console.ReadLine().Trim(); }
static public char GetChar() { return Console.ReadLine().Trim()[0]; }
static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
static public double GetDouble() {
return double.Parse(Console.ReadLine().Trim());
}
static public string[] GetStrArray() {
return Console.ReadLine().Trim().Split(' ');
}
static public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
static public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
static public void WriteObjects<T>(IList<T> values) {
var num = values.Count;
for (int i = 0; i < num; i++) {
Console.Write(values[i]);
if (i < num - 1) {
Console.Write(" ");
}
}
Console.WriteLine();
}
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
partial class Program {
static long mod = 1000000007;
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
Solve();
Console.Out.Flush();
Console.ReadKey();
}
///ここから
static int N;
static int M;
static void Solve() {
var ans = Ans();
Console.WriteLine(ans);
}
static int Ans() {
Multi(out N, out M);
if (N == 1 && M == 0) {
return 0;
}
var pair = Enumerable.Repeat(0, M)
.Select(s => GetIntArray())
.Select(s => new { s = s[0], c = s[1] })
.ToArray();
if (pair.Select(p => p.s).Distinct().Count() != pair.Distinct().Count())
return -1; // sが一緒でcが異なるものを除外
if (pair.Any(p => p.s == 1 && p.c == 0)) {
if (N == 1)
return 0;
else
return -1;
}
var ans = Enumerable.Repeat('0', N).ToArray();
ans[0] = '1';
pair.ToList().ForEach(p => ans[p.s - 1] = p.c.ToString()[0]);
return int.Parse(new string(ans));
}
}
//拡張メソッド
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static string yesno(this bool b) { return b ? "yes" : "no"; }
public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
}
partial class Program {
static public string GetStr() { return Console.ReadLine().Trim(); }
static public char GetChar() { return Console.ReadLine().Trim()[0]; }
static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
static public double GetDouble() {
return double.Parse(Console.ReadLine().Trim());
}
static public string[] GetStrArray() {
return Console.ReadLine().Trim().Split(' ');
}
static public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
static public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
static public void WriteObjects<T>(IList<T> values) {
var num = values.Count;
for (int i = 0; i < num; i++) {
Console.Write(values[i]);
if (i < num - 1) {
Console.Write(" ");
}
}
Console.WriteLine();
}
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 57, 64, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95]]
| 8
| 1,312
| 27
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
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 int digit(long x) {
int d = 0;
while (x > 0) {
x /= 10;
d++;
}
return d;
}
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var input = Reads();
var n = input[0];
var m = input[1];
var s = new long[m];
var c = new long[m];
for (int i = 0; i < m; i++) {
input = Reads();
s[i] = input[0];
c[i] = input[1];
}
bool g = false;
long anwer = 0;
var d = new long[n];
for (long i = 0; i < (long)Math.Pow(10, n); i++) {
int count = 0;
for (int j = 0; j < m; j++) {
if (c[j] == i / (long)Math.Pow(10, n - s[j]) % 10)
count++;
}
if (count == m && n == digit(i)) {
g = true;
anwer = i;
break;
}
}
if (g)
Console.WriteLine(anwer);
else
Console.WriteLine(-1);
Console.Out.Flush();
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
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 int digit(long x) {
int d = 0;
if (x == 0)
return 1;
else {
while (x > 0) {
x /= 10;
d++;
}
return d;
}
}
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var input = Reads();
var n = input[0];
var m = input[1];
var s = new long[m];
var c = new long[m];
for (int i = 0; i < m; i++) {
input = Reads();
s[i] = input[0];
c[i] = input[1];
}
bool g = false;
long anwer = 0;
var d = new long[n];
for (long i = 0; i < (long)Math.Pow(10, n); i++) {
int count = 0;
for (int j = 0; j < m; j++) {
if (c[j] == i / (long)Math.Pow(10, n - s[j]) % 10)
count++;
}
if (count == m && n == digit(i)) {
g = true;
anwer = i;
break;
}
}
if (g)
Console.WriteLine(anwer);
else
Console.WriteLine(-1);
Console.Out.Flush();
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 379
| 12
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
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 void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var input = Reads();
var n = input[0];
var m = input[1];
var s = new long[m];
var c = new long[m];
var d = new Dictionary<long, long>();
bool f = false;
for (int i = 0; i < m; i++) {
input = Reads();
if ((n == 2 || n == 3) && input[0] == 1 && input[1] == 0)
f = true;
else if (!d.ContainsKey(input[0]))
d.Add(input[0], input[1]);
else {
if (d[input[0]] != input[1])
f = true;
}
}
long answer = 0;
foreach (KeyValuePair<long, long> item in d) {
answer += item.Value * (long)Math.Pow(10, n - item.Key);
}
if (f)
Console.WriteLine(-1);
else {
if (n == 2) {
if (answer < 10)
Console.WriteLine(answer + 10);
else
Console.WriteLine(answer);
}
if (n == 3) {
if (answer < 100)
Console.WriteLine(answer + 100);
else
Console.WriteLine(answer);
}
}
Console.Out.Flush();
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
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 void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var input = Reads();
var n = input[0];
var m = input[1];
var s = new long[m];
var c = new long[m];
var d = new Dictionary<long, long>();
bool f = false;
for (int i = 0; i < m; i++) {
input = Reads();
if ((n == 2 || n == 3) && input[0] == 1 && input[1] == 0)
f = true;
else if (!d.ContainsKey(input[0]))
d.Add(input[0], input[1]);
else {
if (d[input[0]] != input[1])
f = true;
}
}
long answer = 0;
foreach (KeyValuePair<long, long> item in d) {
answer += item.Value * (long)Math.Pow(10, n - item.Key);
}
if (f)
Console.WriteLine(-1);
else {
if (n == 1)
Console.WriteLine(answer);
if (n == 2) {
if (answer < 10)
Console.WriteLine(answer + 10);
else
Console.WriteLine(answer);
}
if (n == 3) {
if (answer < 100)
Console.WriteLine(answer + 100);
else
Console.WriteLine(answer);
}
}
Console.Out.Flush();
}
}
|
[["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60]]
| 8
| 401
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
var nm = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }),
number => int.Parse(number));
var n = nm[0];
var m = nm[1];
if (m == 0) {
if (n == 1) {
Console.WriteLine(0);
return;
} else {
Console.WriteLine(Math.Pow(10, n - 1));
return;
}
}
var scs = new Dictionary<int, int>();
for (var i = 0; i < m; ++i) {
var sc = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }),
number => int.Parse(number));
if (sc[0] == 1 && sc[1] == 0) {
Console.WriteLine(-1);
return;
}
if (scs.ContainsKey(sc[0])) {
if (sc[1] != scs[sc[0]]) {
Console.WriteLine(-1);
return;
}
} else {
scs.Add(sc[0], sc[1]);
}
}
var sortedScs = scs.OrderBy(sc => sc.Key);
var min = Math.Pow(10, n - 1);
var max = Math.Pow(10, n) - 1;
for (var i = min; i <= max; ++i) {
var numText = i.ToString();
var isRight = true;
foreach (var sc in sortedScs) {
if (numText.Length < sc.Key) {
isRight = false;
break;
} else if (int.Parse(numText[sc.Key - 1].ToString()) != sc.Value) {
isRight = false;
break;
}
}
if (isRight) {
Console.WriteLine(i);
return;
}
}
Console.WriteLine(-1);
//デバッグ実行での確認用。そのまま提出しても問題なし
Console.ReadKey();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
var nm = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }),
number => int.Parse(number));
var n = nm[0];
var m = nm[1];
if (m == 0) {
if (n == 1) {
Console.WriteLine(0);
return;
} else {
Console.WriteLine(Math.Pow(10, n - 1));
return;
}
}
var scs = new Dictionary<int, int>();
for (var i = 0; i < m; ++i) {
var sc = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }),
number => int.Parse(number));
if (sc[0] == 1 && sc[1] == 0) {
if (n == 1) {
Console.WriteLine(0);
return;
} else {
Console.WriteLine(-1);
return;
}
}
if (scs.ContainsKey(sc[0])) {
if (sc[1] != scs[sc[0]]) {
Console.WriteLine(-1);
return;
}
} else {
scs.Add(sc[0], sc[1]);
}
}
var min = Math.Pow(10, n - 1);
var max = Math.Pow(10, n) - 1;
for (var i = min; i <= max; ++i) {
var numText = i.ToString();
var isRight = true;
foreach (var sc in scs) {
if (numText.Length < sc.Key) {
isRight = false;
break;
} else if (int.Parse(numText[sc.Key - 1].ToString()) != sc.Value) {
isRight = false;
break;
}
}
if (isRight) {
Console.WriteLine(i);
return;
}
}
Console.WriteLine(-1);
//デバッグ実行での確認用。そのまま提出しても問題なし
Console.ReadKey();
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 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], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46], ["-", 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, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 7, 8, 196, 0, 210, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 210, 12, 22]]
| 8
| 436
| 36
|
using System;
using System.Linq;
namespace ConsoleApp {
class Program {
static void Main(string[] args) {
var input1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
var N = input1[0];
var M = input1[1];
var a = Enumerable.Repeat(-1, N + 1).ToArray();
for (int _ = 0; _ < M; _++) {
var input2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
var s = input2[0];
var c = input2[1];
if (a[s] == -1) {
a[s] = c;
} else {
if (a[s] != c) {
Console.WriteLine(-1);
return;
}
}
}
if (a[1] == 0) {
Console.WriteLine(-1);
return;
}
if (a[1] == -1)
a[1] = 1;
var ans = a.Skip(1)
.Select(s => s == -1 ? 0 : s)
.Select(s => s.ToString())
.Aggregate((s, t) => s += t);
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Linq;
namespace ConsoleApp {
class Program {
static void Main(string[] args) {
var input1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
var N = input1[0];
var M = input1[1];
var a = Enumerable.Repeat(-1, N + 1).ToArray();
for (int _ = 0; _ < M; _++) {
var input2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
var s = input2[0];
var c = input2[1];
if (a[s] == -1) {
a[s] = c;
} else {
if (a[s] != c) {
Console.WriteLine(-1);
return;
}
}
}
if (N == 1) {
Console.WriteLine(a[1] == -1 ? 0 : a[1]);
return;
}
if (a[1] == 0) {
Console.WriteLine(-1);
return;
}
if (a[1] == -1)
a[1] = 1;
var ans = a.Skip(1)
.Select(s => s == -1 ? 0 : s)
.Select(s => s.ToString())
.Aggregate((s, t) => s += t);
Console.WriteLine(ans);
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 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, 28, 0, 41, 15, 16, 31, 204, 205, 22], ["+", 0, 41, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 41, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 0, 28, 0, 41, 15, 16, 12, 241, 0, 33], ["+", 0, 28, 0, 41, 15, 16, 12, 241, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 204, 205, 22], ["+", 0, 28, 0, 41, 75, 204, 206, 207, 0, 70], ["+", 0, 41, 75, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 41, 75, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24]]
| 8
| 278
| 30
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC157C {
class Program {
static void Main(string[] args) {
var NM = ReadInt();
int N = NM[0];
int M = NM[1];
int[] s = new int[M];
string[] c = new string[M];
for (int i = 0; i < M; i++) {
var input = ReadInt();
s[i] = input[0] - 1;
c[i] = input[1].ToString();
}
int ans = Solve(N, M, s, c);
Console.WriteLine(ans);
Console.ReadKey();
}
static int Solve(int N, int M, int[] s, string[] c) {
int start = (int)Math.Pow(10, N - 1);
if (N == 1)
start = 0;
for (int i = start; i < (int)Math.Pow(10, N); i++) {
string str = i.ToString();
for (int j = 0; j < M; j++) {
string a = str[s[j]].ToString();
if (a != c[j])
break;
//終了条件
if (j == M - 1)
return i;
}
}
return -1;
}
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 ABC157C {
class Program {
static void Main(string[] args) {
var NM = ReadInt();
int N = NM[0];
int M = NM[1];
int[] s = new int[M];
string[] c = new string[M];
for (int i = 0; i < M; i++) {
var input = ReadInt();
s[i] = input[0] - 1;
c[i] = input[1].ToString();
}
int ans = Solve(N, M, s, c);
Console.WriteLine(ans);
Console.ReadKey();
}
static int Solve(int N, int M, int[] s, string[] c) {
int start = (int)Math.Pow(10, N - 1);
if (N == 1)
start = 0;
int end = (int)Math.Pow(10, N);
for (int i = start; i < end; i++) {
string str = i.ToString();
bool ok = true;
for (int j = 0; j < M; j++) {
string a = str[s[j]].ToString();
if (a != c[j]) {
ok = false;
break;
}
}
if (ok)
return i;
}
return -1;
}
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, 7, 0, 88], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 146], ["+", 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], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 15, 22], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 373
| 38
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
namespace ForATCODER {
public class Program {
public static void Main(string[] args) {
int ccc = 0;
int[] d = s2iarray(Console.ReadLine().Split(' '));
int N = (int)Math.Pow(10, d[0] - 1);
int max = (int)Math.Pow(10, d[0]);
int[] d1 = new int[d[1]];
char[] d2 = new char[d[1]];
Dictionary<int, int> s = new Dictionary<int, int>();
for (int i = 0; i < d[1]; i++) {
int[] dd = s2iarray(Console.ReadLine().Split(' '));
d1[i] = dd[0];
d2[i] = Convert.ToString(dd[1])[0];
}
for (; N < max; N++) {
String ss = N.ToString();
int i = 0;
for (; i < d[1]; i++) {
if (ss[d1[i] - 1] != d2[i])
break;
else {
// RESULT(N);
}
}
if (i == d[1]) {
RESULT(N);
return;
};
}
RESULT(-1);
}
public static bool checka(int[] a, int m) {
int back = 1;
for (int i = 0; i < a.Length; i++) {
if (a[i] >= 1 && a[i] <= m) {
if (a[i] >= back) {
back = a[i];
} else {
return false;
}
} else {
return false;
}
}
return true;
}
public static ulong pow(int a, int b) {
ulong res = 1;
for (int i = 0; i < b; i++) {
res *= (ulong)a;
}
return res;
}
static int s2i(String s) { return Convert.ToInt32(s); }
static ulong s2l(String s) { return Convert.ToUInt64(s); }
static void RESULT(double res) { Console.WriteLine(res); }
static void RESULT(long res) { Console.WriteLine(res); }
static void RESULT(ulong res) { Console.WriteLine(res); }
static void RESULT(int res) { Console.WriteLine(res); }
static void RESULT(String res) { Console.WriteLine(res); }
static String[] ReadLineAll(int count) {
String[] res = new String[count];
for (int i = 0; i < count; i++) {
res[i] = Console.ReadLine();
}
return res;
}
static int[] s2iarray(String[] src) {
int len = src.Length;
int[] res = new int[len];
for (int i = 0; i < len; i++) {
res[i] = Convert.ToInt32(src[i]);
}
return res;
}
static long[] s2larray(String[] src) {
int len = src.Length;
long[] res = new long[len];
for (int i = 0; i < len; i++) {
res[i] = Convert.ToInt64(src[i]);
}
return res;
}
static ulong[] s2larray2(String[] src) {
int len = src.Length;
ulong[] res = new ulong[len];
for (int i = 0; i < len; i++) {
res[i] = Convert.ToUInt64(src[i]);
}
return res;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
namespace ForATCODER {
public class Program {
public static void Main(string[] args) {
int ccc = 0;
int[] d = s2iarray(Console.ReadLine().Split(' '));
int N = (int)Math.Pow(10, d[0] - 1);
int max = (int)Math.Pow(10, d[0]);
int[] d1 = new int[d[1]];
char[] d2 = new char[d[1]];
Dictionary<int, int> s = new Dictionary<int, int>();
for (int i = 0; i < d[1]; i++) {
int[] dd = s2iarray(Console.ReadLine().Split(' '));
d1[i] = dd[0];
d2[i] = Convert.ToString(dd[1])[0];
}
if (d[0] == 1)
N = 0;
for (; N < max; N++) {
String ss = N.ToString();
int i = 0;
for (; i < d[1]; i++) {
if (ss[d1[i] - 1] != d2[i])
break;
else {
// RESULT(N);
}
}
if (i == d[1]) {
RESULT(N);
return;
};
}
RESULT(-1);
}
public static bool checka(int[] a, int m) {
int back = 1;
for (int i = 0; i < a.Length; i++) {
if (a[i] >= 1 && a[i] <= m) {
if (a[i] >= back) {
back = a[i];
} else {
return false;
}
} else {
return false;
}
}
return true;
}
public static ulong pow(int a, int b) {
ulong res = 1;
for (int i = 0; i < b; i++) {
res *= (ulong)a;
}
return res;
}
static int s2i(String s) { return Convert.ToInt32(s); }
static ulong s2l(String s) { return Convert.ToUInt64(s); }
static void RESULT(double res) { Console.WriteLine(res); }
static void RESULT(long res) { Console.WriteLine(res); }
static void RESULT(ulong res) { Console.WriteLine(res); }
static void RESULT(int res) { Console.WriteLine(res); }
static void RESULT(String res) { Console.WriteLine(res); }
static String[] ReadLineAll(int count) {
String[] res = new String[count];
for (int i = 0; i < count; i++) {
res[i] = Console.ReadLine();
}
return res;
}
static int[] s2iarray(String[] src) {
int len = src.Length;
int[] res = new int[len];
for (int i = 0; i < len; i++) {
res[i] = Convert.ToInt32(src[i]);
}
return res;
}
static long[] s2larray(String[] src) {
int len = src.Length;
long[] res = new long[len];
for (int i = 0; i < len; i++) {
res[i] = Convert.ToInt64(src[i]);
}
return res;
}
static ulong[] s2larray2(String[] src) {
int len = src.Length;
ulong[] res = new ulong[len];
for (int i = 0; i < len; i++) {
res[i] = Convert.ToUInt64(src[i]);
}
return res;
}
}
}
|
[["+", 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, 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], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 831
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
namespace Atcoder {
class Program {
static void Main(string[] args) {
try {
Solve.Answer();
} catch (Exception ex) {
WriteLine(ex.ToString());
}
}
}
public class Solve {
public static void Answer() {
var nm = IO.ReadSplitInt;
var s = new int[nm[1]];
var c = new int[nm[1]];
for (int i = 0; i < nm[1]; i++) {
var t = IO.ReadSplitInt;
s[i] = t[0];
c[i] = t[1];
}
int min = 0;
int max = 0;
if (nm[0] == 1) {
max = 9;
} else if (nm[0] == 2) {
min = 10;
max = 99;
} else {
min = 100;
max = 999;
}
int ans = -1;
for (int i = min; i <= max; i++) {
var f = true;
for (int j = 0; j < nm[1]; j++) {
#region
if (nm[0] == 3) {
if (s[j] == 1) {
if (i / 100 != c[j]) {
f = false;
break;
}
} else if (s[j] == 2) {
if (i / 10 % 10 != c[j]) {
f = false;
break;
}
} else {
if (i % 10 != c[j]) {
f = false;
break;
}
}
} else if (nm[0] == 2) {
if (s[j] == 1) {
if (i / 10 % 10 != c[j]) {
f = false;
break;
}
} else {
if (i % 10 != c[j]) {
f = false;
break;
}
}
} else {
if (i != c[j]) {
f = false;
break;
}
}
#endregion
if (j == nm[1] - 1 && f == true) {
ans = i;
break;
}
}
if (ans != -1)
break;
}
WriteLine(ans);
}
public class IO {
#region Input
public static string ReadString => ReadLine();
public static int ReadInt => int.Parse(ReadLine());
public static long ReadLong => long.Parse(ReadLine());
public static double ReadDouble => double.Parse(ReadLine());
public static List<string> ReadSplitString => ReadLine().Split().ToList();
public static List<int> ReadSplitInt =>
ReadLine().Split().Select(s => int.Parse(s)).ToList();
public static List<long> ReadSplitLong =>
ReadLine().Split().Select(s => long.Parse(s)).ToList();
public static List<double> ReadSplitdouble =>
ReadLine().Split().Select(s => double.Parse(s)).ToList();
#endregion
#region Output
public static void
OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes"
: "No");
#endregion
}
public class Mod {
#region
// 割る数の定義
private readonly static long M = 1000000007;
// 足し算
public static long Add(long a, long b) => (a * b) % M;
// 引き算
public static long Sub(long a, long b) => (a - b) % M >= 0
? (a - b) % M
: (a - b) % M + M;
// 掛け算
public static long Multi(long a, long b) => (a * b) % M;
#endregion
}
public class Scanner {
#region
public string Str => Console.ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
// public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
// public int[] ArrInt1D(int n) => Create(n, () => Int);
// public long[] ArrLong1D(int n) => Create(n, () => Long);
// public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
// public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// インライン化を推奨する
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
#endregion
}
public static long GCD(long x, long y) {
#region
if (x < y) {
var tmp = x;
x = y;
y = tmp;
}
while (true)
{
if (x % y == 0) {
return y;
} else {
var tmp = x;
x = y;
y = tmp % y;
}
}
#endregion
}
public static long Choice2(long n) {
#region
if (n <= 1)
return 0;
if (n == 2)
return 1;
else
return n * (n - 1) / 2;
#endregion
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
namespace Atcoder {
class Program {
static void Main(string[] args) {
try {
Solve.Answer();
} catch (Exception ex) {
WriteLine(ex.ToString());
}
}
}
public class Solve {
public static void Answer() {
var nm = IO.ReadSplitInt;
var s = new int[nm[1]];
var c = new int[nm[1]];
for (int i = 0; i < nm[1]; i++) {
var t = IO.ReadSplitInt;
s[i] = t[0];
c[i] = t[1];
}
int min = 0;
int max = 0;
if (nm[0] == 1) {
max = 9;
} else if (nm[0] == 2) {
min = 10;
max = 99;
} else {
min = 100;
max = 999;
}
int ans = -1;
for (int i = min; i <= max; i++) {
var f = true;
for (int j = 0; j < nm[1]; j++) {
#region
if (nm[0] == 3) {
if (s[j] == 1) {
if (i / 100 != c[j]) {
f = false;
break;
}
} else if (s[j] == 2) {
if (i / 10 % 10 != c[j]) {
f = false;
break;
}
} else {
if (i % 10 != c[j]) {
f = false;
break;
}
}
} else if (nm[0] == 2) {
if (s[j] == 1) {
if (i / 10 % 10 != c[j]) {
f = false;
break;
}
} else {
if (i % 10 != c[j]) {
f = false;
break;
}
}
} else {
if (i != c[j]) {
f = false;
break;
}
}
#endregion
}
if (f) {
ans = i;
break;
}
}
WriteLine(ans);
}
public class IO {
#region Input
public static string ReadString => ReadLine();
public static int ReadInt => int.Parse(ReadLine());
public static long ReadLong => long.Parse(ReadLine());
public static double ReadDouble => double.Parse(ReadLine());
public static List<string> ReadSplitString => ReadLine().Split().ToList();
public static List<int> ReadSplitInt =>
ReadLine().Split().Select(s => int.Parse(s)).ToList();
public static List<long> ReadSplitLong =>
ReadLine().Split().Select(s => long.Parse(s)).ToList();
public static List<double> ReadSplitdouble =>
ReadLine().Split().Select(s => double.Parse(s)).ToList();
#endregion
#region Output
public static void
OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes"
: "No");
#endregion
}
public class Mod {
#region
// 割る数の定義
private readonly static long M = 1000000007;
// 足し算
public static long Add(long a, long b) => (a * b) % M;
// 引き算
public static long Sub(long a, long b) => (a - b) % M >= 0
? (a - b) % M
: (a - b) % M + M;
// 掛け算
public static long Multi(long a, long b) => (a * b) % M;
#endregion
}
public class Scanner {
#region
public string Str => Console.ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
// public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
// public int[] ArrInt1D(int n) => Create(n, () => Int);
// public long[] ArrLong1D(int n) => Create(n, () => Long);
// public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
// public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// インライン化を推奨する
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
#endregion
}
public static long GCD(long x, long y) {
#region
if (x < y) {
var tmp = x;
x = y;
y = tmp;
}
while (true)
{
if (x % y == 0) {
return y;
} else {
var tmp = x;
x = y;
y = tmp % y;
}
}
#endregion
}
public static long Choice2(long n) {
#region
if (n <= 1)
return 0;
if (n == 2)
return 1;
else
return n * (n - 1) / 2;
#endregion
}
}
}
|
[["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 15, 16, 31, 16, 12, 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, 33], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 0, 57, 15, 16, 12, 16, 12, 211, 0, 146], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 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, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35]]
| 8
| 1,431
| 22
|
using System;
namespace ABC157C {
class Program {
static void Main(string[] args) {
string[] nms = Console.ReadLine().Split();
int n = int.Parse(nms[0]);
int m = int.Parse(nms[1]);
string scs;
int[] s = new int[m];
int[] c = new int[m];
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = -1;
}
int ans = 0;
for (int i = 0; i < m; i++) {
scs = Console.ReadLine();
string[] sc = scs.Split();
s[i] = int.Parse(sc[0]);
c[i] = int.Parse(sc[1]);
}
for (int i = 0; i < m; i++) {
if ((a[s[i] - 1] != -1 && a[s[i] - 1] != c[i]) ||
(s[i] == 1 && c[i] == 0 && n != 1)) {
for (int j = 0; j < n; j++) {
a[j] = -1;
}
break;
}
a[s[i] - 1] = c[i];
}
bool isErr = true;
bool left = true;
for (int i = 0; i < n; i++) {
if (a[i] != -1) {
ans += a[i] * (int)Math.Pow(10, n - i - 1);
left = false;
isErr = false;
} else if (left) {
ans += 1 * (int)Math.Pow(10, n - i - 1);
left = false;
}
}
if (isErr) {
ans = -1;
}
if (m == 0) {
ans = 0;
}
Console.WriteLine(ans);
}
}
}
|
using System;
namespace ABC157C {
class Program {
static void Main(string[] args) {
string[] nms = Console.ReadLine().Split();
int n = int.Parse(nms[0]);
int m = int.Parse(nms[1]);
string scs;
int[] s = new int[m];
int[] c = new int[m];
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = -1;
}
int ans = 0;
for (int i = 0; i < m; i++) {
scs = Console.ReadLine();
string[] sc = scs.Split();
s[i] = int.Parse(sc[0]);
c[i] = int.Parse(sc[1]);
}
for (int i = 0; i < m; i++) {
if ((a[s[i] - 1] != -1 && a[s[i] - 1] != c[i]) ||
(s[i] == 1 && c[i] == 0 && n != 1)) {
for (int j = 0; j < n; j++) {
a[j] = -1;
}
break;
}
a[s[i] - 1] = c[i];
}
bool isErr = true;
bool left = true;
for (int i = 0; i < n; i++) {
if (a[i] != -1) {
ans += a[i] * (int)Math.Pow(10, n - i - 1);
left = false;
isErr = false;
} else if (left) {
ans += 1 * (int)Math.Pow(10, n - i - 1);
left = false;
}
}
if (isErr) {
ans = -1;
}
if (m == 0) {
switch (n) {
case 1:
ans = 0;
break;
case 2:
ans = 10;
break;
case 3:
ans = 100;
break;
}
}
Console.WriteLine(ans);
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 99, 0, 155], ["+", 8, 196, 0, 57, 64, 196, 0, 99, 0, 24], ["+", 8, 196, 0, 57, 64, 196, 0, 99, 51, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 99, 0, 25], ["+", 0, 57, 64, 196, 0, 99, 8, 254, 0, 45], ["+", 0, 99, 8, 254, 0, 239, 0, 264, 0, 173], ["+", 0, 99, 8, 254, 0, 239, 0, 264, 0, 203], ["+", 0, 99, 8, 254, 0, 239, 0, 264, 0, 102], ["+", 0, 99, 8, 254, 0, 239, 0, 93, 0, 94], ["+", 0, 99, 8, 254, 0, 239, 0, 93, 0, 35], ["+", 8, 254, 0, 239, 0, 1, 0, 11, 31, 22], ["+", 0, 239, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 254, 0, 239, 0, 1, 0, 11, 12, 203], ["+", 0, 99, 8, 254, 0, 239, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 99, 8, 254, 0, 46]]
| 8
| 434
| 29
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Math;
using static ABC156.Cin;
using static ABC156.Util;
using Pair = ABC156.VTuple<long, long>;
using Graph =
System.Collections.Generic.List<System.Collections.Generic.List<long>>;
namespace ABC156 {
public class Program {
static void Main(string[] args) { Abc157_C(); }
public static void Abc157_F() {}
public static void Abc157_E() {}
public static void Abc157_D() {}
public static void Abc157_C() {
long n = rl;
long m = rl;
long[] s, c;
ReadCols(out s, out c, m);
long min = (long)Math.Pow(10, n - 1);
if (n == 1)
min = 0;
long max = (long)Math.Pow(10, n) - 1;
for (int i = (int)min; i <= max; i++) {
var keta = new long[3];
FillArray(keta, -1);
keta[0] = 0;
for (int j = 0; j < 3; j++) {
var t = i / (long)Math.Pow(10, j);
if (t == 0)
continue;
keta[j] = t % 10;
}
bool b = true;
for (int j = 0; j < m; j++) {
b = b && keta[2 - (s[j] - 1)] == c[j];
}
if (b) {
Console.WriteLine(i);
return;
}
}
Console.WriteLine(-1);
}
public static void Abc157_B() {
long[][] a = ReadLongTable(3);
long n = rl;
HashSet<long> hs = new HashSet<long>();
for (int i = 0; i < n; i++) {
hs.Add(rl);
}
for (int i = 0; i < 3; i++) {
bool b = true;
for (int j = 0; j < 3; j++) {
b = b && hs.Contains(a[i][j]);
}
if (b) {
Console.WriteLine("Yes");
return;
}
}
for (int i = 0; i < 3; i++) {
bool b = true;
for (int j = 0; j < 3; j++) {
b = b && hs.Contains(a[j][i]);
}
if (b) {
Console.WriteLine("Yes");
return;
}
}
bool c = true;
for (int j = 0; j < 3; j++) {
c = c && hs.Contains(a[j][j]);
}
if (c) {
Console.WriteLine("Yes");
return;
}
c = true;
for (int j = 0; j < 3; j++) {
c = c && hs.Contains(a[2 - j][j]);
}
if (c) {
Console.WriteLine("Yes");
return;
}
Console.WriteLine("No");
}
public static void Abc157_A() {
long N = rl;
Console.WriteLine((N + 1) / 2);
}
}
public struct Mint {
public static long MOD = (long)1e9 + 7;
/// <summary>
/// 0以上MOD未満の整数
/// </summary>
public long Value;
public Mint(long val) {
Value = val % MOD;
if (Value < 0)
Value += MOD;
}
private static Mint Ctor(long val) { return new Mint() { Value = val }; }
public static Mint operator +(Mint a, Mint b) {
long res = a.Value + b.Value;
if (res > MOD)
res -= MOD;
return Ctor(res);
}
public static Mint operator -(Mint a, Mint b) {
long res = a.Value - b.Value;
if (res < 0)
res += MOD;
return Ctor(res);
}
public static Mint operator *(Mint a, Mint b) {
long res = a.Value * b.Value;
if (res > MOD)
res %= MOD;
return Ctor(res);
}
public static Mint operator /(Mint a, Mint b) { return a * Inv(b); }
public static Mint Pow(Mint a, long n) {
if (n == 0)
return new Mint(1);
Mint b = Pow(a, n >> 1);
b *= b;
if ((n & 1) == 1)
b *= a;
return b;
}
public static Mint Inv(Mint n) {
long a = n.Value;
long b = MOD;
long x = 1;
long u = 0;
while (b != 0) {
long k = a / b;
long _x = u;
u = x - k * u;
x = _x;
long _a = a;
a = b;
b = _a - (k * b);
}
return new Mint(x);
}
public override string ToString() { return Value.ToString(); }
public static implicit operator Mint(long a) { return new Mint(a); }
public static explicit operator long(Mint a) { return a.Value; }
}
public class HashMap<K, V> : Dictionary<K, V> {
V i;
static Func<V> j =
System.Linq.Expressions.Expression
.Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V)))
.Compile();
public HashMap() {}
public HashMap(V a) { i = a; }
new public V this[K a] { get { V b;
if (TryGetValue(a, out b))
return b;
else
return base[a] = i != null ? i : j();
}
set { base[a] = value; }
}
}
public static class Util {
public static readonly long INF = (long)1e17;
public readonly static long MOD = (long)1e9 + 7;
public static void DontAutoFlush() {
var a = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(a);
}
public static void Flush() { Console.Out.Flush(); }
public static T[] Sort<T>(T[] a) {
Array.Sort<T>(a);
return a;
}
public static T[] SortDecend<T>(T[] a) {
Array.Sort<T>(a);
Array.Reverse(a);
return a;
}
public static void Swap<T>(ref T a, ref T b) {
T c = a;
a = b;
b = c;
}
public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); }
public static void ChMax(ref long a, long b) {
if (a < b)
a = b;
}
public static void ChMin(ref long a, long b) {
if (a > b)
a = b;
}
public static long ModAdd(long a, long b) {
long c = a + b;
if (c >= MOD)
return c % MOD;
return c;
}
public static long ModMul(long a, long b) {
long c = a * b;
if (c >= MOD)
return c % MOD;
return c;
}
public static void ChModAdd(ref long a, long b) {
a += b;
if (a >= MOD)
a %= MOD;
}
public static void ChModMul(ref long a, long b) {
a *= b;
if (a >= MOD)
a %= MOD;
}
public static void FillArray<T>(T[] a, T b) {
int c = a.Length;
for (int d = 0; d < c; d++)
a[d] = b;
}
public static void FillArray<T>(T[,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
for (int e = 0; e < c; e++)
for (int f = 0; f < d; f++) {
a[e, f] = b;
}
}
public static void FillArray<T>(T[,,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
int e = a.GetLength(2);
for (int f = 0; f < c; f++)
for (int g = 0; g < d; g++) {
for (int h = 0; h < e; h++) {
a[f, g, h] = b;
}
}
}
public static long[] Accumulate(long[] a) {
long[] b = new long[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
public static double[] Accumulate(double[] a) {
double[] b = new double[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
}
public static class Cin {
public static long rl {
get { return ReadLong(); }
}
public static long[] rla {
get { return ReadLongArray(); }
}
public static double rd {
get { return ReadDouble(); }
}
public static double[] rda {
get { return ReadDoubleArray(); }
}
public static string rs {
get { return ReadString(); }
}
public static int ReadInt() { return int.Parse(k()); }
public static long ReadLong() { return long.Parse(k()); }
public static double ReadDouble() { return double.Parse(k()); }
public static string ReadString() { return k(); }
public static int[] ReadIntArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
public static long[] ReadLongArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
public static double[] ReadDoubleArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
}
public static void ReadCols(out long[] a, out long[] b, long c) {
a = new long[c];
b = new long[c];
for (int d = 0; d < c; d++) {
a[d] = ReadLong();
b[d] = ReadLong();
}
}
public static void ReadCols(out long[] a, out long[] b, out long[] c,
long d) {
a = new long[d];
b = new long[d];
c = new long[d];
for (int e = 0; e < d; e++) {
a[e] = ReadLong();
b[e] = ReadLong();
c[e] = ReadLong();
}
}
public static int[][] ReadIntTable(int a) {
i = null;
int[][] b = new int [a][];
for (int c = 0; c < a; c++)
b[c] = ReadIntArray();
return b;
}
public static long[][] ReadLongTable(long a) {
i = null;
long[][] b = new long [a][];
for (long c = 0; c < a; c++)
b[c] = ReadLongArray();
return b;
}
static string[] i { get; set; }
static int j { get; set; }
static string k() {
if (i == null || i.Length <= j) {
i = Console.ReadLine().Split(' ');
j = 0;
}
return i[j++];
}
}
public struct VTuple<T1, T2> : IComparable<VTuple<T1, T2>>,
IEquatable<VTuple<T1, T2>> {
public T1 First;
public T2 Second;
public VTuple(T1 a, T2 b) {
First = a;
Second = b;
}
public int CompareTo(VTuple<T1, T2> a) {
int b = Comparer<T1>.Default.Compare(First, a.First);
if (b != 0)
return b;
return Comparer<T2>.Default.Compare(Second, a.Second);
}
public override bool Equals(object a) {
return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a);
}
public bool Equals(VTuple<T1, T2> a) {
return EqualityComparer<T1>.Default.Equals(First, a.First) &&
EqualityComparer<T2>.Default.Equals(Second, a.Second);
}
public override int GetHashCode() {
int a = First != null ? First.GetHashCode() : 0;
int b = Second != null ? Second.GetHashCode() : 0;
uint c = ((uint)a << 5) | ((uint)a >> 27);
return ((int)c + a) ^ b;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Math;
using static ABC156.Cin;
using static ABC156.Util;
using Pair = ABC156.VTuple<long, long>;
using Graph =
System.Collections.Generic.List<System.Collections.Generic.List<long>>;
namespace ABC156 {
public class Program {
static void Main(string[] args) { Abc157_C(); }
public static void Abc157_F() {}
public static void Abc157_E() {}
public static void Abc157_D() {}
public static void Abc157_C() {
long n = rl;
long m = rl;
long[] s, c;
ReadCols(out s, out c, m);
long min = (long)Math.Pow(10, n - 1);
if (n == 1)
min = 0;
long max = (long)Math.Pow(10, n) - 1;
for (int i = (int)min; i <= max; i++) {
var keta = new long[3];
FillArray(keta, -1);
keta[0] = 0;
int len = 0;
for (int j = 0; j < 3; j++) {
var t = i / (long)Math.Pow(10, j);
if (t == 0)
continue;
len = j;
keta[j] = t % 10;
}
bool b = true;
for (int j = 0; j < m; j++) {
if (len - (s[j] - 1) < 0) {
Console.WriteLine(-1);
return;
}
b = b && keta[len - (s[j] - 1)] == c[j];
}
if (b) {
Console.WriteLine(i);
return;
}
}
Console.WriteLine(-1);
}
public static void Abc157_B() {
long[][] a = ReadLongTable(3);
long n = rl;
HashSet<long> hs = new HashSet<long>();
for (int i = 0; i < n; i++) {
hs.Add(rl);
}
for (int i = 0; i < 3; i++) {
bool b = true;
for (int j = 0; j < 3; j++) {
b = b && hs.Contains(a[i][j]);
}
if (b) {
Console.WriteLine("Yes");
return;
}
}
for (int i = 0; i < 3; i++) {
bool b = true;
for (int j = 0; j < 3; j++) {
b = b && hs.Contains(a[j][i]);
}
if (b) {
Console.WriteLine("Yes");
return;
}
}
bool c = true;
for (int j = 0; j < 3; j++) {
c = c && hs.Contains(a[j][j]);
}
if (c) {
Console.WriteLine("Yes");
return;
}
c = true;
for (int j = 0; j < 3; j++) {
c = c && hs.Contains(a[2 - j][j]);
}
if (c) {
Console.WriteLine("Yes");
return;
}
Console.WriteLine("No");
}
public static void Abc157_A() {
long N = rl;
Console.WriteLine((N + 1) / 2);
}
}
public struct Mint {
public static long MOD = (long)1e9 + 7;
/// <summary>
/// 0以上MOD未満の整数
/// </summary>
public long Value;
public Mint(long val) {
Value = val % MOD;
if (Value < 0)
Value += MOD;
}
private static Mint Ctor(long val) { return new Mint() { Value = val }; }
public static Mint operator +(Mint a, Mint b) {
long res = a.Value + b.Value;
if (res > MOD)
res -= MOD;
return Ctor(res);
}
public static Mint operator -(Mint a, Mint b) {
long res = a.Value - b.Value;
if (res < 0)
res += MOD;
return Ctor(res);
}
public static Mint operator *(Mint a, Mint b) {
long res = a.Value * b.Value;
if (res > MOD)
res %= MOD;
return Ctor(res);
}
public static Mint operator /(Mint a, Mint b) { return a * Inv(b); }
public static Mint Pow(Mint a, long n) {
if (n == 0)
return new Mint(1);
Mint b = Pow(a, n >> 1);
b *= b;
if ((n & 1) == 1)
b *= a;
return b;
}
public static Mint Inv(Mint n) {
long a = n.Value;
long b = MOD;
long x = 1;
long u = 0;
while (b != 0) {
long k = a / b;
long _x = u;
u = x - k * u;
x = _x;
long _a = a;
a = b;
b = _a - (k * b);
}
return new Mint(x);
}
public override string ToString() { return Value.ToString(); }
public static implicit operator Mint(long a) { return new Mint(a); }
public static explicit operator long(Mint a) { return a.Value; }
}
public class HashMap<K, V> : Dictionary<K, V> {
V i;
static Func<V> j =
System.Linq.Expressions.Expression
.Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V)))
.Compile();
public HashMap() {}
public HashMap(V a) { i = a; }
new public V this[K a] { get { V b;
if (TryGetValue(a, out b))
return b;
else
return base[a] = i != null ? i : j();
}
set { base[a] = value; }
}
}
public static class Util {
public static readonly long INF = (long)1e17;
public readonly static long MOD = (long)1e9 + 7;
public static void DontAutoFlush() {
var a = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(a);
}
public static void Flush() { Console.Out.Flush(); }
public static T[] Sort<T>(T[] a) {
Array.Sort<T>(a);
return a;
}
public static T[] SortDecend<T>(T[] a) {
Array.Sort<T>(a);
Array.Reverse(a);
return a;
}
public static void Swap<T>(ref T a, ref T b) {
T c = a;
a = b;
b = c;
}
public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); }
public static void ChMax(ref long a, long b) {
if (a < b)
a = b;
}
public static void ChMin(ref long a, long b) {
if (a > b)
a = b;
}
public static long ModAdd(long a, long b) {
long c = a + b;
if (c >= MOD)
return c % MOD;
return c;
}
public static long ModMul(long a, long b) {
long c = a * b;
if (c >= MOD)
return c % MOD;
return c;
}
public static void ChModAdd(ref long a, long b) {
a += b;
if (a >= MOD)
a %= MOD;
}
public static void ChModMul(ref long a, long b) {
a *= b;
if (a >= MOD)
a %= MOD;
}
public static void FillArray<T>(T[] a, T b) {
int c = a.Length;
for (int d = 0; d < c; d++)
a[d] = b;
}
public static void FillArray<T>(T[,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
for (int e = 0; e < c; e++)
for (int f = 0; f < d; f++) {
a[e, f] = b;
}
}
public static void FillArray<T>(T[,,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
int e = a.GetLength(2);
for (int f = 0; f < c; f++)
for (int g = 0; g < d; g++) {
for (int h = 0; h < e; h++) {
a[f, g, h] = b;
}
}
}
public static long[] Accumulate(long[] a) {
long[] b = new long[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
public static double[] Accumulate(double[] a) {
double[] b = new double[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
}
public static class Cin {
public static long rl {
get { return ReadLong(); }
}
public static long[] rla {
get { return ReadLongArray(); }
}
public static double rd {
get { return ReadDouble(); }
}
public static double[] rda {
get { return ReadDoubleArray(); }
}
public static string rs {
get { return ReadString(); }
}
public static int ReadInt() { return int.Parse(k()); }
public static long ReadLong() { return long.Parse(k()); }
public static double ReadDouble() { return double.Parse(k()); }
public static string ReadString() { return k(); }
public static int[] ReadIntArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
public static long[] ReadLongArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
public static double[] ReadDoubleArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
}
public static void ReadCols(out long[] a, out long[] b, long c) {
a = new long[c];
b = new long[c];
for (int d = 0; d < c; d++) {
a[d] = ReadLong();
b[d] = ReadLong();
}
}
public static void ReadCols(out long[] a, out long[] b, out long[] c,
long d) {
a = new long[d];
b = new long[d];
c = new long[d];
for (int e = 0; e < d; e++) {
a[e] = ReadLong();
b[e] = ReadLong();
c[e] = ReadLong();
}
}
public static int[][] ReadIntTable(int a) {
i = null;
int[][] b = new int [a][];
for (int c = 0; c < a; c++)
b[c] = ReadIntArray();
return b;
}
public static long[][] ReadLongTable(long a) {
i = null;
long[][] b = new long [a][];
for (long c = 0; c < a; c++)
b[c] = ReadLongArray();
return b;
}
static string[] i { get; set; }
static int j { get; set; }
static string k() {
if (i == null || i.Length <= j) {
i = Console.ReadLine().Split(' ');
j = 0;
}
return i[j++];
}
}
public struct VTuple<T1, T2> : IComparable<VTuple<T1, T2>>,
IEquatable<VTuple<T1, T2>> {
public T1 First;
public T2 Second;
public VTuple(T1 a, T2 b) {
First = a;
Second = b;
}
public int CompareTo(VTuple<T1, T2> a) {
int b = Comparer<T1>.Default.Compare(First, a.First);
if (b != 0)
return b;
return Comparer<T2>.Default.Compare(Second, a.Second);
}
public override bool Equals(object a) {
return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a);
}
public bool Equals(VTuple<T1, T2> a) {
return EqualityComparer<T1>.Default.Equals(First, a.First) &&
EqualityComparer<T2>.Default.Equals(Second, a.Second);
}
public override int GetHashCode() {
int a = First != null ? First.GetHashCode() : 0;
int b = Second != null ? Second.GetHashCode() : 0;
uint c = ((uint)a << 5) | ((uint)a >> 27);
return ((int)c + a) ^ b;
}
}
}
|
[["+", 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, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 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, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 25], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 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, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 31, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22]]
| 8
| 2,883
| 38
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test {
class Program {
static void Main(string[] args) {
var r = Console.ReadLine().Split(' ');
var N = r[0].ToInt();
var M = r[1].ToInt();
var max = Math.Pow(10, N).ToInt();
var min = Math.Pow(10, N - 1).ToInt();
var l = new Dictionary<int, int>();
var ans = 0;
for (int i = 0; i < M; i++) {
var sc = Console.ReadLine().Split(' ');
var s = sc[0].ToInt();
var c = sc[1].ToInt();
if (l.ContainsKey(s)) {
if (l[s] == c) {
continue;
} else {
Console.WriteLine(-1);
return;
}
}
l.Add(s, c);
ans += Math.Pow(10, N - s).ToInt() * c;
if (s == 1 && ans < min) {
Console.WriteLine(-1);
return;
}
}
if (ans >= max) {
Console.WriteLine(-1);
return;
}
if (ans < min) {
ans += min;
}
Console.WriteLine(ans);
Console.ReadLine();
}
}
public static class Extensions {
public static int ToInt(this object str) { return int.Parse(str.ToString()); }
public static decimal ToDecimal(this object str) {
return decimal.Parse(str.ToString());
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test {
class Program {
static void Main(string[] args) {
var r = Console.ReadLine().Split(' ');
var N = r[0].ToInt();
var M = r[1].ToInt();
var max = Math.Pow(10, N).ToInt();
var min = Math.Pow(10, N - 1).ToInt();
if (min == 1)
min = 0;
var l = new Dictionary<int, int>();
var ans = 0;
for (int i = 0; i < M; i++) {
var sc = Console.ReadLine().Split(' ');
var s = sc[0].ToInt();
var c = sc[1].ToInt();
if (l.ContainsKey(s)) {
if (l[s] == c) {
continue;
} else {
Console.WriteLine(-1);
return;
}
}
l.Add(s, c);
ans += Math.Pow(10, N - s).ToInt() * c;
if (s == 1 && ans < min) {
Console.WriteLine(-1);
return;
}
}
if (ans >= max) {
Console.WriteLine(-1);
return;
}
if (ans < min) {
ans += min;
}
Console.WriteLine(ans);
Console.ReadLine();
}
}
public static class Extensions {
public static int ToInt(this object str) { return int.Parse(str.ToString()); }
public static decimal ToDecimal(this object str) {
return decimal.Parse(str.ToString());
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 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], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 369
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var l = Console.ReadLine();
var digit = int.Parse(l.Split(' ')[0]);
var num = int.Parse(l.Split(' ')[1]);
// line.Split(' ');
var flag = true;
if (num == 0) {
if (digit == 1) {
Console.WriteLine(0);
} else {
var s = "1";
for (var i = 2; i < digit + 1; i++) {
s += "0";
}
Console.WriteLine(s);
}
return;
}
var dict = new Dictionary<int, int>();
for (var i = 0; i < num; i++) {
var line = Console.ReadLine();
var digitPlace = int.Parse(line.Split(' ')[0]);
var digitNum = int.Parse(line.Split(' ')[1]);
if (!dict.ContainsKey(digitPlace)) {
dict.Add(digitPlace, digitNum);
} else {
if (dict[digitPlace] != digitNum) {
flag = false;
break;
}
}
}
var str = "";
if (flag) {
for (var i = 1; i < digit + 1; i++) {
if (i == 1 && dict[1] == 0 && digit != 1) {
Console.WriteLine(-1);
break;
}
if (dict.ContainsKey(i)) {
str += dict[i];
} else {
if (i == 1) {
str += "1";
} else {
str += "0";
}
}
}
Console.WriteLine(str);
} else {
Console.WriteLine(-1);
}
// Console.ReadKey();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var l = Console.ReadLine();
var digit = int.Parse(l.Split(' ')[0]);
var num = int.Parse(l.Split(' ')[1]);
// line.Split(' ');
var flag = true;
if (num == 0) {
if (digit == 1) {
Console.WriteLine(0);
} else {
var s = "1";
for (var i = 2; i < digit + 1; i++) {
s += "0";
}
Console.WriteLine(s);
}
return;
}
var dict = new Dictionary<int, int>();
for (var i = 0; i < num; i++) {
var line = Console.ReadLine();
var digitPlace = int.Parse(line.Split(' ')[0]);
var digitNum = int.Parse(line.Split(' ')[1]);
if (!dict.ContainsKey(digitPlace)) {
dict.Add(digitPlace, digitNum);
} else {
if (dict[digitPlace] != digitNum) {
flag = false;
break;
}
}
}
var str = "";
if (flag) {
for (var i = 1; i < digit + 1; i++) {
if (i == 1 && dict.ContainsKey(1) && dict[1] == 0 && digit != 1) {
Console.WriteLine(-1);
break;
}
if (dict.ContainsKey(i)) {
str += dict[i];
} else {
if (i == 1) {
str += "1";
} else {
str += "0";
}
}
}
Console.WriteLine(str);
} else {
Console.WriteLine(-1);
}
// Console.ReadKey();
}
}
|
[["+", 31, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["+", 31, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 31, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 31, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 31, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 15, 16, 31, 16, 12, 16, 31, 204, 205, 22]]
| 8
| 392
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
//[summary]C - Guess The Number
Console.WriteLine(CreateNumber());
}
static int CreateNumber() {
var line = ReadLine();
int N = line[0];
int M = line[1];
var number = new SortedDictionary<int, int>();
for (int i = 0; i < M; i++) {
line = ReadLine();
int s = line[0];
int c = line[1];
if (N > 1 && s == 1 && c == 0) {
return -1;
}
if (number.ContainsKey(s)) {
if (number[s] != c) {
return -1;
}
} else {
number.Add(s, c);
}
}
for (int i = 1; i <= N; i++) {
if (!number.ContainsKey(i)) {
if (i == 1) {
number.Add(i, 1);
} else {
number.Add(i, 0);
}
}
}
string ans = "";
foreach (var n in number.Values) {
ans += n;
}
return int.Parse(ans);
}
static List<int> ReadLine() {
var line = Console.ReadLine();
var arr = line.Split(' ');
return arr.Select(x => int.Parse(x)).ToList();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
//[summary]C - Guess The Number
Console.WriteLine(CreateNumber());
}
static int CreateNumber() {
var line = ReadLine();
int N = line[0];
int M = line[1];
var number = new SortedDictionary<int, int>();
for (int i = 0; i < M; i++) {
line = ReadLine();
int s = line[0];
int c = line[1];
if (N > 1 && s == 1 && c == 0) {
return -1;
}
if (number.ContainsKey(s)) {
if (number[s] != c) {
return -1;
}
} else {
number.Add(s, c);
}
}
for (int i = 1; i <= N; i++) {
if (!number.ContainsKey(i)) {
if (i == 1 && N == 1) {
number.Add(i, 0);
} else if (i == 1) {
number.Add(i, 1);
} else {
number.Add(i, 0);
}
}
}
string ans = "";
foreach (var n in number.Values) {
ans += n;
}
return int.Parse(ans);
}
static List<int> ReadLine() {
var line = Console.ReadLine();
var arr = line.Split(' ');
return arr.Select(x => int.Parse(x)).ToList();
}
}
}
|
[["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 24], ["+", 64, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 64, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 64, 196, 0, 57, 75, 57, 15, 16, 12, 203]]
| 8
| 319
| 22
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using ll=System.Int64;
using static Contest_A.Lib_IO;
using static Contest_A.Lib_Minifunc;
public static class Contest_A
{
public static void Main() {
checked{
long a, b;
string s, t, u;
Lib_IO.rm(out s, out t);
Lib_IO.rm(out a, out b);
Lib_IO.rm(out u);
Lib_IO.wm(u==s?a-1:b-1);
}
}
#region BaseModule
public static class Lib_Minifunc{
[MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
[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 の方が小さければ交換
[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 を更新
[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 を更新
[MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n);
[MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h));
[MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min();
[MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max();
[MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); }
[MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ
[MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b);
[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);
[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);
[MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } }
public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; }
public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; }
public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; }
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
}
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[] {' '};
[MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U));
[MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T));
[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 = z.Select(cv<T>).ToArray();
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);
}
[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));
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) {
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 System.Runtime.CompilerServices;
using System.Diagnostics;
using ll=System.Int64;
using static Contest_A.Lib_IO;
using static Contest_A.Lib_Minifunc;
public static class Contest_A
{
public static void Main() {
checked{
long a, b;
string s, t, u;
Lib_IO.rm(out s, out t);
Lib_IO.rm(out a, out b);
Lib_IO.rm(out u);
Lib_IO.wm(u==s?a-1:a, u==s?b:b-1);
}
}
#region BaseModule
public static class Lib_Minifunc{
[MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
[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 の方が小さければ交換
[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 を更新
[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 を更新
[MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n);
[MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h));
[MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min();
[MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max();
[MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); }
[MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ
[MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b);
[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);
[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);
[MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } }
public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; }
public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; }
public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; }
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
}
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[] {' '};
[MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U));
[MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T));
[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 = z.Select(cv<T>).ToArray();
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);
}
[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));
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) {
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, 213, 3, 4, 0, 28, 0, 41, 75, 22], ["+", 0, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 31, 22]]
| 8
| 2,932
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace CSharpSample01 {
class Program {
static void Main(string[] args) {
// スペース区切りの整数の入力
var S = Console.ReadLine();
var answer = "";
for (int i = 0; i < S.Length; i++) {
answer += "x";
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace CSharpSample01 {
class Program {
static void Main(string[] args) {
// スペース区切りの整数の入力
var S = Console.ReadLine();
var answer = "";
for (int i = 0; i < S.Length; i++) {
answer += "x";
}
Console.WriteLine(answer);
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 74
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] array = Console.ReadLine().Split(' ').Select(x => x).ToArray();
HashSet<string> hsTable = new HashSet<string>();
string message = "Yes";
for (long j = 0; j < N; j++)
hsTable.Add(array[j]);
if (N > hsTable.Count)
message = "No";
Console.WriteLine(message);
}
}
}
// 24579 = hon
// 0168 = pon
// 3 = bon
// long n = long.Parse(Console.ReadLine());
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
// Console.WriteLine(cnt);
// Console.ReadKey();
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] array = Console.ReadLine().Split(' ').Select(x => x).ToArray();
HashSet<string> hsTable = new HashSet<string>();
// var num = int.Parse(Console.ReadLine());
// var num2 = Console.ReadLine().Split(' ').GroupBy(a =>
// a).ToArray().Length; if (num == num2)
// Console.Write("YES");
// else
// Console.Write("NO");
string message = "";
for (long j = 0; j < N; j++)
hsTable.Add(array[j]);
if (N == hsTable.Count)
message = "YES";
else
message = "NO";
Console.WriteLine(message);
}
}
}
// 24579 = hon
// 0168 = pon
// 3 = bon
// long n = long.Parse(Console.ReadLine());
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
// Console.WriteLine(cnt);
// Console.ReadKey();
|
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 1, 0, 11, 12, 5, 0, 62], ["+", 0, 57, 64, 1, 0, 11, 12, 5, 0, 222], ["-", 0, 57, 64, 1, 0, 11, 12, 5, 0, 222], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 1, 0, 11, 12, 5, 0, 62], ["+", 0, 57, 75, 1, 0, 11, 12, 5, 0, 222]]
| 8
| 151
| 12
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
namespace AtCoder {
class Program {
public static void Main() {
#if TextInput
using (var reader = new StreamReader(Debug.SampleTextPath)) {
Console.SetIn(reader);
#endif
var num = IO.ReadInt();
IO.Write(IO.ReadIntArray().Distinct().Count() == num);
#if TextInput
}
#endif
}
}
public static class IO {
public static string Read() { return Console.ReadLine(); }
public static string[] ReadArray(char iSplitter = ' ') {
return Read().Split(iSplitter);
}
public static int ReadInt() { return int.Parse(Read()); }
public static int[] ReadIntArray(char iSplitter = ' ') {
return ReadArray().Select(iText => int.Parse(iText)).ToArray();
}
public static long ReadLong() { return int.Parse(Read()); }
public static long[] ReadLongArray(char iSplitter = ' ') {
return ReadArray().Select(iText => long.Parse(iText)).ToArray();
}
public static double ReadDouble() { return double.Parse(Read()); }
public static double[] ReadDoubleArray(char iSplitter = ' ') {
return ReadArray().Select(iText => double.Parse(iText)).ToArray();
}
public static char[] ReadCharArray() { return Read().ToCharArray(); }
public static void Write(string iValue) { Console.WriteLine(iValue); }
public static void Write(int iValue) { Console.WriteLine(iValue); }
public static void Write(long iValue) { Console.WriteLine(iValue); }
public static void Write(double iValue) { Console.WriteLine(iValue); }
public static void Write(decimal iValue) { Console.WriteLine(iValue); }
public static void Write(bool iValue) {
Console.WriteLine(iValue ? "Yes" : "No");
}
public static void Write<Type>(IEnumerable<Type> iValue,
string iJoinWord = " ") {
Console.WriteLine(string.Join(iJoinWord, iValue));
}
}
public static class Util {
public static long Gcd(long i0, long i1) {
return (i0 > i1) ? _Gcd(i0, i1) : _Gcd(i1, i0);
}
public static long Lcm(long i0, long i1) { return (i0 * i1) / Gcd(i0, i1); }
public static long ModPow(long iBaseNumber, long iPow, long iModNumber) {
var num = 1L;
while (iPow != 0) {
if ((iPow & 0x1) != 0) {
num = (num * iBaseNumber) % iModNumber;
}
iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber;
iPow >>= 1;
}
return num;
}
public static long CombinationNum(int iLeftNumber, int iRightNumber) {
if (iRightNumber == 0) {
return 1;
}
if (iLeftNumber == 0) {
return 0;
}
return iLeftNumber * CombinationNum(iLeftNumber - 1, iRightNumber - 1) /
iRightNumber;
}
private static long _Gcd(long i0, long i1) {
return (i1 == 0) ? i0 : _Gcd(i1, i0 % i1);
}
}
public class UnionFind {
public int[] Parents;
public int[] RootNums;
public UnionFind(int iRootNum) {
Parents = Enumerable.Range(0, iRootNum).ToArray();
RootNums = new int[iRootNum];
}
public void Normalize() {
for (var iIndex = 0; iIndex < Parents.Length; ++iIndex) {
var rootIndex = _GetRoot(iIndex);
++RootNums[rootIndex];
Parents[iIndex] = rootIndex;
}
}
public void Union(int iNumber0, int iNumber1) {
var rootNumber0 = _GetRoot(iNumber0);
var rootNumber1 = _GetRoot(iNumber1);
if (rootNumber0 < rootNumber1) {
Parents[rootNumber1] = rootNumber0;
} else {
Parents[rootNumber0] = rootNumber1;
}
}
public int _GetRoot(int iNumber) {
return (Parents[iNumber] == iNumber) ? iNumber : _GetRoot(Parents[iNumber]);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
namespace AtCoder {
class Program {
public static void Main() {
#if TextInput
using (var reader = new StreamReader(Debug.SampleTextPath)) {
Console.SetIn(reader);
#endif
var num = IO.ReadInt();
IO.Write(IO.ReadIntArray().Distinct().Count() == num ? "YES" : "NO");
#if TextInput
}
#endif
}
}
public static class IO {
public static string Read() { return Console.ReadLine(); }
public static string[] ReadArray(char iSplitter = ' ') {
return Read().Split(iSplitter);
}
public static int ReadInt() { return int.Parse(Read()); }
public static int[] ReadIntArray(char iSplitter = ' ') {
return ReadArray().Select(iText => int.Parse(iText)).ToArray();
}
public static long ReadLong() { return int.Parse(Read()); }
public static long[] ReadLongArray(char iSplitter = ' ') {
return ReadArray().Select(iText => long.Parse(iText)).ToArray();
}
public static double ReadDouble() { return double.Parse(Read()); }
public static double[] ReadDoubleArray(char iSplitter = ' ') {
return ReadArray().Select(iText => double.Parse(iText)).ToArray();
}
public static char[] ReadCharArray() { return Read().ToCharArray(); }
public static void Write(string iValue) { Console.WriteLine(iValue); }
public static void Write(int iValue) { Console.WriteLine(iValue); }
public static void Write(long iValue) { Console.WriteLine(iValue); }
public static void Write(double iValue) { Console.WriteLine(iValue); }
public static void Write(decimal iValue) { Console.WriteLine(iValue); }
public static void Write(bool iValue) {
Console.WriteLine(iValue ? "Yes" : "No");
}
public static void Write<Type>(IEnumerable<Type> iValue,
string iJoinWord = " ") {
Console.WriteLine(string.Join(iJoinWord, iValue));
}
}
public static class Util {
public static long Gcd(long i0, long i1) {
return (i0 > i1) ? _Gcd(i0, i1) : _Gcd(i1, i0);
}
public static long Lcm(long i0, long i1) { return (i0 * i1) / Gcd(i0, i1); }
public static long ModPow(long iBaseNumber, long iPow, long iModNumber) {
var num = 1L;
while (iPow != 0) {
if ((iPow & 0x1) != 0) {
num = (num * iBaseNumber) % iModNumber;
}
iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber;
iPow >>= 1;
}
return num;
}
public static long CombinationNum(int iLeftNumber, int iRightNumber) {
if (iRightNumber == 0) {
return 1;
}
if (iLeftNumber == 0) {
return 0;
}
return iLeftNumber * CombinationNum(iLeftNumber - 1, iRightNumber - 1) /
iRightNumber;
}
private static long _Gcd(long i0, long i1) {
return (i1 == 0) ? i0 : _Gcd(i1, i0 % i1);
}
}
public class UnionFind {
public int[] Parents;
public int[] RootNums;
public UnionFind(int iRootNum) {
Parents = Enumerable.Range(0, iRootNum).ToArray();
RootNums = new int[iRootNum];
}
public void Normalize() {
for (var iIndex = 0; iIndex < Parents.Length; ++iIndex) {
var rootIndex = _GetRoot(iIndex);
++RootNums[rootIndex];
Parents[iIndex] = rootIndex;
}
}
public void Union(int iNumber0, int iNumber1) {
var rootNumber0 = _GetRoot(iNumber0);
var rootNumber1 = _GetRoot(iNumber1);
if (rootNumber0 < rootNumber1) {
Parents[rootNumber1] = rootNumber0;
} else {
Parents[rootNumber0] = rootNumber1;
}
}
public int _GetRoot(int iNumber) {
return (Parents[iNumber] == iNumber) ? iNumber : _GetRoot(Parents[iNumber]);
}
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
| 8
| 869
| 8
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace C {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(double.Parse).ToArray();
Console.WriteLine(check(a));
}
private static string check(double[] a) {
for (int i = 0; i < a.Length - 1; i++) {
if (a[i] == a[i + 1]) {
return "NO";
}
}
return "YES";
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace C {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
// var a =
// Console.ReadLine().Split().Select(double.Parse).OrderBy(x=>x).ToArray();
var a = Console.ReadLine()
.Split()
.Select(double.Parse)
.OrderBy(x => x)
.Distinct();
Console.WriteLine(n == a.Count() ? "YES" : "NO");
// Console.WriteLine(check(a));
}
private static string check(double[] a) {
for (int i = 0; i < a.Length - 1; i++) {
if (a[i] == a[i + 1]) {
return "NO";
}
}
return "YES";
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 8, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 0, 41, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 41, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 41, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
| 8
| 140
| 7
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace C {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(double.Parse).ToArray();
Console.WriteLine(check(a));
}
private static string check(double[] a) {
for (int i = 0; i < a.Length - 1; i++) {
if (a[i] == a[i + 1]) {
return "NO";
}
}
return "YES";
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace C {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var a = Console.ReadLine()
.Split()
.Select(double.Parse)
.OrderBy(x => x)
.ToArray();
Console.WriteLine(check(a));
}
private static string check(double[] a) {
for (int i = 0; i < a.Length - 1; i++) {
if (a[i] == a[i + 1]) {
return "NO";
}
}
return "YES";
}
}
}
|
[["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 8, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131]]
| 8
| 140
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class QuestionC {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var n = long.Parse(Console.ReadLine());
// 整数配列の入力
var inputLongArray =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
var dic = new Dictionary<long, bool>();
foreach (var x in inputLongArray) {
if (dic.ContainsKey(x)) {
Console.WriteLine("NO");
return;
}
dic.Add(x, true);
}
Console.WriteLine("YES");
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class QuestionC {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var n = long.Parse(Console.ReadLine());
// 整数配列の入力
var inputLongArray =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
var dic = new Dictionary<long, bool>();
foreach (var x in inputLongArray) {
if (dic.ContainsKey(x)) {
Console.WriteLine("NO");
Console.Out.Flush();
return;
}
dic.Add(x, true);
}
Console.WriteLine("YES");
Console.Out.Flush();
}
}
}
|
[["+", 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], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 195
| 8
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
public class Hello {
public static void Main() {
int[] num = inta();
int nummax = 1;
for (int i = 0; i < num[0]; i++) {
nummax *= 10;
}
int nummin = nummax / 10;
if (nummin == 1) {
nummin = 0;
}
int[,] jd = inta2(num[1], 2);
/*
for(int i=0;i<num[1];i++){
WriteLine(jd[i,1]);
}
*/
int ans = -2;
for (int i = 0; i < num[1] - 1; i++) {
for (int j = i + 1; j < num[1]; j++) {
if (jd[i, 0] == jd[j, 0]) {
if (jd[i, 1] != jd[j, 1]) {
ans = -1;
}
}
}
}
if (ans == -1) {
WriteLine(ans);
} else {
ans = -1;
// nummin = 700;
// nummax = 705;
for (int i = nummin; i < nummax; i++) {
int count = 0;
// WriteLine(i);
for (int j = 0; j < num[1]; j++) {
if (jd[j, 0] == 1) {
int check = i / nummin;
if (jd[j, 1] == check) {
// WriteLine(111);
count++;
}
} else if (jd[j, 0] == 2) {
int check = (i % 100) / 10;
if (jd[j, 1] == check) {
// WriteLine(222);
count++;
}
} else if (jd[j, 0] == 3) {
int check = i % 10;
// WriteLine(jd[j,1]);
// WriteLine(check);
if (jd[j, 1] == check) {
// WriteLine(333);
count++;
}
}
}
// WriteLine(count);
if (count == num[1]) {
ans = i;
break;
}
}
WriteLine(ans);
}
}
//各種読取
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 int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// A/B小数点以下切上
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
//知見
// (string) hogestr -> (char[]) hoge
// char hoge = hogestr.ToCharArray();
// (char[]) hoge -> (string) hogestr
// string hoge = new string(hoge);
// Hashtable × Dictionary ○
// Dictionary hoge<string,int>
// hoge.ContainsKey(string) -> return boolean
// hoge[string] -> return int
// hoge[int] -> CE
// Dictionary hoge<int1,int2>
// hoge<int1,int2>: hoge[int1] -> return int2
// KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2
// SortedDictionary() > SortedList() ???
// キュー -> 幅優先 ???
// スタック -> 深さ優先 ???
// if (list?.Count > 0) リストが空でもnullでもない
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
public class Hello {
public static void Main() {
int[] num = inta();
int nummax = 1;
for (int i = 0; i < num[0]; i++) {
nummax *= 10;
}
int nummin = nummax / 10;
if (nummin == 1) {
nummin = 0;
}
int[,] jd = inta2(num[1], 2);
/*
for(int i=0;i<num[1];i++){
WriteLine(jd[i,1]);
}
*/
int ans = -2;
for (int i = 0; i < num[1] - 1; i++) {
for (int j = i + 1; j < num[1]; j++) {
if (jd[i, 0] == jd[j, 0]) {
if (jd[i, 1] != jd[j, 1]) {
ans = -1;
}
}
}
}
if (ans == -1) {
WriteLine(ans);
} else {
ans = -1;
// nummin = 700;
// nummax = 705;
for (int i = nummin; i < nummax; i++) {
int count = 0;
// WriteLine(i);
for (int j = 0; j < num[1]; j++) {
if (jd[j, 0] == 1) {
int check = i / Max(nummin, 1);
if (jd[j, 1] == check) {
// WriteLine(111);
count++;
}
} else if (jd[j, 0] == 2) {
int check = (i % nummin) / (nummin / 10);
if (jd[j, 1] == check) {
// WriteLine(222);
count++;
}
} else if (jd[j, 0] == 3) {
int check = i % 10;
// WriteLine(jd[j,1]);
// WriteLine(check);
if (jd[j, 1] == check) {
// WriteLine(333);
count++;
}
}
}
// WriteLine(count);
if (count == num[1]) {
ans = i;
break;
}
}
WriteLine(ans);
}
}
//各種読取
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 int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// A/B小数点以下切上
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
//知見
// (string) hogestr -> (char[]) hoge
// char hoge = hogestr.ToCharArray();
// (char[]) hoge -> (string) hogestr
// string hoge = new string(hoge);
// Hashtable × Dictionary ○
// Dictionary hoge<string,int>
// hoge.ContainsKey(string) -> return boolean
// hoge[string] -> return int
// hoge[int] -> CE
// Dictionary hoge<int1,int2>
// hoge<int1,int2>: hoge[int1] -> return int2
// KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2
// SortedDictionary() > SortedList() ???
// キュー -> 幅優先 ???
// スタック -> 深さ優先 ???
// if (list?.Count > 0) リストが空でもnullでもない
|
[["+", 0, 200, 0, 212, 0, 16, 12, 213, 63, 22], ["+", 0, 212, 0, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 16, 12, 213, 3, 4, 0, 21], ["+", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 212, 0, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 85], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25]]
| 8
| 938
| 11
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Contest {
class Program {
static void Main(string[] args) { ABC157C(); }
static void ABC157A() {
var N = ReadInt();
Console.WriteLine((N + 1) / 2);
}
static void ABC157B() {
var A1 = ReadIntN();
var A2 = ReadIntN();
var A3 = ReadIntN();
var N = ReadInt();
var A = new int[3, 3];
for (int i = 0; i < 3; ++i) {
A[0, i] = A1[i];
A[1, i] = A2[i];
A[2, i] = A3[i];
}
var B = new bool[3, 3];
for (int i = 0; i < N; ++i) {
var b = ReadInt();
for (int j1 = 0; j1 < 3; ++j1) {
for (int j2 = 0; j2 < 3; ++j2) {
if (A[j1, j2] == b) {
B[j1, j2] = true;
}
}
}
}
bool bingo = false;
for (int i = 0; i < 3; ++i) {
if (B[0, i] && B[1, i] && B[2, i]) {
bingo = true;
}
if (B[i, 0] && B[i, 1] && B[i, 2]) {
bingo = true;
}
}
if (B[0, 0] && B[1, 1] && B[2, 2]) {
bingo = true;
}
if (B[2, 0] && B[1, 1] && B[0, 2]) {
bingo = true;
}
Console.WriteLine(bingo ? "Yes" : "No");
}
static void ABC157C() {
var nm = ReadIntN();
var N = nm[0];
var M = nm[1];
var sc = ReadTupleLong(M);
var has = new bool[4];
var cand = new long[4];
bool ok = true;
foreach (var t in sc) {
var S = t.Item1;
var C = t.Item2;
if (has[S]) {
if (cand[S] != C) {
ok = false;
}
} else {
has[S] = true;
cand[S] = C;
}
}
if (!ok) {
Console.WriteLine("-1");
return;
}
if (N == 1) {
if (has[1]) {
Console.WriteLine(cand[1]);
return;
} else {
Console.WriteLine(0);
return;
}
}
if (has[1] && cand[1] == 0) {
Console.WriteLine("-1");
return;
}
cand[1] = 1;
if (N == 2) {
Console.WriteLine(cand[1] * 10 + cand[2]);
return;
}
Console.WriteLine(cand[1] * 100 + cand[2] * 10 + cand[3]);
}
static void ABC157D() {}
static void ABC157E() {}
static void ABC157F() {}
class Util {
public static readonly long P = 1000000007;
public static long Sum(long[] array) { return Sum(array, array.Length); }
public static long Sum(long[] array, int n) {
long total = 0;
for (int i = 0; i < n; ++i) {
total += array[i];
}
return total;
}
public static long Count(long[] array, long x) {
return Count(array, x, array.Length);
}
public static long Count(long[] array, long x, int n) {
long total = 0;
for (int i = 0; i < n; ++i) {
total += (array[i] == x ? 1 : 0);
}
return total;
}
public static long[] ASum(long[] array) {
var res = new long[array.Length + 1];
for (int i = 0; i < array.Length; ++i) {
res[i + 1] = res[i] + array[i];
}
return res;
}
public static long GCD(long a, long b) {
while (b > 0) {
var c = a % b;
a = b;
b = c;
}
return a;
}
public static bool IsPrime(long x) {
var fact = Factorize(x);
return fact.Count == 1 && fact.Values.ElementAt(0) == 1;
}
public static Dictionary<long, int> Factorize(long x) {
var dict = new Dictionary<long, int>();
long minp = 2;
while (x > 1) {
bool ok = false;
for (long p = minp; p * p <= x; ++p) {
if (x % p == 0) {
if (!dict.ContainsKey(p)) {
dict.Add(p, 0);
}
dict[p]++;
minp = p;
x /= p;
ok = true;
break;
}
}
if (!ok) {
if (!dict.ContainsKey(x)) {
dict.Add(x, 0);
}
dict[x]++;
break;
}
}
return dict;
}
public static long Inverse(long a, long p) {
long b = p, c = 1, d = 0, e = 0, f = 0;
while (b != 0) {
e = a / b;
f = b;
b = a - e * b;
a = f;
f = d;
d = c - e * d;
c = f;
}
c %= p;
return c + (c < 0 ? p : 0);
}
public static long[] Facts(int n, long p) {
var facts = new long[n + 1];
facts[0] = 1;
for (int i = 1; i <= n; ++i) {
facts[i] = (i * facts[i - 1]) % p;
}
return facts;
}
public static Func<int, int, long> Combin(int n, long P) {
var fact = Facts(n, P);
var inv = fact.Select(x => Inverse(x, P)).ToArray();
return (N, M) => {
if (N < 0 || N < M || M < 0) {
return 0;
}
return (((fact[N] * inv[M]) % P) * inv[N - M]) % P;
};
}
/// <summary>
/// Calc Combin(n,m) where n is large and m<=mMax
/// </summary>
public static Func<int, int, long> CombinLarge(int mMax, long p) {
var inv = Enumerable.Range(0, mMax + 1)
.Select(x => Util.Inverse(x, Util.P))
.ToArray();
return (n, m) => {
long mult = 1;
for (int i = 1; i <= m; ++i) {
mult = (((mult * (n + 1 - i)) % Util.P) * inv[i]) % Util.P;
}
return mult;
};
}
/// <summary>
/// Calc 2^n mod p
/// </summary>
public static long Power2(long n, long p) { return Power(2, n, p); }
public static long Power(long a, long n, long p) {
long res = 1;
long mult = a;
for (int i = 0; i < 40; ++i) {
if ((n & ((long)1 << i)) > 0) {
res = (res * mult) % p;
}
mult = (mult * mult) % p;
}
return res;
}
}
static string ReadStr() { return Console.ReadLine(); }
static string[] ReadStrN() { return Console.ReadLine().Split(' '); }
static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); }
static int[] ReadIntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); }
static long[] ReadLongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
static Tuple<string, string>[] ReadTupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = ReadStrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<long, long>[] ReadTupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<double, double>[] ReadTupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Contest {
class Program {
static void Main(string[] args) { ABC157C(); }
static void ABC157A() {
var N = ReadInt();
Console.WriteLine((N + 1) / 2);
}
static void ABC157B() {
var A1 = ReadIntN();
var A2 = ReadIntN();
var A3 = ReadIntN();
var N = ReadInt();
var A = new int[3, 3];
for (int i = 0; i < 3; ++i) {
A[0, i] = A1[i];
A[1, i] = A2[i];
A[2, i] = A3[i];
}
var B = new bool[3, 3];
for (int i = 0; i < N; ++i) {
var b = ReadInt();
for (int j1 = 0; j1 < 3; ++j1) {
for (int j2 = 0; j2 < 3; ++j2) {
if (A[j1, j2] == b) {
B[j1, j2] = true;
}
}
}
}
bool bingo = false;
for (int i = 0; i < 3; ++i) {
if (B[0, i] && B[1, i] && B[2, i]) {
bingo = true;
}
if (B[i, 0] && B[i, 1] && B[i, 2]) {
bingo = true;
}
}
if (B[0, 0] && B[1, 1] && B[2, 2]) {
bingo = true;
}
if (B[2, 0] && B[1, 1] && B[0, 2]) {
bingo = true;
}
Console.WriteLine(bingo ? "Yes" : "No");
}
static void ABC157C() {
var nm = ReadIntN();
var N = nm[0];
var M = nm[1];
var sc = ReadTupleLong(M);
var has = new bool[4];
var cand = new long[4];
bool ok = true;
foreach (var t in sc) {
var S = t.Item1;
var C = t.Item2;
if (has[S]) {
if (cand[S] != C) {
ok = false;
}
} else {
has[S] = true;
cand[S] = C;
}
}
if (!ok) {
Console.WriteLine("-1");
return;
}
if (N == 1) {
if (has[1]) {
Console.WriteLine(cand[1]);
return;
} else {
Console.WriteLine(0);
return;
}
}
if (has[1] && cand[1] == 0) {
Console.WriteLine("-1");
return;
}
if (!has[1]) {
cand[1] = 1;
}
if (N == 2) {
Console.WriteLine(cand[1] * 10 + cand[2]);
return;
}
Console.WriteLine(cand[1] * 100 + cand[2] * 10 + cand[3]);
}
static void ABC157D() {}
static void ABC157E() {}
static void ABC157F() {}
class Util {
public static readonly long P = 1000000007;
public static long Sum(long[] array) { return Sum(array, array.Length); }
public static long Sum(long[] array, int n) {
long total = 0;
for (int i = 0; i < n; ++i) {
total += array[i];
}
return total;
}
public static long Count(long[] array, long x) {
return Count(array, x, array.Length);
}
public static long Count(long[] array, long x, int n) {
long total = 0;
for (int i = 0; i < n; ++i) {
total += (array[i] == x ? 1 : 0);
}
return total;
}
public static long[] ASum(long[] array) {
var res = new long[array.Length + 1];
for (int i = 0; i < array.Length; ++i) {
res[i + 1] = res[i] + array[i];
}
return res;
}
public static long GCD(long a, long b) {
while (b > 0) {
var c = a % b;
a = b;
b = c;
}
return a;
}
public static bool IsPrime(long x) {
var fact = Factorize(x);
return fact.Count == 1 && fact.Values.ElementAt(0) == 1;
}
public static Dictionary<long, int> Factorize(long x) {
var dict = new Dictionary<long, int>();
long minp = 2;
while (x > 1) {
bool ok = false;
for (long p = minp; p * p <= x; ++p) {
if (x % p == 0) {
if (!dict.ContainsKey(p)) {
dict.Add(p, 0);
}
dict[p]++;
minp = p;
x /= p;
ok = true;
break;
}
}
if (!ok) {
if (!dict.ContainsKey(x)) {
dict.Add(x, 0);
}
dict[x]++;
break;
}
}
return dict;
}
public static long Inverse(long a, long p) {
long b = p, c = 1, d = 0, e = 0, f = 0;
while (b != 0) {
e = a / b;
f = b;
b = a - e * b;
a = f;
f = d;
d = c - e * d;
c = f;
}
c %= p;
return c + (c < 0 ? p : 0);
}
public static long[] Facts(int n, long p) {
var facts = new long[n + 1];
facts[0] = 1;
for (int i = 1; i <= n; ++i) {
facts[i] = (i * facts[i - 1]) % p;
}
return facts;
}
public static Func<int, int, long> Combin(int n, long P) {
var fact = Facts(n, P);
var inv = fact.Select(x => Inverse(x, P)).ToArray();
return (N, M) => {
if (N < 0 || N < M || M < 0) {
return 0;
}
return (((fact[N] * inv[M]) % P) * inv[N - M]) % P;
};
}
/// <summary>
/// Calc Combin(n,m) where n is large and m<=mMax
/// </summary>
public static Func<int, int, long> CombinLarge(int mMax, long p) {
var inv = Enumerable.Range(0, mMax + 1)
.Select(x => Util.Inverse(x, Util.P))
.ToArray();
return (n, m) => {
long mult = 1;
for (int i = 1; i <= m; ++i) {
mult = (((mult * (n + 1 - i)) % Util.P) * inv[i]) % Util.P;
}
return mult;
};
}
/// <summary>
/// Calc 2^n mod p
/// </summary>
public static long Power2(long n, long p) { return Power(2, n, p); }
public static long Power(long a, long n, long p) {
long res = 1;
long mult = a;
for (int i = 0; i < 40; ++i) {
if ((n & ((long)1 << i)) > 0) {
res = (res * mult) % p;
}
mult = (mult * mult) % p;
}
return res;
}
}
static string ReadStr() { return Console.ReadLine(); }
static string[] ReadStrN() { return Console.ReadLine().Split(' '); }
static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); }
static int[] ReadIntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); }
static long[] ReadLongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
static Tuple<string, string>[] ReadTupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = ReadStrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<long, long>[] ReadTupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<double, double>[] ReadTupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
}
}
|
[["+", 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], ["+", 8, 196, 0, 57, 15, 241, 0, 204, 205, 22], ["+", 0, 57, 15, 241, 0, 204, 206, 207, 0, 70], ["+", 15, 241, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 241, 0, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 2,093
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
string[] buf = Console.ReadLine().Split(' ');
int digit = int.Parse(buf[0]);
int max = int.Parse(buf[1]);
List<int> testcaseS = new List<int>();
List<int> testcaseM = new List<int>();
for (int i = 0; i < max; i++) {
buf = Console.ReadLine().Split(' ');
testcaseS.Add(int.Parse(buf[0]));
testcaseM.Add(int.Parse(buf[1]));
}
int startRange = 0;
int endRange = 0;
if (digit == 1) {
startRange = 0;
endRange = 10;
} else if (digit == 2) {
startRange = 10;
endRange = 100;
} else if (digit == 3) {
startRange = 100;
endRange = 1000;
}
bool checkF;
for (int i = startRange; i < endRange; i++) {
checkF = false;
List<char> target = new List<char>(i.ToString().ToCharArray());
for (int j = 0; j < max; j++) {
if (int.Parse(target[testcaseS[j] - 1].ToString()) == testcaseM[j]) {
checkF = true;
} else {
checkF = false;
break;
}
}
if (checkF) {
Console.WriteLine(i);
return;
}
}
Console.WriteLine(-1);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
string[] buf = Console.ReadLine().Split(' ');
int digit = int.Parse(buf[0]);
int max = int.Parse(buf[1]);
List<int> testcaseS = new List<int>();
List<int> testcaseM = new List<int>();
for (int i = 0; i < max; i++) {
buf = Console.ReadLine().Split(' ');
testcaseS.Add(int.Parse(buf[0]));
testcaseM.Add(int.Parse(buf[1]));
}
int startRange = 0;
int endRange = 0;
if (digit == 1) {
startRange = 0;
endRange = 10;
} else if (digit == 2) {
startRange = 10;
endRange = 100;
} else if (digit == 3) {
startRange = 100;
endRange = 1000;
}
bool checkF;
for (int i = startRange; i < endRange; i++) {
if (max == 0) {
Console.WriteLine(startRange);
return;
}
checkF = false;
List<char> target = new List<char>(i.ToString().ToCharArray());
for (int j = 0; j < max; j++) {
if (int.Parse(target[testcaseS[j] - 1].ToString()) == testcaseM[j]) {
checkF = true;
} else {
checkF = false;
break;
}
}
if (checkF) {
Console.WriteLine(i);
return;
}
}
Console.WriteLine(-1);
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 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, 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, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 353
| 17
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var line1 =
Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList();
var N = line1[0];
var M = line1[1];
// key=桁数、val:数値
Dictionary<int, int> ranks = new Dictionary<int, int>();
for (int i = 0; i < M; i++) {
var line =
Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList();
var s = N + 1 - line[0];
var c = line[1];
if (s == N && c == 0) {
Console.WriteLine("-1");
return;
}
if (!ranks.ContainsKey(s)) {
ranks.Add(s, c);
} else {
if (ranks[s] != c) {
Console.WriteLine("-1");
return;
}
}
}
var min = (long)Math.Pow(10, N - 1);
long answer = 0;
foreach (var kvp in ranks) {
var val = (long)Math.Pow(10, kvp.Key - 1) * kvp.Value;
answer += val;
}
if (answer < min) {
answer += min;
}
Console.WriteLine(answer.ToString());
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var line1 =
Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList();
var N = line1[0];
var M = line1[1];
// key=桁数、val:数値
Dictionary<int, int> ranks = new Dictionary<int, int>();
for (int i = 0; i < M; i++) {
var line =
Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList();
var s = N + 1 - line[0];
var c = line[1];
if (s > 1 && s == N && c == 0) {
Console.WriteLine("-1");
return;
}
if (!ranks.ContainsKey(s)) {
ranks.Add(s, c);
} else {
if (ranks[s] != c) {
Console.WriteLine("-1");
return;
}
}
}
var min = (long)Math.Pow(10, N - 1);
long answer = 0;
foreach (var kvp in ranks) {
var val = (long)Math.Pow(10, kvp.Key - 1) * kvp.Value;
answer += val;
}
if (min >= 10 && answer < min) {
answer += min;
}
Console.WriteLine(answer.ToString());
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 8, 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, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
| 8
| 315
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
class readint {
public readint(out int i) { i = int.Parse(Console.ReadLine()); }
public readint(out int a, out int b) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readint(out int a, out int b, out int c) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readint(out int a, out int b, out int c, out int d) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class readlong {
public readlong(out long i) { i = long.Parse(Console.ReadLine()); }
public readlong(out long a, out long b) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readlong(out long a, out long b, out long c) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readlong(out long a, out long b, out long c, out long d) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class modMWorld {
public static long M = (int)Math.Pow(10, 9) + 7;
//必要な演算は、加減乗除、nCk,n!,a^n
public static long add(long a, long b) {
long sum = a + b;
sum += M;
return sum % M;
}
public static long sub(long a, long b) {
long dif = a - b;
dif += M * 2;
return dif % M;
}
public static long mul(long a, long b) {
long product = a;
product *= b;
return product % M;
}
public static long div(long a, long b) { return mul(a, Pow(b, M - 2)); }
/// <summary>
/// a^m modMを求める
/// </summary>
/// <param name="a"></param>
/// <param name="m"></param>
/// <returns></returns>
public static long Pow(long a, long m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
long p1 = Pow(a, m / 2);
long p2 = mul(p1, p1);
return ((m % 2) == 0) ? p2 : mul(p2, a);
}
}
public static long kaijou(long n) {
//!
long output = 1;
for (int i = 0; i < n; i++) {
output = mul(output, n - i);
}
return output;
}
public static long nCk(long n, long k) {
long output = 1;
for (int i = 1; i <= k; i++) {
output = mul(output, n - (i - 1));
output = div(output, i);
}
return output;
}
}
class Util {
public static int[] readintarr() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static long[] readlongarr() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
/// <summary>
/// nの約数を小さい順のリストで返します。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static List<int> make_divisor(int n) {
List<int> output = new List<int>();
for (int i = 1; i <= Math.Sqrt(n) + 1; i++) {
if (n % i == 0) {
output.Add(i);
if (i * i != n) {
output.Add(n / i);
}
}
}
output.Sort();
return output;
}
// iの素因数分解をします
public static List<int> soinsuuBunkai(int n) {
//素因数分解をします
List<int> output = new List<int>();
int target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
public static List<long> soinsuuBunkai(long n) {
List<long> output = new List<long>();
long target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
/// <summary>
/// 2引数の最大公約数を返します。longです。
/// </summary>
/// <param name="a">long 引数1</param>
/// <param name="b">long 引数2</param>
/// <returns></returns>
public static long GCD(long a, long b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2引数の最大公約数を返します。intです。
/// </summary>
/// <param name="a">int 引数1</param>
/// <param name="b">int 引数2</param>
/// <returns></returns>
public static int GCD(int a, int b) {
// if (a < b)
// swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2つの変数の中身を交換する。型はなんでもいい
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="a"></param>
/// <param name="b"></param>
public static void swap<T>(ref T a, ref T b) {
T temp = b;
b = a;
a = temp;
}
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); }
public static int M = (int)(Math.Pow(10, 9)) + 7;
private static int[] factorial_modM;
/// <summary>
/// 2引数の積 mod Mを求める。Mは10億7。
/// 変えられるよ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Multiple_modM(int a, int b) {
return (int)(Math.BigMul(a, b) % M);
}
/// <summary>
/// n! modMまたはnCmを求めるための準備を行う。引数は最大値。
/// </summary>
/// <param name="n"></param>
public static void factorial_modM_Prepare(int n) {
factorial_modM = new int[n + 1];
factorial_modM[0] = 1;
for (int i = 1; i <= n; ++i) {
factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i);
}
}
/// <summary>
/// n! mod M を返す。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static int Factorial(int n) { return factorial_modM[n]; }
/// <summary>
/// a^m modMを求める
/// </summary>
/// <param name="a"></param>
/// <param name="m"></param>
/// <returns></returns>
public static int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Multiple_modM(p1, p1);
return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a);
}
}
/// <summary>
/// a / m Mod M を求める。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Div(int a, int b) {
return Multiple_modM(a, Pow(b, M - 2));
}
/// <summary>
/// nCr mod M を求める。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <param name="r"></param>
/// <returns></returns>
public static int nCr_modM(int n, int r) {
if (r < 0)
return 0;
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int res = Factorial(n);
res = Div(res, Factorial(r));
res = Div(res, Factorial(n - r));
return res;
}
}
/// <summary>
/// Union-Find木を定義する。コンストラクタの指定は、頂点の番号。
/// おすすめとしては、UnionFind<T>[] で宣言してしまう。
/// </summary>
/// <typeparam name="T">int固定でいいよね。</typeparam>
class UnionFind<T> {
public int tree_height;
public UnionFind<T> parent;
public T item { get; private set; }
public UnionFind(T item) {
tree_height = 0;
parent = this;
}
/// <summary>
/// 一番上の親を探す。
/// 探しながら繋がり方を最適化している。
/// UnionFindの頂点そのものを返すので、==での比較が可能。
/// </summary>
/// <returns></returns>
public UnionFind<T> FindAdam() {
if (parent == this)
return this;
else {
UnionFind<T> ParentOfParent = parent.FindAdam();
parent = ParentOfParent; //縦長な構成をつなぎ直している
return ParentOfParent;
}
}
/// <summary>
/// unionfind2つを一つにつなぐ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public static void Unite(UnionFind<T> a, UnionFind<T> b) {
UnionFind<T> ParentOfA = a.FindAdam();
UnionFind<T> ParentOfB = b.FindAdam();
if (ParentOfA.tree_height < ParentOfB.tree_height) {
ParentOfA.parent = ParentOfB;
ParentOfB.tree_height =
Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height);
} else {
ParentOfB.parent = ParentOfA;
ParentOfA.tree_height =
Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height);
}
}
}
// Treap 平衡二分木
class Treap<T>
where T : IComparable {
private class Node {
private static Random g_rand = new Random();
private readonly int m_rank = g_rand.Next();
private readonly T m_value;
private Node m_lch;
private Node m_rch;
private int m_count;
public Node(T value) {
m_value = value;
m_count = 1;
}
private static int Count(Node node) {
return (node != null) ? node.m_count : 0;
}
private Node Update() {
m_count = Count(m_lch) + Count(m_rch) + 1;
return this;
}
public static Node Merge(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
if (a.m_rank < b.m_rank) {
a.m_rch = Merge(a.m_rch, b);
return a.Update();
} else {
b.m_lch = Merge(a, b.m_lch);
return b.Update();
}
}
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null) {
return new Tuple<Node, Node>(null, null);
}
if (k <= Count(t.m_lch)) {
var pair = Split(t.m_lch, k);
t.m_lch = pair.Item2;
return new Tuple<Node, Node>(pair.Item1, t.Update());
} else {
var pair = Split(t.m_rch, k - Count(t.m_lch) - 1);
t.m_rch = pair.Item1;
return new Tuple<Node, Node>(t.Update(), pair.Item2);
}
}
public int FindIndex(T value) {
int L = Count(m_lch);
if (value.CompareTo(m_value) < 0) {
return (m_lch != null) ? m_lch.FindIndex(value) : 0;
} else if (value.CompareTo(m_value) > 0) {
return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1;
} else {
return L;
}
}
public T this[int i] {
get {
int L = Count(m_lch);
if (i < L) {
return m_lch[i];
} else if (i > L) {
return m_rch[i - L - 1];
} else {
return m_value;
}
}
}
}
private Node node;
public void Insert(T value) {
if (node != null) {
int k = node.FindIndex(value);
var pair = Node.Split(node, k);
node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2);
} else {
node = new Node(value);
}
}
public int FindIndex(T value) { return node.FindIndex(value); }
public T this[int i] {
get { return node[i]; }
}
}
/// <summary>
/// 使い方:Permutation.next(配列) で次の配列を返す
/// 配列を受け取って、その配列の要素を全部使った組み合わせのうち、辞書順で次のものを返します。
/// もし、次のがない場合、空の配列を返します。
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Permutation<T>
where T : IComparable {
public static T[] next(T[] letters) {
int pivot = -1;
for (int i = letters.Length - 2; i >= 0; i--) {
if (letters[i].CompareTo(letters[i + 1]) < 0) {
pivot = i;
break;
}
}
if (pivot == -1) {
return new T[0];
}
int big_min = letters.Length - 1;
T big_min_T = letters[letters.Length - 1];
for (int i = letters.Length - 1; i > pivot;
i--) { // big_min_Tより小さいかつ、pivotのより大きい
if (letters[pivot].CompareTo(letters[i]) > 0 &&
letters[pivot].CompareTo(big_min_T) < 0) {
big_min_T = letters[i];
big_min = i;
}
}
T temp = letters[pivot];
letters[pivot] = letters[big_min];
letters[big_min] = temp;
Array.Sort(letters, pivot + 1, letters.Length - pivot - 1);
return letters;
}
}
/// <summary>
/// 使い方 : Combination
/// .AllCombination(使える文字を、小さい順から配列にしたもの,ほしい文字数)
/// 使える文字を、小さい順から配列にしたものを重複ありで組み合わせて、stringのlistで出力する
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Combination<T>
where T : IComparable {
private static bool stop = false;
public static List<string> AllCombination(T[] letters, int n) {
// n桁ですよね。
List<string> outlist = new List<string>();
T[] state = new T[n];
for (int i = 0; i < n; i++) {
state[i] = letters[0];
}
outlist.Add(String.Join(" ", state));
while (true) {
next_keta(ref state, state.Length - 1, letters);
if (stop)
break;
outlist.Add(string.Join(" ", state));
}
return outlist;
}
public static T[] next_keta(ref T[] state, int keta, T[] letters) {
if (keta == -1) {
stop = true;
return new T[0];
}
if (state[keta].CompareTo(letters[letters.Length - 1]) == 0) {
//見た桁を最初の要素にする処理を
state[keta] = letters[0];
return next_keta(ref state, keta - 1, letters);
} else {
int ketaindex = 0;
for (int i = 0; i < letters.Length; i++) {
if (state[keta].CompareTo(letters[i]) == 0) {
ketaindex = i;
break;
}
}
state[keta] = letters[ketaindex + 1];
return state;
}
}
}
namespace CompLib.Collections {
#region PriorityQueue
/// <summary>
/// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します.
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam>
/// <remarks>内部的にはバイナリヒープによって実装されています.</remarks>
public class PriorityQueue<T> {
readonly List<T> heap = new List<T>();
readonly Comparison<T> cmp;
/// <summary>
/// デフォルトの比較子を使用してインスタンスを初期化します.
/// </summary>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue() { cmp = Comparer<T>.Default.Compare; }
/// <summary>
/// デリゲートで表されるような比較関数を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparison"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }
/// <summary>
/// 指定された比較子を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparer"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; }
/// <summary>
/// 優先度付きキューに要素を追加します.
/// </summary>
/// <param name="item">優先度付きキューに追加される要素</param>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public void Enqueue(T item) {
var pos = heap.Count;
heap.Add(item);
while (pos > 0) {
var par = (pos - 1) / 2;
if (cmp(heap[par], item) <= 0)
break;
heap[pos] = heap[par];
pos = par;
}
heap[pos] = item;
}
/// <summary>
/// 優先度付きキューから最も価値が低い要素を削除し,返します.
/// </summary>
/// <returns>優先度付きキューから削除された要素.</returns>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public T Dequeue() {
var ret = heap[0];
var pos = 0;
var x = heap[heap.Count - 1];
while (pos * 2 + 1 < heap.Count - 1) {
var lch = pos * 2 + 1;
var rch = pos * 2 + 2;
if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0)
lch = rch;
if (cmp(heap[lch], x) >= 0)
break;
heap[pos] = heap[lch];
pos = lch;
}
heap[pos] = x;
heap.RemoveAt(heap.Count - 1);
return ret;
}
/// <summary>
/// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します.
/// </summary>
/// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public T Peek() { return heap[0]; }
/// <summary>
/// 優先度付きキュー内の要素の数を取得します.
/// </summary>
/// <returns>優先度付キュー内にある要素の数</returns>
/// <remarks>最悪計算量 O(1) で実行されます.</remarks>
public int Count {
get { return heap.Count; }
}
/// <summary>
/// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します.
/// </summary>
/// <returns>優先度付キュー内にある要素が存在するならば
/// true,そうでなければ false.</returns> <remarks>この操作は O(1)
/// で実行されます.</remarks>
public bool Any() { return heap.Count > 0; }
/// <summary>
/// 優先度付きキューに含まれる要素を昇順に並べて返します.
/// </summary>
/// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks>
public T[] Items {
get {
var ret = heap.ToArray();
Array.Sort(ret, cmp);
return ret;
}
}
}
#endregion
}
/// <summary>
/// SEGTREEは1-BASE運用でございます
/// よろしくおねがいします
/// あと絶対コンストラクタ使ってね
/// </summary>
/// <typeparam name="T"></typeparam>
class Segtree<T> {
int n; //高さ
T[] tree; //本体
Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか
T exnum; //初期値
int count;
/// <summary>
/// !!!WARNING!!! 1-BASEです。
/// </summary>
/// <param name="m">最大値。200001とか入れておくとよい</param>
/// <param name="f">2引数の関数</param>
/// <param
/// name="ex">葉に書いてある値の初期値。fの関数に影響を与えない数値、零元とかにしておくべき。バグり散らかす。</param>
public Segtree(int m, Func<T, T, T> f, T ex) {
this.count = 0;
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
this.count = 0;
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
/// <summary>
/// j番目の値をxにする。計算し直さないので、
/// 入れ替えた後はall_update();を使おう
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
/// <summary>
/// j番目の値をxにする。計算し直すので、ちょっと計算時間がかかる
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void update(int j, T x) // j番目をxにする
{
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
this.count++;
}
/// <summary>
/// 木を全部計算し直す。多分NlogN。違うかも知れないから
/// よかったら教えて
/// </summary>
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
/// <summary>
/// j番目を消す。
/// </summary>
/// <param name="j"></param>
public void delete (int j) {
int i = j + n - 1;
tree[i] = exnum;
int moved = 0;
while (true) {
tree[i + 1] = tree[i];
T check = tree[i];
moved++;
if (moved + j + 2 > count) {
break;
}
}
all_update();
}
// [s, t)
/// <summary>
/// s番目からt番目までの結果を返す。
/// これも当然のように1-BASE.
/// </summary>
/// <param name="s"></param>
/// <param name="t"></param>
/// <returns></returns>
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class pair<T> {
public T A;
public T B;
public pair() {}
public pair(T A, T B) {
this.A = A;
this.B = B;
}
}
public class ABC {
// long[] sp = Console.ReadLine().Split().Select(long
// .Parse).ToArray(); int[] sp =
// Console.ReadLine().Split().Select(int.Parse).ToArray(); int N =
// int.Parse(Console.ReadLine());
// CompLib.Collections.PriorityQueue<?>
//文字列比較のcomparer
// StringComparer.OrdinalIgnoreCase
public static void Main() {
int N, M;
new readint(out N, out M);
pair<int>[] pairs = new pair<int>[M];
for (int i = 0; i < M; i++) {
int a, b;
new readint(out a, out b);
pairs[i] = new pair<int>(a, b);
}
if (pairs.Count() >= 2) {
Array.Sort(pairs, (a, b) => a.A.CompareTo(b.A));
} // 1,0があうと、X,AとX,Bがあるならあうと
if (N >= 2)
for (int i = 0; i < pairs.Length; i++) {
if (pairs[i].A == 1 && pairs[i].B == 0) {
Console.WriteLine(-1);
return;
}
}
string X = "";
for (int i = 0; i < N; i++) {
X = X + "X";
}
for (int i = 0; i < M; i++) {
int target = pairs[i].A - 1;
string targetstring = X[target].ToString();
if (targetstring == "X") {
X = X.Substring(0, target) + pairs[i].B +
X.Substring(target + 1, X.Length - target - 1);
} else {
if (targetstring != pairs[i].B.ToString()) {
Console.WriteLine(-1);
return;
}
}
}
bool first_keta_came = false;
for (int i = (int)(Math.Pow(10, N - 1)); i < (int)(Math.Pow(10, N)); i++) {
string istring = i.ToString();
while (istring.Length < X.Length) {
istring = "0" + istring;
}
bool go = true;
for (int last = 0; last < X.Length; last++) {
string Xst = X[last].ToString();
string ist = istring[last].ToString();
if (Xst == "X") {
} else {
if (Xst != ist) {
go = false;
break;
}
}
}
if (go) {
Console.WriteLine(i);
return;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
class readint {
public readint(out int i) { i = int.Parse(Console.ReadLine()); }
public readint(out int a, out int b) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readint(out int a, out int b, out int c) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readint(out int a, out int b, out int c, out int d) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class readlong {
public readlong(out long i) { i = long.Parse(Console.ReadLine()); }
public readlong(out long a, out long b) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readlong(out long a, out long b, out long c) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readlong(out long a, out long b, out long c, out long d) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class modMWorld {
public static long M = (int)Math.Pow(10, 9) + 7;
//必要な演算は、加減乗除、nCk,n!,a^n
public static long add(long a, long b) {
long sum = a + b;
sum += M;
return sum % M;
}
public static long sub(long a, long b) {
long dif = a - b;
dif += M * 2;
return dif % M;
}
public static long mul(long a, long b) {
long product = a;
product *= b;
return product % M;
}
public static long div(long a, long b) { return mul(a, Pow(b, M - 2)); }
/// <summary>
/// a^m modMを求める
/// </summary>
/// <param name="a"></param>
/// <param name="m"></param>
/// <returns></returns>
public static long Pow(long a, long m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
long p1 = Pow(a, m / 2);
long p2 = mul(p1, p1);
return ((m % 2) == 0) ? p2 : mul(p2, a);
}
}
public static long kaijou(long n) {
//!
long output = 1;
for (int i = 0; i < n; i++) {
output = mul(output, n - i);
}
return output;
}
public static long nCk(long n, long k) {
long output = 1;
for (int i = 1; i <= k; i++) {
output = mul(output, n - (i - 1));
output = div(output, i);
}
return output;
}
}
class Util {
public static int[] readintarr() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static long[] readlongarr() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
/// <summary>
/// nの約数を小さい順のリストで返します。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static List<int> make_divisor(int n) {
List<int> output = new List<int>();
for (int i = 1; i <= Math.Sqrt(n) + 1; i++) {
if (n % i == 0) {
output.Add(i);
if (i * i != n) {
output.Add(n / i);
}
}
}
output.Sort();
return output;
}
// iの素因数分解をします
public static List<int> soinsuuBunkai(int n) {
//素因数分解をします
List<int> output = new List<int>();
int target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
public static List<long> soinsuuBunkai(long n) {
List<long> output = new List<long>();
long target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
/// <summary>
/// 2引数の最大公約数を返します。longです。
/// </summary>
/// <param name="a">long 引数1</param>
/// <param name="b">long 引数2</param>
/// <returns></returns>
public static long GCD(long a, long b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2引数の最大公約数を返します。intです。
/// </summary>
/// <param name="a">int 引数1</param>
/// <param name="b">int 引数2</param>
/// <returns></returns>
public static int GCD(int a, int b) {
// if (a < b)
// swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2つの変数の中身を交換する。型はなんでもいい
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="a"></param>
/// <param name="b"></param>
public static void swap<T>(ref T a, ref T b) {
T temp = b;
b = a;
a = temp;
}
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); }
public static int M = (int)(Math.Pow(10, 9)) + 7;
private static int[] factorial_modM;
/// <summary>
/// 2引数の積 mod Mを求める。Mは10億7。
/// 変えられるよ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Multiple_modM(int a, int b) {
return (int)(Math.BigMul(a, b) % M);
}
/// <summary>
/// n! modMまたはnCmを求めるための準備を行う。引数は最大値。
/// </summary>
/// <param name="n"></param>
public static void factorial_modM_Prepare(int n) {
factorial_modM = new int[n + 1];
factorial_modM[0] = 1;
for (int i = 1; i <= n; ++i) {
factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i);
}
}
/// <summary>
/// n! mod M を返す。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static int Factorial(int n) { return factorial_modM[n]; }
/// <summary>
/// a^m modMを求める
/// </summary>
/// <param name="a"></param>
/// <param name="m"></param>
/// <returns></returns>
public static int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Multiple_modM(p1, p1);
return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a);
}
}
/// <summary>
/// a / m Mod M を求める。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Div(int a, int b) {
return Multiple_modM(a, Pow(b, M - 2));
}
/// <summary>
/// nCr mod M を求める。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <param name="r"></param>
/// <returns></returns>
public static int nCr_modM(int n, int r) {
if (r < 0)
return 0;
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int res = Factorial(n);
res = Div(res, Factorial(r));
res = Div(res, Factorial(n - r));
return res;
}
}
/// <summary>
/// Union-Find木を定義する。コンストラクタの指定は、頂点の番号。
/// おすすめとしては、UnionFind<T>[] で宣言してしまう。
/// </summary>
/// <typeparam name="T">int固定でいいよね。</typeparam>
class UnionFind<T> {
public int tree_height;
public UnionFind<T> parent;
public T item { get; private set; }
public UnionFind(T item) {
tree_height = 0;
parent = this;
}
/// <summary>
/// 一番上の親を探す。
/// 探しながら繋がり方を最適化している。
/// UnionFindの頂点そのものを返すので、==での比較が可能。
/// </summary>
/// <returns></returns>
public UnionFind<T> FindAdam() {
if (parent == this)
return this;
else {
UnionFind<T> ParentOfParent = parent.FindAdam();
parent = ParentOfParent; //縦長な構成をつなぎ直している
return ParentOfParent;
}
}
/// <summary>
/// unionfind2つを一つにつなぐ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public static void Unite(UnionFind<T> a, UnionFind<T> b) {
UnionFind<T> ParentOfA = a.FindAdam();
UnionFind<T> ParentOfB = b.FindAdam();
if (ParentOfA.tree_height < ParentOfB.tree_height) {
ParentOfA.parent = ParentOfB;
ParentOfB.tree_height =
Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height);
} else {
ParentOfB.parent = ParentOfA;
ParentOfA.tree_height =
Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height);
}
}
}
// Treap 平衡二分木
class Treap<T>
where T : IComparable {
private class Node {
private static Random g_rand = new Random();
private readonly int m_rank = g_rand.Next();
private readonly T m_value;
private Node m_lch;
private Node m_rch;
private int m_count;
public Node(T value) {
m_value = value;
m_count = 1;
}
private static int Count(Node node) {
return (node != null) ? node.m_count : 0;
}
private Node Update() {
m_count = Count(m_lch) + Count(m_rch) + 1;
return this;
}
public static Node Merge(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
if (a.m_rank < b.m_rank) {
a.m_rch = Merge(a.m_rch, b);
return a.Update();
} else {
b.m_lch = Merge(a, b.m_lch);
return b.Update();
}
}
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null) {
return new Tuple<Node, Node>(null, null);
}
if (k <= Count(t.m_lch)) {
var pair = Split(t.m_lch, k);
t.m_lch = pair.Item2;
return new Tuple<Node, Node>(pair.Item1, t.Update());
} else {
var pair = Split(t.m_rch, k - Count(t.m_lch) - 1);
t.m_rch = pair.Item1;
return new Tuple<Node, Node>(t.Update(), pair.Item2);
}
}
public int FindIndex(T value) {
int L = Count(m_lch);
if (value.CompareTo(m_value) < 0) {
return (m_lch != null) ? m_lch.FindIndex(value) : 0;
} else if (value.CompareTo(m_value) > 0) {
return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1;
} else {
return L;
}
}
public T this[int i] {
get {
int L = Count(m_lch);
if (i < L) {
return m_lch[i];
} else if (i > L) {
return m_rch[i - L - 1];
} else {
return m_value;
}
}
}
}
private Node node;
public void Insert(T value) {
if (node != null) {
int k = node.FindIndex(value);
var pair = Node.Split(node, k);
node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2);
} else {
node = new Node(value);
}
}
public int FindIndex(T value) { return node.FindIndex(value); }
public T this[int i] {
get { return node[i]; }
}
}
/// <summary>
/// 使い方:Permutation.next(配列) で次の配列を返す
/// 配列を受け取って、その配列の要素を全部使った組み合わせのうち、辞書順で次のものを返します。
/// もし、次のがない場合、空の配列を返します。
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Permutation<T>
where T : IComparable {
public static T[] next(T[] letters) {
int pivot = -1;
for (int i = letters.Length - 2; i >= 0; i--) {
if (letters[i].CompareTo(letters[i + 1]) < 0) {
pivot = i;
break;
}
}
if (pivot == -1) {
return new T[0];
}
int big_min = letters.Length - 1;
T big_min_T = letters[letters.Length - 1];
for (int i = letters.Length - 1; i > pivot;
i--) { // big_min_Tより小さいかつ、pivotのより大きい
if (letters[pivot].CompareTo(letters[i]) > 0 &&
letters[pivot].CompareTo(big_min_T) < 0) {
big_min_T = letters[i];
big_min = i;
}
}
T temp = letters[pivot];
letters[pivot] = letters[big_min];
letters[big_min] = temp;
Array.Sort(letters, pivot + 1, letters.Length - pivot - 1);
return letters;
}
}
/// <summary>
/// 使い方 : Combination
/// .AllCombination(使える文字を、小さい順から配列にしたもの,ほしい文字数)
/// 使える文字を、小さい順から配列にしたものを重複ありで組み合わせて、stringのlistで出力する
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Combination<T>
where T : IComparable {
private static bool stop = false;
public static List<string> AllCombination(T[] letters, int n) {
// n桁ですよね。
List<string> outlist = new List<string>();
T[] state = new T[n];
for (int i = 0; i < n; i++) {
state[i] = letters[0];
}
outlist.Add(String.Join(" ", state));
while (true) {
next_keta(ref state, state.Length - 1, letters);
if (stop)
break;
outlist.Add(string.Join(" ", state));
}
return outlist;
}
public static T[] next_keta(ref T[] state, int keta, T[] letters) {
if (keta == -1) {
stop = true;
return new T[0];
}
if (state[keta].CompareTo(letters[letters.Length - 1]) == 0) {
//見た桁を最初の要素にする処理を
state[keta] = letters[0];
return next_keta(ref state, keta - 1, letters);
} else {
int ketaindex = 0;
for (int i = 0; i < letters.Length; i++) {
if (state[keta].CompareTo(letters[i]) == 0) {
ketaindex = i;
break;
}
}
state[keta] = letters[ketaindex + 1];
return state;
}
}
}
namespace CompLib.Collections {
#region PriorityQueue
/// <summary>
/// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します.
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam>
/// <remarks>内部的にはバイナリヒープによって実装されています.</remarks>
public class PriorityQueue<T> {
readonly List<T> heap = new List<T>();
readonly Comparison<T> cmp;
/// <summary>
/// デフォルトの比較子を使用してインスタンスを初期化します.
/// </summary>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue() { cmp = Comparer<T>.Default.Compare; }
/// <summary>
/// デリゲートで表されるような比較関数を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparison"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }
/// <summary>
/// 指定された比較子を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparer"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; }
/// <summary>
/// 優先度付きキューに要素を追加します.
/// </summary>
/// <param name="item">優先度付きキューに追加される要素</param>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public void Enqueue(T item) {
var pos = heap.Count;
heap.Add(item);
while (pos > 0) {
var par = (pos - 1) / 2;
if (cmp(heap[par], item) <= 0)
break;
heap[pos] = heap[par];
pos = par;
}
heap[pos] = item;
}
/// <summary>
/// 優先度付きキューから最も価値が低い要素を削除し,返します.
/// </summary>
/// <returns>優先度付きキューから削除された要素.</returns>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public T Dequeue() {
var ret = heap[0];
var pos = 0;
var x = heap[heap.Count - 1];
while (pos * 2 + 1 < heap.Count - 1) {
var lch = pos * 2 + 1;
var rch = pos * 2 + 2;
if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0)
lch = rch;
if (cmp(heap[lch], x) >= 0)
break;
heap[pos] = heap[lch];
pos = lch;
}
heap[pos] = x;
heap.RemoveAt(heap.Count - 1);
return ret;
}
/// <summary>
/// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します.
/// </summary>
/// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public T Peek() { return heap[0]; }
/// <summary>
/// 優先度付きキュー内の要素の数を取得します.
/// </summary>
/// <returns>優先度付キュー内にある要素の数</returns>
/// <remarks>最悪計算量 O(1) で実行されます.</remarks>
public int Count {
get { return heap.Count; }
}
/// <summary>
/// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します.
/// </summary>
/// <returns>優先度付キュー内にある要素が存在するならば
/// true,そうでなければ false.</returns> <remarks>この操作は O(1)
/// で実行されます.</remarks>
public bool Any() { return heap.Count > 0; }
/// <summary>
/// 優先度付きキューに含まれる要素を昇順に並べて返します.
/// </summary>
/// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks>
public T[] Items {
get {
var ret = heap.ToArray();
Array.Sort(ret, cmp);
return ret;
}
}
}
#endregion
}
/// <summary>
/// SEGTREEは1-BASE運用でございます
/// よろしくおねがいします
/// あと絶対コンストラクタ使ってね
/// </summary>
/// <typeparam name="T"></typeparam>
class Segtree<T> {
int n; //高さ
T[] tree; //本体
Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか
T exnum; //初期値
int count;
/// <summary>
/// !!!WARNING!!! 1-BASEです。
/// </summary>
/// <param name="m">最大値。200001とか入れておくとよい</param>
/// <param name="f">2引数の関数</param>
/// <param
/// name="ex">葉に書いてある値の初期値。fの関数に影響を与えない数値、零元とかにしておくべき。バグり散らかす。</param>
public Segtree(int m, Func<T, T, T> f, T ex) {
this.count = 0;
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
this.count = 0;
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
/// <summary>
/// j番目の値をxにする。計算し直さないので、
/// 入れ替えた後はall_update();を使おう
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
/// <summary>
/// j番目の値をxにする。計算し直すので、ちょっと計算時間がかかる
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void update(int j, T x) // j番目をxにする
{
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
this.count++;
}
/// <summary>
/// 木を全部計算し直す。多分NlogN。違うかも知れないから
/// よかったら教えて
/// </summary>
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
/// <summary>
/// j番目を消す。
/// </summary>
/// <param name="j"></param>
public void delete (int j) {
int i = j + n - 1;
tree[i] = exnum;
int moved = 0;
while (true) {
tree[i + 1] = tree[i];
T check = tree[i];
moved++;
if (moved + j + 2 > count) {
break;
}
}
all_update();
}
// [s, t)
/// <summary>
/// s番目からt番目までの結果を返す。
/// これも当然のように1-BASE.
/// </summary>
/// <param name="s"></param>
/// <param name="t"></param>
/// <returns></returns>
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class pair<T> {
public T A;
public T B;
public pair() {}
public pair(T A, T B) {
this.A = A;
this.B = B;
}
}
public class ABC {
// long[] sp = Console.ReadLine().Split().Select(long
// .Parse).ToArray(); int[] sp =
// Console.ReadLine().Split().Select(int.Parse).ToArray(); int N =
// int.Parse(Console.ReadLine());
// CompLib.Collections.PriorityQueue<?>
//文字列比較のcomparer
// StringComparer.OrdinalIgnoreCase
public static void Main() {
int N, M;
new readint(out N, out M);
pair<int>[] pairs = new pair<int>[M];
for (int i = 0; i < M; i++) {
int a, b;
new readint(out a, out b);
pairs[i] = new pair<int>(a, b);
}
if (pairs.Count() >= 2) {
Array.Sort(pairs, (a, b) => a.A.CompareTo(b.A));
} // 1,0があうと、X,AとX,Bがあるならあうと
if (N >= 2)
for (int i = 0; i < pairs.Length; i++) {
if (pairs[i].A == 1 && pairs[i].B == 0) {
Console.WriteLine(-1);
return;
}
}
string X = "";
for (int i = 0; i < N; i++) {
X = X + "X";
}
for (int i = 0; i < M; i++) {
int target = pairs[i].A - 1;
string targetstring = X[target].ToString();
if (targetstring == "X") {
X = X.Substring(0, target) + pairs[i].B +
X.Substring(target + 1, X.Length - target - 1);
} else {
if (targetstring != pairs[i].B.ToString()) {
Console.WriteLine(-1);
return;
}
}
}
bool first_keta_came = false;
if (N >= 2) {
for (int i = (int)(Math.Pow(10, N - 1)); i <= (int)(Math.Pow(10, N));
i++) {
string istring = i.ToString();
while (istring.Length < X.Length) {
istring = "0" + istring;
}
bool go = true;
for (int last = 0; last < X.Length; last++) {
string Xst = X[last].ToString();
string ist = istring[last].ToString();
if (Xst == "X") {
} else {
if (Xst != ist) {
go = false;
break;
}
}
}
if (go) {
Console.WriteLine(i);
return;
}
}
} else {
if (X == "X")
Console.WriteLine(0);
else
Console.WriteLine(X);
}
}
}
|
[["+", 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, 20], ["+", 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, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 75, 196, 0, 57, 15, 16, 12, 5, 0, 62], ["+", 75, 196, 0, 57, 15, 16, 12, 5, 0, 222], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 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], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 75, 1, 0, 35]]
| 8
| 4,700
| 36
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace CSharpSample01 {
class Program {
static void Main(string[] args) {
var inputNum = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var N = inputNum[0];
var M = inputNum[1];
var dicInput = new Dictionary<int, List<int>>();
for (int i = 0; i < M; i++) {
var inputRule = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
if (dicInput.ContainsKey(inputRule[0])) {
dicInput[inputRule[0]].Add(inputRule[1]);
} else {
dicInput[inputRule[0]] = new List<int> { inputRule[1] };
}
}
var flag = true;
if (dicInput.ContainsKey(1)) {
if (dicInput[1].Any(x => x == 0)) {
flag = false;
}
}
if (flag) {
for (int i = 1; i <= N; i++) {
if (dicInput.ContainsKey(i)) {
if (dicInput[i].Distinct().Count() > 1) {
flag = false;
break;
}
}
}
}
var answer = "";
// 出力
if (flag) {
if (dicInput.ContainsKey(1)) {
answer += dicInput[1].First();
} else {
answer += "1";
}
if (N > 1) {
if (dicInput.ContainsKey(2)) {
answer += dicInput[2].First();
} else {
answer += "0";
}
}
if (N > 2) {
if (dicInput.ContainsKey(3)) {
answer += dicInput[3].First();
} else {
answer += "0";
}
}
Console.WriteLine(answer);
} else {
if (N == 1) {
if (dicInput.ContainsKey(1)) {
if (dicInput[1].Distinct().Count() == 1 && dicInput[1].First() == 0) {
Console.WriteLine(0);
} else {
Console.WriteLine(-1);
}
} else {
Console.WriteLine(-1);
}
} else {
Console.WriteLine(-1);
}
}
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace CSharpSample01 {
class Program {
static void Main(string[] args) {
var inputNum = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var N = inputNum[0];
var M = inputNum[1];
var dicInput = new Dictionary<int, List<int>>();
for (int i = 0; i < M; i++) {
var inputRule = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
if (dicInput.ContainsKey(inputRule[0])) {
dicInput[inputRule[0]].Add(inputRule[1]);
} else {
dicInput[inputRule[0]] = new List<int> { inputRule[1] };
}
}
var flag = true;
if (dicInput.ContainsKey(1)) {
if (dicInput[1].Any(x => x == 0)) {
flag = false;
}
}
if (flag) {
for (int i = 1; i <= N; i++) {
if (dicInput.ContainsKey(i)) {
if (dicInput[i].Distinct().Count() > 1) {
flag = false;
break;
}
}
}
}
var answer = "";
// 出力
if (flag) {
if (dicInput.ContainsKey(1)) {
answer += dicInput[1].First();
} else {
if (N == 1 && M == 0) {
answer = "0";
} else {
answer += "1";
}
}
if (N > 1) {
if (dicInput.ContainsKey(2)) {
answer += dicInput[2].First();
} else {
answer += "0";
}
}
if (N > 2) {
if (dicInput.ContainsKey(3)) {
answer += dicInput[3].First();
} else {
answer += "0";
}
}
Console.WriteLine(answer);
} else {
if (N == 1) {
if (dicInput.ContainsKey(1)) {
if (dicInput[1].Distinct().Count() == 1 && dicInput[1].First() == 0) {
Console.WriteLine(0);
} else {
Console.WriteLine(-1);
}
} else {
Console.WriteLine(-1);
}
} else {
Console.WriteLine(-1);
}
}
}
}
}
|
[["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 98], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 62], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 511
| 21
|
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() { hoge(); }
public static void hoge() {
var line = System.Console.ReadLine().Split(' ');
var n = int.Parse(line[0]);
var m = int.Parse(line[1]);
int[] num = { 0, 0, 0 };
Dictionary<int, int> deta = new Dictionary<int, int>();
if (n == 1) {
num[0] = 1;
for (int i = 0; i < m; i++) {
line = System.Console.ReadLine().Split(' ');
var s = int.Parse(line[0]);
var c = int.Parse(line[1]);
if (deta.ContainsKey(s) && deta[s] != c) {
for (int j = i + 1; j < m; j++) {
System.Console.ReadLine();
}
System.Console.WriteLine("-1");
return;
}
if (deta.ContainsKey(s) && deta[s] == c) {
continue;
}
if (s == 1) {
num[0] = c;
}
deta.Add(s, c);
}
if (num[0] == 0) {
num[0] = -1;
}
System.Console.WriteLine(num[0]);
return;
}
if (n == 2) {
num[1] = 1;
for (int i = 0; i < m; i++) {
line = System.Console.ReadLine().Split(' ');
var s = int.Parse(line[0]);
var c = int.Parse(line[1]);
if (deta.ContainsKey(s) && deta[s] != c) {
for (int j = i + 1; j < m; j++) {
System.Console.ReadLine();
}
System.Console.WriteLine("-1");
return;
}
if (deta.ContainsKey(s) && deta[s] == c) {
continue;
}
if (s == 1) {
num[1] = c;
} else {
num[0] = c;
}
deta.Add(s, c);
}
if (num[1] == 0) {
System.Console.WriteLine("-1");
return;
}
System.Console.WriteLine("" + num[1] + num[0]);
return;
}
if (n == 3) {
num[2] = 1;
for (int i = 0; i < m; i++) {
line = System.Console.ReadLine().Split(' ');
var s = int.Parse(line[0]);
var c = int.Parse(line[1]);
if (deta.ContainsKey(s) && deta[s] != c) {
for (int j = i + 1; j < m; j++) {
System.Console.ReadLine();
}
System.Console.WriteLine("-1");
return;
}
if (deta.ContainsKey(s) && deta[s] == c) {
continue;
}
if (s == 1) {
num[2] = c;
} else if (s == 2) {
num[1] = c;
} else {
num[0] = c;
}
deta.Add(s, c);
}
if (num[2] == 0) {
System.Console.WriteLine("-1");
return;
}
System.Console.WriteLine("" + num[2] + num[1] + num[0]);
return;
}
}
}
|
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() { hoge(); }
public static void hoge() {
var line = System.Console.ReadLine().Split(' ');
var n = int.Parse(line[0]);
var m = int.Parse(line[1]);
int[] num = { 0, 0, 0 };
Dictionary<int, int> deta = new Dictionary<int, int>();
if (n == 1) {
num[0] = 0;
for (int i = 0; i < m; i++) {
line = System.Console.ReadLine().Split(' ');
var s = int.Parse(line[0]);
var c = int.Parse(line[1]);
if (deta.ContainsKey(s) && deta[s] != c) {
for (int j = i + 1; j < m; j++) {
System.Console.ReadLine();
}
System.Console.WriteLine("-1");
return;
}
if (deta.ContainsKey(s) && deta[s] == c) {
continue;
}
if (s == 1) {
num[0] = c;
}
deta.Add(s, c);
}
System.Console.WriteLine(num[0]);
return;
}
if (n == 2) {
num[1] = 1;
for (int i = 0; i < m; i++) {
line = System.Console.ReadLine().Split(' ');
var s = int.Parse(line[0]);
var c = int.Parse(line[1]);
if (deta.ContainsKey(s) && deta[s] != c) {
for (int j = i + 1; j < m; j++) {
System.Console.ReadLine();
}
System.Console.WriteLine("-1");
return;
}
if (deta.ContainsKey(s) && deta[s] == c) {
continue;
}
if (s == 1) {
num[1] = c;
} else {
num[0] = c;
}
deta.Add(s, c);
}
if (num[1] == 0) {
System.Console.WriteLine("-1");
return;
}
System.Console.WriteLine("" + num[1] + num[0]);
return;
}
if (n == 3) {
num[2] = 1;
for (int i = 0; i < m; i++) {
line = System.Console.ReadLine().Split(' ');
var s = int.Parse(line[0]);
var c = int.Parse(line[1]);
if (deta.ContainsKey(s) && deta[s] != c) {
for (int j = i + 1; j < m; j++) {
System.Console.ReadLine();
}
System.Console.WriteLine("-1");
return;
}
if (deta.ContainsKey(s) && deta[s] == c) {
continue;
}
if (s == 1) {
num[2] = c;
} else if (s == 2) {
num[1] = c;
} else {
num[0] = c;
}
deta.Add(s, c);
}
if (num[2] == 0) {
System.Console.WriteLine("-1");
return;
}
System.Console.WriteLine("" + num[2] + num[1] + num[0]);
return;
}
}
}
|
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 64, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 64, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["-", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203]]
| 8
| 803
| 21
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
int n = nm[0];
int m = nm[1];
int[] s = new int[m];
int[] c = new int[m];
for (int i = 0; i < m; i++) {
int[] tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
s[i] = tmp[0];
c[i] = tmp[1];
}
// ダメなパターン
// 一桁目0
for (int i = 0; i < m; i++) {
if (s[i] == 1 && c[i] == 0 && n != 1) {
Console.WriteLine("-1");
return;
}
}
// 同じ桁で異なる条件
for (int i = 0; i < m; i++) {
for (int k = 0; k < m; k++) {
if (s[i] == s[k] && c[i] != c[k]) {
Console.WriteLine("-1");
return;
}
}
}
// OKパターン
StringBuilder ans = new StringBuilder("");
for (int i = 0; i < n; i++) {
ans.Append("0");
}
for (int i = 0; i < m; i++) {
ans.Replace("0", c[i].ToString(), s[i] - 1, 1);
}
// all 0の場合
int all0 = 0;
for (int i = 0; i < n; i++) {
if (ans[i] != '0') {
all0 = 1;
}
}
if (all0 == 0) {
Console.WriteLine("0");
return;
}
//一桁目が0なら1に置き換える
if (ans[0] == '0') {
ans.Replace("0", "1", 0, 1);
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
int n = nm[0];
int m = nm[1];
int[] s = new int[m];
int[] c = new int[m];
for (int i = 0; i < m; i++) {
int[] tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
s[i] = tmp[0];
c[i] = tmp[1];
}
// ダメなパターン
// 一桁目0
for (int i = 0; i < m; i++) {
if (s[i] == 1 && c[i] == 0 && n != 1) {
Console.WriteLine("-1");
return;
}
}
// 同じ桁で異なる条件
for (int i = 0; i < m; i++) {
for (int k = 0; k < m; k++) {
if (s[i] == s[k] && c[i] != c[k]) {
Console.WriteLine("-1");
return;
}
}
}
// OKパターン
StringBuilder ans = new StringBuilder("");
for (int i = 0; i < n; i++) {
ans.Append("0");
}
for (int i = 0; i < m; i++) {
ans.Replace("0", c[i].ToString(), s[i] - 1, 1);
}
// all 0の場合
if (n == 1 && ans[0] == '0') {
Console.WriteLine("0");
return;
}
//一桁目が0なら1に置き換える
if (ans[0] == '0') {
ans.Replace("0", "1", 0, 1);
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 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], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 461
| 41
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1 {
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
public class Class1 {
static Dictionary<Tuple<long, long>, long> dic =
new Dictionary<Tuple<long, long>, long>();
static long mod = 1000000007;
static long[] factorial = new long[1000001];
static long[] invFactorial = new long[1000001];
private static void calcFanctorial(long N) {
factorial[0] = 1;
for (int i = 1; i < N + 1; i++) {
factorial[i] = factorial[i - 1] * i;
factorial[i] %= mod;
}
invFactorial[N] = inv(factorial[N]);
for (int i = (int)N; i > 0; i--) {
invFactorial[i - 1] = invFactorial[i] * i % mod;
}
}
static void Main(string[] args) {
var NN = ReadLongArr();
long N = NN[0];
long M = NN[1];
var MM = new long [M][];
if (M > 0) {
for (int i = 0; i < M; i++) {
MM[i] = ReadLongArr();
if (MM[i][0] == 1 && MM[i][1] == 0 && N > 1) {
Console.WriteLine(-1);
return;
}
}
} else {
if (N == 1) {
Console.WriteLine(0);
} else {
Console.WriteLine((long)Math.Pow(10, N - 1));
}
return;
}
var res = -1;
for (int i = 0; i < 1000; i++) {
if (i == 0 || (i < Math.Pow(10, N) && i > Math.Pow(10, N - 1))) {
bool b = true;
for (int j = 0; j < M; j++) {
long x = (long)(i / Math.Pow(10, N - MM[j][0]));
x = x % 10;
if (x != MM[j][1]) {
b = false;
break;
}
}
if (b) {
res = i;
break;
}
}
}
Console.WriteLine(res);
}
static long bin(long a, long x, long n) {
long y = a;
long res = 1;
while (x > 0) {
if (x % 2 == 1) {
res = res * y % n;
}
x /= 2;
y = y * y % n;
}
return res;
}
int cmp(string a, string b) {
for (var i = 0; i < Math.Min(a.Length, b.Length); i++)
if (a[i] < b[i])
return -1;
else if (a[i] > b[i])
return 1;
if (a.Length == b.Length)
return 0;
if (a.Length > b.Length)
return 1;
else
return -1;
}
private static long nCm(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod;
}
private static long nCm2(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
long res = 1;
for (long i = n; i > n - m; i--) {
res *= i;
res %= mod;
}
return res * invFactorial[m] % mod;
}
public static long pow(long a, long b, long mod) {
a %= mod;
if (b <= 0)
return 1;
var t = pow(a, b / 2, mod);
if ((b & 1) == 0)
return t * t % mod;
return t * t % mod * a % mod;
}
public static long Lcm(long a, long b) {
return a * b % mod * inv(Gcd(a, b)) % mod;
}
public static long Lcm(long[] a) {
List<long> vect = new List<long>();
long lcm = 1;
for (int i = 0; i < a.Count(); i++) {
var factor = a[i] / GcdVector(vect, a[i]);
vect.Add(factor);
lcm = lcm * factor % mod;
}
return lcm;
}
static long GcdVector(List<long> a, long b) {
long ma = 1;
for (int i = 0; i < a.Count; i++)
ma = ma * a[i] % b;
return Gcd(b, ma);
}
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public static long pow(long a, long b) => pow(a, b, mod);
public static long inv(long a) => pow(a, mod - 2);
private static char[][] ReadCharMatrix(long h) {
char[][] mtx = new char [h][];
for (int i = 0; i < h; i++) {
var s = ReadString();
mtx[i] = s.ToCharArray();
}
return mtx;
}
private static int[][] CreateIntMatrix(long h, long w) {
int[][] mtx = new int [h][];
for (int i = 0; i < h; i++) {
mtx[i] = new int[w];
}
return mtx;
}
private static string ReadString() { return Console.ReadLine(); }
private static string[] ReadStringArr() {
return Console.ReadLine().Split(' ');
}
private static long ReadLong() { return long.Parse(Console.ReadLine()); }
private static long[] ReadLongArr() {
string[] s = ReadStringArr();
long[] l = new long[s.Length];
for (int i = 0; i < l.Length; i++) {
l[i] = long.Parse(s[i]);
}
return l;
}
}
class StringComparator2 : IComparer<string> {
int IComparer<string>.Compare(string a, string b) {
int length = Math.Min(a.Length, b.Length);
// Console.WriteLine("Comparing with length {0}", length);
for (int i = 0; i < length; i++) {
if (a[i] < b[i]) {
// Console.WriteLine("returning -1");
return -1;
} else if (a[i] > b[i])
return 1;
}
if (a.Length < b.Length)
return -1;
if (a.Length > b.Length)
return 1;
// Console.WriteLine("Why are we at the end?");
return 0;
}
}
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;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
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);
}
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() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1 {
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
public class Class1 {
static Dictionary<Tuple<long, long>, long> dic =
new Dictionary<Tuple<long, long>, long>();
static long mod = 1000000007;
static long[] factorial = new long[1000001];
static long[] invFactorial = new long[1000001];
private static void calcFanctorial(long N) {
factorial[0] = 1;
for (int i = 1; i < N + 1; i++) {
factorial[i] = factorial[i - 1] * i;
factorial[i] %= mod;
}
invFactorial[N] = inv(factorial[N]);
for (int i = (int)N; i > 0; i--) {
invFactorial[i - 1] = invFactorial[i] * i % mod;
}
}
static void Main(string[] args) {
var NN = ReadLongArr();
long N = NN[0];
long M = NN[1];
var MM = new long [M][];
if (M > 0) {
for (int i = 0; i < M; i++) {
MM[i] = ReadLongArr();
if (MM[i][0] == 1 && MM[i][1] == 0 && N > 1) {
Console.WriteLine(-1);
return;
}
}
} else {
if (N == 1) {
Console.WriteLine(0);
} else {
Console.WriteLine((long)Math.Pow(10, N - 1));
}
return;
}
var res = -1;
for (int i = 0; i < 1000; i++) {
if ((N == 1 && i == 0) ||
(i < Math.Pow(10, N) && i >= Math.Pow(10, N - 1))) {
bool b = true;
for (int j = 0; j < M; j++) {
long x = (long)(i / Math.Pow(10, N - MM[j][0]));
x = x % 10;
if (x != MM[j][1]) {
b = false;
break;
}
}
if (b) {
res = i;
break;
}
}
}
Console.WriteLine(res);
}
static long bin(long a, long x, long n) {
long y = a;
long res = 1;
while (x > 0) {
if (x % 2 == 1) {
res = res * y % n;
}
x /= 2;
y = y * y % n;
}
return res;
}
int cmp(string a, string b) {
for (var i = 0; i < Math.Min(a.Length, b.Length); i++)
if (a[i] < b[i])
return -1;
else if (a[i] > b[i])
return 1;
if (a.Length == b.Length)
return 0;
if (a.Length > b.Length)
return 1;
else
return -1;
}
private static long nCm(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod;
}
private static long nCm2(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
long res = 1;
for (long i = n; i > n - m; i--) {
res *= i;
res %= mod;
}
return res * invFactorial[m] % mod;
}
public static long pow(long a, long b, long mod) {
a %= mod;
if (b <= 0)
return 1;
var t = pow(a, b / 2, mod);
if ((b & 1) == 0)
return t * t % mod;
return t * t % mod * a % mod;
}
public static long Lcm(long a, long b) {
return a * b % mod * inv(Gcd(a, b)) % mod;
}
public static long Lcm(long[] a) {
List<long> vect = new List<long>();
long lcm = 1;
for (int i = 0; i < a.Count(); i++) {
var factor = a[i] / GcdVector(vect, a[i]);
vect.Add(factor);
lcm = lcm * factor % mod;
}
return lcm;
}
static long GcdVector(List<long> a, long b) {
long ma = 1;
for (int i = 0; i < a.Count; i++)
ma = ma * a[i] % b;
return Gcd(b, ma);
}
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public static long pow(long a, long b) => pow(a, b, mod);
public static long inv(long a) => pow(a, mod - 2);
private static char[][] ReadCharMatrix(long h) {
char[][] mtx = new char [h][];
for (int i = 0; i < h; i++) {
var s = ReadString();
mtx[i] = s.ToCharArray();
}
return mtx;
}
private static int[][] CreateIntMatrix(long h, long w) {
int[][] mtx = new int [h][];
for (int i = 0; i < h; i++) {
mtx[i] = new int[w];
}
return mtx;
}
private static string ReadString() { return Console.ReadLine(); }
private static string[] ReadStringArr() {
return Console.ReadLine().Split(' ');
}
private static long ReadLong() { return long.Parse(Console.ReadLine()); }
private static long[] ReadLongArr() {
string[] s = ReadStringArr();
long[] l = new long[s.Length];
for (int i = 0; i < l.Length; i++) {
l[i] = long.Parse(s[i]);
}
return l;
}
}
class StringComparator2 : IComparer<string> {
int IComparer<string>.Compare(string a, string b) {
int length = Math.Min(a.Length, b.Length);
// Console.WriteLine("Comparing with length {0}", length);
for (int i = 0; i < length; i++) {
if (a[i] < b[i]) {
// Console.WriteLine("returning -1");
return -1;
} else if (a[i] > b[i])
return 1;
}
if (a.Length < b.Length)
return -1;
if (a.Length > b.Length)
return 1;
// Console.WriteLine("Why are we at the end?");
return 0;
}
}
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;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
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);
}
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() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 17, 60], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 17, 47], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 20]]
| 8
| 2,091
| 8
|
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 M = cin.ReadInt;
var Num = new string[N];
for (var i = 0; i < N; i++) {
Num[i] = "0";
}
var ans = "";
var Selected = new int[N];
for (var i = 0; i < M; i++) {
var s = cin.ReadInt;
var c = cin.ReadInt;
if (s == 1 && c == 0) {
ans = "-1";
break;
}
if (Selected[s - 1] == 1 && Num[s - 1].Equals(c.ToString()) == false) {
ans = "-1";
break;
}
Selected[s - 1] = 1;
Num[s - 1] = c.ToString();
}
if (!ans.Equals("-1")) {
ans = "";
if (Num[0].Equals("0"))
ans = "1";
else
ans = Num[0];
for (var i = 1; i < N; i++) {
ans += Num[i];
}
}
WriteLine(ans);
}
}
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 M = cin.ReadInt;
var Num = new string[N];
for (var i = 0; i < N; i++) {
Num[i] = "0";
}
var ans = "";
var Selected = new int[N];
for (var i = 0; i < M; i++) {
var s = cin.ReadInt;
var c = cin.ReadInt;
if (N != 1 && s == 1 && c == 0) {
ans = "-1";
break;
}
if (Selected[s - 1] == 1 && Num[s - 1].Equals(c.ToString()) == false) {
ans = "-1";
break;
}
Selected[s - 1] = 1;
Num[s - 1] = c.ToString();
}
if (!ans.Equals("-1")) {
ans = "";
if (N != 1 && Num[0].Equals("0"))
ans = "1";
else
ans = Num[0];
for (var i = 1; i < N; i++) {
ans += Num[i];
}
}
WriteLine(ans);
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; i++)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 79], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98]]
| 8
| 673
| 8
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
// 整数の入力
// int a = int.Parse(Console.ReadLine());
// スペース区切りの整数の入力
string[] NM = Console.ReadLine().Split(' ');
int N = int.Parse(NM[0]);
int M = int.Parse(NM[1]);
List<int> bingo = new List<int>() { -1, -1, -1 };
for (int i = 0; i < M; i++) {
// 条件を満たすかチェックする
string[] sc = Console.ReadLine().Split(' ');
int s = int.Parse(sc[0]);
int c = int.Parse(sc[1]);
int a = s - 1 + (3 - N);
if (a < 0 || a > 2 || (bingo[a] != -1 && bingo[a] != c)) {
Console.WriteLine("-1");
return;
} else {
bingo[a] = c;
}
}
// Console.WriteLine("aaa " + bingo[0] + ";" + bingo[1] + "; " + bingo[2]);
// 条件を満たす整数を求める
if (N == 1) {
if (bingo[0] > 0 || bingo[1] > 0) {
Console.WriteLine("-1");
} else {
Console.WriteLine(bingo[2]);
}
} else if (N == 2) {
if (bingo[0] > 0 || bingo[1] == 0) {
Console.WriteLine("-1");
} else {
if (bingo[1] == -1)
bingo[1] = 1;
if (bingo[2] == -1)
bingo[2] = 0;
Console.WriteLine(bingo[1].ToString() + bingo[2].ToString());
}
} else if (N == 3) {
if (bingo[0] == 0) {
Console.WriteLine("-1");
} else {
if (bingo[0] == -1)
bingo[0] = 1;
if (bingo[1] == -1)
bingo[1] = 0;
if (bingo[2] == -1)
bingo[2] = 0;
Console.WriteLine(bingo[0].ToString() + bingo[1].ToString() +
bingo[2].ToString());
}
}
// 文字列の入力
// string s = Console.ReadLine();
//出力
// Console.WriteLine((a+b+c) + " " + s);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
// 整数の入力
// int a = int.Parse(Console.ReadLine());
// スペース区切りの整数の入力
string[] NM = Console.ReadLine().Split(' ');
int N = int.Parse(NM[0]);
int M = int.Parse(NM[1]);
List<int> bingo = new List<int>() { -1, -1, -1 };
for (int i = 0; i < M; i++) {
// 条件を満たすかチェックする
string[] sc = Console.ReadLine().Split(' ');
int s = int.Parse(sc[0]);
int c = int.Parse(sc[1]);
int a = s - 1 + (3 - N);
if (a < 0 || a > 2 || (bingo[a] != -1 && bingo[a] != c)) {
Console.WriteLine("-1");
return;
} else {
bingo[a] = c;
}
}
// Console.WriteLine("aaa " + bingo[0] + ";" + bingo[1] + "; " + bingo[2]);
// 条件を満たす整数を求める
if (N == 1) {
if (bingo[0] > 0 || bingo[1] > 0) {
Console.WriteLine("-1");
} else {
if (bingo[2] == -1)
bingo[2] = 0;
Console.WriteLine(bingo[2]);
}
} else if (N == 2) {
if (bingo[0] > 0 || bingo[1] == 0) {
Console.WriteLine("-1");
} else {
if (bingo[1] == -1)
bingo[1] = 1;
if (bingo[2] == -1)
bingo[2] = 0;
Console.WriteLine(bingo[1].ToString() + bingo[2].ToString());
}
} else if (N == 3) {
if (bingo[0] == 0) {
Console.WriteLine("-1");
} else {
if (bingo[0] == -1)
bingo[0] = 1;
if (bingo[1] == -1)
bingo[1] = 0;
if (bingo[2] == -1)
bingo[2] = 0;
Console.WriteLine(bingo[0].ToString() + bingo[1].ToString() +
bingo[2].ToString());
}
}
// 文字列の入力
// string s = Console.ReadLine();
//出力
// Console.WriteLine((a+b+c) + " " + s);
}
}
|
[["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 75, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 75, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 75, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 11, 31, 204, 205, 22], ["+", 64, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 64, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 485
| 17
|
using System;
using System.Linq;
namespace CSharp {
class Program {
static void Main() {
var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
var N = input[0];
var M = input[1];
var s = new int [M][];
for (int i = 0; i < M; i++) {
s[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
}
for (int i = 0; i < M; i++) {
if (N > 1 && s[i][0] == 1 && s[i][1] == 0) {
Console.WriteLine("-1");
return;
}
for (int j = 0; j < M; j++) {
if (s[i][0] == s[j][0] && s[i][1] != s[j][1]) {
Console.WriteLine("-1");
return;
}
}
}
var c = new char[N];
for (int i = 0; i < N; i++) {
c[i] = '0';
}
for (int i = 0; i < M; i++) {
c[s[i][0] - 1] = char.Parse(s[i][1].ToString());
}
Console.WriteLine(int.Parse(string.Join(string.Empty, c)));
}
}
}
|
using System;
using System.Linq;
namespace CSharp {
class Program {
static void Main() {
var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
var N = input[0];
var M = input[1];
var s = new int [M][];
for (int i = 0; i < M; i++) {
s[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
}
for (int i = 0; i < M; i++) {
if (N > 1 && s[i][0] == 1 && s[i][1] == 0) {
Console.WriteLine("-1");
return;
}
for (int j = 0; j < M; j++) {
if (s[i][0] == s[j][0] && s[i][1] != s[j][1]) {
Console.WriteLine("-1");
return;
}
}
}
var c = new char[N];
for (int i = 0; i < N; i++) {
c[i] = '0';
}
for (int i = 0; i < M; i++) {
c[s[i][0] - 1] = char.Parse(s[i][1].ToString());
}
if (N > 1 && c[0] == '0') {
c[0] = '1';
}
Console.WriteLine(int.Parse(string.Join(string.Empty, c)));
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 104], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 253], ["+", 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, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 252, 0, 104], ["+", 64, 196, 0, 1, 0, 11, 12, 252, 0, 253], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 335
| 26
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var sol = new Solve();
sol.Exec();
}
}
class Solve {
public void Exec() {
var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = l[0], M = l[1];
var dict = new Dictionary<int, int>();
for (var i = 0; i < M; i++) {
var t = Console.ReadLine().Split().Select(int.Parse).ToArray();
if (t[0] == 1 && t[1] == 0) {
if (N != 1) {
Console.WriteLine(-1);
return;
}
}
if (dict.ContainsKey(t[0])) {
if (dict[t[0]] != t[1]) {
Console.WriteLine(-1);
return;
}
} else
dict[t[0]] = t[1];
}
var one = dict.ContainsKey(1) ? dict[1] : 1;
var two = dict.ContainsKey(2) ? dict[2] : 0;
var three = dict.ContainsKey(3) ? dict[3] : 0;
var ans = one.ToString();
if (N >= 2)
ans += two.ToString();
if (N >= 3)
ans += three.ToString();
Console.WriteLine(ans);
}
}
public class Util {}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var sol = new Solve();
sol.Exec();
}
}
class Solve {
public void Exec() {
var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = l[0], M = l[1];
var dict = new Dictionary<int, int>();
if (N == 1 && M == 0) {
Console.WriteLine(0);
return;
}
for (var i = 0; i < M; i++) {
var t = Console.ReadLine().Split().Select(int.Parse).ToArray();
if (t[0] == 1 && t[1] == 0) {
if (N != 1) {
Console.WriteLine(-1);
return;
}
}
if (dict.ContainsKey(t[0])) {
if (dict[t[0]] != t[1]) {
Console.WriteLine(-1);
return;
}
} else
dict[t[0]] = t[1];
}
var one = dict.ContainsKey(1) ? dict[1] : 1;
var two = dict.ContainsKey(2) ? dict[2] : 0;
var three = dict.ContainsKey(3) ? dict[3] : 0;
var ans = one.ToString();
if (N >= 2)
ans += two.ToString();
if (N >= 3)
ans += three.ToString();
Console.WriteLine(ans);
}
}
public class Util {}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 338
| 21
|
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 NM = ReadInts();
var list = new List<string>();
int ii = 0;
switch (NM[0]) {
case 1:
ii = 1;
break;
case 2:
ii = 10;
break;
case 3:
ii = 100;
break;
}
for (int i = 0; i < NM[1]; i++) {
var sc = Read();
list.Add(sc);
}
for (int i = ii; i < 1000; i++) {
var b = true;
for (int j = 0; j < list.Count; j++) {
var a = list[j].Split(' ');
var s = int.Parse(a[0]);
var c = int.Parse(a[1]);
var istr = i.ToString();
try {
if (istr[s - 1] != c.ToString()[0]) {
b = false;
}
} catch (Exception) {
b = false;
}
}
if (b) {
if (i == 0) {
WriteLine(-1);
return;
}
WriteLine(i);
return;
}
}
WriteLine(-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 NM = ReadInts();
var list = new List<string>();
int ii = 0;
switch (NM[0]) {
case 1:
ii = 0;
break;
case 2:
ii = 10;
break;
case 3:
ii = 100;
break;
}
for (int i = 0; i < NM[1]; i++) {
var sc = Read();
list.Add(sc);
}
for (int i = ii; i < 1000; i++) {
var b = true;
for (int j = 0; j < list.Count; j++) {
var a = list[j].Split(' ');
var s = int.Parse(a[0]);
var c = int.Parse(a[1]);
var istr = i.ToString();
try {
if (istr[s - 1] != c.ToString()[0]) {
b = false;
}
} catch (Exception) {
b = false;
}
}
if (b) {
// if (i == 0)
//{
// WriteLine(-1);
// return;
//}
WriteLine(i);
return;
}
}
WriteLine(-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, 254, 0, 239, 0, 1, 0, 11, 12, 203], ["+", 8, 254, 0, 239, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["-", 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], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 64, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 64, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 481
| 18
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
internal static class CR {
public static string GetText() { return Console.ReadLine(); }
public static List<string> GetTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long GetLong() { return long.Parse(Console.ReadLine()); }
public static List<long> GetLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
}
namespace AtCoder.C {
public class Program {
public static long N { get; private set; }
public static long M { get; private set; }
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var inputs = CR.GetLongs();
N = inputs[0];
M = inputs[1];
var sc = new List<SC>();
for (int i = 0; i < M; i++) {
inputs = CR.GetLongs();
sc.Add(new SC {
S = inputs[0],
C = inputs[1],
});
}
// 最大桁数が0ならNG
if (N != 1 // 1桁のときは最大桁が0でもよい
&& sc.Any(x => x.S == 1 && x.C == 0))
return "-1";
// 制約が破綻しているならNG
foreach (var item in sc) {
if (sc.Any(x => x.S == item.S && x.C != item.C))
return "-1";
}
var result = "";
for (int i = 1; i <= N; i++) {
var v = sc.FirstOrDefault(x => x.S == i);
if (v != null) {
result += v.C;
} else {
result += i == 1 ? 1 : 0;
}
}
return result;
}
}
internal class SC {
public long S { get; internal set; }
public long C { get; internal set; }
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
internal static class CR {
public static string GetText() { return Console.ReadLine(); }
public static List<string> GetTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long GetLong() { return long.Parse(Console.ReadLine()); }
public static List<long> GetLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
}
namespace AtCoder.C {
public class Program {
public static long N { get; private set; }
public static long M { get; private set; }
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var inputs = CR.GetLongs();
N = inputs[0];
M = inputs[1];
var sc = new List<SC>();
for (int i = 0; i < M; i++) {
inputs = CR.GetLongs();
sc.Add(new SC {
S = inputs[0],
C = inputs[1],
});
}
// 最大桁数が0ならNG
if (N != 1 // 1桁のときは最大桁が0でもよい
&& sc.Any(x => x.S == 1 && x.C == 0))
return "-1";
// 制約が破綻しているならNG
foreach (var item in sc) {
if (sc.Any(x => x.S == item.S && x.C != item.C))
return "-1";
}
// 1つも制約がなかった場合
if (M == 0) {
if (N == 1)
return 0;
if (N == 2)
return 10;
if (N == 3)
return 100;
}
var result = "";
for (int i = 1; i <= N; i++) {
var v = sc.FirstOrDefault(x => x.S == i);
if (v != null) {
result += v.C;
} else {
result += i == 1 ? 1 : 0;
}
}
return result;
}
}
internal class SC {
public long S { get; internal set; }
public long C { get; internal set; }
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 57, 64, 196, 0, 57, 64, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 448
| 35
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
int[] tmpArr = Console.ReadLine()
.Trim()
.Split(' ')
.Select(hogehoge => int.Parse(hogehoge))
.ToArray<int>();
int n = tmpArr[0];
int m = tmpArr[1];
int[] tmp = new int[n];
int[] ans = new int[n];
for (int i = 0; i < m; i++) {
int[] arr = Console.ReadLine()
.Trim()
.Split(' ')
.Select(hogehoge => int.Parse(hogehoge))
.ToArray<int>();
if (arr[0] == 1 && arr[1] == 0 && n != 1) {
Console.WriteLine(-1);
return;
}
if (tmp[arr[0] - 1] != -1) {
ans[arr[0] - 1] = arr[1];
tmp[arr[0] - 1] = -1;
} else {
if (ans[arr[0] - 1] == arr[1])
continue;
Console.WriteLine(-1);
return;
}
}
if (ans[0] == 0 && n != 1) {
Console.WriteLine(-1);
return;
}
for (int i = 0; i < n; i++) {
Console.Write(ans[i]);
}
return;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
int[] tmpArr = Console.ReadLine()
.Trim()
.Split(' ')
.Select(hogehoge => int.Parse(hogehoge))
.ToArray<int>();
int n = tmpArr[0];
int m = tmpArr[1];
int[] tmp = new int[n];
int[] ans = new int[n];
for (int i = 0; i < m; i++) {
int[] arr = Console.ReadLine()
.Trim()
.Split(' ')
.Select(hogehoge => int.Parse(hogehoge))
.ToArray<int>();
if (arr[0] == 1 && arr[1] == 0 && n != 1) {
Console.WriteLine(-1);
return;
}
if (tmp[arr[0] - 1] != -1) {
ans[arr[0] - 1] = arr[1];
tmp[arr[0] - 1] = -1;
} else {
if (ans[arr[0] - 1] == arr[1])
continue;
Console.WriteLine(-1);
return;
}
}
if (ans[0] == 0 && n != 1) {
ans[0] = 1;
}
for (int i = 0; i < n; i++) {
Console.Write(ans[i]);
}
return;
}
}
}
|
[["-", 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], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 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
| 332
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;
namespace AtCoder_1 {
class Program {
static void Main(string[] args) {
int[] nm = CinTAr();
int[] p = new int[nm[0]];
for (int i = 0; i < nm[0]; i++) {
p[i] = -1;
}
bool ok = true;
for (int i = 0; i < nm[1]; i++) {
int[] sc = CinTAr();
if (p[sc[0] - 1] == -1 || p[sc[0] - 1] == sc[1]) {
p[sc[0] - 1] = sc[1];
} else {
ok = false;
}
if (nm[0] > 1 && sc[0] == 1 && sc[1] == 0) {
ok = false;
}
if (!ok) {
break;
}
}
if (ok) {
string res = "";
for (int i = 0; i < nm[0]; i++) {
if (i == 0) {
if (nm[0] > 1) {
if (p[0] == -1) {
res += "1";
} else {
res += p[0] + "";
}
} else {
res = "0";
}
} else {
if (p[i] == -1) {
res += "0";
} else {
res += p[i] + "";
}
}
}
Cout(res);
} else {
Cout(-1);
}
Cin();
}
static Random Rand = new Random();
static string[] AlphabetTable =
new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z" };
static int GetDigits(long num) {
return (int)Math.Floor(Math.Log10(num)) + 1;
}
static int GetNumByDigit(long num, int digit) {
return (int)((num / ((int)Math.Pow(10, digit - 1))) % 10);
}
static int loop(int num, int max) {
if (num > max) {
return num % max;
} else if (num < 0) {
return max - (-num) % max;
} else {
return num;
}
}
static long GCD(long a, long b) {
if (a < b) {
swap(ref a, ref b);
}
if (a % b == 0) {
return b;
} else {
return GCD(b, a % b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
static void swap<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static readonly int MOD10_9_7 = (1000000000 + 7);
static bool IsInt(double d) { return (int)d == d; }
static string Cin() { return ReadLine(); }
static string[] CinAr() { return ReadLine().Split(' '); }
static int CinT() { return S2i(Cin()); }
static int[] CinTAr() {
return CinAr().Select((x, i) => { return S2i(x); }).ToArray();
}
static long CinL() { return S2L(Cin()); }
static long[] CinLAr() {
return CinAr().Select((x, i) => { return S2L(x); }).ToArray();
}
static double CinD() { return S2D(Cin()); }
static double[] CinDAr() {
return CinAr().Select((x, i) => { return S2D(x); }).ToArray();
}
static int S2i(string s) { return int.Parse(s); }
static long S2L(string s) { return long.Parse(s); }
static double S2D(string s) { return double.Parse(s); }
static void Cout(object s) { WriteLine(s); }
static long[] yakusuu(long n) {
if (n == 1) {
return new long[] { 1 };
}
List<long> res = new List<long>();
res.Add(1);
for (long i = 2; i <= n / 2 + 1; i++) {
if (n % i == 0) {
res.Add(i);
}
}
res.Add(n);
return res.ToArray();
}
static bool isPrime(long num) {
if (num == 1) {
return false;
}
for (long i = 2; i <= Math.Sqrt(num) + 1; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
static void CoutAr<Type>(IEnumerable<Type> types) {
WriteLine(string.Join(" ", types));
}
public static long nCr(int n, int r) {
// naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
return nPr(n, r) / Factorial(r);
}
public static long nPr(int n, int r) {
// naive: return Factorial(n) / Factorial(n - r);
return FactorialDivision(n, n - r);
}
private static long FactorialDivision(int topFactorial,
int divisorFactorial) {
long result = 1;
for (int i = topFactorial; i > divisorFactorial; i--)
result *= i;
return result;
}
private static long Factorial(int i) {
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}
}
public struct Pair<T> {
public T a;
public T b;
public T c;
public Pair(T _a, T _b) {
a = _a;
b = _b;
c = default(T);
}
public Pair(T _a, T _b, T _c) {
a = _a;
b = _b;
c = _c;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;
namespace AtCoder_1 {
class Program {
static void Main(string[] args) {
int[] nm = CinTAr();
int[] p = new int[nm[0]];
for (int i = 0; i < nm[0]; i++) {
p[i] = -1;
}
bool ok = true;
for (int i = 0; i < nm[1]; i++) {
int[] sc = CinTAr();
if (p[sc[0] - 1] == -1 || p[sc[0] - 1] == sc[1]) {
p[sc[0] - 1] = sc[1];
} else {
ok = false;
}
if (nm[0] > 1 && sc[0] == 1 && sc[1] == 0) {
ok = false;
}
if (!ok) {
break;
}
}
if (ok) {
string res = "";
for (int i = 0; i < nm[0]; i++) {
if (i == 0) {
if (nm[0] > 1) {
if (p[0] == -1) {
res += "1";
} else {
res += p[0] + "";
}
} else {
if (p[0] == -1) {
res += "0";
} else {
res += p[0] + "";
}
}
} else {
if (p[i] == -1) {
res += "0";
} else {
res += p[i] + "";
}
}
}
Cout(res);
} else {
Cout(-1);
}
Cin();
}
static Random Rand = new Random();
static string[] AlphabetTable =
new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z" };
static int GetDigits(long num) {
return (int)Math.Floor(Math.Log10(num)) + 1;
}
static int GetNumByDigit(long num, int digit) {
return (int)((num / ((int)Math.Pow(10, digit - 1))) % 10);
}
static int loop(int num, int max) {
if (num > max) {
return num % max;
} else if (num < 0) {
return max - (-num) % max;
} else {
return num;
}
}
static long GCD(long a, long b) {
if (a < b) {
swap(ref a, ref b);
}
if (a % b == 0) {
return b;
} else {
return GCD(b, a % b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
static void swap<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static readonly int MOD10_9_7 = (1000000000 + 7);
static bool IsInt(double d) { return (int)d == d; }
static string Cin() { return ReadLine(); }
static string[] CinAr() { return ReadLine().Split(' '); }
static int CinT() { return S2i(Cin()); }
static int[] CinTAr() {
return CinAr().Select((x, i) => { return S2i(x); }).ToArray();
}
static long CinL() { return S2L(Cin()); }
static long[] CinLAr() {
return CinAr().Select((x, i) => { return S2L(x); }).ToArray();
}
static double CinD() { return S2D(Cin()); }
static double[] CinDAr() {
return CinAr().Select((x, i) => { return S2D(x); }).ToArray();
}
static int S2i(string s) { return int.Parse(s); }
static long S2L(string s) { return long.Parse(s); }
static double S2D(string s) { return double.Parse(s); }
static void Cout(object s) { WriteLine(s); }
static long[] yakusuu(long n) {
if (n == 1) {
return new long[] { 1 };
}
List<long> res = new List<long>();
res.Add(1);
for (long i = 2; i <= n / 2 + 1; i++) {
if (n % i == 0) {
res.Add(i);
}
}
res.Add(n);
return res.ToArray();
}
static bool isPrime(long num) {
if (num == 1) {
return false;
}
for (long i = 2; i <= Math.Sqrt(num) + 1; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
static void CoutAr<Type>(IEnumerable<Type> types) {
WriteLine(string.Join(" ", types));
}
public static long nCr(int n, int r) {
// naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
return nPr(n, r) / Factorial(r);
}
public static long nPr(int n, int r) {
// naive: return Factorial(n) / Factorial(n - r);
return FactorialDivision(n, n - r);
}
private static long FactorialDivision(int topFactorial,
int divisorFactorial) {
long result = 1;
for (int i = topFactorial; i > divisorFactorial; i--)
result *= i;
return result;
}
private static long Factorial(int i) {
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}
}
public struct Pair<T> {
public T a;
public T b;
public T c;
public Pair(T _a, T _b) {
a = _a;
b = _b;
c = default(T);
}
public Pair(T _a, T _b, T _c) {
a = _a;
b = _b;
c = _c;
}
}
}
|
[["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 75, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 75, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 75, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 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, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 12, 5, 0, 62], ["+", 75, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 1,385
| 27
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace C {
internal static class Program {
private static void Main(string[] args) {
var n = Cint();
var m = Cint();
var s = new int[m];
var c = new int[m];
Loop(m, i => {
s[i] = Cint();
c[i] = Cint();
});
var num = new string('0', n).ToCharArray();
var written = new List<Tuple<int, int>>();
Loop(m, i => {
if (written.Any(w => w.Item1 == s[i] && w.Item2 != c[i]) ||
s[i] == 1 && c[i] == 0) {
Cout(-1);
Environment.Exit(0);
}
num[s[i] - 1] = c[i].ToString().First();
written.Add(new Tuple<int, int>(s[i], c[i]));
});
if (num[0] == '0') {
num[0] = '1';
}
Cout(int.Parse(new string(num)));
}
#region Input and Output
private static readonly List<string> Buffer = new List<string>();
private static string Cin() {
ReadBuffer();
var str = Buffer.First();
Buffer.RemoveAt(0);
return str;
}
private static IEnumerable<string> CinA() => Console.ReadLine()?.Split();
private static int Cint() => int.Parse(Cin());
private static int[] CintA() => CinA().Select(int.Parse).ToArray();
private static void Cout(object obj) => Console.WriteLine(obj);
private static void ReadBuffer() {
if (Buffer.Any())
return;
var line = Console.ReadLine();
if (line != null && line.Contains(' ')) {
Buffer.AddRange(line.Split());
} else {
Buffer.Add(line);
}
}
#endregion
#region Loops
private static void Loop(int count, Action<int> action) => Loop(0, count,
action);
private static void Loop(int init, int count, Action<int> action,
int step = 1) {
for (var i = init; i < count + init; i += step) {
action(i);
}
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace C {
internal static class Program {
private static void Main(string[] args) {
var n = Cint();
var m = Cint();
var s = new int[m];
var c = new int[m];
Loop(m, i => {
s[i] = Cint();
c[i] = Cint();
});
var num = new string('0', n).ToCharArray();
var written = new List<Tuple<int, int>>();
Loop(m, i => {
if (written.Any(w => w.Item1 == s[i] && w.Item2 != c[i]) ||
s[i] == 1 && c[i] == 0 && n > 1) {
Cout(-1);
Environment.Exit(0);
}
num[s[i] - 1] = c[i].ToString().First();
written.Add(new Tuple<int, int>(s[i], c[i]));
});
if (num[0] == '0' && n > 1) {
num[0] = '1';
}
Cout(int.Parse(new string(num)));
}
#region Input and Output
private static readonly List<string> Buffer = new List<string>();
private static string Cin() {
ReadBuffer();
var str = Buffer.First();
Buffer.RemoveAt(0);
return str;
}
private static IEnumerable<string> CinA() => Console.ReadLine()?.Split();
private static int Cint() => int.Parse(Cin());
private static int[] CintA() => CinA().Select(int.Parse).ToArray();
private static void Cout(object obj) => Console.WriteLine(obj);
private static void ReadBuffer() {
if (Buffer.Any())
return;
var line = Console.ReadLine();
if (line != null && line.Contains(' ')) {
Buffer.AddRange(line.Split());
} else {
Buffer.Add(line);
}
}
#endregion
#region Loops
private static void Loop(int count, Action<int> action) => Loop(0, count,
action);
private static void Loop(int init, int count, Action<int> action,
int step = 1) {
for (var i = init; i < count + init; i += step) {
action(i);
}
}
#endregion
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 551
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;
namespace AtCoderTemplate {
class ProgramC {
static void Main() {
int N = NextInt, M = NextInt;
var array = Enumerable.Repeat(-1, N).ToArray();
for (int i = 0; i < M; i++) {
int s = NextInt - 1, c = NextInt;
if (array[s] == -1) {
if (s == 0 && c == 0 && N != 1) {
System.Console.WriteLine("-1");
return;
}
array[s] = c;
} else if (array[s] != c) {
System.Console.WriteLine("-1");
return;
}
}
System.Console.WriteLine(string.Join("", array.Select((x, i) => {
if (i == 0 && x == -1)
return 1;
if (x == -1)
return 0;
return x;
})));
}
}
}
namespace Library {
class Input {
static IEnumerator<string> enumerator =
new string[] {}.AsEnumerable().GetEnumerator();
public static string Line => Console.ReadLine();
public static string[] StrArr => Line.Split(' ');
public static int NextInt => int.Parse(NextWord());
public static long NextLong => long.Parse(NextWord());
public static List<int> IntList => StrArr.Select(int.Parse).ToList();
public static List<long> LongList => StrArr.Select(long.Parse).ToList();
public static IEnumerable<long[]> TakeLine(int N) {
return Enumerable.Repeat(0, N).Select(
_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
}
public static string NextWord() {
while (!enumerator.MoveNext()) {
enumerator = StrArr.AsEnumerable().GetEnumerator();
}
return enumerator.Current;
}
}
}
namespace Library {
class Modular {
public const int mod = 1000000007;
public readonly long value;
public Modular(long value) { this.value = value; }
public static implicit operator Modular(long a) {
var m = a % mod;
return new Modular((m < 0) ? m + mod : m);
}
public static Modular operator +(Modular a, Modular b) {
return a.value + b.value;
}
public static Modular operator -(Modular a, Modular b) {
return a.value - b.value;
}
public static Modular operator *(Modular a, Modular b) {
return a.value * b.value;
}
public static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b) {
return a * Pow(b, mod - 2);
}
private static readonly List<int> facs = new List<int> { 1 };
private static Modular Fac(int n) {
for (int i = facs.Count; i <= n; ++i) {
facs.Add((int)(Math.BigMul(facs.Last(), i) % mod));
}
return facs[n];
}
public static Modular Ncr(int n, int r) {
return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a) { return (int)a.value; }
}
}
namespace Library {
class MyMath {
public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); }
public static long Sqrt(long n) {
if (n < 0)
return 0;
long a = 0, tmp = 0, b = 0;
for (int i = 62; i >= 0; i -= 2) {
tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0;
a = a << 1 | tmp;
n -= (((b << 1) + 1) * tmp) << i;
b = (b << 1) + tmp + tmp;
}
return a;
}
public static long Nck(int n, int k) {
if (k == 0)
return 1;
if (n == 0)
return 0;
return n * Nck(n - 1, k - 1) / k;
}
}
}
namespace Library {
public class PriorityQueue<T> {
readonly List<T> _heap = new List<T>();
readonly Comparison<T> _comparison;
public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; }
public PriorityQueue() : this(Comparer<T>.Default.Compare) {}
public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {}
public void Enqueue(T item) {
_heap.Add(item);
int childID = _heap.Count - 1;
int parentID = (childID - 1) / 2;
while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) {
Swap(parentID, childID);
childID = parentID;
parentID = (parentID - 1) / 2;
}
}
public T Dequeue() {
var first = _heap.First();
_heap[0] = _heap.Last();
_heap.RemoveAt(_heap.Count - 1);
int parentID = 0;
int childID = parentID * 2 + 2;
if (childID >= _heap.Count ||
_comparison(_heap[childID], _heap[childID - 1]) > 0)
childID--;
while (childID < _heap.Count &&
_comparison(_heap[parentID], _heap[childID]) > 0) {
Swap(parentID, childID);
parentID = childID;
childID = parentID * 2 + 2;
if (childID >= _heap.Count ||
_comparison(_heap[childID], _heap[childID - 1]) > 0)
childID--;
}
return first;
}
void Swap(int parent, int child) {
var tmp = _heap[parent];
_heap[parent] = _heap[child];
_heap[child] = tmp;
}
public T Peek() { return _heap[0]; }
public int Count => _heap.Count;
public bool Any() { return _heap.Any(); }
public List<T> Data => _heap;
}
}
namespace Library {
public class UnionFind {
public int[] Parents { get; set; }
public UnionFind(int size) {
Parents = Enumerable.Repeat(-1, size).ToArray();
}
public int Find(int num) {
if (Parents[num] < 0)
return num;
Parents[num] = Find(Parents[num]);
return Parents[num];
}
public int Size(int num) { return -Parents[Find(num)]; }
public bool Same(int a, int b) { return Find(a) == Find(b); }
public void Unite(int a, int b) {
int x = Find(a), y = Find(b);
if (Size(x) > Size(y)) {
Parents[x] += Parents[y];
Parents[y] = x;
} else {
Parents[y] += Parents[x];
Parents[x] = y;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;
namespace AtCoderTemplate {
class ProgramC {
static void Main() {
int N = NextInt, M = NextInt;
var array = Enumerable.Repeat(-1, N).ToArray();
for (int i = 0; i < M; i++) {
int s = NextInt - 1, c = NextInt;
if (array[s] == -1) {
if (s == 0 && c == 0 && N != 1) {
System.Console.WriteLine("-1");
return;
}
array[s] = c;
} else if (array[s] != c) {
System.Console.WriteLine("-1");
return;
}
}
System.Console.WriteLine(string.Join("", array.Select((x, i) => {
if (N == 1 && i == 0 && x == -1)
return 0;
if (i == 0 && x == -1)
return 1;
if (x == -1)
return 0;
return x;
})));
}
}
}
namespace Library {
class Input {
static IEnumerator<string> enumerator =
new string[] {}.AsEnumerable().GetEnumerator();
public static string Line => Console.ReadLine();
public static string[] StrArr => Line.Split(' ');
public static int NextInt => int.Parse(NextWord());
public static long NextLong => long.Parse(NextWord());
public static List<int> IntList => StrArr.Select(int.Parse).ToList();
public static List<long> LongList => StrArr.Select(long.Parse).ToList();
public static IEnumerable<long[]> TakeLine(int N) {
return Enumerable.Repeat(0, N).Select(
_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
}
public static string NextWord() {
while (!enumerator.MoveNext()) {
enumerator = StrArr.AsEnumerable().GetEnumerator();
}
return enumerator.Current;
}
}
}
namespace Library {
class Modular {
public const int mod = 1000000007;
public readonly long value;
public Modular(long value) { this.value = value; }
public static implicit operator Modular(long a) {
var m = a % mod;
return new Modular((m < 0) ? m + mod : m);
}
public static Modular operator +(Modular a, Modular b) {
return a.value + b.value;
}
public static Modular operator -(Modular a, Modular b) {
return a.value - b.value;
}
public static Modular operator *(Modular a, Modular b) {
return a.value * b.value;
}
public static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b) {
return a * Pow(b, mod - 2);
}
private static readonly List<int> facs = new List<int> { 1 };
private static Modular Fac(int n) {
for (int i = facs.Count; i <= n; ++i) {
facs.Add((int)(Math.BigMul(facs.Last(), i) % mod));
}
return facs[n];
}
public static Modular Ncr(int n, int r) {
return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a) { return (int)a.value; }
}
}
namespace Library {
class MyMath {
public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); }
public static long Sqrt(long n) {
if (n < 0)
return 0;
long a = 0, tmp = 0, b = 0;
for (int i = 62; i >= 0; i -= 2) {
tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0;
a = a << 1 | tmp;
n -= (((b << 1) + 1) * tmp) << i;
b = (b << 1) + tmp + tmp;
}
return a;
}
public static long Nck(int n, int k) {
if (k == 0)
return 1;
if (n == 0)
return 0;
return n * Nck(n - 1, k - 1) / k;
}
}
}
namespace Library {
public class PriorityQueue<T> {
readonly List<T> _heap = new List<T>();
readonly Comparison<T> _comparison;
public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; }
public PriorityQueue() : this(Comparer<T>.Default.Compare) {}
public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {}
public void Enqueue(T item) {
_heap.Add(item);
int childID = _heap.Count - 1;
int parentID = (childID - 1) / 2;
while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) {
Swap(parentID, childID);
childID = parentID;
parentID = (parentID - 1) / 2;
}
}
public T Dequeue() {
var first = _heap.First();
_heap[0] = _heap.Last();
_heap.RemoveAt(_heap.Count - 1);
int parentID = 0;
int childID = parentID * 2 + 2;
if (childID >= _heap.Count ||
_comparison(_heap[childID], _heap[childID - 1]) > 0)
childID--;
while (childID < _heap.Count &&
_comparison(_heap[parentID], _heap[childID]) > 0) {
Swap(parentID, childID);
parentID = childID;
childID = parentID * 2 + 2;
if (childID >= _heap.Count ||
_comparison(_heap[childID], _heap[childID - 1]) > 0)
childID--;
}
return first;
}
void Swap(int parent, int child) {
var tmp = _heap[parent];
_heap[parent] = _heap[child];
_heap[child] = tmp;
}
public T Peek() { return _heap[0]; }
public int Count => _heap.Count;
public bool Any() { return _heap.Any(); }
public List<T> Data => _heap;
}
}
namespace Library {
public class UnionFind {
public int[] Parents { get; set; }
public UnionFind(int size) {
Parents = Enumerable.Repeat(-1, size).ToArray();
}
public int Find(int num) {
if (Parents[num] < 0)
return num;
Parents[num] = Find(Parents[num]);
return Parents[num];
}
public int Size(int num) { return -Parents[Find(num)]; }
public bool Same(int a, int b) { return Find(a) == Find(b); }
public void Unite(int a, int b) {
int x = Find(a), y = Find(b);
if (Size(x) > Size(y)) {
Parents[x] += Parents[y];
Parents[y] = x;
} else {
Parents[y] += Parents[x];
Parents[x] = y;
}
}
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 218, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 203], ["+", 0, 28, 0, 218, 8, 196, 0, 57, 0, 25], ["+", 0, 218, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 218, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 218, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 0, 28, 0, 218, 8, 196, 0, 57, 0, 121], ["+", 0, 28, 0, 218, 8, 196, 0, 57, 0, 24]]
| 8
| 1,611
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoderBeginnerContest157 {
class Program {
static void Main(string[] args) {
var nm = ReadIntArray();
var pairs = new List<int[]>(nm[1]);
for (var i = 0; i < nm[1]; i++) {
var tmp = ReadIntArray();
if ((nm[0] != 1 && tmp[1] == 0) ||
(i != 0 && pairs.Any(x => x[0] == tmp[0] && x[1] != tmp[1]))) {
Console.WriteLine("-1");
return;
}
pairs.Add(tmp);
}
switch (nm[0]) {
case 1: {
if (nm[1] != 0 && pairs.Any(x => x[0] == 1)) {
Console.WriteLine(pairs.Where(x => x[0] == 1).ToArray() [0][1]);
return;
} else {
Console.WriteLine(0);
return;
}
}
case 2: {
var two = 1;
var one = 0;
if (nm[1] != 0 && pairs.Any(x => x[0] == 1)) {
two = pairs.Where(x => x[0] == 1).ToArray() [0][1];
}
if (nm[1] != 0 && pairs.Any(x => x[0] == 2)) {
one = pairs.Where(x => x[0] == 2).ToArray() [0][1];
}
Console.WriteLine(two * 10 + one);
return;
}
case 3: {
var three = 1;
var two = 0;
var one = 0;
if (nm[1] != 0 && pairs.Any(x => x[0] == 1)) {
three = pairs.Where(x => x[0] == 1).ToArray() [0][1];
}
if (nm[1] != 0 && pairs.Any(x => x[0] == 2)) {
two = pairs.Where(x => x[0] == 2).ToArray() [0][1];
}
if (nm[1] != 0 && pairs.Any(x => x[0] == 3)) {
one = pairs.Where(x => x[0] == 3).ToArray() [0][1];
}
Console.WriteLine(three * 100 + two * 10 + one);
return;
}
}
}
public static int ReadInt() => int.Parse(Console.ReadLine());
public static int[] ReadIntArray() =>
Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
public static long ReadLong() => long.Parse(Console.ReadLine());
public static long[] ReadLongArray() =>
Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
public static string ReadString() => Console.ReadLine();
public static string[] ReadStringArray() => Console.ReadLine().Split();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoderBeginnerContest157 {
class Program {
static void Main(string[] args) {
var nm = ReadIntArray();
var pairs = new List<int[]>(nm[1]);
for (var i = 0; i < nm[1]; i++) {
var tmp = ReadIntArray();
if ((nm[0] != 1 && tmp[0] == 1 && tmp[1] == 0) ||
(i != 0 && pairs.Any(x => x[0] == tmp[0] && x[1] != tmp[1]))) {
Console.WriteLine("-1");
return;
}
pairs.Add(tmp);
}
switch (nm[0]) {
case 1: {
if (nm[1] != 0 && pairs.Any(x => x[0] == 1)) {
Console.WriteLine(pairs.Where(x => x[0] == 1).ToArray() [0][1]);
return;
} else {
Console.WriteLine(0);
return;
}
}
case 2: {
var two = 1;
var one = 0;
if (nm[1] != 0 && pairs.Any(x => x[0] == 1)) {
two = pairs.Where(x => x[0] == 1).ToArray() [0][1];
}
if (nm[1] != 0 && pairs.Any(x => x[0] == 2)) {
one = pairs.Where(x => x[0] == 2).ToArray() [0][1];
}
Console.WriteLine(two * 10 + one);
return;
}
case 3: {
var three = 1;
var two = 0;
var one = 0;
if (nm[1] != 0 && pairs.Any(x => x[0] == 1)) {
three = pairs.Where(x => x[0] == 1).ToArray() [0][1];
}
if (nm[1] != 0 && pairs.Any(x => x[0] == 2)) {
two = pairs.Where(x => x[0] == 2).ToArray() [0][1];
}
if (nm[1] != 0 && pairs.Any(x => x[0] == 3)) {
one = pairs.Where(x => x[0] == 3).ToArray() [0][1];
}
Console.WriteLine(three * 100 + two * 10 + one);
return;
}
}
}
public static int ReadInt() => int.Parse(Console.ReadLine());
public static int[] ReadIntArray() =>
Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
public static long ReadLong() => long.Parse(Console.ReadLine());
public static long[] ReadLongArray() =>
Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
public static string ReadString() => Console.ReadLine();
public static string[] ReadStringArray() => Console.ReadLine().Split();
}
}
|
[["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 31, 23, 0, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 98], ["+", 31, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70]]
| 8
| 695
| 7
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Numerics;
namespace AtCoder {
public class Program {
// 最小公倍数
public static long Lcm(long a, long b) { return a * b / Gcd(a, b); }
// ユークリッドの互除法
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
Console.ReadLine();
}
public void Solve(ConsoleInput cin) {
int[] data = cin.ReadIntArray(2);
int n = data[0];
int m = data[1];
int[,] seiyaku = new int[m, 2];
for (int i = 0; i < m; i++) {
int[] tmp = cin.ReadIntArray(2);
seiyaku[i, 0] = tmp[0];
seiyaku[i, 1] = tmp[1];
}
int[] check = new int[n];
for (int i = 0; i < check.Length; i++) {
check[i] = -1;
}
for (int i = 0; i < m; i++) {
int keta = seiyaku[i, 0];
int v = seiyaku[i, 1];
if (v == 0 && seiyaku[i, 0] == 1) {
//最上位のけたを0にしようとしているのでだめ
Console.WriteLine(-1);
return;
}
if (check[keta - 1] != -1 && check[keta - 1] != v) {
//2つの反する条件を満たそうとするができないのでだめ
Console.WriteLine(-1);
return;
}
check[keta - 1] = v;
}
string ans = "";
// 1桁目は0不可なので
ans += check[0] == -1 ? "1" : check[0].ToString();
for (int i = 1; i < n; i++) {
ans += check[i] == -1 ? "0" : check[i].ToString();
}
Console.WriteLine(ans);
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
public class Util {
// nCrを計算したいときに使用
public static ModInt Comb(int n, int r) {
ModInt res = 1;
for (int i = 1; i <= r; i++) {
res *= n;
res /= i;
n--;
}
return res;
}
// n^mを計算
public static ModInt Power(ModInt n, long m) {
ModInt pow = n;
ModInt res = 1;
while (m > 0) {
if ((m & 1) == 1)
res *= pow;
pow *= pow;
m >>= 1;
}
return res;
}
}
public struct ModInt {
public const int Mod = 1000000007;
const long POSITIVIZER = ((long)Mod) << 31;
long Data;
public ModInt(long data) {
if ((Data = data % Mod) < 0)
Data += Mod;
}
public static implicit operator long(ModInt modInt) => modInt.Data;
public static implicit operator ModInt(long val) => new ModInt(val);
public static ModInt operator -(ModInt a, int b) => new ModInt() {
Data = (a.Data - b + POSITIVIZER) % Mod
};
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + Mod : res };
}
public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b);
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % Mod
};
public static ModInt operator /(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * GetInverse(b) % Mod
};
public override int GetHashCode() => (int)Data;
static long GetInverse(long a) {
long div, p = Mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + Mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + Mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Numerics;
namespace AtCoder {
public class Program {
// 最小公倍数
public static long Lcm(long a, long b) { return a * b / Gcd(a, b); }
// ユークリッドの互除法
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
Console.ReadLine();
}
public void Solve(ConsoleInput cin) {
int[] data = cin.ReadIntArray(2);
int n = data[0];
int m = data[1];
int[,] seiyaku = new int[m, 2];
for (int i = 0; i < m; i++) {
int[] tmp = cin.ReadIntArray(2);
seiyaku[i, 0] = tmp[0];
seiyaku[i, 1] = tmp[1];
}
int[] check = new int[n];
for (int i = 0; i < check.Length; i++) {
check[i] = -1;
}
for (int i = 0; i < m; i++) {
int keta = seiyaku[i, 0];
int v = seiyaku[i, 1];
if (v == 0 && seiyaku[i, 0] == 1 && n != 1) {
//最上位のけたを0にしようとしているのでだめ
Console.WriteLine(-1);
return;
}
if (check[keta - 1] != -1 && check[keta - 1] != v) {
//2つの反する条件を満たそうとするができないのでだめ
Console.WriteLine(-1);
return;
}
check[keta - 1] = v;
}
string ans = "";
// 1桁目は0不可なので
ans += check[0] == -1 ? "1" : check[0].ToString();
if (n == 1 && check[0] == -1) {
// 1桁のみのときは例外的に0
ans = "0";
}
for (int i = 1; i < n; i++) {
ans += check[i] == -1 ? "0" : check[i].ToString();
}
Console.WriteLine(ans);
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
public class Util {
// nCrを計算したいときに使用
public static ModInt Comb(int n, int r) {
ModInt res = 1;
for (int i = 1; i <= r; i++) {
res *= n;
res /= i;
n--;
}
return res;
}
// n^mを計算
public static ModInt Power(ModInt n, long m) {
ModInt pow = n;
ModInt res = 1;
while (m > 0) {
if ((m & 1) == 1)
res *= pow;
pow *= pow;
m >>= 1;
}
return res;
}
}
public struct ModInt {
public const int Mod = 1000000007;
const long POSITIVIZER = ((long)Mod) << 31;
long Data;
public ModInt(long data) {
if ((Data = data % Mod) < 0)
Data += Mod;
}
public static implicit operator long(ModInt modInt) => modInt.Data;
public static implicit operator ModInt(long val) => new ModInt(val);
public static ModInt operator -(ModInt a, int b) => new ModInt() {
Data = (a.Data - b + POSITIVIZER) % Mod
};
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + Mod : res };
}
public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b);
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % Mod
};
public static ModInt operator /(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * GetInverse(b) % Mod
};
public override int GetHashCode() => (int)Data;
static long GetInverse(long a) {
long div, p = Mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + Mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + Mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 11, 12, 41, 75, 213, 3, 4, 0, 25], ["+", 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, 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], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 62], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 1,302
| 26
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var M = sc.ReadInt();
var a = Enumerable.Repeat(int.MaxValue, N).ToArray();
for (int i = 0; i < M; i++) {
var s = sc.ReadInt() - 1;
var c = sc.ReadInt();
if (a[s] == int.MaxValue || a[s] == c) {
a[s] = c;
if (s == 0 && c == 0) {
Console.WriteLine(-1);
return;
}
} else {
Console.WriteLine(-1);
return;
}
}
for (int i = 0; i < N; i++) {
if (a[i] == int.MaxValue)
a[i] = 0;
if (i == 0 && a[i] == 0)
a[i] = 1;
Console.Write(a[i]);
}
Console.WriteLine();
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var M = sc.ReadInt();
var a = Enumerable.Repeat(int.MaxValue, N).ToArray();
for (int i = 0; i < M; i++) {
var s = sc.ReadInt() - 1;
var c = sc.ReadInt();
if (a[s] == int.MaxValue || a[s] == c) {
a[s] = c;
if (s == 0 && c == 0 && N != 1) {
Console.WriteLine(-1);
return;
}
} else {
Console.WriteLine(-1);
return;
}
}
if (N == 1 && (a[0] == 0 || a[0] == int.MaxValue)) {
Console.WriteLine(0);
return;
}
for (int i = 0; i < N; i++) {
if (a[i] == int.MaxValue)
a[i] = 0;
if (i == 0 && a[i] == 0)
a[i] = 1;
Console.Write(a[i]);
}
Console.WriteLine();
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 12, 23, 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], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 60], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 106], ["+", 12, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 60], ["+", 12, 23, 0, 16, 12, 16, 12, 214, 205, 199], ["+", 12, 23, 0, 16, 12, 16, 12, 214, 0, 131], ["+", 12, 23, 0, 16, 12, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
| 8
| 1,205
| 39
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;
public class C {
public static void Main() => (new Solver()).Solve();
}
public class Solver {
public void Solve() {
int N = GetInt();
int M = GetInt();
int[] s = new int[M];
int[] c = new int[M];
for (int i = 0; i < M; i++) {
s[i] = GetInt() - 1;
c[i] = GetInt();
}
if (M == 0) {
switch (N) {
case 1:
WriteLine(0);
return;
case 2:
WriteLine(10);
return;
case 3:
WriteLine(100);
return;
}
}
int[] ans = new int[N];
for (int i = 0; i < M; i++) {
if (s[i] >= N || (N > 1 && s[i] == 0 && c[i] == 0)) {
WriteLine(-1);
return;
}
ans[s[i]] = c[i];
for (int j = i + 1; j < M; j++) {
if (s[i] == s[j] && c[i] != c[j]) {
WriteLine(-1);
return;
}
}
}
WriteLine(string.Concat(ans));
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() => int.Parse(getArg());
public static long GetLong() => long.Parse(getArg());
public static double GetDouble() => double.Parse(getArg());
public static decimal GetDecimal() => decimal.Parse(getArg());
public static string GetString() => getArg();
public static char GetChar() => getArg()[0];
public static int[] GetInts(long N) =>
Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
public static long[] GetLongs(long N) =>
Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
public static double[] GetDoubles(long N) =>
Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
public static decimal[] GetDecimals(long N) =>
Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
public static string[] GetStrings(long N) =>
Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}
public static class MyUtil {
public static void chmax<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) < 0)
x = y;
}
public static void chmin<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) > 0)
x = y;
}
public static void swap<T>(ref T x, ref T y) {
T tmp = x;
x = y;
y = tmp;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;
public class C {
public static void Main() => (new Solver()).Solve();
}
public class Solver {
public void Solve() {
int N = GetInt();
int M = GetInt();
int[] s = new int[M];
int[] c = new int[M];
for (int i = 0; i < M; i++) {
s[i] = GetInt() - 1;
c[i] = GetInt();
}
if (M == 0) {
switch (N) {
case 1:
WriteLine(0);
return;
case 2:
WriteLine(10);
return;
case 3:
WriteLine(100);
return;
}
}
int[] ans = new int[N];
ans[0] = 1;
for (int i = 0; i < M; i++) {
if (s[i] >= N || (N > 1 && s[i] == 0 && c[i] == 0)) {
WriteLine(-1);
return;
}
ans[s[i]] = c[i];
for (int j = i + 1; j < M; j++) {
if (s[i] == s[j] && c[i] != c[j]) {
WriteLine(-1);
return;
}
}
}
WriteLine(string.Concat(ans));
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() => int.Parse(getArg());
public static long GetLong() => long.Parse(getArg());
public static double GetDouble() => double.Parse(getArg());
public static decimal GetDecimal() => decimal.Parse(getArg());
public static string GetString() => getArg();
public static char GetChar() => getArg()[0];
public static int[] GetInts(long N) =>
Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
public static long[] GetLongs(long N) =>
Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
public static double[] GetDoubles(long N) =>
Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
public static decimal[] GetDecimals(long N) =>
Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
public static string[] GetStrings(long N) =>
Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}
public static class MyUtil {
public static void chmax<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) < 0)
x = y;
}
public static void chmin<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) > 0)
x = y;
}
public static void swap<T>(ref T x, ref T y) {
T tmp = x;
x = y;
y = tmp;
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 800
| 7
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 1000001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static void Solve() {
var n = Input.NextInt();
var m = Input.NextInt();
var s = new int[m];
var c = new int[m];
for (int i = 0; i < m; ++i) {
s[i] = Input.NextInt();
c[i] = Input.NextInt();
}
int max = (int)pow(10, n);
for (int i = 0; i < max; ++i) {
if (IsValid(i, s, c)) {
Console.WriteLine(i);
return;
}
}
Console.WriteLine(-1);
}
private static bool IsValid(int digit, int[] s, int[] c) {
var sz = digit.ToString();
for (int i = 0; i < s.Length; ++i) {
int idx = s[i] - 1;
if (idx >= sz.Length) {
return false;
}
int d = sz[idx] - '0';
if (c[i] != d) {
return false;
}
}
return true;
}
private static long NCR(long n, int r) {
long ans = 1;
for (int i = 0; i < r; ++i) {
ans *= (n - i);
ans %= MOD;
}
for (int i = r; i >= 1; i--) {
ans = ans * ModInv(i, MOD) % MOD;
}
return ans;
}
private static long ModInv(long a, long m) {
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;
}
#region よく使う便利関数
private static Dictionary<long, int> Factorize(long n) {
var dic = new Dictionary<long, int>();
for (long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 0);
}
dic[i]++;
n /= i;
}
}
if (n != 1) {
dic.Add(n, 1);
}
return dic;
}
static void COMinit() {
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 % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static 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>
static bool read() {
var s = Console.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 static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
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;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
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);
}
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() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 1000001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static void Solve() {
var n = Input.NextInt();
var m = Input.NextInt();
var s = new int[m];
var c = new int[m];
for (int i = 0; i < m; ++i) {
s[i] = Input.NextInt();
c[i] = Input.NextInt();
}
int max = (int)pow(10, n);
for (int i = 0; i < max; ++i) {
if (IsValid(i, s, c, n)) {
Console.WriteLine(i);
return;
}
}
Console.WriteLine(-1);
}
private static bool IsValid(int digit, int[] s, int[] c, int keta) {
var sz = digit.ToString();
if (sz.Length != keta) {
return false;
}
for (int i = 0; i < s.Length; ++i) {
int idx = s[i] - 1;
if (idx >= sz.Length) {
return false;
}
int d = sz[idx] - '0';
if (c[i] != d) {
return false;
}
}
return true;
}
private static long NCR(long n, int r) {
long ans = 1;
for (int i = 0; i < r; ++i) {
ans *= (n - i);
ans %= MOD;
}
for (int i = r; i >= 1; i--) {
ans = ans * ModInv(i, MOD) % MOD;
}
return ans;
}
private static long ModInv(long a, long m) {
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;
}
#region よく使う便利関数
private static Dictionary<long, int> Factorize(long n) {
var dic = new Dictionary<long, int>();
for (long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 0);
}
dic[i]++;
n /= i;
}
}
if (n != 1) {
dic.Add(n, 1);
}
return dic;
}
static void COMinit() {
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 % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static 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>
static bool read() {
var s = Console.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 static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
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;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
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);
}
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() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
[["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 21], ["+", 0, 57, 15, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 21], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 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, 201, 0, 195, 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, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 37, 0, 211, 0, 147], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 2,772
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;
class Solver {
public void Solve(Scanner sc) {
int N, M;
sc.Make(out N, out M);
var p = Create(N, () => -1);
for (int i = 0; i < M; i++) {
int s, c;
sc.Make(out s, out c);
s--;
if (s == 0 && c == 0 && N != 1)
Fail(-1);
if (p[s] == -1)
p[s] = c;
else {
if (p[s] != c)
Fail("-1");
}
}
var res = p[0] == -1 ? 1 : p[0];
for (int i = 1; i < N; i++) {
res *= 10;
res += p[i] == -1 ? 0 : p[i];
}
WriteLine(res);
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve(new Scanner());
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
public string Str => Console.ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
public int[] ArrInt1D(int n) => Create(n, () => Int);
public long[] ArrLong1D(int n) => Create(n, () => Long);
public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
// public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1,
// v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2,
// out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3,
// T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2,
// v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2> p) {
var c = Comparer<T1>.Default.Compare(v1, p.v1);
if (c == 0)
c = Comparer<T2>.Default.Compare(v2, p.v2);
return c;
}
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public void Deconstruct(out T1 a, out T2 b) {
a = v1;
b = v2;
}
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() {}
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2, T3> p) {
var c = base.CompareTo(p);
if (c == 0)
c = Comparer<T3>.Default.Compare(v3, p.v3);
return c;
}
public override string ToString() => $"{base.ToString()} {v3.ToString()}";
public void Deconstruct(out T1 a, out T2 b, out T3 c) {
Deconstruct(out a, out b);
c = v3;
}
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;
class Solver {
public void Solve(Scanner sc) {
int N, M;
sc.Make(out N, out M);
var p = Create(N, () => -1);
for (int i = 0; i < M; i++) {
int s, c;
sc.Make(out s, out c);
s--;
if (s == 0 && c == 0 && N != 1)
Fail(-1);
if (p[s] == -1)
p[s] = c;
else {
if (p[s] != c)
Fail("-1");
}
}
if (N == 1 && (p[0] == 0 || p[0] == -1))
Fail(0);
var res = p[0] == -1 ? 1 : p[0];
for (int i = 1; i < N; i++) {
res *= 10;
res += p[i] == -1 ? 0 : p[i];
}
WriteLine(res);
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve(new Scanner());
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
public string Str => Console.ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
public int[] ArrInt1D(int n) => Create(n, () => Int);
public long[] ArrLong1D(int n) => Create(n, () => Long);
public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
// public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1,
// v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2,
// out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3,
// T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2,
// v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2> p) {
var c = Comparer<T1>.Default.Compare(v1, p.v1);
if (c == 0)
c = Comparer<T2>.Default.Compare(v2, p.v2);
return c;
}
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public void Deconstruct(out T1 a, out T2 b) {
a = v1;
b = v2;
}
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() {}
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2, T3> p) {
var c = base.CompareTo(p);
if (c == 0)
c = Comparer<T3>.Default.Compare(v3, p.v3);
return c;
}
public override string ToString() => $"{base.ToString()} {v3.ToString()}";
public void Deconstruct(out T1 a, out T2 b, out T3 c) {
Deconstruct(out a, out b);
c = v3;
}
}
#endregion
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 12, 23, 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], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 60], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 106], ["+", 12, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 60], ["+", 12, 23, 0, 16, 12, 16, 12, 241, 0, 33], ["+", 12, 23, 0, 16, 12, 16, 12, 241, 0, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 213, 63, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 1,597
| 28
|
using AtCoderBeginnerContest157.Questions;
using AtCoderBeginnerContest157.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoderBeginnerContest157.Questions {
// 復習
public class QuestionD_UnionFind : AtCoderQuestionBase {
int n, m, k;
UnionFindNode<int>[] people = null;
List<int>[] friends = null;
int[] blockCount;
int[] group;
List<int> groupMemberCount = new List<int>();
public override IEnumerable<object> Solve(TextReader inputStream) {
var nmk = inputStream.ReadIntArray();
n = nmk[0];
m = nmk[1];
k = nmk[2];
people = Enumerable.Range(0, n)
.Select(i => new UnionFindNode<int>(i))
.ToArray();
friends = Enumerable.Range(0, n).Select(_ => new List<int>()).ToArray();
group = Enumerable.Repeat(-1, n).ToArray();
blockCount = new int[n];
for (int i = 0; i < m; i++) {
var ab = inputStream.ReadIntArray();
var a = ab[0] - 1;
var b = ab[1] - 1;
people[a].Unite(people[b]);
friends[a].Add(b);
friends[b].Add(a);
}
for (int i = 0; i < k; i++) {
var cd = inputStream.ReadIntArray();
if (people[cd[0] - 1].IsInSameGroup(people[cd[1] - 1])) {
blockCount[cd[0] - 1] += 1;
blockCount[cd[1] - 1] += 1;
}
}
yield return string.Join(" ", Enumerable.Range(0, n).Select(
i => GetFriendCount(i).ToString()));
}
int GetFriendCount(int me) {
return people[me].GetSize() - friends[me].Count - blockCount[me] - 1;
}
}
public class UnionFindNode<T> {
private int _height; // rootのときのみ有効
private int _size; // 同上
private UnionFindNode<T> _parent;
public T Item { get; }
public UnionFindNode(T item) {
_height = 0;
_size = 1;
_parent = this;
Item = item;
}
public UnionFindNode<T> FindRoot() {
if (_parent != this) // not ref equals
{
var root = _parent.FindRoot();
_parent = root;
}
return _parent;
}
public int GetSize() => FindRoot()._size;
public void Unite(UnionFindNode<T> other) {
var thisRoot = this.FindRoot();
var otherRoot = other.FindRoot();
if (thisRoot._height < otherRoot._height) {
thisRoot._parent = otherRoot;
thisRoot._size = otherRoot._size;
otherRoot._height = Math.Max(thisRoot._height + 1, otherRoot._height);
} else {
otherRoot._parent = thisRoot;
otherRoot._size = thisRoot._size;
thisRoot._height = Math.Max(otherRoot._height + 1, thisRoot._height);
}
}
public bool IsInSameGroup(UnionFindNode<T> other) =>
this.FindRoot() == other.FindRoot();
}
}
namespace AtCoderBeginnerContest157 {
class Program {
static void Main(string[] args) {
IAtCoderQuestion question =
new QuestionD_UnionFind(); // 問題に合わせて書き換え
var answers = question.Solve(Console.In);
foreach (var answer in answers) {
Console.WriteLine(answer);
}
}
}
}
#region Base Classes
namespace AtCoderBeginnerContest157.Questions {
public interface IAtCoderQuestion {
IEnumerable<object> Solve(string input);
IEnumerable<object> Solve(TextReader inputStream);
}
public abstract class AtCoderQuestionBase : IAtCoderQuestion {
public IEnumerable<object> Solve(string input) {
var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
var reader = new StreamReader(stream, Encoding.Unicode);
return Solve(reader);
}
public abstract IEnumerable<object> Solve(TextReader inputStream);
}
}
#endregion
#region Extensions
namespace AtCoderBeginnerContest157.Extensions {
internal static class TextReaderExtensions {
internal static int
ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
internal static long
ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
internal static double
ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
internal static string
ReadString(this TextReader reader) => reader.ReadLine();
internal static int[] ReadIntArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(int.Parse).ToArray();
internal static long[] ReadLongArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(long.Parse).ToArray();
internal static double[] ReadDoubleArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(double.Parse).ToArray();
internal static string[] ReadStringArray(this TextReader reader,
char separator = ' ') =>
reader.ReadLine().Split(separator);
}
}
#endregion
|
using AtCoderBeginnerContest157.Questions;
using AtCoderBeginnerContest157.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoderBeginnerContest157.Questions {
// 復習
public class QuestionD_UnionFind : AtCoderQuestionBase {
int n, m, k;
UnionFindNode<int>[] people = null;
List<int>[] friends = null;
int[] blockCount;
int[] group;
List<int> groupMemberCount = new List<int>();
public override IEnumerable<object> Solve(TextReader inputStream) {
var nmk = inputStream.ReadIntArray();
n = nmk[0];
m = nmk[1];
k = nmk[2];
people = Enumerable.Range(0, n)
.Select(i => new UnionFindNode<int>(i))
.ToArray();
friends = Enumerable.Range(0, n).Select(_ => new List<int>()).ToArray();
group = Enumerable.Repeat(-1, n).ToArray();
blockCount = new int[n];
for (int i = 0; i < m; i++) {
var ab = inputStream.ReadIntArray();
var a = ab[0] - 1;
var b = ab[1] - 1;
people[a].Unite(people[b]);
friends[a].Add(b);
friends[b].Add(a);
}
for (int i = 0; i < k; i++) {
var cd = inputStream.ReadIntArray();
if (people[cd[0] - 1].IsInSameGroup(people[cd[1] - 1])) {
blockCount[cd[0] - 1] += 1;
blockCount[cd[1] - 1] += 1;
}
}
yield return string.Join(" ", Enumerable.Range(0, n).Select(
i => GetFriendCount(i).ToString()));
}
int GetFriendCount(int me) {
return people[me].GetSize() - friends[me].Count - blockCount[me] - 1;
}
}
public class UnionFindNode<T> {
private int _height; // rootのときのみ有効
private int _size; // 同上
private UnionFindNode<T> _parent;
public T Item { get; }
public UnionFindNode(T item) {
_height = 0;
_size = 1;
_parent = this;
Item = item;
}
public UnionFindNode<T> FindRoot() {
if (_parent != this) // not ref equals
{
var root = _parent.FindRoot();
_parent = root;
}
return _parent;
}
public int GetSize() => FindRoot()._size;
public void Unite(UnionFindNode<T> other) {
var thisRoot = this.FindRoot();
var otherRoot = other.FindRoot();
if (thisRoot == otherRoot) {
return;
}
if (thisRoot._height < otherRoot._height) {
thisRoot._parent = otherRoot;
otherRoot._size += thisRoot._size;
otherRoot._height = Math.Max(thisRoot._height + 1, otherRoot._height);
} else {
otherRoot._parent = thisRoot;
thisRoot._size += otherRoot._size;
thisRoot._height = Math.Max(otherRoot._height + 1, thisRoot._height);
}
}
public bool IsInSameGroup(UnionFindNode<T> other) =>
this.FindRoot() == other.FindRoot();
public override string ToString() => $"{Item} root:{FindRoot().Item}";
}
}
namespace AtCoderBeginnerContest157 {
class Program {
static void Main(string[] args) {
IAtCoderQuestion question =
new QuestionD_UnionFind(); // 問題に合わせて書き換え
var answers = question.Solve(Console.In);
foreach (var answer in answers) {
Console.WriteLine(answer);
}
}
}
}
#region Base Classes
namespace AtCoderBeginnerContest157.Questions {
public interface IAtCoderQuestion {
IEnumerable<object> Solve(string input);
IEnumerable<object> Solve(TextReader inputStream);
}
public abstract class AtCoderQuestionBase : IAtCoderQuestion {
public IEnumerable<object> Solve(string input) {
var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
var reader = new StreamReader(stream, Encoding.Unicode);
return Solve(reader);
}
public abstract IEnumerable<object> Solve(TextReader inputStream);
}
}
#endregion
#region Extensions
namespace AtCoderBeginnerContest157.Extensions {
internal static class TextReaderExtensions {
internal static int
ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
internal static long
ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
internal static double
ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
internal static string
ReadString(this TextReader reader) => reader.ReadLine();
internal static int[] ReadIntArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(int.Parse).ToArray();
internal static long[] ReadLongArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(long.Parse).ToArray();
internal static double[] ReadDoubleArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(double.Parse).ToArray();
internal static string[] ReadStringArray(this TextReader reader,
char separator = ' ') =>
reader.ReadLine().Split(separator);
}
}
#endregion
|
[["+", 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], ["+", 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, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 11, 31, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 31, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 11, 31, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 11, 31, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 75, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 259], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 310], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 306, 0, 221], ["+", 8, 201, 0, 195, 8, 306, 0, 283, 0, 295], ["+", 0, 195, 8, 306, 0, 283, 0, 284, 0, 45], ["+", 0, 195, 8, 306, 0, 283, 0, 284, 0, 22], ["+", 0, 195, 8, 306, 0, 283, 0, 284, 0, 46], ["+", 8, 201, 0, 195, 8, 306, 0, 283, 0, 296], ["+", 0, 283, 0, 284, 0, 214, 205, 213, 63, 22], ["+", 0, 284, 0, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 284, 0, 214, 205, 213, 3, 4, 0, 25], ["+", 8, 306, 0, 283, 0, 284, 0, 214, 0, 131], ["+", 8, 306, 0, 283, 0, 284, 0, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 306, 0, 283, 0, 62]]
| 8
| 1,074
| 43
|
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) {
string[] nmk = Console.ReadLine().Split(' ');
int n = int.Parse(nmk[0]);
int m = int.Parse(nmk[1]);
int k = int.Parse(nmk[2]);
int[] a = new int[m];
int[] b = new int[m];
int[] yujins = new int[n];
UnionFind uni = new UnionFind(n);
int[] blocking = new int[n];
for (int i = 0; i < m; i++) {
string[] ab = Console.ReadLine().Split(' ');
a[i] = int.Parse(ab[0]) - 1;
b[i] = int.Parse(ab[1]) - 1;
yujins[a[i]]++;
yujins[b[i]]++;
uni.Unite(a[i], b[i]);
}
int[] c = new int[k];
int[] d = new int[k];
for (int i = 0; i < k; i++) {
string[] ab = Console.ReadLine().Split(' ');
c[i] = int.Parse(ab[0]) - 1;
d[i] = int.Parse(ab[1]) - 1;
if (uni.IsSameGroup(c[i], d[i])) {
blocking[c[i]]++;
blocking[d[i]]++;
}
}
for (int i = 0; i < n; i++) {
int kore = uni.Root(i);
int kouhos = uni.data[uni.Root(i)];
Console.Write(-kouhos - yujins[i] - blocking[i] - 1);
}
Console.WriteLine();
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
}
|
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) {
string[] nmk = Console.ReadLine().Split(' ');
int n = int.Parse(nmk[0]);
int m = int.Parse(nmk[1]);
int k = int.Parse(nmk[2]);
int[] a = new int[m];
int[] b = new int[m];
int[] yujins = new int[n];
UnionFind uni = new UnionFind(n);
int[] blocking = new int[n];
for (int i = 0; i < m; i++) {
string[] ab = Console.ReadLine().Split(' ');
a[i] = int.Parse(ab[0]) - 1;
b[i] = int.Parse(ab[1]) - 1;
yujins[a[i]]++;
yujins[b[i]]++;
uni.Unite(a[i], b[i]);
}
int[] c = new int[k];
int[] d = new int[k];
for (int i = 0; i < k; i++) {
string[] ab = Console.ReadLine().Split(' ');
c[i] = int.Parse(ab[0]) - 1;
d[i] = int.Parse(ab[1]) - 1;
if (uni.IsSameGroup(c[i], d[i])) {
blocking[c[i]]++;
blocking[d[i]]++;
}
}
for (int i = 0; i < n; i++) {
int kore = uni.Root(i);
int kouhos = uni.data[uni.Root(i)];
Console.Write(-kouhos - yujins[i] - blocking[i] - 1);
if (i != n - 1) {
Console.Write(" ");
}
}
Console.WriteLine();
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 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, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 638
| 19
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = (int)1e9 + 7;
static void Main() {
Sc sc = new Sc();
var s = sc.Ia;
Uf uf = new Uf(s[0] + 1);
var h = new int[s[0] + 1];
var b = new int[s[0] + 1];
var ans = new int[s[0]];
for (int i = 0; i < s[1]; i++) {
var e = sc.Ia;
uf.Union(e[0], e[1]);
h[e[0]]++;
h[e[1]]++;
}
for (int i = 0; i < s[2]; i++) {
var e = sc.Ia;
if (uf.Same(e[0], e[1])) {
b[e[0]]++;
b[e[1]]++;
}
}
for (int i = 1; i <= s[0]; i++) {
Console.WriteLine("{0} {1} {2}", uf.Size(i), h[i], b[i]);
ans[i - 1] = uf.Size(i) - h[i] - b[i] - 1;
}
Console.WriteLine("{0}", String.Join(" ", ans));
}
}
public class Uf {
private int[] arr, hi;
public int all;
public Uf(int n) {
arr = new int[n];
hi = new int[n];
all = n;
for (int i = 0; i < n; i++) {
arr[i] = -1;
}
}
public void Union(int a, int b) {
a = Root(a);
b = Root(b);
if (a != b) {
if (hi[a] < hi[b]) {
a ^= b;
b ^= a;
a ^= b;
}
arr[a] += arr[b];
hi[a] = Math.Max(hi[a], hi[b] + 1);
arr[b] = a;
all--;
}
}
public bool Same(int a, int b) { return Root(a) == Root(b); }
public int Size(int a) { return -arr[Root(a)]; }
public int Root(int a) { return arr[a] < 0 ? a : arr[a] = Root(arr[a]); }
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
int.Parse);
}
public int[] Ia3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
long.Parse);
}
public long[] La3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
double.Parse);
}
public double[] Da3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
double.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = (int)1e9 + 7;
static void Main() {
Sc sc = new Sc();
var s = sc.Ia;
Uf uf = new Uf(s[0] + 1);
var h = new int[s[0] + 1];
var b = new int[s[0] + 1];
var ans = new int[s[0]];
for (int i = 0; i < s[1]; i++) {
var e = sc.Ia;
uf.Union(e[0], e[1]);
h[e[0]]++;
h[e[1]]++;
}
for (int i = 0; i < s[2]; i++) {
var e = sc.Ia;
if (uf.Same(e[0], e[1])) {
b[e[0]]++;
b[e[1]]++;
}
}
for (int i = 1; i <= s[0]; i++) {
ans[i - 1] = uf.Size(i) - h[i] - b[i] - 1;
}
Console.WriteLine("{0}", String.Join(" ", ans));
}
}
public class Uf {
private int[] arr, hi;
public int all;
public Uf(int n) {
arr = new int[n];
hi = new int[n];
all = n;
for (int i = 0; i < n; i++) {
arr[i] = -1;
}
}
public void Union(int a, int b) {
a = Root(a);
b = Root(b);
if (a != b) {
if (hi[a] < hi[b]) {
a ^= b;
b ^= a;
a ^= b;
}
arr[a] += arr[b];
hi[a] = Math.Max(hi[a], hi[b] + 1);
arr[b] = a;
all--;
}
}
public bool Same(int a, int b) { return Root(a) == Root(b); }
public int Size(int a) { return -arr[Root(a)]; }
public int Root(int a) { return arr[a] < 0 ? a : arr[a] = Root(arr[a]); }
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
int.Parse);
}
public int[] Ia3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
long.Parse);
}
public long[] La3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
double.Parse);
}
public double[] Da3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
double.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
[["-", 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, 21], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 1,553
| 26
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = (int)1e9 + 7;
static void Main() {
Sc sc = new Sc();
var n = sc.I;
var t = "X" + sc.S;
int m = sc.I;
St st = new St(n + 1);
for (int i = 1; i <= n; i++) {
st.Ud(i, t[i] - 96);
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < m; i++) {
var e = sc.Sa;
if (e[0] == "1") {
st.Ud(int.Parse(e[1]), e[2][0] - 96);
} else {
sb.Append(bits(st.Get(int.Parse(e[1]), int.Parse(e[2]))) + "\n");
}
}
Console.Write(sb);
}
static int bits(long bits) {
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (int)((bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff));
}
}
public class St {
private long[] dat;
private int m = 1, cnt = 0;
public St(int n) {
while (m < n) {
m <<= 1;
}
cnt = m + n - 1;
dat = new long[cnt];
}
public void Ud(int q, long b) {
q += m - 1;
dat[q] = b;
while (true) {
q = (q - 1) >> 1;
if ((q << 1) + 2 < cnt) {
dat[q] = dat[(q << 1) + 1] | dat[(q << 1) + 2];
} else {
dat[q] = dat[(q << 1) + 1];
}
if (q == 0) {
break;
}
}
}
private long Fdg(int a, int b, int k, int l, int r) {
if (r < a || b < l) {
return 0;
}
if (a <= l && r <= b) {
return dat[k];
} else {
return Fdg(a, b, k * 2 + 1, l, (l + r) >> 1) |
Fdg(a, b, k * 2 + 2, (l + r + 1) >> 1, r);
}
}
public long Get(int a, int b) { return Fdg(a, b, 0, 0, m - 1); }
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
int.Parse);
}
public int[] Ia3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
long.Parse);
}
public long[] La3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
double.Parse);
}
public double[] Da3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
double.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = (int)1e9 + 7;
static void Main() {
Sc sc = new Sc();
var n = sc.I;
var t = "X" + sc.S;
int m = sc.I;
St st = new St(n + 1);
for (int i = 1; i <= n; i++) {
st.Ud(i, 1 << (t[i] - 97));
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < m; i++) {
var e = sc.Sa;
if (e[0] == "1") {
st.Ud(int.Parse(e[1]), 1 << (e[2][0] - 97));
} else {
sb.Append(bits(st.Get(int.Parse(e[1]), int.Parse(e[2]))) + "\n");
}
}
Console.Write(sb);
}
static int bits(long bits) {
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (int)((bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff));
}
}
public class St {
private long[] dat;
private int m = 1, cnt = 0;
public St(int n) {
while (m < n) {
m <<= 1;
}
cnt = m + n - 1;
dat = new long[cnt];
}
public void Ud(int q, long b) {
q += m - 1;
dat[q] = b;
while (q > 0) {
q = (q - 1) >> 1;
if ((q << 1) + 2 < cnt) {
dat[q] = dat[(q << 1) + 1] | dat[(q << 1) + 2];
} else {
dat[q] = dat[(q << 1) + 1];
}
}
}
private long Fdg(int a, int b, int k, int l, int r) {
if (r < a || b < l) {
return 0;
}
if (a <= l && r <= b) {
return dat[k];
} else {
return Fdg(a, b, k * 2 + 1, l, (l + r) >> 1) |
Fdg(a, b, k * 2 + 2, (l + r + 1) >> 1, r);
}
}
public long Get(int a, int b) { return Fdg(a, b, 0, 0, m - 1); }
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
int.Parse);
}
public int[] Ia3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
long.Parse);
}
public long[] La3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
double.Parse);
}
public double[] Da3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
double.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 151], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["-", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 203], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["-", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
| 8
| 1,611
| 26
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
var cin = new Scanner2();
int n = cin.Int();
string s = cin.Next();
int q = cin.Int();
char[] ss = s.ToArray();
var segs = new LazySegmentTree<int>[26];
for (int i = 0; i < 26; i++) {
segs[i] = new LazySegmentTree<int>(n + 1, 0, (x, y) => x + y);
}
for (int i = 0; i < n; i++) {
var c = s[i] - 'a';
segs[c].Update(i + 1, n + 1, 1);
}
var sb = new StringBuilder();
for (int i = 0; i < q; i++) {
int qq = cin.Int();
if (qq == 1) {
int ii = cin.Int() - 1;
char c = (char)(cin.Next()[0] - 'a');
if (ss[ii] != c) {
int c2 = ss[ii] - 'a';
ss[ii] = c;
segs[c2].Update(ii + 1, n + 1, -1);
segs[c].Update(ii + 1, n + 1, 1);
}
} else {
int l = cin.Int() - 1;
int r = cin.Int();
int cnt = 0;
for (int j = 0; j < 26; j++) {
if (segs[j].Query(r) - segs[j].Query(l) > 0) {
cnt++;
}
}
sb.AppendLine(cnt.ToString());
}
}
Console.WriteLine(sb.ToString());
}
}
public class LazySegmentTree<T> {
private readonly int n_;
private readonly T unit_;
private readonly T[] tree_;
private readonly bool[] should_;
private readonly Func<T, T, T> merge_;
public int Count { get; }
public LazySegmentTree(int count, T unit, Func<T, T, T> merge) {
merge_ = merge;
unit_ = unit;
Count = count;
n_ = 1;
while (n_ < count) {
n_ <<= 1;
}
tree_ = new T[n_ << 1];
should_ = new bool[n_ << 1];
for (int i = 0; i < tree_.Length; i++) {
tree_[i] = unit;
}
}
public T this[int i] {
get { return Query(i); }
}
public void Update(int left, int right, T item) {
UpdateCore(left, right, 1, 0, n_, item);
}
public T Query(int i) {
int l = 0;
int r = n_;
int k = 1;
while (r - l > 1) {
Evaluate(k, l, r);
int m = (l + r) / 2;
if (i < m) {
r = m;
k = k << 1;
} else {
l = m;
k = (k << 1) + 1;
}
}
return tree_[k];
}
private void Evaluate(int k, int l, int r) {
if (should_[k]) {
if (r - l > 1) {
tree_[k << 1] = merge_(tree_[k << 1], tree_[k]);
should_[k << 1] = true;
tree_[(k << 1) + 1] = merge_(tree_[(k << 1) + 1], tree_[k]);
should_[(k << 1) + 1] = true;
tree_[k] = unit_;
}
should_[k] = false;
}
}
private void UpdateCore(int left, int right, int k, int l, int r, T item) {
Evaluate(k, l, r);
if (r <= left || right <= l) {
return;
}
if (left <= l && r <= right) {
tree_[k] = merge_(tree_[k], item);
should_[k] = true;
Evaluate(k, l, r);
return;
}
UpdateCore(left, right, k << 1, l, (l + r) / 2, item);
UpdateCore(left, right, (k << 1) + 1, (l + r) / 2, r, item);
}
}
public class Scanner2 {
private readonly char[] delimiter_ = new char[] { ' ' };
private readonly string filePath_;
private readonly Func<string> reader_;
private string[] buf_;
private int index_;
public Scanner2(string file = "") {
if (string.IsNullOrWhiteSpace(file)) {
reader_ = Console.ReadLine;
} else {
filePath_ = file;
var fs = new StreamReader(file);
reader_ = fs.ReadLine;
}
buf_ = new string[0];
index_ = 0;
}
public string Next() {
if (index_ < buf_.Length) {
return buf_[index_++];
}
string st = reader_();
while (st == "") {
st = reader_();
}
buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
if (buf_.Length == 0) {
return Next();
}
index_ = 0;
return buf_[index_++];
}
public int Int() => int.Parse(Next());
public long Long() => long.Parse(Next());
public double Double() => double.Parse(Next());
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
public void Save(string text) {
if (string.IsNullOrWhiteSpace(filePath_)) {
return;
}
File.WriteAllText(filePath_ + "_output.txt", text);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
var cin = new Scanner2();
int n = cin.Int();
string s = cin.Next();
int q = cin.Int();
char[] ss = s.Select(x => (char)(x - 'a')).ToArray();
var segs = new LazySegmentTree<int>[26];
for (int i = 0; i < 26; i++) {
segs[i] = new LazySegmentTree<int>(n + 1, 0, (x, y) => x + y);
}
for (int i = 0; i < n; i++) {
var c = s[i] - 'a';
segs[c].Update(i + 1, n + 1, 1);
}
var sb = new StringBuilder();
for (int i = 0; i < q; i++) {
int qq = cin.Int();
if (qq == 1) {
int ii = cin.Int() - 1;
char c = (char)(cin.Next()[0] - 'a');
if (ss[ii] != c) {
int c2 = ss[ii];
ss[ii] = c;
segs[c2].Update(ii + 1, n + 1, -1);
segs[c].Update(ii + 1, n + 1, 1);
}
} else {
int l = cin.Int() - 1;
int r = cin.Int();
int cnt = 0;
for (int j = 0; j < 26; j++) {
if (segs[j].Query(r) - segs[j].Query(l) > 0) {
cnt++;
}
}
sb.AppendLine(cnt.ToString());
}
}
Console.WriteLine(sb.ToString());
}
}
public class LazySegmentTree<T> {
private readonly int n_;
private readonly T unit_;
private readonly T[] tree_;
private readonly bool[] should_;
private readonly Func<T, T, T> merge_;
public int Count { get; }
public LazySegmentTree(int count, T unit, Func<T, T, T> merge) {
merge_ = merge;
unit_ = unit;
Count = count;
n_ = 1;
while (n_ < count) {
n_ <<= 1;
}
tree_ = new T[n_ << 1];
should_ = new bool[n_ << 1];
for (int i = 0; i < tree_.Length; i++) {
tree_[i] = unit;
}
}
public T this[int i] {
get { return Query(i); }
}
public void Update(int left, int right, T item) {
UpdateCore(left, right, 1, 0, n_, item);
}
public T Query(int i) {
int l = 0;
int r = n_;
int k = 1;
while (r - l > 1) {
Evaluate(k, l, r);
int m = (l + r) / 2;
if (i < m) {
r = m;
k = k << 1;
} else {
l = m;
k = (k << 1) + 1;
}
}
return tree_[k];
}
private void Evaluate(int k, int l, int r) {
if (should_[k]) {
if (r - l > 1) {
tree_[k << 1] = merge_(tree_[k << 1], tree_[k]);
should_[k << 1] = true;
tree_[(k << 1) + 1] = merge_(tree_[(k << 1) + 1], tree_[k]);
should_[(k << 1) + 1] = true;
tree_[k] = unit_;
}
should_[k] = false;
}
}
private void UpdateCore(int left, int right, int k, int l, int r, T item) {
Evaluate(k, l, r);
if (r <= left || right <= l) {
return;
}
if (left <= l && r <= right) {
tree_[k] = merge_(tree_[k], item);
should_[k] = true;
Evaluate(k, l, r);
return;
}
UpdateCore(left, right, k << 1, l, (l + r) / 2, item);
UpdateCore(left, right, (k << 1) + 1, (l + r) / 2, r, item);
}
}
public class Scanner2 {
private readonly char[] delimiter_ = new char[] { ' ' };
private readonly string filePath_;
private readonly Func<string> reader_;
private string[] buf_;
private int index_;
public Scanner2(string file = "") {
if (string.IsNullOrWhiteSpace(file)) {
reader_ = Console.ReadLine;
} else {
filePath_ = file;
var fs = new StreamReader(file);
reader_ = fs.ReadLine;
}
buf_ = new string[0];
index_ = 0;
}
public string Next() {
if (index_ < buf_.Length) {
return buf_[index_++];
}
string st = reader_();
while (st == "") {
st = reader_();
}
buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
if (buf_.Length == 0) {
return Next();
}
index_ = 0;
return buf_[index_++];
}
public int Int() => int.Parse(Next());
public long Long() => long.Parse(Next());
public double Double() => double.Parse(Next());
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
public void Save(string text) {
if (string.IsNullOrWhiteSpace(filePath_)) {
return;
}
File.WriteAllText(filePath_ + "_output.txt", text);
}
}
}
|
[["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 0, 25], ["+", 0, 28, 0, 218, 8, 74, 51, 23, 0, 24], ["+", 0, 218, 8, 74, 51, 23, 0, 16, 31, 22], ["+", 0, 218, 8, 74, 51, 23, 0, 16, 17, 33], ["+", 8, 74, 51, 23, 0, 16, 12, 252, 0, 104], ["+", 8, 74, 51, 23, 0, 16, 12, 252, 0, 253], ["+", 0, 28, 0, 218, 8, 74, 51, 23, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 200, 0, 212, 0, 16, 12, 252, 0, 104], ["-", 0, 200, 0, 212, 0, 16, 12, 252, 0, 253]]
| 8
| 1,452
| 20
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace V {
partial class Solver {
public void Solve() {
long n = Read;
char[] s = Str.ToArray();
long q = Read;
var st = Enumerable.Range(0, 26)
.Select(x => (char)('a' + x))
.ToDictionary(x => x, x => new C.BinaryIndexTree(n));
var idx = 0;
foreach (var c in s) {
st[c].Add(idx, 1);
idx++;
}
foreach (var _ in C.Loop(q)) {
var type = Read;
if (type == 1) {
var i = Read - 1;
var newC = Str[0];
var oldC = s[i];
st[oldC].Add(i, -1);
st[newC].Add(i, 1);
} else {
var l = Read - 1;
var r = Read - 1;
var res = st.Values.Select(x => x.Sum(r) - x.Sum(l - 1))
.Where(x => x > 0)
.Count();
Wr(res);
}
}
// Write(SolveLong());
// YesNo(SolveBool());
}
public long SolveLong() {
long n = Read;
return 0;
}
public bool SolveBool() {
long n = Read;
return false;
}
}
}
namespace V {
class StartingPoint {
static void Main(string[] args) {
try {
var streamReader = args.Any()
? new StreamReader(args[0])
: new StreamReader(Console.OpenStandardInput());
var streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
var scanner = new Scanner(streamReader);
var printer = new Printer(streamWriter);
var solver = new Solver(scanner, printer);
solver.Solve();
streamWriter.Flush();
} catch (Exception e) {
Console.WriteLine(e);
if (args.Any() == false)
throw e;
}
if (args.Any())
Console.ReadKey();
}
}
}
namespace V {
partial class Solver {
public Solver(Scanner sc, Printer pr) {
this.sc = sc;
this.pr = pr;
}
private readonly Scanner sc;
private readonly Printer pr;
private IEnumerable<int> Loop(int n) => C.Loop(n);
private IEnumerable<long> Loop(long n) => C.Loop(n);
private int RdInt => sc.Int;
private int ReadInt => sc.Int;
private long Rd => sc.Long;
private long Read => sc.Long;
private long ReadLong => sc.Long;
private double RdDouble => sc.Double;
private double ReadDouble => sc.Double;
private string Str => sc.Str;
private string RdStr => sc.Str;
private string ReadStr => sc.Str;
private int[] ArrInt(int n) => sc.Ints(n);
private int[] ArrInt(long n) => sc.Ints(n);
private long[] Arr(int n) => sc.Longs(n);
private long[] Arr(long n) => sc.Longs(n);
private long[] ArrLong(int n) => sc.Longs(n);
private long[] ArrLong(long n) => sc.Longs(n);
private double[] ArrDouble(int n) => sc.Doubles(n);
private double[] ArrDouble(long n) => sc.Doubles(n);
private string[] ArrStr(int n) => sc.Strs(n);
private string[] ArrStr(long n) => sc.Strs(n);
private void Wr(string s) => pr.Write(s);
private void Wr(object obj) => pr.Write(obj);
private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts);
private void Wr(params object[] objs) => pr.Write(objs);
private void Write(string s) => pr.Write(s);
private void Write(object obj) => pr.Write(obj);
private void Write<T>(IEnumerable<T> ts) => pr.Write(ts);
private void Write(params object[] objs) => pr.Write(objs);
private void YesNo(bool b) => Write(b ? "Yes" : "No");
private void YESNO(bool b) => Write(b ? "YES" : "NO");
}
class Scanner {
private readonly TextReader reader;
public Scanner(TextReader reader) { this.reader = reader; }
private Queue<string> strQueue = new Queue<string>();
public string Str {
get {
if (strQueue.Count > 0)
return strQueue.Dequeue();
string[] strs = null;
do {
strs = reader.ReadLine().Split(new[] { ' ' },
StringSplitOptions.RemoveEmptyEntries);
} while (strs.Any() == false);
foreach (var s in strs.Skip(1))
strQueue.Enqueue(s);
return strs[0];
}
}
public int Int => int.Parse(this.Str);
public long Long => long.Parse(this.Str);
public double Double => double.Parse(this.Str);
public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2));
public static T1
ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1));
public static T1 Convert<T1>(string s) =>
TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s))
: TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s))
: TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s))
: TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0])
: ChangeTypes<T1, string>(s);
public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str),
Convert<TY>(this.Str));
public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>(
Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str));
public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() =>
new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str),
Convert<TZ>(this.Str), Convert<TW>(this.Str));
}
static class ScannerExtension {
public static int[] Ints(this Scanner scanner,
int n) => scanner.Ints((long)n);
public static int[] Ints(this Scanner scanner,
long n) => scanner.ScanStrs<int>(n).ToArray();
public static long[] Longs(this Scanner scanner,
int n) => scanner.Longs((long)n);
public static long[] Longs(this Scanner scanner,
long n) => scanner.ScanStrs<long>(n).ToArray();
public static double[] Doubles(this Scanner scanner,
int n) => scanner.Doubles((long)n);
public static double[] Doubles(this Scanner scanner, long n) =>
scanner.ScanStrs<double>(n).ToArray();
public static string[] Strs(this Scanner scanner,
int n) => scanner.Strs((long)n);
public static string[] Strs(this Scanner scanner,
long n) => scanner.ScanStrs<string>(n).ToArray();
private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return Scanner.Convert<T>(scanner.Str);
}
public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) =>
scanner.Pairs<TX, TY>((long)n);
public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) =>
scanner.ScanPairs<TX, TY>(n).ToArray();
public static Pair<long, long>[] Pairs(this Scanner scanner,
int n) => scanner.Pairs((long)n);
public static Pair<long, long>[] Pairs(this Scanner scanner, long n) =>
scanner.ScanPairs<long, long>(n).ToArray();
public static Pair<int, int>[] PairsInt(this Scanner scanner,
int n) => scanner.PairsInt((long)n);
public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) =>
scanner.ScanPairs<int, int>(n).ToArray();
private static IEnumerable<Pair<TX, TY>>
ScanPairs<TX, TY>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return scanner.P2<TX, TY>();
}
public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(
this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n);
public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner,
long n) =>
scanner.ScanPairs3<TX, TY, TZ>(n).ToArray();
public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) =>
scanner.Pairs3((long)n);
public static Pair3<long, long, long>[] Pairs3(this Scanner scanner,
long n) =>
scanner.ScanPairs3<long, long, long>(n).ToArray();
public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) =>
scanner.Pairs3Int((long)n);
public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner,
long n) =>
scanner.ScanPairs3<int, int, int>(n).ToArray();
private static IEnumerable<Pair3<TX, TY, TZ>>
ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return scanner.P3<TX, TY, TZ>();
}
public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>(
this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n);
public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>(
this Scanner scanner,
long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray();
public static Pair4<long, long, long, long>[] Pairs4(
this Scanner scanner, int n) => scanner.Pairs4((long)n);
public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner,
long n) =>
scanner.ScanPairs4<long, long, long, long>(n).ToArray();
public static Pair4<int, int, int, int>[] Pairs4Int(
this Scanner scanner, int n) => scanner.Pairs4Int((long)n);
public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner,
long n) =>
scanner.ScanPairs4<int, int, int, int>(n).ToArray();
private static IEnumerable<Pair4<TX, TY, TZ, TW>>
ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return scanner.P4<TX, TY, TZ, TW>();
}
}
class Pair<TX, TY> {
public TX X { get; }
public TY Y { get; }
public Pair(TX x, TY y) {
this.X = x;
this.Y = y;
}
}
class Pair : Pair<long, long> {
public Pair(long x, long y) : base(x, y) {}
}
class PairInt : Pair<int, int> {
public PairInt(int x, int y) : base(x, y) {}
}
class Pair3<TX, TY, TZ> {
public TX X { get; }
public TY Y { get; }
public TZ Z { get; }
public Pair3(TX x, TY y, TZ z) {
this.X = x;
this.Y = y;
this.Z = z;
}
}
class Pair3 : Pair3<long, long, long> {
public Pair3(long x, long y, long z) : base(x, y, z) {}
}
class Pair3Int : Pair3<int, int, int> {
public Pair3Int(int x, int y, int z) : base(x, y, z) {}
}
class Pair4<TX, TY, TZ, TW> {
public TX X { get; }
public TY Y { get; }
public TZ Z { get; }
public TW W { get; }
public Pair4(TX x, TY y, TZ z, TW w) {
this.X = x;
this.Y = y;
this.Z = z;
this.W = w;
}
}
class Pair4 : Pair4<long, long, long, long> {
public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {}
}
class Pair4Int : Pair4<int, int, int, int> {
public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {}
}
class Printer {
private readonly TextWriter writer;
public Printer(TextWriter writer) { this.writer = writer; }
public void Write(string obj) { writer.WriteLine(obj); }
public void Write(object obj) { writer.WriteLine(obj); }
public void Write<T>(IEnumerable<T> ts) {
writer.WriteLine(string.Join(" ", ts));
}
public void Write(params object[] objs) {
writer.WriteLine(string.Join(" ", objs));
}
}
static class Extension {
public static bool TryRemove<T>(this HashSet<T> ts, T t) {
if (ts.Contains(t)) {
ts.Remove(t);
return true;
} else {
return false;
}
}
public static HashSet<T>
ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct());
public static long ToDigit(this char c) => (long)(c - '0');
public static long ToSmallAbcIndex(this char c) => (long)(c - 'a');
public static long ToLargeAbcIndex(this char c) => (long)(c - 'A');
public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount();
}
class C {
public class Tree {
public Tree() { to = new Dictionary<long, long[]>(); }
public Tree(Scanner sc, long n, bool base1 = true,
bool singleDirection = false) {
Adjust(sc.Pairs(n), base1, singleDirection);
}
public Tree(Pair<long, long>[] edges, bool base1 = true,
bool singleDirection = false) {
Adjust(edges, base1, singleDirection);
}
public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true,
bool singleDirection = false) {
Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1,
singleDirection);
}
private void Adjust(Pair<long, long>[] edges, bool base1,
bool singleDirection) {
var arrows = base1
? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 })
: edges.Select(x => new { from = x.X, to = x.Y });
if (singleDirection == false)
arrows =
arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from }));
to = arrows.GroupBy(x => x.from)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray());
}
private long[] empty = new long[0];
private Dictionary<long, long[]> to;
public long[] To(long from) {
long[] res = null;
if (to.TryGetValue(from, out res))
return res;
else
return empty;
}
}
public class PriorityQueue<TKey, TState>
where TKey : IComparable<TKey> {
public int Count { get; private set; }
private readonly Func<TState, TKey> keySelector;
private readonly bool desc;
private TState[] states = new TState[65536];
private TKey[] keys = new TKey[65536];
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) {
this.keySelector = keySelector;
this.desc = desc;
}
public TState Top {
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
ValidateNonEmpty();
return states[1];
}
}
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TState Dequeue() {
var top = Top;
var item = states[Count];
var key = keys[Count];
Count--;
int index = 1;
while (true) {
if ((index << 1) >= Count) {
if (index << 1 > Count)
break;
if (key.CompareTo(keys[index << 1]) <= 0 ^ desc)
break;
states[index] = states[index << 1];
keys[index] = keys[index << 1];
index <<= 1;
} else {
var nextIndex =
keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc
? (index << 1)
: (index << 1) + 1;
if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc)
break;
states[index] = states[nextIndex];
keys[index] = keys[nextIndex];
index = nextIndex;
}
}
states[index] = item;
keys[index] = key;
return top;
}
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(TState state) {
var key = keySelector.Invoke(state);
Count++;
int index = Count;
if (states.Length == Count)
Extend(states.Length * 2);
while ((index >> 1) != 0) {
if (keys[index >> 1].CompareTo(key) <= 0 ^ desc)
break;
states[index] = states[index >> 1];
keys[index] = keys[index >> 1];
index >>= 1;
}
states[index] = state;
keys[index] = key;
}
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Extend(int newSize) {
TState[] newStates = new TState[newSize];
TKey[] newKeys = new TKey[newSize];
states.CopyTo(newStates, 0);
keys.CopyTo(newKeys, 0);
states = newStates;
keys = newKeys;
}
private void ValidateNonEmpty() {
if (Count == 0)
throw new IndexOutOfRangeException();
}
}
public class BinaryIndexTree {
long length;
long[] binaryIndexedTree;
public BinaryIndexTree(long length) {
this.length = length;
binaryIndexedTree = new long[length + 1];
}
public void Add(long indexZeroBase, long additional) {
// i += i & -i
// 1が立っている最下位ビットを足す、の意味
for (long i = indexZeroBase + 1; i <= length; i += i & -i) {
binaryIndexedTree[i] += additional;
}
}
public long Sum(long indexZeroBase) {
long result = 0;
// i += i & -i
// 1が立っている最下位ビットを引く、の意味
for (long i = indexZeroBase + 1; i > 0; i -= i & -i) {
result += binaryIndexedTree[i];
}
return result;
}
}
public static class BinarySearch {
public static int GetFirstIndexGreater(long x, ref List<long> listOrdered) {
var count = listOrdered.Count;
if (count == 0)
return 0;
if (listOrdered[count - 1] <= x)
return count;
int low = 0;
int high = listOrdered.Count - 1;
while (low < high) {
var mid = (low + high) / 2;
if (listOrdered[mid] > x)
high = mid;
else
low = mid + 1;
}
return low;
}
public static int GetFirstIndexGreater(int x, ref List<int> listOrdered) {
var count = listOrdered.Count;
if (count == 0)
return 0;
if (listOrdered[count - 1] <= x)
return count;
int low = 0;
int high = listOrdered.Count - 1;
while (low < high) {
var mid = (low + high) / 2;
if (listOrdered[mid] > x)
high = mid;
else
low = mid + 1;
}
return low;
}
public static int GetLastIndexLess(long x, ref List<long> listOrdered) {
var count = listOrdered.Count;
if (count == 0)
return -1;
if (listOrdered[0] >= x)
return -1;
int low = 0;
int high = listOrdered.Count - 1;
while (low < high) {
var mid = (low + high + 1) / 2;
if (listOrdered[mid] < x)
low = mid;
else
high = mid - 1;
}
return low;
}
public static int GetLastIndexLess(int x, ref List<int> listOrdered) {
var count = listOrdered.Count;
if (count == 0)
return -1;
if (listOrdered[0] >= x)
return -1;
int low = 0;
int high = listOrdered.Count - 1;
while (low < high) {
var mid = (low + high + 1) / 2;
if (listOrdered[mid] < x)
low = mid;
else
high = mid - 1;
}
return low;
}
}
public static class BellmanFord {
public class Vertex {
public long Distance { get; set; }
public Vertex() { Distance = long.MaxValue; }
}
public class Edge {
public int From { get; private set; }
public int To { get; private set; }
public long Weight { get; private set; }
public Edge(int from, int to, long weight) {
From = from;
To = to;
Weight = weight;
}
}
private static void GetReachable(int origin, ref HashSet<int> reached,
ref Dictionary<int, int[]> paths) {
if (reached.Contains(origin))
return;
reached.Add(origin);
if (paths.ContainsKey(origin) == false)
return;
foreach (var p in paths[origin])
GetReachable(p, ref reached, ref paths);
}
/// <summary>
/// null: 負の無限大
/// long.MaxValue: たどり着けない
/// その他: 距離
/// </summary>
public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges,
int source, int dest) {
var forwards =
rawEdges.GroupBy(x => x.From)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(
x => x.Key, x => x.Select(xs => xs.From).ToArray());
var fromSource = new HashSet<int>();
var toDest = new HashSet<int>();
GetReachable(source, ref fromSource, ref forwards);
GetReachable(dest, ref toDest, ref reverses);
var edges = rawEdges.Where(e => fromSource.Contains(e.From))
.Where(e => fromSource.Contains(e.To))
.Where(e => toDest.Contains(e.From))
.Where(e => toDest.Contains(e.To))
.ToArray();
// initialize distances
var vertices = new List<Vertex>();
for (int i = 0; i < vertexCount; i++)
vertices.Add(new Vertex());
vertices[source].Distance = 0L;
// update distances
for (int i = 0; i < vertices.Count; i++) {
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance == long.MaxValue)
continue;
var newDistance = from.Distance + e.Weight;
if (to.Distance > newDistance) {
to.Distance = newDistance;
}
}
}
// check negative cycle
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance + e.Weight < to.Distance)
return null;
}
return vertices[dest].Distance;
}
}
public static long Gcd(int a, int b) => Gcd((long)a, (long)b);
public static long Gcd(long a, long b) {
if (a < b)
return GcdImpl(b, a);
else
return GcdImpl(a, b);
}
private static long GcdImpl(long a, long b) {
var remainder = a % b;
if (remainder == 0)
return b;
else
return GcdImpl(b, remainder);
}
public static long Lcm(int a, int b) => Lcm((long)a, (long)b);
public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
public static long Pow(int n, int p) => Pow((long)n, (long)p);
public static long Pow(long n, long p) {
var res = 1L;
for (long i = 0; i < p; i++)
res *= n;
return res;
}
public static Dictionary<long, long> Factorize(int n) => Factorize((long)n);
public static Dictionary<long, long> Factorize(long n) {
var res = new Dictionary<long, long>();
var r = n;
for (long i = 2; i * i <= r; i++) {
var c = 0L;
while (r % i == 0) {
c++;
r /= i;
}
if (c > 0)
res.Add(i, c);
}
if (r > 1)
res.Add(r, 1);
return res;
}
public static IEnumerable<long> Divisors(int n) => Divisors((long)n);
public static IEnumerable<long> Divisors(long n) {
var cache = new Stack<long>();
for (long i = 1; i * i <= n; i++) {
if (n % i == 0) {
yield return i;
cache.Push(i);
}
}
var r = cache.Peek();
if (r * r == n)
cache.Pop();
while (cache.Count > 0) {
var i = cache.Pop();
yield return n / i;
}
}
public static IEnumerable<int> Loop(int n) {
for (int i = 0; i < n; i++)
yield return i;
}
public static IEnumerable<long> Loop(long n) {
for (long i = 0L; i < n; i++)
yield return i;
}
}
struct Mint {
public static long Divider {
set { divider = value; }
}
private static long divider = 1000000007L;
public static void Set998244353() { divider = 998244353L; }
public static void Set1000000009() { divider = 1000000009L; }
public long Value { get; }
public override string ToString() => this.Value.ToString();
public Mint(long value) { this.Value = value; }
// public static implicit operator Mint(long a) => new Mint(a % divider);
// public static implicit operator Mint(int a) => new Mint(a % divider);
// public static explicit operator long(Mint a) => a.Value;
// public static explicit operator int(Mint a) => (int)a.Value;
public static Mint
operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider);
public static Mint operator +(Mint a, long b) => a + new Mint(b);
public static Mint operator +(Mint a, int b) => a + new Mint(b);
public static Mint operator -(Mint a, Mint b) {
var t = (a.Value - b.Value) % divider;
if (t < 0L)
t += divider;
return new Mint(t);
}
public static Mint operator -(Mint a, long b) => a - new Mint(b);
public static Mint operator -(Mint a, int b) => a - new Mint(b);
public static Mint
operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider);
public static Mint operator *(Mint a, long b) => a * new Mint(b);
public static Mint operator *(Mint a, int b) => a * new Mint(b);
public static Mint operator /(Mint a, Mint b) =>
new Mint((a.Value * InvImpl(b.Value)) % divider);
public static Mint operator /(Mint a, long b) => a / new Mint(b);
public static Mint operator /(Mint a, int b) => a / new Mint(b);
public Mint Pow(long p) => new Mint(PowImpl(Value, p));
public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p));
private static long PowImpl(long a, long p) {
if (p == 0L)
return 1L;
if (p == 1L)
return a;
var halfP = p / 2L;
var halfPowered = PowImpl(a, halfP);
var powered = halfPowered * halfPowered % divider;
return p % 2L == 0L ? powered : powered * a % divider;
}
public static Mint Inv(long a) => new Mint(InvImpl(a));
private static readonly Dictionary<long, long> invCache =
new Dictionary<long, long>();
private static long InvImpl(long a) {
long cache;
if (invCache.TryGetValue(a, out cache))
return cache;
var result = PowImpl(a, divider - 2L);
invCache.Add(a, result);
return result;
}
public static Mint Fac(long a) => new Mint(FacImpl(a));
private static long[] facCache = new long[262144];
private static long cachedFac = 0L;
private static long FacImpl(long a) {
if (a >= divider)
return 0L;
facCache[0] = 1L;
if (facCache.LongLength <= a) {
long newSize = facCache.LongLength;
while (newSize <= a) {
newSize *= 2;
}
ExtendFacCache(newSize);
}
if (cachedFac < a) {
var val = facCache[cachedFac];
var start = cachedFac + 1L;
for (long i = start; i <= a; i++) {
val = (val * i) % divider;
facCache[i] = val;
}
cachedFac = a;
}
return facCache[a];
}
private static void ExtendFacCache(long newSize) {
long[] newFacCache = new long[newSize];
facCache.CopyTo(newFacCache, 0);
facCache = newFacCache;
}
public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r));
private static long PermImpl(long n, long r) {
if (n < r)
return 0L;
if (r <= 0L)
return 1L;
var nn = FacImpl(n);
var nr = FacImpl(n - r);
return (nn * InvImpl(nr)) % divider;
}
public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r));
private static long CombImpl(long n, long r) {
if (n < r)
return 0L;
if (n == r)
return 1L;
if (n - r < r)
return CombImpl(n, n - r);
var nn = FacImpl(n);
var nr = FacImpl(n - r);
var rr = FacImpl(r);
var nrrr = (nr * rr) % divider;
return (nn * InvImpl(nrrr)) % divider;
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace V {
partial class Solver {
public void Solve() {
long n = Read;
char[] s = Str.ToArray();
long q = Read;
var st = Enumerable.Range(0, 26)
.Select(x => (char)('a' + x))
.ToDictionary(x => x, x => new C.BinaryIndexTree(n));
var idx = 0;
foreach (var c in s) {
st[c].Add(idx, 1);
idx++;
}
foreach (var _ in C.Loop(q)) {
var type = Read;
if (type == 1) {
var i = Read - 1;
var newC = Str[0];
var oldC = s[i];
s[i] = newC;
st[oldC].Add(i, -1);
st[newC].Add(i, 1);
} else {
var l = Read - 1;
var r = Read - 1;
var res = st.Values.Select(x => x.Sum(r) - x.Sum(l - 1))
.Where(x => x > 0)
.Count();
Wr(res);
}
}
// Write(SolveLong());
// YesNo(SolveBool());
}
public long SolveLong() {
long n = Read;
return 0;
}
public bool SolveBool() {
long n = Read;
return false;
}
}
}
namespace V {
class StartingPoint {
static void Main(string[] args) {
try {
var streamReader = args.Any()
? new StreamReader(args[0])
: new StreamReader(Console.OpenStandardInput());
var streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
var scanner = new Scanner(streamReader);
var printer = new Printer(streamWriter);
var solver = new Solver(scanner, printer);
solver.Solve();
streamWriter.Flush();
} catch (Exception e) {
Console.WriteLine(e);
if (args.Any() == false)
throw e;
}
if (args.Any())
Console.ReadKey();
}
}
}
namespace V {
partial class Solver {
public Solver(Scanner sc, Printer pr) {
this.sc = sc;
this.pr = pr;
}
private readonly Scanner sc;
private readonly Printer pr;
private IEnumerable<int> Loop(int n) => C.Loop(n);
private IEnumerable<long> Loop(long n) => C.Loop(n);
private int RdInt => sc.Int;
private int ReadInt => sc.Int;
private long Rd => sc.Long;
private long Read => sc.Long;
private long ReadLong => sc.Long;
private double RdDouble => sc.Double;
private double ReadDouble => sc.Double;
private string Str => sc.Str;
private string RdStr => sc.Str;
private string ReadStr => sc.Str;
private int[] ArrInt(int n) => sc.Ints(n);
private int[] ArrInt(long n) => sc.Ints(n);
private long[] Arr(int n) => sc.Longs(n);
private long[] Arr(long n) => sc.Longs(n);
private long[] ArrLong(int n) => sc.Longs(n);
private long[] ArrLong(long n) => sc.Longs(n);
private double[] ArrDouble(int n) => sc.Doubles(n);
private double[] ArrDouble(long n) => sc.Doubles(n);
private string[] ArrStr(int n) => sc.Strs(n);
private string[] ArrStr(long n) => sc.Strs(n);
private void Wr(string s) => pr.Write(s);
private void Wr(object obj) => pr.Write(obj);
private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts);
private void Wr(params object[] objs) => pr.Write(objs);
private void Write(string s) => pr.Write(s);
private void Write(object obj) => pr.Write(obj);
private void Write<T>(IEnumerable<T> ts) => pr.Write(ts);
private void Write(params object[] objs) => pr.Write(objs);
private void YesNo(bool b) => Write(b ? "Yes" : "No");
private void YESNO(bool b) => Write(b ? "YES" : "NO");
}
class Scanner {
private readonly TextReader reader;
public Scanner(TextReader reader) { this.reader = reader; }
private Queue<string> strQueue = new Queue<string>();
public string Str {
get {
if (strQueue.Count > 0)
return strQueue.Dequeue();
string[] strs = null;
do {
strs = reader.ReadLine().Split(new[] { ' ' },
StringSplitOptions.RemoveEmptyEntries);
} while (strs.Any() == false);
foreach (var s in strs.Skip(1))
strQueue.Enqueue(s);
return strs[0];
}
}
public int Int => int.Parse(this.Str);
public long Long => long.Parse(this.Str);
public double Double => double.Parse(this.Str);
public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2));
public static T1
ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1));
public static T1 Convert<T1>(string s) =>
TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s))
: TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s))
: TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s))
: TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0])
: ChangeTypes<T1, string>(s);
public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str),
Convert<TY>(this.Str));
public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>(
Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str));
public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() =>
new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str),
Convert<TZ>(this.Str), Convert<TW>(this.Str));
}
static class ScannerExtension {
public static int[] Ints(this Scanner scanner,
int n) => scanner.Ints((long)n);
public static int[] Ints(this Scanner scanner,
long n) => scanner.ScanStrs<int>(n).ToArray();
public static long[] Longs(this Scanner scanner,
int n) => scanner.Longs((long)n);
public static long[] Longs(this Scanner scanner,
long n) => scanner.ScanStrs<long>(n).ToArray();
public static double[] Doubles(this Scanner scanner,
int n) => scanner.Doubles((long)n);
public static double[] Doubles(this Scanner scanner, long n) =>
scanner.ScanStrs<double>(n).ToArray();
public static string[] Strs(this Scanner scanner,
int n) => scanner.Strs((long)n);
public static string[] Strs(this Scanner scanner,
long n) => scanner.ScanStrs<string>(n).ToArray();
private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return Scanner.Convert<T>(scanner.Str);
}
public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) =>
scanner.Pairs<TX, TY>((long)n);
public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) =>
scanner.ScanPairs<TX, TY>(n).ToArray();
public static Pair<long, long>[] Pairs(this Scanner scanner,
int n) => scanner.Pairs((long)n);
public static Pair<long, long>[] Pairs(this Scanner scanner, long n) =>
scanner.ScanPairs<long, long>(n).ToArray();
public static Pair<int, int>[] PairsInt(this Scanner scanner,
int n) => scanner.PairsInt((long)n);
public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) =>
scanner.ScanPairs<int, int>(n).ToArray();
private static IEnumerable<Pair<TX, TY>>
ScanPairs<TX, TY>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return scanner.P2<TX, TY>();
}
public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(
this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n);
public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner,
long n) =>
scanner.ScanPairs3<TX, TY, TZ>(n).ToArray();
public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) =>
scanner.Pairs3((long)n);
public static Pair3<long, long, long>[] Pairs3(this Scanner scanner,
long n) =>
scanner.ScanPairs3<long, long, long>(n).ToArray();
public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) =>
scanner.Pairs3Int((long)n);
public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner,
long n) =>
scanner.ScanPairs3<int, int, int>(n).ToArray();
private static IEnumerable<Pair3<TX, TY, TZ>>
ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return scanner.P3<TX, TY, TZ>();
}
public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>(
this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n);
public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>(
this Scanner scanner,
long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray();
public static Pair4<long, long, long, long>[] Pairs4(
this Scanner scanner, int n) => scanner.Pairs4((long)n);
public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner,
long n) =>
scanner.ScanPairs4<long, long, long, long>(n).ToArray();
public static Pair4<int, int, int, int>[] Pairs4Int(
this Scanner scanner, int n) => scanner.Pairs4Int((long)n);
public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner,
long n) =>
scanner.ScanPairs4<int, int, int, int>(n).ToArray();
private static IEnumerable<Pair4<TX, TY, TZ, TW>>
ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return scanner.P4<TX, TY, TZ, TW>();
}
}
class Pair<TX, TY> {
public TX X { get; }
public TY Y { get; }
public Pair(TX x, TY y) {
this.X = x;
this.Y = y;
}
}
class Pair : Pair<long, long> {
public Pair(long x, long y) : base(x, y) {}
}
class PairInt : Pair<int, int> {
public PairInt(int x, int y) : base(x, y) {}
}
class Pair3<TX, TY, TZ> {
public TX X { get; }
public TY Y { get; }
public TZ Z { get; }
public Pair3(TX x, TY y, TZ z) {
this.X = x;
this.Y = y;
this.Z = z;
}
}
class Pair3 : Pair3<long, long, long> {
public Pair3(long x, long y, long z) : base(x, y, z) {}
}
class Pair3Int : Pair3<int, int, int> {
public Pair3Int(int x, int y, int z) : base(x, y, z) {}
}
class Pair4<TX, TY, TZ, TW> {
public TX X { get; }
public TY Y { get; }
public TZ Z { get; }
public TW W { get; }
public Pair4(TX x, TY y, TZ z, TW w) {
this.X = x;
this.Y = y;
this.Z = z;
this.W = w;
}
}
class Pair4 : Pair4<long, long, long, long> {
public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {}
}
class Pair4Int : Pair4<int, int, int, int> {
public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {}
}
class Printer {
private readonly TextWriter writer;
public Printer(TextWriter writer) { this.writer = writer; }
public void Write(string obj) { writer.WriteLine(obj); }
public void Write(object obj) { writer.WriteLine(obj); }
public void Write<T>(IEnumerable<T> ts) {
writer.WriteLine(string.Join(" ", ts));
}
public void Write(params object[] objs) {
writer.WriteLine(string.Join(" ", objs));
}
}
static class Extension {
public static bool TryRemove<T>(this HashSet<T> ts, T t) {
if (ts.Contains(t)) {
ts.Remove(t);
return true;
} else {
return false;
}
}
public static HashSet<T>
ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct());
public static long ToDigit(this char c) => (long)(c - '0');
public static long ToSmallAbcIndex(this char c) => (long)(c - 'a');
public static long ToLargeAbcIndex(this char c) => (long)(c - 'A');
public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount();
}
class C {
public class Tree {
public Tree() { to = new Dictionary<long, long[]>(); }
public Tree(Scanner sc, long n, bool base1 = true,
bool singleDirection = false) {
Adjust(sc.Pairs(n), base1, singleDirection);
}
public Tree(Pair<long, long>[] edges, bool base1 = true,
bool singleDirection = false) {
Adjust(edges, base1, singleDirection);
}
public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true,
bool singleDirection = false) {
Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1,
singleDirection);
}
private void Adjust(Pair<long, long>[] edges, bool base1,
bool singleDirection) {
var arrows = base1
? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 })
: edges.Select(x => new { from = x.X, to = x.Y });
if (singleDirection == false)
arrows =
arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from }));
to = arrows.GroupBy(x => x.from)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray());
}
private long[] empty = new long[0];
private Dictionary<long, long[]> to;
public long[] To(long from) {
long[] res = null;
if (to.TryGetValue(from, out res))
return res;
else
return empty;
}
}
public class PriorityQueue<TKey, TState>
where TKey : IComparable<TKey> {
public int Count { get; private set; }
private readonly Func<TState, TKey> keySelector;
private readonly bool desc;
private TState[] states = new TState[65536];
private TKey[] keys = new TKey[65536];
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) {
this.keySelector = keySelector;
this.desc = desc;
}
public TState Top {
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
ValidateNonEmpty();
return states[1];
}
}
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TState Dequeue() {
var top = Top;
var item = states[Count];
var key = keys[Count];
Count--;
int index = 1;
while (true) {
if ((index << 1) >= Count) {
if (index << 1 > Count)
break;
if (key.CompareTo(keys[index << 1]) <= 0 ^ desc)
break;
states[index] = states[index << 1];
keys[index] = keys[index << 1];
index <<= 1;
} else {
var nextIndex =
keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc
? (index << 1)
: (index << 1) + 1;
if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc)
break;
states[index] = states[nextIndex];
keys[index] = keys[nextIndex];
index = nextIndex;
}
}
states[index] = item;
keys[index] = key;
return top;
}
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(TState state) {
var key = keySelector.Invoke(state);
Count++;
int index = Count;
if (states.Length == Count)
Extend(states.Length * 2);
while ((index >> 1) != 0) {
if (keys[index >> 1].CompareTo(key) <= 0 ^ desc)
break;
states[index] = states[index >> 1];
keys[index] = keys[index >> 1];
index >>= 1;
}
states[index] = state;
keys[index] = key;
}
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Extend(int newSize) {
TState[] newStates = new TState[newSize];
TKey[] newKeys = new TKey[newSize];
states.CopyTo(newStates, 0);
keys.CopyTo(newKeys, 0);
states = newStates;
keys = newKeys;
}
private void ValidateNonEmpty() {
if (Count == 0)
throw new IndexOutOfRangeException();
}
}
public class BinaryIndexTree {
long length;
long[] binaryIndexedTree;
public BinaryIndexTree(long length) {
this.length = length;
binaryIndexedTree = new long[length + 1];
}
public void Add(long indexZeroBase, long additional) {
// i += i & -i
// 1が立っている最下位ビットを足す、の意味
for (long i = indexZeroBase + 1; i <= length; i += i & -i) {
binaryIndexedTree[i] += additional;
}
}
public long Sum(long indexZeroBase) {
long result = 0;
// i += i & -i
// 1が立っている最下位ビットを引く、の意味
for (long i = indexZeroBase + 1; i > 0; i -= i & -i) {
result += binaryIndexedTree[i];
}
return result;
}
}
public static class BinarySearch {
public static int GetFirstIndexGreater(long x, ref List<long> listOrdered) {
var count = listOrdered.Count;
if (count == 0)
return 0;
if (listOrdered[count - 1] <= x)
return count;
int low = 0;
int high = listOrdered.Count - 1;
while (low < high) {
var mid = (low + high) / 2;
if (listOrdered[mid] > x)
high = mid;
else
low = mid + 1;
}
return low;
}
public static int GetFirstIndexGreater(int x, ref List<int> listOrdered) {
var count = listOrdered.Count;
if (count == 0)
return 0;
if (listOrdered[count - 1] <= x)
return count;
int low = 0;
int high = listOrdered.Count - 1;
while (low < high) {
var mid = (low + high) / 2;
if (listOrdered[mid] > x)
high = mid;
else
low = mid + 1;
}
return low;
}
public static int GetLastIndexLess(long x, ref List<long> listOrdered) {
var count = listOrdered.Count;
if (count == 0)
return -1;
if (listOrdered[0] >= x)
return -1;
int low = 0;
int high = listOrdered.Count - 1;
while (low < high) {
var mid = (low + high + 1) / 2;
if (listOrdered[mid] < x)
low = mid;
else
high = mid - 1;
}
return low;
}
public static int GetLastIndexLess(int x, ref List<int> listOrdered) {
var count = listOrdered.Count;
if (count == 0)
return -1;
if (listOrdered[0] >= x)
return -1;
int low = 0;
int high = listOrdered.Count - 1;
while (low < high) {
var mid = (low + high + 1) / 2;
if (listOrdered[mid] < x)
low = mid;
else
high = mid - 1;
}
return low;
}
}
public static class BellmanFord {
public class Vertex {
public long Distance { get; set; }
public Vertex() { Distance = long.MaxValue; }
}
public class Edge {
public int From { get; private set; }
public int To { get; private set; }
public long Weight { get; private set; }
public Edge(int from, int to, long weight) {
From = from;
To = to;
Weight = weight;
}
}
private static void GetReachable(int origin, ref HashSet<int> reached,
ref Dictionary<int, int[]> paths) {
if (reached.Contains(origin))
return;
reached.Add(origin);
if (paths.ContainsKey(origin) == false)
return;
foreach (var p in paths[origin])
GetReachable(p, ref reached, ref paths);
}
/// <summary>
/// null: 負の無限大
/// long.MaxValue: たどり着けない
/// その他: 距離
/// </summary>
public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges,
int source, int dest) {
var forwards =
rawEdges.GroupBy(x => x.From)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(
x => x.Key, x => x.Select(xs => xs.From).ToArray());
var fromSource = new HashSet<int>();
var toDest = new HashSet<int>();
GetReachable(source, ref fromSource, ref forwards);
GetReachable(dest, ref toDest, ref reverses);
var edges = rawEdges.Where(e => fromSource.Contains(e.From))
.Where(e => fromSource.Contains(e.To))
.Where(e => toDest.Contains(e.From))
.Where(e => toDest.Contains(e.To))
.ToArray();
// initialize distances
var vertices = new List<Vertex>();
for (int i = 0; i < vertexCount; i++)
vertices.Add(new Vertex());
vertices[source].Distance = 0L;
// update distances
for (int i = 0; i < vertices.Count; i++) {
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance == long.MaxValue)
continue;
var newDistance = from.Distance + e.Weight;
if (to.Distance > newDistance) {
to.Distance = newDistance;
}
}
}
// check negative cycle
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance + e.Weight < to.Distance)
return null;
}
return vertices[dest].Distance;
}
}
public static long Gcd(int a, int b) => Gcd((long)a, (long)b);
public static long Gcd(long a, long b) {
if (a < b)
return GcdImpl(b, a);
else
return GcdImpl(a, b);
}
private static long GcdImpl(long a, long b) {
var remainder = a % b;
if (remainder == 0)
return b;
else
return GcdImpl(b, remainder);
}
public static long Lcm(int a, int b) => Lcm((long)a, (long)b);
public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
public static long Pow(int n, int p) => Pow((long)n, (long)p);
public static long Pow(long n, long p) {
var res = 1L;
for (long i = 0; i < p; i++)
res *= n;
return res;
}
public static Dictionary<long, long> Factorize(int n) => Factorize((long)n);
public static Dictionary<long, long> Factorize(long n) {
var res = new Dictionary<long, long>();
var r = n;
for (long i = 2; i * i <= r; i++) {
var c = 0L;
while (r % i == 0) {
c++;
r /= i;
}
if (c > 0)
res.Add(i, c);
}
if (r > 1)
res.Add(r, 1);
return res;
}
public static IEnumerable<long> Divisors(int n) => Divisors((long)n);
public static IEnumerable<long> Divisors(long n) {
var cache = new Stack<long>();
for (long i = 1; i * i <= n; i++) {
if (n % i == 0) {
yield return i;
cache.Push(i);
}
}
var r = cache.Peek();
if (r * r == n)
cache.Pop();
while (cache.Count > 0) {
var i = cache.Pop();
yield return n / i;
}
}
public static IEnumerable<int> Loop(int n) {
for (int i = 0; i < n; i++)
yield return i;
}
public static IEnumerable<long> Loop(long n) {
for (long i = 0L; i < n; i++)
yield return i;
}
}
struct Mint {
public static long Divider {
set { divider = value; }
}
private static long divider = 1000000007L;
public static void Set998244353() { divider = 998244353L; }
public static void Set1000000009() { divider = 1000000009L; }
public long Value { get; }
public override string ToString() => this.Value.ToString();
public Mint(long value) { this.Value = value; }
// public static implicit operator Mint(long a) => new Mint(a % divider);
// public static implicit operator Mint(int a) => new Mint(a % divider);
// public static explicit operator long(Mint a) => a.Value;
// public static explicit operator int(Mint a) => (int)a.Value;
public static Mint
operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider);
public static Mint operator +(Mint a, long b) => a + new Mint(b);
public static Mint operator +(Mint a, int b) => a + new Mint(b);
public static Mint operator -(Mint a, Mint b) {
var t = (a.Value - b.Value) % divider;
if (t < 0L)
t += divider;
return new Mint(t);
}
public static Mint operator -(Mint a, long b) => a - new Mint(b);
public static Mint operator -(Mint a, int b) => a - new Mint(b);
public static Mint
operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider);
public static Mint operator *(Mint a, long b) => a * new Mint(b);
public static Mint operator *(Mint a, int b) => a * new Mint(b);
public static Mint operator /(Mint a, Mint b) =>
new Mint((a.Value * InvImpl(b.Value)) % divider);
public static Mint operator /(Mint a, long b) => a / new Mint(b);
public static Mint operator /(Mint a, int b) => a / new Mint(b);
public Mint Pow(long p) => new Mint(PowImpl(Value, p));
public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p));
private static long PowImpl(long a, long p) {
if (p == 0L)
return 1L;
if (p == 1L)
return a;
var halfP = p / 2L;
var halfPowered = PowImpl(a, halfP);
var powered = halfPowered * halfPowered % divider;
return p % 2L == 0L ? powered : powered * a % divider;
}
public static Mint Inv(long a) => new Mint(InvImpl(a));
private static readonly Dictionary<long, long> invCache =
new Dictionary<long, long>();
private static long InvImpl(long a) {
long cache;
if (invCache.TryGetValue(a, out cache))
return cache;
var result = PowImpl(a, divider - 2L);
invCache.Add(a, result);
return result;
}
public static Mint Fac(long a) => new Mint(FacImpl(a));
private static long[] facCache = new long[262144];
private static long cachedFac = 0L;
private static long FacImpl(long a) {
if (a >= divider)
return 0L;
facCache[0] = 1L;
if (facCache.LongLength <= a) {
long newSize = facCache.LongLength;
while (newSize <= a) {
newSize *= 2;
}
ExtendFacCache(newSize);
}
if (cachedFac < a) {
var val = facCache[cachedFac];
var start = cachedFac + 1L;
for (long i = start; i <= a; i++) {
val = (val * i) % divider;
facCache[i] = val;
}
cachedFac = a;
}
return facCache[a];
}
private static void ExtendFacCache(long newSize) {
long[] newFacCache = new long[newSize];
facCache.CopyTo(newFacCache, 0);
facCache = newFacCache;
}
public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r));
private static long PermImpl(long n, long r) {
if (n < r)
return 0L;
if (r <= 0L)
return 1L;
var nn = FacImpl(n);
var nr = FacImpl(n - r);
return (nn * InvImpl(nr)) % divider;
}
public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r));
private static long CombImpl(long n, long r) {
if (n < r)
return 0L;
if (n == r)
return 1L;
if (n - r < r)
return CombImpl(n, n - r);
var nn = FacImpl(n);
var nr = FacImpl(n - r);
var rr = FacImpl(r);
var nrrr = (nr * rr) % divider;
return (nn * InvImpl(nrrr)) % divider;
}
}
}
|
[["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 6,900
| 7
|
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
var Dic = new Dictionary<char, Set<int>>();
for (var i = 'a'; i <= 'z'; i++) {
Dic.Add(i, new Set<int>());
}
var S = Console.ReadLine();
for (int i = 0; i < N; i++) {
Dic[S[i]].Insert(i);
}
// var NK = Console.ReadLine().Split(' ').Select(x =>
// int.Parse(x)).ToArray();
var Q = long.Parse(Console.ReadLine());
for (int i = 0; i < Q; i++) {
var Query = Console.ReadLine().Split(' ').ToArray();
if (Query[0] == "1") {
var l = int.Parse(Query[1]) - 1;
var s = S[l];
var c = Convert.ToChar(Query[2]);
Dic[s].Remove(l);
Dic[c].Insert(l);
} else {
var l = int.Parse(Query[1]) - 1;
var r = int.Parse(Query[2]) - 1;
var count = 0;
foreach (var item in Dic) {
var lower = item.Value.LowerBound(l);
if (lower == item.Value.Count() || lower < 0) {
continue;
}
if (item.Value[lower] <= r) {
count++;
}
}
Console.WriteLine(count);
}
}
}
public static int LowerBound<T>(T[] a, T v) {
return LowerBound(a, v, Comparer<T>.Default);
}
public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp) {
var l = 0;
var r = a.Length - 1;
while (l <= r) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(a[mid], v);
if (res == -1)
l = mid + 1;
else
r = mid - 1;
}
return l;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
var Dic = new Dictionary<char, Set<int>>();
for (var i = 'a'; i <= 'z'; i++) {
Dic.Add(i, new Set<int>());
}
var S = Console.ReadLine();
var charS = S.ToCharArray();
for (int i = 0; i < N; i++) {
Dic[S[i]].Insert(i);
}
// var NK = Console.ReadLine().Split(' ').Select(x =>
// int.Parse(x)).ToArray();
var Q = long.Parse(Console.ReadLine());
for (int i = 0; i < Q; i++) {
var Query = Console.ReadLine().Split(' ').ToArray();
if (Query[0] == "1") {
var l = int.Parse(Query[1]) - 1;
var s = charS[l];
var c = Convert.ToChar(Query[2]);
Dic[s].Remove(l);
Dic[c].Insert(l);
charS[l] = c;
} else {
var l = int.Parse(Query[1]) - 1;
var r = int.Parse(Query[2]) - 1;
var count = 0;
foreach (var item in Dic) {
var lower = item.Value.LowerBound(l);
if (lower == item.Value.Count() || lower < 0) {
continue;
}
if (item.Value[lower] <= r) {
count++;
}
}
Console.WriteLine(count);
}
}
}
public static int LowerBound<T>(T[] a, T v) {
return LowerBound(a, v, Comparer<T>.Default);
}
public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp) {
var l = 0;
var r = a.Length - 1;
while (l <= r) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(a[mid], v);
if (res == -1)
l = mid + 1;
else
r = mid - 1;
}
return l;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 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, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22]]
| 8
| 2,091
| 18
|
using Yorukatsu021.Questions;
using Yorukatsu021.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Yorukatsu021.Questions {
/// <summary>
/// ABC157 E
/// </summary>
public class QuestionE : AtCoderQuestionBase {
public override IEnumerable<object> Solve(TextReader inputStream) {
var n = inputStream.ReadInt();
var s = inputStream.ReadLine();
var q = inputStream.ReadInt();
var segmentationTree = new SegmentationTree(s);
for (int i = 0; i < q; i++) {
var query = inputStream.ReadLine().Split(' ');
switch (query[0]) {
case "1":
segmentationTree.Update(int.Parse(query[1]) - 1, query[2][0]);
break;
case "2":
yield return segmentationTree.GetVariety(int.Parse(query[1]) - 1,
int.Parse(query[2]) - 1);
break;
default:
break;
}
}
}
}
public class SegmentationTree {
private readonly int _bufferLength;
private readonly int _leafCount;
private readonly int[,] _charCount;
private readonly char[] _rawString;
const int alphabetCount = 'z' - 'a' + 1;
public SegmentationTree(string s) {
_leafCount = GetMinimumPow2(s.Length);
_bufferLength = 2 * _leafCount - 1;
_charCount = new int[_bufferLength, alphabetCount];
for (int i = 0; i < s.Length; i++) {
Update(i, s[i]);
}
_rawString = s.ToCharArray();
}
public void Update(int index, char newChar) {
var oldChar = _rawString?[index];
if (oldChar != null) {
_rawString[index] = newChar;
}
index += _leafCount - 1;
var tempIndex = index;
_charCount[index, newChar - 'a']++;
while (index > 0) {
index = (index - 1) / 2;
_charCount[index, newChar - 'a']++;
}
index = tempIndex;
if (oldChar != null) {
_charCount[index, oldChar.Value - 'a']++;
while (index > 0) {
index = (index - 1) / 2;
_charCount[index, oldChar.Value - 'a']++;
}
}
}
public int GetVariety(int begin, int end) =>
GetVariety(begin, end + 1, 0, 0, _leafCount).Count();
private IEnumerable<char> GetVariety(int begin, int end, int currentIndex,
int currentLeft, int currentRight) {
if (currentRight <= begin || end <= currentLeft) // 全く被らない
{
return Enumerable.Empty<char>();
} else if (begin <= currentLeft && currentRight <= end) // 全部被る
{
return GetCharsAt(currentIndex).ToArray();
} else // 一部被る
{
var leftChars =
GetVariety(begin, end, currentIndex * 2 + 1, currentLeft,
(currentLeft + currentRight) / 2)
.ToArray();
var rightChars =
GetVariety(begin, end, currentIndex * 2 + 2,
(currentLeft + currentRight) / 2, currentRight)
.ToArray();
return leftChars.Union(rightChars);
}
}
private IEnumerable<char> GetCharsAt(int index) {
for (int i = 0; i < alphabetCount; i++) {
if (_charCount[index, i] > 0) {
yield return (char)(i + 'a');
}
}
}
private int GetMinimumPow2(int n) {
var p = 1;
while (p < n) {
p *= 2;
}
return p;
}
}
}
namespace Yorukatsu021 {
class Program {
static void Main(string[] args) {
IAtCoderQuestion question = new QuestionE(); // 問題に合わせて書き換え
var answers = question.Solve(Console.In);
foreach (var answer in answers) {
Console.WriteLine(answer);
}
}
}
}
#region Base Classes
namespace Yorukatsu021.Questions {
public interface IAtCoderQuestion {
IEnumerable<object> Solve(string input);
IEnumerable<object> Solve(TextReader inputStream);
}
public abstract class AtCoderQuestionBase : IAtCoderQuestion {
public IEnumerable<object> Solve(string input) {
var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
var reader = new StreamReader(stream, Encoding.Unicode);
return Solve(reader);
}
public abstract IEnumerable<object> Solve(TextReader inputStream);
}
}
#endregion
#region Extensions
namespace Yorukatsu021.Extensions {
internal static class TextReaderExtensions {
internal static int
ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
internal static long
ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
internal static double
ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
internal static string
ReadString(this TextReader reader) => reader.ReadLine();
internal static int[] ReadIntArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(int.Parse).ToArray();
internal static long[] ReadLongArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(long.Parse).ToArray();
internal static double[] ReadDoubleArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(double.Parse).ToArray();
internal static string[] ReadStringArray(this TextReader reader,
char separator = ' ') =>
reader.ReadLine().Split(separator);
}
}
#endregion
|
using Yorukatsu021.Questions;
using Yorukatsu021.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Yorukatsu021.Questions {
/// <summary>
/// ABC157 E
/// </summary>
public class QuestionE : AtCoderQuestionBase {
public override IEnumerable<object> Solve(TextReader inputStream) {
var n = inputStream.ReadInt();
var s = inputStream.ReadLine();
var q = inputStream.ReadInt();
var segmentationTree = new SegmentationTree(s);
for (int i = 0; i < q; i++) {
var query = inputStream.ReadLine().Split(' ');
switch (query[0]) {
case "1":
segmentationTree.Update(int.Parse(query[1]) - 1, query[2][0]);
break;
case "2":
yield return segmentationTree.GetVariety(int.Parse(query[1]) - 1,
int.Parse(query[2]) - 1);
break;
default:
break;
}
}
}
}
public class SegmentationTree {
private readonly int _bufferLength;
private readonly int _leafCount;
private readonly int[,] _charCount;
private readonly char[] _rawString;
const int alphabetCount = 'z' - 'a' + 1;
public SegmentationTree(string s) {
_leafCount = GetMinimumPow2(s.Length);
_bufferLength = 2 * _leafCount - 1;
_charCount = new int[_bufferLength, alphabetCount];
for (int i = 0; i < s.Length; i++) {
Update(i, s[i]);
}
_rawString = s.ToCharArray();
}
public void Update(int index, char newChar) {
var oldChar = _rawString?[index];
if (oldChar != null) {
_rawString[index] = newChar;
}
index += _leafCount - 1;
var tempIndex = index;
_charCount[index, newChar - 'a']++;
while (index > 0) {
index = (index - 1) / 2;
_charCount[index, newChar - 'a']++;
}
index = tempIndex;
if (oldChar != null) {
_charCount[index, oldChar.Value - 'a']--;
while (index > 0) {
index = (index - 1) / 2;
_charCount[index, oldChar.Value - 'a']--;
}
}
}
public int GetVariety(int begin, int end) =>
GetVariety(begin, end + 1, 0, 0, _leafCount).Count();
private IEnumerable<char> GetVariety(int begin, int end, int currentIndex,
int currentLeft, int currentRight) {
if (currentRight <= begin || end <= currentLeft) // 全く被らない
{
return Enumerable.Empty<char>();
} else if (begin <= currentLeft && currentRight <= end) // 全部被る
{
return GetCharsAt(currentIndex);
} else // 一部被る
{
var leftChars =
GetVariety(begin, end, currentIndex * 2 + 1, currentLeft,
(currentLeft + currentRight) / 2);
var rightChars =
GetVariety(begin, end, currentIndex * 2 + 2,
(currentLeft + currentRight) / 2, currentRight);
return leftChars.Union(rightChars);
}
}
private IEnumerable<char> GetCharsAt(int index) {
for (int i = 0; i < alphabetCount; i++) {
if (_charCount[index, i] > 0) {
yield return (char)(i + 'a');
}
}
}
private int GetMinimumPow2(int n) {
var p = 1;
while (p < n) {
p *= 2;
}
return p;
}
}
}
namespace Yorukatsu021 {
class Program {
static void Main(string[] args) {
IAtCoderQuestion question = new QuestionE(); // 問題に合わせて書き換え
var answers = question.Solve(Console.In);
foreach (var answer in answers) {
Console.WriteLine(answer);
}
}
}
}
#region Base Classes
namespace Yorukatsu021.Questions {
public interface IAtCoderQuestion {
IEnumerable<object> Solve(string input);
IEnumerable<object> Solve(TextReader inputStream);
}
public abstract class AtCoderQuestionBase : IAtCoderQuestion {
public IEnumerable<object> Solve(string input) {
var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
var reader = new StreamReader(stream, Encoding.Unicode);
return Solve(reader);
}
public abstract IEnumerable<object> Solve(TextReader inputStream);
}
}
#endregion
#region Extensions
namespace Yorukatsu021.Extensions {
internal static class TextReaderExtensions {
internal static int
ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
internal static long
ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
internal static double
ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
internal static string
ReadString(this TextReader reader) => reader.ReadLine();
internal static int[] ReadIntArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(int.Parse).ToArray();
internal static long[] ReadLongArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(long.Parse).ToArray();
internal static double[] ReadDoubleArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(double.Parse).ToArray();
internal static string[] ReadStringArray(this TextReader reader,
char separator = ' ') =>
reader.ReadLine().Split(separator);
}
}
#endregion
|
[["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 68], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 37, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 37, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 37, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24]]
| 8
| 1,126
| 16
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var N = sc.ReadInt();
var bt = new BinaryIndexedTree[26];
for (int i = 0; i < 26; i++) {
bt[i] = new BinaryIndexedTree(N);
}
var S = sc.ReadStr().ToArray();
for (int i = 0; i < N; i++) {
var c = S[i];
bt[c - 'a'].Add(i + 1, 1);
}
var Q = sc.ReadInt();
for (int i = 0; i < Q; i++) {
var com = sc.ReadInt();
if (com == 1) {
var x = sc.ReadInt();
var c = sc.ReadStr()[0];
var prev = S[x - 1];
bt[prev - 'a'].Add(x, -1);
bt[c - 'a'].Add(x, 1);
} else {
var l = sc.ReadInt();
var r = sc.ReadInt();
var ans = 0;
foreach (var b in bt) {
var sum = b.Sum(l, r);
if (sum > 0)
ans++;
}
Console.WriteLine(ans);
}
}
}
class BinaryIndexedTree {
public int N { get; set; }
public long[] Array { get; set; }
public BinaryIndexedTree(int n) {
this.N = n;
this.Array = new long[N + 1];
}
public void Add(int index, long value) {
while (index <= this.N) {
this.Array[index] += value;
index += index & (-index);
}
}
public long Sum(int l, int r) { return this.Sum(r) - this.Sum(l - 1); }
public long Sum(int index) {
var sum = 0L;
while (index > 0) {
sum += this.Array[index];
index -= index & (-index);
}
return sum;
}
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var N = sc.ReadInt();
var bt = new BinaryIndexedTree[26];
for (int i = 0; i < 26; i++) {
bt[i] = new BinaryIndexedTree(N);
}
var S = sc.ReadStr().ToArray();
for (int i = 0; i < N; i++) {
var c = S[i];
bt[c - 'a'].Add(i + 1, 1);
}
var Q = sc.ReadInt();
for (int i = 0; i < Q; i++) {
var com = sc.ReadInt();
if (com == 1) {
var x = sc.ReadInt();
var c = sc.ReadStr()[0];
var prev = S[x - 1];
bt[prev - 'a'].Add(x, -1);
bt[c - 'a'].Add(x, 1);
S[x - 1] = c;
} else {
var l = sc.ReadInt();
var r = sc.ReadInt();
var ans = 0;
foreach (var b in bt) {
var sum = b.Sum(l, r);
if (sum > 0)
ans++;
}
Console.WriteLine(ans);
}
}
}
class BinaryIndexedTree {
public int N { get; set; }
public long[] Array { get; set; }
public BinaryIndexedTree(int n) {
this.N = n;
this.Array = new long[N + 1];
}
public void Add(int index, long value) {
while (index <= this.N) {
this.Array[index] += value;
index += index & (-index);
}
}
public long Sum(int l, int r) { return this.Sum(r) - this.Sum(l - 1); }
public long Sum(int index) {
var sum = 0L;
while (index > 0) {
sum += this.Array[index];
index -= index & (-index);
}
return sum;
}
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 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, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 1,481
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.ABC_157 {
class E {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush =
false };
SetOut(sw);
Method(args);
Out.Flush();
}
static void Method(string[] args) {
int n = ReadInt();
char[] s = Read().ToCharArray();
int q = ReadInt();
SegTree segTree = new SegTree(n, (a, b) => {
bool[] res = new bool[26];
for (int i = 0; i < a.Length; i++) {
res[i] = a[i] | b[i];
}
return res;
});
for (int i = 0; i < n; i++) {
bool[] tmp = segTree.Look(i);
tmp[s[i] - 'a'] = true;
segTree.Update(i);
}
for (int i = 0; i < q; i++) {
string[] query = Read().Split();
int type = int.Parse(query[0]);
if (type == 1) {
int index = int.Parse(query[1]) - 1;
bool[] tmp = segTree.Look(index);
tmp[s[index] - 'a'] = false;
tmp[query[2][0] - 'a'] = true;
s[index] = (char)(query[2][0] - 'a');
segTree.Update(index);
} else {
int l = int.Parse(query[1]) - 1;
int r = int.Parse(query[2]);
bool[] tmp = segTree.Scan(l, r);
int kinds = 0;
for (int j = 0; j < 26; j++) {
if (tmp[j]) {
kinds++;
}
}
WriteLine(kinds);
}
}
}
class SegTree {
int totalLength;
bool[][] tree;
Func<bool[], bool[], bool[]> integrate;
public SegTree(int length, Func<bool[], bool[], bool[]> integrate) {
this.integrate = integrate;
totalLength = 1;
while (totalLength < length)
totalLength *= 2;
tree = new bool [2 * totalLength - 1][];
for (int i = 0; i < tree.Length; i++) {
tree[i] = new bool[26];
}
}
public void Update(int i) {
int now = i + totalLength - 1;
while (now > 0) {
now = (now - 1) / 2;
tree[now] = integrate(tree[now * 2 + 1], tree[now * 2 + 2]);
}
}
public bool[] Look(int i) { return tree[i + totalLength - 1]; }
//[top,last)
public bool[] Scan(int top, int last) {
return Query(top, last, 0, 0, totalLength);
}
bool[] Query(int top, int last, int i, int left, int right) {
if (right <= top || last <= left)
return new bool[26];
if (top <= left && right <= last)
return tree[i];
bool[] leftValue =
Query(top, last, i * 2 + 1, left, (left + right) / 2);
bool[] rightValue =
Query(top, last, (i + 1) * 2, (left + right) / 2, right);
return integrate(leftValue, rightValue);
}
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.ABC_157 {
class E {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush =
false };
SetOut(sw);
Method(args);
Out.Flush();
}
static void Method(string[] args) {
int n = ReadInt();
char[] s = Read().ToCharArray();
int q = ReadInt();
SegTree segTree = new SegTree(n, (a, b) => {
bool[] res = new bool[26];
for (int i = 0; i < a.Length; i++) {
res[i] = a[i] | b[i];
}
return res;
});
for (int i = 0; i < n; i++) {
bool[] tmp = segTree.Look(i);
tmp[s[i] - 'a'] = true;
segTree.Update(i);
}
for (int i = 0; i < q; i++) {
string[] query = Read().Split();
int type = int.Parse(query[0]);
if (type == 1) {
int index = int.Parse(query[1]) - 1;
bool[] tmp = segTree.Look(index);
tmp[s[index] - 'a'] = false;
tmp[query[2][0] - 'a'] = true;
s[index] = query[2][0];
segTree.Update(index);
} else {
int l = int.Parse(query[1]) - 1;
int r = int.Parse(query[2]);
bool[] tmp = segTree.Scan(l, r);
int kinds = 0;
for (int j = 0; j < 26; j++) {
if (tmp[j]) {
kinds++;
}
}
WriteLine(kinds);
}
}
}
class SegTree {
int totalLength;
bool[][] tree;
Func<bool[], bool[], bool[]> integrate;
public SegTree(int length, Func<bool[], bool[], bool[]> integrate) {
this.integrate = integrate;
totalLength = 1;
while (totalLength < length)
totalLength *= 2;
tree = new bool [2 * totalLength - 1][];
for (int i = 0; i < tree.Length; i++) {
tree[i] = new bool[26];
}
}
public void Update(int i) {
int now = i + totalLength - 1;
while (now > 0) {
now = (now - 1) / 2;
tree[now] = integrate(tree[now * 2 + 1], tree[now * 2 + 2]);
}
}
public bool[] Look(int i) { return tree[i + totalLength - 1]; }
//[top,last)
public bool[] Scan(int top, int last) {
return Query(top, last, 0, 0, totalLength);
}
bool[] Query(int top, int last, int i, int left, int right) {
if (right <= top || last <= left)
return new bool[26];
if (top <= left && right <= last)
return tree[i];
bool[] leftValue =
Query(top, last, i * 2 + 1, left, (left + right) / 2);
bool[] rightValue =
Query(top, last, (i + 1) * 2, (left + right) / 2, right);
return integrate(leftValue, rightValue);
}
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["-", 64, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["-", 64, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 64, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["-", 0, 1, 0, 11, 12, 74, 51, 23, 0, 24], ["-", 0, 11, 12, 74, 51, 23, 0, 16, 17, 33], ["-", 12, 74, 51, 23, 0, 16, 12, 252, 0, 104], ["-", 12, 74, 51, 23, 0, 16, 12, 252, 0, 253], ["-", 0, 1, 0, 11, 12, 74, 51, 23, 0, 25]]
| 8
| 993
| 9
|
using System.Collections.Generic;
using System;
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
// <summary>
// Self-Balancing Binary Search Tree
// (using Randamized BST)
// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
// public int Sum; //sum of the value of
// the sub tree
public Node(T v) {
Value = v;
Count = 1;
// Sum = v;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
// public static int Sum(Node t)
//{
// return t == null ? 0 : t.Sum;
//}
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
// t.Sum = Sum(t.LChild) + Sum(t.RChild) + t.Value;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble())
// if ((double)Count(l) / (double)(Count(l) + Count(r)) > 0.5)
// //debug
{
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
public class Hello {
public static void Main() {
var a = new Set<int>[26];
for (int i = 0; i < 26; i++)
a[i] = new Set<int>();
var n = int.Parse(Console.ReadLine().Trim());
var s = Console.ReadLine().Trim();
for (int i = 0; i < n; i++)
a[s[i] - 'a'].Insert(i);
var sc = s.ToCharArray();
var q = int.Parse(Console.ReadLine().Trim());
for (int i = 0; i < q; i++) {
string[] line = Console.ReadLine().Trim().Split(' ');
if (line[0] == "1") {
var si = int.Parse(line[1]) - 1;
var pre = sc[si] - 'a';
a[pre].Remove(si);
var st = line[2][0];
sc[si] = st;
a[st - 'a'].Insert(si);
} else {
var count = 0;
for (int j = 0; j < 26; j++) {
var L = int.Parse(line[1]) - 1;
var r = int.Parse(line[2]) - 1;
if (check(a[j], L, r))
count++;
}
Console.WriteLine(count);
}
}
}
static bool check(Set<int> a, int L, int r) {
var c = a.Count();
if (c == 0)
return false;
var L0 = a.LowerBound(L);
var r0 = a.LowerBound(r);
if (L0 < r0)
return true;
if (L0 == 0 && r0 == 0)
return a.ElementAt(0) == r;
if (L0 == c - 1 && r0 == c - 1)
return a.ElementAt(c - 1) == r;
if (L0 == r0 && L0 <= c - 1)
return a.ElementAt(L0) == L;
return false;
}
}
|
using System.Collections.Generic;
using System;
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
// <summary>
// Self-Balancing Binary Search Tree
// (using Randamized BST)
// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
// public int Sum; //sum of the value of
// the sub tree
public Node(T v) {
Value = v;
Count = 1;
// Sum = v;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
// public static int Sum(Node t)
//{
// return t == null ? 0 : t.Sum;
//}
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
// t.Sum = Sum(t.LChild) + Sum(t.RChild) + t.Value;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble())
// if ((double)Count(l) / (double)(Count(l) + Count(r)) > 0.5)
// //debug
{
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
public class Hello {
public static void Main() {
var a = new Set<int>[26];
for (int i = 0; i < 26; i++)
a[i] = new Set<int>();
var n = int.Parse(Console.ReadLine().Trim());
var s = Console.ReadLine().Trim();
for (int i = 0; i < n; i++)
a[s[i] - 'a'].Insert(i);
var sc = s.ToCharArray();
var q = int.Parse(Console.ReadLine().Trim());
for (int i = 0; i < q; i++) {
string[] line = Console.ReadLine().Trim().Split(' ');
if (line[0] == "1") {
var si = int.Parse(line[1]) - 1;
var pre = sc[si] - 'a';
a[pre].Remove(si);
var st = line[2][0];
sc[si] = st;
a[st - 'a'].Insert(si);
} else {
var count = 0;
for (int j = 0; j < 26; j++) {
var L = int.Parse(line[1]) - 1;
var r = int.Parse(line[2]) - 1;
if (check(a[j], L, r))
count++;
}
Console.WriteLine(count);
}
}
}
static bool check(Set<int> a, int L, int r) {
var c = a.Count();
if (c == 0)
return false;
var L0 = a.LowerBound(L);
var r0 = a.LowerBound(r);
if (L0 < r0)
return true;
if (L0 == 0 && r0 == 0)
return a.ElementAt(0) == r;
if (L0 == c - 1 && r0 == c - 1)
return a.ElementAt(r0) == r;
if (L0 == r0 && L0 == c)
return false;
if (L0 == r0)
return a.ElementAt(r0) == r;
return false;
}
}
|
[["-", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 17, 33], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 37, 0, 211, 0, 147], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 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, 37, 0, 38], ["-", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 57, 64, 37, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 37, 0, 16, 12, 22]]
| 8
| 2,076
| 21
|
using System;
using CompLib.Util;
public class Program {
private int N, K;
private double[] X, Y, C;
public void Solve() {
var sc = new Scanner();
N = sc.NextInt();
K = sc.NextInt();
X = new double[N];
Y = new double[N];
C = new double[N];
for (int i = 0; i < N; i++) {
X[i] = sc.NextDouble();
Y[i] = sc.NextDouble();
C[i] = sc.NextDouble();
}
// c * dist <= t
// dist <= t/c
// 時間tを決める t/C_iの円がN個ある K個以上重なる領域ができる最小のt
double ok = int.MaxValue;
double ng = 0;
for (int q = 0; q < 100; q++) {
double mid = (ok + ng) / 2;
if (Check(mid))
ok = mid;
else
ng = mid;
}
Console.WriteLine($"{ok:f10}");
}
bool Check(double t) {
// t/C_iの円がN個ある
// K個以上重なる
// ある円とそれを含む大きな円
for (int i = 0; i < N; i++) {
int cnt = 1;
for (int j = 0; j < N; j++) {
if (i == j)
continue;
double dx = Math.Abs(X[i] - X[j]);
double dy = Math.Abs(Y[i] - Y[j]);
double dist = Math.Sqrt(dx * dx + dy * dy);
double r1 = t / C[i];
double r2 = t / C[j];
if (r2 >= dist + r1)
cnt++;
}
if (cnt >= K) {
return true;
}
}
// ある2円の交点とそれを含む円
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
double dx = Math.Abs(X[i] - X[j]);
double dy = Math.Abs(Y[i] - Y[j]);
double dist = Math.Sqrt(dx * dx + dy * dy);
double r1 = t / C[i];
double r2 = t / C[j];
// 重ならない
if (r1 + r2 < dist)
continue;
if (Math.Max(r1, r2) > dist + Math.Min(r1, r2))
continue;
// 余弦定理
double cos =
(r1 * r1 + (dx * dx + dy * dy) - r2 * r2) / (2 * r1 * dist);
double q = Math.Acos(cos);
double w = Math.Atan2(Y[j] - Y[i], X[j] - X[i]);
double p1X = X[i] + Math.Cos(q + w) * r1;
double p1Y = Y[i] + Math.Sin(q + w) * r1;
int cnt1 = 2;
for (int k = 0; k < N; k++) {
if (k == i || k == j)
continue;
double tdx = Math.Abs(X[k] - p1X);
double tdy = Math.Abs(Y[k] - p1Y);
double tr = t / C[k];
if (tdx * tdx + tdy * tdy <= tr * tr)
cnt1++;
}
if (cnt1 >= K)
return true;
int cnt2 = 2;
double p2X = X[i] + Math.Cos(q - w) * r1;
double p2Y = Y[i] + Math.Sin(q - w) * r1;
for (int k = 0; k < N; k++) {
if (k == i || k == j)
continue;
double tdx = Math.Abs(X[k] - p2X);
double tdy = Math.Abs(Y[k] - p2Y);
double tr = t / C[k];
if (tdx * tdx + tdy * tdy <= tr * tr)
cnt2++;
}
if (cnt2 >= K)
return true;
}
}
return false;
}
public static void Main(string[] args) => new Program().Solve();
}
namespace CompLib.Util {
using System;
using System.Linq;
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
if (_index >= _line.Length) {
string s;
do {
s = Console.ReadLine();
} while (s.Length == 0);
_line = s.Split(Separator);
_index = 0;
}
return _line[_index++];
}
public string ReadLine() {
_index = _line.Length;
return Console.ReadLine();
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
string s = Console.ReadLine();
_line = s.Length == 0 ? new string[0] : s.Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using CompLib.Util;
public class Program {
private int N, K;
private double[] X, Y, C;
public void Solve() {
var sc = new Scanner();
N = sc.NextInt();
K = sc.NextInt();
X = new double[N];
Y = new double[N];
C = new double[N];
for (int i = 0; i < N; i++) {
X[i] = sc.NextDouble();
Y[i] = sc.NextDouble();
C[i] = sc.NextDouble();
}
// c * dist <= t
// dist <= t/c
// 時間tを決める t/C_iの円がN個ある K個以上重なる領域ができる最小のt
double ok = int.MaxValue;
double ng = 0;
for (int q = 0; q < 100; q++) {
double mid = (ok + ng) / 2;
if (Check(mid))
ok = mid;
else
ng = mid;
}
Console.WriteLine($"{ok:f10}");
}
bool Check(double t) {
// t/C_iの円がN個ある
// K個以上重なる
// ある円とそれを含む大きな円
for (int i = 0; i < N; i++) {
int cnt = 1;
for (int j = 0; j < N; j++) {
if (i == j)
continue;
double dx = Math.Abs(X[i] - X[j]);
double dy = Math.Abs(Y[i] - Y[j]);
double dist = Math.Sqrt(dx * dx + dy * dy);
double r1 = t / C[i];
double r2 = t / C[j];
if (r2 >= dist + r1)
cnt++;
}
if (cnt >= K) {
return true;
}
}
// ある2円の交点とそれを含む円
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
double dx = Math.Abs(X[i] - X[j]);
double dy = Math.Abs(Y[i] - Y[j]);
double dist = Math.Sqrt(dx * dx + dy * dy);
double r1 = t / C[i];
double r2 = t / C[j];
// 重ならない
if (r1 + r2 < dist)
continue;
if (Math.Max(r1, r2) > dist + Math.Min(r1, r2))
continue;
// 余弦定理
double cos =
(r1 * r1 + (dx * dx + dy * dy) - r2 * r2) / (2 * r1 * dist);
double q = Math.Acos(cos);
double w = Math.Atan2(Y[j] - Y[i], X[j] - X[i]);
double p1X = X[i] + Math.Cos(w + q) * r1;
double p1Y = Y[i] + Math.Sin(w + q) * r1;
int cnt1 = 2;
for (int k = 0; k < N; k++) {
if (k == i || k == j)
continue;
double tdx = Math.Abs(X[k] - p1X);
double tdy = Math.Abs(Y[k] - p1Y);
double tr = t / C[k];
if (tdx * tdx + tdy * tdy <= tr * tr)
cnt1++;
}
if (cnt1 >= K)
return true;
int cnt2 = 2;
double p2X = X[i] + Math.Cos(w - q) * r1;
double p2Y = Y[i] + Math.Sin(w - q) * r1;
for (int k = 0; k < N; k++) {
if (k == i || k == j)
continue;
double tdx = Math.Abs(X[k] - p2X);
double tdy = Math.Abs(Y[k] - p2Y);
double tr = t / C[k];
if (tdx * tdx + tdy * tdy <= tr * tr)
cnt2++;
}
if (cnt2 >= K)
return true;
}
}
return false;
}
public static void Main(string[] args) => new Program().Solve();
}
namespace CompLib.Util {
using System;
using System.Linq;
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
if (_index >= _line.Length) {
string s;
do {
s = Console.ReadLine();
} while (s.Length == 0);
_line = s.Split(Separator);
_index = 0;
}
return _line[_index++];
}
public string ReadLine() {
_index = _line.Length;
return Console.ReadLine();
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
string s = Console.ReadLine();
_line = s.Length == 0 ? new string[0] : s.Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
| 8
| 1,227
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ForAtCoder {
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split(' ');
List<int> xi = str.Select(int.Parse).ToList();
xi.Sort();
int min = xi[0];
int max = xi[xi.Count - 1];
long dist = long.MaxValue;
for (int p = 0; p < max; p++) {
long tmpdist = 0;
for (int i = 0; i < n; i++) {
tmpdist += (long)(Math.Pow((xi[i] - p), 2));
}
if (tmpdist < dist) {
dist = tmpdist;
}
}
Console.WriteLine(dist);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ForAtCoder {
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split(' ');
List<int> xi = str.Select(int.Parse).ToList();
int min = xi.Min();
int max = xi.Max();
long dist = long.MaxValue;
for (int p = min; p <= max; p++) {
long tmpdist = 0;
for (int i = 0; i < n; i++) {
tmpdist += (long)(Math.Pow((xi[i] - p), 2));
}
if (tmpdist < dist) {
dist = tmpdist;
}
}
Console.WriteLine(dist);
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 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, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 193
| 26
|
using System;
using System.Linq;
namespace ABC156C {
class MainClass {
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
int min = x.Min();
int max = x.Max();
int center = (min + max) / 2;
long ans = long.MaxValue;
for (int i = 1; i <= center; i++) {
long sum = 0;
foreach (var item in x) {
sum += (long)Math.Pow((item - i), 2);
}
ans = Math.Min(ans, sum);
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Linq;
namespace ABC156C {
class MainClass {
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
int min = x.Min();
int max = x.Max();
int center = (int)Math.Ceiling(x.Average());
long ans = long.MaxValue;
for (int i = 1; i <= center; i++) {
long sum = 0;
foreach (var item in x) {
sum += (long)Math.Pow((item - i), 2);
}
ans = Math.Min(ans, sum);
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 212, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 205, 22], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 74, 51, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 212, 0, 74, 51, 213, 3, 4, 0, 25]]
| 8
| 170
| 16
|
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 nab = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
var p = (long)Math.Pow(10, 9) + 7;
var all = Power(2, nab[0], p) - 1;
var combA = CombinationCount(nab[0], nab[1], p);
var combB = CombinationCount(nab[0], nab[2], p);
var result = (all - combA - combB + p) % p;
Console.WriteLine(result);
}
static long PermutationCount(long n, long k, long mod) {
if (n < k)
throw new ArgumentException();
var result = 1L;
for (var i = 0; i < k; i++)
result = (result * (n - i) % mod) % mod;
return result;
}
static long CombinationCount(long n, long k, long mod) {
if (n < k)
throw new ArgumentException();
k = Math.Min(k, n - k);
var top = PermutationCount(n, k, mod);
var bottom = PermutationCount(k, k, mod);
return (top * Power(bottom, mod - 2, mod)) % mod;
}
static long Power(long x, long y, long mod) {
var result = 1L;
while (y > 0) {
if ((y & 1) == 1)
result = ((result % mod) * (x % mod)) % mod;
x = ((x % mod) * (x % mod)) % mod;
y >>= 1;
}
return result;
}
}
}
|
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 nab = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
var p = (long)Math.Pow(10, 9) + 7;
var all = Power(2, nab[0], p);
var combA = CombinationCount(nab[0], nab[1], p);
var combB = CombinationCount(nab[0], nab[2], p);
var result = (all - combA - combB - 1) % p;
if (result < 0)
result += p;
Console.WriteLine(result);
}
static long PermutationCount(long n, long k, long mod) {
if (n < k)
throw new ArgumentException();
var result = 1L;
for (var i = 0; i < k; i++)
result = (result * (n - i) % mod) % mod;
return result;
}
static long CombinationCount(long n, long k, long mod) {
if (n < k)
throw new ArgumentException();
k = Math.Min(k, n - k);
var top = PermutationCount(n, k, mod);
var bottom = PermutationCount(k, k, mod);
return (top * Power(bottom, mod - 2, mod)) % mod;
}
static long Power(long x, long y, long mod) {
var result = 1L;
while (y > 0) {
if ((y & 1) == 1)
result = ((result % mod) * (x % mod)) % mod;
x = ((x % mod) * (x % mod)) % mod;
y >>= 1;
}
return result;
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 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], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107]]
| 8
| 441
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoders {
class Program {
static void Main(string[] args) {
var inputArray = retreiveLongArray();
var inputCount = 3;
// 不正な入力は処理しない
if (inputArray.Length != inputCount) {
Console.WriteLine("invalid input");
return;
}
var N = inputArray[0];
var a = inputArray[1];
var b = inputArray[2];
//答えの出力
var ans = getAns(N, a, b);
Console.WriteLine(ans);
}
/// <summary>
/// 答えを求める
/// </summary>
/// <param name="N"></param>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
private static long getAns(long N, long a, long b) {
if (N == 2) {
return 0;
}
long limit = 1000000000 + 7;
// a,bの条件を考えない場合 2n-1通り。(-1は一本も選ばないとき)
var pattern = repeatNijou(2, N, limit) - 1;
var ans =
pattern - calcCombination(N, a, limit) - calcCombination(N, a, limit);
// nCaをlimitで割ったあまりは,
while (ans < 0) {
ans = ans + limit;
}
return ans;
}
/// <summary>
/// 繰り返し2乗法
/// </summary>
/// <param name="tei"></param>
/// <param name="beki"></param>
/// <param name="limit"></param>
/// <returns></returns>
private static long repeatNijou(long tei, long beki, long limit) {
if (beki == 1) {
return tei;
}
var result = repeatNijou(tei, beki / 2, limit) % limit;
//べきが偶数のときは、半分同士をかける
if (beki % 2 == 0) {
var ans = result * result;
return (ans % limit);
} //べきが奇数の時
else {
var ans = ((result * result) % limit) * tei;
return (ans % limit);
}
}
/// <summary>
/// n個からp個を選ぶ組み合わせの数をlimitで割ったあまりを求める
/// X*Y(limit-2)
/// </summary>
/// <param name="n"></param>
/// <param name="p"></param>
/// <returns></returns>
private static long calcCombination(long N, long p, long limit) {
long x = 1;
long y = 1;
for (long i = 0; i < p; i++) {
x = (x * (N - i)) % limit;
y = (y * (p - i)) % limit;
// Console.WriteLine($"p={p},combi={combinationNum}");
}
var longAns = x * repeatNijou(y, limit - 2, limit);
return longAns;
}
/// <summary>
/// スペースで区切られた文字列配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static string[] retreiveStringArray() {
var inputArray = Console.ReadLine().Split(' ');
return inputArray;
}
/// <summary>
/// スペースで区切られた整数配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static long[] retreiveLongArray() {
var inputArray = Console.ReadLine().Split(' ');
var longArray = inputArray.Select(s => long.Parse(s));
return longArray.ToArray();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoders {
class Program {
static void Main(string[] args) {
var inputArray = retreiveLongArray();
var inputCount = 3;
// 不正な入力は処理しない
if (inputArray.Length != inputCount) {
Console.WriteLine("invalid input");
return;
}
var N = inputArray[0];
var a = inputArray[1];
var b = inputArray[2];
//答えの出力
var ans = getAns(N, a, b);
Console.WriteLine(ans);
}
/// <summary>
/// 答えを求める
/// </summary>
/// <param name="N"></param>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
private static long getAns(long N, long a, long b) {
if (N == 2) {
return 0;
}
long limit = 1000000000 + 7;
// a,bの条件を考えない場合 2n-1通り。(-1は一本も選ばないとき)
var pattern = repeatNijou(2, N, limit) - 1;
// Console.WriteLine($"合計{pattern}");
var num_a = calcCombination(N, a, limit);
var num_b = calcCombination(N, b, limit);
var ans = pattern - num_a - num_b;
// nCaをlimitで割ったあまりは,
while (ans < 0) {
// Console.WriteLine($"途中経過{ans}");
ans = ans + limit;
}
return ans;
}
/// <summary>
/// 繰り返し2乗法
/// </summary>
/// <param name="tei"></param>
/// <param name="beki"></param>
/// <param name="limit"></param>
/// <returns></returns>
private static long repeatNijou(long tei, long beki, long limit) {
if (beki == 1) {
return tei;
}
var result = repeatNijou(tei, beki / 2, limit) % limit;
//べきが偶数のときは、半分同士をかける
if (beki % 2 == 0) {
var ans = result * result;
return (ans % limit);
} //べきが奇数の時
else {
var ans = ((result * result) % limit) * tei;
return (ans % limit);
}
}
/// <summary>
/// n個からp個を選ぶ組み合わせの数をlimitで割ったあまりを求める
/// X*Y(limit-2)
/// </summary>
/// <param name="n"></param>
/// <param name="p"></param>
/// <returns></returns>
private static long calcCombination(long N, long p, long limit) {
long x = 1;
long y = 1;
for (long i = 0; i < p; i++) {
x = (x * (N - i)) % limit; //分子
y = (y * (i + 1)) % limit; //分母
// Console.WriteLine($"p={p},combi={combinationNum}");
}
var longAns = x * repeatNijou(y, limit - 2, limit);
return longAns % limit;
}
/// <summary>
/// スペースで区切られた文字列配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static string[] retreiveStringArray() {
var inputArray = Console.ReadLine().Split(' ');
return inputArray;
}
/// <summary>
/// スペースで区切られた整数配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static long[] retreiveLongArray() {
var inputArray = Console.ReadLine().Split(' ');
var longArray = inputArray.Select(s => long.Parse(s));
return longArray.ToArray();
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 8, 201, 0, 195, 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, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["+", 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, 22], ["-", 31, 23, 0, 16, 12, 23, 0, 16, 31, 22], ["-", 31, 23, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 17, 109], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 12, 22]]
| 8
| 506
| 26
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
var num = long.Parse(input[0]);
var hateNum1 = long.Parse(input[1]);
var hateNum2 = long.Parse(input[2]);
var sum = Calc.ModPow(2, num, 1000000007) - 1;
long x1 = 1;
long x2 = 1;
for (var i = 0; i < hateNum1; i++) {
x1 *= (num - i);
x1 %= 1000000007;
}
for (var i = 0; i < hateNum2; i++) {
x2 *= (num - i);
x2 %= 1000000007;
}
var hate1 =
(x1 * (Calc.ModPow(Calc.Factorial(hateNum1), 1000000005, 1000000007))) %
1000000007;
var hate2 =
(x2 * (Calc.ModPow(Calc.Factorial(hateNum2), 1000000005, 1000000007))) %
1000000007;
long result = 0;
if (sum - hate1 - hate2 < 0) {
result = (1000000007 + sum - hate1 - hate2) % 1000000007;
} else {
result = (sum - hate1 - hate2) % 1000000007;
}
Console.WriteLine(result);
}
}
class Calc {
public static long Factorial(long n) {
var result = n;
if (n > 0) {
while (n > 1) {
n--;
result *= n;
result %= 1000000007;
}
return result;
} else {
return 1;
}
}
public static long ModPow(long b, long pow, long mod) {
if (pow == 1) {
return b % mod;
}
long n = ModPow(b, pow / 2, mod) % mod;
if (pow % 2 == 0) {
return (n * n) % mod;
} else {
return (b * ((n * n) % mod)) % mod;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
var num = long.Parse(input[0]);
var hateNum1 = long.Parse(input[1]);
var hateNum2 = long.Parse(input[2]);
var sum = Calc.ModPow(2, num, 1000000007) - 1;
long x1 = 1;
long x2 = 1;
for (var i = 0; i < hateNum1; i++) {
x1 *= (num - i);
x1 %= 1000000007;
}
for (var i = 0; i < hateNum2; i++) {
x2 *= (num - i);
x2 %= 1000000007;
}
var hate1 =
(x1 * (Calc.ModPow(Calc.Factorial(hateNum1), 1000000005, 1000000007))) %
1000000007;
var hate2 =
(x2 * (Calc.ModPow(Calc.Factorial(hateNum2), 1000000005, 1000000007))) %
1000000007;
long result = 0;
if (sum - hate1 - hate2 < 0) {
result = (2000000014 + sum - hate1 - hate2) % 1000000007;
} else {
result = (sum - hate1 - hate2) % 1000000007;
}
Console.WriteLine(result);
Console.ReadLine();
}
}
class Calc {
public static long Factorial(long n) {
var result = n;
if (n > 0) {
while (n > 1) {
n--;
result *= n;
result %= 1000000007;
}
return result;
} else {
return 1;
}
}
public static long ModPow(long b, long pow, long mod) {
if (pow == 1) {
return b % mod;
}
long n = ModPow(b, pow / 2, mod) % mod;
if (pow % 2 == 0) {
return (n * n) % mod;
} else {
return (b * ((n * n) % mod)) % mod;
}
}
}
|
[["-", 31, 23, 0, 16, 31, 16, 31, 16, 31, 203], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 31, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
| 8
| 413
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
class readint {
public readint(out int i) { i = int.Parse(Console.ReadLine()); }
public readint(out int a, out int b) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readint(out int a, out int b, out int c) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readint(out int a, out int b, out int c, out int d) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class readlong {
public readlong(out long i) { i = long.Parse(Console.ReadLine()); }
public readlong(out long a, out long b) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readlong(out long a, out long b, out long c) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readlong(out long a, out long b, out long c, out long d) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class Util {
public static int[] readintarr() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static long[] readlongarr() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
/// <summary>
/// nの約数を小さい順のリストで返します。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static List<int> make_divisor(int n) {
List<int> output = new List<int>();
for (int i = 1; i <= Math.Sqrt(n) + 1; i++) {
if (n % i == 0) {
output.Add(i);
if (i * i != n) {
output.Add(n / i);
}
}
}
output.Sort();
return output;
}
// iの素因数分解をします
public static List<int> soinsuuBunkai(int n) {
//素因数分解をします
List<int> output = new List<int>();
int target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
public static List<long> soinsuuBunkai(long n) {
List<long> output = new List<long>();
long target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
/// <summary>
/// 2引数の最大公約数を返します。longです。
/// </summary>
/// <param name="a">long 引数1</param>
/// <param name="b">long 引数2</param>
/// <returns></returns>
public static long GCD(long a, long b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2引数の最大公約数を返します。intです。
/// </summary>
/// <param name="a">int 引数1</param>
/// <param name="b">int 引数2</param>
/// <returns></returns>
public static int GCD(int a, int b) {
// if (a < b)
// swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2つの変数の中身を交換する。型はなんでもいい
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="a"></param>
/// <param name="b"></param>
public static void swap<T>(ref T a, ref T b) {
T temp = b;
b = a;
a = temp;
}
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); }
public static int M = (int)(Math.Pow(10, 9)) + 7;
private static int[] factorial_modM;
/// <summary>
/// 2引数の積 mod Mを求める。Mは10億7。
/// 変えられるよ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Multiple_modM(int a, int b) {
return (int)(Math.BigMul(a, b) % M);
}
/// <summary>
/// n! modMを求めるための準備を行う。引数は最大値。
/// </summary>
/// <param name="n"></param>
public static void factorial_modM_Prepare(int n) {
factorial_modM = new int[n + 1];
factorial_modM[0] = 1;
for (int i = 1; i <= n; ++i) {
factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i);
}
}
/// <summary>
/// n! mod M を返す。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static int Factorial(int n) { return factorial_modM[n]; }
/// <summary>
/// a^m modMを求める
/// </summary>
/// <param name="a"></param>
/// <param name="m"></param>
/// <returns></returns>
public static int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Multiple_modM(p1, p1);
return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a);
}
}
/// <summary>
/// a / m Mod M を求める。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Div(int a, int b) {
return Multiple_modM(a, Pow(b, M - 2));
}
/// <summary>
/// nCr mod M を求める。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <param name="r"></param>
/// <returns></returns>
public static int nCr_modM(int n, int r) {
if (r < 0)
return 0;
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int res = Factorial(n);
res = Div(res, Factorial(r));
res = Div(res, Factorial(n - r));
return res;
}
}
/// <summary>
/// Union-Find木を定義する。コンストラクタの指定は、頂点の番号。
/// おすすめとしては、UnionFind<T>[] で宣言してしまう。
/// </summary>
/// <typeparam name="T">int固定でいいよね。</typeparam>
class UnionFind<T> {
public int tree_height;
public UnionFind<T> parent;
public T item { get; private set; }
public UnionFind(T item) {
tree_height = 0;
parent = this;
}
/// <summary>
/// 一番上の親を探す。
/// 探しながら繋がり方を最適化している。
/// UnionFindの頂点そのものを返すので、==での比較が可能。
/// </summary>
/// <returns></returns>
public UnionFind<T> FindAdam() {
if (parent == this)
return this;
else {
UnionFind<T> ParentOfParent = parent.FindAdam();
parent = ParentOfParent; //縦長な構成をつなぎ直している
return ParentOfParent;
}
}
/// <summary>
/// unionfind2つを一つにつなぐ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public static void Unite(UnionFind<T> a, UnionFind<T> b) {
UnionFind<T> ParentOfA = a.FindAdam();
UnionFind<T> ParentOfB = b.FindAdam();
if (ParentOfA.tree_height < ParentOfB.tree_height) {
ParentOfA.parent = ParentOfB;
ParentOfB.tree_height =
Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height);
} else {
ParentOfB.parent = ParentOfA;
ParentOfA.tree_height =
Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height);
}
}
}
// Treap 平衡二分木
class Treap<T>
where T : IComparable {
private class Node {
private static Random g_rand = new Random();
private readonly int m_rank = g_rand.Next();
private readonly T m_value;
private Node m_lch;
private Node m_rch;
private int m_count;
public Node(T value) {
m_value = value;
m_count = 1;
}
private static int Count(Node node) {
return (node != null) ? node.m_count : 0;
}
private Node Update() {
m_count = Count(m_lch) + Count(m_rch) + 1;
return this;
}
public static Node Merge(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
if (a.m_rank < b.m_rank) {
a.m_rch = Merge(a.m_rch, b);
return a.Update();
} else {
b.m_lch = Merge(a, b.m_lch);
return b.Update();
}
}
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null) {
return new Tuple<Node, Node>(null, null);
}
if (k <= Count(t.m_lch)) {
var pair = Split(t.m_lch, k);
t.m_lch = pair.Item2;
return new Tuple<Node, Node>(pair.Item1, t.Update());
} else {
var pair = Split(t.m_rch, k - Count(t.m_lch) - 1);
t.m_rch = pair.Item1;
return new Tuple<Node, Node>(t.Update(), pair.Item2);
}
}
public int FindIndex(T value) {
int L = Count(m_lch);
if (value.CompareTo(m_value) < 0) {
return (m_lch != null) ? m_lch.FindIndex(value) : 0;
} else if (value.CompareTo(m_value) > 0) {
return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1;
} else {
return L;
}
}
public T this[int i] {
get {
int L = Count(m_lch);
if (i < L) {
return m_lch[i];
} else if (i > L) {
return m_rch[i - L - 1];
} else {
return m_value;
}
}
}
}
private Node node;
public void Insert(T value) {
if (node != null) {
int k = node.FindIndex(value);
var pair = Node.Split(node, k);
node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2);
} else {
node = new Node(value);
}
}
public int FindIndex(T value) { return node.FindIndex(value); }
public T this[int i] {
get { return node[i]; }
}
}
/// <summary>
/// 使い方:Permutation.next(配列) で次の配列を返す
/// 配列を受け取って、その配列の要素を全部使った組み合わせのうち、辞書順で次のものを返します。
/// もし、次のがない場合、空の配列を返します。
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Permutation<T>
where T : IComparable {
public static T[] next(T[] letters) {
int pivot = -1;
for (int i = letters.Length - 2; i >= 0; i--) {
if (letters[i].CompareTo(letters[i + 1]) < 0) {
pivot = i;
break;
}
}
if (pivot == -1) {
return new T[0];
}
int big_min = letters.Length - 1;
T big_min_T = letters[letters.Length - 1];
for (int i = letters.Length - 1; i > pivot;
i--) { // big_min_Tより小さいかつ、pivotのより大きい
if (letters[pivot].CompareTo(letters[i]) > 0 &&
letters[pivot].CompareTo(big_min_T) < 0) {
big_min_T = letters[i];
big_min = i;
}
}
T temp = letters[pivot];
letters[pivot] = letters[big_min];
letters[big_min] = temp;
Array.Sort(letters, pivot + 1, letters.Length - pivot - 1);
return letters;
}
}
/// <summary>
/// 使い方 : Combination
/// .AllCombination(使える文字を、小さい順から配列にしたもの,ほしい文字数)
/// 使える文字を、小さい順から配列にしたものを重複ありで組み合わせて、stringのlistで出力する
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Combination<T>
where T : IComparable {
private static bool stop = false;
public static List<string> AllCombination(T[] letters, int n) {
// n桁ですよね。
List<string> outlist = new List<string>();
T[] state = new T[n];
for (int i = 0; i < n; i++) {
state[i] = letters[0];
}
outlist.Add(String.Join(" ", state));
while (true) {
next_keta(ref state, state.Length - 1, letters);
if (stop)
break;
outlist.Add(string.Join(" ", state));
}
return outlist;
}
public static T[] next_keta(ref T[] state, int keta, T[] letters) {
if (keta == -1) {
stop = true;
return new T[0];
}
if (state[keta].CompareTo(letters[letters.Length - 1]) == 0) {
//見た桁を最初の要素にする処理を
state[keta] = letters[0];
return next_keta(ref state, keta - 1, letters);
} else {
int ketaindex = 0;
for (int i = 0; i < letters.Length; i++) {
if (state[keta].CompareTo(letters[i]) == 0) {
ketaindex = i;
break;
}
}
state[keta] = letters[ketaindex + 1];
return state;
}
}
}
namespace CompLib.Collections {
#region PriorityQueue
/// <summary>
/// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します.
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam>
/// <remarks>内部的にはバイナリヒープによって実装されています.</remarks>
public class PriorityQueue<T> {
readonly List<T> heap = new List<T>();
readonly Comparison<T> cmp;
/// <summary>
/// デフォルトの比較子を使用してインスタンスを初期化します.
/// </summary>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue() { cmp = Comparer<T>.Default.Compare; }
/// <summary>
/// デリゲートで表されるような比較関数を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparison"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }
/// <summary>
/// 指定された比較子を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparer"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; }
/// <summary>
/// 優先度付きキューに要素を追加します.
/// </summary>
/// <param name="item">優先度付きキューに追加される要素</param>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public void Enqueue(T item) {
var pos = heap.Count;
heap.Add(item);
while (pos > 0) {
var par = (pos - 1) / 2;
if (cmp(heap[par], item) <= 0)
break;
heap[pos] = heap[par];
pos = par;
}
heap[pos] = item;
}
/// <summary>
/// 優先度付きキューから最も価値が低い要素を削除し,返します.
/// </summary>
/// <returns>優先度付きキューから削除された要素.</returns>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public T Dequeue() {
var ret = heap[0];
var pos = 0;
var x = heap[heap.Count - 1];
while (pos * 2 + 1 < heap.Count - 1) {
var lch = pos * 2 + 1;
var rch = pos * 2 + 2;
if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0)
lch = rch;
if (cmp(heap[lch], x) >= 0)
break;
heap[pos] = heap[lch];
pos = lch;
}
heap[pos] = x;
heap.RemoveAt(heap.Count - 1);
return ret;
}
/// <summary>
/// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します.
/// </summary>
/// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public T Peek() { return heap[0]; }
/// <summary>
/// 優先度付きキュー内の要素の数を取得します.
/// </summary>
/// <returns>優先度付キュー内にある要素の数</returns>
/// <remarks>最悪計算量 O(1) で実行されます.</remarks>
public int Count {
get { return heap.Count; }
}
/// <summary>
/// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します.
/// </summary>
/// <returns>優先度付キュー内にある要素が存在するならば
/// true,そうでなければ false.</returns> <remarks>この操作は O(1)
/// で実行されます.</remarks>
public bool Any() { return heap.Count > 0; }
/// <summary>
/// 優先度付きキューに含まれる要素を昇順に並べて返します.
/// </summary>
/// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks>
public T[] Items {
get {
var ret = heap.ToArray();
Array.Sort(ret, cmp);
return ret;
}
}
}
#endregion
}
/// <summary>
/// SEGTREEは1-BASE運用でございます
/// よろしくおねがいします
/// あと絶対コンストラクタ使ってね
/// </summary>
/// <typeparam name="T"></typeparam>
class Segtree<T> {
int n; //高さ
T[] tree; //本体
Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか
T exnum; //初期値
int count;
/// <summary>
/// !!!WARNING!!! 1-BASEです。
/// </summary>
/// <param name="m">最大値。200001とか入れておくとよい</param>
/// <param name="f">2引数の関数</param>
/// <param
/// name="ex">葉に書いてある値の初期値。fの関数に影響を与えない数値、零元とかにしておくべき。バグり散らかす。</param>
public Segtree(int m, Func<T, T, T> f, T ex) {
this.count = 0;
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
this.count = 0;
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
/// <summary>
/// j番目の値をxにする。計算し直さないので、
/// 入れ替えた後はall_update();を使おう
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
/// <summary>
/// j番目の値をxにする。計算し直すので、ちょっと計算時間がかかる
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void update(int j, T x) // j番目をxにする
{
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
this.count++;
}
/// <summary>
/// 木を全部計算し直す。多分NlogN。違うかも知れないから
/// よかったら教えて
/// </summary>
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
/// <summary>
/// j番目を消す。
/// </summary>
/// <param name="j"></param>
public void delete (int j) {
int i = j + n - 1;
tree[i] = exnum;
int moved = 0;
while (true) {
tree[i + 1] = tree[i];
T check = tree[i];
moved++;
if (moved + j + 2 > count) {
break;
}
}
all_update();
}
// [s, t)
/// <summary>
/// s番目からt番目までの結果を返す。
/// これも当然のように1-BASE.
/// </summary>
/// <param name="s"></param>
/// <param name="t"></param>
/// <returns></returns>
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class pair<T> {
public T A;
public T B;
public pair() {}
public pair(T A, T B) {
this.A = A;
this.B = B;
}
}
public class ABC {
// long[] sp = Console.ReadLine().Split().Select(long
// .Parse).ToArray(); int[] sp =
// Console.ReadLine().Split().Select(int.Parse).ToArray(); int N =
// int.Parse(Console.ReadLine());
// CompLib.Collections.PriorityQueue<?>
//文字列比較のcomparer
// StringComparer.OrdinalIgnoreCase
public static void Main() {
int N, a, b;
new readint(out N, out a, out b);
int ichi = Util.Pow(2, N) - 1;
ichi = ichi % Util.M;
long ni = 1;
long san = 1;
if (a >= N / 2)
a = N - a;
if (b >= N / 2)
b = N - b;
for (int i = 1; i <= a; i++) {
ni *= (N + 1 - i);
ni %= Util.M;
ni = Util.Div((int)ni, i);
}
for (int i = 1; i <= b; i++) {
san *= (N + 1 - i);
san %= Util.M;
san = Util.Div((int)san, i);
}
ni = ni % Util.M;
san = san % Util.M;
long sum = ichi - ni - san;
if (sum < 0)
sum += Util.M;
sum %= Util.M;
Console.WriteLine(sum);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
class readint {
public readint(out int i) { i = int.Parse(Console.ReadLine()); }
public readint(out int a, out int b) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readint(out int a, out int b, out int c) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readint(out int a, out int b, out int c, out int d) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class readlong {
public readlong(out long i) { i = long.Parse(Console.ReadLine()); }
public readlong(out long a, out long b) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readlong(out long a, out long b, out long c) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readlong(out long a, out long b, out long c, out long d) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class Util {
public static int[] readintarr() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static long[] readlongarr() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
/// <summary>
/// nの約数を小さい順のリストで返します。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static List<int> make_divisor(int n) {
List<int> output = new List<int>();
for (int i = 1; i <= Math.Sqrt(n) + 1; i++) {
if (n % i == 0) {
output.Add(i);
if (i * i != n) {
output.Add(n / i);
}
}
}
output.Sort();
return output;
}
// iの素因数分解をします
public static List<int> soinsuuBunkai(int n) {
//素因数分解をします
List<int> output = new List<int>();
int target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
public static List<long> soinsuuBunkai(long n) {
List<long> output = new List<long>();
long target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
/// <summary>
/// 2引数の最大公約数を返します。longです。
/// </summary>
/// <param name="a">long 引数1</param>
/// <param name="b">long 引数2</param>
/// <returns></returns>
public static long GCD(long a, long b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2引数の最大公約数を返します。intです。
/// </summary>
/// <param name="a">int 引数1</param>
/// <param name="b">int 引数2</param>
/// <returns></returns>
public static int GCD(int a, int b) {
// if (a < b)
// swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2つの変数の中身を交換する。型はなんでもいい
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="a"></param>
/// <param name="b"></param>
public static void swap<T>(ref T a, ref T b) {
T temp = b;
b = a;
a = temp;
}
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); }
public static int M = (int)(Math.Pow(10, 9)) + 7;
private static int[] factorial_modM;
/// <summary>
/// 2引数の積 mod Mを求める。Mは10億7。
/// 変えられるよ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Multiple_modM(int a, int b) {
return (int)(Math.BigMul(a, b) % M);
}
/// <summary>
/// n! modMを求めるための準備を行う。引数は最大値。
/// </summary>
/// <param name="n"></param>
public static void factorial_modM_Prepare(int n) {
factorial_modM = new int[n + 1];
factorial_modM[0] = 1;
for (int i = 1; i <= n; ++i) {
factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i);
}
}
/// <summary>
/// n! mod M を返す。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static int Factorial(int n) { return factorial_modM[n]; }
/// <summary>
/// a^m modMを求める
/// </summary>
/// <param name="a"></param>
/// <param name="m"></param>
/// <returns></returns>
public static int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Multiple_modM(p1, p1);
return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a);
}
}
/// <summary>
/// a / m Mod M を求める。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Div(int a, int b) {
return Multiple_modM(a, Pow(b, M - 2));
}
/// <summary>
/// nCr mod M を求める。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <param name="r"></param>
/// <returns></returns>
public static int nCr_modM(int n, int r) {
if (r < 0)
return 0;
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int res = Factorial(n);
res = Div(res, Factorial(r));
res = Div(res, Factorial(n - r));
return res;
}
}
/// <summary>
/// Union-Find木を定義する。コンストラクタの指定は、頂点の番号。
/// おすすめとしては、UnionFind<T>[] で宣言してしまう。
/// </summary>
/// <typeparam name="T">int固定でいいよね。</typeparam>
class UnionFind<T> {
public int tree_height;
public UnionFind<T> parent;
public T item { get; private set; }
public UnionFind(T item) {
tree_height = 0;
parent = this;
}
/// <summary>
/// 一番上の親を探す。
/// 探しながら繋がり方を最適化している。
/// UnionFindの頂点そのものを返すので、==での比較が可能。
/// </summary>
/// <returns></returns>
public UnionFind<T> FindAdam() {
if (parent == this)
return this;
else {
UnionFind<T> ParentOfParent = parent.FindAdam();
parent = ParentOfParent; //縦長な構成をつなぎ直している
return ParentOfParent;
}
}
/// <summary>
/// unionfind2つを一つにつなぐ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public static void Unite(UnionFind<T> a, UnionFind<T> b) {
UnionFind<T> ParentOfA = a.FindAdam();
UnionFind<T> ParentOfB = b.FindAdam();
if (ParentOfA.tree_height < ParentOfB.tree_height) {
ParentOfA.parent = ParentOfB;
ParentOfB.tree_height =
Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height);
} else {
ParentOfB.parent = ParentOfA;
ParentOfA.tree_height =
Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height);
}
}
}
// Treap 平衡二分木
class Treap<T>
where T : IComparable {
private class Node {
private static Random g_rand = new Random();
private readonly int m_rank = g_rand.Next();
private readonly T m_value;
private Node m_lch;
private Node m_rch;
private int m_count;
public Node(T value) {
m_value = value;
m_count = 1;
}
private static int Count(Node node) {
return (node != null) ? node.m_count : 0;
}
private Node Update() {
m_count = Count(m_lch) + Count(m_rch) + 1;
return this;
}
public static Node Merge(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
if (a.m_rank < b.m_rank) {
a.m_rch = Merge(a.m_rch, b);
return a.Update();
} else {
b.m_lch = Merge(a, b.m_lch);
return b.Update();
}
}
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null) {
return new Tuple<Node, Node>(null, null);
}
if (k <= Count(t.m_lch)) {
var pair = Split(t.m_lch, k);
t.m_lch = pair.Item2;
return new Tuple<Node, Node>(pair.Item1, t.Update());
} else {
var pair = Split(t.m_rch, k - Count(t.m_lch) - 1);
t.m_rch = pair.Item1;
return new Tuple<Node, Node>(t.Update(), pair.Item2);
}
}
public int FindIndex(T value) {
int L = Count(m_lch);
if (value.CompareTo(m_value) < 0) {
return (m_lch != null) ? m_lch.FindIndex(value) : 0;
} else if (value.CompareTo(m_value) > 0) {
return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1;
} else {
return L;
}
}
public T this[int i] {
get {
int L = Count(m_lch);
if (i < L) {
return m_lch[i];
} else if (i > L) {
return m_rch[i - L - 1];
} else {
return m_value;
}
}
}
}
private Node node;
public void Insert(T value) {
if (node != null) {
int k = node.FindIndex(value);
var pair = Node.Split(node, k);
node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2);
} else {
node = new Node(value);
}
}
public int FindIndex(T value) { return node.FindIndex(value); }
public T this[int i] {
get { return node[i]; }
}
}
/// <summary>
/// 使い方:Permutation.next(配列) で次の配列を返す
/// 配列を受け取って、その配列の要素を全部使った組み合わせのうち、辞書順で次のものを返します。
/// もし、次のがない場合、空の配列を返します。
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Permutation<T>
where T : IComparable {
public static T[] next(T[] letters) {
int pivot = -1;
for (int i = letters.Length - 2; i >= 0; i--) {
if (letters[i].CompareTo(letters[i + 1]) < 0) {
pivot = i;
break;
}
}
if (pivot == -1) {
return new T[0];
}
int big_min = letters.Length - 1;
T big_min_T = letters[letters.Length - 1];
for (int i = letters.Length - 1; i > pivot;
i--) { // big_min_Tより小さいかつ、pivotのより大きい
if (letters[pivot].CompareTo(letters[i]) > 0 &&
letters[pivot].CompareTo(big_min_T) < 0) {
big_min_T = letters[i];
big_min = i;
}
}
T temp = letters[pivot];
letters[pivot] = letters[big_min];
letters[big_min] = temp;
Array.Sort(letters, pivot + 1, letters.Length - pivot - 1);
return letters;
}
}
/// <summary>
/// 使い方 : Combination
/// .AllCombination(使える文字を、小さい順から配列にしたもの,ほしい文字数)
/// 使える文字を、小さい順から配列にしたものを重複ありで組み合わせて、stringのlistで出力する
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Combination<T>
where T : IComparable {
private static bool stop = false;
public static List<string> AllCombination(T[] letters, int n) {
// n桁ですよね。
List<string> outlist = new List<string>();
T[] state = new T[n];
for (int i = 0; i < n; i++) {
state[i] = letters[0];
}
outlist.Add(String.Join(" ", state));
while (true) {
next_keta(ref state, state.Length - 1, letters);
if (stop)
break;
outlist.Add(string.Join(" ", state));
}
return outlist;
}
public static T[] next_keta(ref T[] state, int keta, T[] letters) {
if (keta == -1) {
stop = true;
return new T[0];
}
if (state[keta].CompareTo(letters[letters.Length - 1]) == 0) {
//見た桁を最初の要素にする処理を
state[keta] = letters[0];
return next_keta(ref state, keta - 1, letters);
} else {
int ketaindex = 0;
for (int i = 0; i < letters.Length; i++) {
if (state[keta].CompareTo(letters[i]) == 0) {
ketaindex = i;
break;
}
}
state[keta] = letters[ketaindex + 1];
return state;
}
}
}
namespace CompLib.Collections {
#region PriorityQueue
/// <summary>
/// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します.
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam>
/// <remarks>内部的にはバイナリヒープによって実装されています.</remarks>
public class PriorityQueue<T> {
readonly List<T> heap = new List<T>();
readonly Comparison<T> cmp;
/// <summary>
/// デフォルトの比較子を使用してインスタンスを初期化します.
/// </summary>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue() { cmp = Comparer<T>.Default.Compare; }
/// <summary>
/// デリゲートで表されるような比較関数を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparison"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }
/// <summary>
/// 指定された比較子を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparer"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; }
/// <summary>
/// 優先度付きキューに要素を追加します.
/// </summary>
/// <param name="item">優先度付きキューに追加される要素</param>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public void Enqueue(T item) {
var pos = heap.Count;
heap.Add(item);
while (pos > 0) {
var par = (pos - 1) / 2;
if (cmp(heap[par], item) <= 0)
break;
heap[pos] = heap[par];
pos = par;
}
heap[pos] = item;
}
/// <summary>
/// 優先度付きキューから最も価値が低い要素を削除し,返します.
/// </summary>
/// <returns>優先度付きキューから削除された要素.</returns>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public T Dequeue() {
var ret = heap[0];
var pos = 0;
var x = heap[heap.Count - 1];
while (pos * 2 + 1 < heap.Count - 1) {
var lch = pos * 2 + 1;
var rch = pos * 2 + 2;
if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0)
lch = rch;
if (cmp(heap[lch], x) >= 0)
break;
heap[pos] = heap[lch];
pos = lch;
}
heap[pos] = x;
heap.RemoveAt(heap.Count - 1);
return ret;
}
/// <summary>
/// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します.
/// </summary>
/// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public T Peek() { return heap[0]; }
/// <summary>
/// 優先度付きキュー内の要素の数を取得します.
/// </summary>
/// <returns>優先度付キュー内にある要素の数</returns>
/// <remarks>最悪計算量 O(1) で実行されます.</remarks>
public int Count {
get { return heap.Count; }
}
/// <summary>
/// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します.
/// </summary>
/// <returns>優先度付キュー内にある要素が存在するならば
/// true,そうでなければ false.</returns> <remarks>この操作は O(1)
/// で実行されます.</remarks>
public bool Any() { return heap.Count > 0; }
/// <summary>
/// 優先度付きキューに含まれる要素を昇順に並べて返します.
/// </summary>
/// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks>
public T[] Items {
get {
var ret = heap.ToArray();
Array.Sort(ret, cmp);
return ret;
}
}
}
#endregion
}
/// <summary>
/// SEGTREEは1-BASE運用でございます
/// よろしくおねがいします
/// あと絶対コンストラクタ使ってね
/// </summary>
/// <typeparam name="T"></typeparam>
class Segtree<T> {
int n; //高さ
T[] tree; //本体
Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか
T exnum; //初期値
int count;
/// <summary>
/// !!!WARNING!!! 1-BASEです。
/// </summary>
/// <param name="m">最大値。200001とか入れておくとよい</param>
/// <param name="f">2引数の関数</param>
/// <param
/// name="ex">葉に書いてある値の初期値。fの関数に影響を与えない数値、零元とかにしておくべき。バグり散らかす。</param>
public Segtree(int m, Func<T, T, T> f, T ex) {
this.count = 0;
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
this.count = 0;
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
/// <summary>
/// j番目の値をxにする。計算し直さないので、
/// 入れ替えた後はall_update();を使おう
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
/// <summary>
/// j番目の値をxにする。計算し直すので、ちょっと計算時間がかかる
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void update(int j, T x) // j番目をxにする
{
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
this.count++;
}
/// <summary>
/// 木を全部計算し直す。多分NlogN。違うかも知れないから
/// よかったら教えて
/// </summary>
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
/// <summary>
/// j番目を消す。
/// </summary>
/// <param name="j"></param>
public void delete (int j) {
int i = j + n - 1;
tree[i] = exnum;
int moved = 0;
while (true) {
tree[i + 1] = tree[i];
T check = tree[i];
moved++;
if (moved + j + 2 > count) {
break;
}
}
all_update();
}
// [s, t)
/// <summary>
/// s番目からt番目までの結果を返す。
/// これも当然のように1-BASE.
/// </summary>
/// <param name="s"></param>
/// <param name="t"></param>
/// <returns></returns>
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class pair<T> {
public T A;
public T B;
public pair() {}
public pair(T A, T B) {
this.A = A;
this.B = B;
}
}
public class ABC {
// long[] sp = Console.ReadLine().Split().Select(long
// .Parse).ToArray(); int[] sp =
// Console.ReadLine().Split().Select(int.Parse).ToArray(); int N =
// int.Parse(Console.ReadLine());
// CompLib.Collections.PriorityQueue<?>
//文字列比較のcomparer
// StringComparer.OrdinalIgnoreCase
public static void Main() {
int N, a, b;
new readint(out N, out a, out b);
int ichi = Util.Pow(2, N) - 1;
ichi = ichi % Util.M;
long ni = 1;
long san = 1;
if (a >= N / 2)
a = N - a;
if (b >= N / 2)
b = N - b;
for (int i = 1; i <= a; i++) {
ni *= (N + 1 - i);
ni %= Util.M;
ni = Util.Div((int)ni, i);
}
for (int i = 1; i <= b; i++) {
san *= (N + 1 - i);
san %= Util.M;
san = Util.Div((int)san, i);
}
ni = ni % Util.M;
san = san % Util.M;
long sum = ichi;
sum -= ni;
if (sum < 0)
sum += Util.M;
sum -= san;
if (sum < 0)
sum += Util.M;
sum %= Util.M;
Console.WriteLine(sum);
}
}
|
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["+", 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, 110], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 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], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 1, 0, 11, 12, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 11, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 4,113
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
public class AtCoderD {
static void Main() {
long mod = 1000000007;
int n;
int a;
int b;
{
var line = Console.ReadLine();
var words = line.Split(' ');
n = int.Parse(words[0]);
a = int.Parse(words[1]);
b = int.Parse(words[2]);
}
long total = 1;
for (int i = 0; i < n; i++) {
if (n - i > 30) {
total *= (1024 * 1024);
i = i + 19;
} else {
total *= 2;
}
total = total % mod;
}
total -= 1;
// Console.WriteLine(total);
long ca = Combination(n, a);
long cb = Combination(n, b);
long answer = total - ca - cb;
if (answer < mod) {
answer += mod;
}
Console.WriteLine(answer % mod);
}
private static long Combination(int n, int k) {
long mod = 1000000007;
long answer = 1;
for (int i = n; i > n - k; i--) {
answer = mul(answer, i);
}
for (int i = 1; i <= k; i++) {
answer = div(answer, i);
}
return answer;
}
private static long mul(long a, long b) {
long mod = 1000000007;
return ((a % mod) * (b % mod)) % mod;
}
private static long pow(long a, long b) {
long mod = 1000000007;
if (b == 0) {
return 1;
} else if (b == 1) {
return a % mod;
} else if (b % 2 == 0) {
long d = pow(a, b / 2);
return d * d % mod;
} else {
return a * pow(a, b - 1) % mod;
}
}
private static long div(long a, long b) {
long mod = 1000000007;
return mul(a, pow(b, mod - 2));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class AtCoderD {
static void Main() {
long mod = 1000000007;
int n;
int a;
int b;
{
var line = Console.ReadLine();
var words = line.Split(' ');
n = int.Parse(words[0]);
a = int.Parse(words[1]);
b = int.Parse(words[2]);
}
long total = 1;
for (int i = 0; i < n; i++) {
if (n - i > 30) {
total *= (1024 * 1024);
i = i + 19;
} else {
total *= 2;
}
total = total % mod;
}
total -= 1;
// Console.WriteLine(total);
long ca = Combination(n, a);
long cb = Combination(n, b);
long answer = total - ca - cb;
if (answer < mod) {
answer += mod;
}
if (answer < mod) {
answer += mod;
}
Console.WriteLine(answer % mod);
}
private static long Combination(int n, int k) {
long mod = 1000000007;
long answer = 1;
for (int i = n; i > n - k; i--) {
answer = mul(answer, i);
}
for (int i = 1; i <= k; i++) {
answer = div(answer, i);
}
return answer;
}
private static long mul(long a, long b) {
long mod = 1000000007;
return ((a % mod) * (b % mod)) % mod;
}
private static long pow(long a, long b) {
long mod = 1000000007;
if (b == 0) {
return 1;
} else if (b == 1) {
return a % mod;
} else if (b % 2 == 0) {
long d = pow(a, b / 2);
return d * d % mod;
} else {
return a * pow(a, b - 1) % mod;
}
}
private static long div(long a, long b) {
long mod = 1000000007;
return mul(a, pow(b, mod - 2));
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 449
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1 {
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
public class Class1 {
static Dictionary<Tuple<long, long>, long> dic =
new Dictionary<Tuple<long, long>, long>();
static long mod = 1000000007;
static long[] factorial = new long[1000001];
static long[] invFactorial = new long[1000001];
private static void calcFanctorial(long N) {
factorial[0] = 1;
for (int i = 1; i < N + 1; i++) {
factorial[i] = factorial[i - 1] * i;
factorial[i] %= mod;
}
invFactorial[N] = inv(factorial[N]);
for (int i = (int)N; i > 0; i--) {
invFactorial[i - 1] = invFactorial[i] * i % mod;
}
}
static void Main(string[] args) {
// N = ReadLong();
var NN = ReadLongArr();
var n = NN[0];
var a = NN[1];
var b = NN[2];
calcFanctorial(200001);
long res = 1;
long tmp = 1;
n = NN[0];
tmp = bin(2, n, mod);
res = tmp;
res -= 1;
res -= nCm2(n, a);
res += mod;
res %= mod;
res -= nCm2(n, b);
res += mod;
res %= mod;
while (res < 0) {
res += mod;
}
Console.WriteLine(res);
}
static long bin(long a, long x, long n) {
long y = a;
long res = 1;
while (x > 0) {
if (x % 2 == 1) {
res = res * y % n;
}
x /= 2;
y = y * y % n;
}
Console.WriteLine(res);
return res;
}
int cmp(string a, string b) {
for (var i = 0; i < Math.Min(a.Length, b.Length); i++)
if (a[i] < b[i])
return -1;
else if (a[i] > b[i])
return 1;
if (a.Length == b.Length)
return 0;
if (a.Length > b.Length)
return 1;
else
return -1;
}
private static long nCm(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod;
}
private static long nCm2(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
long res = 1;
for (long i = n; i > n - m; i--) {
res *= i;
res %= mod;
}
return res * invFactorial[m] % mod;
}
public static long pow(long a, long b, long mod) {
a %= mod;
if (b <= 0)
return 1;
var t = pow(a, b / 2, mod);
if ((b & 1) == 0)
return t * t % mod;
return t * t % mod * a % mod;
}
public static long Lcm(long a, long b) {
return a * b % mod * inv(Gcd(a, b)) % mod;
}
public static long Lcm(long[] a) {
List<long> vect = new List<long>();
long lcm = 1;
for (int i = 0; i < a.Count(); i++) {
var factor = a[i] / GcdVector(vect, a[i]);
vect.Add(factor);
lcm = lcm * factor % mod;
}
return lcm;
}
static long GcdVector(List<long> a, long b) {
long ma = 1;
for (int i = 0; i < a.Count; i++)
ma = ma * a[i] % b;
return Gcd(b, ma);
}
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public static long pow(long a, long b) => pow(a, b, mod);
public static long inv(long a) => pow(a, mod - 2);
private static char[][] ReadCharMatrix(long h) {
char[][] mtx = new char [h][];
for (int i = 0; i < h; i++) {
var s = ReadString();
mtx[i] = s.ToCharArray();
}
return mtx;
}
private static int[][] CreateIntMatrix(long h, long w) {
int[][] mtx = new int [h][];
for (int i = 0; i < h; i++) {
mtx[i] = new int[w];
}
return mtx;
}
private static string ReadString() { return Console.ReadLine(); }
private static string[] ReadStringArr() {
return Console.ReadLine().Split(' ');
}
private static long ReadLong() { return long.Parse(Console.ReadLine()); }
private static long[] ReadLongArr() {
string[] s = ReadStringArr();
long[] l = new long[s.Length];
for (int i = 0; i < l.Length; i++) {
l[i] = long.Parse(s[i]);
}
return l;
}
}
class StringComparator2 : IComparer<string> {
int IComparer<string>.Compare(string a, string b) {
int length = Math.Min(a.Length, b.Length);
// Console.WriteLine("Comparing with length {0}", length);
for (int i = 0; i < length; i++) {
if (a[i] < b[i]) {
// Console.WriteLine("returning -1");
return -1;
} else if (a[i] > b[i])
return 1;
}
if (a.Length < b.Length)
return -1;
if (a.Length > b.Length)
return 1;
// Console.WriteLine("Why are we at the end?");
return 0;
}
}
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;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
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);
}
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() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1 {
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
public class Class1 {
static Dictionary<Tuple<long, long>, long> dic =
new Dictionary<Tuple<long, long>, long>();
static long mod = 1000000007;
static long[] factorial = new long[1000001];
static long[] invFactorial = new long[1000001];
private static void calcFanctorial(long N) {
factorial[0] = 1;
for (int i = 1; i < N + 1; i++) {
factorial[i] = factorial[i - 1] * i;
factorial[i] %= mod;
}
invFactorial[N] = inv(factorial[N]);
for (int i = (int)N; i > 0; i--) {
invFactorial[i - 1] = invFactorial[i] * i % mod;
}
}
static void Main(string[] args) {
// N = ReadLong();
var NN = ReadLongArr();
var n = NN[0];
var a = NN[1];
var b = NN[2];
calcFanctorial(200001);
long res = 1;
long tmp = 1;
n = NN[0];
tmp = bin(2, n, mod);
res = tmp;
res -= 1;
res -= nCm2(n, a);
res += mod;
res %= mod;
res -= nCm2(n, b);
res += mod;
res %= mod;
while (res < 0) {
res += mod;
}
Console.WriteLine(res);
}
static long bin(long a, long x, long n) {
long y = a;
long res = 1;
while (x > 0) {
if (x % 2 == 1) {
res = res * y % n;
}
x /= 2;
y = y * y % n;
}
return res;
}
int cmp(string a, string b) {
for (var i = 0; i < Math.Min(a.Length, b.Length); i++)
if (a[i] < b[i])
return -1;
else if (a[i] > b[i])
return 1;
if (a.Length == b.Length)
return 0;
if (a.Length > b.Length)
return 1;
else
return -1;
}
private static long nCm(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod;
}
private static long nCm2(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
long res = 1;
for (long i = n; i > n - m; i--) {
res *= i;
res %= mod;
}
return res * invFactorial[m] % mod;
}
public static long pow(long a, long b, long mod) {
a %= mod;
if (b <= 0)
return 1;
var t = pow(a, b / 2, mod);
if ((b & 1) == 0)
return t * t % mod;
return t * t % mod * a % mod;
}
public static long Lcm(long a, long b) {
return a * b % mod * inv(Gcd(a, b)) % mod;
}
public static long Lcm(long[] a) {
List<long> vect = new List<long>();
long lcm = 1;
for (int i = 0; i < a.Count(); i++) {
var factor = a[i] / GcdVector(vect, a[i]);
vect.Add(factor);
lcm = lcm * factor % mod;
}
return lcm;
}
static long GcdVector(List<long> a, long b) {
long ma = 1;
for (int i = 0; i < a.Count; i++)
ma = ma * a[i] % b;
return Gcd(b, ma);
}
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public static long pow(long a, long b) => pow(a, b, mod);
public static long inv(long a) => pow(a, mod - 2);
private static char[][] ReadCharMatrix(long h) {
char[][] mtx = new char [h][];
for (int i = 0; i < h; i++) {
var s = ReadString();
mtx[i] = s.ToCharArray();
}
return mtx;
}
private static int[][] CreateIntMatrix(long h, long w) {
int[][] mtx = new int [h][];
for (int i = 0; i < h; i++) {
mtx[i] = new int[w];
}
return mtx;
}
private static string ReadString() { return Console.ReadLine(); }
private static string[] ReadStringArr() {
return Console.ReadLine().Split(' ');
}
private static long ReadLong() { return long.Parse(Console.ReadLine()); }
private static long[] ReadLongArr() {
string[] s = ReadStringArr();
long[] l = new long[s.Length];
for (int i = 0; i < l.Length; i++) {
l[i] = long.Parse(s[i]);
}
return l;
}
}
class StringComparator2 : IComparer<string> {
int IComparer<string>.Compare(string a, string b) {
int length = Math.Min(a.Length, b.Length);
// Console.WriteLine("Comparing with length {0}", length);
for (int i = 0; i < length; i++) {
if (a[i] < b[i]) {
// Console.WriteLine("returning -1");
return -1;
} else if (a[i] > b[i])
return 1;
}
if (a.Length < b.Length)
return -1;
if (a.Length > b.Length)
return 1;
// Console.WriteLine("Why are we at the end?");
return 0;
}
}
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;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
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);
}
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() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 1,928
| 7
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
static class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
int N;
int a;
int b;
Multi(out N, out a, out b);
long sum = ModPow(2, N, mod) - 1;
List<long> Inv = new List<long>();
Inv.Add(0);
for (int i = 1; i <= 2 * 100000; i++) {
Inv.Add(GetInv(i, mod));
}
long A = 1;
for (int i = 0; i < a; i++) {
A = A * (N - i) % mod;
}
for (int i = 1; i <= a; i++) {
A = A * Inv[i] % mod;
}
long B = 1;
for (int i = 0; i < b; i++) {
B = B * (N - i) % mod;
}
for (int i = 1; i <= b; i++) {
B = B * Inv[i] % mod;
}
long ans = sum - A - B;
if (ans < 0) {
ans += mod;
}
Console.WriteLine(ans);
Console.Out.Flush();
Console.ReadKey();
}
static long GetInv(long a, long mod) { return ModPow(a, mod - 2, mod); }
static long ModPow(long a, long n, long mod) {
long res = 1;
while (n > 0) {
if ((n & 1) == 1) {
res = res * a % mod;
}
a = a * a % mod;
;
n >>= 1;
}
return res;
}
static long mod = 1000000007;
static public string GetStr() { return Console.ReadLine().Trim(); }
static public char GetChar() { return Console.ReadLine().Trim()[0]; }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
static public int[] GetIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Split(' ').Select(char.Parse).ToArray();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteObjects<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
static string yesno(this bool b) { return b ? "yes" : "no"; }
static string YesNo(this bool b) { return b ? "Yes" : "No"; }
static string YESNO(this bool b) { return b ? "YES" : "NO"; }
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
static class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
int N;
int a;
int b;
Multi(out N, out a, out b);
long sum = ModPow(2, N, mod) - 1;
List<long> Inv = new List<long>();
Inv.Add(0);
for (int i = 1; i <= 2 * 100000; i++) {
Inv.Add(GetInv(i, mod));
}
long A = 1;
for (int i = 0; i < a; i++) {
A = A * (N - i) % mod;
}
for (int i = 1; i <= a; i++) {
A = A * Inv[i] % mod;
}
long B = 1;
for (int i = 0; i < b; i++) {
B = B * (N - i) % mod;
}
for (int i = 1; i <= b; i++) {
B = B * Inv[i] % mod;
}
long ans = ((sum - A + mod) % mod - B + mod) % mod;
Console.WriteLine(ans);
Console.Out.Flush();
Console.ReadKey();
}
static long GetInv(long a, long mod) { return ModPow(a, mod - 2, mod); }
static long ModPow(long a, long n, long mod) {
long res = 1;
while (n > 0) {
if ((n & 1) == 1) {
res = res * a % mod;
}
a = a * a % mod;
;
n >>= 1;
}
return res;
}
static long mod = 1000000007;
static public string GetStr() { return Console.ReadLine().Trim(); }
static public char GetChar() { return Console.ReadLine().Trim()[0]; }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
static public int[] GetIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Split(' ').Select(char.Parse).ToArray();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteObjects<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
static string yesno(this bool b) { return b ? "yes" : "no"; }
static string YesNo(this bool b) { return b ? "Yes" : "No"; }
static string YESNO(this bool b) { return b ? "YES" : "NO"; }
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
}
|
[["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 16, 31, 16, 31, 16, 31, 23, 0, 25], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 17, 109], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 12, 22], ["-", 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], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 1,268
| 20
|
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
var NK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
var N = NK[0];
var K = NK[1];
// 0が0個の時
var ans = new Modular(1);
// 0がi個の時
for (long i = 1; i <= K && i < N; i++) {
ans +=
Modular.Ncr((int)N, (int)i) * Modular.Ncr((int)(N - 1), (int)i - 1);
}
Console.WriteLine(ans.value % 1000000007);
}
}
class Modular {
private const int M = 1000000007;
public long value;
public Modular(long value) { this.value = value; }
public static implicit operator Modular(long a) {
var m = a % M;
return new Modular((m < 0) ? m + M : m);
}
public static Modular operator +(Modular a, Modular b) {
return (a.value + b.value) % M;
}
public static Modular operator -(Modular a, Modular b) {
return a.value - b.value;
}
public static Modular operator *(Modular a, Modular b) {
return a.value * b.value;
}
public static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b) {
return a * Pow(b, M - 2);
}
private static readonly List<int> facs = new List<int> { 1 };
private static Modular Fac(int n) {
for (int i = facs.Count; i <= n; ++i) {
facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
}
return facs[n];
}
public static Modular Ncr(int n, int r) {
return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a) { return (int)a.value; }
public static Modular Lcm(Modular a, Modular b) {
var tmp = Gcdl(a.value, b.value);
return ((a * b) / new Modular(tmp));
}
static Modular Gcd(Modular m, Modular n) {
if (n.value > m.value)
return Gcd(n, m);
if (n.value == 0)
return m;
var r = new Modular(m.value % n.value);
return Gcd(n, r);
}
static long Gcdl(long m, long n) {
if (n > m)
return Gcdl(n, m);
if (n == 0)
return m;
return Gcdl(n, m % n);
}
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
var NK = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var N = NK[0];
var K = NK[1];
// 0が0個の時
var ans = new Modular(1);
// 0がi個の時
for (int i = 1; i <= K && i < N; i++) {
var b = Modular.Ncr(N, i);
ans += b * Modular.Ncr((N - 1), N - i - 1);
}
Console.WriteLine((int)ans);
}
}
class Modular {
private const int M = 1000000007;
public long value;
public Modular(long value) { this.value = value; }
public static implicit operator Modular(long a) {
var m = a % M;
return new Modular((m < 0) ? m + M : m);
}
public static Modular operator +(Modular a, Modular b) {
return (a.value + b.value) % M;
}
public static Modular operator -(Modular a, Modular b) {
return a.value - b.value;
}
public static Modular operator *(Modular a, Modular b) {
return a.value * b.value;
}
public static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b) {
return a * Pow(b, M - 2);
}
private static readonly List<int> facs = new List<int> { 1 };
private static Modular Fac(int n) {
for (int i = facs.Count; i <= n; ++i) {
facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
}
return facs[n];
}
public static Modular Ncr(int n, int r) {
return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a) { return (int)a.value; }
public static Modular Lcm(Modular a, Modular b) {
var tmp = Gcdl(a.value, b.value);
return ((a * b) / new Modular(tmp));
}
static Modular Gcd(Modular m, Modular n) {
if (n.value > m.value)
return Gcd(n, m);
if (n.value == 0)
return m;
var r = new Modular(m.value % n.value);
return Gcd(n, r);
}
static long Gcdl(long m, long n) {
if (n > m)
return Gcdl(n, m);
if (n == 0)
return m;
return Gcdl(n, m % n);
}
}
}
|
[["-", 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, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 31, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["-", 31, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["-", 31, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["+", 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, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 0, 11, 12, 16, 12, 213, 3, 4, 0, 24], ["-", 12, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["-", 12, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["-", 3, 4, 0, 28, 0, 16, 31, 74, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["-", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["-", 3, 4, 0, 28, 0, 16, 31, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 697
| 34
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC156E {
class Input {
/// <summary>
/// 1行の入力を取得する
/// </summary>
/// <returns>文字列</returns>
public string String() { return Console.ReadLine(); }
/// <summary>
/// 複数行の入力を取得
/// </summary>
/// <returns>文字列の配列</returns>
public string[] ArrayString(int rowNumber) {
string[] s = new string[rowNumber];
for (int i = 0; i < rowNumber; i++) {
s[i] = String();
}
return s;
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>int型の値</returns>
public int Int() { return int.Parse(String()); }
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>int型の配列</returns>
public int[] ArrayInt() { return Split().Select(int.Parse).ToArray(); }
/// <summary>
/// 複数行の入力を取得
/// </summary>
/// <param name="rowNumber">行数</param>
/// <returns>int型の配列</returns>
public int[] ArrayInt(int rowNumber) {
int[] ints = new int[rowNumber];
for (int i = 0; i < rowNumber; i++) {
ints[i] = Int();
}
return ints;
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>long型の値</returns>
public long Long() { return long.Parse(String()); }
/// <summary>
/// 2つの整数が1行に書かれている入力を、2つのlongで受け取る
/// </summary>
/// <param name="A"></param>
/// <param name="B"></param>
public void Longs(ref long A, ref long B) {
var longs = ArrayLong();
A = longs[0];
B = longs[1];
}
/// <summary>
/// 3つの整数が1行に書かれている入力を、3つのlongで受け取る
/// </summary>
/// <param name="A"></param>
/// <param name="B"></param>
/// <param name="C"></param>
public void Longs(ref long A, ref long B, ref long C) {
var longs = ArrayLong();
A = longs[0];
B = longs[1];
C = longs[2];
}
/// <summary>
/// 4つの整数が1行に書かれている入力を、4つのlongで受け取る
/// </summary>
/// <param name="A"></param>
/// <param name="B"></param>
/// <param name="C"></param>
/// <param name="D"></param>
public void Longs(ref long A, ref long B, ref long C, ref long D) {
var longs = ArrayLong();
A = longs[0];
B = longs[1];
C = longs[2];
D = longs[3];
}
/// <summary>
/// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="A"></param>
/// <param name="B"></param>
public void LongsArray(long rowNumber, ref long[] A, ref long[] B) {
A = new long[rowNumber];
B = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
var l = ArrayLong();
A[i] = l[0];
B[i] = l[1];
}
}
/// <summary>
/// 3つの整数が複数行に書かれている入力を、2つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="A"></param>
/// <param name="B"></param>
/// <param name="C"></param>
public void LongsArray(long rowNumber, ref long[] A, ref long[] B,
ref long[] C) {
A = new long[rowNumber];
B = new long[rowNumber];
C = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
var l = ArrayLong();
A[i] = l[0];
B[i] = l[1];
C[i] = l[2];
}
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>long型の配列</returns>
public long[] ArrayLong() { return Split().Select(long.Parse).ToArray(); }
public long[] ArrayLong(int rowNumber) {
long[] longs = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
longs[i] = Long();
}
return longs;
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の値</returns>
public double Double() { return double.Parse(String()); }
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の配列</returns>
public double[] ArrayDouble() {
return Split().Select(double.Parse).ToArray();
}
private IEnumerable<string> Split() { return String().Split(' '); }
}
class Program {
static void Main(string[] args) {
Solver solver = new Solver();
solver.Solve();
}
}
class Solver {
public Solver() {
Input input = new Input();
input.Longs(ref N, ref K);
}
private long N;
private long K;
public void Solve() {
Modular ans = 0;
// Kが偶数
if (K % 2 == 0) {
// (1, 1, 1, ... , 1)
ans += 1;
}
Modular factN = Modular.Fac((int)N);
// iは結果に含まれる0の数
for (int i = 1; i <= N - 1; i++) {
// Kが足りないので0を作れない
if (i > K) {
break;
}
// Kの偶奇を考慮しない部屋の分割方法
Modular b = Modular.Ncr((int)N - 1, (int)N - i - 1);
// Console.WriteLine();
// Console.WriteLine(i);
// Console.WriteLine((int) b);
// Console.WriteLine((int)(factN / Modular.Fac(i) / Modular.Fac((int) N -
// i))); 0と0でない数字の並びを考える
ans = ans + b * (factN / Modular.Fac(i) / Modular.Fac((int)N - i));
// Console.WriteLine((int)ans);
}
Console.WriteLine((int)ans);
}
}
class Modular {
public static int M = 1000000007;
private long V;
public Modular(long v) { V = v; }
public static implicit operator Modular(long a) {
var m = a % M;
return new Modular(m < 0 ? m + M : m);
}
public static Modular operator +(Modular a, Modular b) { return a.V + b.V; }
public static Modular operator -(Modular a, Modular b) { return a.V - b.V; }
public static Modular operator *(Modular a, Modular b) { return a.V * b.V; }
public static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b) {
return a * Pow(b, M - 2);
}
private static readonly List<int> Facts = new List<int> { 1 };
public static Modular Fac(int n) {
for (int i = Facts.Count; i <= n; ++i) {
Facts.Add((int)(Math.BigMul(Facts.Last(), i) % M));
}
return Facts[n];
}
public static Modular Ncr(int n, int r) {
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
return Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a) { return (int)a.V; }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC156E {
class Input {
/// <summary>
/// 1行の入力を取得する
/// </summary>
/// <returns>文字列</returns>
public string String() { return Console.ReadLine(); }
/// <summary>
/// 複数行の入力を取得
/// </summary>
/// <returns>文字列の配列</returns>
public string[] ArrayString(int rowNumber) {
string[] s = new string[rowNumber];
for (int i = 0; i < rowNumber; i++) {
s[i] = String();
}
return s;
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>int型の値</returns>
public int Int() { return int.Parse(String()); }
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>int型の配列</returns>
public int[] ArrayInt() { return Split().Select(int.Parse).ToArray(); }
/// <summary>
/// 複数行の入力を取得
/// </summary>
/// <param name="rowNumber">行数</param>
/// <returns>int型の配列</returns>
public int[] ArrayInt(int rowNumber) {
int[] ints = new int[rowNumber];
for (int i = 0; i < rowNumber; i++) {
ints[i] = Int();
}
return ints;
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>long型の値</returns>
public long Long() { return long.Parse(String()); }
/// <summary>
/// 2つの整数が1行に書かれている入力を、2つのlongで受け取る
/// </summary>
/// <param name="A"></param>
/// <param name="B"></param>
public void Longs(ref long A, ref long B) {
var longs = ArrayLong();
A = longs[0];
B = longs[1];
}
/// <summary>
/// 3つの整数が1行に書かれている入力を、3つのlongで受け取る
/// </summary>
/// <param name="A"></param>
/// <param name="B"></param>
/// <param name="C"></param>
public void Longs(ref long A, ref long B, ref long C) {
var longs = ArrayLong();
A = longs[0];
B = longs[1];
C = longs[2];
}
/// <summary>
/// 4つの整数が1行に書かれている入力を、4つのlongで受け取る
/// </summary>
/// <param name="A"></param>
/// <param name="B"></param>
/// <param name="C"></param>
/// <param name="D"></param>
public void Longs(ref long A, ref long B, ref long C, ref long D) {
var longs = ArrayLong();
A = longs[0];
B = longs[1];
C = longs[2];
D = longs[3];
}
/// <summary>
/// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="A"></param>
/// <param name="B"></param>
public void LongsArray(long rowNumber, ref long[] A, ref long[] B) {
A = new long[rowNumber];
B = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
var l = ArrayLong();
A[i] = l[0];
B[i] = l[1];
}
}
/// <summary>
/// 3つの整数が複数行に書かれている入力を、2つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="A"></param>
/// <param name="B"></param>
/// <param name="C"></param>
public void LongsArray(long rowNumber, ref long[] A, ref long[] B,
ref long[] C) {
A = new long[rowNumber];
B = new long[rowNumber];
C = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
var l = ArrayLong();
A[i] = l[0];
B[i] = l[1];
C[i] = l[2];
}
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>long型の配列</returns>
public long[] ArrayLong() { return Split().Select(long.Parse).ToArray(); }
public long[] ArrayLong(int rowNumber) {
long[] longs = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
longs[i] = Long();
}
return longs;
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の値</returns>
public double Double() { return double.Parse(String()); }
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の配列</returns>
public double[] ArrayDouble() {
return Split().Select(double.Parse).ToArray();
}
private IEnumerable<string> Split() { return String().Split(' '); }
}
class Program {
static void Main(string[] args) {
Solver solver = new Solver();
solver.Solve();
}
}
class Solver {
public Solver() {
Input input = new Input();
input.Longs(ref N, ref K);
}
private long N;
private long K;
public void Solve() {
Modular ans = 1;
Modular factN = Modular.Fac((int)N);
// iは結果に含まれる0の数
for (int i = 1; i <= N - 1; i++) {
// Kが足りないので0を作れない
if (i > K) {
break;
}
// Kの偶奇を考慮しない部屋の分割方法
Modular b = Modular.Ncr((int)N - 1, (int)N - i - 1);
// Console.WriteLine();
// Console.WriteLine(i);
// Console.WriteLine((int) b);
// Console.WriteLine((int)(factN / Modular.Fac(i) / Modular.Fac((int) N -
// i))); 0と0でない数字の並びを考える
ans = ans + b * (factN / Modular.Fac(i) / Modular.Fac((int)N - i));
// Console.WriteLine((int)ans);
}
Console.WriteLine((int)ans);
}
}
class Modular {
public static int M = 1000000007;
private long V;
public Modular(long v) { V = v; }
public static implicit operator Modular(long a) {
var m = a % M;
return new Modular(m < 0 ? m + M : m);
}
public static Modular operator +(Modular a, Modular b) { return a.V + b.V; }
public static Modular operator -(Modular a, Modular b) { return a.V - b.V; }
public static Modular operator *(Modular a, Modular b) { return a.V * b.V; }
public static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b) {
return a * Pow(b, M - 2);
}
private static readonly List<int> Facts = new List<int> { 1 };
public static Modular Fac(int n) {
for (int i = Facts.Count; i <= n; ++i) {
Facts.Add((int)(Math.BigMul(Facts.Last(), i) % M));
}
return Facts[n];
}
public static Modular Ncr(int n, int r) {
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
return Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a) { return (int)a.V; }
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 1,297
| 14
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
public static class P {
public static void Main() {
var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
var n = nk[0];
var k = nk[1];
// k回の移動であり得ない組み合わせを引く
// k+1個以上部屋が空
//仕切りn-1とnを並び替え
var res = Factorial(n + n - 1) / Factorial(n) / Factorial(n - 1);
for (int i = n - 1; i > k; i--) {
var room = (n - i);
var perm = Factorial(n + room - 1) / Factorial(n) / Factorial(room - 1);
var perm2 = Factorial(n) / Factorial(room) / Factorial(n - room);
res -= perm + perm2;
}
Console.WriteLine(res);
}
static List<ModInt> factorialMemo = new List<ModInt>() { 1 };
static ModInt Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static ModInt Power(ModInt n, long m) {
ModInt pow = n;
ModInt res = 1;
while (m > 0) {
if ((m & 1) == 1)
res *= pow;
pow *= pow;
m >>= 1;
}
return res;
}
}
struct ModInt {
public const int Mod = 1000000007;
const long POSITIVIZER = ((long)Mod) << 31;
long Data;
public ModInt(long data) {
if ((Data = data % Mod) < 0)
Data += Mod;
}
public static implicit operator long(ModInt modInt) => modInt.Data;
public static implicit operator ModInt(long val) => new ModInt(val);
public static ModInt operator +(ModInt a, int b) => new ModInt() {
Data = (a.Data + b + POSITIVIZER) % Mod
};
public static ModInt operator +(ModInt a, long b) => new ModInt(a.Data + b);
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= Mod ? res - Mod : res };
}
public static ModInt operator -(ModInt a, int b) => new ModInt() {
Data = (a.Data - b + POSITIVIZER) % Mod
};
public static ModInt operator -(ModInt a, long b) => new ModInt(a.Data - b);
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + Mod : res };
}
public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b);
public static ModInt operator *(ModInt a, long b) => a * new ModInt(b);
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % Mod
};
public static ModInt operator /(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * GetInverse(b) % Mod
};
public static bool operator ==(ModInt a, ModInt b) => a.Data == b.Data;
public static bool operator !=(ModInt a, ModInt b) => a.Data != b.Data;
public override string ToString() => Data.ToString();
public override bool Equals(object obj) => (ModInt)obj == this;
public override int GetHashCode() => (int)Data;
static long GetInverse(long a) {
long div, p = Mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + Mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + Mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
public static class P {
public static void Main() {
var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
var n = nk[0];
var k = nk[1];
// k回の移動であり得ない組み合わせを引く
// k+1個以上部屋が空
//仕切りn-1とnを並び替え
var res = Factorial(n + n - 1) / Factorial(n) / Factorial(n - 1);
//ありえない空の部屋数
for (int i = n - 1; i > k; i--) {
var room = (n - i);
var perm = Factorial((n - room) + room - 1) / Factorial(n - room) /
Factorial(room - 1);
var perm2 = Factorial(n) / Factorial(room) / Factorial(n - room);
res -= perm * perm2;
}
Console.WriteLine(res);
}
static List<ModInt> factorialMemo = new List<ModInt>() { 1 };
static ModInt Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static ModInt Power(ModInt n, long m) {
ModInt pow = n;
ModInt res = 1;
while (m > 0) {
if ((m & 1) == 1)
res *= pow;
pow *= pow;
m >>= 1;
}
return res;
}
}
struct ModInt {
public const int Mod = 1000000007;
const long POSITIVIZER = ((long)Mod) << 31;
long Data;
public ModInt(long data) {
if ((Data = data % Mod) < 0)
Data += Mod;
}
public static implicit operator long(ModInt modInt) => modInt.Data;
public static implicit operator ModInt(long val) => new ModInt(val);
public static ModInt operator +(ModInt a, int b) => new ModInt() {
Data = (a.Data + b + POSITIVIZER) % Mod
};
public static ModInt operator +(ModInt a, long b) => new ModInt(a.Data + b);
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= Mod ? res - Mod : res };
}
public static ModInt operator -(ModInt a, int b) => new ModInt() {
Data = (a.Data - b + POSITIVIZER) % Mod
};
public static ModInt operator -(ModInt a, long b) => new ModInt(a.Data - b);
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + Mod : res };
}
public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b);
public static ModInt operator *(ModInt a, long b) => a * new ModInt(b);
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % Mod
};
public static ModInt operator /(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * GetInverse(b) % Mod
};
public static bool operator ==(ModInt a, ModInt b) => a.Data == b.Data;
public static bool operator !=(ModInt a, ModInt b) => a.Data != b.Data;
public override string ToString() => Data.ToString();
public override bool Equals(object obj) => (ModInt)obj == this;
public override int GetHashCode() => (int)Data;
static long GetInverse(long a) {
long div, p = Mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + Mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + Mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
|
[["+", 0, 28, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 28, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48]]
| 8
| 939
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using ll=System.Int64;
using static Contest_F.Lib_IO;
using static Contest_F.Lib_Minifunc;
public static class Contest_F
{
public static void Main() {
checked{
ll k,q;
Lib_IO.rm(out k, out q);
ll[] d;
ra(out d);
P<ll,ll,ll>[] nxm;
rl(q,out nxm);
List<ll> ans = new List<ll>();
foreach (var qq in nxm)
{
ll lp = 0;
ll md = 0;
foreach(var e in d){
ll v = e%qq.C;
if(v==0){
lp++;
}else{
md += v;
if(qq.C<=md){
md-=qq.C;
lp++;
}
}
}
ll w = qq.A/k;
ll a = qq.B%qq.C;
ll cnt = (k-lp)*w-(a+md*w)/qq.C;
a = (a+md*w)%qq.C;
for (ll j = w*k; j < qq.A-1; j++)
{
ll b = (a + d[j%k])%qq.C;
if(a<b) cnt++;
a = b;
}
ans.Add(cnt);
}
Lib_IO.wl(ans);
}
}
#region BaseModule
public static class Lib_Minifunc{
[MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
[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 の方が小さければ交換
[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 を更新
[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 を更新
[MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n);
[MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h));
[MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min();
[MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max();
[MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); }
[MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ
[MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b);
[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);
[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);
[MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } }
public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; }
public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; }
public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; }
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
}
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[] {' '};
[MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U));
[MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T));
[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 = z.Select(cv<T>).ToArray();
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);
}
[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));
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) {
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 System.Runtime.CompilerServices;
using System.Diagnostics;
using ll=System.Int64;
using static Contest_F.Lib_IO;
using static Contest_F.Lib_Minifunc;
public static class Contest_F
{
public static void Main() {
checked{
ll k,q;
Lib_IO.rm(out k, out q);
ll[] d;
ra(out d);
P<ll,ll,ll>[] nxm;
rl(q,out nxm);
List<ll> ans = new List<ll>();
foreach (var qq in nxm)
{
ll lp = 0;
ll md = 0;
foreach(var e in d){
ll v = e%qq.C;
if(v==0){
lp++;
}else{
md += v;
if(qq.C<=md){
md-=qq.C;
lp++;
}
}
}
ll w = (qq.A-1)/k;
ll a = qq.B%qq.C+md*w;
ll cnt = (k-lp)*w-a/qq.C;
a = a%qq.C;
for (ll j = w*k; j < qq.A-1; j++)
{
ll b = (a + d[j%k])%qq.C;
if(a<b) cnt++;
a = b;
}
ans.Add(cnt);
}
Lib_IO.wl(ans);
}
}
#region BaseModule
public static class Lib_Minifunc{
[MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
[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 の方が小さければ交換
[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 を更新
[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 を更新
[MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n);
[MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h));
[MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min();
[MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max();
[MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); }
[MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ
[MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b);
[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);
[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);
[MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } }
public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; }
public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; }
public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; }
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
}
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[] {' '};
[MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U));
[MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T));
[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 = z.Select(cv<T>).ToArray();
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);
}
[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));
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) {
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, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 48], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 22], ["-", 0, 212, 0, 16, 12, 16, 31, 23, 0, 24], ["-", 0, 16, 12, 16, 31, 23, 0, 16, 17, 72], ["-", 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, 22], ["-", 0, 212, 0, 16, 12, 16, 31, 23, 0, 25], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25]]
| 8
| 3,132
| 20
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using E = System.Linq.Enumerable;
internal partial class Solver {
public void Run() {
var k = ni();
var q = ni();
var d = ni(k);
for (int _ = 0; _ < q; _++) {
var n = ni();
var x = ni();
var m = ni();
cout.WriteLine(Solve(d, n, x, m));
}
}
private long Solve(int[] d, int n, int x, int m) {
var k = d.Length;
long sum = 0;
foreach (var p in d) {
sum += p % m == 0 ? m : p % m;
}
long after = x % m + sum * ((n - 1) / k);
for (int i = 0; i < (n - 1) % k; i++) {
after += d[i] % m;
}
return n - 1 - after / m;
}
}
// PREWRITEN CODE BEGINS FROM HERE
internal partial class Solver : Scanner {
public static void Main(string[] args) {
#if LOCAL
byte[] inputBuffer = new byte[1000000];
var inputStream = Console.OpenStandardInput(inputBuffer.Length);
using (var reader = new StreamReader(inputStream, Console.InputEncoding,
false, inputBuffer.Length)) {
Console.SetIn(reader);
new Solver(Console.In, Console.Out).Run();
}
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver(Console.In, Console.Out).Run();
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return checked(NextInt()); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
internal static class LinqPadExtension {
[Conditional("DEBUG")]
public static void Dump<T>(this T obj) {
#if DEBUG
LINQPad.Extensions.Dump(obj);
#endif
}
}
public class Scanner {
private readonly TextReader Reader;
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
private readonly char[] buffer = new char[2 * 1024];
private int cursor = 0, length = 0;
private string Token;
private readonly StringBuilder sb = new StringBuilder(1024);
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return checked((int)NextLong()); }
public long NextLong() {
var s = Next();
long r = 0;
int i = 0;
bool negative = false;
if (s[i] == '-') {
negative = true;
i++;
}
for (; i < s.Length; i++) {
r = r * 10 + (s[i] - '0');
#if DEBUG
if (!char.IsDigit(s[i]))
throw new FormatException();
#endif
}
return negative ? -r : r;
}
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (Token == null) {
if (!StockToken()) {
throw new InvalidOperationException();
}
}
var token = Token;
Token = null;
return token;
}
public bool HasNext() {
if (Token != null) {
return true;
}
return StockToken();
}
private bool StockToken() {
while (true) {
sb.Clear();
while (true) {
if (cursor >= length) {
cursor = 0;
if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
break;
}
}
var c = buffer[cursor++];
if (33 <= c && c <= 126) {
sb.Append(c);
} else {
if (sb.Length > 0)
break;
}
}
if (sb.Length > 0) {
Token = sb.ToString();
return true;
}
return false;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using E = System.Linq.Enumerable;
internal partial class Solver {
public void Run() {
var k = ni();
var q = ni();
var d = ni(k);
for (int _ = 0; _ < q; _++) {
var n = ni();
var x = ni();
var m = ni();
cout.WriteLine(Solve(d, n, x, m));
}
}
private long Solve(int[] d, int n, int x, int m) {
var k = d.Length;
var a = d.Select(p => (long)(p % m == 0 ? m : p % m)).ToArray();
long sum = a.Sum();
long after = x % m + sum * ((n - 1) / k);
for (int i = 0; i < (n - 1) % k; i++) {
after += a[i];
}
return n - 1 - after / m;
}
}
// PREWRITEN CODE BEGINS FROM HERE
internal partial class Solver : Scanner {
public static void Main(string[] args) {
#if LOCAL
byte[] inputBuffer = new byte[1000000];
var inputStream = Console.OpenStandardInput(inputBuffer.Length);
using (var reader = new StreamReader(inputStream, Console.InputEncoding,
false, inputBuffer.Length)) {
Console.SetIn(reader);
new Solver(Console.In, Console.Out).Run();
}
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver(Console.In, Console.Out).Run();
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return checked(NextInt()); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
internal static class LinqPadExtension {
[Conditional("DEBUG")]
public static void Dump<T>(this T obj) {
#if DEBUG
LINQPad.Extensions.Dump(obj);
#endif
}
}
public class Scanner {
private readonly TextReader Reader;
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
private readonly char[] buffer = new char[2 * 1024];
private int cursor = 0, length = 0;
private string Token;
private readonly StringBuilder sb = new StringBuilder(1024);
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return checked((int)NextLong()); }
public long NextLong() {
var s = Next();
long r = 0;
int i = 0;
bool negative = false;
if (s[i] == '-') {
negative = true;
i++;
}
for (; i < s.Length; i++) {
r = r * 10 + (s[i] - '0');
#if DEBUG
if (!char.IsDigit(s[i]))
throw new FormatException();
#endif
}
return negative ? -r : r;
}
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (Token == null) {
if (!StockToken()) {
throw new InvalidOperationException();
}
}
var token = Token;
Token = null;
return token;
}
public bool HasNext() {
if (Token != null) {
return true;
}
return StockToken();
}
private bool StockToken() {
while (true) {
sb.Clear();
while (true) {
if (cursor >= length) {
cursor = 0;
if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
break;
}
}
var c = buffer[cursor++];
if (33 <= c && c <= 126) {
sb.Append(c);
} else {
if (sb.Length > 0)
break;
}
}
if (sb.Length > 0) {
Token = sb.ToString();
return true;
}
return false;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 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, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 210, 39, 216, 0, 217], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 39, 199], ["-", 0, 195, 8, 196, 0, 210, 8, 196, 0, 45], ["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 28, 0, 218, 8, 74, 51, 23, 0, 24], ["+", 0, 28, 0, 218, 8, 74, 51, 23, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 1,264
| 40
|
using CompLib.Util;
using System;
using System.Text;
public class Program {
long K, Q;
long[] D;
long[] N, X, M;
public void Solve() {
var sc = new Scanner();
K = sc.NextInt();
Q = sc.NextInt();
D = sc.LongArray();
N = new long[Q];
X = new long[Q];
M = new long[Q];
for (int i = 0; i < Q; i++) {
N[i] = sc.NextInt();
X[i] = sc.NextInt();
M[i] = sc.NextInt();
}
var sb = new StringBuilder();
for (int i = 0; i < Q; i++) {
var dm = new long[K];
for (int j = 0; j < K; j++) {
dm[j] = D[j] % M[i] == 0 ? M[i] : D[j] % M[i];
}
// a[j] == a[j + 1]となる場合
// 0をmとすることで下のに統合できる
// a[j] >= a[j+1]となる場合
// a[j]をmで割った商 + 1 == a[j+1]をmで割った商
long f = X[i];
long l = X[i];
for (int j = 0; j < K; j++) {
if (j < ((N[i] - 1) % K)) {
l += dm[j] * (N[i] / K + 1);
} else {
l += dm[j] * (N[i] / K);
}
}
long b = (l / M[i]) - (f / M[i]);
sb.AppendLine((N[i] - 1 - b).ToString());
}
Console.Write(sb.ToString());
}
public static void Main(string[] args) => new Program().Solve();
}
namespace CompLib.Util {
using System;
using System.Linq;
class Scanner {
private int _index;
private string[] _line;
const char separator = ' ';
public Scanner() {
_index = 0;
_line = new string[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 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();
}
}
|
using CompLib.Util;
using System;
using System.Text;
public class Program {
long K, Q;
long[] D;
long[] N, X, M;
public void Solve() {
var sc = new Scanner();
K = sc.NextInt();
Q = sc.NextInt();
D = sc.LongArray();
N = new long[Q];
X = new long[Q];
M = new long[Q];
for (int i = 0; i < Q; i++) {
N[i] = sc.NextInt();
X[i] = sc.NextInt();
M[i] = sc.NextInt();
}
var sb = new StringBuilder();
for (int i = 0; i < Q; i++) {
var dm = new long[K];
for (int j = 0; j < K; j++) {
dm[j] = D[j] % M[i] == 0 ? M[i] : D[j] % M[i];
}
// a[j] == a[j + 1]となる場合
// 0をmとすることで下のに統合できる
// a[j] >= a[j+1]となる場合
// a[j]をmで割った商 + 1 == a[j+1]をmで割った商
long f = X[i];
long l = X[i];
for (int j = 0; j < K; j++) {
if (j < ((N[i] - 1) % K)) {
l += dm[j] * ((N[i] - 1) / K + 1);
} else {
l += dm[j] * ((N[i] - 1) / K);
}
}
long b = (l / M[i]) - (f / M[i]);
sb.AppendLine((N[i] - 1 - b).ToString());
}
Console.Write(sb.ToString());
}
public static void Main(string[] args) => new Program().Solve();
}
namespace CompLib.Util {
using System;
using System.Linq;
class Scanner {
private int _index;
private string[] _line;
const char separator = ' ';
public Scanner() {
_index = 0;
_line = new string[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 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();
}
}
|
[["+", 12, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 12, 23, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 12, 16, 12, 23, 0, 16, 31, 23, 0, 25]]
| 8
| 663
| 8
|
/*********************************************
* 20.05.11 AtCoder Beginner Contest 157. A, B, C
*
*
*********************************************/
/*********************************************
::test input::
*********************************************/
namespace TempName {
using System;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using static System.Console;
using static IOmacro.CSharpInput;
using static IOmacro.CppInput;
using static IOmacro.CConst;
public class CRun {
public readonly char problem_num = 'A';
public void solve_1() {
// A - Poor
// 3개의 수 중에서 2개가 같고, 나머지가 다른 경우
int a = cin, b = cin, c = cin;
string ans = "No";
if (a == b)
if (a != c)
ans = "Yes";
if (a == c)
if (a != b)
ans = "Yes";
WriteLine(ans);
}
public void solve_2() {}
public void solve_3() {}
public void solve_4() {}
public void solve_5() {}
public void solve_6() {}
}
class Program {
static void Main() {
var run = new CRun();
if (run.problem_num == 'A')
run.solve_1();
if (run.problem_num == 'B')
run.solve_2();
if (run.problem_num == 'C')
run.solve_3();
if (run.problem_num == 'D')
run.solve_4();
if (run.problem_num == 'E')
run.solve_5();
if (run.problem_num == 'F')
run.solve_6();
}
}
}
namespace IOmacro {
// 20.05.10. 수정
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
public class CSharpInput {
public static StreamWriter _writer =
new StreamWriter(Console.OpenStandardOutput());
public const char separator = ' ';
public static string _string {
get { return Console.ReadLine(); }
}
public static string[] _stringa {
get { return (Console.ReadLine().Split(separator)); }
}
public static int _int {
get { return int.Parse(Console.ReadLine()); }
}
public static int[] _inta {
get {
return Console.ReadLine().Split(separator).Select(int.Parse).ToArray();
}
}
public static long _long {
get { return long.Parse(Console.ReadLine()); }
}
public static long[] _longa {
get {
return Console.ReadLine().Split(separator).Select(long.Parse).ToArray();
}
}
public static double _double {
get { return double.Parse(Console.ReadLine()); }
}
public static double[] _doublea {
get {
return Console.ReadLine().Split(separator).Select(double.Parse).ToArray();
}
}
}
public class CConst {
public static readonly int MINI = int.MaxValue;
public static readonly long INF = Int64.MaxValue;
}
public class CppInput {
public static CppInput cin => new CppInput();
public const char separator = ' ';
private static readonly Queue<string> _input = new Queue<string>();
private CppInput() {}
public static implicit operator string(CppInput _) {
if (_input.Count == 0)
Console.ReadLine().Split(separator).foreachExtension(
x => _input.Enqueue(x));
return _input.Dequeue();
}
public static implicit operator int(CppInput _) {
if (_input.Count == 0)
Console.ReadLine().Split(separator).foreachExtension(
x => _input.Enqueue(x));
return int.Parse(_input.Dequeue());
}
public static implicit operator long(CppInput _) {
if (_input.Count == 0)
Console.ReadLine().Split(separator).foreachExtension(
x => _input.Enqueue(x));
return long.Parse(_input.Dequeue());
}
public static implicit operator double(CppInput _) {
if (_input.Count == 0)
Console.ReadLine().Split(separator).foreachExtension(
x => _input.Enqueue(x));
return double.Parse(_input.Dequeue());
}
}
public static class EnumerableExtension {
public delegate void Function<in T>(T val);
public static void foreachExtension<T>(this IEnumerable<T> enumerable,
Function<T> function) {
foreach (var x in enumerable)
function(x);
}
}
}
|
/*********************************************
* 20.05.11 AtCoder Beginner Contest 157. A, B, C
*
*
*********************************************/
/*********************************************
::test input::
*********************************************/
namespace TempName {
using System;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using static System.Console;
using static IOmacro.CSharpInput;
using static IOmacro.CppInput;
using static IOmacro.CConst;
public class CRun {
public readonly char problem_num = 'A';
public void solve_1() {
// A - Poor
// 3개의 수 중에서 2개가 같고, 나머지가 다른 경우
int a = cin, b = cin, c = cin;
string ans = "No";
if (a == b)
if (a != c)
ans = "Yes";
if (a == c)
if (a != b)
ans = "Yes";
if (b == c)
if (a != b)
ans = "Yes";
WriteLine(ans);
}
public void solve_2() {}
public void solve_3() {}
public void solve_4() {}
public void solve_5() {}
public void solve_6() {}
}
class Program {
static void Main() {
var run = new CRun();
if (run.problem_num == 'A')
run.solve_1();
if (run.problem_num == 'B')
run.solve_2();
if (run.problem_num == 'C')
run.solve_3();
if (run.problem_num == 'D')
run.solve_4();
if (run.problem_num == 'E')
run.solve_5();
if (run.problem_num == 'F')
run.solve_6();
}
}
}
namespace IOmacro {
// 20.05.10. 수정
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
public class CSharpInput {
public static StreamWriter _writer =
new StreamWriter(Console.OpenStandardOutput());
public const char separator = ' ';
public static string _string {
get { return Console.ReadLine(); }
}
public static string[] _stringa {
get { return (Console.ReadLine().Split(separator)); }
}
public static int _int {
get { return int.Parse(Console.ReadLine()); }
}
public static int[] _inta {
get {
return Console.ReadLine().Split(separator).Select(int.Parse).ToArray();
}
}
public static long _long {
get { return long.Parse(Console.ReadLine()); }
}
public static long[] _longa {
get {
return Console.ReadLine().Split(separator).Select(long.Parse).ToArray();
}
}
public static double _double {
get { return double.Parse(Console.ReadLine()); }
}
public static double[] _doublea {
get {
return Console.ReadLine().Split(separator).Select(double.Parse).ToArray();
}
}
}
public class CConst {
public static readonly int MINI = int.MaxValue;
public static readonly long INF = Int64.MaxValue;
}
public class CppInput {
public static CppInput cin => new CppInput();
public const char separator = ' ';
private static readonly Queue<string> _input = new Queue<string>();
private CppInput() {}
public static implicit operator string(CppInput _) {
if (_input.Count == 0)
Console.ReadLine().Split(separator).foreachExtension(
x => _input.Enqueue(x));
return _input.Dequeue();
}
public static implicit operator int(CppInput _) {
if (_input.Count == 0)
Console.ReadLine().Split(separator).foreachExtension(
x => _input.Enqueue(x));
return int.Parse(_input.Dequeue());
}
public static implicit operator long(CppInput _) {
if (_input.Count == 0)
Console.ReadLine().Split(separator).foreachExtension(
x => _input.Enqueue(x));
return long.Parse(_input.Dequeue());
}
public static implicit operator double(CppInput _) {
if (_input.Count == 0)
Console.ReadLine().Split(separator).foreachExtension(
x => _input.Enqueue(x));
return double.Parse(_input.Dequeue());
}
}
public static class EnumerableExtension {
public delegate void Function<in T>(T val);
public static void foreachExtension<T>(this IEnumerable<T> enumerable,
Function<T> function) {
foreach (var x in enumerable)
function(x);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 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, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 64, 57, 0, 24], ["+", 8, 196, 0, 57, 64, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 64, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 64, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 57, 0, 25], ["+", 0, 57, 64, 57, 64, 1, 0, 11, 31, 22], ["+", 64, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 57, 64, 1, 0, 11, 12, 5, 0, 62], ["+", 64, 57, 64, 1, 0, 11, 12, 5, 0, 222], ["+", 8, 196, 0, 57, 64, 57, 64, 1, 0, 35]]
| 8
| 881
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 演習4_1_2 {
class Program {
static void Main(string[] args) {
var x = Console.ReadLine().Split(' ');
if ((x[0] == x[1] && x[0] == x[2]) || (x[0] != x[1] && x[0] != x[2]))
Console.WriteLine("No");
else
Console.WriteLine("Yes");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 演習4_1_2 {
class Program {
static void Main(string[] args) {
var x = Console.ReadLine().Split(' ');
if ((x[0] == x[1] && x[0] == x[2]) ||
(x[0] != x[1] && x[0] != x[2] && x[1] != x[2]))
Console.WriteLine("No");
else
Console.WriteLine("Yes");
}
}
}
|
[["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 12, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 79], ["+", 12, 23, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 128
| 10
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
static void Main(string[] args) {
var r = Console.ReadLine().Split(' ');
if (r.GroupBy(x => x).Count() == 2) {
Console.WriteLine("Yew");
} else {
Console.WriteLine("No");
}
}
}
}
public static class Extentions {
public static int ToInt(this object obj) { return int.Parse(obj.ToString()); }
public static decimal ToDecimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double ToDouble(this object obj) {
return double.Parse(obj.ToString());
}
}
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
static void Main(string[] args) {
var r = Console.ReadLine().Split(' ');
if (r.GroupBy(x => x).Count() == 2) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
Console.ReadLine();
}
}
}
public static class Extentions {
public static int ToInt(this object obj) { return int.Parse(obj.ToString()); }
public static decimal ToDecimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double ToDouble(this object obj) {
return double.Parse(obj.ToString());
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 183
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Console;
namespace CPLib {
class Atria {
static void Main(string[] args) {
int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
Array.Sort(s);
if (s[0] == s[1] && s[0] != s[2]) {
WriteLine("Yes");
} else
WriteLine("No");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Console;
namespace CPLib {
class Atria {
static void Main(string[] args) {
int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
Array.Sort(s);
if ((s[0] == s[1] && s[0] != s[2]) || (s[2] == s[1] && s[0] != s[1])) {
WriteLine("Yes");
} else
WriteLine("No");
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 60], ["+", 12, 23, 0, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 12, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 79], ["+", 12, 23, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
| 8
| 129
| 24
|
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
hoge();
System.Console.ReadLine();
}
public static void hoge() {
var line = System.Console.ReadLine()
.Split(' ')
.Select(x => long.Parse(x))
.ToArray();
var same = line[0] == line[1] || line[2] == line[1];
var other = line[0] != line[1] || line[2] != line[1];
if (same || other) {
System.Console.WriteLine("No");
} else {
System.Console.WriteLine("Yes");
}
}
}
|
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
hoge();
System.Console.ReadLine();
}
public static void hoge() {
var line = System.Console.ReadLine()
.Split(' ')
.Select(x => long.Parse(x))
.ToArray();
var same = line[0] == line[1] && line[2] == line[1];
var other = line[0] != line[1] && line[2] != line[1] && line[0] != line[2];
if (same || other) {
System.Console.WriteLine("No");
} else {
System.Console.WriteLine("Yes");
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 106], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 98], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 98], ["+", 31, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 212, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 79], ["+", 0, 212, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 158
| 14
|
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var a = int.Parse(line[0]);
var b = int.Parse(line[1]);
var c = int.Parse(line[2]);
Console.WriteLine((a == b && b != c) | (b == c && a != b) ? "Yes" : "No");
}
}
|
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var a = int.Parse(line[0]);
var b = int.Parse(line[1]);
var c = int.Parse(line[2]);
Console.WriteLine(
(a == b && b != c) | (b == c && a != b) | (a == c && a != b) ? "Yes"
: "No");
}
}
|
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 139], ["+", 0, 28, 0, 41, 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, 41, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 79], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 22], ["+", 0, 28, 0, 41, 15, 16, 12, 23, 0, 25]]
| 8
| 110
| 10
|
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
int a;
int b;
int c;
string str = Console.ReadLine();
string[] str1 = str.Split(' ');
a = int.Parse(str1[0]);
b = int.Parse(str1[1]);
c = int.Parse(str1[2]);
if (a == b) {
if (b != c && a != c) {
Console.WriteLine("Yes");
}
} else if (b == c) {
if (a != c && a != b) {
Console.WriteLine("Yes");
}
} else if (a == c) {
if (b != c && b != a) {
Console.WriteLine("Yes");
}
} else if (a == b && b == c) {
Console.WriteLine("No");
} else {
Console.Write("No");
}
Console.ReadKey();
}
}
}
|
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
int a;
int b;
int c;
string str = Console.ReadLine();
string[] str1 = str.Split(' ');
a = int.Parse(str1[0]);
b = int.Parse(str1[1]);
c = int.Parse(str1[2]);
if (a == b) {
if (b != c && a != c) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else if (b == c) {
if (a != c && a != b) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else if (a == c) {
if (b != c && b != a) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else {
Console.WriteLine("No");
}
Console.ReadKey();
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 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, 57, 75, 57, 64, 196, 0, 46], ["-", 0, 57, 75, 57, 75, 57, 75, 57, 0, 121], ["-", 0, 57, 75, 57, 75, 57, 75, 57, 0, 24], ["-", 75, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["-", 75, 57, 75, 57, 15, 16, 31, 16, 17, 60], ["-", 75, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["-", 75, 57, 75, 57, 75, 57, 15, 16, 17, 98], ["-", 75, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["-", 75, 57, 75, 57, 15, 16, 12, 16, 17, 60], ["-", 75, 57, 75, 57, 15, 16, 12, 16, 12, 22], ["-", 0, 57, 75, 57, 75, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 57, 75, 57, 64, 196, 0, 46], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22]]
| 8
| 219
| 38
|
using System;
using System.Collections.Generic;
using System.Linq;
class sample {
static void Main() {
string[] input = Console.ReadLine().Split(' ');
List<int> num = new List<int>();
for (int i = 0; i < input.Length; i++) {
num.Add(Convert.ToInt32(input[i]));
}
num = num.Distinct().ToList();
if (num.Count == 2) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
Console.WriteLine(num.Count);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class sample {
static void Main() {
string[] input = Console.ReadLine().Split(' ');
List<int> num = new List<int>();
for (int i = 0; i < input.Length; i++) {
num.Add(Convert.ToInt32(input[i]));
}
num = num.Distinct().ToList();
if (num.Count == 2) {
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, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 143
| 9
|
using System;
namespace A {
class Program {
static void Main(string[] args) {
Console.WriteLine(solver() ? "Yes" : "No");
}
static bool solver() {
var ABC = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
if (ABC[0] == ABC[1]) {
return ABC[0] != ABC[2];
} else if (ABC[0] == ABC[2]) {
return true;
} else {
return false;
}
}
}
}
|
using System;
namespace A {
class Program {
static void Main(string[] args) {
Console.WriteLine(solver() ? "Yes" : "No");
}
static bool solver() {
var ABC = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
if (ABC[0] == ABC[1]) {
return ABC[0] != ABC[2];
} else if (ABC[0] == ABC[2]) {
return true;
} else {
return ABC[1] == ABC[2];
}
}
}
}
|
[["-", 75, 57, 75, 196, 0, 37, 0, 211, 0, 147], ["+", 75, 196, 0, 37, 0, 16, 31, 204, 205, 22], ["+", 0, 37, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 37, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 75, 57, 75, 196, 0, 37, 0, 16, 17, 60], ["+", 75, 196, 0, 37, 0, 16, 12, 204, 205, 22], ["+", 0, 37, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 37, 0, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 120
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
// https://atcoder.jp/contests/abc141/tasks/abc141_a
public class QuestionA {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数配列の入力
var abc =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
var flag = false;
if (abc[0] == abc[1] && abc[1] != abc[2]) {
flag = true;
} else if (abc[0] == abc[2] && abc[1] != abc[2]) {
flag = true;
}
Console.WriteLine(flag ? "Yes" : "No");
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
// https://atcoder.jp/contests/abc141/tasks/abc141_a
public class QuestionA {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数配列の入力
var abc =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
var flag = false;
if (abc[0] == abc[1] && abc[1] != abc[2]) {
flag = true;
} else if (abc[0] == abc[2] && abc[1] != abc[2]) {
flag = true;
} else if (abc[1] == abc[2] && abc[0] != abc[1]) {
flag = true;
}
Console.WriteLine(flag ? "Yes" : "No");
Console.Out.Flush();
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 17, 60], ["+", 75, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 98], ["+", 75, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 17, 79], ["+", 75, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 57, 75, 57, 64, 196, 0, 45], ["+", 75, 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], ["+", 75, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 57, 75, 57, 64, 196, 0, 46]]
| 8
| 198
| 29
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.