buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder.ABC {
class QuestionB {
public static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var d = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
var max = d.Max();
var dict = new int[n];
for (int i = 0; i < n; i++) {
dict[d[i]]++;
}
var ans = 0L;
if (dict[0] == 1) {
ans = 1;
for (int i = 1; i <= max; i++) {
long temp = Pow(dict[i - 1], dict[i], 998244353);
ans *= temp;
ans %= 998244353;
}
}
Console.WriteLine(ans);
}
public static long Pow(long a, long b, long mod = 0L) {
var temp = a;
var i = 0;
var ans = 1L;
while (true) {
if (b >> i == 0) {
break;
}
var t = b >> i & 1;
if (t != 0) {
ans *= temp;
if (mod != 0) {
ans %= mod;
}
}
temp *= temp;
if (mod != 0) {
temp %= mod;
}
i++;
}
return ans;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder.ABC {
class QuestionB {
public static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var d = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
var max = d.Max();
var dict = new int[n];
for (int i = 0; i < n; i++) {
dict[d[i]]++;
}
var ans = 0L;
if (dict[0] == 1) {
ans = 1;
for (int i = 1; i <= max; i++) {
long temp = Pow(dict[i - 1], dict[i], 998244353);
ans *= temp;
ans %= 998244353;
}
}
if (d[0] != 0) {
ans = 0;
}
Console.WriteLine(ans);
}
public static long Pow(long a, long b, long mod = 0L) {
var temp = a;
var i = 0;
var ans = 1L;
while (true) {
if (b >> i == 0) {
break;
}
var t = b >> i & 1;
if (t != 0) {
ans *= temp;
if (mod != 0) {
ans %= mod;
}
}
temp *= temp;
if (mod != 0) {
temp %= mod;
}
i++;
}
return ans;
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 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, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 320
| 15
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class MainClass {
static void Main() {
int N = int.Parse(ReadLine());
var D = ReadLine().Split().Select(int.Parse).ToArray();
var A = new int[N];
int max = 0;
for (int i = 0; i < N; i++) {
A[D[i]]++;
max = Max(max, D[i]);
}
Modular ans = 1;
for (int i = 0; i < max; i++) {
ans *= Modular.Pow(A[i], A[i + 1]);
}
WriteLine((long)ans);
}
}
class Modular {
private const long M = 998244353;
private long value;
public Modular(long value) { this.value = value; }
public static implicit operator Modular(long a) {
var m = a % M;
return new Modular((m < 0) ? m + M : m);
}
public static Modular operator +(Modular a, Modular b) {
return a.value + b.value;
}
public static Modular operator -(Modular a, Modular b) {
return a.value - b.value;
}
public static Modular operator *(Modular a, Modular b) {
return a.value * b.value;
}
public static Modular Pow(Modular a, long n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular 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; }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class MainClass {
static void Main() {
int N = int.Parse(ReadLine());
var D = ReadLine().Split().Select(int.Parse).ToArray();
var A = new int[N];
int max = 0;
for (int i = 0; i < N; i++) {
A[D[i]]++;
max = Max(max, D[i]);
}
if (A[0] != 1 || D[0] != 0) {
WriteLine(0);
return;
}
Modular ans = 1;
for (int i = 0; i < max; i++) {
ans *= Modular.Pow(A[i], A[i + 1]);
}
WriteLine((long)ans);
}
}
class Modular {
private const long M = 998244353;
private long value;
public Modular(long value) { this.value = value; }
public static implicit operator Modular(long a) {
var m = a % M;
return new Modular((m < 0) ? m + M : m);
}
public static Modular operator +(Modular a, Modular b) {
return a.value + b.value;
}
public static Modular operator -(Modular a, Modular b) {
return a.value - b.value;
}
public static Modular operator *(Modular a, Modular b) {
return a.value * b.value;
}
public static Modular Pow(Modular a, long n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular 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; }
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 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], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 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, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 534
| 25
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
const long mod = 998244353;
// 入力
long n = long.Parse(Console.ReadLine());
long[] d = Console.ReadLine().Split().Select(long.Parse).ToArray();
var max = d.Max();
var array = new long[max + 1];
for (int i = 0; i < d.Length; i++) {
array[d[i]]++;
}
long ans = 1;
long count = 0;
long parent = 0;
if (array[0] != 1) {
ans = 0;
} else {
for (int i = 1; i < array.Length; i++) {
for (int j = 0; j < array[i]; j++) {
ans *= array[i - 1];
ans %= mod;
}
}
}
// 出力
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) {
const long mod = 998244353;
// 入力
long n = long.Parse(Console.ReadLine());
long[] d = Console.ReadLine().Split().Select(long.Parse).ToArray();
var max = d.Max();
var array = new long[max + 1];
for (int i = 0; i < d.Length; i++) {
array[d[i]]++;
}
long ans = 1;
long count = 0;
long parent = 0;
if (d[0] != 0 || array[0] != 1) {
ans = 0;
} else {
for (int i = 1; i < array.Length; i++) {
for (int j = 0; j < array[i]; j++) {
ans *= array[i - 1];
ans %= mod;
}
}
}
// 出力
Console.WriteLine(ans);
}
}
|
[["+", 0, 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], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106]]
| 8
| 225
| 7
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split();
int[] D = new int[N];
var r = 1L;
for (int i = 0; i < N; i++) {
D[i] = int.Parse(input[i]);
if (D[0] > 0) {
r = 0;
}
if (i != 0 && D[i] == 0) {
r = 0;
}
}
Array.Sort(D);
var c = D.GroupBy(x => x).ToDictionary(g => g.Key, g => g.Count());
var max = c.Keys.Max();
if (c.Count <= max) {
Console.WriteLine(0);
return;
}
Console.WriteLine(c[0]);
Console.WriteLine(max);
for (int i = 0; i < max; i++)
r = MMul(r, MPow(c[i], c[i + 1]));
Console.WriteLine(r);
}
const int M = 998244353;
static long MPow(long b, int i) {
for (var r = 1L;; b = b * b % M) {
if (i % 2 > 0)
r = r * b % M;
if ((i /= 2) < 1)
return r;
}
}
static long MMul(long x, long y) => x * y % M;
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split();
int[] D = new int[N];
var r = 1L;
for (int i = 0; i < N; i++) {
D[i] = int.Parse(input[i]);
if (D[0] > 0) {
r = 0;
}
if (i != 0 && D[i] == 0) {
r = 0;
}
}
Array.Sort(D);
var c = D.GroupBy(x => x).ToDictionary(g => g.Key, g => g.Count());
var max = c.Keys.Max();
if (c.Count <= max) {
Console.WriteLine(0);
return;
}
for (int i = 0; i < max; i++)
r = MMul(r, MPow(c[i], c[i + 1]));
Console.WriteLine(r);
}
const int M = 998244353;
static long MPow(long b, int i) {
for (var r = 1L;; b = b * b % M) {
if (i % 2 > 0)
r = r * b % M;
if ((i /= 2) < 1)
return r;
}
}
static long MMul(long x, long y) => x * y % M;
}
|
[["-", 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, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 341
| 17
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
const long MOD = 998244353;
static void Main(string[] args) {
var cin = new Scanner2();
int n = cin.Int();
int[] ds = new int[n];
for (int i = 0; i < n; i++) {
int d = cin.Int();
ds[d]++;
}
long ans = 1;
int count = 0;
for (int i = 0; i < n; i++) {
if (ds[i] == 0) {
Console.WriteLine(0);
return;
}
if (i == 0) {
if (ds[i] != 1) {
Console.WriteLine(0);
return;
}
} else {
long prev = ds[i - 1];
long cur = ds[i];
for (int j = 0; j < cur; j++) {
ans = (ans * prev) % MOD;
}
}
count += ds[i];
if (count >= n) {
break;
}
}
Console.WriteLine(ans);
}
}
public class Scanner2 {
private readonly char[] delimiter_ = new char[] { ' ' };
private readonly string filePath_;
private string[] buf_;
private int index_;
Func<string> reader_;
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.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
const long MOD = 998244353;
static void Main(string[] args) {
var cin = new Scanner2();
int n = cin.Int();
int[] ds = new int[n];
for (int i = 0; i < n; i++) {
int d = cin.Int();
if (i == 0 && d != 0) {
Console.WriteLine(0);
return;
}
ds[d]++;
}
long ans = 1;
int count = 0;
for (int i = 0; i < n; i++) {
if (ds[i] == 0) {
Console.WriteLine(0);
return;
}
if (i == 0) {
if (ds[i] != 1) {
Console.WriteLine(0);
return;
}
} else {
long prev = ds[i - 1];
long cur = ds[i];
for (int j = 0; j < cur; j++) {
ans = (ans * prev) % MOD;
}
}
count += ds[i];
if (count >= n) {
break;
}
}
Console.WriteLine(ans);
}
}
public class Scanner2 {
private readonly char[] delimiter_ = new char[] { ' ' };
private readonly string filePath_;
private string[] buf_;
private int index_;
Func<string> reader_;
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);
}
}
}
|
[["+", 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, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 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, 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, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 708
| 21
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;
namespace SolutionCS {
class Program {
class modMCalc {
private const int M = 998244353; // 素数(int範囲)
// 乗算結果 % Mを求める
static public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); }
// 冪乗(mod M)
static public int Pow(int a, int m) {
if (0 == m) {
return 1;
}
if (1 == m) {
return a;
}
int result = 1;
int param = a;
for (; m > 0; m >>= 1) {
if ((m & 0x01) == 1) {
result = Mul(result, param);
}
param = Mul(param, param);
}
return result;
}
// 除算(mod M)
static public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); }
}
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
int[] v = new int[N];
if (int.Parse(s[0]) != 0) {
Console.WriteLine("0");
return;
}
int maxInd = 0;
for (int i = 0; i < N; i++) {
int ind = int.Parse(s[i]);
v[ind]++;
maxInd = Math.Max(maxInd, ind);
}
int ans = 1;
for (int i = 0; i < maxInd; i++) {
int m = modMCalc.Pow(v[i], v[i + 1]);
ans = modMCalc.Mul(ans, m);
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;
namespace SolutionCS {
class Program {
class modMCalc {
private const int M = 998244353; // 素数(int範囲)
// 乗算結果 % Mを求める
static public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); }
// 冪乗(mod M)
static public int Pow(int a, int m) {
if (0 == m) {
return 1;
}
if (1 == m) {
return a;
}
int result = 1;
int param = a;
for (; m > 0; m >>= 1) {
if ((m & 0x01) == 1) {
result = Mul(result, param);
}
param = Mul(param, param);
}
return result;
}
// 除算(mod M)
static public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); }
}
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
int[] v = new int[N];
if (int.Parse(s[0]) != 0) {
Console.WriteLine("0");
return;
}
int maxInd = 0;
for (int i = 0; i < N; i++) {
int ind = int.Parse(s[i]);
v[ind]++;
maxInd = Math.Max(maxInd, ind);
}
if (v[0] != 1) {
Console.WriteLine("0");
return;
}
int ans = 1;
for (int i = 0; i < maxInd; i++) {
int m = modMCalc.Pow(v[i], v[i + 1]);
ans = modMCalc.Mul(ans, m);
}
Console.WriteLine(ans);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 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, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 388
| 22
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
static class Extensions {
public static int LowerBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c > 0)
l = m + 1;
else
r = m;
}
return l;
}
public static int UpperBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c >= 0)
l = m + 1;
else
r = m;
}
return r;
}
}
class Program {
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int[] ReadIntArray(int n) {
var a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ReadInt();
}
return a;
}
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long[] ReadLongArray(int n) {
var a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ReadLong();
}
return a;
}
static List<T> ReadObjects<T>(int n, Func<int[], T> creator) {
var l = new List<T>(n);
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
l.Add(creator(a));
}
return l;
}
static int[,] ReadMatrix(int n, int m) {
var r = new int[n, m];
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
for (int j = 0; j < m; j++) {
r[i, j] = a[j];
}
}
return r;
}
public static int[] ZAlgotithm(string s) {
var len = s.Length;
var a = new int[len];
a[0] = len;
var i = 1;
var j = 0;
while (i < len) {
while (i + j < len && s[j] == s[i + j])
j++;
a[i] = j;
if (j == 0) {
i++;
continue;
}
var k = 1;
while (i + k < len && k + a[k] < j) {
a[i + k] = a[k];
k++;
}
i += k;
j -= k;
}
return a;
}
public class MaxHeap<T> : IEnumerable<T> {
private List<T> _list;
private Comparer<T> _comp;
public int Count {
get { return _list.Count; }
}
public MaxHeap() : this(0) {}
public MaxHeap(int capacity, Comparison<T> comp = null) {
_list = new List<T>(capacity);
if (comp == null) {
_comp = Comparer<T>.Default;
} else {
_comp = Comparer<T>.Create(comp);
}
}
public void Push(T elem) { Upheap(elem); }
public T Pop() { return Downheap(); }
public T Peek() { return _list[0]; }
private void Swap(int i, int j) {
var a = _list[j];
_list[j] = _list[i];
_list[i] = a;
}
private void Upheap(T elem) {
_list.Add(elem);
var i = _list.Count - 1;
while (true) {
if (i == 0)
return;
var j = (i - 1) / 2;
var e = _list[i];
var p = _list[j];
var c = _comp.Compare(e, p);
if (c > 0) {
Swap(i, j);
i = j;
continue;
} else {
break;
}
}
}
private T Downheap() {
var result = _list[0];
var last = _list.Count - 1;
Swap(0, last);
_list.RemoveAt(last);
if (_list.Count == 0)
return result;
var i = 0;
while (true) {
if (i == _list.Count - 1)
return result;
var p = _list[i];
var j = i * 2 + 1;
if (j >= _list.Count)
return result;
if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) {
j++;
}
if (_comp.Compare(_list[i], _list[j]) < 0) {
Swap(i, j);
i = j;
} else {
return result;
}
}
}
public MaxHeap<T> Copy(Comparison<T> comp = null) {
var c = new MaxHeap<T>(0, comp);
c._list = _list.ToList();
return c;
}
public MaxHeap(List<T> list) {
_list = list;
_comp = Comparer<T>.Default;
}
public List<T> GetList() { return _list; }
public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
public class MinHeap<T> : IEnumerable<T> {
private List<T> _list;
private Comparer<T> _comp;
public int Count {
get { return _list.Count; }
}
public MinHeap() : this(0) {}
public MinHeap(int capacity, Comparison<T> comp = null) {
_list = new List<T>(capacity);
if (comp == null) {
_comp = Comparer<T>.Default;
} else {
_comp = Comparer<T>.Create(comp);
}
}
public void Push(T elem) { Upheap(elem); }
public T Pop() { return Downheap(); }
public T Peek() { return _list[0]; }
private void Swap(int i, int j) {
var a = _list[j];
_list[j] = _list[i];
_list[i] = a;
}
private void Upheap(T elem) {
_list.Add(elem);
var i = _list.Count - 1;
while (true) {
if (i == 0)
return;
var j = (i - 1) / 2;
var e = _list[i];
var p = _list[j];
var c = _comp.Compare(e, p);
if (c < 0) {
Swap(i, j);
i = j;
continue;
} else {
break;
}
}
}
private T Downheap() {
var result = _list[0];
var last = _list.Count - 1;
Swap(0, last);
_list.RemoveAt(last);
if (_list.Count == 0)
return result;
var i = 0;
while (true) {
if (i == _list.Count - 1)
return result;
var p = _list[i];
var j = i * 2 + 1;
if (j >= _list.Count)
return result;
if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) > 0) {
j++;
}
if (_comp.Compare(_list[i], _list[j]) > 0) {
Swap(i, j);
i = j;
} else {
return result;
}
}
}
public MinHeap<T> Copy(Comparison<T> comp = null) {
var c = new MinHeap<T>(0, comp);
c._list = _list.ToList();
return c;
}
public MinHeap(List<T> list) {
_list = list;
_comp = Comparer<T>.Default;
}
public List<T> GetList() { return _list; }
public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
class InputLine {
private string[] _inputs;
private int _index = 0;
InputLine(string input) {
_inputs = input.Split();
_index = 0;
}
public static InputLine Read() { return new InputLine(Console.ReadLine()); }
public int NextInt() { return int.Parse(_inputs[_index++]); }
public long NextLong() { return long.Parse(_inputs[_index++]); }
public double NextDouble() { return double.Parse(_inputs[_index++]); }
}
public static int GCD(int x, int y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
public static long GCD(long x, long y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
static long ModPower(long x, long y, long mod) {
var bytes = BitConverter.GetBytes(y);
var bits = new System.Collections.BitArray(bytes);
var max2 = 0;
for (int i = bits.Length - 1; i >= 0; i--) {
if (bits[i]) {
max2 = i;
break;
}
}
long result = 1;
for (int i = max2; i >= 0; i--) {
result = (result * result) % mod;
if (bits[i]) {
result = (result * x) % mod;
}
}
return result;
}
static long ModFact(long n, long mod) {
long result = 1;
for (int i = 1; i <= n; i++) {
result = result * i % mod;
}
return result;
}
static long ModAdd(long x, long y, long mod) {
return ((x % mod) + (y % mod)) % mod;
}
static long ModMul(long x, long y, long mod) {
return ((x % mod) * (y % mod)) % mod;
}
static long ModDiv(long x, long y, long mod) {
//フェルマーの小定理より、a^(-1) = a^(p-2)
return ModMul(x, ModPower(y, mod - 2, mod), mod);
}
static long ModComb(long n, long r, long mod) {
long numerator = 1;
for (int i = 0; i < r; i++) {
numerator = ModMul(numerator, n - i, mod);
}
long denominator = ModFact(r, mod);
return ModDiv(numerator, denominator, mod);
}
class Graph {
private int _size;
private List<int>[] _map;
public IEnumerable<int> this[int i] {
get {
if (_map[i] == null)
return Enumerable.Empty<int>();
return _map[i];
}
}
public Graph(int size) {
_size = size;
_map = new List<int>[size];
}
public void Add(int from, int to) {
if (_map[from] == null) {
_map[from] = new List<int>();
}
_map[from].Add(to);
}
}
static long p1097 = 1000000007;
static void Main(string[] args) {
//↓
var n = ReadInt();
var ds = ReadIntArray().ToList();
var p = 998244353;
// ds.Sort();
if (ds[0] > 0) {
Console.WriteLine(0);
return;
}
////頂点1と距離がdであるような頂点の数を持つ
// var a = new int[n + 1];
// a[0] = 1;
// long result = 1;
// for (int i = 1; i < n; i++)
//{
// var d = ds[i];
// result = ModMul(result, a[d - 1], p);
// a[d] += 1;
//}
var a = new int[n];
for (int i = 0; i < n; i++) {
a[ds[i]] += 1;
}
long result = 1;
for (int i = 1; i < n; i++) {
if (ds[i] == 0)
result = 0;
result = ModMul(result, a[ds[i] - 1], p);
}
Console.WriteLine(result);
//↑
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
static class Extensions {
public static int LowerBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c > 0)
l = m + 1;
else
r = m;
}
return l;
}
public static int UpperBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c >= 0)
l = m + 1;
else
r = m;
}
return r;
}
}
class Program {
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int[] ReadIntArray(int n) {
var a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ReadInt();
}
return a;
}
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long[] ReadLongArray(int n) {
var a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ReadLong();
}
return a;
}
static List<T> ReadObjects<T>(int n, Func<int[], T> creator) {
var l = new List<T>(n);
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
l.Add(creator(a));
}
return l;
}
static int[,] ReadMatrix(int n, int m) {
var r = new int[n, m];
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
for (int j = 0; j < m; j++) {
r[i, j] = a[j];
}
}
return r;
}
public static int[] ZAlgotithm(string s) {
var len = s.Length;
var a = new int[len];
a[0] = len;
var i = 1;
var j = 0;
while (i < len) {
while (i + j < len && s[j] == s[i + j])
j++;
a[i] = j;
if (j == 0) {
i++;
continue;
}
var k = 1;
while (i + k < len && k + a[k] < j) {
a[i + k] = a[k];
k++;
}
i += k;
j -= k;
}
return a;
}
public class MaxHeap<T> : IEnumerable<T> {
private List<T> _list;
private Comparer<T> _comp;
public int Count {
get { return _list.Count; }
}
public MaxHeap() : this(0) {}
public MaxHeap(int capacity, Comparison<T> comp = null) {
_list = new List<T>(capacity);
if (comp == null) {
_comp = Comparer<T>.Default;
} else {
_comp = Comparer<T>.Create(comp);
}
}
public void Push(T elem) { Upheap(elem); }
public T Pop() { return Downheap(); }
public T Peek() { return _list[0]; }
private void Swap(int i, int j) {
var a = _list[j];
_list[j] = _list[i];
_list[i] = a;
}
private void Upheap(T elem) {
_list.Add(elem);
var i = _list.Count - 1;
while (true) {
if (i == 0)
return;
var j = (i - 1) / 2;
var e = _list[i];
var p = _list[j];
var c = _comp.Compare(e, p);
if (c > 0) {
Swap(i, j);
i = j;
continue;
} else {
break;
}
}
}
private T Downheap() {
var result = _list[0];
var last = _list.Count - 1;
Swap(0, last);
_list.RemoveAt(last);
if (_list.Count == 0)
return result;
var i = 0;
while (true) {
if (i == _list.Count - 1)
return result;
var p = _list[i];
var j = i * 2 + 1;
if (j >= _list.Count)
return result;
if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) {
j++;
}
if (_comp.Compare(_list[i], _list[j]) < 0) {
Swap(i, j);
i = j;
} else {
return result;
}
}
}
public MaxHeap<T> Copy(Comparison<T> comp = null) {
var c = new MaxHeap<T>(0, comp);
c._list = _list.ToList();
return c;
}
public MaxHeap(List<T> list) {
_list = list;
_comp = Comparer<T>.Default;
}
public List<T> GetList() { return _list; }
public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
public class MinHeap<T> : IEnumerable<T> {
private List<T> _list;
private Comparer<T> _comp;
public int Count {
get { return _list.Count; }
}
public MinHeap() : this(0) {}
public MinHeap(int capacity, Comparison<T> comp = null) {
_list = new List<T>(capacity);
if (comp == null) {
_comp = Comparer<T>.Default;
} else {
_comp = Comparer<T>.Create(comp);
}
}
public void Push(T elem) { Upheap(elem); }
public T Pop() { return Downheap(); }
public T Peek() { return _list[0]; }
private void Swap(int i, int j) {
var a = _list[j];
_list[j] = _list[i];
_list[i] = a;
}
private void Upheap(T elem) {
_list.Add(elem);
var i = _list.Count - 1;
while (true) {
if (i == 0)
return;
var j = (i - 1) / 2;
var e = _list[i];
var p = _list[j];
var c = _comp.Compare(e, p);
if (c < 0) {
Swap(i, j);
i = j;
continue;
} else {
break;
}
}
}
private T Downheap() {
var result = _list[0];
var last = _list.Count - 1;
Swap(0, last);
_list.RemoveAt(last);
if (_list.Count == 0)
return result;
var i = 0;
while (true) {
if (i == _list.Count - 1)
return result;
var p = _list[i];
var j = i * 2 + 1;
if (j >= _list.Count)
return result;
if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) > 0) {
j++;
}
if (_comp.Compare(_list[i], _list[j]) > 0) {
Swap(i, j);
i = j;
} else {
return result;
}
}
}
public MinHeap<T> Copy(Comparison<T> comp = null) {
var c = new MinHeap<T>(0, comp);
c._list = _list.ToList();
return c;
}
public MinHeap(List<T> list) {
_list = list;
_comp = Comparer<T>.Default;
}
public List<T> GetList() { return _list; }
public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
class InputLine {
private string[] _inputs;
private int _index = 0;
InputLine(string input) {
_inputs = input.Split();
_index = 0;
}
public static InputLine Read() { return new InputLine(Console.ReadLine()); }
public int NextInt() { return int.Parse(_inputs[_index++]); }
public long NextLong() { return long.Parse(_inputs[_index++]); }
public double NextDouble() { return double.Parse(_inputs[_index++]); }
}
public static int GCD(int x, int y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
public static long GCD(long x, long y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
static long ModPower(long x, long y, long mod) {
var bytes = BitConverter.GetBytes(y);
var bits = new System.Collections.BitArray(bytes);
var max2 = 0;
for (int i = bits.Length - 1; i >= 0; i--) {
if (bits[i]) {
max2 = i;
break;
}
}
long result = 1;
for (int i = max2; i >= 0; i--) {
result = (result * result) % mod;
if (bits[i]) {
result = (result * x) % mod;
}
}
return result;
}
static long ModFact(long n, long mod) {
long result = 1;
for (int i = 1; i <= n; i++) {
result = result * i % mod;
}
return result;
}
static long ModAdd(long x, long y, long mod) {
return ((x % mod) + (y % mod)) % mod;
}
static long ModMul(long x, long y, long mod) {
return ((x % mod) * (y % mod)) % mod;
}
static long ModDiv(long x, long y, long mod) {
//フェルマーの小定理より、a^(-1) = a^(p-2)
return ModMul(x, ModPower(y, mod - 2, mod), mod);
}
static long ModComb(long n, long r, long mod) {
long numerator = 1;
for (int i = 0; i < r; i++) {
numerator = ModMul(numerator, n - i, mod);
}
long denominator = ModFact(r, mod);
return ModDiv(numerator, denominator, mod);
}
class Graph {
private int _size;
private List<int>[] _map;
public IEnumerable<int> this[int i] {
get {
if (_map[i] == null)
return Enumerable.Empty<int>();
return _map[i];
}
}
public Graph(int size) {
_size = size;
_map = new List<int>[size];
}
public void Add(int from, int to) {
if (_map[from] == null) {
_map[from] = new List<int>();
}
_map[from].Add(to);
}
}
static long p1097 = 1000000007;
static void Main(string[] args) {
//↓
var n = ReadInt();
var ds = ReadIntArray();
var p = 998244353;
// ds.Sort();
if (ds[0] > 0) {
Console.WriteLine(0);
return;
}
////頂点1と距離がdであるような頂点の数を持つ
// var a = new int[n + 1];
// a[0] = 1;
// long result = 1;
// for (int i = 1; i < n; i++)
//{
// var d = ds[i];
// result = ModMul(result, a[d - 1], p);
// a[d] += 1;
//}
var a = new int[n];
for (int i = 0; i < n; i++) {
a[ds[i]] += 1;
}
long result = 1;
for (int i = 1; i < n; i++) {
if (ds[i] == 0) {
result = 0;
break;
}
result = ModMul(result, a[ds[i] - 1], p);
}
Console.WriteLine(result);
//↑
}
}
}
|
[["-", 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, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 2,768
| 8
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
namespace Algorithm {
class Program {
const int Mod = 998244353;
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var d = Console.ReadLine().Split().Select(int.Parse).ToArray();
var dict = new Dictionary<int, int>();
for (var i = 0; i < n; i++) {
if (dict.ContainsKey(d[i]))
dict[d[i]]++;
else
dict[d[i]] = 1;
}
var total = 1L;
var before = 1;
var count = 0;
foreach (var data in dict.OrderBy(z => z.Key)) {
if (data.Key != count) {
Console.WriteLine(0);
return;
}
if (data.Key != 0 && data.Key != 1) {
total *= Multiple(before, data.Value);
total %= Mod;
}
before = data.Value;
count++;
}
Console.WriteLine(total);
}
static long Multiple(long val, int multiple) {
var ans = 1L;
foreach (var i in Enumerable.Range(1, multiple)) {
ans *= val % Mod;
}
return ans;
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
namespace Algorithm {
class Program {
const int Mod = 998244353;
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var d = Console.ReadLine().Split().Select(int.Parse).ToArray();
var dict = new Dictionary<int, int>();
for (var i = 0; i < n; i++) {
if (dict.ContainsKey(d[i]))
dict[d[i]]++;
else
dict[d[i]] = 1;
}
if (d[0] != 0 || dict[0] > 1) {
Console.WriteLine(0);
return;
}
var total = 1L;
var before = 1;
var count = 0;
foreach (var data in dict.OrderBy(z => z.Key)) {
if (data.Key != count) {
Console.WriteLine(0);
return;
}
if (data.Key != 0 && data.Key != 1) {
total *= Multiple(before, data.Value);
total %= Mod;
}
before = data.Value;
count++;
}
Console.WriteLine(total);
}
static long Multiple(long val, int multiple) {
var ans = 1L;
foreach (var i in Enumerable.Range(1, multiple)) {
ans *= val;
ans %= Mod;
}
return ans % Mod;
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 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], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 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, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 17, 109], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 12, 22]]
| 8
| 285
| 33
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
namespace Program {
public static class NIKKEI2019_2_QUALB {
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var DList = NNList(N);
Mod._mod = 998244353;
var sorted =
DList.GroupBy(e => e).ToDictionary(e => e.Key, e => (long)e.Count());
var chk = DList.OrderByRand().OrderBy(e => e).ToList();
for (var i = 1; i < N; i++) {
if (chk[i - 1] + 1 < chk[i]) {
Console.WriteLine(0);
return;
}
}
if (!sorted.ContainsKey(0)) {
Console.WriteLine(0);
return;
}
if (DList[0] > 0) {
Console.WriteLine(0);
return;
}
if (N == 1) {
Console.WriteLine(1);
return;
}
Mod ans = 1;
var max = sorted.Select(e => e.Key).Max();
if (sorted.Count <= max) {
Console.WriteLine(0);
return;
}
for (var i = 0; i < max; i++) {
ans *= Pow((Mod)sorted[i], (Mod)sorted[i + 1]);
}
Console.WriteLine(ans);
}
static public void Main(string[] args) {
if (args.Length == 0) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
Console.Out.Flush();
}
static class Console_ {
static Queue<string> param = new Queue<string>();
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static IEnumerable<long> Primes(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
static IEnumerable<long> Factors(long x) {
if (x < 2)
yield break;
while (x % 2 == 0) {
x /= 2;
yield return 2;
}
var max = (long)Math.Sqrt(x);
for (long i = 3; i <= max; i += 2)
while (x % i == 0) {
x /= i;
yield return i;
}
if (x != 1)
yield return x;
}
static IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
static long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
static long LCM(long a, long b) => a * b / GCD(a, b);
static Mod Pow(Mod x, long y) {
Mod a = 1;
while (y != 0) {
if ((y & 1) == 1)
a.Mul(x);
x.Mul(x);
y >>= 1;
}
return a;
}
static long Pow(long x, long y) {
long a = 1;
while (y != 0) {
if ((y & 1) == 1)
a *= x;
x *= x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>() { 1 };
static void _B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static long Comb(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static long Perm(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) {
Func<TR> t = () => default(TR);
return t = () => f(t);
}
static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) {
Func<T1, TR> t = x1 => default(TR);
return t = x1 => f(x1, t);
}
static Func<T1, T2, TR>
Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) {
Func<T1, T2, TR> t = (x1, x2) => default(TR);
return t = (x1, x2) => f(x1, x2, t);
}
static Func<T1, T2, T3, TR>
Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) {
Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR);
return t = (x1, x2, x3) => f(x1, x2, x3, t);
}
static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>(
Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) {
Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR);
return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t);
}
static List<T> LCS<T>(T[] s, T[] t)
where T : IEquatable<T> {
int sl = s.Length, tl = t.Length;
var dp = new int[sl + 1, tl + 1];
for (var i = 0; i < sl; i++)
for (var j = 0; j < tl; j++)
dp[i + 1, j + 1] =
s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]);
{
var r = new List<T>();
int i = sl, j = tl;
while (i > 0 && j > 0)
if (s[--i].Equals(t[--j]))
r.Add(s[i]);
else if (dp[i, j + 1] > dp[i + 1, j])
++j;
else
++i;
r.Reverse();
return r;
}
}
static long LIS<T>(T[] array, bool strict) {
var l = new List<T>();
foreach (var e in array) {
var i = l.BinarySearch(e);
if (i < 0)
i = ~i;
else if (!strict)
++i;
if (i == l.Count)
l.Add(e);
else
l[i] = e;
}
return l.Count;
}
class PQ<T> {
List<T> h;
Comparison<T> c;
public T Peek => h[0];
public int Count => h.Count;
public PQ(int cap, Comparison<T> c, bool asc = true) {
h = new List<T>(cap);
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(Comparison<T> c, bool asc = true) {
h = new List<T>();
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(int cap, bool asc = true)
: this(cap, Comparer<T>.Default.Compare, asc) {}
public PQ(bool asc = true) : this(Comparer<T>.Default.Compare, asc) {}
public void Push(T v) {
var i = h.Count;
h.Add(v);
while (i > 0) {
var ni = (i - 1) / 2;
if (c(v, h[ni]) >= 0)
break;
h[i] = h[ni];
i = ni;
}
h[i] = v;
}
public T Pop() {
var r = h[0];
var v = h[h.Count - 1];
h.RemoveAt(h.Count - 1);
if (h.Count == 0)
return r;
var i = 0;
while (i * 2 + 1 < h.Count) {
var i1 = i * 2 + 1;
var i2 = i * 2 + 2;
if (i2 < h.Count && c(h[i1], h[i2]) > 0)
i1 = i2;
if (c(v, h[i1]) <= 0)
break;
h[i] = h[i1];
i = i1;
}
h[i] = v;
return r;
}
}
class PQ<TK, TV> {
PQ<Tuple<TK, TV>> q;
public Tuple<TK, TV> Peek => q.Peek;
public int Count => q.Count;
public PQ(int cap, Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(int cap, bool asc = true)
: this(cap, Comparer<TK>.Default.Compare, asc) {}
public PQ(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) {}
public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v));
public Tuple<TK, TV> Pop() => q.Pop();
}
public class UF {
long[] d;
public UF(long s) { d = Repeat(-1L, s).ToArray(); }
public bool Unite(long x, long y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (d[y] < d[x]) {
var t = y;
y = x;
x = t;
}
d[x] += d[y];
d[y] = x;
}
return x != y;
}
public bool IsSame(long x, long y) => Root(x) == Root(y);
public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
public long Count(long x) => -d[Root(x)];
}
struct Mod : IEquatable<Mod>, IEquatable<long> {
static public long _mod = 1000000007;
long v;
public Mod(long x) {
if (x < _mod && x >= 0)
v = x;
else if ((v = x % _mod) < 0)
v += _mod;
}
static public implicit operator Mod(long x) => new Mod(x);
static public implicit operator long(Mod x) => x.v;
public void Add(Mod x) {
if ((v += x.v) >= _mod)
v -= _mod;
}
public void Sub(Mod x) {
if ((v -= x.v) < 0)
v += _mod;
}
public void Mul(Mod x) => v = (v * x.v) % _mod;
public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod;
static public Mod operator +(Mod x, Mod y) {
var t = x.v + y.v;
return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t };
}
static public Mod operator -(Mod x, Mod y) {
var t = x.v - y.v;
return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t };
}
static public Mod operator *(Mod x, Mod y) => x.v * y.v;
static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v);
static public bool operator ==(Mod x, Mod y) => x.v == y.v;
static public bool operator !=(Mod x, Mod y) => x.v != y.v;
static public long Inverse(long x) {
long b = _mod, r = 1, u = 0, t = 0;
while (b > 0) {
var q = x / b;
t = u;
u = r - q * u;
r = t;
t = b;
b = x - q * b;
x = t;
}
return r < 0 ? r + _mod : r;
}
public bool Equals(Mod x) => v == x.v;
public bool Equals(long x) => v == x;
public override bool Equals(object x) => x == null ? false : Equals((Mod)x);
public override int GetHashCode() => v.GetHashCode();
public override string ToString() => v.ToString();
static List<Mod> _fact = new List<Mod>() { 1 };
static void B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static public Mod Comb(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static public Mod Perm(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
}
class Tree {
long N;
int l;
List<long>[] p;
int[] d;
long[][] pr;
long r;
Tuple<long, long, int>[] e;
Tuple<long, long>[] b;
bool lca;
bool euler;
bool bfs;
public Tree(List<long>[] p_, long r_) {
N = p_.Length;
p = p_;
r = r_;
lca = false;
euler = false;
}
public Tuple<long, long>[] BFSRoot() {
if (!bfs) {
var nb = new List<Tuple<long, long>>();
var q = new Queue<long>();
var d = new bool[N];
nb.Add(Tuple.Create(r, -1L));
d[r] = true;
q.Enqueue(r);
while (q.Count > 0) {
var w = q.Dequeue();
foreach (var i in p[w]) {
if (d[i])
continue;
d[i] = true;
q.Enqueue(i);
nb.Add(Tuple.Create(i, w));
}
}
b = nb.ToArray();
bfs = true;
}
return b;
}
public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray();
public Tuple<long, long, int>[] Euler() {
if (!euler) {
var ne = new List<Tuple<long, long, int>>();
var s = new Stack<Tuple<long, long>>();
var d = new bool[N];
d[r] = true;
s.Push(Tuple.Create(r, -1L));
while (s.Count > 0) {
var w = s.Peek();
var ad = true;
foreach (var i in p[w.Item1]) {
if (d[i])
continue;
d[i] = true;
ad = false;
s.Push(Tuple.Create(i, w.Item1));
}
if (!ad || p[w.Item1].Count == 1)
ne.Add(Tuple.Create(w.Item1, w.Item2, 1));
if (ad) {
s.Pop();
ne.Add(Tuple.Create(w.Item1, w.Item2, -1));
}
}
e = ne.ToArray();
euler = true;
}
return e;
}
public long LCA(long u, long v) {
if (!lca) {
l = 0;
while (N > (1 << l))
l++;
d = new int[N];
pr = Repeat(0, l).Select(_ => new long[N]).ToArray();
d[r] = 0;
pr[0][r] = -1;
var q = new Stack<long>();
q.Push(r);
while (q.Count > 0) {
var w = q.Pop();
foreach (var i in p[w]) {
if (i == pr[0][w])
continue;
q.Push(i);
d[i] = d[w] + 1;
pr[0][i] = w;
}
}
for (var k = 0; k + 1 < l; k++)
for (var w = 0; w < N; w++)
if (pr[k][w] < 0)
pr[k + 1][w] = -1;
else
pr[k + 1][w] = pr[k][pr[k][w]];
lca = true;
}
if (d[u] > d[v]) {
var t = u;
u = v;
v = t;
}
for (var k = 0; k < l; k++)
if ((((d[v] - d[u]) >> k) & 1) != 0)
v = pr[k][v];
if (u == v)
return u;
for (var k = l - 1; k >= 0; k--)
if (pr[k][u] != pr[k][v]) {
u = pr[k][u];
v = pr[k][v];
}
return pr[0][u];
}
}
class BT<T>
where T : IComparable {
class Node {
public Node l;
public Node r;
public T v;
public bool b;
public int c;
}
Comparison<T> c;
Node r;
bool ch;
T lm;
public BT(Comparison<T> _c) { c = _c; }
public BT() : this((x, y) => x.CompareTo(y)) {}
bool R(Node n) => n != null && !n.b;
bool B(Node n) => n != null && n.b;
long C(Node n) => n?.c ?? 0;
Node RtL(Node n) {
Node m = n.r, t = m.l;
m.l = n;
n.r = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtR(Node n) {
Node m = n.l, t = m.r;
m.r = n;
n.l = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtLR(Node n) {
n.l = RtL(n.l);
return RtR(n);
}
Node RtRL(Node n) {
n.r = RtR(n.r);
return RtL(n);
}
public void Add(T x) {
r = A(r, x);
r.b = true;
}
Node A(Node n, T x) {
if (n == null) {
ch = true;
return new Node() { v = x, c = 1 };
}
if (c(x, n.v) < 0)
n.l = A(n.l, x);
else
n.r = A(n.r, x);
n.c++;
return Bl(n);
}
Node Bl(Node n) {
if (!ch)
return n;
if (!B(n))
return n;
if (R(n.l) && R(n.l.l)) {
n = RtR(n);
n.l.b = true;
} else if (R(n.l) && R(n.l.r)) {
n = RtLR(n);
n.l.b = true;
} else if (R(n.r) && R(n.r.l)) {
n = RtRL(n);
n.r.b = true;
} else if (R(n.r) && R(n.r.r)) {
n = RtL(n);
n.r.b = true;
} else
ch = false;
return n;
}
public void Remove(T x) {
r = Rm(r, x);
if (r != null)
r.b = true;
}
Node Rm(Node n, T x) {
if (n == null) {
ch = false;
return n;
}
n.c--;
var r = c(x, n.v);
if (r < 0) {
n.l = Rm(n.l, x);
return BlL(n);
}
if (r > 0) {
n.r = Rm(n.r, x);
return BlR(n);
}
if (n.l == null) {
ch = n.b;
return n.r;
}
n.l = RmM(n.l);
n.v = lm;
return BlL(n);
}
Node RmM(Node n) {
n.c--;
if (n.r != null) {
n.r = RmM(n.r);
return BlR(n);
}
lm = n.v;
ch = n.b;
return n.l;
}
Node BlL(Node n) {
if (!ch)
return n;
if (B(n.r) && R(n.r.l)) {
var b = n.b;
n = RtRL(n);
n.b = b;
n.l.b = true;
ch = false;
} else if (B(n.r) && R(n.r.r)) {
var b = n.b;
n = RtL(n);
n.b = b;
n.r.b = true;
n.l.b = true;
ch = false;
} else if (B(n.r)) {
ch = n.b;
n.b = true;
n.r.b = false;
} else {
n = RtL(n);
n.b = true;
n.l.b = false;
n.l = BlL(n.l);
ch = false;
}
return n;
}
Node BlR(Node n) {
if (!ch)
return n;
if (B(n.l) && R(n.l.r)) {
var b = n.b;
n = RtLR(n);
n.b = b;
n.r.b = true;
ch = false;
} else if (B(n.l) && R(n.l.l)) {
var b = n.b;
n = RtR(n);
n.b = b;
n.l.b = true;
n.r.b = true;
ch = false;
} else if (B(n.l)) {
ch = n.b;
n.b = true;
n.l.b = false;
} else {
n = RtR(n);
n.b = true;
n.r.b = false;
n.r = BlR(n.r);
ch = false;
}
return n;
}
public T this[long i] {
get { return At(r, i); }
}
T At(Node n, long i) {
if (n == null)
return default(T);
if (n.l == null)
if (i == 0)
return n.v;
else
return At(n.r, i - 1);
if (n.l.c == i)
return n.v;
if (n.l.c > i)
return At(n.l, i);
return At(n.r, i - n.l.c - 1);
}
public bool Have(T x) {
var t = FindUpper(x);
return t < C(r) && c(At(r, t), x) == 0;
}
public long FindUpper(T x, bool allowSame = true) => allowSame
? FL(r, x) + 1
: FU(r, x);
long FU(Node n, T x) {
if (n == null)
return 0;
var r = c(x, n.v);
if (r < 0)
return FU(n.l, x);
return C(n.l) + 1 + FU(n.r, x);
}
public long FindLower(T x, bool allowSame = true) {
var t = FL(r, x);
if (allowSame)
return t + 1 < C(r) && c(At(r, t + 1), x) == 0 ? t + 1
: t < 0 ? C(r)
: t;
return t < 0 ? C(r) : t;
}
long FL(Node n, T x) {
if (n == null)
return -1;
var r = c(x, n.v);
if (r > 0)
return C(n.l) + 1 + FL(n.r, x);
return FL(n.l, x);
}
public T Min() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.l;
}
return p == null ? default(T) : p.v;
}
public T Max() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.r;
}
return p == null ? default(T) : p.v;
}
public bool Any() => r != null;
public long Count() => C(r);
public IEnumerable<T> List() => L(r);
IEnumerable<T> L(Node n) {
if (n == null)
yield break;
foreach (var i in L(n.l))
yield return i;
yield return n.v;
foreach (var i in L(n.r))
yield return i;
}
}
class Dict<K, V> : Dictionary<K, V> {
Func<K, V> d;
public Dict(Func<K, V> _d) { d = _d; }
public Dict() : this(_ => default(V)) {}
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = d(i);
}
set { base[i] = value; }
}
public override int GetHashCode() {
var ret = 0;
for (var e = GetEnumerator(); e.MoveNext();) {
ret ^= e.Current.Key.GetHashCode();
ret ^= e.Current.Value.GetHashCode();
}
return ret;
}
public override bool Equals(object obj) {
var o = (Dict<K, V>)obj;
foreach (var kv in o) {
if (!ContainsKey(kv.Key) || !this[kv.Key].Equals(kv.Value))
return false;
}
return o.Count == Count;
}
}
class Deque<T> {
T[] b;
int o, c;
public int Count;
public T this[int i] {
get { return b[gi(i)]; }
set { b[gi(i)] = value; }
}
public Deque(int cap = 16) { b = new T[c = cap]; }
int gi(int i) {
if (i >= c)
throw new Exception();
var r = o + i;
return r >= c ? r - c : r;
}
public void PushFront(T x) {
if (Count == c)
e();
if (--o < 0)
o += b.Length;
b[o] = x;
++Count;
}
public T PopFront() {
if (Count-- == 0)
throw new Exception();
var r = b[o++];
if (o >= c)
o -= c;
return r;
}
public T Front => b[o];
public void PushBack(T x) {
if (Count == c)
e();
var i = o + Count++;
b[i >= c ? i - c : i] = x;
}
public T PopBack() {
if (Count == 0)
throw new Exception();
return b[gi(--Count)];
}
public T Back => b[gi(Count - 1)];
void e() {
T[] nb = new T[c << 1];
if (o > c - Count) {
var l = b.Length - o;
Array.Copy(b, o, nb, 0, l);
Array.Copy(b, 0, nb, l, Count - l);
} else
Array.Copy(b, o, nb, 0, Count);
b = nb;
o = 0;
c <<= 1;
}
public void Insert(int i, T x) {
if (i > Count)
throw new Exception();
this.PushFront(x);
for (int j = 0; j < i; j++)
this[j] = this[j + 1];
this[i] = x;
}
public T RemoveAt(int i) {
if (i < 0 || i >= Count)
throw new Exception();
var r = this[i];
for (int j = i; j > 0; j--)
this[j] = this[j - 1];
this.PopFront();
return r;
}
}
class SegTree<T> {
int n;
T ti;
Func<T, T, T> f;
T[] dat;
public SegTree(long _n, T _ti, Func<T, T, T> _f) {
n = 1;
while (n < _n)
n <<= 1;
ti = _ti;
f = _f;
dat = Repeat(ti, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public void Update(long i, T v) {
dat[i += n] = v;
while ((i >>= 1) > 0)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public T Query(long l, long r) {
var vl = ti;
var vr = ti;
for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, dat[li++]);
if ((ri & 1) == 1)
vr = f(dat[--ri], vr);
}
return f(vl, vr);
}
public T this[long idx] {
get { return dat[idx + n]; }
set { Update(idx, value); }
}
}
class LazySegTree<T, E> {
int n, height;
T ti;
E ei;
Func<T, T, T> f;
Func<T, E, T> g;
Func<E, E, E> h;
T[] dat;
E[] laz;
public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g,
Func<E, E, E> _h) {
n = 1;
height = 0;
while (n < _n) {
n <<= 1;
++height;
}
ti = _ti;
ei = _ei;
f = _f;
g = _g;
h = _h;
dat = Repeat(ti, n << 1).ToArray();
laz = Repeat(ei, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f,
Func<T, E, T> _g, Func<E, E, E> _h)
: this(l.Count, _ti, _ei, _f, _g, _h) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]);
void Eval(long i) {
if (laz[i].Equals(ei))
return;
laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]);
laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]);
dat[i] = Reflect(i);
laz[i] = ei;
}
void Thrust(long i) {
for (var j = height; j > 0; j--)
Eval(i >> j);
}
void Recalc(long i) {
while ((i >>= 1) > 0)
dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1));
}
public void Update(long l, long r, E v) {
Thrust(l += n);
Thrust(r += n - 1);
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1) {
laz[li] = h(laz[li], v);
++li;
}
if ((ri & 1) == 1) {
--ri;
laz[ri] = h(laz[ri], v);
}
}
Recalc(l);
Recalc(r);
}
public T Query(long l, long r) {
Thrust(l += n);
Thrust(r += n - 1);
var vl = ti;
var vr = ti;
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, Reflect(li++));
if ((ri & 1) == 1)
vr = f(Reflect(--ri), vr);
}
return f(vl, vr);
}
public T this[long idx] {
get {
Thrust(idx += n);
return dat[idx] = Reflect(idx);
}
set {
Thrust(idx += n);
dat[idx] = value;
laz[idx] = ei;
Recalc(idx);
}
}
}
class SlidingWindowAggregation<T> {
T[][] l;
T[][] a;
int[] n;
Func<T, T, T> f;
public SlidingWindowAggregation(IEnumerable<T> ary, Func<T, T, T> _f) {
l = new T[2][];
a = new T[2][];
n = new int[2];
f = _f;
l[0] = new T[16];
a[0] = new T[16];
n[0] = 0;
if (ary.Any()) {
var t = ary.ToArray();
n[1] = t.Length;
l[1] = new T[n[1]];
a[1] = new T[n[1]];
for (var i = 0; i < l[1].Length; i++) {
l[1][i] = t[i];
if (i == 0)
a[1][i] = t[i];
else
a[1][i] = this.f(a[1][i - 1], t[i]);
}
} else {
l[1] = new T[16];
a[1] = new T[16];
n[1] = 0;
}
}
public SlidingWindowAggregation(Func<T, T, T> f) : this(new T[0], f) {}
public int Count => n[0] + n[1];
void Push(int la, T v) {
if (l[la].Length == n[la]) {
var nar = new T[n[la] * 2];
var nag = new T[n[la] * 2];
Array.Copy(l[la], nar, n[la]);
Array.Copy(a[la], nag, n[la]);
l[la] = nar;
a[la] = nag;
}
if (n[la] == 0)
a[la][0] = v;
else
a[la][n[la]] = la == 0 ? f(v, a[la][n[la] - 1]) : f(a[la][n[la] - 1], v);
l[la][n[la]++] = v;
}
public void PushBack(T val) => Push(1, val);
public void PushFront(T val) => Push(0, val);
public T Pop(int la) {
var lb = 1 - la;
if (n[la] == 0) {
if (n[lb] == 0)
throw new Exception();
var m = (n[lb] - 1) / 2;
if (l[la].Length <= m) {
l[la] = new T[m + 1];
a[la] = new T[m + 1];
}
n[la] = 0;
for (var i = m; i >= 0; i--) {
if (n[la] == 0)
a[la][n[la]] = l[lb][i];
else
a[la][n[la]] = la == 0 ? f(l[lb][i], a[la][n[la] - 1])
: f(a[la][n[la] - 1], l[lb][i]);
l[la][n[la]++] = l[lb][i];
}
for (var i = m + 1; i < n[lb]; i++) {
var j = i - m - 1;
if (j == 0)
a[lb][j] = l[lb][i];
else
a[lb][j] =
la == 0 ? f(l[lb][i], a[lb][j - 1]) : f(a[lb][j - 1], l[lb][i]);
l[lb][j] = l[lb][i];
}
n[lb] -= n[la];
}
return l[la][--n[la]];
}
public T PopBack() => Pop(1);
public T PopFront() => Pop(0);
public T Aggregate() {
if (n[0] == 0 && n[1] == 0)
throw new Exception();
else if (n[1] == 0)
return a[0][n[0] - 1];
else if (n[0] == 0)
return a[1][n[1] - 1];
else
return f(a[0][n[0] - 1], a[1][n[1] - 1]);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
namespace Program {
public static class NIKKEI2019_2_QUALB {
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var DList = NNList(N);
Mod._mod = 998244353;
var sorted =
DList.GroupBy(e => e).ToDictionary(e => e.Key, e => (long)e.Count());
var chk = DList.OrderByRand().OrderBy(e => e).ToList();
for (var i = 1; i < N; i++) {
if (chk[i - 1] + 1 < chk[i]) {
Console.WriteLine(0);
return;
}
}
if (!sorted.ContainsKey(0)) {
Console.WriteLine(0);
return;
}
if (DList.Skip(1).Any(e => e == 0)) {
Console.WriteLine(0);
return;
}
if (DList[0] > 0) {
Console.WriteLine(0);
return;
}
if (N == 1) {
Console.WriteLine(1);
return;
}
Mod ans = 1;
var max = sorted.Select(e => e.Key).Max();
if (sorted.Count <= max) {
Console.WriteLine(0);
return;
}
for (var i = 0; i < max; i++) {
ans *= Pow((Mod)sorted[i], (Mod)sorted[i + 1]);
}
Console.WriteLine(ans);
}
static public void Main(string[] args) {
if (args.Length == 0) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
Console.Out.Flush();
}
static class Console_ {
static Queue<string> param = new Queue<string>();
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static IEnumerable<long> Primes(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
static IEnumerable<long> Factors(long x) {
if (x < 2)
yield break;
while (x % 2 == 0) {
x /= 2;
yield return 2;
}
var max = (long)Math.Sqrt(x);
for (long i = 3; i <= max; i += 2)
while (x % i == 0) {
x /= i;
yield return i;
}
if (x != 1)
yield return x;
}
static IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
static long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
static long LCM(long a, long b) => a * b / GCD(a, b);
static Mod Pow(Mod x, long y) {
Mod a = 1;
while (y != 0) {
if ((y & 1) == 1)
a.Mul(x);
x.Mul(x);
y >>= 1;
}
return a;
}
static long Pow(long x, long y) {
long a = 1;
while (y != 0) {
if ((y & 1) == 1)
a *= x;
x *= x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>() { 1 };
static void _B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static long Comb(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static long Perm(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) {
Func<TR> t = () => default(TR);
return t = () => f(t);
}
static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) {
Func<T1, TR> t = x1 => default(TR);
return t = x1 => f(x1, t);
}
static Func<T1, T2, TR>
Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) {
Func<T1, T2, TR> t = (x1, x2) => default(TR);
return t = (x1, x2) => f(x1, x2, t);
}
static Func<T1, T2, T3, TR>
Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) {
Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR);
return t = (x1, x2, x3) => f(x1, x2, x3, t);
}
static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>(
Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) {
Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR);
return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t);
}
static List<T> LCS<T>(T[] s, T[] t)
where T : IEquatable<T> {
int sl = s.Length, tl = t.Length;
var dp = new int[sl + 1, tl + 1];
for (var i = 0; i < sl; i++)
for (var j = 0; j < tl; j++)
dp[i + 1, j + 1] =
s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]);
{
var r = new List<T>();
int i = sl, j = tl;
while (i > 0 && j > 0)
if (s[--i].Equals(t[--j]))
r.Add(s[i]);
else if (dp[i, j + 1] > dp[i + 1, j])
++j;
else
++i;
r.Reverse();
return r;
}
}
static long LIS<T>(T[] array, bool strict) {
var l = new List<T>();
foreach (var e in array) {
var i = l.BinarySearch(e);
if (i < 0)
i = ~i;
else if (!strict)
++i;
if (i == l.Count)
l.Add(e);
else
l[i] = e;
}
return l.Count;
}
class PQ<T> {
List<T> h;
Comparison<T> c;
public T Peek => h[0];
public int Count => h.Count;
public PQ(int cap, Comparison<T> c, bool asc = true) {
h = new List<T>(cap);
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(Comparison<T> c, bool asc = true) {
h = new List<T>();
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(int cap, bool asc = true)
: this(cap, Comparer<T>.Default.Compare, asc) {}
public PQ(bool asc = true) : this(Comparer<T>.Default.Compare, asc) {}
public void Push(T v) {
var i = h.Count;
h.Add(v);
while (i > 0) {
var ni = (i - 1) / 2;
if (c(v, h[ni]) >= 0)
break;
h[i] = h[ni];
i = ni;
}
h[i] = v;
}
public T Pop() {
var r = h[0];
var v = h[h.Count - 1];
h.RemoveAt(h.Count - 1);
if (h.Count == 0)
return r;
var i = 0;
while (i * 2 + 1 < h.Count) {
var i1 = i * 2 + 1;
var i2 = i * 2 + 2;
if (i2 < h.Count && c(h[i1], h[i2]) > 0)
i1 = i2;
if (c(v, h[i1]) <= 0)
break;
h[i] = h[i1];
i = i1;
}
h[i] = v;
return r;
}
}
class PQ<TK, TV> {
PQ<Tuple<TK, TV>> q;
public Tuple<TK, TV> Peek => q.Peek;
public int Count => q.Count;
public PQ(int cap, Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(int cap, bool asc = true)
: this(cap, Comparer<TK>.Default.Compare, asc) {}
public PQ(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) {}
public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v));
public Tuple<TK, TV> Pop() => q.Pop();
}
public class UF {
long[] d;
public UF(long s) { d = Repeat(-1L, s).ToArray(); }
public bool Unite(long x, long y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (d[y] < d[x]) {
var t = y;
y = x;
x = t;
}
d[x] += d[y];
d[y] = x;
}
return x != y;
}
public bool IsSame(long x, long y) => Root(x) == Root(y);
public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
public long Count(long x) => -d[Root(x)];
}
struct Mod : IEquatable<Mod>, IEquatable<long> {
static public long _mod = 1000000007;
long v;
public Mod(long x) {
if (x < _mod && x >= 0)
v = x;
else if ((v = x % _mod) < 0)
v += _mod;
}
static public implicit operator Mod(long x) => new Mod(x);
static public implicit operator long(Mod x) => x.v;
public void Add(Mod x) {
if ((v += x.v) >= _mod)
v -= _mod;
}
public void Sub(Mod x) {
if ((v -= x.v) < 0)
v += _mod;
}
public void Mul(Mod x) => v = (v * x.v) % _mod;
public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod;
static public Mod operator +(Mod x, Mod y) {
var t = x.v + y.v;
return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t };
}
static public Mod operator -(Mod x, Mod y) {
var t = x.v - y.v;
return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t };
}
static public Mod operator *(Mod x, Mod y) => x.v * y.v;
static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v);
static public bool operator ==(Mod x, Mod y) => x.v == y.v;
static public bool operator !=(Mod x, Mod y) => x.v != y.v;
static public long Inverse(long x) {
long b = _mod, r = 1, u = 0, t = 0;
while (b > 0) {
var q = x / b;
t = u;
u = r - q * u;
r = t;
t = b;
b = x - q * b;
x = t;
}
return r < 0 ? r + _mod : r;
}
public bool Equals(Mod x) => v == x.v;
public bool Equals(long x) => v == x;
public override bool Equals(object x) => x == null ? false : Equals((Mod)x);
public override int GetHashCode() => v.GetHashCode();
public override string ToString() => v.ToString();
static List<Mod> _fact = new List<Mod>() { 1 };
static void B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static public Mod Comb(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static public Mod Perm(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
}
class Tree {
long N;
int l;
List<long>[] p;
int[] d;
long[][] pr;
long r;
Tuple<long, long, int>[] e;
Tuple<long, long>[] b;
bool lca;
bool euler;
bool bfs;
public Tree(List<long>[] p_, long r_) {
N = p_.Length;
p = p_;
r = r_;
lca = false;
euler = false;
}
public Tuple<long, long>[] BFSRoot() {
if (!bfs) {
var nb = new List<Tuple<long, long>>();
var q = new Queue<long>();
var d = new bool[N];
nb.Add(Tuple.Create(r, -1L));
d[r] = true;
q.Enqueue(r);
while (q.Count > 0) {
var w = q.Dequeue();
foreach (var i in p[w]) {
if (d[i])
continue;
d[i] = true;
q.Enqueue(i);
nb.Add(Tuple.Create(i, w));
}
}
b = nb.ToArray();
bfs = true;
}
return b;
}
public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray();
public Tuple<long, long, int>[] Euler() {
if (!euler) {
var ne = new List<Tuple<long, long, int>>();
var s = new Stack<Tuple<long, long>>();
var d = new bool[N];
d[r] = true;
s.Push(Tuple.Create(r, -1L));
while (s.Count > 0) {
var w = s.Peek();
var ad = true;
foreach (var i in p[w.Item1]) {
if (d[i])
continue;
d[i] = true;
ad = false;
s.Push(Tuple.Create(i, w.Item1));
}
if (!ad || p[w.Item1].Count == 1)
ne.Add(Tuple.Create(w.Item1, w.Item2, 1));
if (ad) {
s.Pop();
ne.Add(Tuple.Create(w.Item1, w.Item2, -1));
}
}
e = ne.ToArray();
euler = true;
}
return e;
}
public long LCA(long u, long v) {
if (!lca) {
l = 0;
while (N > (1 << l))
l++;
d = new int[N];
pr = Repeat(0, l).Select(_ => new long[N]).ToArray();
d[r] = 0;
pr[0][r] = -1;
var q = new Stack<long>();
q.Push(r);
while (q.Count > 0) {
var w = q.Pop();
foreach (var i in p[w]) {
if (i == pr[0][w])
continue;
q.Push(i);
d[i] = d[w] + 1;
pr[0][i] = w;
}
}
for (var k = 0; k + 1 < l; k++)
for (var w = 0; w < N; w++)
if (pr[k][w] < 0)
pr[k + 1][w] = -1;
else
pr[k + 1][w] = pr[k][pr[k][w]];
lca = true;
}
if (d[u] > d[v]) {
var t = u;
u = v;
v = t;
}
for (var k = 0; k < l; k++)
if ((((d[v] - d[u]) >> k) & 1) != 0)
v = pr[k][v];
if (u == v)
return u;
for (var k = l - 1; k >= 0; k--)
if (pr[k][u] != pr[k][v]) {
u = pr[k][u];
v = pr[k][v];
}
return pr[0][u];
}
}
class BT<T>
where T : IComparable {
class Node {
public Node l;
public Node r;
public T v;
public bool b;
public int c;
}
Comparison<T> c;
Node r;
bool ch;
T lm;
public BT(Comparison<T> _c) { c = _c; }
public BT() : this((x, y) => x.CompareTo(y)) {}
bool R(Node n) => n != null && !n.b;
bool B(Node n) => n != null && n.b;
long C(Node n) => n?.c ?? 0;
Node RtL(Node n) {
Node m = n.r, t = m.l;
m.l = n;
n.r = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtR(Node n) {
Node m = n.l, t = m.r;
m.r = n;
n.l = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtLR(Node n) {
n.l = RtL(n.l);
return RtR(n);
}
Node RtRL(Node n) {
n.r = RtR(n.r);
return RtL(n);
}
public void Add(T x) {
r = A(r, x);
r.b = true;
}
Node A(Node n, T x) {
if (n == null) {
ch = true;
return new Node() { v = x, c = 1 };
}
if (c(x, n.v) < 0)
n.l = A(n.l, x);
else
n.r = A(n.r, x);
n.c++;
return Bl(n);
}
Node Bl(Node n) {
if (!ch)
return n;
if (!B(n))
return n;
if (R(n.l) && R(n.l.l)) {
n = RtR(n);
n.l.b = true;
} else if (R(n.l) && R(n.l.r)) {
n = RtLR(n);
n.l.b = true;
} else if (R(n.r) && R(n.r.l)) {
n = RtRL(n);
n.r.b = true;
} else if (R(n.r) && R(n.r.r)) {
n = RtL(n);
n.r.b = true;
} else
ch = false;
return n;
}
public void Remove(T x) {
r = Rm(r, x);
if (r != null)
r.b = true;
}
Node Rm(Node n, T x) {
if (n == null) {
ch = false;
return n;
}
n.c--;
var r = c(x, n.v);
if (r < 0) {
n.l = Rm(n.l, x);
return BlL(n);
}
if (r > 0) {
n.r = Rm(n.r, x);
return BlR(n);
}
if (n.l == null) {
ch = n.b;
return n.r;
}
n.l = RmM(n.l);
n.v = lm;
return BlL(n);
}
Node RmM(Node n) {
n.c--;
if (n.r != null) {
n.r = RmM(n.r);
return BlR(n);
}
lm = n.v;
ch = n.b;
return n.l;
}
Node BlL(Node n) {
if (!ch)
return n;
if (B(n.r) && R(n.r.l)) {
var b = n.b;
n = RtRL(n);
n.b = b;
n.l.b = true;
ch = false;
} else if (B(n.r) && R(n.r.r)) {
var b = n.b;
n = RtL(n);
n.b = b;
n.r.b = true;
n.l.b = true;
ch = false;
} else if (B(n.r)) {
ch = n.b;
n.b = true;
n.r.b = false;
} else {
n = RtL(n);
n.b = true;
n.l.b = false;
n.l = BlL(n.l);
ch = false;
}
return n;
}
Node BlR(Node n) {
if (!ch)
return n;
if (B(n.l) && R(n.l.r)) {
var b = n.b;
n = RtLR(n);
n.b = b;
n.r.b = true;
ch = false;
} else if (B(n.l) && R(n.l.l)) {
var b = n.b;
n = RtR(n);
n.b = b;
n.l.b = true;
n.r.b = true;
ch = false;
} else if (B(n.l)) {
ch = n.b;
n.b = true;
n.l.b = false;
} else {
n = RtR(n);
n.b = true;
n.r.b = false;
n.r = BlR(n.r);
ch = false;
}
return n;
}
public T this[long i] {
get { return At(r, i); }
}
T At(Node n, long i) {
if (n == null)
return default(T);
if (n.l == null)
if (i == 0)
return n.v;
else
return At(n.r, i - 1);
if (n.l.c == i)
return n.v;
if (n.l.c > i)
return At(n.l, i);
return At(n.r, i - n.l.c - 1);
}
public bool Have(T x) {
var t = FindUpper(x);
return t < C(r) && c(At(r, t), x) == 0;
}
public long FindUpper(T x, bool allowSame = true) => allowSame
? FL(r, x) + 1
: FU(r, x);
long FU(Node n, T x) {
if (n == null)
return 0;
var r = c(x, n.v);
if (r < 0)
return FU(n.l, x);
return C(n.l) + 1 + FU(n.r, x);
}
public long FindLower(T x, bool allowSame = true) {
var t = FL(r, x);
if (allowSame)
return t + 1 < C(r) && c(At(r, t + 1), x) == 0 ? t + 1
: t < 0 ? C(r)
: t;
return t < 0 ? C(r) : t;
}
long FL(Node n, T x) {
if (n == null)
return -1;
var r = c(x, n.v);
if (r > 0)
return C(n.l) + 1 + FL(n.r, x);
return FL(n.l, x);
}
public T Min() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.l;
}
return p == null ? default(T) : p.v;
}
public T Max() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.r;
}
return p == null ? default(T) : p.v;
}
public bool Any() => r != null;
public long Count() => C(r);
public IEnumerable<T> List() => L(r);
IEnumerable<T> L(Node n) {
if (n == null)
yield break;
foreach (var i in L(n.l))
yield return i;
yield return n.v;
foreach (var i in L(n.r))
yield return i;
}
}
class Dict<K, V> : Dictionary<K, V> {
Func<K, V> d;
public Dict(Func<K, V> _d) { d = _d; }
public Dict() : this(_ => default(V)) {}
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = d(i);
}
set { base[i] = value; }
}
public override int GetHashCode() {
var ret = 0;
for (var e = GetEnumerator(); e.MoveNext();) {
ret ^= e.Current.Key.GetHashCode();
ret ^= e.Current.Value.GetHashCode();
}
return ret;
}
public override bool Equals(object obj) {
var o = (Dict<K, V>)obj;
foreach (var kv in o) {
if (!ContainsKey(kv.Key) || !this[kv.Key].Equals(kv.Value))
return false;
}
return o.Count == Count;
}
}
class Deque<T> {
T[] b;
int o, c;
public int Count;
public T this[int i] {
get { return b[gi(i)]; }
set { b[gi(i)] = value; }
}
public Deque(int cap = 16) { b = new T[c = cap]; }
int gi(int i) {
if (i >= c)
throw new Exception();
var r = o + i;
return r >= c ? r - c : r;
}
public void PushFront(T x) {
if (Count == c)
e();
if (--o < 0)
o += b.Length;
b[o] = x;
++Count;
}
public T PopFront() {
if (Count-- == 0)
throw new Exception();
var r = b[o++];
if (o >= c)
o -= c;
return r;
}
public T Front => b[o];
public void PushBack(T x) {
if (Count == c)
e();
var i = o + Count++;
b[i >= c ? i - c : i] = x;
}
public T PopBack() {
if (Count == 0)
throw new Exception();
return b[gi(--Count)];
}
public T Back => b[gi(Count - 1)];
void e() {
T[] nb = new T[c << 1];
if (o > c - Count) {
var l = b.Length - o;
Array.Copy(b, o, nb, 0, l);
Array.Copy(b, 0, nb, l, Count - l);
} else
Array.Copy(b, o, nb, 0, Count);
b = nb;
o = 0;
c <<= 1;
}
public void Insert(int i, T x) {
if (i > Count)
throw new Exception();
this.PushFront(x);
for (int j = 0; j < i; j++)
this[j] = this[j + 1];
this[i] = x;
}
public T RemoveAt(int i) {
if (i < 0 || i >= Count)
throw new Exception();
var r = this[i];
for (int j = i; j > 0; j--)
this[j] = this[j - 1];
this.PopFront();
return r;
}
}
class SegTree<T> {
int n;
T ti;
Func<T, T, T> f;
T[] dat;
public SegTree(long _n, T _ti, Func<T, T, T> _f) {
n = 1;
while (n < _n)
n <<= 1;
ti = _ti;
f = _f;
dat = Repeat(ti, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public void Update(long i, T v) {
dat[i += n] = v;
while ((i >>= 1) > 0)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public T Query(long l, long r) {
var vl = ti;
var vr = ti;
for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, dat[li++]);
if ((ri & 1) == 1)
vr = f(dat[--ri], vr);
}
return f(vl, vr);
}
public T this[long idx] {
get { return dat[idx + n]; }
set { Update(idx, value); }
}
}
class LazySegTree<T, E> {
int n, height;
T ti;
E ei;
Func<T, T, T> f;
Func<T, E, T> g;
Func<E, E, E> h;
T[] dat;
E[] laz;
public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g,
Func<E, E, E> _h) {
n = 1;
height = 0;
while (n < _n) {
n <<= 1;
++height;
}
ti = _ti;
ei = _ei;
f = _f;
g = _g;
h = _h;
dat = Repeat(ti, n << 1).ToArray();
laz = Repeat(ei, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f,
Func<T, E, T> _g, Func<E, E, E> _h)
: this(l.Count, _ti, _ei, _f, _g, _h) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]);
void Eval(long i) {
if (laz[i].Equals(ei))
return;
laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]);
laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]);
dat[i] = Reflect(i);
laz[i] = ei;
}
void Thrust(long i) {
for (var j = height; j > 0; j--)
Eval(i >> j);
}
void Recalc(long i) {
while ((i >>= 1) > 0)
dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1));
}
public void Update(long l, long r, E v) {
Thrust(l += n);
Thrust(r += n - 1);
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1) {
laz[li] = h(laz[li], v);
++li;
}
if ((ri & 1) == 1) {
--ri;
laz[ri] = h(laz[ri], v);
}
}
Recalc(l);
Recalc(r);
}
public T Query(long l, long r) {
Thrust(l += n);
Thrust(r += n - 1);
var vl = ti;
var vr = ti;
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, Reflect(li++));
if ((ri & 1) == 1)
vr = f(Reflect(--ri), vr);
}
return f(vl, vr);
}
public T this[long idx] {
get {
Thrust(idx += n);
return dat[idx] = Reflect(idx);
}
set {
Thrust(idx += n);
dat[idx] = value;
laz[idx] = ei;
Recalc(idx);
}
}
}
class SlidingWindowAggregation<T> {
T[][] l;
T[][] a;
int[] n;
Func<T, T, T> f;
public SlidingWindowAggregation(IEnumerable<T> ary, Func<T, T, T> _f) {
l = new T[2][];
a = new T[2][];
n = new int[2];
f = _f;
l[0] = new T[16];
a[0] = new T[16];
n[0] = 0;
if (ary.Any()) {
var t = ary.ToArray();
n[1] = t.Length;
l[1] = new T[n[1]];
a[1] = new T[n[1]];
for (var i = 0; i < l[1].Length; i++) {
l[1][i] = t[i];
if (i == 0)
a[1][i] = t[i];
else
a[1][i] = this.f(a[1][i - 1], t[i]);
}
} else {
l[1] = new T[16];
a[1] = new T[16];
n[1] = 0;
}
}
public SlidingWindowAggregation(Func<T, T, T> f) : this(new T[0], f) {}
public int Count => n[0] + n[1];
void Push(int la, T v) {
if (l[la].Length == n[la]) {
var nar = new T[n[la] * 2];
var nag = new T[n[la] * 2];
Array.Copy(l[la], nar, n[la]);
Array.Copy(a[la], nag, n[la]);
l[la] = nar;
a[la] = nag;
}
if (n[la] == 0)
a[la][0] = v;
else
a[la][n[la]] = la == 0 ? f(v, a[la][n[la] - 1]) : f(a[la][n[la] - 1], v);
l[la][n[la]++] = v;
}
public void PushBack(T val) => Push(1, val);
public void PushFront(T val) => Push(0, val);
public T Pop(int la) {
var lb = 1 - la;
if (n[la] == 0) {
if (n[lb] == 0)
throw new Exception();
var m = (n[lb] - 1) / 2;
if (l[la].Length <= m) {
l[la] = new T[m + 1];
a[la] = new T[m + 1];
}
n[la] = 0;
for (var i = m; i >= 0; i--) {
if (n[la] == 0)
a[la][n[la]] = l[lb][i];
else
a[la][n[la]] = la == 0 ? f(l[lb][i], a[la][n[la] - 1])
: f(a[la][n[la] - 1], l[lb][i]);
l[la][n[la]++] = l[lb][i];
}
for (var i = m + 1; i < n[lb]; i++) {
var j = i - m - 1;
if (j == 0)
a[lb][j] = l[lb][i];
else
a[lb][j] =
la == 0 ? f(l[lb][i], a[lb][j - 1]) : f(a[lb][j - 1], l[lb][i]);
l[lb][j] = l[lb][i];
}
n[lb] -= n[la];
}
return l[la][--n[la]];
}
public T PopBack() => Pop(1);
public T PopFront() => Pop(0);
public T Aggregate() {
if (n[0] == 0 && n[1] == 0)
throw new Exception();
else if (n[1] == 0)
return a[0][n[0] - 1];
else if (n[0] == 0)
return a[1][n[1] - 1];
else
return f(a[0][n[0] - 1], a[1][n[1] - 1]);
}
}
}
}
|
[["+", 15, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 15, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 15, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 15, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 15, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 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], ["+", 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, 204, 205, 22]]
| 8
| 9,783
| 29
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var waaaa = new waaaa();
waaaa.Solve();
}
}
public class waaaa {
const int MOD = 1000000007;
const long INF = 1 << 61;
const int MOD2 = 998244353;
Scaner cin = new Scaner();
write cout = new write();
Math2 mmath = new Math2();
public void Solve() {
//ここから
var o = cin.IntM;
var N = o[0];
var D = cin.IntM;
int[] x = new int[N];
for (int i = 0; i < N; ++i) {
x[D[i]]++;
}
long max = D.Max();
long ans = 1;
for (int i = 1; (i < N) && (i <= max); ++i) {
ans *= mmath.pow(x[i - 1], x[i], MOD2);
ans %= MOD2;
}
cout.wri(ans);
}
}
// b-aで降順
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
public class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
// Nまでの階乗をセットしておく
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = pow(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
// nCr 引数:n r (mod)
public long nCr(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
//階乗(O(logN)) 引数:底x n乗 (MOD)
public long pow(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
//最大公約数 引数:整数x,y
public long GCD(long x, long y) {
while (y != 0) {
var r = x % y;
x = y;
y = r;
}
return x;
}
//最小公倍数 引数:整数x,y
public long LCM(long x, long y) { return x * y / GCD(x, y); }
//素因数分解 引数:整数N
public Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> PrimeFactorization2(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
namespace CompLib.Algorithms {
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrM => Str.Split(' ');
public long[] LongM => StrM.Select(long.Parse).ToArray();
public int[] IntM => StrM.Select(int.Parse).ToArray();
public char[] CharM => Str.ToArray();
public long Long1 => LongM[0];
public int Int1 => IntM[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var waaaa = new waaaa();
waaaa.Solve();
}
}
public class waaaa {
const int MOD = 1000000007;
const long INF = 1 << 61;
const int MOD2 = 998244353;
Scaner cin = new Scaner();
write cout = new write();
Math2 mmath = new Math2();
public void Solve() {
//ここから
var o = cin.IntM;
var N = o[0];
var D = cin.IntM;
int[] x = new int[N];
for (int i = 0; i < N; ++i) {
if ((i != 0 && D[i] == 0) || D[0] != 0) {
cout.wri(0);
return;
}
x[D[i]]++;
}
long max = D.Max();
long ans = 1;
for (int i = 1; (i < N) && (i <= max); ++i) {
ans *= (mmath.pow(x[i - 1], x[i], MOD2));
ans %= MOD2;
}
cout.wri(ans);
}
}
// b-aで降順
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
public class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
// Nまでの階乗をセットしておく
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = pow(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
// nCr 引数:n r (mod)
public long nCr(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
//階乗(O(logN)) 引数:底x n乗 (MOD)
public long pow(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
//最大公約数 引数:整数x,y
public long GCD(long x, long y) {
while (y != 0) {
var r = x % y;
x = y;
y = r;
}
return x;
}
//最小公倍数 引数:整数x,y
public long LCM(long x, long y) { return x * y / GCD(x, y); }
//素因数分解 引数:整数N
public Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> PrimeFactorization2(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
namespace CompLib.Algorithms {
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrM => Str.Split(' ');
public long[] LongM => StrM.Select(long.Parse).ToArray();
public int[] IntM => StrM.Select(int.Parse).ToArray();
public char[] CharM => Str.ToArray();
public long Long1 => LongM[0];
public int Int1 => IntM[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
[["+", 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, 23, 0, 24], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 17, 79], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["+", 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], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 17, 60], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 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, 79], ["+", 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, 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, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["+", 0, 11, 12, 23, 0, 213, 3, 4, 0, 25]]
| 8
| 1,559
| 35
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
Console.WriteLine(Solve());
// Solve();
return;
}
public static string Solve() {
long N = ReadLong();
long[] D = ReadLongs();
long mod = 998244353;
long ans = 1;
long target = 0;
long cnt = 0;
Array.Sort(D);
List<long> Dc = new List<long>();
for (int i = 0; i < N; i++) {
if (D[i] == target) {
cnt++;
} else if (D[i] == target + 1) {
Dc.Add(cnt);
target++;
cnt = 1;
} else {
return "0";
}
}
Dc.Add(cnt);
for (int i = 0; i < Dc.Count - 1; i++) {
ans = (ans * Pow(Dc[i], Dc[i + 1])) % mod;
}
return ans.ToString();
}
private static long Pow(long a, long b) {
long mod = 998244353;
long res = 1;
for (long i = 0; i < b; i++) {
res = (res * a) % mod;
}
return res;
}
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
Console.WriteLine(Solve());
// Solve();
return;
}
public static string Solve() {
long N = ReadLong();
long[] D = ReadLongs();
long mod = 998244353;
long ans = 1;
long target = 1;
long cnt = 0;
if (D[0] != 0) {
return "0";
}
Array.Sort(D);
if (D[1] != 1) {
return "0";
}
List<long> Dc = new List<long>();
for (int i = 1; i < N; i++) {
if (D[i] == target) {
cnt++;
} else if (D[i] == target + 1) {
Dc.Add(cnt);
target++;
cnt = 1;
} else {
return "0";
}
}
Dc.Add(cnt);
for (int i = 0; i < Dc.Count - 1; i++) {
ans = (ans * Pow(Dc[i], Dc[i + 1])) % mod;
}
return ans.ToString();
}
private static long Pow(long a, long b) {
long mod = 998244353;
long res = 1;
for (long i = 0; i < b; i++) {
res = (res * a) % mod;
}
return res;
}
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 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, 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, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 37, 0, 5, 0, 62], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 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], ["+", 0, 57, 64, 196, 0, 37, 0, 5, 0, 222], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 431
| 36
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;
public class Prog {
public static void Solve() {
int N = NextInt();
NX mod = 998244353;
NX[] D = LineLong();
var d = D.OrderBy(x => x).ToList();
if (N > 1 && d[1] == 0) {
Console.WriteLine(0);
return;
}
int counter = 0;
for (int i = 0; i < N; i++) {
if (counter != d[i]) {
if (d[i] - counter == 1) {
counter++;
continue;
} else {
Console.WriteLine(0);
return;
}
}
}
Dictionary<NX, NX> dic = new Dictionary<NX, NX>();
for (int i = 0; i < N; i++) {
if (!dic.ContainsKey(d[i]))
dic[d[i]] = 0;
dic[d[i]]++;
}
bool f = true;
NX before = 0;
NX ans = 1;
foreach (var e in dic) {
if (f) {
f = false;
before = e.Value;
continue;
}
ans *= RepPow(before, e.Value, mod) % mod;
ans %= mod;
before = e.Value;
}
Console.WriteLine(ans % mod);
}
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
return;
}
public static long RepPow(long x, long p, long m = 1000000007) {
if (p == 1)
return x % m;
long b = RepPow(x, p / 2, m) % m;
if (p % 2 == 0) {
return (b * b) % m;
} else {
return (x * ((b * b) % m)) % m;
}
}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
public long Abs(long a, long b) => Math.Abs(a - b);
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;
public class Prog {
public static void Solve() {
int N = NextInt();
NX mod = 998244353;
NX[] D = LineLong();
if (D[0] != 0) {
Console.WriteLine(0);
return;
}
var d = D.OrderBy(x => x).ToList();
if (N > 1 && d[1] == 0) {
Console.WriteLine(0);
return;
}
int counter = 0;
for (int i = 0; i < N; i++) {
if (counter != d[i]) {
if (d[i] - counter == 1) {
counter++;
continue;
} else {
Console.WriteLine(0);
return;
}
}
}
Dictionary<NX, NX> dic = new Dictionary<NX, NX>();
for (int i = 0; i < N; i++) {
if (!dic.ContainsKey(d[i]))
dic[d[i]] = 0;
dic[d[i]]++;
}
bool f = true;
NX before = 0;
NX ans = 1;
foreach (var e in dic) {
if (f) {
f = false;
before = e.Value;
continue;
}
ans *= RepPow(before, e.Value, mod) % mod;
ans %= mod;
before = e.Value;
}
Console.WriteLine(ans % mod);
}
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
return;
}
public static long RepPow(long x, long p, long m = 1000000007) {
if (p == 1)
return x % m;
long b = RepPow(x, p / 2, m) % m;
if (p % 2 == 0) {
return (b * b) % m;
} else {
return (x * ((b * b) % m)) % m;
}
}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
public long Abs(long a, long b) => Math.Abs(a - b);
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 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, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 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
| 759
| 20
|
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 = 998244353; // 1000000007;
private const int MAX = 100001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static void Solve() {
int n = Input.NextInt();
var d = Input.NextInt(n);
var totals = new int[n];
for (int i = 0; i < n; ++i) {
totals[d[i]]++;
}
if (totals[0] != 1) {
Console.WriteLine(0);
return;
}
int lastIdx = 0;
for (int i = 1; i < n; ++i) {
if (totals[i] != 0) {
lastIdx = i;
} else {
break;
}
}
for (int i = lastIdx + 1; i < n; ++i) {
if (totals[i] != 0) {
Console.WriteLine(0);
return;
}
}
long ans = 1;
for (int i = 1; i <= lastIdx; ++i) {
long a = totals[i - 1];
long b = totals[i];
for (int j = 0; j < b; ++j) {
ans *= a;
ans %= MOD;
}
}
Console.WriteLine(ans);
}
private static double Convert(double tan) {
return Math.Atan(tan) * 180.0 / Math.PI;
}
#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 = 998244353; // 1000000007;
private const int MAX = 100001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static void Solve() {
int n = Input.NextInt();
var d = Input.NextInt(n);
if (d[0] != 0) {
Console.WriteLine(0);
return;
}
var totals = new int[n];
for (int i = 0; i < n; ++i) {
totals[d[i]]++;
}
if (totals[0] != 1) {
Console.WriteLine(0);
return;
}
int lastIdx = 0;
for (int i = 1; i < n; ++i) {
if (totals[i] != 0) {
lastIdx = i;
} else {
break;
}
}
for (int i = lastIdx + 1; i < n; ++i) {
if (totals[i] != 0) {
Console.WriteLine(0);
return;
}
}
long ans = 1;
for (int i = 1; i <= lastIdx; ++i) {
long a = totals[i - 1];
long b = totals[i];
for (int j = 0; j < b; ++j) {
ans *= a;
ans %= MOD;
}
}
Console.WriteLine(ans);
}
private static double Convert(double tan) {
return Math.Atan(tan) * 180.0 / Math.PI;
}
#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, 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, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 2,621
| 20
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
long mod = 998244353;
long[] B = new long[N + 1];
long[] A = new long[N + 1];
string[] str = Console.ReadLine().Split();
for (var i = 0; i < N; i++) {
int a2 = int.Parse(str[i]);
B[i] = a2;
A[a2]++;
}
long ans = 0;
long a1 = 0;
bool flag = true;
if (B[0] == 0) {
ans = 1;
a1 = 1;
for (var i = 1; i <= N; i++) {
if (A[i] > 0) {
if (flag == false) {
ans = 0;
}
ans = ans * Mpow(a1, A[i], mod) % mod;
a1 = A[i];
} else {
flag = false;
}
// Console.WriteLine(A[i]+" "+a1+" "+ans);
}
}
Console.WriteLine(ans);
}
public static long Mpow(long x, long n, long m) {
long ans = 1;
while (n > 0) {
if (n % 2 == 1) {
ans = ans * x % m;
n -= 1;
}
x = x * x % m;
n /= 2;
}
return ans;
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
long mod = 998244353;
long[] B = new long[N + 1];
long[] A = new long[N + 1];
string[] str = Console.ReadLine().Split();
for (var i = 0; i < N; i++) {
int a2 = int.Parse(str[i]);
B[i] = a2;
A[a2]++;
}
long ans = 0;
long a1 = 0;
bool flag = true;
if (B[0] == 0 && A[0] == 1) {
ans = 1;
a1 = 1;
for (var i = 1; i <= N; i++) {
if (A[i] > 0) {
if (flag == false) {
ans = 0;
}
ans = ans * Mpow(a1, A[i], mod) % mod;
a1 = A[i];
} else {
flag = false;
}
// Console.WriteLine(A[i]+" "+a1+" "+ans);
}
}
Console.WriteLine(ans);
}
public static long Mpow(long x, long n, long m) {
long ans = 1;
while (n > 0) {
if (n % 2 == 1) {
ans = ans * x % m;
n -= 1;
}
x = x * x % m;
n /= 2;
}
return ans;
}
}
|
[["+", 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], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 306
| 7
|
using System;
using System.Linq;
namespace B {
class Program {
static void Main(string[] args) { Console.WriteLine(solver()); }
static long solver() {
var N = int.Parse(Console.ReadLine());
var D = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
long MOD = 998244353;
var distance = new long[D.Max() + 1];
foreach (int d in D)
distance[d] += 1;
if (distance[0] != 1)
return 0;
long result = 1;
for (int i = 1; i < distance.Length; i++) {
for (int j = 0; j < distance[i]; j++) {
result *= distance[i - 1];
result %= MOD;
}
}
return result;
}
}
}
|
using System;
using System.Linq;
namespace B {
class Program {
static void Main(string[] args) { Console.WriteLine(solver()); }
static long solver() {
var N = int.Parse(Console.ReadLine());
var D = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
long MOD = 998244353;
if (D[0] != 0)
return 0;
var distance = new long[D.Max() + 1];
foreach (int d in D)
distance[d] += 1;
if (distance[0] != 1)
return 0;
long result = 1;
for (int i = 1; i < distance.Length; i++) {
for (int j = 0; j < distance[i]; j++) {
result *= distance[i - 1];
result %= MOD;
}
}
return result;
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 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, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35]]
| 8
| 186
| 12
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
long mod = 998244353;
long answer = 1;
long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
if (nums[0] != 0)
answer = 0;
Array.Sort(nums);
int vertexMemo = 0;
long lastlastCount = 1;
long lastCount = 1;
long countMemo = 0;
for (int i = 1; i < n; i++) {
if (vertexMemo + 1 == nums[i]) {
vertexMemo++;
answer *= DivideMod(lastlastCount, lastCount, mod);
answer %= mod;
lastlastCount = lastCount;
lastCount = 1;
} else if (vertexMemo == nums[i]) {
lastCount++;
} else
answer = 0;
// Console.WriteLine(lastlastCount+" "+lastCount+" "+answer);
}
answer *= DivideMod(lastlastCount, lastCount, mod);
answer %= mod;
Console.WriteLine(answer);
}
static long DivideMod(long x, long a, long p) //戻り値はx^a(mod p)。O(loga)
{
long num = 2;
long answer = 1;
long check = a;
long memo = x % p;
while (check > 0) {
if (check % num == num / 2) {
check -= num / 2;
answer *= memo;
answer %= p;
}
memo *= memo;
memo %= p;
num *= 2;
}
return answer;
}
}
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
long mod = 998244353;
long answer = 1;
long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
if (nums[0] != 0)
answer = 0;
Array.Sort(nums);
int vertexMemo = 0;
long lastlastCount = 1;
long lastCount = 1;
long countMemo = 0;
for (int i = 1; i < n; i++) {
if (nums[1] != 1)
answer = 0;
if (vertexMemo + 1 == nums[i]) {
vertexMemo++;
answer *= DivideMod(lastlastCount, lastCount, mod);
answer %= mod;
lastlastCount = lastCount;
lastCount = 1;
} else if (vertexMemo == nums[i]) {
lastCount++;
} else
answer = 0;
// Console.WriteLine(lastlastCount+" "+lastCount+" "+answer);
}
answer *= DivideMod(lastlastCount, lastCount, mod);
answer %= mod;
Console.WriteLine(answer);
}
static long DivideMod(long x, long a, long p) //戻り値はx^a(mod p)。O(loga)
{
long num = 2;
long answer = 1;
long check = a;
long memo = x % p;
while (check > 0) {
if (check % num == num / 2) {
check -= num / 2;
answer *= memo;
answer %= p;
}
memo *= memo;
memo %= p;
num *= 2;
}
return answer;
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24]]
| 8
| 309
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder {
class AC {
const int MOD = 1000000007;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
const double EPS = 1e-8;
static readonly int[] dx = { 0, 1, 0, -1 };
static readonly int[] dy = { 1, 0, -1, 0 };
static void Main(string[] args) {
// var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
// false }; Console.SetOut(sw);
var cin = new Scanner();
int N = int.Parse(Console.ReadLine());
var D = cin.SplitRead();
if (N == 1) {
Console.WriteLine(D[0] == 0 ? 1 : 0);
return;
}
var c = new int[N];
Initialize(ref c, 0);
for (var i = 0; i < N; i++) {
c[D[i]]++;
}
if (c[0] != 1) {
Console.WriteLine(0);
return;
}
long ans = 1;
int mod = 998244353;
for (var i = 1; i < N; i++) {
ans = (ans * c[D[i] - 1]) % mod;
}
Console.WriteLine(ans);
// Console.Out.Flush();
}
}
public class PriorityQueue<T>
where T : IComparable<T> {
private List<T> Q;
private readonly int r;
public PriorityQueue(bool ascending) {
if (ascending) {
r = 1;
} else {
r = -1;
}
Q = new List<T>();
}
private void PushHeap(List<T> list, T item) {
int n = list.Count();
list.Add(item);
while (n != 0) {
int pIndex = (n - 1) / 2;
if (list[n].CompareTo(list[pIndex]) * r > 0) {
Swap(Q, n, pIndex);
} else {
break;
}
n = pIndex;
}
}
private void PopHeap(List<T> list) {
int n = list.Count() - 1;
list[0] = list[n];
list.RemoveAt(n);
int cur = 0;
int comp;
while (2 * cur + 1 <= n - 1) {
int c1 = 2 * cur + 1;
int c2 = 2 * (cur + 1);
if (c1 == n - 1) {
comp = c1;
} else {
comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2;
}
if (list[cur].CompareTo(list[comp]) * r < 0) {
Swap(Q, cur, comp);
} else {
break;
}
cur = comp;
}
}
private void Swap(List<T> list, int a, int b) {
T keep = list[a];
list[a] = list[b];
list[b] = keep;
}
public void Enqueue(T value) { PushHeap(Q, value); }
public T Dequeue() {
T ret = Q[0];
PopHeap(Q);
return ret;
}
public T Peek() { return Q[0]; }
public int CountItem() { return Q.Count(); }
}
public class Scanner {
public int[] SplitRead() {
int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
return array;
}
public long[] SplitReadL() {
long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
return array;
}
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
for (var i = 0; i < array.Length; i++) {
array[i] = initialvalue;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder {
class AC {
const int MOD = 1000000007;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
const double EPS = 1e-8;
static readonly int[] dx = { 0, 1, 0, -1 };
static readonly int[] dy = { 1, 0, -1, 0 };
static void Main(string[] args) {
// var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
// false }; Console.SetOut(sw);
var cin = new Scanner();
int N = int.Parse(Console.ReadLine());
var D = cin.SplitRead();
if (N == 1) {
Console.WriteLine(D[0] == 0 ? 1 : 0);
return;
}
var c = new int[N];
Initialize(ref c, 0);
for (var i = 0; i < N; i++) {
c[D[i]]++;
}
if (c[0] != 1) {
Console.WriteLine(0);
return;
}
if (D[0] != 0) {
Console.WriteLine(0);
return;
}
long ans = 1;
int mod = 998244353;
for (var i = 1; i < N; i++) {
ans = (ans * c[D[i] - 1]) % mod;
}
Console.WriteLine(ans);
// Console.Out.Flush();
}
}
public class PriorityQueue<T>
where T : IComparable<T> {
private List<T> Q;
private readonly int r;
public PriorityQueue(bool ascending) {
if (ascending) {
r = 1;
} else {
r = -1;
}
Q = new List<T>();
}
private void PushHeap(List<T> list, T item) {
int n = list.Count();
list.Add(item);
while (n != 0) {
int pIndex = (n - 1) / 2;
if (list[n].CompareTo(list[pIndex]) * r > 0) {
Swap(Q, n, pIndex);
} else {
break;
}
n = pIndex;
}
}
private void PopHeap(List<T> list) {
int n = list.Count() - 1;
list[0] = list[n];
list.RemoveAt(n);
int cur = 0;
int comp;
while (2 * cur + 1 <= n - 1) {
int c1 = 2 * cur + 1;
int c2 = 2 * (cur + 1);
if (c1 == n - 1) {
comp = c1;
} else {
comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2;
}
if (list[cur].CompareTo(list[comp]) * r < 0) {
Swap(Q, cur, comp);
} else {
break;
}
cur = comp;
}
}
private void Swap(List<T> list, int a, int b) {
T keep = list[a];
list[a] = list[b];
list[b] = keep;
}
public void Enqueue(T value) { PushHeap(Q, value); }
public T Dequeue() {
T ret = Q[0];
PopHeap(Q);
return ret;
}
public T Peek() { return Q[0]; }
public int CountItem() { return Q.Count(); }
}
public class Scanner {
public int[] SplitRead() {
int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
return array;
}
public long[] SplitReadL() {
long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
return array;
}
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
for (var i = 0; i < array.Length; i++) {
array[i] = initialvalue;
}
}
}
}
|
[["+", 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, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 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
| 856
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;
using Number = System.Int64;
class Solver {
public void Solve() {
var num = Input.num;
var ds = Input.ar;
Array.Sort(ds);
var ct = new int[num];
for (var i = 0; i < num; i++)
ct[ds[i]]++;
if (ct[0] > 1)
Fail(0);
var max = ds[num - 1];
var res = (ModInt)1;
for (var i = 1; i <= max; i++)
res *= ModInt.Pow(ct[i - 1], ct[i]);
WriteLine(res);
}
}
public struct ModInt {
// public const long MOD = (int)1e9 + 7;
public const long MOD = 998244353;
public long num { get; set; }
public ModInt(long n = 0) { num = n; }
private static ModInt[] _fac; //階乗
private static ModInt[] _inv; //逆数
private static ModInt[] _facrev; // 1/(i!)
public override string ToString() => num.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= MOD)
l.num -= MOD;
return l;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += MOD;
return l;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt l,
ModInt r) => new ModInt(l.num * r.num % MOD);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt l) => l.num;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long n) {
n %= MOD;
if (n < 0)
n += MOD;
return new ModInt(n);
}
public static ModInt Pow(ModInt m, long n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return Pow(m * m, n >> 1);
else
return Pow(m * m, n >> 1) * m;
}
public static void CombBuild(int n) {
_fac = new ModInt[n + 1];
_facrev = new ModInt[n + 1];
_inv = new ModInt[n + 1];
_inv[1] = 1;
_fac[0] = _fac[1] = 1;
_facrev[0] = _facrev[1] = 1;
for (var i = 2; i <= n; i++) {
_fac[i] = _fac[i - 1] * i;
_inv[i] = MOD - _inv[MOD % i] * (MOD / i);
_facrev[i] = _facrev[i - 1] * _inv[i];
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Fac(ModInt n) => _fac[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Div(ModInt n) => _inv[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt FacRev(ModInt n) => _facrev[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Comb(ModInt n, ModInt r) {
if (n < r)
return 0;
if (n == r)
return 1;
var calc = _fac[n];
calc = calc * _facrev[r];
calc = calc * _facrev[n - r];
return calc;
}
}
#region Template
public class Template {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == 1) {
num = val;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == -1) {
num = val;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T v1, ref T v2) {
var t = v2;
v2 = v1;
v1 = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<T> f) =>
Enumerable.Repeat(0, n).Select(_ => f()).ToArray();
public static void Fail() => Fail("No");
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var p = new Solver();
for (var i = 1; i > 0; --i)
p.Solve();
Console.Out.Flush();
}
}
public class Input {
public static string read => Console.ReadLine().Trim();
public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
public static int num => Convert.ToInt32(read);
public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
public static long numL => Convert.ToInt64(read);
public static char[][] grid(int h) => Create(h, () => read.ToCharArray());
public static int[] ar1D(int n) => Create(n, () => num);
public static long[] arL1D(int n) => Create(n, () => numL);
public static string[] strs(int n) => Create(n, () => read);
public static int[][] ar2D(int n) => Create(n, () => ar);
public static long[][] arL2D(int n) => Create(n, () => arL);
public static List<T>[] edge<T>(int n) => Create(n, () => new List<T>());
public static void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public static 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 static 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 static 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>();
}
static Input() {
sc = new Queue<string>();
dic = new Dictionary<Type, Func<string, object>>();
dic[typeof(int)] = s => int.Parse(s);
dic[typeof(long)] = s => long.Parse(s);
dic[typeof(char)] = s => char.Parse(s);
dic[typeof(double)] = s => double.Parse(s);
dic[typeof(uint)] = s => uint.Parse(s);
dic[typeof(ulong)] = s => ulong.Parse(s);
dic[typeof(string)] = s => s;
}
private static Dictionary<Type, Func<string, object>> dic;
private static Queue<string> sc;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Next<T>() {
if (sc.Count == 0)
foreach (var item in read.Split(' '))
sc.Enqueue(item);
return (T)dic[typeof(T)](sc.Dequeue());
}
public const int MOD = 1000000007;
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {
v1 = default(T1);
v2 = default(T2);
}
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 class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() { v3 = default(T3); }
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()}";
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;
using Number = System.Int64;
class Solver {
public void Solve() {
var num = Input.num;
var ds = Input.ar;
if (ds[0] != 0)
Fail(0);
Array.Sort(ds);
var ct = new int[num];
for (var i = 0; i < num; i++)
ct[ds[i]]++;
if (ct[0] != 1)
Fail(0);
var max = ds[num - 1];
var res = (ModInt)1;
for (var i = 1; i <= max; i++)
res *= ModInt.Pow(ct[i - 1], ct[i]);
WriteLine(res);
}
}
public struct ModInt {
// public const long MOD = (int)1e9 + 7;
public const long MOD = 998244353;
public long num { get; set; }
public ModInt(long n = 0) { num = n; }
private static ModInt[] _fac; //階乗
private static ModInt[] _inv; //逆数
private static ModInt[] _facrev; // 1/(i!)
public override string ToString() => num.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= MOD)
l.num -= MOD;
return l;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += MOD;
return l;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt l,
ModInt r) => new ModInt(l.num * r.num % MOD);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt l) => l.num;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long n) {
n %= MOD;
if (n < 0)
n += MOD;
return new ModInt(n);
}
public static ModInt Pow(ModInt m, long n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return Pow(m * m, n >> 1);
else
return Pow(m * m, n >> 1) * m;
}
public static void CombBuild(int n) {
_fac = new ModInt[n + 1];
_facrev = new ModInt[n + 1];
_inv = new ModInt[n + 1];
_inv[1] = 1;
_fac[0] = _fac[1] = 1;
_facrev[0] = _facrev[1] = 1;
for (var i = 2; i <= n; i++) {
_fac[i] = _fac[i - 1] * i;
_inv[i] = MOD - _inv[MOD % i] * (MOD / i);
_facrev[i] = _facrev[i - 1] * _inv[i];
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Fac(ModInt n) => _fac[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Div(ModInt n) => _inv[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt FacRev(ModInt n) => _facrev[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Comb(ModInt n, ModInt r) {
if (n < r)
return 0;
if (n == r)
return 1;
var calc = _fac[n];
calc = calc * _facrev[r];
calc = calc * _facrev[n - r];
return calc;
}
}
#region Template
public class Template {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == 1) {
num = val;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == -1) {
num = val;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T v1, ref T v2) {
var t = v2;
v2 = v1;
v1 = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<T> f) =>
Enumerable.Repeat(0, n).Select(_ => f()).ToArray();
public static void Fail() => Fail("No");
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var p = new Solver();
for (var i = 1; i > 0; --i)
p.Solve();
Console.Out.Flush();
}
}
public class Input {
public static string read => Console.ReadLine().Trim();
public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
public static int num => Convert.ToInt32(read);
public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
public static long numL => Convert.ToInt64(read);
public static char[][] grid(int h) => Create(h, () => read.ToCharArray());
public static int[] ar1D(int n) => Create(n, () => num);
public static long[] arL1D(int n) => Create(n, () => numL);
public static string[] strs(int n) => Create(n, () => read);
public static int[][] ar2D(int n) => Create(n, () => ar);
public static long[][] arL2D(int n) => Create(n, () => arL);
public static List<T>[] edge<T>(int n) => Create(n, () => new List<T>());
public static void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public static 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 static 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 static 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>();
}
static Input() {
sc = new Queue<string>();
dic = new Dictionary<Type, Func<string, object>>();
dic[typeof(int)] = s => int.Parse(s);
dic[typeof(long)] = s => long.Parse(s);
dic[typeof(char)] = s => char.Parse(s);
dic[typeof(double)] = s => double.Parse(s);
dic[typeof(uint)] = s => uint.Parse(s);
dic[typeof(ulong)] = s => ulong.Parse(s);
dic[typeof(string)] = s => s;
}
private static Dictionary<Type, Func<string, object>> dic;
private static Queue<string> sc;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Next<T>() {
if (sc.Count == 0)
foreach (var item in read.Split(' '))
sc.Enqueue(item);
return (T)dic[typeof(T)](sc.Dequeue());
}
public const int MOD = 1000000007;
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {
v1 = default(T1);
v2 = default(T2);
}
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 class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() { v3 = default(T3); }
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()}";
}
#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, 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, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 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], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
| 8
| 2,271
| 16
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
namespace Program {
public static class NIKKEI2019_2_QUALD {
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var M = NN;
var LRC =
Repeat(0, M).Select(_ => new { L = NN, R = NN, C = NN }).ToArray();
var segtree = new SegTree<long>(N + 1, 1000000000000000000, Min);
segtree.Update(1, 0);
foreach (var item in LRC.OrderByRand().OrderBy(e => e.R)) {
var minItem = segtree.Query(item.L, item.R + 1);
segtree.Update(item.R, minItem + item.C);
}
var ans = segtree[N];
if (ans >= 1000000000000000000) {
Console.WriteLine(-1);
} else {
Console.WriteLine(ans);
}
}
static public void Main(string[] args) {
if (args.Length == 0) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
Console.Out.Flush();
}
static class Console_ {
static Queue<string> param = new Queue<string>();
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static IEnumerable<long> Primes(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
static IEnumerable<long> Factors(long x) {
if (x < 2)
yield break;
while (x % 2 == 0) {
x /= 2;
yield return 2;
}
var max = (long)Math.Sqrt(x);
for (long i = 3; i <= max; i += 2)
while (x % i == 0) {
x /= i;
yield return i;
}
if (x != 1)
yield return x;
}
static IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
static long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
static long LCM(long a, long b) => a * b / GCD(a, b);
static Mod Pow(Mod x, long y) {
Mod a = 1;
while (y != 0) {
if ((y & 1) == 1)
a.Mul(x);
x.Mul(x);
y >>= 1;
}
return a;
}
static long Pow(long x, long y) {
long a = 1;
while (y != 0) {
if ((y & 1) == 1)
a *= x;
x *= x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>() { 1 };
static void _B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static long Comb(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static long Perm(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) {
Func<TR> t = () => default(TR);
return t = () => f(t);
}
static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) {
Func<T1, TR> t = x1 => default(TR);
return t = x1 => f(x1, t);
}
static Func<T1, T2, TR>
Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) {
Func<T1, T2, TR> t = (x1, x2) => default(TR);
return t = (x1, x2) => f(x1, x2, t);
}
static Func<T1, T2, T3, TR>
Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) {
Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR);
return t = (x1, x2, x3) => f(x1, x2, x3, t);
}
static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>(
Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) {
Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR);
return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t);
}
static List<T> LCS<T>(T[] s, T[] t)
where T : IEquatable<T> {
int sl = s.Length, tl = t.Length;
var dp = new int[sl + 1, tl + 1];
for (var i = 0; i < sl; i++)
for (var j = 0; j < tl; j++)
dp[i + 1, j + 1] =
s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]);
{
var r = new List<T>();
int i = sl, j = tl;
while (i > 0 && j > 0)
if (s[--i].Equals(t[--j]))
r.Add(s[i]);
else if (dp[i, j + 1] > dp[i + 1, j])
++j;
else
++i;
r.Reverse();
return r;
}
}
static long LIS<T>(T[] array, bool strict) {
var l = new List<T>();
foreach (var e in array) {
var i = l.BinarySearch(e);
if (i < 0)
i = ~i;
else if (!strict)
++i;
if (i == l.Count)
l.Add(e);
else
l[i] = e;
}
return l.Count;
}
class PQ<T> {
List<T> h;
Comparison<T> c;
public T Peek => h[0];
public int Count => h.Count;
public PQ(int cap, Comparison<T> c, bool asc = true) {
h = new List<T>(cap);
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(Comparison<T> c, bool asc = true) {
h = new List<T>();
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(int cap, bool asc = true)
: this(cap, Comparer<T>.Default.Compare, asc) {}
public PQ(bool asc = true) : this(Comparer<T>.Default.Compare, asc) {}
public void Push(T v) {
var i = h.Count;
h.Add(v);
while (i > 0) {
var ni = (i - 1) / 2;
if (c(v, h[ni]) >= 0)
break;
h[i] = h[ni];
i = ni;
}
h[i] = v;
}
public T Pop() {
var r = h[0];
var v = h[h.Count - 1];
h.RemoveAt(h.Count - 1);
if (h.Count == 0)
return r;
var i = 0;
while (i * 2 + 1 < h.Count) {
var i1 = i * 2 + 1;
var i2 = i * 2 + 2;
if (i2 < h.Count && c(h[i1], h[i2]) > 0)
i1 = i2;
if (c(v, h[i1]) <= 0)
break;
h[i] = h[i1];
i = i1;
}
h[i] = v;
return r;
}
}
class PQ<TK, TV> {
PQ<Tuple<TK, TV>> q;
public Tuple<TK, TV> Peek => q.Peek;
public int Count => q.Count;
public PQ(int cap, Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(int cap, bool asc = true)
: this(cap, Comparer<TK>.Default.Compare, asc) {}
public PQ(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) {}
public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v));
public Tuple<TK, TV> Pop() => q.Pop();
}
public class UF {
long[] d;
public UF(long s) { d = Repeat(-1L, s).ToArray(); }
public bool Unite(long x, long y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (d[y] < d[x]) {
var t = y;
y = x;
x = t;
}
d[x] += d[y];
d[y] = x;
}
return x != y;
}
public bool IsSame(long x, long y) => Root(x) == Root(y);
public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
public long Count(long x) => -d[Root(x)];
}
struct Mod : IEquatable<Mod>, IEquatable<long> {
static public long _mod = 1000000007;
long v;
public Mod(long x) {
if (x < _mod && x >= 0)
v = x;
else if ((v = x % _mod) < 0)
v += _mod;
}
static public implicit operator Mod(long x) => new Mod(x);
static public implicit operator long(Mod x) => x.v;
public void Add(Mod x) {
if ((v += x.v) >= _mod)
v -= _mod;
}
public void Sub(Mod x) {
if ((v -= x.v) < 0)
v += _mod;
}
public void Mul(Mod x) => v = (v * x.v) % _mod;
public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod;
static public Mod operator +(Mod x, Mod y) {
var t = x.v + y.v;
return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t };
}
static public Mod operator -(Mod x, Mod y) {
var t = x.v - y.v;
return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t };
}
static public Mod operator *(Mod x, Mod y) => x.v * y.v;
static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v);
static public bool operator ==(Mod x, Mod y) => x.v == y.v;
static public bool operator !=(Mod x, Mod y) => x.v != y.v;
static public long Inverse(long x) {
long b = _mod, r = 1, u = 0, t = 0;
while (b > 0) {
var q = x / b;
t = u;
u = r - q * u;
r = t;
t = b;
b = x - q * b;
x = t;
}
return r < 0 ? r + _mod : r;
}
public bool Equals(Mod x) => v == x.v;
public bool Equals(long x) => v == x;
public override bool Equals(object x) => x == null ? false : Equals((Mod)x);
public override int GetHashCode() => v.GetHashCode();
public override string ToString() => v.ToString();
static List<Mod> _fact = new List<Mod>() { 1 };
static void B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static public Mod Comb(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static public Mod Perm(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
}
class Tree {
long N;
int l;
List<long>[] p;
int[] d;
long[][] pr;
long r;
Tuple<long, long, int>[] e;
Tuple<long, long>[] b;
bool lca;
bool euler;
bool bfs;
public Tree(List<long>[] p_, long r_) {
N = p_.Length;
p = p_;
r = r_;
lca = false;
euler = false;
}
public Tuple<long, long>[] BFSRoot() {
if (!bfs) {
var nb = new List<Tuple<long, long>>();
var q = new Queue<long>();
var d = new bool[N];
nb.Add(Tuple.Create(r, -1L));
d[r] = true;
q.Enqueue(r);
while (q.Count > 0) {
var w = q.Dequeue();
foreach (var i in p[w]) {
if (d[i])
continue;
d[i] = true;
q.Enqueue(i);
nb.Add(Tuple.Create(i, w));
}
}
b = nb.ToArray();
bfs = true;
}
return b;
}
public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray();
public Tuple<long, long, int>[] Euler() {
if (!euler) {
var ne = new List<Tuple<long, long, int>>();
var s = new Stack<Tuple<long, long>>();
var d = new bool[N];
d[r] = true;
s.Push(Tuple.Create(r, -1L));
while (s.Count > 0) {
var w = s.Peek();
var ad = true;
foreach (var i in p[w.Item1]) {
if (d[i])
continue;
d[i] = true;
ad = false;
s.Push(Tuple.Create(i, w.Item1));
}
if (!ad || p[w.Item1].Count == 1)
ne.Add(Tuple.Create(w.Item1, w.Item2, 1));
if (ad) {
s.Pop();
ne.Add(Tuple.Create(w.Item1, w.Item2, -1));
}
}
e = ne.ToArray();
euler = true;
}
return e;
}
public long LCA(long u, long v) {
if (!lca) {
l = 0;
while (N > (1 << l))
l++;
d = new int[N];
pr = Repeat(0, l).Select(_ => new long[N]).ToArray();
d[r] = 0;
pr[0][r] = -1;
var q = new Stack<long>();
q.Push(r);
while (q.Count > 0) {
var w = q.Pop();
foreach (var i in p[w]) {
if (i == pr[0][w])
continue;
q.Push(i);
d[i] = d[w] + 1;
pr[0][i] = w;
}
}
for (var k = 0; k + 1 < l; k++)
for (var w = 0; w < N; w++)
if (pr[k][w] < 0)
pr[k + 1][w] = -1;
else
pr[k + 1][w] = pr[k][pr[k][w]];
lca = true;
}
if (d[u] > d[v]) {
var t = u;
u = v;
v = t;
}
for (var k = 0; k < l; k++)
if ((((d[v] - d[u]) >> k) & 1) != 0)
v = pr[k][v];
if (u == v)
return u;
for (var k = l - 1; k >= 0; k--)
if (pr[k][u] != pr[k][v]) {
u = pr[k][u];
v = pr[k][v];
}
return pr[0][u];
}
}
class BT<T>
where T : IComparable {
class Node {
public Node l;
public Node r;
public T v;
public bool b;
public int c;
}
Comparison<T> c;
Node r;
bool ch;
T lm;
public BT(Comparison<T> _c) { c = _c; }
public BT() : this((x, y) => x.CompareTo(y)) {}
bool R(Node n) => n != null && !n.b;
bool B(Node n) => n != null && n.b;
long C(Node n) => n?.c ?? 0;
Node RtL(Node n) {
Node m = n.r, t = m.l;
m.l = n;
n.r = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtR(Node n) {
Node m = n.l, t = m.r;
m.r = n;
n.l = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtLR(Node n) {
n.l = RtL(n.l);
return RtR(n);
}
Node RtRL(Node n) {
n.r = RtR(n.r);
return RtL(n);
}
public void Add(T x) {
r = A(r, x);
r.b = true;
}
Node A(Node n, T x) {
if (n == null) {
ch = true;
return new Node() { v = x, c = 1 };
}
if (c(x, n.v) < 0)
n.l = A(n.l, x);
else
n.r = A(n.r, x);
n.c++;
return Bl(n);
}
Node Bl(Node n) {
if (!ch)
return n;
if (!B(n))
return n;
if (R(n.l) && R(n.l.l)) {
n = RtR(n);
n.l.b = true;
} else if (R(n.l) && R(n.l.r)) {
n = RtLR(n);
n.l.b = true;
} else if (R(n.r) && R(n.r.l)) {
n = RtRL(n);
n.r.b = true;
} else if (R(n.r) && R(n.r.r)) {
n = RtL(n);
n.r.b = true;
} else
ch = false;
return n;
}
public void Remove(T x) {
r = Rm(r, x);
if (r != null)
r.b = true;
}
Node Rm(Node n, T x) {
if (n == null) {
ch = false;
return n;
}
n.c--;
var r = c(x, n.v);
if (r < 0) {
n.l = Rm(n.l, x);
return BlL(n);
}
if (r > 0) {
n.r = Rm(n.r, x);
return BlR(n);
}
if (n.l == null) {
ch = n.b;
return n.r;
}
n.l = RmM(n.l);
n.v = lm;
return BlL(n);
}
Node RmM(Node n) {
n.c--;
if (n.r != null) {
n.r = RmM(n.r);
return BlR(n);
}
lm = n.v;
ch = n.b;
return n.l;
}
Node BlL(Node n) {
if (!ch)
return n;
if (B(n.r) && R(n.r.l)) {
var b = n.b;
n = RtRL(n);
n.b = b;
n.l.b = true;
ch = false;
} else if (B(n.r) && R(n.r.r)) {
var b = n.b;
n = RtL(n);
n.b = b;
n.r.b = true;
n.l.b = true;
ch = false;
} else if (B(n.r)) {
ch = n.b;
n.b = true;
n.r.b = false;
} else {
n = RtL(n);
n.b = true;
n.l.b = false;
n.l = BlL(n.l);
ch = false;
}
return n;
}
Node BlR(Node n) {
if (!ch)
return n;
if (B(n.l) && R(n.l.r)) {
var b = n.b;
n = RtLR(n);
n.b = b;
n.r.b = true;
ch = false;
} else if (B(n.l) && R(n.l.l)) {
var b = n.b;
n = RtR(n);
n.b = b;
n.l.b = true;
n.r.b = true;
ch = false;
} else if (B(n.l)) {
ch = n.b;
n.b = true;
n.l.b = false;
} else {
n = RtR(n);
n.b = true;
n.r.b = false;
n.r = BlR(n.r);
ch = false;
}
return n;
}
public T this[long i] {
get { return At(r, i); }
}
T At(Node n, long i) {
if (n == null)
return default(T);
if (n.l == null)
if (i == 0)
return n.v;
else
return At(n.r, i - 1);
if (n.l.c == i)
return n.v;
if (n.l.c > i)
return At(n.l, i);
return At(n.r, i - n.l.c - 1);
}
public bool Have(T x) {
var t = FindUpper(x);
return t < C(r) && c(At(r, t), x) == 0;
}
public long FindUpper(T x, bool allowSame = true) => allowSame
? FL(r, x) + 1
: FU(r, x);
long FU(Node n, T x) {
if (n == null)
return 0;
var r = c(x, n.v);
if (r < 0)
return FU(n.l, x);
return C(n.l) + 1 + FU(n.r, x);
}
public long FindLower(T x, bool allowSame = true) {
var t = FL(r, x);
if (allowSame)
return t + 1 < C(r) && c(At(r, t + 1), x) == 0 ? t + 1
: t < 0 ? C(r)
: t;
return t < 0 ? C(r) : t;
}
long FL(Node n, T x) {
if (n == null)
return -1;
var r = c(x, n.v);
if (r > 0)
return C(n.l) + 1 + FL(n.r, x);
return FL(n.l, x);
}
public T Min() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.l;
}
return p == null ? default(T) : p.v;
}
public T Max() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.r;
}
return p == null ? default(T) : p.v;
}
public bool Any() => r != null;
public long Count() => C(r);
public IEnumerable<T> List() => L(r);
IEnumerable<T> L(Node n) {
if (n == null)
yield break;
foreach (var i in L(n.l))
yield return i;
yield return n.v;
foreach (var i in L(n.r))
yield return i;
}
}
class Dict<K, V> : Dictionary<K, V> {
Func<K, V> d;
public Dict(Func<K, V> _d) { d = _d; }
public Dict() : this(_ => default(V)) {}
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = d(i);
}
set { base[i] = value; }
}
public override int GetHashCode() {
var ret = 0;
for (var e = GetEnumerator(); e.MoveNext();) {
ret ^= e.Current.Key.GetHashCode();
ret ^= e.Current.Value.GetHashCode();
}
return ret;
}
public override bool Equals(object obj) {
var o = (Dict<K, V>)obj;
foreach (var kv in o) {
if (!ContainsKey(kv.Key) || !this[kv.Key].Equals(kv.Value))
return false;
}
return o.Count == Count;
}
}
class Deque<T> {
T[] b;
int o, c;
public int Count;
public T this[int i] {
get { return b[gi(i)]; }
set { b[gi(i)] = value; }
}
public Deque(int cap = 16) { b = new T[c = cap]; }
int gi(int i) {
if (i >= c)
throw new Exception();
var r = o + i;
return r >= c ? r - c : r;
}
public void PushFront(T x) {
if (Count == c)
e();
if (--o < 0)
o += b.Length;
b[o] = x;
++Count;
}
public T PopFront() {
if (Count-- == 0)
throw new Exception();
var r = b[o++];
if (o >= c)
o -= c;
return r;
}
public T Front => b[o];
public void PushBack(T x) {
if (Count == c)
e();
var i = o + Count++;
b[i >= c ? i - c : i] = x;
}
public T PopBack() {
if (Count == 0)
throw new Exception();
return b[gi(--Count)];
}
public T Back => b[gi(Count - 1)];
void e() {
T[] nb = new T[c << 1];
if (o > c - Count) {
var l = b.Length - o;
Array.Copy(b, o, nb, 0, l);
Array.Copy(b, 0, nb, l, Count - l);
} else
Array.Copy(b, o, nb, 0, Count);
b = nb;
o = 0;
c <<= 1;
}
public void Insert(int i, T x) {
if (i > Count)
throw new Exception();
this.PushFront(x);
for (int j = 0; j < i; j++)
this[j] = this[j + 1];
this[i] = x;
}
public T RemoveAt(int i) {
if (i < 0 || i >= Count)
throw new Exception();
var r = this[i];
for (int j = i; j > 0; j--)
this[j] = this[j - 1];
this.PopFront();
return r;
}
}
class SegTree<T> {
int n;
T ti;
Func<T, T, T> f;
T[] dat;
public SegTree(long _n, T _ti, Func<T, T, T> _f) {
n = 1;
while (n < _n)
n <<= 1;
ti = _ti;
f = _f;
dat = Repeat(ti, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public void Update(long i, T v) {
dat[i += n] = v;
while ((i >>= 1) > 0)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public T Query(long l, long r) {
var vl = ti;
var vr = ti;
for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, dat[li++]);
if ((ri & 1) == 1)
vr = f(dat[--ri], vr);
}
return f(vl, vr);
}
public T this[long idx] {
get { return dat[idx + n]; }
set { Update(idx, value); }
}
}
class LazySegTree<T, E> {
int n, height;
T ti;
E ei;
Func<T, T, T> f;
Func<T, E, T> g;
Func<E, E, E> h;
T[] dat;
E[] laz;
public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g,
Func<E, E, E> _h) {
n = 1;
height = 0;
while (n < _n) {
n <<= 1;
++height;
}
ti = _ti;
ei = _ei;
f = _f;
g = _g;
h = _h;
dat = Repeat(ti, n << 1).ToArray();
laz = Repeat(ei, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f,
Func<T, E, T> _g, Func<E, E, E> _h)
: this(l.Count, _ti, _ei, _f, _g, _h) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]);
void Eval(long i) {
if (laz[i].Equals(ei))
return;
laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]);
laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]);
dat[i] = Reflect(i);
laz[i] = ei;
}
void Thrust(long i) {
for (var j = height; j > 0; j--)
Eval(i >> j);
}
void Recalc(long i) {
while ((i >>= 1) > 0)
dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1));
}
public void Update(long l, long r, E v) {
Thrust(l += n);
Thrust(r += n - 1);
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1) {
laz[li] = h(laz[li], v);
++li;
}
if ((ri & 1) == 1) {
--ri;
laz[ri] = h(laz[ri], v);
}
}
Recalc(l);
Recalc(r);
}
public T Query(long l, long r) {
Thrust(l += n);
Thrust(r += n - 1);
var vl = ti;
var vr = ti;
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, Reflect(li++));
if ((ri & 1) == 1)
vr = f(Reflect(--ri), vr);
}
return f(vl, vr);
}
public T this[long idx] {
get {
Thrust(idx += n);
return dat[idx] = Reflect(idx);
}
set {
Thrust(idx += n);
dat[idx] = value;
laz[idx] = ei;
Recalc(idx);
}
}
}
class SlidingWindowAggregation<T> {
T[][] l;
T[][] a;
int[] n;
Func<T, T, T> f;
public SlidingWindowAggregation(IEnumerable<T> ary, Func<T, T, T> _f) {
l = new T[2][];
a = new T[2][];
n = new int[2];
f = _f;
l[0] = new T[16];
a[0] = new T[16];
n[0] = 0;
if (ary.Any()) {
var t = ary.ToArray();
n[1] = t.Length;
l[1] = new T[n[1]];
a[1] = new T[n[1]];
for (var i = 0; i < l[1].Length; i++) {
l[1][i] = t[i];
if (i == 0)
a[1][i] = t[i];
else
a[1][i] = this.f(a[1][i - 1], t[i]);
}
} else {
l[1] = new T[16];
a[1] = new T[16];
n[1] = 0;
}
}
public SlidingWindowAggregation(Func<T, T, T> f) : this(new T[0], f) {}
public int Count => n[0] + n[1];
void Push(int la, T v) {
if (l[la].Length == n[la]) {
var nar = new T[n[la] * 2];
var nag = new T[n[la] * 2];
Array.Copy(l[la], nar, n[la]);
Array.Copy(a[la], nag, n[la]);
l[la] = nar;
a[la] = nag;
}
if (n[la] == 0)
a[la][0] = v;
else
a[la][n[la]] = la == 0 ? f(v, a[la][n[la] - 1]) : f(a[la][n[la] - 1], v);
l[la][n[la]++] = v;
}
public void PushBack(T val) => Push(1, val);
public void PushFront(T val) => Push(0, val);
public T Pop(int la) {
var lb = 1 - la;
if (n[la] == 0) {
if (n[lb] == 0)
throw new Exception();
var m = (n[lb] - 1) / 2;
if (l[la].Length <= m) {
l[la] = new T[m + 1];
a[la] = new T[m + 1];
}
n[la] = 0;
for (var i = m; i >= 0; i--) {
if (n[la] == 0)
a[la][n[la]] = l[lb][i];
else
a[la][n[la]] = la == 0 ? f(l[lb][i], a[la][n[la] - 1])
: f(a[la][n[la] - 1], l[lb][i]);
l[la][n[la]++] = l[lb][i];
}
for (var i = m + 1; i < n[lb]; i++) {
var j = i - m - 1;
if (j == 0)
a[lb][j] = l[lb][i];
else
a[lb][j] =
la == 0 ? f(l[lb][i], a[lb][j - 1]) : f(a[lb][j - 1], l[lb][i]);
l[lb][j] = l[lb][i];
}
n[lb] -= n[la];
}
return l[la][--n[la]];
}
public T PopBack() => Pop(1);
public T PopFront() => Pop(0);
public T Aggregate() {
if (n[0] == 0 && n[1] == 0)
throw new Exception();
else if (n[1] == 0)
return a[0][n[0] - 1];
else if (n[0] == 0)
return a[1][n[1] - 1];
else
return f(a[0][n[0] - 1], a[1][n[1] - 1]);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
namespace Program {
public static class NIKKEI2019_2_QUALD {
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var M = NN;
var LRC =
Repeat(0, M).Select(_ => new { L = NN, R = NN, C = NN }).ToArray();
var segtree = new SegTree<long>(N + 1, 1000000000000000000, Min);
segtree.Update(1, 0);
foreach (var item in LRC.OrderByRand().OrderBy(e => e.R)) {
var minItem = segtree.Query(item.L, item.R + 1);
segtree.Update(item.R, Min(segtree[item.R], minItem + item.C));
}
var ans = segtree[N];
if (ans >= 1000000000000000000) {
Console.WriteLine(-1);
} else {
Console.WriteLine(ans);
}
}
static public void Main(string[] args) {
if (args.Length == 0) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
Console.Out.Flush();
}
static class Console_ {
static Queue<string> param = new Queue<string>();
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static IEnumerable<long> Primes(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
static IEnumerable<long> Factors(long x) {
if (x < 2)
yield break;
while (x % 2 == 0) {
x /= 2;
yield return 2;
}
var max = (long)Math.Sqrt(x);
for (long i = 3; i <= max; i += 2)
while (x % i == 0) {
x /= i;
yield return i;
}
if (x != 1)
yield return x;
}
static IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
static long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
static long LCM(long a, long b) => a * b / GCD(a, b);
static Mod Pow(Mod x, long y) {
Mod a = 1;
while (y != 0) {
if ((y & 1) == 1)
a.Mul(x);
x.Mul(x);
y >>= 1;
}
return a;
}
static long Pow(long x, long y) {
long a = 1;
while (y != 0) {
if ((y & 1) == 1)
a *= x;
x *= x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>() { 1 };
static void _B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static long Comb(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static long Perm(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) {
Func<TR> t = () => default(TR);
return t = () => f(t);
}
static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) {
Func<T1, TR> t = x1 => default(TR);
return t = x1 => f(x1, t);
}
static Func<T1, T2, TR>
Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) {
Func<T1, T2, TR> t = (x1, x2) => default(TR);
return t = (x1, x2) => f(x1, x2, t);
}
static Func<T1, T2, T3, TR>
Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) {
Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR);
return t = (x1, x2, x3) => f(x1, x2, x3, t);
}
static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>(
Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) {
Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR);
return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t);
}
static List<T> LCS<T>(T[] s, T[] t)
where T : IEquatable<T> {
int sl = s.Length, tl = t.Length;
var dp = new int[sl + 1, tl + 1];
for (var i = 0; i < sl; i++)
for (var j = 0; j < tl; j++)
dp[i + 1, j + 1] =
s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]);
{
var r = new List<T>();
int i = sl, j = tl;
while (i > 0 && j > 0)
if (s[--i].Equals(t[--j]))
r.Add(s[i]);
else if (dp[i, j + 1] > dp[i + 1, j])
++j;
else
++i;
r.Reverse();
return r;
}
}
static long LIS<T>(T[] array, bool strict) {
var l = new List<T>();
foreach (var e in array) {
var i = l.BinarySearch(e);
if (i < 0)
i = ~i;
else if (!strict)
++i;
if (i == l.Count)
l.Add(e);
else
l[i] = e;
}
return l.Count;
}
class PQ<T> {
List<T> h;
Comparison<T> c;
public T Peek => h[0];
public int Count => h.Count;
public PQ(int cap, Comparison<T> c, bool asc = true) {
h = new List<T>(cap);
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(Comparison<T> c, bool asc = true) {
h = new List<T>();
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(int cap, bool asc = true)
: this(cap, Comparer<T>.Default.Compare, asc) {}
public PQ(bool asc = true) : this(Comparer<T>.Default.Compare, asc) {}
public void Push(T v) {
var i = h.Count;
h.Add(v);
while (i > 0) {
var ni = (i - 1) / 2;
if (c(v, h[ni]) >= 0)
break;
h[i] = h[ni];
i = ni;
}
h[i] = v;
}
public T Pop() {
var r = h[0];
var v = h[h.Count - 1];
h.RemoveAt(h.Count - 1);
if (h.Count == 0)
return r;
var i = 0;
while (i * 2 + 1 < h.Count) {
var i1 = i * 2 + 1;
var i2 = i * 2 + 2;
if (i2 < h.Count && c(h[i1], h[i2]) > 0)
i1 = i2;
if (c(v, h[i1]) <= 0)
break;
h[i] = h[i1];
i = i1;
}
h[i] = v;
return r;
}
}
class PQ<TK, TV> {
PQ<Tuple<TK, TV>> q;
public Tuple<TK, TV> Peek => q.Peek;
public int Count => q.Count;
public PQ(int cap, Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(int cap, bool asc = true)
: this(cap, Comparer<TK>.Default.Compare, asc) {}
public PQ(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) {}
public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v));
public Tuple<TK, TV> Pop() => q.Pop();
}
public class UF {
long[] d;
public UF(long s) { d = Repeat(-1L, s).ToArray(); }
public bool Unite(long x, long y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (d[y] < d[x]) {
var t = y;
y = x;
x = t;
}
d[x] += d[y];
d[y] = x;
}
return x != y;
}
public bool IsSame(long x, long y) => Root(x) == Root(y);
public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
public long Count(long x) => -d[Root(x)];
}
struct Mod : IEquatable<Mod>, IEquatable<long> {
static public long _mod = 1000000007;
long v;
public Mod(long x) {
if (x < _mod && x >= 0)
v = x;
else if ((v = x % _mod) < 0)
v += _mod;
}
static public implicit operator Mod(long x) => new Mod(x);
static public implicit operator long(Mod x) => x.v;
public void Add(Mod x) {
if ((v += x.v) >= _mod)
v -= _mod;
}
public void Sub(Mod x) {
if ((v -= x.v) < 0)
v += _mod;
}
public void Mul(Mod x) => v = (v * x.v) % _mod;
public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod;
static public Mod operator +(Mod x, Mod y) {
var t = x.v + y.v;
return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t };
}
static public Mod operator -(Mod x, Mod y) {
var t = x.v - y.v;
return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t };
}
static public Mod operator *(Mod x, Mod y) => x.v * y.v;
static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v);
static public bool operator ==(Mod x, Mod y) => x.v == y.v;
static public bool operator !=(Mod x, Mod y) => x.v != y.v;
static public long Inverse(long x) {
long b = _mod, r = 1, u = 0, t = 0;
while (b > 0) {
var q = x / b;
t = u;
u = r - q * u;
r = t;
t = b;
b = x - q * b;
x = t;
}
return r < 0 ? r + _mod : r;
}
public bool Equals(Mod x) => v == x.v;
public bool Equals(long x) => v == x;
public override bool Equals(object x) => x == null ? false : Equals((Mod)x);
public override int GetHashCode() => v.GetHashCode();
public override string ToString() => v.ToString();
static List<Mod> _fact = new List<Mod>() { 1 };
static void B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static public Mod Comb(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static public Mod Perm(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
}
class Tree {
long N;
int l;
List<long>[] p;
int[] d;
long[][] pr;
long r;
Tuple<long, long, int>[] e;
Tuple<long, long>[] b;
bool lca;
bool euler;
bool bfs;
public Tree(List<long>[] p_, long r_) {
N = p_.Length;
p = p_;
r = r_;
lca = false;
euler = false;
}
public Tuple<long, long>[] BFSRoot() {
if (!bfs) {
var nb = new List<Tuple<long, long>>();
var q = new Queue<long>();
var d = new bool[N];
nb.Add(Tuple.Create(r, -1L));
d[r] = true;
q.Enqueue(r);
while (q.Count > 0) {
var w = q.Dequeue();
foreach (var i in p[w]) {
if (d[i])
continue;
d[i] = true;
q.Enqueue(i);
nb.Add(Tuple.Create(i, w));
}
}
b = nb.ToArray();
bfs = true;
}
return b;
}
public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray();
public Tuple<long, long, int>[] Euler() {
if (!euler) {
var ne = new List<Tuple<long, long, int>>();
var s = new Stack<Tuple<long, long>>();
var d = new bool[N];
d[r] = true;
s.Push(Tuple.Create(r, -1L));
while (s.Count > 0) {
var w = s.Peek();
var ad = true;
foreach (var i in p[w.Item1]) {
if (d[i])
continue;
d[i] = true;
ad = false;
s.Push(Tuple.Create(i, w.Item1));
}
if (!ad || p[w.Item1].Count == 1)
ne.Add(Tuple.Create(w.Item1, w.Item2, 1));
if (ad) {
s.Pop();
ne.Add(Tuple.Create(w.Item1, w.Item2, -1));
}
}
e = ne.ToArray();
euler = true;
}
return e;
}
public long LCA(long u, long v) {
if (!lca) {
l = 0;
while (N > (1 << l))
l++;
d = new int[N];
pr = Repeat(0, l).Select(_ => new long[N]).ToArray();
d[r] = 0;
pr[0][r] = -1;
var q = new Stack<long>();
q.Push(r);
while (q.Count > 0) {
var w = q.Pop();
foreach (var i in p[w]) {
if (i == pr[0][w])
continue;
q.Push(i);
d[i] = d[w] + 1;
pr[0][i] = w;
}
}
for (var k = 0; k + 1 < l; k++)
for (var w = 0; w < N; w++)
if (pr[k][w] < 0)
pr[k + 1][w] = -1;
else
pr[k + 1][w] = pr[k][pr[k][w]];
lca = true;
}
if (d[u] > d[v]) {
var t = u;
u = v;
v = t;
}
for (var k = 0; k < l; k++)
if ((((d[v] - d[u]) >> k) & 1) != 0)
v = pr[k][v];
if (u == v)
return u;
for (var k = l - 1; k >= 0; k--)
if (pr[k][u] != pr[k][v]) {
u = pr[k][u];
v = pr[k][v];
}
return pr[0][u];
}
}
class BT<T>
where T : IComparable {
class Node {
public Node l;
public Node r;
public T v;
public bool b;
public int c;
}
Comparison<T> c;
Node r;
bool ch;
T lm;
public BT(Comparison<T> _c) { c = _c; }
public BT() : this((x, y) => x.CompareTo(y)) {}
bool R(Node n) => n != null && !n.b;
bool B(Node n) => n != null && n.b;
long C(Node n) => n?.c ?? 0;
Node RtL(Node n) {
Node m = n.r, t = m.l;
m.l = n;
n.r = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtR(Node n) {
Node m = n.l, t = m.r;
m.r = n;
n.l = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtLR(Node n) {
n.l = RtL(n.l);
return RtR(n);
}
Node RtRL(Node n) {
n.r = RtR(n.r);
return RtL(n);
}
public void Add(T x) {
r = A(r, x);
r.b = true;
}
Node A(Node n, T x) {
if (n == null) {
ch = true;
return new Node() { v = x, c = 1 };
}
if (c(x, n.v) < 0)
n.l = A(n.l, x);
else
n.r = A(n.r, x);
n.c++;
return Bl(n);
}
Node Bl(Node n) {
if (!ch)
return n;
if (!B(n))
return n;
if (R(n.l) && R(n.l.l)) {
n = RtR(n);
n.l.b = true;
} else if (R(n.l) && R(n.l.r)) {
n = RtLR(n);
n.l.b = true;
} else if (R(n.r) && R(n.r.l)) {
n = RtRL(n);
n.r.b = true;
} else if (R(n.r) && R(n.r.r)) {
n = RtL(n);
n.r.b = true;
} else
ch = false;
return n;
}
public void Remove(T x) {
r = Rm(r, x);
if (r != null)
r.b = true;
}
Node Rm(Node n, T x) {
if (n == null) {
ch = false;
return n;
}
n.c--;
var r = c(x, n.v);
if (r < 0) {
n.l = Rm(n.l, x);
return BlL(n);
}
if (r > 0) {
n.r = Rm(n.r, x);
return BlR(n);
}
if (n.l == null) {
ch = n.b;
return n.r;
}
n.l = RmM(n.l);
n.v = lm;
return BlL(n);
}
Node RmM(Node n) {
n.c--;
if (n.r != null) {
n.r = RmM(n.r);
return BlR(n);
}
lm = n.v;
ch = n.b;
return n.l;
}
Node BlL(Node n) {
if (!ch)
return n;
if (B(n.r) && R(n.r.l)) {
var b = n.b;
n = RtRL(n);
n.b = b;
n.l.b = true;
ch = false;
} else if (B(n.r) && R(n.r.r)) {
var b = n.b;
n = RtL(n);
n.b = b;
n.r.b = true;
n.l.b = true;
ch = false;
} else if (B(n.r)) {
ch = n.b;
n.b = true;
n.r.b = false;
} else {
n = RtL(n);
n.b = true;
n.l.b = false;
n.l = BlL(n.l);
ch = false;
}
return n;
}
Node BlR(Node n) {
if (!ch)
return n;
if (B(n.l) && R(n.l.r)) {
var b = n.b;
n = RtLR(n);
n.b = b;
n.r.b = true;
ch = false;
} else if (B(n.l) && R(n.l.l)) {
var b = n.b;
n = RtR(n);
n.b = b;
n.l.b = true;
n.r.b = true;
ch = false;
} else if (B(n.l)) {
ch = n.b;
n.b = true;
n.l.b = false;
} else {
n = RtR(n);
n.b = true;
n.r.b = false;
n.r = BlR(n.r);
ch = false;
}
return n;
}
public T this[long i] {
get { return At(r, i); }
}
T At(Node n, long i) {
if (n == null)
return default(T);
if (n.l == null)
if (i == 0)
return n.v;
else
return At(n.r, i - 1);
if (n.l.c == i)
return n.v;
if (n.l.c > i)
return At(n.l, i);
return At(n.r, i - n.l.c - 1);
}
public bool Have(T x) {
var t = FindUpper(x);
return t < C(r) && c(At(r, t), x) == 0;
}
public long FindUpper(T x, bool allowSame = true) => allowSame
? FL(r, x) + 1
: FU(r, x);
long FU(Node n, T x) {
if (n == null)
return 0;
var r = c(x, n.v);
if (r < 0)
return FU(n.l, x);
return C(n.l) + 1 + FU(n.r, x);
}
public long FindLower(T x, bool allowSame = true) {
var t = FL(r, x);
if (allowSame)
return t + 1 < C(r) && c(At(r, t + 1), x) == 0 ? t + 1
: t < 0 ? C(r)
: t;
return t < 0 ? C(r) : t;
}
long FL(Node n, T x) {
if (n == null)
return -1;
var r = c(x, n.v);
if (r > 0)
return C(n.l) + 1 + FL(n.r, x);
return FL(n.l, x);
}
public T Min() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.l;
}
return p == null ? default(T) : p.v;
}
public T Max() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.r;
}
return p == null ? default(T) : p.v;
}
public bool Any() => r != null;
public long Count() => C(r);
public IEnumerable<T> List() => L(r);
IEnumerable<T> L(Node n) {
if (n == null)
yield break;
foreach (var i in L(n.l))
yield return i;
yield return n.v;
foreach (var i in L(n.r))
yield return i;
}
}
class Dict<K, V> : Dictionary<K, V> {
Func<K, V> d;
public Dict(Func<K, V> _d) { d = _d; }
public Dict() : this(_ => default(V)) {}
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = d(i);
}
set { base[i] = value; }
}
public override int GetHashCode() {
var ret = 0;
for (var e = GetEnumerator(); e.MoveNext();) {
ret ^= e.Current.Key.GetHashCode();
ret ^= e.Current.Value.GetHashCode();
}
return ret;
}
public override bool Equals(object obj) {
var o = (Dict<K, V>)obj;
foreach (var kv in o) {
if (!ContainsKey(kv.Key) || !this[kv.Key].Equals(kv.Value))
return false;
}
return o.Count == Count;
}
}
class Deque<T> {
T[] b;
int o, c;
public int Count;
public T this[int i] {
get { return b[gi(i)]; }
set { b[gi(i)] = value; }
}
public Deque(int cap = 16) { b = new T[c = cap]; }
int gi(int i) {
if (i >= c)
throw new Exception();
var r = o + i;
return r >= c ? r - c : r;
}
public void PushFront(T x) {
if (Count == c)
e();
if (--o < 0)
o += b.Length;
b[o] = x;
++Count;
}
public T PopFront() {
if (Count-- == 0)
throw new Exception();
var r = b[o++];
if (o >= c)
o -= c;
return r;
}
public T Front => b[o];
public void PushBack(T x) {
if (Count == c)
e();
var i = o + Count++;
b[i >= c ? i - c : i] = x;
}
public T PopBack() {
if (Count == 0)
throw new Exception();
return b[gi(--Count)];
}
public T Back => b[gi(Count - 1)];
void e() {
T[] nb = new T[c << 1];
if (o > c - Count) {
var l = b.Length - o;
Array.Copy(b, o, nb, 0, l);
Array.Copy(b, 0, nb, l, Count - l);
} else
Array.Copy(b, o, nb, 0, Count);
b = nb;
o = 0;
c <<= 1;
}
public void Insert(int i, T x) {
if (i > Count)
throw new Exception();
this.PushFront(x);
for (int j = 0; j < i; j++)
this[j] = this[j + 1];
this[i] = x;
}
public T RemoveAt(int i) {
if (i < 0 || i >= Count)
throw new Exception();
var r = this[i];
for (int j = i; j > 0; j--)
this[j] = this[j - 1];
this.PopFront();
return r;
}
}
class SegTree<T> {
int n;
T ti;
Func<T, T, T> f;
T[] dat;
public SegTree(long _n, T _ti, Func<T, T, T> _f) {
n = 1;
while (n < _n)
n <<= 1;
ti = _ti;
f = _f;
dat = Repeat(ti, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public void Update(long i, T v) {
dat[i += n] = v;
while ((i >>= 1) > 0)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public T Query(long l, long r) {
var vl = ti;
var vr = ti;
for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, dat[li++]);
if ((ri & 1) == 1)
vr = f(dat[--ri], vr);
}
return f(vl, vr);
}
public T this[long idx] {
get { return dat[idx + n]; }
set { Update(idx, value); }
}
}
class LazySegTree<T, E> {
int n, height;
T ti;
E ei;
Func<T, T, T> f;
Func<T, E, T> g;
Func<E, E, E> h;
T[] dat;
E[] laz;
public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g,
Func<E, E, E> _h) {
n = 1;
height = 0;
while (n < _n) {
n <<= 1;
++height;
}
ti = _ti;
ei = _ei;
f = _f;
g = _g;
h = _h;
dat = Repeat(ti, n << 1).ToArray();
laz = Repeat(ei, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f,
Func<T, E, T> _g, Func<E, E, E> _h)
: this(l.Count, _ti, _ei, _f, _g, _h) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]);
void Eval(long i) {
if (laz[i].Equals(ei))
return;
laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]);
laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]);
dat[i] = Reflect(i);
laz[i] = ei;
}
void Thrust(long i) {
for (var j = height; j > 0; j--)
Eval(i >> j);
}
void Recalc(long i) {
while ((i >>= 1) > 0)
dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1));
}
public void Update(long l, long r, E v) {
Thrust(l += n);
Thrust(r += n - 1);
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1) {
laz[li] = h(laz[li], v);
++li;
}
if ((ri & 1) == 1) {
--ri;
laz[ri] = h(laz[ri], v);
}
}
Recalc(l);
Recalc(r);
}
public T Query(long l, long r) {
Thrust(l += n);
Thrust(r += n - 1);
var vl = ti;
var vr = ti;
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, Reflect(li++));
if ((ri & 1) == 1)
vr = f(Reflect(--ri), vr);
}
return f(vl, vr);
}
public T this[long idx] {
get {
Thrust(idx += n);
return dat[idx] = Reflect(idx);
}
set {
Thrust(idx += n);
dat[idx] = value;
laz[idx] = ei;
Recalc(idx);
}
}
}
class SlidingWindowAggregation<T> {
T[][] l;
T[][] a;
int[] n;
Func<T, T, T> f;
public SlidingWindowAggregation(IEnumerable<T> ary, Func<T, T, T> _f) {
l = new T[2][];
a = new T[2][];
n = new int[2];
f = _f;
l[0] = new T[16];
a[0] = new T[16];
n[0] = 0;
if (ary.Any()) {
var t = ary.ToArray();
n[1] = t.Length;
l[1] = new T[n[1]];
a[1] = new T[n[1]];
for (var i = 0; i < l[1].Length; i++) {
l[1][i] = t[i];
if (i == 0)
a[1][i] = t[i];
else
a[1][i] = this.f(a[1][i - 1], t[i]);
}
} else {
l[1] = new T[16];
a[1] = new T[16];
n[1] = 0;
}
}
public SlidingWindowAggregation(Func<T, T, T> f) : this(new T[0], f) {}
public int Count => n[0] + n[1];
void Push(int la, T v) {
if (l[la].Length == n[la]) {
var nar = new T[n[la] * 2];
var nag = new T[n[la] * 2];
Array.Copy(l[la], nar, n[la]);
Array.Copy(a[la], nag, n[la]);
l[la] = nar;
a[la] = nag;
}
if (n[la] == 0)
a[la][0] = v;
else
a[la][n[la]] = la == 0 ? f(v, a[la][n[la] - 1]) : f(a[la][n[la] - 1], v);
l[la][n[la]++] = v;
}
public void PushBack(T val) => Push(1, val);
public void PushFront(T val) => Push(0, val);
public T Pop(int la) {
var lb = 1 - la;
if (n[la] == 0) {
if (n[lb] == 0)
throw new Exception();
var m = (n[lb] - 1) / 2;
if (l[la].Length <= m) {
l[la] = new T[m + 1];
a[la] = new T[m + 1];
}
n[la] = 0;
for (var i = m; i >= 0; i--) {
if (n[la] == 0)
a[la][n[la]] = l[lb][i];
else
a[la][n[la]] = la == 0 ? f(l[lb][i], a[la][n[la] - 1])
: f(a[la][n[la] - 1], l[lb][i]);
l[la][n[la]++] = l[lb][i];
}
for (var i = m + 1; i < n[lb]; i++) {
var j = i - m - 1;
if (j == 0)
a[lb][j] = l[lb][i];
else
a[lb][j] =
la == 0 ? f(l[lb][i], a[lb][j - 1]) : f(a[lb][j - 1], l[lb][i]);
l[lb][j] = l[lb][i];
}
n[lb] -= n[la];
}
return l[la][--n[la]];
}
public T PopBack() => Pop(1);
public T PopFront() => Pop(0);
public T Aggregate() {
if (n[0] == 0 && n[1] == 0)
throw new Exception();
else if (n[1] == 0)
return a[0][n[0] - 1];
else if (n[0] == 0)
return a[1][n[1] - 1];
else
return f(a[0][n[0] - 1], a[1][n[1] - 1]);
}
}
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 204, 206, 207, 0, 28, 0, 214, 205, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 214, 0, 131], ["+", 0, 204, 206, 207, 0, 28, 0, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 9,683
| 10
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace A {
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 s = Console.ReadLine();
var n = s.Length + 1;
var ai = new long[n];
for (var i = 1; i < s.Length; i++) {
if (s[i] == '<')
ai[i + 1] = ai[i] + 1;
}
for (var i = s.Length - 1; i > 0; i--) {
if (s[i] == '>') {
ai[i] = Math.Max(ai[i], ai[i + 1] + 1);
}
}
Console.WriteLine(ai.Sum());
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace A {
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 s = Console.ReadLine();
var n = s.Length + 1;
var ai = new long[n];
for (var i = 0; i < s.Length; i++) {
if (s[i] == '<')
ai[i + 1] = Math.Max(ai[i + 1], ai[i] + 1);
}
for (var i = s.Length - 1; i >= 0; i--) {
if (s[i] == '>')
ai[i] = Math.Max(ai[i], ai[i + 1] + 1);
}
Console.WriteLine(ai.Sum());
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 228
| 18
|
using System;
class ProgramA {
static void Main(string[] args) {
string input = Console.ReadLine();
ulong[] line = new ulong[1000000];
ulong count = 1;
ulong count_line = 0;
ulong sum = 0;
ulong start = 1;
for (int i = 1; i < input.Length; i++) {
if (input[i] == input[i - 1]) {
count++;
} else {
line[count_line] = count;
count = 1;
count_line++;
}
if (i == input.Length - 1) {
line[count_line] = count;
count_line++;
}
}
for (ulong i = 0; i < count_line; i++) {
ulong plus = line[i] - 1;
sum += (plus + 1) * plus / 2;
}
if (input[0] == '>') {
start = 2;
sum += line[0];
}
for (ulong i = start; i <= count_line; i = i + 2) {
if (line[i] > line[i - 1])
sum += line[i];
else
sum += line[i - 1];
}
Console.WriteLine(sum);
}
}
|
using System;
class ProgramA {
static void Main(string[] args) {
string input = Console.ReadLine();
ulong[] line = new ulong[10000000];
ulong count = 1;
ulong count_line = 0;
ulong sum = 0;
ulong start = 1;
if (input.Length == 1) {
Console.WriteLine("1");
return;
}
for (int i = 1; i < input.Length; i++) {
if (input[i] == input[i - 1]) {
count++;
} else {
line[count_line] = count;
count = 1;
count_line++;
}
if (i == input.Length - 1) {
line[count_line] = count;
count_line++;
}
}
for (ulong i = 0; i < count_line; i++) {
ulong plus = line[i] - 1;
sum += (plus + 1) * plus / 2;
}
if (input[0] == '>') {
start = 2;
sum += line[0];
}
for (ulong i = start; i <= count_line; i = i + 2) {
if (line[i] > line[i - 1])
sum += line[i];
else
sum += line[i - 1];
}
Console.WriteLine(sum);
}
}
|
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 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], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 253
| 23
|
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 s = cin.next();
var cc = s.ToCharArray();
var daiCount = 1L;
var syouCount = 0L;
var ans = 0L;
var before = cc[0];
var daiLast = 0L;
for (int i = 1; i < cc.Length; i++) {
var now = cc[i];
if (before == '<' && now == '<') {
syouCount++;
}
if (before == '<' && now == '>') {
daiLast = (syouCount + 1);
ans += (syouCount * (syouCount + 1)) / 2;
syouCount = 0;
}
if (before == '>' && now == '>') {
daiCount++;
}
if (before == '>' && now == '<') {
if (daiLast > daiCount) {
daiCount--;
ans += daiLast;
ans += (daiCount * (daiCount + 1)) / 2;
} else {
ans += (daiCount * (daiCount + 1)) / 2;
}
daiCount = 1;
}
before = now;
}
if (cc[cc.Length - 1] == '<') {
ans++;
} else {
if (daiLast > daiCount) {
daiCount--;
ans += daiLast;
ans += (daiCount * (daiCount + 1)) / 2;
} else {
ans += (daiCount * (daiCount + 1)) / 2;
}
}
Console.WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public 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 s = cin.next();
var cc = s.ToCharArray();
var daiCount = 1L;
var syouCount = 0L;
var ans = 0L;
var before = cc[0];
var daiLast = 0L;
for (int i = 1; i < cc.Length; i++) {
var now = cc[i];
if (before == '<' && now == '<') {
syouCount++;
}
if (before == '<' && now == '>') {
daiLast = (syouCount + 1);
ans += (syouCount * (syouCount + 1)) / 2;
syouCount = 0;
}
if (before == '>' && now == '>') {
daiCount++;
}
if (before == '>' && now == '<') {
if (daiLast > daiCount) {
daiCount--;
ans += daiLast;
ans += (daiCount * (daiCount + 1)) / 2;
} else {
ans += (daiCount * (daiCount + 1)) / 2;
}
daiCount = 1;
}
before = now;
}
if (cc[cc.Length - 1] == '<') {
syouCount++;
ans += (syouCount * (syouCount + 1)) / 2;
} else {
if (daiLast > daiCount) {
daiCount--;
ans += daiLast;
ans += (daiCount * (daiCount + 1)) / 2;
} else {
ans += (daiCount * (daiCount + 1)) / 2;
}
}
Console.WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public 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, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 48], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 837
| 16
|
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) {
////整数の入力
// int a = int.Parse(Console.ReadLine());
////スペース区切りの整数の入力
// string[] input = Console.ReadLine().Split(' ');
// int b = int.Parse(input[0]);
// int c = int.Parse(input[1]);
////文字列の入力
// string s = Console.ReadLine();
////出力
// Console.WriteLine((a + b + c) + " " + s);
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int ans = a * b;
if (((a >= 1 && a <= 9)) || ((b >= 1 && b <= 9))) {
Console.WriteLine(ans);
} else {
Console.WriteLine(-1);
}
}
}
}
|
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[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int ans = a * b;
if (a >= 10 || b >= 10) {
Console.WriteLine(-1);
} else {
Console.WriteLine(ans);
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["-", 0, 57, 15, 16, 31, 23, 0, 23, 0, 24], ["-", 31, 23, 0, 23, 0, 16, 31, 16, 12, 203], ["-", 15, 16, 31, 23, 0, 23, 0, 16, 17, 98], ["-", 31, 23, 0, 23, 0, 16, 12, 16, 31, 22], ["-", 31, 23, 0, 23, 0, 16, 12, 16, 17, 19], ["-", 31, 23, 0, 23, 0, 16, 12, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 23, 0, 23, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["-", 0, 57, 15, 16, 12, 23, 0, 23, 0, 24], ["-", 12, 23, 0, 23, 0, 16, 31, 16, 12, 203], ["-", 15, 16, 12, 23, 0, 23, 0, 16, 17, 98], ["-", 12, 23, 0, 23, 0, 16, 12, 16, 31, 22], ["-", 12, 23, 0, 23, 0, 16, 12, 16, 17, 19], ["-", 12, 23, 0, 23, 0, 16, 12, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 23, 0, 23, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 153
| 26
|
using System;
namespace AtCoder {
class Program {
static void Main(string[] args) {
// 整数の入力
// int a = int.Parse(Console.ReadLine());
// スペース区切りの整数の入力
string[] input = Console.ReadLine().Split(' ');
int b = int.Parse(input[0]);
int c = int.Parse(input[1]);
// 文字列の入力
// string s = Console.ReadLine();
int seki = b * c;
if (seki <= 81)
Console.WriteLine(seki);
else {
Console.WriteLine(-1);
}
}
}
}
|
using System;
namespace AtCoder {
class Program {
static void Main(string[] args) {
// 整数の入力
// int a = int.Parse(Console.ReadLine());
// スペース区切りの整数の入力
string[] input = Console.ReadLine().Split(' ');
int b = int.Parse(input[0]);
int c = int.Parse(input[1]);
// 文字列の入力
// string s = Console.ReadLine();
if (b <= 9 && c <= 9)
Console.WriteLine(b * c);
else {
Console.WriteLine(-1);
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 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, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 102
| 19
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
const int MOD = 1000000007;
const int INF = 1 << 30;
static void Main(string[] args) { Solve(); }
static void Solve() {
Scaner cin = new Scaner();
write cout = new write();
Math2 mmath = new Math2();
//ここから
var o = cin.IntM;
int N = o[0];
int W = o[1];
if (N > 10 || W > 10)
cout.wri(-1);
else
cout.wri(N * W);
}
}
// b-aで降順
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
public class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
// Nまでの階乗をセットしておく
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = pow(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
// nCr 引数:n r (mod)
public long nCr(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
//階乗(O(logN)) 引数:底x n乗 (MOD)
public long pow(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
//最大公約数 引数:整数x,y
public long GCD(long x, long y) {
while (y != 0) {
var r = x % y;
x = y;
y = r;
}
return x;
}
//最小公倍数 引数:整数x,y
public long LCM(long x, long y) { return x * y / GCD(x, y); }
//素因数分解 引数:整数N
public Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
}
namespace CompLib.Algorithms {
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrM => Str.Split(' ');
public long[] LongM => StrM.Select(long.Parse).ToArray();
public int[] IntM => StrM.Select(int.Parse).ToArray();
public char[] CharM => Str.ToArray();
public long Long1 => LongM[0];
public int Int1 => IntM[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
const int MOD = 1000000007;
const int INF = 1 << 30;
static void Main(string[] args) { Solve(); }
static void Solve() {
Scaner cin = new Scaner();
write cout = new write();
Math2 mmath = new Math2();
//ここから
var o = cin.LongM;
var A = o[0];
var B = o[1];
if (A >= 10 || B >= 10)
cout.wri("-1");
else
cout.wri(A * B);
}
}
// b-aで降順
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
public class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
// Nまでの階乗をセットしておく
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = pow(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
// nCr 引数:n r (mod)
public long nCr(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
//階乗(O(logN)) 引数:底x n乗 (MOD)
public long pow(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
//最大公約数 引数:整数x,y
public long GCD(long x, long y) {
while (y != 0) {
var r = x % y;
x = y;
y = r;
}
return x;
}
//最小公倍数 引数:整数x,y
public long LCM(long x, long y) { return x * y / GCD(x, y); }
//素因数分解 引数:整数N
public Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
}
namespace CompLib.Algorithms {
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrM => Str.Split(' ');
public long[] LongM => StrM.Select(long.Parse).ToArray();
public int[] IntM => StrM.Select(int.Parse).ToArray();
public char[] CharM => Str.ToArray();
public long Long1 => LongM[0];
public int Int1 => IntM[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 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], ["-", 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, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 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, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 1,391
| 27
|
using System;
using System.Collections.Generic;
using System.Linq;
public static class Program {
public static void Main(string[] args) {
var inputs = Console.ReadLine().Split(' ');
var a = int.Parse(inputs[0]);
var b = int.Parse(inputs[1]);
if (a < 10 && b < 10) {
Console.WriteLine("-1");
}
{ Console.WriteLine(a * b); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public static class Program {
public static void Main(string[] args) {
var inputs = Console.ReadLine().Split(' ');
var a = int.Parse(inputs[0]);
var b = int.Parse(inputs[1]);
if (a < 10 && b < 10) {
Console.WriteLine(a * b);
} else {
Console.WriteLine("-1");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 107
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC143D {
class Program {
static int ans = 0;
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] Linput = Console.ReadLine().Split(' ');
int[] L = new int[N];
for (int i = 0; i < N; i++) {
L[i] = int.Parse(Linput[i]);
}
Array.Sort(L);
// Console.WriteLine(string.Join(" ",L));
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
nibun(j + 1, N - 1, L, L[i] + L[j], j);
// Console.WriteLine(ans);
}
// Console.WriteLine(ans);
}
Console.WriteLine(ans);
}
static void nibun(int min, int max, int[] L, int ab, int j) {
int center = (min + max) / 2;
if (min == center) {
if (L[min] == ab) {
ans += min - j - 1;
} else if (L[min] < ab) {
if (L[max] < ab && min != max) {
ans += max - j;
} else {
ans += min - j;
}
}
return;
} else {
if (L[center] <= ab) {
nibun(center, max, L, ab, j);
} else {
nibun(min, center, L, ab, j);
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC143D {
class Program {
static int ans = 0;
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] Linput = Console.ReadLine().Split(' ');
int[] L = new int[N];
for (int i = 0; i < N; i++) {
L[i] = int.Parse(Linput[i]);
}
Array.Sort(L);
// Console.WriteLine(string.Join(" ",L));
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
nibun(j + 1, N - 1, L, L[i] + L[j], j);
// Console.WriteLine(ans);
}
// Console.WriteLine(ans);
}
Console.WriteLine(ans);
}
static void nibun(int min, int max, int[] L, int ab, int j) {
int center = (min + max) / 2;
if (min == center) {
if (L[min] == ab) {
while (L[min] == L[min - 1] && min > j) {
min -= 1;
}
ans += min - j - 1;
// Console.WriteLine("a");
// Console.WriteLine(ans);
} else if (L[min] < ab) {
//
if (L[max] >= ab) {
ans += min - j;
// Console.WriteLine("b");
// Console.WriteLine(ans);
} else {
ans += max - j;
// Console.WriteLine("c");
// Console.WriteLine(ans);
}
}
return;
} else {
if (L[center] <= ab) {
nibun(center, max, L, ab, j);
} else {
nibun(min, center, L, ab, j);
}
}
}
}
}
|
[["+", 64, 196, 0, 57, 64, 196, 0, 52, 0, 89], ["+", 64, 196, 0, 57, 64, 196, 0, 52, 0, 24], ["+", 0, 52, 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, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 52, 15, 16, 31, 16, 17, 60], ["+", 0, 52, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 196, 0, 52, 15, 16, 17, 98], ["+", 64, 196, 0, 52, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 52, 15, 16, 12, 16, 17, 47], ["+", 64, 196, 0, 52, 15, 16, 12, 16, 12, 22], ["+", 64, 196, 0, 57, 64, 196, 0, 52, 0, 25], ["+", 0, 57, 64, 196, 0, 52, 8, 196, 0, 45], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 64, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 52, 8, 196, 0, 46], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 17, 20], ["-", 75, 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, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22]]
| 8
| 354
| 34
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var A = sc.ReadIntArray(N);
Array.Sort(A);
long ans = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
var l = A.LowerBound(A[j] + 1);
var r = A.LowerBound(A[i] + A[j]);
ans += Math.Max(0, r - l);
}
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public 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;
}
}
static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var A = sc.ReadIntArray(N);
Array.Sort(A);
long ans = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (j + 1 == N)
break;
var l = j + 1;
var r = A.LowerBound(A[i] + A[j]);
ans += Math.Max(0, r - l);
}
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public 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;
}
}
static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 939
| 18
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var n = cin.nextInt();
var a = cin.ArrayLong(n);
Array.Sort(a);
var ans = 0L;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
var aa = a[i];
var bb = a[j];
ans += C.LowerBound(a, aa + bb) - (j + 1);
}
}
Console.WriteLine(ans);
}
}
static class C {
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long UpperBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] < key)
l = mid + 1;
else
r = mid;
}
return l;
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var n = cin.nextInt();
var l = cin.ArrayLong(n);
Array.Sort(l);
var ans = 0L;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
var aa = l[i];
var bb = l[j];
var r = C.LowerBound(l, aa + bb - 1);
ans += r - j - 1;
}
}
Console.WriteLine(ans);
}
}
static class C {
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long UpperBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] < key)
l = mid + 1;
else
r = mid;
}
return l;
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 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], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 12, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 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, 107], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
| 8
| 801
| 25
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using System.Numerics;
using static System.Math;
using Number = System.Int32;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var a = Enumerate(n, x => ri);
Array.Sort(a);
var ans = 1L * n * (n - 1) * (n - 2) / 6;
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) {
var u = a[i] + a[j];
Debug.WriteLine($"{a[i]} {a[j]} {n - a.LowerBound(u)}");
ans -= n - a.UpperBound(u);
}
Console.WriteLine(ans);
}
const long INF = 1L << 60;
static int[] dx = { -1, 0, 1, 0 };
static int[] dy = { 0, 1, 0, -1 };
int ri {
get { return sc.Integer(); }
}
long rl {
get { return sc.Long(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public IO.StreamScanner sc =
new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < a.Length; ++i)
a[i] = f(i);
return a;
}
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
}
}
#region main
static class Ex {
static public string AsString(this IEnumerable<char> ie) {
return new string(ie.ToArray());
}
static public string AsJoinedString<T>(this IEnumerable<T> ie,
string st = " ") {
return string.Join(st, ie);
}
static public void Main() {
Console.SetOut(new Program.IO.Printer(
Console.OpenStandardOutput()) { AutoFlush = true });
var solver = new Program.Solver();
/*
var t = new System.Threading.Thread(solver.Solve, 50000000);
t.Start();
t.Join();
//*/
solver.Solve();
Console.Out.Flush();
}
}
#endregion
#region Ex
namespace Program.IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
}
#endregion
#region ModInt
/// <summary>
/// [0,<see cref="Mod"/>) までの値を取るような数
/// </summary>
public struct ModInt {
/// <summary>
/// 剰余を取る値.
/// </summary>
public const long Mod = (int)1e9 + 7;
/// <summary>
/// 実際の数値.
/// </summary>
public long num;
/// <summary>
/// 値が <paramref name="n"/> であるようなインスタンスを構築します.
/// </summary>
/// <param name="n">インスタンスが持つ値</param>
/// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref
/// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/>
/// を渡してください.このコンストラクタは O(1) で実行されます.</remarks>
public ModInt(long n) { num = n; }
/// <summary>
/// このインスタンスの数値を文字列に変換します.
/// </summary>
/// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10
/// 進表記したもの.</returns>
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
/// <summary>
/// 与えられた 2 つの数値からべき剰余を計算します.
/// </summary>
/// <param name="v">べき乗の底</param>
/// <param name="k">べき指数</param>
/// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns>
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
/// <summary>
/// 与えられた 2 つの数値からべき剰余を計算します.
/// </summary>
/// <param name="v">べき乗の底</param>
/// <param name="k">べき指数</param>
/// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns>
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
/// <summary>
/// 与えられた数の逆元を計算します.
/// </summary>
/// <param name="v">逆元を取る対象となる数</param>
/// <returns>逆元となるような値</returns>
/// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を
/// O(log N) で計算します.</remarks>
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
#region Binomial Coefficient
public class BinomialCoefficient {
public ModInt[] fact, ifact;
public BinomialCoefficient(int n) {
fact = new ModInt[n + 1];
ifact = new ModInt[n + 1];
fact[0] = 1;
for (int i = 1; i <= n; i++)
fact[i] = fact[i - 1] * i;
ifact[n] = ModInt.Inverse(fact[n]);
for (int i = n - 1; i >= 0; i--)
ifact[i] = ifact[i + 1] * (i + 1);
ifact[0] = ifact[1];
}
public ModInt this[int n, int r] {
get {
if (n < 0 || n >= fact.Length || r < 0 || r > n)
return 0;
return fact[n] * ifact[n - r] * ifact[r];
}
}
public ModInt RepeatedCombination(int n, int k) {
if (k == 0)
return 1;
return this[n + k - 1, k];
}
}
#endregion
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using System.Numerics;
using static System.Math;
using Number = System.Int32;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var a = Enumerate(n, x => ri);
Array.Sort(a);
var ans = 0L;
Debug.WriteLine(a.AsJoinedString());
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) {
var u = a[i] + a[j];
Debug.WriteLine($"{a[i]} {a[j]} { a.LowerBound(u) - j - 1}");
ans += a.LowerBound(u) - j - 1;
}
Console.WriteLine(ans);
}
const long INF = 1L << 60;
static int[] dx = { -1, 0, 1, 0 };
static int[] dy = { 0, 1, 0, -1 };
int ri {
get { return sc.Integer(); }
}
long rl {
get { return sc.Long(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public IO.StreamScanner sc =
new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < a.Length; ++i)
a[i] = f(i);
return a;
}
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
}
}
#region main
static class Ex {
static public string AsString(this IEnumerable<char> ie) {
return new string(ie.ToArray());
}
static public string AsJoinedString<T>(this IEnumerable<T> ie,
string st = " ") {
return string.Join(st, ie);
}
static public void Main() {
Console.SetOut(new Program.IO.Printer(
Console.OpenStandardOutput()) { AutoFlush = true });
var solver = new Program.Solver();
/*
var t = new System.Threading.Thread(solver.Solve, 50000000);
t.Start();
t.Join();
//*/
solver.Solve();
Console.Out.Flush();
}
}
#endregion
#region Ex
namespace Program.IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
}
#endregion
#region ModInt
/// <summary>
/// [0,<see cref="Mod"/>) までの値を取るような数
/// </summary>
public struct ModInt {
/// <summary>
/// 剰余を取る値.
/// </summary>
public const long Mod = (int)1e9 + 7;
/// <summary>
/// 実際の数値.
/// </summary>
public long num;
/// <summary>
/// 値が <paramref name="n"/> であるようなインスタンスを構築します.
/// </summary>
/// <param name="n">インスタンスが持つ値</param>
/// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref
/// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/>
/// を渡してください.このコンストラクタは O(1) で実行されます.</remarks>
public ModInt(long n) { num = n; }
/// <summary>
/// このインスタンスの数値を文字列に変換します.
/// </summary>
/// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10
/// 進表記したもの.</returns>
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
/// <summary>
/// 与えられた 2 つの数値からべき剰余を計算します.
/// </summary>
/// <param name="v">べき乗の底</param>
/// <param name="k">べき指数</param>
/// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns>
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
/// <summary>
/// 与えられた 2 つの数値からべき剰余を計算します.
/// </summary>
/// <param name="v">べき乗の底</param>
/// <param name="k">べき指数</param>
/// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns>
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
/// <summary>
/// 与えられた数の逆元を計算します.
/// </summary>
/// <param name="v">逆元を取る対象となる数</param>
/// <returns>逆元となるような値</returns>
/// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を
/// O(log N) で計算します.</remarks>
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
#region Binomial Coefficient
public class BinomialCoefficient {
public ModInt[] fact, ifact;
public BinomialCoefficient(int n) {
fact = new ModInt[n + 1];
ifact = new ModInt[n + 1];
fact[0] = 1;
for (int i = 1; i <= n; i++)
fact[i] = fact[i - 1] * i;
ifact[n] = ModInt.Inverse(fact[n]);
for (int i = n - 1; i >= 0; i--)
ifact[i] = ifact[i + 1] * (i + 1);
ifact[0] = ifact[1];
}
public ModInt this[int n, int r] {
get {
if (n < 0 || n >= fact.Length || r < 0 || r > n)
return 0;
return fact[n] * ifact[n - r] * ifact[r];
}
}
public ModInt RepeatedCombination(int n, int k) {
if (k == 0)
return 1;
return this[n + k - 1, k];
}
}
#endregion
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
|
[["-", 0, 16, 31, 16, 31, 16, 31, 16, 31, 203], ["-", 0, 16, 31, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 212, 0, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 31, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["-", 31, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["-", 31, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 16, 31, 16, 31, 16, 12, 23, 0, 25], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["+", 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], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 31, 22], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 17, 33], ["+", 0, 283, 0, 284, 0, 16, 31, 16, 17, 33], ["+", 0, 283, 0, 284, 0, 16, 31, 16, 12, 22], ["+", 0, 28, 0, 283, 0, 284, 0, 16, 17, 33], ["+", 0, 28, 0, 283, 0, 284, 0, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 11, 12, 16, 12, 213, 63, 214, 141, 22], ["+", 12, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 1,879
| 39
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder {
public class ABC {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
int n = int.Parse(Console.ReadLine());
int[] l =
Console.ReadLine().Split().Select(int.Parse).OrderBy(p => p).ToArray();
long ans = 0;
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
if (l[j + 1] < l[i] + l[j]) {
int index = Array.BinarySearch(l, j + 1, n - (j + 1), l[i] + l[j]);
if (index < 0) {
index = ~index;
}
ans += index - (j + 1);
}
// for (int k = j + 1; k < n; k++) {
// if (l[k] < l[i] + l[j]) {
// ans++;
// } else {
// break;
// }
//}
}
}
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder {
public class ABC {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
int n = int.Parse(Console.ReadLine());
int[] l =
Console.ReadLine().Split().Select(int.Parse).OrderBy(p => p).ToArray();
long ans = 0;
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
if (l[j + 1] < l[i] + l[j]) {
int index = Array.BinarySearch(l, j + 1, n - (j + 1), l[i] + l[j]);
if (index > 0) {
while (l[index - 1] == l[index]) {
index--;
}
} else {
index = ~index;
}
ans += index - (j + 1);
}
// int cnt = 0;
// for (int k = j + 1; k < n; k++) {
// if (l[k] < l[i] + l[j]) {
// cnt++;
// } else {
// break;
// }
//}
// System.Diagnostics.Debug.WriteLine($"{i} {j} {cnt}");
// ans += cnt;
}
}
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
|
[["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 57, 64, 196, 0, 52, 0, 89], ["+", 64, 196, 0, 57, 64, 196, 0, 52, 0, 24], ["+", 64, 196, 0, 52, 15, 16, 31, 204, 205, 22], ["+", 0, 52, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 52, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 196, 0, 52, 15, 16, 17, 60], ["+", 64, 196, 0, 52, 15, 16, 12, 204, 205, 22], ["+", 0, 52, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 52, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 196, 0, 52, 8, 196, 0, 45], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68], ["+", 64, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 52, 8, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95]]
| 8
| 260
| 24
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ABC143 {
class D {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
var L =
Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
var indexMax = 0;
var count = 0;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
indexMax = Array.BinarySearch(L, L[i] + L[j]);
if (indexMax < 0)
indexMax = ~indexMax;
count += indexMax - (j + 1);
}
}
Console.WriteLine(count);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ABC143 {
class D {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var L =
Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();
var indexMax = 0;
var count = 0;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
indexMax = Array.BinarySearch(L, L[i] + L[j]);
if (indexMax < 0)
indexMax = ~indexMax;
else {
while (L[indexMax] == L[indexMax - 1])
indexMax--;
}
count += indexMax - (j + 1);
/*
for (int k = N - 1; j < k; k--)
{
if (L[k] < L[i] + L[j])
{
count += k - j;
break;
}
}
*/
}
}
Console.WriteLine(count);
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 57, 64, 1, 0, 11, 12, 241, 0, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 52, 0, 89], ["+", 8, 196, 0, 57, 75, 196, 0, 52, 0, 24], ["+", 75, 196, 0, 52, 15, 16, 31, 204, 205, 22], ["+", 0, 52, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 52, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 196, 0, 52, 15, 16, 17, 60], ["+", 75, 196, 0, 52, 15, 16, 12, 204, 205, 22], ["+", 0, 52, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 52, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 196, 0, 52, 0, 25], ["+", 75, 196, 0, 52, 8, 1, 0, 223, 0, 22], ["+", 75, 196, 0, 52, 8, 1, 0, 223, 0, 68], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 174
| 24
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Procon {
static void Main(string[] agrs) {
int N = Int();
int[] L = Ints();
Array.Sort(L);
long ret = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
int index2 = BinarySearch(L, L[i] + L[j]);
int max = index2 - 1;
int min = Math.Max(i, j);
if (max - min > 0) {
ret += max - min;
}
}
}
Console.WriteLine(ret);
}
static int BinarySearch(int[] a, int b) {
int index = Array.BinarySearch(a, b);
if (index < 0) {
return ~index;
}
return index;
}
static string String() => Scanner.nextString();
static int Int() => int.Parse(Scanner.nextString());
static long Long() => long.Parse(Scanner.nextString());
static double Double() => double.Parse(Scanner.nextString());
static char[] Chars() => String().ToCharArray();
static string[] Strings() => Console.ReadLine().Split(' ');
static int[] Ints() => Strings().Select(v => int.Parse(v)).ToArray();
static long[] Longs() => Strings().Select(v => long.Parse(v)).ToArray();
static double[] Doubles() => Strings().Select(v => double.Parse(v)).ToArray();
const int M = 1000000007;
}
class PriorityQueue<T>
where T : IComparable<T> {
public T[] heap;
public int size;
public int sign;
public PriorityQueue(int N, bool descend = false) {
heap = new T[N];
sign = 1;
if (descend)
sign = -1;
}
public int Compare(T x, T y) { return x.CompareTo(y) * sign; }
public void Push(T x) {
int i = size++;
while (i > 0) {
int p = (i - 1) / 2;
if (Compare(x, heap[p]) >= 0) {
break;
}
heap[i] = heap[p];
i = p;
}
heap[i] = x;
}
public T Pop() {
T ret = heap[0];
T x = heap[--size];
int i = 0;
while (i * 2 + 1 < size) {
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < size && Compare(heap[a], heap[b]) > 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 size; }
}
class Scanner {
static string[] s = new string[0];
static int i = 0;
static int max_i = 0;
static public string nextString() {
if (i >= s.Length) {
s = Console.ReadLine().Split(' ');
max_i = s.Length;
i = 0;
if (max_i == 0) {
return "";
}
return s[i++];
}
return s[i++];
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Procon {
static void Main(string[] agrs) {
int N = Int();
int[] L = Ints();
Array.Sort(L);
long ret = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
int max = BinarySearch(L, L[i] + L[j]);
int min = Math.Max(i, j);
if (max - min - 1 > 0) {
ret += max - min - 1;
}
}
}
Console.WriteLine(ret);
}
static int BinarySearch(int[] a, int b) {
int index = Array.BinarySearch(a, b);
if (index < 0) {
return ~index;
}
int tmp = a[index];
while (tmp == a[index - 1]) {
index--;
}
return index;
}
static string String() => Scanner.nextString();
static int Int() => int.Parse(Scanner.nextString());
static long Long() => long.Parse(Scanner.nextString());
static double Double() => double.Parse(Scanner.nextString());
static char[] Chars() => String().ToCharArray();
static string[] Strings() => Console.ReadLine().Split(' ');
static int[] Ints() => Strings().Select(v => int.Parse(v)).ToArray();
static long[] Longs() => Strings().Select(v => long.Parse(v)).ToArray();
static double[] Doubles() => Strings().Select(v => double.Parse(v)).ToArray();
const int M = 1000000007;
}
class PriorityQueue<T>
where T : IComparable<T> {
public T[] heap;
public int size;
public int sign;
public PriorityQueue(int N, bool descend = false) {
heap = new T[N];
sign = 1;
if (descend)
sign = -1;
}
public int Compare(T x, T y) { return x.CompareTo(y) * sign; }
public void Push(T x) {
int i = size++;
while (i > 0) {
int p = (i - 1) / 2;
if (Compare(x, heap[p]) >= 0) {
break;
}
heap[i] = heap[p];
i = p;
}
heap[i] = x;
}
public T Pop() {
T ret = heap[0];
T x = heap[--size];
int i = 0;
while (i * 2 + 1 < size) {
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < size && Compare(heap[a], heap[b]) > 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 size; }
}
class Scanner {
static string[] s = new string[0];
static int i = 0;
static int max_i = 0;
static public string nextString() {
if (i >= s.Length) {
s = Console.ReadLine().Split(' ');
max_i = s.Length;
i = 0;
if (max_i == 0) {
return "";
}
return s[i++];
}
return s[i++];
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 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, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 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, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 60], ["+", 8, 196, 0, 52, 15, 16, 12, 204, 205, 22], ["+", 0, 52, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 52, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68]]
| 8
| 797
| 37
|
using System;
using System.Linq;
class Assignment {
static void Main() {
var N = int.Parse(Console.ReadLine().Trim());
var L = Console.ReadLine()
.Trim()
.Split(' ')
.Select(x => int.Parse(x.Trim()))
.Distinct()
.ToArray();
N = L.Length;
var answer = 0;
//ソート
Array.Sort(L);
// Console.WriteLine(string.Join(" ", L));
for (var i = 0; i < N - 2; i++) {
for (var j = i + 1; j < N - 1; j++) {
/*
if(L[j] == L[i]) {
continue;
}
*/
for (var k = j + 1; k < N; k++) {
// Console.WriteLine(i + ", " + j + ", " + k + ", " + answer);
if (L[i] + L[j] > L[k]) {
answer++;
} else {
break;
}
}
}
}
Console.WriteLine(answer);
}
}
|
using System;
using System.Linq;
class Assignment {
static void Main() {
var N = int.Parse(Console.ReadLine().Trim());
var L = Console.ReadLine()
.Trim()
.Split(' ')
.Select(x => int.Parse(x.Trim()))
.ToArray();
// N = L.Length;
var answer = 0;
// var prev_i = 0;
//ソート
Array.Sort(L);
// Console.WriteLine(string.Join(" ", L));
for (var i = 0; i < N - 2; i++) {
/*
var prev_j = 0;
if(L[i] == prev_i) {
continue;
}
*/
for (var j = i + 1; j < N - 1; j++) {
/*
var prev_k = 0;
if(L[j] == prev_j) {
continue;
}
*/
/*
if(L[j] == L[i]) {
continue;
}
*/
for (var k = N - 1; k > j; k--) {
if (L[i] + L[j] > L[k]) {
answer += k - j;
break;
}
}
/*
for(var k = j + 1; k < N; k++) {
//Console.WriteLine(i + ", " + j + ", " + k + ", " + answer);
if(L[i] + L[j] > L[k]) {
answer++;
} else {
break;
}
}
*/
}
}
Console.WriteLine(answer);
}
}
|
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 68], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45]]
| 8
| 193
| 28
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
// var s = Console.ReadLine();
var l = Console.ReadLine()
.Split(' ')
.Select(int.Parse)
.OrderBy(x => -x)
.ToArray();
var ans = 0;
for (int i = 0; i < l.Length - 2; i++) {
for (int j = i + 1; j < l.Length - 1; j++) {
for (int k = j + 1; k < l.Length; k++) {
if (l[i] < l[j] + l[k] && l[j] < l[k] + l[i] && l[k] < l[i] + l[j]) {
ans += l.Length - k;
break;
}
}
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
// var s = Console.ReadLine();
var l = Console.ReadLine()
.Split(' ')
.Select(int.Parse)
.OrderBy(x => -x)
.ToArray();
var ans = 0;
for (int i = 0; i < l.Length - 2; i++) {
for (int j = i + 1; j < l.Length - 1; j++) {
for (int k = l.Length - 1; k > j; k--) {
if (l[i] < l[j] + l[k] && l[j] < l[k] + l[i] && l[k] < l[i] + l[j]) {
ans += k - j;
break;
}
}
}
}
Console.WriteLine(ans);
}
}
|
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 68], ["-", 0, 1, 0, 11, 12, 16, 31, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 16, 31, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 218
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Text;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
var solver = new Solver(sw);
// var t = new Thread(solver.solve, 1 << 26); // 64 MB
// t.Start();
// t.Join();
solver.solve();
sw.Flush();
}
}
class Solver {
StreamWriter sw;
Scan sc;
void Prt(string a) => sw.WriteLine(a);
void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
void Prt(params object[] a) => Prt(string.Join(" ", a));
public Solver(StreamWriter sw) {
this.sw = sw;
this.sc = new Scan();
}
public void solve() {
int n, m, l;
sc.Multi(out n, out m, out l);
var edge = new List<P>[n];
for (int i = 0; i < n; i++) {
edge[i] = new List<P>();
}
for (int i = 0; i < m; i++) {
int u, v, c;
sc.Multi(out u, out v, out c);
--u;
--v;
if (c <= l) {
edge[u].Add(new P(c, v));
edge[v].Add(new P(c, u));
}
}
var dist = new P[n][];
for (int i = 0; i < n; i++) {
dist[i] = new P[n];
for (int j = 0; j < n; j++) {
dist[i][j] = new P(M, -1);
}
dist[i][i] = new P(0, l);
var vis = new bool[n];
Func<P, P, int> cmp = (x, y) =>
x.v1 != y.v1 ? x.v1.CompareTo(y.v1) : y.v2.CompareTo(x.v2);
int now = i;
vis[now] = true;
while (now != -1) {
foreach (var item in edge[now]) {
P nex;
if (dist[i][now].v2 >= item.v1) {
nex = new P(dist[i][now].v1, dist[i][now].v2 - item.v1);
} else {
nex = new P(dist[i][now].v1 + 1, l - item.v1);
}
if (cmp(nex, dist[i][item.v2]) < 0) {
dist[i][item.v2] = nex;
}
}
var min = new P(M, -1);
int mik = -1;
for (int k = 0; k < n; k++) {
if (!vis[k] && cmp(dist[i][k], min) < 0) {
min = dist[i][k];
mik = k;
}
}
now = mik;
vis[mik] = true;
}
}
int que = sc.Int;
for (int i = 0; i < que; i++) {
int u, v;
sc.Multi(out u, out v);
--u;
--v;
Prt(dist[u][v].v1 == M ? -1 : dist[u][v].v1);
}
}
}
class pair<T, U> : IComparable<pair<T, U>> {
public T v1;
public U v2;
public pair() : this(default(T), default(U)) {}
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) {
int c = Comparer<T>.Default.Compare(v1, a.v1);
return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2);
}
public override string ToString() => v1 + " " + v2;
public void Deconstruct(out T a, out U b) {
a = v1;
b = v2;
}
}
static class util {
public static readonly int M = 1000000007;
// public static readonly int M = 998244353;
public static readonly long LM = 1L << 60;
public static readonly double eps = 1e-11;
public static void DBG(string a) => Console.Error.WriteLine(a);
public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
public static void DBG(params object[] a) => DBG(string.Join(" ", a));
public static void Assert(bool cond) {
if (!cond)
throw new Exception();
}
public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1,
v2);
public static int CompareList<T>(IList<T> a, IList<T> b)
where T : IComparable<T> {
for (int i = 0; i < a.Count && i < b.Count; i++)
if (a[i].CompareTo(b[i]) != 0)
return a[i].CompareTo(b[i]);
return a.Count.CompareTo(b.Count);
}
public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h
&& j >= 0 && j < w;
static readonly int[] dd = { 0, 1, 0, -1 };
// static readonly string dstring = "RDLU";
public static P[] adjacents(int i,
int j) => Enumerable.Range(0, dd.Length)
.Select(k => new P(i + dd[k],
j + dd[k ^ 1]))
.ToArray();
public static P[] adjacents(int i, int j, int h, int w) =>
Enumerable.Range(0, dd.Length)
.Select(k => new P(i + dd[k], j + dd[k ^ 1]))
.Where(p => inside(p.v1, p.v2, h, w))
.ToArray();
public static P[] adjacents(this P p) => adjacents(p.v1, p.v2);
public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2,
h, w);
public static Dictionary<T, int>
compress<T>(this IEnumerable<T> a) => a.Distinct()
.OrderBy(v => v)
.Select((v, i) => new { v, i })
.ToDictionary(p => p.v, p => p.i);
public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) =>
compress(a.Aggregate(Enumerable.Union));
public static T[] inv<T>(this Dictionary<T, int> dic) {
var res = new T[dic.Count];
foreach (var item in dic)
res[item.Value] = item.Key;
return res;
}
public static void swap<T>(ref T a, ref T b)
where T : struct {
var t = a;
a = b;
b = t;
}
public static void swap<T>(this IList<T> a, int i, int j)
where T : struct {
var t = a[i];
a[i] = a[j];
a[j] = t;
}
public static T[] copy<T>(this IList<T> a) {
var ret = new T[a.Count];
for (int i = 0; i < a.Count; i++)
ret[i] = a[i];
return ret;
}
}
class Scan {
StreamReader sr;
public Scan() { sr = new StreamReader(Console.OpenStandardInput()); }
public Scan(string path) { sr = new StreamReader(path); }
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => sr.ReadLine().Trim();
public pair<T, U> Pair<T, U>() {
T a;
U b;
Multi(out a, out b);
return new pair<T, U>(a, b);
}
public P P => Pair<int, int>();
public int[] IntArr => StrArr.Select(int.Parse).ToArray();
public long[] LongArr => StrArr.Select(long.Parse).ToArray();
public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
public string[] StrArr =>
Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public void Multi<T>(out T a) => a = cv<T>(Str);
public void Multi<T, U>(out T a, out U b) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
public void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Text;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
var solver = new Solver(sw);
// var t = new Thread(solver.solve, 1 << 26); // 64 MB
// t.Start();
// t.Join();
solver.solve();
sw.Flush();
}
}
class Solver {
StreamWriter sw;
Scan sc;
void Prt(string a) => sw.WriteLine(a);
void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
void Prt(params object[] a) => Prt(string.Join(" ", a));
public Solver(StreamWriter sw) {
this.sw = sw;
this.sc = new Scan();
}
public void solve() {
int n, m, l;
sc.Multi(out n, out m, out l);
var edge = new List<P>[n];
for (int i = 0; i < n; i++) {
edge[i] = new List<P>();
}
for (int i = 0; i < m; i++) {
int u, v, c;
sc.Multi(out u, out v, out c);
--u;
--v;
if (c <= l) {
edge[u].Add(new P(c, v));
edge[v].Add(new P(c, u));
}
}
var dist = new P[n][];
for (int i = 0; i < n; i++) {
dist[i] = new P[n];
for (int j = 0; j < n; j++) {
dist[i][j] = new P(M, -1);
}
dist[i][i] = new P(0, l);
var vis = new bool[n];
Func<P, P, int> cmp = (x, y) =>
x.v1 != y.v1 ? x.v1.CompareTo(y.v1) : y.v2.CompareTo(x.v2);
int now = i;
while (now != -1) {
vis[now] = true;
foreach (var item in edge[now]) {
P nex;
if (dist[i][now].v2 >= item.v1) {
nex = new P(dist[i][now].v1, dist[i][now].v2 - item.v1);
} else {
nex = new P(dist[i][now].v1 + 1, l - item.v1);
}
if (cmp(nex, dist[i][item.v2]) < 0) {
dist[i][item.v2] = nex;
}
}
var min = new P(M, -1);
int mik = -1;
for (int k = 0; k < n; k++) {
if (!vis[k] && cmp(dist[i][k], min) < 0) {
min = dist[i][k];
mik = k;
}
}
now = mik;
}
}
int que = sc.Int;
for (int i = 0; i < que; i++) {
int u, v;
sc.Multi(out u, out v);
--u;
--v;
Prt(dist[u][v].v1 == M ? -1 : dist[u][v].v1);
}
}
}
class pair<T, U> : IComparable<pair<T, U>> {
public T v1;
public U v2;
public pair() : this(default(T), default(U)) {}
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) {
int c = Comparer<T>.Default.Compare(v1, a.v1);
return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2);
}
public override string ToString() => v1 + " " + v2;
public void Deconstruct(out T a, out U b) {
a = v1;
b = v2;
}
}
static class util {
public static readonly int M = 1000000007;
// public static readonly int M = 998244353;
public static readonly long LM = 1L << 60;
public static readonly double eps = 1e-11;
public static void DBG(string a) => Console.Error.WriteLine(a);
public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
public static void DBG(params object[] a) => DBG(string.Join(" ", a));
public static void Assert(bool cond) {
if (!cond)
throw new Exception();
}
public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1,
v2);
public static int CompareList<T>(IList<T> a, IList<T> b)
where T : IComparable<T> {
for (int i = 0; i < a.Count && i < b.Count; i++)
if (a[i].CompareTo(b[i]) != 0)
return a[i].CompareTo(b[i]);
return a.Count.CompareTo(b.Count);
}
public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h
&& j >= 0 && j < w;
static readonly int[] dd = { 0, 1, 0, -1 };
// static readonly string dstring = "RDLU";
public static P[] adjacents(int i,
int j) => Enumerable.Range(0, dd.Length)
.Select(k => new P(i + dd[k],
j + dd[k ^ 1]))
.ToArray();
public static P[] adjacents(int i, int j, int h, int w) =>
Enumerable.Range(0, dd.Length)
.Select(k => new P(i + dd[k], j + dd[k ^ 1]))
.Where(p => inside(p.v1, p.v2, h, w))
.ToArray();
public static P[] adjacents(this P p) => adjacents(p.v1, p.v2);
public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2,
h, w);
public static Dictionary<T, int>
compress<T>(this IEnumerable<T> a) => a.Distinct()
.OrderBy(v => v)
.Select((v, i) => new { v, i })
.ToDictionary(p => p.v, p => p.i);
public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) =>
compress(a.Aggregate(Enumerable.Union));
public static T[] inv<T>(this Dictionary<T, int> dic) {
var res = new T[dic.Count];
foreach (var item in dic)
res[item.Value] = item.Key;
return res;
}
public static void swap<T>(ref T a, ref T b)
where T : struct {
var t = a;
a = b;
b = t;
}
public static void swap<T>(this IList<T> a, int i, int j)
where T : struct {
var t = a[i];
a[i] = a[j];
a[j] = t;
}
public static T[] copy<T>(this IList<T> a) {
var ret = new T[a.Count];
for (int i = 0; i < a.Count; i++)
ret[i] = a[i];
return ret;
}
}
class Scan {
StreamReader sr;
public Scan() { sr = new StreamReader(Console.OpenStandardInput()); }
public Scan(string path) { sr = new StreamReader(path); }
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => sr.ReadLine().Trim();
public pair<T, U> Pair<T, U>() {
T a;
U b;
Multi(out a, out b);
return new pair<T, U>(a, b);
}
public P P => Pair<int, int>();
public int[] IntArr => StrArr.Select(int.Parse).ToArray();
public long[] LongArr => StrArr.Select(long.Parse).ToArray();
public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
public string[] StrArr =>
Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public void Multi<T>(out T a) => a = cv<T>(Str);
public void Multi<T, U>(out T a, out U b) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
public void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 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, 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], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
| 8
| 2,486
| 21
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<long> Slist() {
return ReadLine().Split().Select(long.Parse).ToList();
}
static readonly long Mod = 1000000000 + 7;
static void Main(string[] args) {
var NML = Sarray();
var N = NML[0];
var M = NML[1];
var L = NML[2];
var G = new long [N]
.Select(_ => new List<KeyValuePair<long, long>>())
.ToArray();
for (var i = 0; i < M; ++i) {
var ABC = Sarray();
var A = ABC[0] - 1;
var B = ABC[1] - 1;
var C = ABC[2];
if (L < C)
continue;
G[A].Add(new KeyValuePair<long, long>(B, C));
G[B].Add(new KeyValuePair<long, long>(A, C));
}
var Q = Sarray()[0];
ANS = new long [N].Select(_ => new long[N]).ToArray();
for (var i = 0; i < N; ++i)
for (var j = 0; j < N; ++j)
ANS[i][j] = long.MaxValue;
for (var i = 0; i < N; ++i)
dijkstra(i, G, L);
SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
for (var i = 0; i < Q; ++i) {
var st = Sarray();
var s = st[0] - 1;
var t = st[1] - 1;
if (long.MaxValue <= ANS[s][t])
WriteLine(-1);
else
WriteLine(ANS[s][t]);
}
Out.Flush();
}
static long[][] ANS;
static readonly int WHITE = 0;
static readonly int GRAY = 1;
static readonly int BLACK = 2;
static void dijkstra(long root, List<KeyValuePair<long, long>>[] M, long L) {
var n = M.Length;
long minv = 0;
long maxl = 0;
var liq = new long[n];
liq[root] = L;
ANS[root][root] = 0;
var color = new long [n].Select(_ => WHITE).ToArray();
color[root] = GRAY;
while (true) {
minv = long.MaxValue;
maxl = long.MinValue;
var u = -1;
for (var i = 0; i < n; ++i) {
if (color[i] != BLACK &&
(ANS[root][i] < minv || (ANS[root][i] == minv && maxl < liq[i]))) {
u = i;
minv = ANS[root][i];
maxl = liq[i];
}
}
if (-1 == u)
break;
color[u] = BLACK;
foreach (var kv in M[u]) {
var ky = kv.Key;
var vl = kv.Value;
if (color[ky] == BLACK)
continue;
var tliq = liq[u] - vl;
var num = ANS[root][u];
if (tliq < 0) {
++num;
tliq = L - vl;
}
if (num < ANS[root][ky] || (num == ANS[root][ky] && liq[ky] < tliq)) {
ANS[root][ky] = num;
liq[ky] = tliq;
color[ky] = GRAY;
}
}
}
return;
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<long> Slist() {
return ReadLine().Split().Select(long.Parse).ToList();
}
static readonly long Mod = 1000000000 + 7;
static void Main(string[] args) {
var NML = Sarray();
var N = NML[0];
var M = NML[1];
var L = NML[2];
var G = new long [N]
.Select(_ => new List<KeyValuePair<long, long>>())
.ToArray();
for (var i = 0; i < M; ++i) {
var ABC = Sarray();
var A = ABC[0] - 1;
var B = ABC[1] - 1;
var C = ABC[2];
if (L < C)
continue;
G[A].Add(new KeyValuePair<long, long>(B, C));
G[B].Add(new KeyValuePair<long, long>(A, C));
}
var Q = Sarray()[0];
ANS = new long [N].Select(_ => new long[N]).ToArray();
for (var i = 0; i < N; ++i)
for (var j = 0; j < N; ++j)
ANS[i][j] = long.MaxValue;
for (var i = 0; i < N; ++i)
dijkstra(i, G, L);
SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
for (var i = 0; i < Q; ++i) {
var st = Sarray();
var s = st[0] - 1;
var t = st[1] - 1;
if (long.MaxValue <= ANS[s][t])
WriteLine(-1);
else
WriteLine(ANS[s][t]);
}
Out.Flush();
}
static long[][] ANS;
static readonly int WHITE = 0;
static readonly int GRAY = 1;
static readonly int BLACK = 2;
static void dijkstra(long root, List<KeyValuePair<long, long>>[] M, long L) {
var n = M.Length;
long minv = 0;
long maxl = 0;
var liq = new long [n].Select(_ => long.MinValue).ToArray();
liq[root] = L;
ANS[root][root] = 0;
var color = new long [n].Select(_ => WHITE).ToArray();
color[root] = GRAY;
while (true) {
minv = long.MaxValue;
maxl = long.MinValue;
var u = -1;
for (var i = 0; i < n; ++i) {
if (color[i] == GRAY &&
(ANS[root][i] < minv || (ANS[root][i] == minv && maxl < liq[i]))) {
u = i;
minv = ANS[root][i];
maxl = liq[i];
}
}
if (-1 == u)
break;
color[u] = BLACK;
foreach (var kv in M[u]) {
var ky = kv.Key;
var vl = kv.Value;
if (color[ky] == BLACK)
continue;
var tliq = liq[u] - vl;
var num = ANS[root][u];
if (tliq < 0) {
++num;
tliq = L - vl;
}
if (num < ANS[root][ky] || (num == ANS[root][ky] && liq[ky] < tliq)) {
ANS[root][ky] = num;
liq[ky] = tliq;
color[ky] = GRAY;
}
}
}
return;
}
}
}
|
[["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 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, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22]]
| 8
| 859
| 17
|
using System;
using System.Linq;
class E {
static void Main() {
Func<int[]> read = () =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
var h = read();
int n = h[0];
var rs = new int[h[1]].Select(_ => read()).ToArray();
var qs =
new int [int.Parse(Console.ReadLine())].Select(_ => read()).ToArray();
var d = new long[n + 1, n + 1];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
d[i, j] = long.MaxValue;
foreach (var r in rs) {
d[r[0], r[1]] = r[2];
d[r[1], r[0]] = r[2];
}
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (d[i, k] < long.MaxValue && d[k, j] < long.MaxValue)
d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (d[i, j] <= h[2])
d[i, j] = 1;
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (d[i, k] < long.MaxValue && d[k, j] < long.MaxValue)
d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]);
Console.WriteLine(
string.Join("\n", qs.Select(x => d[x[0], x[1]])
.Select(x => x < long.MaxValue ? x - 1 : -1)));
}
}
|
using System;
using System.Linq;
class E {
static void Main() {
Func<int[]> read = () =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
var h = read();
int n = h[0];
var rs = new int[h[1]].Select(_ => read()).ToArray();
var qs =
new int [int.Parse(Console.ReadLine())].Select(_ => read()).ToArray();
var d = new long[n + 1, n + 1];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
d[i, j] = long.MaxValue;
foreach (var r in rs) {
d[r[0], r[1]] = r[2];
d[r[1], r[0]] = r[2];
}
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (d[i, k] < long.MaxValue && d[k, j] < long.MaxValue)
d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
d[i, j] = d[i, j] <= h[2] ? 1 : long.MaxValue;
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (d[i, k] < long.MaxValue && d[k, j] < long.MaxValue)
d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]);
Console.WriteLine(
string.Join("\n", qs.Select(x => d[x[0], x[1]])
.Select(x => x < long.MaxValue ? x - 1 : -1)));
}
}
|
[["-", 8, 196, 0, 7, 8, 7, 8, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 7, 8, 57, 0, 24], ["-", 8, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 7, 8, 57, 15, 16, 17, 19], ["-", 8, 7, 8, 57, 15, 16, 12, 204, 205, 22], ["-", 8, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 8, 196, 0, 7, 8, 7, 8, 57, 0, 25], ["+", 8, 7, 8, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 1, 0, 11, 12, 41, 15, 16, 17, 19], ["+", 0, 11, 12, 41, 15, 16, 12, 204, 205, 22], ["+", 12, 41, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 41, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 7, 8, 1, 0, 11, 12, 41, 0, 101], ["+", 8, 7, 8, 1, 0, 11, 12, 41, 0, 102], ["+", 8, 1, 0, 11, 12, 41, 75, 214, 205, 199], ["+", 8, 1, 0, 11, 12, 41, 75, 214, 0, 131], ["+", 8, 1, 0, 11, 12, 41, 75, 214, 141, 22]]
| 8
| 522
| 20
|
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;
int n = s[0], m = s[1];
long inf = long.MaxValue / 3;
var dp1 = new long [n + 1][];
for (int i = 1; i <= n; i++) {
dp1[i] = new long[n + 1];
for (int j = 1; j <= n; j++) {
if (i != j) {
dp1[i][j] = inf;
}
}
}
for (int i = 0; i < m; i++) {
var e = sc.Ia;
if (e[2] <= s[2]) {
dp1[e[0]][e[1]] = e[2];
dp1[e[1]][e[0]] = e[2];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
dp1[j][k] = Min(dp1[j][k], dp1[j][i] + dp1[i][k]);
}
}
}
var dp2 = new long [n + 1][];
for (int i = 1; i <= n; i++) {
dp2[i] = new long[n + 1];
for (int j = 1; j <= n; j++) {
if (dp1[i][j] > s[2]) {
dp2[i][j] = inf;
} else {
dp2[i][j] = 1;
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
dp2[j][k] = Min(dp2[j][k], dp2[j][i] + dp2[i][k]);
}
}
}
var q = sc.I;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < q; i++) {
int[] e = sc.Ia;
sb.Append((dp2[e[0]][e[1]] - 1) + "\n");
}
Console.Write(sb);
}
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
int.Parse);
}
public int[] Ia3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
long.Parse);
}
public long[] La3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
long.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = (int)1e9 + 7;
static void Main() {
Sc sc = new Sc();
var s = sc.Ia;
int n = s[0], m = s[1];
long inf = long.MaxValue / 3;
var dp1 = new long [n + 1][];
for (int i = 1; i <= n; i++) {
dp1[i] = new long[n + 1];
for (int j = 1; j <= n; j++) {
if (i != j) {
dp1[i][j] = inf;
}
}
}
for (int i = 0; i < m; i++) {
var e = sc.Ia;
if (e[2] <= s[2]) {
dp1[e[0]][e[1]] = e[2];
dp1[e[1]][e[0]] = e[2];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
dp1[j][k] = Min(dp1[j][k], dp1[j][i] + dp1[i][k]);
}
}
}
var dp2 = new long [n + 1][];
for (int i = 1; i <= n; i++) {
dp2[i] = new long[n + 1];
for (int j = 1; j <= n; j++) {
if (dp1[i][j] > s[2]) {
dp2[i][j] = inf;
} else {
dp2[i][j] = 1;
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
dp2[j][k] = Min(dp2[j][k], dp2[j][i] + dp2[i][k]);
}
}
}
var q = sc.I;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < q; i++) {
int[] e = sc.Ia;
sb.Append((dp2[e[0]][e[1]] == inf ? -1 : dp2[e[0]][e[1]] - 1) + "\n");
}
Console.Write(sb);
}
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
int.Parse);
}
public int[] Ia3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
long.Parse);
}
public long[] La3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
long.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
[["+", 0, 16, 31, 23, 0, 41, 15, 16, 17, 60], ["+", 0, 16, 31, 23, 0, 41, 15, 16, 12, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 41, 0, 101], ["+", 0, 16, 31, 23, 0, 41, 64, 241, 0, 203], ["+", 0, 28, 0, 16, 31, 23, 0, 41, 0, 102], ["+", 0, 41, 75, 16, 31, 204, 205, 204, 205, 22], ["+", 75, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 205, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 75, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 41, 75, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 0, 41, 75, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 16, 31, 23, 0, 41, 75, 16, 17, 33]]
| 8
| 1,395
| 19
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
int N = int.Parse(str[0]);
int M = int.Parse(str[1]);
long L = long.Parse(str[2]);
int[,] A = new int[M, 3];
long[,] B = new long[N, N];
var list = new List<int>[N];
for (var i = 0; i < N; i++) {
list[i] = new List<int>();
}
for (var i = 0; i < M; i++) {
string[] str2 = Console.ReadLine().Split();
A[i, 0] = int.Parse(str2[0]);
A[i, 1] = int.Parse(str2[1]);
A[i, 2] = int.Parse(str2[2]);
B[A[i, 0] - 1, A[i, 1] - 1] = A[i, 2];
B[A[i, 1] - 1, A[i, 0] - 1] = A[i, 2];
list[A[i, 0] - 1].Add(A[i, 1] - 1);
list[A[i, 1] - 1].Add(A[i, 0] - 1);
}
long[,] D = new long[N, N];
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
D[i, j] = -1;
}
int[] F = new int[N];
var pq = new PriorityQueue<long>((x, y) => D[i, x].CompareTo(D[i, y]));
pq.Enqueue(i);
D[i, i] = 0;
while (pq.Count > 0) {
long a1 = pq.Dequeue();
if (F[a1] == 0) {
F[a1] = 1;
foreach (var a2 in list[a1]) {
if (B[a1, a2] <= L) {
long d1 = D[i, a1] + B[a1, a2];
if (D[i, a2] == -1 || d1 < D[i, a2]) {
D[i, a2] = d1;
pq.Enqueue(a2);
}
}
}
}
}
}
var list2 = new List<int>[N];
for (var i = 0; i < N; i++) {
list2[i] = new List<int>();
}
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
if (D[i, j] != -1 && D[i, j] <= L) {
list2[i].Add(j);
}
}
}
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
D[i, j] = -1;
}
int[] F = new int[N];
var pq = new PriorityQueue<long>((x, y) => D[i, x].CompareTo(D[i, y]));
pq.Enqueue(i);
D[i, i] = 0;
while (pq.Count > 0) {
long a1 = pq.Dequeue();
if (F[a1] == 0) {
F[a1] = 1;
foreach (var a2 in list2[a1]) {
long d1 = D[i, a1] + 1;
if (D[i, a2] == -1 || d1 < D[i, a2]) {
D[i, a2] = d1;
pq.Enqueue(a2);
}
}
}
}
}
int Q = int.Parse(Console.ReadLine());
for (var q = 0; q < Q; q++) {
string[] str3 = Console.ReadLine().Split();
int c1 = int.Parse(str3[0]);
int c2 = int.Parse(str3[1]);
long ans = D[c1 - 1, c2 - 1];
if (ans == -1) {
ans = -1;
}
Console.WriteLine(Math.Max(0, ans - 1));
}
}
}
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
int N = int.Parse(str[0]);
int M = int.Parse(str[1]);
long L = long.Parse(str[2]);
int[,] A = new int[M, 3];
long[,] B = new long[N, N];
var list = new List<int>[N];
for (var i = 0; i < N; i++) {
list[i] = new List<int>();
}
for (var i = 0; i < M; i++) {
string[] str2 = Console.ReadLine().Split();
A[i, 0] = int.Parse(str2[0]);
A[i, 1] = int.Parse(str2[1]);
A[i, 2] = int.Parse(str2[2]);
B[A[i, 0] - 1, A[i, 1] - 1] = A[i, 2];
B[A[i, 1] - 1, A[i, 0] - 1] = A[i, 2];
list[A[i, 0] - 1].Add(A[i, 1] - 1);
list[A[i, 1] - 1].Add(A[i, 0] - 1);
}
long[,] D = new long[N, N];
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
D[i, j] = -1;
}
int[] F = new int[N];
var pq = new PriorityQueue<long>((x, y) => D[i, x].CompareTo(D[i, y]));
pq.Enqueue(i);
D[i, i] = 0;
while (pq.Count > 0) {
long a1 = pq.Dequeue();
if (F[a1] == 0) {
F[a1] = 1;
foreach (var a2 in list[a1]) {
if (B[a1, a2] <= L) {
long d1 = D[i, a1] + B[a1, a2];
if (D[i, a2] == -1 || d1 < D[i, a2]) {
D[i, a2] = d1;
pq.Enqueue(a2);
}
}
}
}
}
}
var list2 = new List<int>[N];
for (var i = 0; i < N; i++) {
list2[i] = new List<int>();
}
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
if (D[i, j] != -1 && D[i, j] <= L) {
list2[i].Add(j);
}
}
}
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
D[i, j] = -1;
}
int[] F = new int[N];
var pq = new PriorityQueue<long>((x, y) => D[i, x].CompareTo(D[i, y]));
pq.Enqueue(i);
D[i, i] = 0;
while (pq.Count > 0) {
long a1 = pq.Dequeue();
if (F[a1] == 0) {
F[a1] = 1;
foreach (var a2 in list2[a1]) {
long d1 = D[i, a1] + 1;
if (D[i, a2] == -1 || d1 < D[i, a2]) {
D[i, a2] = d1;
pq.Enqueue(a2);
}
}
}
}
}
int Q = int.Parse(Console.ReadLine());
for (var q = 0; q < Q; q++) {
string[] str3 = Console.ReadLine().Split();
int c1 = int.Parse(str3[0]);
int c2 = int.Parse(str3[1]);
long ans = D[c1 - 1, c2 - 1];
if (ans != -1) {
ans = Math.Max(0, ans - 1);
}
Console.WriteLine(ans);
}
}
}
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["-", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 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, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 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
| 1,368
| 17
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(ReadLine()); }
public static long[] Reads() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
public static long gcd(long x, long y) {
if (x < y)
gcd(y, x);
while (y != 0) {
var z = x;
x = y;
y = z % y;
}
return x;
}
public static long lcm(long x, long y) { return x * y / gcd(x, y); }
public static long C(long n, long k) {
long x = 1;
for (long i = 1; i <= k; i++) {
x *= n - i + 1;
x /= i;
}
return x;
}
static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var s = ReadLine();
var k = Read();
var l = new List<long>();
var b = "";
long ans = 0;
for (int i = 0; i < s.Length; i++) {
if (s[i].ToString() == b)
l[l.Count - 1]++;
else
l.Add(1);
b = s[i].ToString();
}
for (int i = 0; i < l.Count; i++) {
ans += l[i] / 2;
}
ans *= k;
if (s.Length != 1 && s[0] == s[s.Length - 1] && l[0] % 2 != 0 &&
l[l.Count - 1] % 2 != 0)
ans += k - 1;
if (s.Length == 1)
ans = k / 2;
WriteLine(ans);
Console.Out.Flush();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(ReadLine()); }
public static long[] Reads() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
public static long gcd(long x, long y) {
if (x < y)
gcd(y, x);
while (y != 0) {
var z = x;
x = y;
y = z % y;
}
return x;
}
public static long lcm(long x, long y) { return x * y / gcd(x, y); }
public static long C(long n, long k) {
long x = 1;
for (long i = 1; i <= k; i++) {
x *= n - i + 1;
x /= i;
}
return x;
}
static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var s = ReadLine();
var k = Read();
var l = new List<long>();
var b = "";
long ans = 0;
for (int i = 0; i < s.Length; i++) {
if (s[i].ToString() == b)
l[l.Count - 1]++;
else
l.Add(1);
b = s[i].ToString();
}
for (int i = 0; i < l.Count; i++) {
ans += l[i] / 2;
}
ans *= k;
if (l.Count != 1 && s[0] == s[s.Length - 1] && l[0] % 2 != 0 &&
l[l.Count - 1] % 2 != 0)
ans += k - 1;
if (l.Count == 1)
ans = s.Length * k / 2;
WriteLine(ans);
Console.Out.Flush();
}
}
}
|
[["-", 31, 16, 31, 16, 31, 16, 31, 214, 205, 22], ["+", 31, 16, 31, 16, 31, 16, 31, 214, 205, 22], ["-", 31, 16, 31, 16, 31, 16, 31, 214, 141, 22], ["+", 31, 16, 31, 16, 31, 16, 31, 214, 141, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 205, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 0, 131], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 141, 22], ["+", 64, 1, 0, 11, 12, 16, 31, 16, 17, 48]]
| 8
| 446
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
string s = sc.Next();
long k = sc.NextInt();
List<int> counts = new List<int>();
int current = 0;
char before = ' ';
for (int i = 0; i < s.Length; i++) {
if (i == 0) {
before = s[i];
current = 1;
continue;
}
if (s[i] == before) {
current++;
} else {
counts.Add(current);
current = 1;
before = s[i];
}
if (i == s.Length - 1 && current > 1) {
counts.Add(current);
}
}
long answer = counts.Select(num => num / 2).Sum() * k;
if (counts.Count() > 0 && s[0] == s[s.Length - 1] &&
counts.First() % 2 == 1 && counts.Last() % 2 == 1) {
answer += k - 1;
}
if (s.Length == 1) {
answer = k / 2;
}
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
string s = sc.Next();
long k = sc.NextInt();
List<int> counts = new List<int>();
int current = 0;
char before = ' ';
for (int i = 0; i < s.Length; i++) {
if (i == 0) {
before = s[i];
current = 1;
continue;
}
if (s[i] == before) {
current++;
} else {
counts.Add(current);
current = 1;
before = s[i];
}
if (i == s.Length - 1 && current > 1) {
counts.Add(current);
}
}
long answer = counts.Select(num => num / 2).Sum() * k;
if (counts.Count() > 0 && s[0] == s[s.Length - 1] &&
counts.First() % 2 == 1 && counts.Last() % 2 == 1) {
answer += k - 1;
}
if (s.Distinct().Count() == 1) {
answer = s.Length * k / 2;
}
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 31, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 31, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 31, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 205, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 0, 131], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48]]
| 8
| 570
| 12
|
using System;
using System.Linq;
class c {
static void Main() {
var s = Console.ReadLine();
var n = s.Length;
var k = long.Parse(Console.ReadLine());
if (s.Distinct().Count() == 1)
Console.WriteLine(s.Count() * k / 2);
else {
long front = 1;
for (int i = 1; i < n; i++) {
if (s[i] == s[i - 1])
front++;
else
break;
}
long rear = 1;
for (int i = n - 2; i >= 0; i--) {
if (s[i] == s[i + 1])
rear++;
else
break;
}
long block = 0;
char temp = s[0];
int cnt = 1;
for (int i = 1; i <= n; i++) {
if (n == i) {
block += cnt / 2;
break;
}
if (s[i] == temp) {
cnt++;
} else {
temp = s[i];
block += cnt / 2;
cnt = 1;
}
}
block -= front / 2 + rear / 2;
if (k == 1)
Console.WriteLine(block + front / 2 + rear / 2);
else
Console.WriteLine(
block * k + front / 2 + rear / 2 +
(s[0] == s[n - 1] ? (front + rear) / 2 * (k - 1) : 0));
}
}
}
|
using System;
using System.Linq;
class c {
static void Main() {
var s = Console.ReadLine();
var n = s.Length;
var k = long.Parse(Console.ReadLine());
if (s.Distinct().Count() == 1)
Console.WriteLine(s.Count() * k / 2);
else {
long front = 1;
for (int i = 1; i < n; i++) {
if (s[i] == s[i - 1])
front++;
else
break;
}
long rear = 1;
for (int i = n - 2; i >= 0; i--) {
if (s[i] == s[i + 1])
rear++;
else
break;
}
long block = 0;
char temp = s[0];
int cnt = 1;
for (int i = 1; i <= n; i++) {
if (n == i) {
block += cnt / 2;
break;
}
if (s[i] == temp) {
cnt++;
} else {
temp = s[i];
block += cnt / 2;
cnt = 1;
}
}
block -= front / 2 + rear / 2;
if (k == 1)
Console.WriteLine(block + front / 2 + rear / 2);
else
Console.WriteLine(block * k + front / 2 + rear / 2 +
(s[0] == s[n - 1]
? (front + rear) / 2 * (k - 1)
: (front / 2 + rear / 2) * (k - 1)));
}
}
}
|
[["-", 0, 28, 0, 16, 12, 23, 0, 41, 75, 203], ["+", 12, 23, 0, 41, 75, 16, 31, 23, 0, 24], ["+", 75, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 75, 16, 31, 23, 0, 16, 31, 16, 17, 85], ["+", 75, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["+", 0, 41, 75, 16, 31, 23, 0, 16, 17, 72], ["+", 75, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["+", 75, 16, 31, 23, 0, 16, 12, 16, 17, 85], ["+", 75, 16, 31, 23, 0, 16, 12, 16, 12, 203], ["+", 12, 23, 0, 41, 75, 16, 31, 23, 0, 25], ["+", 0, 16, 12, 23, 0, 41, 75, 16, 17, 48], ["+", 12, 23, 0, 41, 75, 16, 12, 23, 0, 24], ["+", 0, 41, 75, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 41, 75, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 41, 75, 16, 12, 23, 0, 16, 12, 203], ["+", 12, 23, 0, 41, 75, 16, 12, 23, 0, 25]]
| 8
| 328
| 16
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp1 {
public class Class1 {
static void Main(string[] args) {
var S = Console.ReadLine();
var K = long.Parse(Console.ReadLine());
long s1 = 0;
long s2 = 0;
for (var i = 0; i < S.Length; i++) {
if (i == S.Length - 1)
break;
if (S[i] == S[i + 1]) {
s1++;
i++;
}
}
S += S;
for (var i = 0; i < S.Length; i++) {
if (i == S.Length - 1)
break;
if (S[i] == S[i + 1]) {
s2++;
i++;
}
}
Console.Write(s1 * (K % 2) + s2 * (K / 2));
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp1 {
public class Class1 {
static void Main(string[] args) {
var S = Console.ReadLine();
var K = long.Parse(Console.ReadLine());
long s1 = 0;
long s2 = 0;
for (var i = 0; i < S.Length; i++) {
if (i == S.Length - 1)
break;
if (S[i] == S[i + 1]) {
s1++;
i++;
}
}
S += S;
for (var i = 0; i < S.Length; i++) {
if (i == S.Length - 1)
break;
if (S[i] == S[i + 1]) {
s2++;
i++;
}
}
if (S.Distinct().Count() == 1) {
Console.Write(s1 * (K % 2) + s2 * (K / 2));
} else {
Console.Write(s1 + (s2 - s1) * (K - 1));
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 31, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 31, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 31, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 31, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 31, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 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, 28, 0, 16, 12, 16, 12, 23, 0, 25], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 12, 16, 31, 23, 0, 24], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 28, 0, 16, 12, 16, 31, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["+", 0, 28, 0, 16, 12, 16, 12, 23, 0, 24], ["+", 0, 16, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 16, 12, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 197
| 38
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace A {
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 s = Console.ReadLine();
var k = long.Parse(Console.ReadLine());
var count = 0;
var left = 0;
var right = 0;
for (var i = 0; i < s.Length; i++) {
if (s[i] == s[0])
left++;
else
break;
}
if (left == s.Length) {
Console.WriteLine(s.Length * k / 2);
return;
}
for (var i = s.Length - 1; i >= 0; i--) {
if (s[i] == s[0])
right++;
else
break;
}
var tmp = 1;
var prev = s[0];
for (var i = left; i < s.Length - right; i++) {
if (s[i] == prev) {
tmp++;
} else {
count += tmp / 2;
tmp = 1;
}
prev = s[i];
}
count += tmp / 2;
var edge = (left + right) / 2;
count += edge;
if (right == 1)
Console.WriteLine(count * k - edge + left / 2);
else
Console.WriteLine(count * k);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace A {
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 s = Console.ReadLine();
var k = long.Parse(Console.ReadLine());
var count = 0;
var left = 0;
var right = 0;
for (var i = 0; i < s.Length; i++) {
if (s[i] == s[0])
left++;
else
break;
}
if (left == s.Length) {
Console.WriteLine(s.Length * k / 2);
return;
}
for (var i = s.Length - 1; i >= 0; i--) {
if (s[i] == s[0])
right++;
else
break;
}
var tmp = 1;
var prev = s[0];
for (var i = left; i < s.Length - right; i++) {
if (s[i] == prev) {
tmp++;
} else {
count += tmp / 2;
tmp = 1;
}
prev = s[i];
}
count += tmp / 2;
var edge = (left + right) / 2;
count += edge;
Console.WriteLine(count * k - edge + left / 2 + right / 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, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["-", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["-", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 85], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203]]
| 8
| 346
| 20
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
public class Hello {
static public int mod = 1000000007;
public static void Main() {
string a = rstr();
string aa = a + a;
long b = rlong();
int acount = 1;
long atotal = 0;
int aacount = 1;
int aatotal = 0;
for (int i = 1; i < a.Length; i++) {
if (a[i - 1] == a[i]) {
acount++;
} else {
atotal += acount / 2;
acount = 1;
}
}
atotal += acount / 2;
for (int i = 1; i < aa.Length; i++) {
if (aa[i - 1] == aa[i]) {
aacount++;
} else {
aatotal += aacount / 2;
aacount = 1;
}
}
aatotal += aacount / 2;
/*
WriteLine(atotal);
WriteLine(aatotal);
WriteLine(aa);
if(aatotal == atotal*2){
long ans = atotal*b;
WriteLine(ans);
}else{
long ans = atotal*b+b-1;
WriteLine(ans);
}
*/
if (a.Length == 1) {
WriteLine(b / 2);
} else {
WriteLine((aatotal - atotal) * b - 1);
}
}
// ncr mod
static int ncr(int n, int r) {
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
// static int square2(long a,long b,long m){var list = new List<int>();int
// temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp <
// b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b >
// 0){if(temp <= b){b -= temp;ret =
// ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
//知見
// (string) hogestr -> (char[]) hoge
// char hoge = hogestr.ToCharArray();
// (char[]) hoge -> (string) hogestr
// string hoge = new string(hoge);
// Hashtable × Dictionary ○
// Dictionary hoge<string,int>
// hoge.ContainsKey(string) -> return boolean
// hoge[string] -> return int
// hoge[int] -> CE
// Dictionary hoge<int1,int2>
// hoge<int1,int2>: hoge[int1] -> return int2
// KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2
// SortedDictionary() > SortedList() ???
// キュー -> 幅優先 ???
// スタック -> 深さ優先 ???
// var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stackPeek()
// stack.Count
// if (list?.Count > 0) リストが空でもnullでもない
// ソート
// list.Sort(StringComparer.Ordinal); listの辞書順ソート
// StringComparer.Ordinal とは
// 出力
// foreach(var a int list){ WriteLine(a); } より
// WriteLine(string.Join("\n", list)); が速い
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
public class Hello {
static public int mod = 1000000007;
public static void Main() {
string a = rstr();
string aa = a + a;
long b = rlong();
long acount = 1;
long atotal = 0;
int aacount = 1;
int aatotal = 0;
for (int i = 1; i < a.Length; i++) {
if (a[i - 1] == a[i]) {
acount++;
} else {
atotal += acount / 2;
acount = 1;
}
}
atotal += acount / 2;
for (int i = 1; i < aa.Length; i++) {
if (aa[i - 1] == aa[i]) {
aacount++;
} else {
aatotal += aacount / 2;
aacount = 1;
}
}
aatotal += aacount / 2;
/*
WriteLine(atotal);
WriteLine(aatotal);
WriteLine(aa);
if(aatotal == atotal*2){
long ans = atotal*b;
WriteLine(ans);
}else{
long ans = atotal*b+b-1;
WriteLine(ans);
}
*/
if (acount == a.Length) {
WriteLine(acount * b / 2);
} else {
WriteLine((aatotal - atotal) * (b - 1) + atotal);
}
}
// ncr mod
static int ncr(int n, int r) {
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
// static int square2(long a,long b,long m){var list = new List<int>();int
// temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp <
// b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b >
// 0){if(temp <= b){b -= temp;ret =
// ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
//知見
// (string) hogestr -> (char[]) hoge
// char hoge = hogestr.ToCharArray();
// (char[]) hoge -> (string) hogestr
// string hoge = new string(hoge);
// Hashtable × Dictionary ○
// Dictionary hoge<string,int>
// hoge.ContainsKey(string) -> return boolean
// hoge[string] -> return int
// hoge[int] -> CE
// Dictionary hoge<int1,int2>
// hoge<int1,int2>: hoge[int1] -> return int2
// KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2
// SortedDictionary() > SortedList() ???
// キュー -> 幅優先 ???
// スタック -> 深さ優先 ???
// var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stackPeek()
// stack.Count
// if (list?.Count > 0) リストが空でもnullでもない
// ソート
// list.Sort(StringComparer.Ordinal); listの辞書順ソート
// StringComparer.Ordinal とは
// 出力
// foreach(var a int list){ WriteLine(a); } より
// WriteLine(string.Join("\n", list)); が速い
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 0, 28, 0, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 984
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
using ll = System.Int64;
public class Contest {
static void Swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static void Swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
Swap1(ref a, ref b);
} // b の方が小さければ交換
static bool Chmin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
} // b の方が小さければ a を更新
static bool Chmax<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
} // b の方が大きければ a を更新
static T[][] InitMat<T>(long len1, long len2, T val) {
T[][] m = new T[len1][];
for (int i = 0; i < m.Length; i++)
m[i] = Enumerable.Repeat(val, (int)len2).ToArray();
return m;
}
static T[][][] InitMat<T>(long len1, long len2, long len3, T val) {
T[][][] m = new T[len1][][];
for (int i = 0; i < m.Length; i++)
m[i] = InitMat(len2, len3, val);
return m;
}
public const long MOD1 = 1000000007; // 10^9+7
public static void Main() { Solve_A(); }
public static void Solve_A() {
string s;
MyIO.ReadMulti(out s);
ll k;
MyIO.ReadMulti(out k);
if (s.Length == 1) {
MyIO.WriteMulti(k / 2);
} else {
ll cnt = 0;
bool lc = false;
ll fn = 0;
for (int i = 0; i < s.Length; i++) {
if (s[0] == s[i]) {
fn++;
} else {
break;
}
}
for (int i = 0; i < s.Length - 1; i++) {
if (s[i] == s[i + 1]) {
cnt++;
if (i == s.Length - 2)
lc = true;
i++;
}
}
if (s[0] == s[s.Length - 1]) {
MyIO.WriteMulti(cnt * k + ((lc || fn % 2 == 0) ? 0 : (k - 1)));
} else {
MyIO.WriteMulti(cnt * k);
}
}
}
public static void Solve_B() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_C() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_D() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_E() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_F() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
}
#region MyIO
public struct VT<T, U> {
public T Item1;
public U Item2;
public VT(T a, U b) {
Item1 = a;
Item2 = b;
}
}
public struct VT<T, U, V> {
public T Item1;
public U Item2;
public V Item3;
public VT(T a, U b, V c) {
Item1 = a;
Item2 = b;
Item3 = c;
}
}
public struct VT<T, U, V, W> {
public T Item1;
public U Item2;
public V Item3;
public W Item4;
public VT(T a, U b, V c, W d) {
Item1 = a;
Item2 = b;
Item3 = c;
Item4 = d;
}
}
public class Printer : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Printer(System.IO.Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(System.IO.Stream stream, Encoding encoding)
: base(stream, encoding) {}
}
public static class MyIO {
private static char[] splitter = new char[] { ' ' };
private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
private static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] ReadMulti<T>(out T a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(ar[0]);
return ar;
}
public static string[] ReadMulti<T, U>(out T a, out U b) {
var ar = ReadMulti<T>(out a);
b = cv<U>(ar[1]);
return ar;
}
public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
var ar = ReadMulti<T, U>(out a, out b);
c = cv<V>(ar[2]);
return ar;
}
public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c,
out W d) {
var ar = ReadMulti<T, U, V>(out a, out b, out c);
d = cv<W>(ar[3]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c,
out W d, out X e) {
var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(ar[4]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e,
out Y f) {
var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(ar[5]);
return ar;
}
public static string[] ReadArray<T>(out T[] a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = ar.Select(cv<T>).ToArray();
return ar;
}
public static string[][] ReadLines<T>(long n, out T[] a) {
a = new T[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadMulti(out a[i]);
return arr;
}
public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) {
a = new VT<T, U>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
arr[i] = ReadMulti(out o, out p);
a[i] = new VT<T, U>(o, p);
}
return arr;
}
public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) {
a = new VT<T, U, V>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
arr[i] = ReadMulti(out o, out p, out q);
a[i] = new VT<T, U, V>(o, p, q);
}
return arr;
}
public static string[][] ReadLines<T, U, V, W>(long n,
out VT<T, U, V, W>[] a) {
a = new VT<T, U, V, W>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
arr[i] = ReadMulti(out o, out p, out q, out r);
a[i] = new VT<T, U, V, W>(o, p, q, r);
}
return arr;
}
public static string[][] ReadMatrix<T>(long n, out T[][] a) {
a = new T[n][];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadArray(out a[i]);
return arr;
}
private static void wwp(Action act) {
var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}"
: "{0}";
public static void WriteMulti(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length; i++) {
string fs = wfm(a[i].GetType()) +
((i < a.Length - 1) ? " " : Environment.NewLine);
Console.Write(fs, a[i]);
}
});
}
public static void WriteArray<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T));
string fs1 = fs + " ";
string fs2 = fs + Environment.NewLine;
for (int i = 0; i < a.Length; i++)
Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]);
});
}
public static void WriteLines<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T)) + Environment.NewLine;
foreach (T x in a)
Console.Write(fs, x);
});
}
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
using ll = System.Int64;
public class Contest {
static void Swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static void Swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
Swap1(ref a, ref b);
} // b の方が小さければ交換
static bool Chmin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
} // b の方が小さければ a を更新
static bool Chmax<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
} // b の方が大きければ a を更新
static T[][] InitMat<T>(long len1, long len2, T val) {
T[][] m = new T[len1][];
for (int i = 0; i < m.Length; i++)
m[i] = Enumerable.Repeat(val, (int)len2).ToArray();
return m;
}
static T[][][] InitMat<T>(long len1, long len2, long len3, T val) {
T[][][] m = new T[len1][][];
for (int i = 0; i < m.Length; i++)
m[i] = InitMat(len2, len3, val);
return m;
}
public const long MOD1 = 1000000007; // 10^9+7
public static void Main() { Solve_A(); }
public static void Solve_A() {
string s;
MyIO.ReadMulti(out s);
ll k;
MyIO.ReadMulti(out k);
if (s.Length == 1) {
MyIO.WriteMulti(k / 2);
} else {
ll cnt = 0;
bool lc = false;
ll fn = 0;
for (int i = 0; i < s.Length; i++) {
if (s[0] == s[i]) {
fn++;
} else {
break;
}
}
if (fn == s.Length) {
MyIO.WriteMulti(s.Length * k / 2);
} else {
for (int i = 0; i < s.Length - 1; i++) {
if (s[i] == s[i + 1]) {
cnt++;
if (i == s.Length - 2)
lc = true;
i++;
}
}
if (s[0] == s[s.Length - 1]) {
MyIO.WriteMulti(cnt * k + ((lc || fn % 2 == 0) ? 0 : (k - 1)));
} else {
MyIO.WriteMulti(cnt * k);
}
}
}
}
public static void Solve_B() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_C() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_D() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_E() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_F() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
}
#region MyIO
public struct VT<T, U> {
public T Item1;
public U Item2;
public VT(T a, U b) {
Item1 = a;
Item2 = b;
}
}
public struct VT<T, U, V> {
public T Item1;
public U Item2;
public V Item3;
public VT(T a, U b, V c) {
Item1 = a;
Item2 = b;
Item3 = c;
}
}
public struct VT<T, U, V, W> {
public T Item1;
public U Item2;
public V Item3;
public W Item4;
public VT(T a, U b, V c, W d) {
Item1 = a;
Item2 = b;
Item3 = c;
Item4 = d;
}
}
public class Printer : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Printer(System.IO.Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(System.IO.Stream stream, Encoding encoding)
: base(stream, encoding) {}
}
public static class MyIO {
private static char[] splitter = new char[] { ' ' };
private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
private static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] ReadMulti<T>(out T a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(ar[0]);
return ar;
}
public static string[] ReadMulti<T, U>(out T a, out U b) {
var ar = ReadMulti<T>(out a);
b = cv<U>(ar[1]);
return ar;
}
public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
var ar = ReadMulti<T, U>(out a, out b);
c = cv<V>(ar[2]);
return ar;
}
public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c,
out W d) {
var ar = ReadMulti<T, U, V>(out a, out b, out c);
d = cv<W>(ar[3]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c,
out W d, out X e) {
var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(ar[4]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e,
out Y f) {
var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(ar[5]);
return ar;
}
public static string[] ReadArray<T>(out T[] a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = ar.Select(cv<T>).ToArray();
return ar;
}
public static string[][] ReadLines<T>(long n, out T[] a) {
a = new T[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadMulti(out a[i]);
return arr;
}
public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) {
a = new VT<T, U>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
arr[i] = ReadMulti(out o, out p);
a[i] = new VT<T, U>(o, p);
}
return arr;
}
public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) {
a = new VT<T, U, V>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
arr[i] = ReadMulti(out o, out p, out q);
a[i] = new VT<T, U, V>(o, p, q);
}
return arr;
}
public static string[][] ReadLines<T, U, V, W>(long n,
out VT<T, U, V, W>[] a) {
a = new VT<T, U, V, W>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
arr[i] = ReadMulti(out o, out p, out q, out r);
a[i] = new VT<T, U, V, W>(o, p, q, r);
}
return arr;
}
public static string[][] ReadMatrix<T>(long n, out T[][] a) {
a = new T[n][];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadArray(out a[i]);
return arr;
}
private static void wwp(Action act) {
var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}"
: "{0}";
public static void WriteMulti(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length; i++) {
string fs = wfm(a[i].GetType()) +
((i < a.Length - 1) ? " " : Environment.NewLine);
Console.Write(fs, a[i]);
}
});
}
public static void WriteArray<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T));
string fs1 = fs + " ";
string fs2 = fs + Environment.NewLine;
for (int i = 0; i < a.Length; i++)
Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]);
});
}
public static void WriteLines<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T)) + Environment.NewLine;
foreach (T x in a)
Console.Write(fs, x);
});
}
}
#endregion
|
[["+", 8, 196, 0, 57, 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, 214, 205, 22], ["+", 75, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 75, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 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, 16, 31, 16, 31, 214, 205, 22], ["+", 0, 28, 0, 16, 31, 16, 31, 214, 0, 131], ["+", 0, 28, 0, 16, 31, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 2,550
| 26
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
internal partial class Solver {
int Calc(string s) {
var inf = 1000000000;
var n = s.Length;
var dp = new int[n, 2];
dp[0, 0] = 0;
dp[0, 1] = 1;
for (int i = 1; i < n; i++) {
if (s[i] == s[i - 1]) {
dp[i, 0] = dp[i - 1, 1];
dp[i, 1] = Math.Min(dp[i - 1, 1] + 1, dp[i - 1, 0] + 1);
} else {
dp[i, 0] = Math.Min(dp[i - 1, 1], dp[i - 1, 0]);
dp[i, 1] = Math.Min(dp[i - 1, 1] + 1, dp[i - 1, 0] + 1);
}
}
return Math.Min(dp[n - 1, 0], dp[n - 1, 1]);
}
string Repeat(string s, int k) {
return string.Concat(Enumerable.Repeat(s, k));
}
public void Run() {
var s = ns();
var k = ni();
long ans = 0;
if (k <= 100) {
ans = Calc(Repeat(s, k));
} else {
var l1 = Calc(Repeat(s, 100));
var l2 = Calc(Repeat(s, 101));
ans = l1 + 1L * (k - 100) * (l2 - l1);
}
cout.WriteLine(ans);
}
}
// PREWRITEN CODE BEGINS FROM HERE
internal partial class Solver : Scanner {
public static void Main(string[] args) {
#if LOCAL
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
}
public void RunMulti() {
while (HasNext()) {
Run();
}
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
public static class LinqPadExtension {
public static T Dump<T>(this T obj) {
#if LOCAL
return LINQPad.Extensions.Dump(obj);
#else
return obj;
#endif
}
}
public class Scanner {
private readonly TextReader Reader;
private readonly Queue<string> TokenQueue = new Queue<string>();
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return int.Parse(Next(), ci); }
public long NextLong() { return long.Parse(Next(), ci); }
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
var array = new string[size];
for (var i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
var array = new int[size];
for (var i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
var array = new long[size];
for (var i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
var array = new double[size];
for (var i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (TokenQueue.Count == 0) {
if (!StockTokens()) {
throw new InvalidOperationException();
}
}
return TokenQueue.Dequeue();
}
public bool HasNext() {
if (TokenQueue.Count > 0) {
return true;
}
return StockTokens();
}
private static readonly char[] _separator = new[] { ' ', '\t' };
private bool StockTokens() {
while (true) {
var line = Reader.ReadLine();
if (line == null) {
return false;
}
var tokens =
line.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length == 0) {
continue;
}
foreach (var token in tokens) {
TokenQueue.Enqueue(token);
}
return true;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
internal partial class Solver {
int Calc(string s) {
var inf = 1000000000;
var n = s.Length;
var dp = new int[n, 2];
dp[0, 0] = 0;
dp[0, 1] = 1;
for (int i = 1; i < n; i++) {
if (s[i] == s[i - 1]) {
dp[i, 0] = dp[i - 1, 1];
dp[i, 1] = Math.Min(dp[i - 1, 1] + 1, dp[i - 1, 0] + 1);
} else {
dp[i, 0] = Math.Min(dp[i - 1, 1], dp[i - 1, 0]);
dp[i, 1] = Math.Min(dp[i - 1, 1] + 1, dp[i - 1, 0] + 1);
}
}
return Math.Min(dp[n - 1, 0], dp[n - 1, 1]);
}
string Repeat(string s, int k) {
return string.Concat(Enumerable.Repeat(s, k));
}
public void Run() {
var s = ns();
var k = ni();
long ans = 0;
if (k <= 100) {
ans = Calc(Repeat(s, k));
} else {
var b = k % 2 == 0 ? 100 : 99;
var l1 = Calc(Repeat(s, b));
var l2 = Calc(Repeat(s, b + 2));
ans = l1 + 1L * (k - b) / 2 * (l2 - l1);
}
cout.WriteLine(ans);
}
}
// PREWRITEN CODE BEGINS FROM HERE
internal partial class Solver : Scanner {
public static void Main(string[] args) {
#if LOCAL
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
}
public void RunMulti() {
while (HasNext()) {
Run();
}
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
public static class LinqPadExtension {
public static T Dump<T>(this T obj) {
#if LOCAL
return LINQPad.Extensions.Dump(obj);
#else
return obj;
#endif
}
}
public class Scanner {
private readonly TextReader Reader;
private readonly Queue<string> TokenQueue = new Queue<string>();
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return int.Parse(Next(), ci); }
public long NextLong() { return long.Parse(Next(), ci); }
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
var array = new string[size];
for (var i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
var array = new int[size];
for (var i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
var array = new long[size];
for (var i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
var array = new double[size];
for (var i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (TokenQueue.Count == 0) {
if (!StockTokens()) {
throw new InvalidOperationException();
}
}
return TokenQueue.Dequeue();
}
public bool HasNext() {
if (TokenQueue.Count > 0) {
return true;
}
return StockTokens();
}
private static readonly char[] _separator = new[] { ' ', '\t' };
private bool StockTokens() {
while (true) {
var line = Reader.ReadLine();
if (line == null) {
return false;
}
var tokens =
line.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length == 0) {
continue;
}
foreach (var token in tokens) {
TokenQueue.Enqueue(token);
}
return true;
}
}
}
|
[["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 212, 0, 41, 15, 16, 31, 16, 31, 22], ["+", 0, 212, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 0, 212, 0, 41, 15, 16, 31, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 60], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 64, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 75, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["+", 75, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 16, 12, 16, 31, 16, 17, 85], ["+", 0, 11, 12, 16, 12, 16, 31, 16, 12, 203]]
| 8
| 1,200
| 23
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var S = Console.ReadLine();
var K = long.Parse(Console.ReadLine());
var firstchr = S[0];
int firstcount = 0;
int lastcount = 0;
int chgcount = 0;
double ans;
for (int i = 0; i < S.Length; i++) {
if (S[i] == firstchr) {
firstcount++;
} else {
break;
}
}
// Console.WriteLine(string.Format("firstcount:{0}", firstcount));
for (int i = S.Length - 1; i > 0; i--) {
if (S[i] == firstchr) {
lastcount++;
} else {
break;
}
}
// Console.WriteLine(string.Format("lastcount:{0}", lastcount));
for (int i = firstcount; i < S.Length - 1 - lastcount; i++) {
if (S[i] == S[i + 1]) {
chgcount++;
i++;
}
}
long firstcountblock = firstcount / 2;
long lastcountblock = lastcount / 2;
long chgcountblock = chgcount * K;
long lastblocak = (firstcount + lastcount) / 2 * (K - 1);
// Console.WriteLine(string.Format("firstcountblock:{0}",
//firstcountblock)); Console.WriteLine(string.Format("lastcountblock:{0}",
//lastcountblock)); Console.WriteLine(string.Format("chgcountblock:{0}",
//chgcountblock)); Console.WriteLine(string.Format("lastblocak:{0}",
//lastblocak));
ans = firstcountblock + lastcountblock + chgcountblock + lastblocak;
if (firstcount == S.Length) {
ans = K;
}
Console.WriteLine(ans);
// Console.ReadLine();
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var S = Console.ReadLine();
var K = long.Parse(Console.ReadLine());
var firstchr = S[0];
int firstcount = 0;
int lastcount = 0;
int chgcount = 0;
double ans;
for (int i = 0; i < S.Length; i++) {
if (S[i] == firstchr) {
firstcount++;
} else {
break;
}
}
// Console.WriteLine(string.Format("firstcount:{0}", firstcount));
for (int i = S.Length - 1; i > 0; i--) {
if (S[i] == firstchr) {
lastcount++;
} else {
break;
}
}
// Console.WriteLine(string.Format("lastcount:{0}", lastcount));
for (int i = firstcount; i < S.Length - 1 - lastcount; i++) {
if (S[i] == S[i + 1]) {
chgcount++;
i++;
}
}
// Console.WriteLine(string.Format("firstcountblock:{0}",
//firstcountblock)); Console.WriteLine(string.Format("lastcountblock:{0}",
//lastcountblock)); Console.WriteLine(string.Format("chgcountblock:{0}",
//chgcountblock)); Console.WriteLine(string.Format("lastblocak:{0}",
//lastblocak));
if (firstcount == S.Length)
lastcount = 0;
double firstcountblock = firstcount / 2;
double lastcountblock = lastcount / 2;
double chgcountblock = chgcount * K;
double lastblocak = (firstcount + lastcount) / 2 * (K - 1);
ans = firstcountblock + lastcountblock + chgcountblock + lastblocak;
if (firstcount == S.Length) {
ans = firstcount * K / 2;
}
Console.WriteLine(ans);
// Console.ReadLine();
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 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], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 271
| 24
|
using System;
class ProgramA {
static void Main(string[] args) {
string s = Console.ReadLine();
ulong k = ulong.Parse(Console.ReadLine());
ulong count = 0;
ulong count2 = 0;
int frag = 0;
int len = s.Length;
for (int i = 1; i < len; i++) {
if (s[i] == s[i - 1]) {
count++;
i++;
}
if (i == len - 1 && s[0] == s[len - 1])
frag = 1;
}
if (frag == 1 && k > 1) {
count2++;
for (int i = 2; i < len; i++) {
if (s[i] == s[i - 1]) {
count2++;
i++;
if (i == len)
frag = 2;
}
}
}
if (frag == 1)
Console.WriteLine(count + count2 * (k - 1));
else if (frag == 2)
Console.WriteLine(count * (ulong)((k + 1) / 2) + count2 * (ulong)(k / 2));
else
Console.WriteLine(count * k);
}
}
|
using System;
class ProgramA {
static void Main(string[] args) {
string s = Console.ReadLine();
ulong k = ulong.Parse(Console.ReadLine());
ulong count = 0;
ulong count2 = 0;
int frag = 0;
int len = s.Length;
for (int i = 1; i < len; i++) {
if (s[i] == s[i - 1]) {
count++;
i++;
}
if (i == len - 1 && s[0] == s[len - 1])
frag = 1;
}
if (frag == 1 && k > 1) {
count2++;
for (int i = 2; i < len; i++) {
if (s[i] == s[i - 1]) {
count2++;
i++;
}
if (i == len)
frag = 2;
}
}
if (len == 1)
Console.WriteLine(k / 2);
else if (frag == 1)
Console.WriteLine(count + count2 * (k - 1));
else if (frag == 2)
Console.WriteLine(count * (ulong)((k + 1) / 2) + count2 * (ulong)(k / 2));
else
Console.WriteLine(count * k);
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
| 8
| 257
| 18
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program {
static long mod = 1000000007;
// static long mod =998244353;
static int[] ans;
static void Main(string[] args) {
char[] cs = new char[] { ' ' };
// char[] cs = new char[] { ' ', ',' };
// int n = int.Parse(Console.ReadLine());
// int val = int.Parse(Console.ReadLine());
// int[] vals = parseAry(Console.ReadLine().Split(cs));
// string str = Console.ReadLine();
// string[] strs = Console.ReadLine().Split(cs);
// string res = "";
long res = 0;
string str = Console.ReadLine();
int n = int.Parse(Console.ReadLine());
if (str.Length == 1) {
Console.WriteLine(n / 2);
return;
}
char ff = str[0];
int fc = 0;
for (int i = 0; i < str.Length; i++) {
if (ff == str[i]) {
fc++;
} else {
break;
}
}
if (fc == str.Length) {
long w = (fc * n) / 2;
Console.WriteLine(w);
return;
}
char gg = str[str.Length - 1];
int gc = 0;
for (int i = str.Length - 1; i >= 0; i--) {
if (gg == str[i]) {
gc++;
} else {
break;
}
}
long d = 0;
for (int i = fc; i < str.Length - gc; i++) {
if (str[i] == str[i + 1]) {
d++;
i++;
}
}
long man = 0;
if (str[0] == str[str.Length - 1]) {
man = (fc + gc) / 2;
} else {
man = fc / 2 + gc / 2;
}
man = man * (n - 1);
d = d * n;
res = fc / 2 + gc / 2 + d + man;
Console.WriteLine(res);
return;
}
// int配列をスペース区切りの文字列に変換
static string stringBuilderArrayInt(int[] a) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < a.Length; i++) {
sb.Append(a[i] + " ");
}
if (sb.Length > 1) {
sb = sb.Remove(sb.Length - 1, 1);
}
return sb.ToString();
;
}
// 文字列strをindex番目からdで上書き
static string strOverWrite(string str, int i, string s) {
return str.Remove(i, s.Length).Insert(i, s);
}
// String[] -----> int[]
static int[] parseAry(string[] str) {
int[] nums = new int[str.Length];
for (int i = 0; i < str.Length; i++) {
nums[i] = int.Parse(str[i]);
}
return nums;
}
// String[] -----> long[]
static long[] parseAryL(string[] str) {
long[] nums = new long[str.Length];
for (int i = 0; i < str.Length; i++) {
nums[i] = long.Parse(str[i]);
}
return nums;
}
//文字列を1文字ずつString[]に入れる
static string[] strAry(String str) {
string[] re = new string[str.Length];
for (int i = 0; i < str.Length; i++) {
re[i] = str[i].ToString();
}
return re;
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program {
static long mod = 1000000007;
// static long mod =998244353;
static int[] ans;
static void Main(string[] args) {
char[] cs = new char[] { ' ' };
// char[] cs = new char[] { ' ', ',' };
// int n = int.Parse(Console.ReadLine());
// int val = int.Parse(Console.ReadLine());
// int[] vals = parseAry(Console.ReadLine().Split(cs));
// string str = Console.ReadLine();
// string[] strs = Console.ReadLine().Split(cs);
// string res = "";
long res = 0;
string str = Console.ReadLine();
int n = int.Parse(Console.ReadLine());
if (str.Length == 1) {
Console.WriteLine(n / 2);
return;
}
char ff = str[0];
long fc = 0;
for (int i = 0; i < str.Length; i++) {
if (ff == str[i]) {
fc++;
} else {
break;
}
}
if (fc == str.Length) {
long w = (long)((long)fc * (long)n) / 2;
Console.WriteLine(w);
return;
}
char gg = str[str.Length - 1];
long gc = 0;
for (int i = str.Length - 1; i >= 0; i--) {
if (gg == str[i]) {
gc++;
} else {
break;
}
}
long d = 0;
for (int i = (int)fc; i < str.Length - gc; i++) {
if (str[i] == str[i + 1]) {
d++;
i++;
}
}
long man = 0;
if (str[0] == str[str.Length - 1]) {
man = (fc + gc) / 2;
} else {
man = fc / 2 + gc / 2;
}
man = (long)man * (n - 1);
d = d * (long)n;
res = fc / 2 + gc / 2 + (long)d + (long)man;
Console.WriteLine(res);
return;
}
// int配列をスペース区切りの文字列に変換
static string stringBuilderArrayInt(int[] a) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < a.Length; i++) {
sb.Append(a[i] + " ");
}
if (sb.Length > 1) {
sb = sb.Remove(sb.Length - 1, 1);
}
return sb.ToString();
;
}
// 文字列strをindex番目からdで上書き
static string strOverWrite(string str, int i, string s) {
return str.Remove(i, s.Length).Insert(i, s);
}
// String[] -----> int[]
static int[] parseAry(string[] str) {
int[] nums = new int[str.Length];
for (int i = 0; i < str.Length; i++) {
nums[i] = int.Parse(str[i]);
}
return nums;
}
// String[] -----> long[]
static long[] parseAryL(string[] str) {
long[] nums = new long[str.Length];
for (int i = 0; i < str.Length; i++) {
nums[i] = long.Parse(str[i]);
}
return nums;
}
//文字列を1文字ずつString[]に入れる
static string[] strAry(String str) {
string[] re = new string[str.Length];
for (int i = 0; i < str.Length; i++) {
re[i] = str[i].ToString();
}
return re;
}
}
|
[["-", 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, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25], ["+", 0, 212, 0, 16, 31, 74, 51, 23, 0, 24], ["+", 31, 74, 51, 23, 0, 16, 31, 74, 0, 24], ["+", 31, 74, 51, 23, 0, 16, 31, 74, 39, 199], ["+", 31, 74, 51, 23, 0, 16, 31, 74, 0, 25], ["+", 31, 74, 51, 23, 0, 16, 12, 74, 0, 24], ["+", 31, 74, 51, 23, 0, 16, 12, 74, 39, 199], ["+", 31, 74, 51, 23, 0, 16, 12, 74, 0, 25], ["+", 10, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 10, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 10, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 0, 25], ["+", 0, 11, 12, 16, 31, 16, 12, 74, 0, 24], ["+", 0, 11, 12, 16, 31, 16, 12, 74, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 12, 74, 0, 25]]
| 8
| 698
| 28
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5 {
class Program {
static void Main(string[] args) {
String S = Console.ReadLine();
long K = long.Parse(Console.ReadLine());
char[] T = new char[S.Length];
long res = 0;
bool start = false;
int count = 1;
for (int i = 0; i < S.Length; i++) {
T[i] = S[i];
if (i >= 1) {
if (T[i] == T[i - 1]) {
T[i] = 'X';
res++;
}
if (start == false && S[i] == S[i - 1]) {
count++;
} else {
start = true;
}
}
}
res = res * K;
if (T[S.Length - 1] == T[0]) {
res = res + (K - 1);
if (S.Length >= 3) {
if (S[0] == S[1] && count % 2 == 0) {
res = res - (K - 1);
}
}
}
Console.WriteLine(res);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5 {
class Program {
static void Main(string[] args) {
String S = Console.ReadLine();
long K = long.Parse(Console.ReadLine());
char[] T = new char[S.Length];
long res = 0;
bool start = false;
int count = 1;
for (int i = 0; i < S.Length; i++) {
T[i] = S[i];
if (i >= 1) {
if (T[i] == T[i - 1]) {
T[i] = 'X';
res++;
}
if (start == false && S[i] == S[i - 1]) {
count++;
} else {
start = true;
}
}
}
res = res * K;
if (T[S.Length - 1] == T[0]) {
res = res + (K - 1);
if (S.Length >= 3) {
if (S[0] == S[1] && count % 2 == 0) {
res = res - (K - 1);
}
}
}
if (count == S.Length) {
res = S.Length * K / 2;
}
Console.WriteLine(res);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 205, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 0, 131], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 272
| 20
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder {
public class ABC {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
string s = Console.ReadLine();
long k = int.Parse(Console.ReadLine());
string s2;
long ans = 0;
if (k < 4) {
s2 = s;
for (int i = 1; i < k; i++) {
s2 += s;
}
char c = s2[0];
for (int i = 1; i < s2.Length; i++) {
if (c == s2[i]) {
ans++;
c = ' ';
} else {
c = s2[i];
}
}
} else {
int[] cnt = new int[4];
s2 = s + s + s + s;
char c = s2[0];
for (int i = 1; i < s2.Length; i++) {
if (c == s2[i]) {
cnt[i / s.Length]++;
c = ' ';
} else {
c = s2[i];
}
}
long even = k / 2 - (k % 2 == 0 ? 1 : 0);
long odd = k / 2 + k % 2 - 1 - (k % 2 == 0 ? 0 : 1);
// System.Diagnostics.Debug.WriteLine($"cnt[0]{cnt[0]} + cnt[1]{cnt[1]} *
// even{even} + cnt[2]{cnt[2]} * odd{odd} + cnt[3]{cnt[3]}");
ans = cnt[0] + cnt[1] * even + cnt[2] * odd + cnt[3];
}
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder {
public class ABC {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
string s = Console.ReadLine();
long k = int.Parse(Console.ReadLine());
string s2;
long ans = 0;
if (k < 4) {
s2 = s;
for (int i = 1; i < k; i++) {
s2 += s;
}
char c = s2[0];
for (int i = 1; i < s2.Length; i++) {
if (c == s2[i]) {
ans++;
c = ' ';
} else {
c = s2[i];
}
}
} else {
int[] cnt = new int[5];
if (k % 2 == 0) {
s2 = s + s + s + s;
} else {
s2 = s + s + s + s + s;
}
char c = s2[0];
for (int i = 1; i < s2.Length; i++) {
if (c == s2[i]) {
cnt[i / s.Length]++;
c = ' ';
} else {
c = s2[i];
}
}
long even = k / 2 - (k % 2 == 0 ? 1 : 0);
long odd = k / 2 + k % 2 - 1 - (k % 2 == 0 ? 0 : 1);
long last = k % 2 == 0 ? 3 : 4;
// System.Diagnostics.Debug.WriteLine($"cnt[0]{cnt[0]} + cnt[1]{cnt[1]} *
// even{even} + cnt[2]{cnt[2]} * odd{odd} + cnt[{last}]{cnt[last]}");
ans = cnt[0] + cnt[1] * even + cnt[2] * odd + cnt[last];
}
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
|
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 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, 109], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 17, 72], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 212, 0, 41, 15, 16, 31, 16, 31, 22], ["+", 0, 212, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 0, 212, 0, 41, 15, 16, 31, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 60], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 64, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 75, 203], ["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 365
| 42
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1 {
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
public class Class1 {
static void Main(string[] args) {
// string[] s = Console.ReadLine().Split(' ');
string s = Console.ReadLine();
long k = long.Parse(Console.ReadLine());
char[] ch = s.ToCharArray();
if (ch.Length == 1) {
Console.WriteLine(k / 2);
return;
}
long op = 0;
long cnt = 1;
char tmp = ' ';
for (int i = 0; i < ch.Length; i++) {
if (tmp == ch[i]) {
cnt++;
} else {
op += cnt / 2;
cnt = 1;
}
tmp = ch[i];
}
op += cnt / 2;
bool extra = false;
if (ch[0] == ch[ch.Length - 1]) {
int ind = 0;
int lastind = 0;
for (int i = 0; i < ch.Length; i++) {
if (ch[i] != ch[0]) {
ind = i + 1;
break;
}
}
if (ind > 0) {
for (int i = 0; i < ch.Length; i++) {
if (ch[ch.Length - i - 1] != ch[0]) {
lastind = i + 1;
break;
}
}
extra = ((ind + lastind) % 2 == 0);
} else {
extra = (ch.Length % 2 > 0);
}
}
long cc = op * k;
if (extra)
cc += k - 1;
Console.WriteLine(cc);
}
static int rec(int[] n, int i, int j, int x) {
if (i + 1 == j) {
return Math.Min(n[j], x);
}
return rec(n, i + 1, j, n[i]) + rec(n, i, j - 1, n[j]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1 {
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
public class Class1 {
static void Main(string[] args) {
// string[] s = Console.ReadLine().Split(' ');
string s = Console.ReadLine();
long k = long.Parse(Console.ReadLine());
char[] ch = s.ToCharArray();
if (ch.Length == 1) {
Console.WriteLine(k / 2);
return;
}
long op = 0;
long cnt = 1;
char tmp = ' ';
for (int i = 0; i < ch.Length; i++) {
if (tmp == ch[i]) {
cnt++;
} else {
op += cnt / 2;
cnt = 1;
}
tmp = ch[i];
}
op += cnt / 2;
bool extra = false;
if (ch[0] == ch[ch.Length - 1]) {
int ind = 0;
int lastind = 0;
for (int i = 0; i < ch.Length; i++) {
if (ch[i] != ch[0]) {
ind = i + 1;
break;
}
}
if (ind > 0) {
for (int i = 0; i < ch.Length; i++) {
if (ch[ch.Length - i - 1] != ch[0]) {
lastind = i + 1;
break;
}
}
extra = ((ind + lastind) % 2 == 0);
} else {
Console.WriteLine(ch.Length * k / 2);
return;
}
}
long cc = op * k;
if (extra)
cc += k - 1;
Console.WriteLine(cc);
}
static int rec(int[] n, int i, int j, int x) {
if (i + 1 == j) {
return Math.Min(n[j], x);
}
return rec(n, i + 1, j, n[i]) + rec(n, i, j - 1, n[j]);
}
}
}
|
[["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 11, 12, 23, 0, 16, 31, 16, 17, 109], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["-", 0, 1, 0, 11, 12, 23, 0, 16, 17, 47], ["-", 0, 1, 0, 11, 12, 23, 0, 16, 12, 203], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 57, 75, 196, 0, 37, 0, 38]]
| 8
| 459
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;
using PL = Pair<long, int>;
// using static System.Globalization.CultureInfo;
using System.Text;
class Program {
public static bool chmin<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == 1) {
num = val;
return true;
}
return false;
}
public static bool chmax<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == -1) {
num = val;
return true;
}
return false;
}
public static void swap<T>(ref T v1, ref T v2) {
var t = v2;
v2 = v1;
v1 = t;
}
public static void Fail() => Fail("No");
public static void Fail<T>(T s) {
WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var p = new Program();
for (var i = 1; i > 0; --i)
p.Solve();
Console.Out.Flush();
}
void Solve() {
var str = ReadLine();
var k = Input.num;
if (str.All(v => v == str[0]))
Fail(str.Length * (long)k / 2);
var len = 1;
var r = 0L;
for (var i = 1; i < str.Length; i++)
if (str[i] == str[i - 1])
len++;
else {
r += len / 2;
len = 1;
}
r += len / 2;
r *= k;
var q = str + str;
var l = str.Length - 2;
var ri = str.Length;
while (l != -1 && q[l] == str.Last())
l--;
while (ri != q.Length && q[ri] == str.Last())
ri++;
if (k > 1 && (str.Length - 1 - l - 1) % 2 == 1 &&
(ri - str.Length) % 2 == 1)
r += k - 2;
WriteLine(r);
}
}
public class Input {
public static string read => ReadLine().Trim();
public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
public static int num => ToInt32(read);
public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
public static long numL => ToInt64(read);
public static T[] Create<T>(int n, Func<T> f) =>
Enumerable.Repeat(0, n).Select(_ => f()).ToArray();
public static char[][] grid(int h) => Create(h, () => read.ToCharArray());
public static int[] ar1D(int n) => Create(n, () => num);
public static long[] arL1D(int n) => Create(n, () => numL);
public static string[] strs(int n) => Create(n, () => read);
public static int[][] ar2D(int n) => Create(n, () => ar);
public static long[][] arL2D(int n) => Create(n, () => arL);
public static List<T>[] edge<T>(int n) => Create(n, () => new List<T>());
public static void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public static 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 static 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 static 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>();
}
static Input() {
sc = new Queue<string>();
dic = new Dictionary<Type, Func<string, object>>();
dic[typeof(int)] = s => int.Parse(s);
dic[typeof(long)] = s => long.Parse(s);
dic[typeof(char)] = s => char.Parse(s);
dic[typeof(double)] = s => double.Parse(s);
dic[typeof(uint)] = s => uint.Parse(s);
dic[typeof(ulong)] = s => ulong.Parse(s);
dic[typeof(string)] = s => s;
}
private static Dictionary<Type, Func<string, object>> dic;
private static Queue<string> sc;
public static T Next<T>() {
if (sc.Count == 0)
foreach (var item in read.Split(' '))
sc.Enqueue(item);
return (T)dic[typeof(T)](sc.Dequeue());
}
public const int MOD = 1000000007;
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1 { get; set; }
public T2 v2 { get; set; }
public Pair() {
v1 = Input.Next<T1>();
v2 = Input.Next<T2>();
}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
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 Pair<T1, T2, T3> Push<T3>(T3 val) => new Pair<T1, T2, T3>(v1, v2, val);
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public override bool Equals(object obj) => this == (Pair<T1, T2>)obj;
public override int GetHashCode() => v1.GetHashCode() ^ v2.GetHashCode();
public static bool operator ==(Pair<T1, T2> p1,
Pair<T1, T2> p2) => p1.CompareTo(p2) == 0;
public static bool operator !=(Pair<T1, T2> p1,
Pair<T1, T2> p2) => p1.CompareTo(p2) != 0;
public static bool operator>(Pair<T1, T2> p1,
Pair<T1, T2> p2) => p1.CompareTo(p2) == 1;
public static bool operator >=(Pair<T1, T2> p1,
Pair<T1, T2> p2) => p1.CompareTo(p2) != -1;
public static bool operator<(Pair<T1, T2> p1,
Pair<T1, T2> p2) => p1.CompareTo(p2) == -1;
public static bool operator <=(Pair<T1, T2> p1,
Pair<T1, T2> p2) => p1.CompareTo(p2) != 1;
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3 { get; set; }
public Pair() : base() { v3 = Input.Next<T3>(); }
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
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()}";
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;
using PL = Pair<long, int>;
// using static System.Globalization.CultureInfo;
using System.Text;
class Program {
public static bool chmin<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == 1) {
num = val;
return true;
}
return false;
}
public static bool chmax<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == -1) {
num = val;
return true;
}
return false;
}
public static void swap<T>(ref T v1, ref T v2) {
var t = v2;
v2 = v1;
v1 = t;
}
public static void Fail() => Fail("No");
public static void Fail<T>(T s) {
WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var p = new Program();
for (var i = 1; i > 0; --i)
p.Solve();
Console.Out.Flush();
}
void Solve() {
var str = ReadLine();
var k = Input.num;
if (str.All(v => v == str[0]))
Fail(str.Length * (long)k / 2);
var len = 1;
var r = 0L;
for (var i = 1; i < str.Length; i++)
if (str[i] == str[i - 1])
len++;
else {
r += len / 2;
len = 1;
}
r += len / 2;
r *= k;
var q = str + str;
var l = str.Length - 2;
var ri = str.Length;
while (l != -1 && q[l] == str.Last())
l--;
while (ri != q.Length && q[ri] == str.Last())
ri++;
if ((str.Length - 1 - l) % 2 == 1 && (ri - str.Length) % 2 == 1)
r += k - 1;
WriteLine(r);
}
}
public class Input {
public static string read => ReadLine().Trim();
public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
public static int num => ToInt32(read);
public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
public static long numL => ToInt64(read);
public static T[] Create<T>(int n, Func<T> f) =>
Enumerable.Repeat(0, n).Select(_ => f()).ToArray();
public static char[][] grid(int h) => Create(h, () => read.ToCharArray());
public static int[] ar1D(int n) => Create(n, () => num);
public static long[] arL1D(int n) => Create(n, () => numL);
public static string[] strs(int n) => Create(n, () => read);
public static int[][] ar2D(int n) => Create(n, () => ar);
public static long[][] arL2D(int n) => Create(n, () => arL);
public static List<T>[] edge<T>(int n) => Create(n, () => new List<T>());
public static void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public static 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 static 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 static 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>();
}
static Input() {
sc = new Queue<string>();
dic = new Dictionary<Type, Func<string, object>>();
dic[typeof(int)] = s => int.Parse(s);
dic[typeof(long)] = s => long.Parse(s);
dic[typeof(char)] = s => char.Parse(s);
dic[typeof(double)] = s => double.Parse(s);
dic[typeof(uint)] = s => uint.Parse(s);
dic[typeof(ulong)] = s => ulong.Parse(s);
dic[typeof(string)] = s => s;
}
private static Dictionary<Type, Func<string, object>> dic;
private static Queue<string> sc;
public static T Next<T>() {
if (sc.Count == 0)
foreach (var item in read.Split(' '))
sc.Enqueue(item);
return (T)dic[typeof(T)](sc.Dequeue());
}
public const int MOD = 1000000007;
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1 { get; set; }
public T2 v2 { get; set; }
public Pair() {
v1 = Input.Next<T1>();
v2 = Input.Next<T2>();
}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
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 Pair<T1, T2, T3> Push<T3>(T3 val) => new Pair<T1, T2, T3>(v1, v2, val);
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public override bool Equals(object obj) => this == (Pair<T1, T2>)obj;
public override int GetHashCode() => v1.GetHashCode() ^ v2.GetHashCode();
public static bool operator ==(Pair<T1, T2> p1,
Pair<T1, T2> p2) => p1.CompareTo(p2) == 0;
public static bool operator !=(Pair<T1, T2> p1,
Pair<T1, T2> p2) => p1.CompareTo(p2) != 0;
public static bool operator>(Pair<T1, T2> p1,
Pair<T1, T2> p2) => p1.CompareTo(p2) == 1;
public static bool operator >=(Pair<T1, T2> p1,
Pair<T1, T2> p2) => p1.CompareTo(p2) != -1;
public static bool operator<(Pair<T1, T2> p1,
Pair<T1, T2> p2) => p1.CompareTo(p2) == -1;
public static bool operator <=(Pair<T1, T2> p1,
Pair<T1, T2> p2) => p1.CompareTo(p2) != 1;
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3 { get; set; }
public Pair() : base() { v3 = Input.Next<T3>(); }
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
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()}";
}
|
[["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 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], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 1,956
| 8
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
string s = Console.ReadLine();
int n = s.Length;
long k = long.Parse(Console.ReadLine());
long answer = 0;
long answerNo = 0; // 1文字目を変更しない場合
long answerYes = 0;
bool finalChanged = false;
for (int i = 1; i < n; i++) {
if (s[i] == s[i - 1]) {
answerNo++;
if (i == n - 1)
finalChanged = true;
i++;
// Console.WriteLine(i+" a");
}
}
if (!finalChanged && n >= 2 && s[0] == s[n - 1]) //最初の文字を変える
{
finalChanged = false;
answerYes++;
for (int i = 2; i < n; i++) {
if (s[i] == s[i - 1]) {
answerYes++;
if (i == n - 1)
finalChanged = true;
i++;
}
}
if (!finalChanged) //最初の文字を変える
{
answer = answerNo + answerYes * (k - 1);
} else {
if (k % 2 == 0)
answer = answerNo * (k / 2) + answerYes * (k / 2);
else
answer = answerNo * (k / 2 + 1) + answerYes * (k / 2);
}
} else {
answer = answerNo * k;
}
Console.WriteLine(answer);
}
}
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
string s = Console.ReadLine();
int n = s.Length;
long k = long.Parse(Console.ReadLine());
long answer = 0;
long answerNo = 0; // 1文字目を変更しない場合
long answerYes = 0;
bool finalChanged = false;
for (int i = 1; i < n; i++) {
if (s[i] == s[i - 1]) {
answerNo++;
if (i == n - 1)
finalChanged = true;
i++;
// Console.WriteLine(i+" a");
}
}
if (!finalChanged && n >= 2 && s[0] == s[n - 1]) //最初の文字を変える
{
finalChanged = false;
answerYes++;
for (int i = 2; i < n; i++) {
if (s[i] == s[i - 1]) {
answerYes++;
if (i == n - 1)
finalChanged = true;
i++;
}
}
if (!finalChanged) //最初の文字を変える
{
answer = answerNo + answerYes * (k - 1);
} else {
if (k % 2 == 0)
answer = answerNo * (k / 2) + answerYes * (k / 2);
else
answer = answerNo * (k / 2 + 1) + answerYes * (k / 2);
}
} else {
answer = answerNo * k;
}
if (n == 1) {
answer = k / 2;
}
Console.WriteLine(answer);
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 302
| 14
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CP {
public void Solve() {
var N = Int1;
var S = Enumerable.Range(0, N)
.Select(_ => Chars.Select(x => (long)(x - '0')).ToArray())
.ToArray();
if (!Graph.IsBipartiteGraph(Graph.toli(S))) {
Put(-1);
return;
}
var ans = 0L;
var dists = Graph.Warshall_Floyd(Graph.toli(S));
foreach (var x in dists) {
foreach (var item in x) {
ans = Max(ans, item);
}
}
Put(ans + 1);
}
}
public static class Graph {
public static long[] dijkstra(List<Tuple<long, int>>[] edge, int from,
long INF = Math2.INFL) {
long[] ret = Enumerable.Range(0, edge.Length).Select(_ => INF).ToArray();
var pq =
new PriorityQueue<Tuple<long, int>>((a, b) => (int)(a.Item1 - b.Item1));
ret[from] = 0;
pq.Enqueue(new Tuple<long, int>(0, from));
while (pq.Count > 0) {
var p = pq.Dequeue();
var v = p.Item2;
if (ret[v] < p.Item1)
continue;
foreach (var e in edge[v]) {
if (ret[e.Item2] > ret[v] + e.Item1) {
ret[e.Item2] = ret[v] + e.Item1;
pq.Enqueue(new Tuple<long, int>(ret[e.Item2], e.Item2));
}
}
}
return ret;
}
public static long[][] Warshall_Floyd(List<Tuple<long, int>>[] edge) {
var ret = new long [edge.Length][];
for (int i = 0; i < edge.Length; ++i) {
ret[i] = Enumerable.Repeat(INFL, edge.Length).ToArray();
}
for (int i = 0; i < edge.Length; ++i) {
foreach (var x in edge[i]) {
ret[i][x.Item2] = x.Item1;
}
}
for (int k = 0; k < edge.Length; ++k) {
for (int i = 0; i < edge.Length; ++i) {
for (int j = 0; j < edge.Length; ++j) {
ret[i][j] = Min(ret[i][j], ret[i][k] + ret[k][j]);
}
}
}
return ret;
}
public static bool IsBipartiteGraph(List<Tuple<long, int>>[] edge) {
var color = Enumerable.Repeat(-1, edge.Length).ToArray();
Func<int, int, bool> dfs = null;
dfs = (int v, int c) => {
color[v] = c;
foreach (var nv in edge[v]) {
if (color[nv.Item2] == c)
return false;
if (color[nv.Item2] == -1 && !dfs(nv.Item2, 1 - c))
return false;
}
return true;
};
for (int i = 0; i < edge.Length; ++i) {
if (color[i] == -1) {
if (!dfs(i, 0)) {
return false;
}
}
}
return true;
}
public static List<Tuple<long, int>>[] totp(List<int>[] lis) {
var ret = new List<Tuple<long, int>>[lis.Length];
for (int i = 0; i < lis.Length; ++i) {
ret[i] = new List<Tuple<long, int>>();
foreach (var x in lis[i]) {
ret[i].Add(new Tuple<long, int>(1, x));
}
}
return ret;
}
public static long[][] tomat(List<Tuple<long, int>>[] edge) {
var ret = new long [edge.Length][];
for (int i = 0; i < edge.Length; ++i) {
ret[i] = new long[edge.Length];
for (int j = 0; j < edge.Length; ++j) {
ret[i][j] = Math2.INFL;
}
}
for (int i = 0; i < edge.Length; ++i) {
foreach (var x in edge[i]) {
ret[i][x.Item1] = x.Item2;
}
}
return ret;
}
public static List<Tuple<long, int>>[] toli(long[][] s) {
var ret = new List<Tuple<long, int>>[s.Length];
for (int i = 0; i < s.Length; ++i)
ret[i] = new List<Tuple<long, int>>();
for (int i = 0; i < s.Length; ++i) {
for (int j = 0; j < s.Length; ++j) {
if (s[i][j] != 0)
ret[i].Add(new Tuple<long, int>(s[i][j], j));
}
}
return ret;
}
}
public class BinarySearch {
public static int Lower_Bound<T>(IList<T> Array, T Target) {
return Lower_Bound<T>(Array, Target, Comparer<T>.Default.Compare);
}
public static int Lower_Bound<T>(IList<T> Array, T Target,
Comparison<T> Comp) {
var cmp = Comparer<T>.Create(Comp);
var l = -1; // always ng
var r = Array.Count(); // always ok
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(Array[mid], Target);
if (res >= 0)
r = mid;
else
l = mid;
}
return r;
}
public static int Upper_Bound<T>(IList<T> Array, T Target) {
return Upper_Bound<T>(Array, Target, Comparer<T>.Default.Compare);
}
public static int Upper_Bound<T>(IList<T> Array, T Target,
Comparison<T> Comp) {
var cmp = Comparer<T>.Create(Comp);
var l = -1;
var r = Array.Count;
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(Array[mid], Target);
if (res > 0)
r = mid;
else
l = mid;
}
return r;
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Power(long a, long b, long MOD = 1000000007) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
public static long Power2(long a, long b) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
public static long GCD(long a, long b) {
while (b > 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static long LCM(long a, long b) => (b / GCD(a, b)) * a;
public static long Comb(long n, long r, int MOD = 1000000007) {
if (r > n - r)
r = n - r;
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno = (Deno * i) % MOD;
Nume = Nume * (n - i + 1) % MOD;
}
return (Nume * inv(Deno)) % MOD;
}
public static long Comb2(long n, long r) {
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno *= i;
Nume *= n - i + 1;
}
return Nume / Deno;
}
public static long inv(long x, int MOD = 1000000007) {
return Power(x, MOD - 2, MOD);
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
public static string ConvertBase(long N, int K) {
StringBuilder ret = new StringBuilder();
while (N > 0) {
var r = N % K;
N /= K;
ret.Append(r);
}
return new string(ret.ToString().ToCharArray().Reverse().ToArray());
}
}
public class PriorityQueue<T> {
List<T> _item;
public int Count {
get { return _item.Count; }
}
bool _isascend { get; set; }
public T Peek {
get { return _item[0]; }
}
Comparison<T> Comp;
public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null)
: this(Comparer<T>.Default.Compare, IsAscend, list) {}
public PriorityQueue(Comparison<T> cmp, bool IsAscend = true,
IEnumerable<T> list = null) {
_item = new List<T>();
_isascend = IsAscend;
this.Comp = cmp;
if (list != null) {
_item.AddRange(list);
Build();
}
}
private int Compare(int i, int j) => (_isascend ? -1 : 1) *
Comp(_item[i], _item[j]);
private void Swap(int i, int j) {
var t = _item[i];
_item[i] = _item[j];
_item[j] = t;
}
private int Parent(int i) => (i - 1) >> 1;
private int Left(int i) => (i << 1) + 1;
public T Enqueue(T val) {
int i = _item.Count;
_item.Add(val);
while (i > 0) {
int p = Parent(i);
if (Compare(i, p) > 0)
Swap(i, p);
i = p;
}
return val;
}
private void Heapify(int index) {
for (int i = index, j; (j = Left(i)) < _item.Count; i = j) {
if (j != _item.Count - 1 && Compare(j, j + 1) < 0)
j++;
if (Compare(i, j) < 0)
Swap(i, j);
}
}
public T Dequeue() {
T val = _item[0];
_item[0] = _item[_item.Count - 1];
_item.RemoveAt(_item.Count - 1);
Heapify(0);
return val;
}
private void Build() {
for (var i = (_item.Count >> 1) - 1; i >= 0; i--)
Heapify(i);
}
}
class Program {
static void Main(string[] args) {
var CP = new CP();
CP.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] VerticalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Put(string a) => Console.WriteLine(a);
public static void Put(params object[] i) => Put(string.Join(" ", i));
public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a));
public static void VerticalPut<T>(IEnumerable<T> a) {
foreach (var z in a)
Put(z);
}
public static void YN(bool i) {
if (i)
Put("Yes");
else
Put("No");
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CP {
public void Solve() {
var N = Int1;
var S = Enumerable.Range(0, N)
.Select(_ => Chars.Select(x => (long)(x - '0')).ToArray())
.ToArray();
if (!Graph.IsBipartiteGraph(Graph.toli(S))) {
Put(-1);
return;
}
var ans = 0L;
var dists = Graph.Warshall_Floyd(Graph.toli(S));
foreach (var x in dists) {
foreach (var item in x) {
ans = Max(ans, item);
}
}
Put(ans + 1);
}
}
public static class Graph {
public static long[] dijkstra(List<Tuple<long, int>>[] edge, int from,
long INF = Math2.INFL) {
long[] ret = Enumerable.Range(0, edge.Length).Select(_ => INF).ToArray();
var pq =
new PriorityQueue<Tuple<long, int>>((a, b) => (int)(a.Item1 - b.Item1));
ret[from] = 0;
pq.Enqueue(new Tuple<long, int>(0, from));
while (pq.Count > 0) {
var p = pq.Dequeue();
var v = p.Item2;
if (ret[v] < p.Item1)
continue;
foreach (var e in edge[v]) {
if (ret[e.Item2] > ret[v] + e.Item1) {
ret[e.Item2] = ret[v] + e.Item1;
pq.Enqueue(new Tuple<long, int>(ret[e.Item2], e.Item2));
}
}
}
return ret;
}
public static long[][] Warshall_Floyd(List<Tuple<long, int>>[] edge) {
var ret = new long [edge.Length][];
for (int i = 0; i < edge.Length; ++i) {
ret[i] = Enumerable.Repeat(INFL, edge.Length).ToArray();
}
for (int i = 0; i < edge.Length; ++i) {
foreach (var x in edge[i]) {
ret[i][x.Item2] = x.Item1;
}
}
for (int i = 0; i < edge.Length; ++i)
ret[i][i] = 0;
for (int k = 0; k < edge.Length; ++k) {
for (int i = 0; i < edge.Length; ++i) {
for (int j = 0; j < edge.Length; ++j) {
ret[i][j] = Min(ret[i][j], ret[i][k] + ret[k][j]);
}
}
}
return ret;
}
public static bool IsBipartiteGraph(List<Tuple<long, int>>[] edge) {
var color = Enumerable.Repeat(-1, edge.Length).ToArray();
Func<int, int, bool> dfs = null;
dfs = (int v, int c) => {
color[v] = c;
foreach (var nv in edge[v]) {
if (color[nv.Item2] == c)
return false;
if (color[nv.Item2] == -1 && !dfs(nv.Item2, 1 - c))
return false;
}
return true;
};
for (int i = 0; i < edge.Length; ++i) {
if (color[i] == -1) {
if (!dfs(i, 0)) {
return false;
}
}
}
return true;
}
public static List<Tuple<long, int>>[] totp(List<int>[] lis) {
var ret = new List<Tuple<long, int>>[lis.Length];
for (int i = 0; i < lis.Length; ++i) {
ret[i] = new List<Tuple<long, int>>();
foreach (var x in lis[i]) {
ret[i].Add(new Tuple<long, int>(1, x));
}
}
return ret;
}
public static long[][] tomat(List<Tuple<long, int>>[] edge) {
var ret = new long [edge.Length][];
for (int i = 0; i < edge.Length; ++i) {
ret[i] = new long[edge.Length];
for (int j = 0; j < edge.Length; ++j) {
ret[i][j] = Math2.INFL;
}
}
for (int i = 0; i < edge.Length; ++i) {
foreach (var x in edge[i]) {
ret[i][x.Item1] = x.Item2;
}
}
return ret;
}
public static List<Tuple<long, int>>[] toli(long[][] s) {
var ret = new List<Tuple<long, int>>[s.Length];
for (int i = 0; i < s.Length; ++i)
ret[i] = new List<Tuple<long, int>>();
for (int i = 0; i < s.Length; ++i) {
for (int j = 0; j < s.Length; ++j) {
if (s[i][j] != 0)
ret[i].Add(new Tuple<long, int>(s[i][j], j));
}
}
return ret;
}
}
public class BinarySearch {
public static int Lower_Bound<T>(IList<T> Array, T Target) {
return Lower_Bound<T>(Array, Target, Comparer<T>.Default.Compare);
}
public static int Lower_Bound<T>(IList<T> Array, T Target,
Comparison<T> Comp) {
var cmp = Comparer<T>.Create(Comp);
var l = -1; // always ng
var r = Array.Count(); // always ok
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(Array[mid], Target);
if (res >= 0)
r = mid;
else
l = mid;
}
return r;
}
public static int Upper_Bound<T>(IList<T> Array, T Target) {
return Upper_Bound<T>(Array, Target, Comparer<T>.Default.Compare);
}
public static int Upper_Bound<T>(IList<T> Array, T Target,
Comparison<T> Comp) {
var cmp = Comparer<T>.Create(Comp);
var l = -1;
var r = Array.Count;
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(Array[mid], Target);
if (res > 0)
r = mid;
else
l = mid;
}
return r;
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Power(long a, long b, long MOD = 1000000007) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
public static long Power2(long a, long b) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
public static long GCD(long a, long b) {
while (b > 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static long LCM(long a, long b) => (b / GCD(a, b)) * a;
public static long Comb(long n, long r, int MOD = 1000000007) {
if (r > n - r)
r = n - r;
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno = (Deno * i) % MOD;
Nume = Nume * (n - i + 1) % MOD;
}
return (Nume * inv(Deno)) % MOD;
}
public static long Comb2(long n, long r) {
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno *= i;
Nume *= n - i + 1;
}
return Nume / Deno;
}
public static long inv(long x, int MOD = 1000000007) {
return Power(x, MOD - 2, MOD);
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
public static string ConvertBase(long N, int K) {
StringBuilder ret = new StringBuilder();
while (N > 0) {
var r = N % K;
N /= K;
ret.Append(r);
}
return new string(ret.ToString().ToCharArray().Reverse().ToArray());
}
}
public class PriorityQueue<T> {
List<T> _item;
public int Count {
get { return _item.Count; }
}
bool _isascend { get; set; }
public T Peek {
get { return _item[0]; }
}
Comparison<T> Comp;
public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null)
: this(Comparer<T>.Default.Compare, IsAscend, list) {}
public PriorityQueue(Comparison<T> cmp, bool IsAscend = true,
IEnumerable<T> list = null) {
_item = new List<T>();
_isascend = IsAscend;
this.Comp = cmp;
if (list != null) {
_item.AddRange(list);
Build();
}
}
private int Compare(int i, int j) => (_isascend ? -1 : 1) *
Comp(_item[i], _item[j]);
private void Swap(int i, int j) {
var t = _item[i];
_item[i] = _item[j];
_item[j] = t;
}
private int Parent(int i) => (i - 1) >> 1;
private int Left(int i) => (i << 1) + 1;
public T Enqueue(T val) {
int i = _item.Count;
_item.Add(val);
while (i > 0) {
int p = Parent(i);
if (Compare(i, p) > 0)
Swap(i, p);
i = p;
}
return val;
}
private void Heapify(int index) {
for (int i = index, j; (j = Left(i)) < _item.Count; i = j) {
if (j != _item.Count - 1 && Compare(j, j + 1) < 0)
j++;
if (Compare(i, j) < 0)
Swap(i, j);
}
}
public T Dequeue() {
T val = _item[0];
_item[0] = _item[_item.Count - 1];
_item.RemoveAt(_item.Count - 1);
Heapify(0);
return val;
}
private void Build() {
for (var i = (_item.Count >> 1) - 1; i >= 0; i--)
Heapify(i);
}
}
class Program {
static void Main(string[] args) {
var CP = new CP();
CP.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] VerticalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Put(string a) => Console.WriteLine(a);
public static void Put(params object[] i) => Put(string.Join(" ", i));
public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a));
public static void VerticalPut<T>(IEnumerable<T> a) {
foreach (var z in a)
Put(z);
}
public static void YN(bool i) {
if (i)
Put("Yes");
else
Put("No");
}
}
|
[["+", 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], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 241, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 241, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 8, 1, 0, 11, 31, 204, 205, 204, 205, 22], ["+", 0, 11, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 8, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 8, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 7, 8, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 8, 1, 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
| 2,978
| 26
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder {
class AC {
const int mod = 1000000007;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
static int[] dx = { 0, 1, 0, -1 };
static int[] dy = { 1, 0, -1, 0 };
static int N;
static Queue<Edge> Q = new Queue<Edge>();
static List<List<int>> G = new List<List<int>>();
static bool ok = true;
static void Main(string[] args) {
// var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
// false }; Console.SetOut(sw);
var cin = new Scanner();
N = int.Parse(Console.ReadLine());
long ans = -1;
for (var i = 0; i < N; i++) {
G.Add(new List<int>());
}
for (var i = 0; i < N; i++) {
var s = Console.ReadLine();
for (var j = 0; j < N; j++) {
if (s[j] == '1') {
G[i].Add(j);
}
}
}
for (var i = 0; i < N; i++) {
int[] num = new int[N];
Initialize(ref num, -1);
num[i] = 1;
foreach (var x in G[i]) {
Q.Enqueue(new Edge(i, x));
}
while (Q.Count() > 0) {
int f = Q.Peek().from;
int t = Q.Dequeue().to;
Console.WriteLine($"{f} {t}");
if (num[t] != -1) {
if (Abs(num[f] - num[t]) != 1) {
ok = false;
break;
}
} else {
num[t] = num[f] + 1;
foreach (var x in G[t]) {
Q.Enqueue(new Edge(t, x));
}
}
}
if (!ok) {
Console.WriteLine(-1);
return;
}
ans = Max(ans, num.Max());
}
Console.WriteLine(ans);
// Console.Out.Flush();
}
struct Edge {
public int from;
public int to;
public Edge(int f, int t) {
from = f;
to = t;
}
}
}
public class Scanner {
public int[] SplitRead() {
int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
return array;
}
public long[] SplitReadL() {
long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
return array;
}
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
for (var i = 0; i < array.Length; i++) {
array[i] = initialvalue;
}
}
static public long Modulo(long value, long mod) {
long r = value % mod;
if (r * mod < 0) {
r += mod;
}
return r;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder {
class AC {
const int mod = 1000000007;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
static int[] dx = { 0, 1, 0, -1 };
static int[] dy = { 1, 0, -1, 0 };
static int N;
static Queue<Edge> Q = new Queue<Edge>();
static List<List<int>> G = new List<List<int>>();
static bool ok = true;
static void Main(string[] args) {
// var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
// false }; Console.SetOut(sw);
var cin = new Scanner();
N = int.Parse(Console.ReadLine());
long ans = -1;
for (var i = 0; i < N; i++) {
G.Add(new List<int>());
}
for (var i = 0; i < N; i++) {
var s = Console.ReadLine();
for (var j = 0; j < N; j++) {
if (s[j] == '1') {
G[i].Add(j);
}
}
}
for (var i = 0; i < N; i++) {
int[] num = new int[N];
Initialize(ref num, -1);
num[i] = 1;
foreach (var x in G[i]) {
Q.Enqueue(new Edge(i, x));
}
while (Q.Count() > 0) {
int f = Q.Peek().from;
int t = Q.Dequeue().to;
// Console.WriteLine($"{f} {t}");
if (num[t] != -1) {
if (Abs(num[f] - num[t]) != 1) {
ok = false;
break;
}
} else {
num[t] = num[f] + 1;
foreach (var x in G[t]) {
Q.Enqueue(new Edge(t, x));
}
}
}
if (!ok) {
Console.WriteLine(-1);
return;
}
ans = Max(ans, num.Max());
}
Console.WriteLine(ans);
// Console.Out.Flush();
}
struct Edge {
public int from;
public int to;
public Edge(int f, int t) {
from = f;
to = t;
}
}
}
public class Scanner {
public int[] SplitRead() {
int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
return array;
}
public long[] SplitReadL() {
long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
return array;
}
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
for (var i = 0; i < array.Length; i++) {
array[i] = initialvalue;
}
}
static public long Modulo(long value, long mod) {
long r = value % mod;
if (r * mod < 0) {
r += mod;
}
return r;
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
| 8
| 721
| 15
|
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
public static class P {
static int n;
public static void Main() {
int n = int.Parse(Console.ReadLine());
var matrix =
Enumerable.Repeat(0, n).Select(_ => Console.ReadLine()).ToArray();
int res = 0;
for (int target = 0; target < n; target++) {
var arrivedStep = new int[n];
Queue<State> queue = new Queue<State>();
queue.Enqueue(new State() { Pos = target, Step = 1 });
while (queue.Count > 0) {
var state = queue.Dequeue();
for (int i = 0; i < n; i++) {
if (matrix[state.Pos][i] == '0')
continue;
if (arrivedStep[i] != 0 && arrivedStep[i] < state.Step - 1)
goto end;
if (arrivedStep[i] != 0)
continue;
arrivedStep[i] = state.Step + 1;
queue.Enqueue(new State() { Pos = i, Step = state.Step + 1 });
}
}
res = Max(res, arrivedStep.Max());
end:;
}
Console.WriteLine(res == 0 ? -1 : res);
}
}
struct State {
public int Pos;
public int Step;
}
|
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
public static class P {
static int n;
public static void Main() {
int n = int.Parse(Console.ReadLine());
var matrix =
Enumerable.Repeat(0, n).Select(_ => Console.ReadLine()).ToArray();
int res = 0;
for (int target = 0; target < n; target++) {
var arrivedStep = new int[n];
Queue<State> queue = new Queue<State>();
queue.Enqueue(new State() { Pos = target, Step = 1 });
arrivedStep[target] = 1;
while (queue.Count > 0) {
var state = queue.Dequeue();
for (int i = 0; i < n; i++) {
if (matrix[state.Pos][i] == '0')
continue;
if (arrivedStep[i] != 0 &&
(arrivedStep[i] < state.Step - 1 || arrivedStep[i] == state.Step))
goto end;
if (arrivedStep[i] != 0)
continue;
arrivedStep[i] = state.Step + 1;
queue.Enqueue(new State() { Pos = i, Step = state.Step + 1 });
}
}
res = Max(res, arrivedStep.Max());
end:;
}
Console.WriteLine(res == 0 ? -1 : res);
}
}
struct State {
public int Pos;
public int Step;
}
|
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 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, 22], ["+", 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, 22], ["+", 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
| 369
| 18
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace program {
class Program {
static void Main() {
var n = Input.ScanDouble();
Out(1 / n);
}
static public void Out(object s) { Console.Write($"{s} "); }
}
static class Input {
static public int ScanInt() { return int.Parse(Console.ReadLine()); }
static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
static public long ScanLong() { return long.Parse(Console.ReadLine()); }
static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
static public int[] ScanIntArray() {
return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
static public uint[] ScanUintArray() {
return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray();
}
static public double[] ScanDoubleArray() {
return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray();
}
static public long[] ScanLongArray() {
return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
static public ulong[] ScanUlongArray() {
return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray();
}
static public string ScanStr() { return Console.ReadLine(); }
static public string[] ScanStrArray() { return ScanStr().Split(); }
}
static class MyMath {
public static int GCD(int a, int b) {
Func<int, int, int> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static long GCD(long a, long b) {
Func<long, long, long> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
var d = extGCD(b, a % b, ref y, ref x);
y -= a / b * x;
return d;
}
public static int LCM(int a, int b) { return a * b / GCD(a, b); }
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace program {
class Program {
static void Main() {
var n = Input.ScanInt();
int k = (n + 1) / 2;
Out((double)k / n);
}
static public void Out(object s) { Console.Write($"{s} "); }
}
static class Input {
static public int ScanInt() { return int.Parse(Console.ReadLine()); }
static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
static public long ScanLong() { return long.Parse(Console.ReadLine()); }
static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
static public int[] ScanIntArray() {
return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
static public uint[] ScanUintArray() {
return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray();
}
static public double[] ScanDoubleArray() {
return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray();
}
static public long[] ScanLongArray() {
return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
static public ulong[] ScanUlongArray() {
return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray();
}
static public string ScanStr() { return Console.ReadLine(); }
static public string[] ScanStrArray() { return ScanStr().Split(); }
}
static class MyMath {
public static int GCD(int a, int b) {
Func<int, int, int> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static long GCD(long a, long b) {
Func<long, long, long> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
var d = extGCD(b, a % b, ref y, ref x);
y -= a / b * x;
return d;
}
public static int LCM(int a, int b) { return a * b / GCD(a, b); }
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 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, 74, 51, 22]]
| 8
| 650
| 18
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var n = ReadInt();
if (n == 1)
WriteLine(1);
else if (n % 2 != 0) {
WriteLine(3.0 / n);
} else {
WriteLine(2.0 / n);
}
}
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.IO;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var n = ReadInt();
var old = 0.0;
for (int i = 1; i <= n; i++) {
if (i % 2 != 0)
old++;
}
WriteLine(old / n);
}
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, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 57, 64, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 250], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 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, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["-", 75, 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, 16, 31, 250], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["-", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 8, 196, 0, 57, 75, 57, 75, 196, 0, 46]]
| 8
| 274
| 42
|
using System;
namespace ABC142 {
class Program {
static void Main(string[] args) {
var N = decimal.Parse(Console.ReadLine());
decimal count = 0;
for (int i = 1; i <= N; i++) {
var flg = i % 2 == 1;
if (flg) {
count++;
}
}
var result = count / N;
Console.WriteLine(result);
Console.ReadKey();
Console.WriteLine("Hello World!");
}
}
}
|
using System;
namespace ABC142 {
class Program {
static void Main(string[] args) {
var N = decimal.Parse(Console.ReadLine());
decimal count = 0;
for (int i = 1; i <= N; i++) {
var flg = i % 2 == 1;
if (flg) {
count++;
}
}
var result = count / N;
Console.WriteLine(result);
Console.ReadKey();
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 104
| 9
|
using System;
class Program {
static void Main(string[] args) {
//// 整数の入力
// int a = int.Parse(Console.ReadLine());
//// スペース区切りの整数の入力
// string[] input = Console.ReadLine().Split(' ');
// int b = int.Parse(input[0]);
// int c = int.Parse(input[1]);
//// 文字列の入力
// string s = Console.ReadLine();
////出力
// Console.WriteLine((a + b + c) + " " + s);
int a = int.Parse(Console.ReadLine());
float answer = 0;
if (a % 2 != 0) {
answer = (a - a / 2) / (float)a;
} else {
answer = 0.5f;
}
}
}
|
using System;
class Program {
static void Main(string[] args) {
//// 整数の入力
// int a = int.Parse(Console.ReadLine());
//// スペース区切りの整数の入力
// string[] input = Console.ReadLine().Split(' ');
// int b = int.Parse(input[0]);
// int c = int.Parse(input[1]);
//// 文字列の入力
// string s = Console.ReadLine();
////出力
// Console.WriteLine((a + b + c) + " " + s);
int a = int.Parse(Console.ReadLine());
float answer = 0;
if (a % 2 != 0) {
answer = (a - a / 2) / (float)a;
} else {
answer = 0.5f;
}
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
| 79
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC141 {
class B {
static void Main(string[] args) {
string S = Console.ReadLine();
bool flag = true;
for (int i = 0; i < S.Length; i++) {
if (i / 2 == 0 && S[i] == 'L') {
flag = false;
break;
}
if (i / 2 == 1 && S[i] == 'R') {
flag = false;
break;
}
}
if (flag) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC141 {
class B {
static void Main(string[] args) {
string S = Console.ReadLine();
bool flag = true;
for (int i = 0; i < S.Length; i++) {
if (i % 2 == 0 && S[i].Equals('L')) {
flag = false;
break;
}
if (i % 2 == 1 && S[i].Equals('R')) {
flag = false;
break;
}
}
if (flag) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 85], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 109], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 155
| 14
|
using System;
class Program {
static void Main(string[] args) {
string anser = "Yes";
// 整数の入力
string S = Console.ReadLine();
char[] a = { 'R', 'U', 'D' };
char[] b = { 'L', 'U', 'D' };
for (int i = 0; i < S.Length; i++) {
if (i % 2 == 0) {
Console.WriteLine(S[i]);
Console.WriteLine(Array.IndexOf(a, S[i]));
if (Array.IndexOf(a, S[i]) < 0) {
anser = "No";
break;
}
} else {
if (Array.IndexOf(b, S[i]) < 0) {
anser = "No";
break;
}
}
}
Console.WriteLine(anser);
}
}
|
using System;
class Program {
static void Main(string[] args) {
string anser = "Yes";
// 整数の入力
string S = Console.ReadLine();
char[] a = { 'R', 'U', 'D' };
char[] b = { 'L', 'U', 'D' };
for (int i = 0; i < S.Length; i++) {
if (i % 2 == 0) {
if (Array.IndexOf(a, S[i]) < 0) {
anser = "No";
break;
}
} else {
if (Array.IndexOf(b, S[i]) < 0) {
anser = "No";
break;
}
}
}
Console.WriteLine(anser);
}
}
|
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 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, 21], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 190
| 27
|
using System;
namespace pro {
class MainClass {
public static void Main() {
string s = Console.ReadLine();
bool b = true;
for (int i = 0; i < s.Length - 1; i += 2) {
if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D') {
} else {
b = false;
}
}
for (int i = 1; i < s.Length - 1; i += 2) {
if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D') {
} else {
b = false;
}
}
if (b) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
namespace pro {
class MainClass {
public static void Main() {
string s = Console.ReadLine();
bool b = true;
for (int i = 0; i < s.Length - 1; i += 2) {
if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D') {
} else {
b = false;
}
}
for (int i = 1; i < s.Length - 1; i += 2) {
if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D') {
} else {
b = false;
}
}
if (s.Length == 1 && s[0] == 'L') {
Console.WriteLine("No");
} else if (b) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 31, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 16, 31, 214, 141, 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, 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, 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, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24]]
| 8
| 178
| 29
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
#if DEBUG
// MyDebugger.MakeTestCase("../TextFile2.txt");
MyDebugger.Test(process, "../TextFile1.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
static object process(TextReader input) {
var s = input.ReadLine();
var ch1 = true;
var ch2 = true;
for (int i = 0; i < s.Length; i++) {
char c = s[i];
if (i % 2 == 0) {
ch1 &= (c == 'R' || c == 'U' || c == 'D');
} else {
ch2 &= (c == 'L' || c == 'U' || c == 'D');
}
}
if (ch1 && (s.Length >= 2 && ch2)) {
return "Yes";
} else {
return "No";
}
}
}
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
#if DEBUG
// MyDebugger.MakeTestCase("../TextFile2.txt");
MyDebugger.Test(process, "../TextFile1.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
static object process(TextReader input) {
var s = input.ReadLine();
var ch1 = true;
var ch2 = true;
for (int i = 0; i < s.Length; i++) {
char c = s[i];
if (i % 2 == 0) {
ch1 &= (c == 'R' || c == 'U' || c == 'D');
} else {
ch2 &= (c == 'L' || c == 'U' || c == 'D');
}
}
if (ch1 && ch2) {
return "Yes";
} else {
return "No";
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["-", 12, 23, 0, 16, 31, 16, 31, 214, 205, 22], ["-", 12, 23, 0, 16, 31, 16, 31, 214, 0, 131], ["-", 12, 23, 0, 16, 31, 16, 31, 214, 141, 22], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 17, 20], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
| 8
| 227
| 8
|
using System;
class Program {
static void Main(string[] args) {
//スペース区切りの整数の入力
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
int q = int.Parse(input[2]);
int allsum = (n - 1) * q;
int[] array = new int[n];
int i = 0;
for (i = 0; i < q; i++) {
int num = int.Parse(Console.ReadLine());
array[num + 1]++;
}
int j = 0;
for (j = 0; j < n; j++) {
if (q - array[j] < k) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
//スペース区切りの整数の入力
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
int q = int.Parse(input[2]);
int allsum = (n - 1) * q;
int[] array = new int[n];
int i = 0;
for (i = 0; i < q; i++) {
int num = int.Parse(Console.ReadLine());
array[num - 1]++;
}
int j = 0;
for (j = 0; j < n; j++) {
if (q - array[j] < k) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33]]
| 8
| 194
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Contest {
class Program {
static void Main() {
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int personCount = input[0];
int point = input[1];
int quizCount = input[2];
int[] person = new int[personCount];
for (int i = 0; i < quizCount; i++) {
int a = int.Parse(Console.ReadLine());
person[a - 1]++;
}
foreach (var p in person) {
if (p - point <= 0) {
Console.WriteLine("No");
} else {
Console.WriteLine("Yes");
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Contest {
class Program {
static void Main() {
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int personCount = input[0];
int point = input[1];
int quizCount = input[2];
int[] person = new int[personCount];
for (int i = 0; i < person.Length; i++) {
person[i] += point - quizCount;
}
for (int i = 0; i < quizCount; i++) {
int a = int.Parse(Console.ReadLine());
person[a - 1]++;
}
foreach (var p in person) {
if (p <= 0) {
Console.WriteLine("No");
} else {
Console.WriteLine("Yes");
}
}
}
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 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], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 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], ["+", 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, 57, 15, 16, 31, 16, 17, 33], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22]]
| 8
| 169
| 29
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace SplitLength {
class Program {
static void Main(string[] args) {
var array = Console.ReadLine().Split().Select(int.Parse).ToArray();
var N = array[0];
var M = array[1];
var priceArray = Console.ReadLine().Split().Select(int.Parse).ToArray();
var queue = new PriorityQueue<decimal, decimal>(d => d);
for (int i = 0; i < priceArray.Length; i++) {
queue.Enqueue(priceArray[i]);
}
for (int i = 0; i < M; i++) {
var max = queue.Dequeue();
queue.Enqueue(max / 2);
}
Console.WriteLine(queue.Sum(_ => Math.Floor(_)));
}
public class PriorityQueue<TKey, TValue> : IEnumerable<TValue>
where TKey : IComparable<TKey> {
private readonly bool _isDescending;
private readonly List<KeyValuePair<TKey, TValue>> _data;
private readonly Func<TValue, TKey> _keySelector;
public PriorityQueue(Func<TValue, TKey> keySelector,
bool isDescending = true) {
_isDescending = isDescending;
_keySelector = keySelector;
}
public void Enqueue(TValue item) {
_data.Add(new KeyValuePair<TKey, TValue>(_keySelector(item), item));
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex].Key, _data[parentIndex].Key) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public TValue Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild].Key, _data[childIndex].Key) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex].Key, _data[childIndex].Key) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem.Value;
}
public TValue Peek() { return _data[0].Value; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(TKey a, TKey b) {
return _isDescending ? b.CompareTo(a) : a.CompareTo(b);
}
public int Count => _data.Count;
public IEnumerator<TValue> GetEnumerator() {
return _data.Select(r => r.Value).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class PriorityQueue<T> : IEnumerable<T>
where T : IComparable<T> {
private readonly bool _isDescending;
private readonly List<T> _data;
public PriorityQueue(bool isDescending = true) : this(0, isDescending) {}
public PriorityQueue(int capacity, bool isDescending = true) {
_data = new List<T>(capacity);
_isDescending = isDescending;
}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? b.CompareTo(a) : a.CompareTo(b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace SplitLength {
class Program {
static void Main(string[] args) {
var array = Console.ReadLine().Split().Select(int.Parse).ToArray();
var N = array[0];
var M = array[1];
var priceArray = Console.ReadLine().Split().Select(int.Parse).ToArray();
var queue = new PriorityQueue<decimal, decimal>(d => d);
for (int i = 0; i < priceArray.Length; i++) {
queue.Enqueue(priceArray[i]);
}
for (int i = 0; i < M; i++) {
var max = queue.Dequeue();
queue.Enqueue(max / 2);
}
Console.WriteLine(queue.Sum(_ => Math.Floor(_)));
}
public class PriorityQueue<TKey, TValue> : IEnumerable<TValue>
where TKey : IComparable<TKey> {
private readonly bool _isDescending;
private readonly List<KeyValuePair<TKey, TValue>> _data;
private readonly Func<TValue, TKey> _keySelector;
public PriorityQueue(Func<TValue, TKey> keySelector,
bool isDescending = true) {
_isDescending = isDescending;
_keySelector = keySelector;
_data = new List<KeyValuePair<TKey, TValue>>();
}
public void Enqueue(TValue item) {
_data.Add(new KeyValuePair<TKey, TValue>(_keySelector(item), item));
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex].Key, _data[parentIndex].Key) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public TValue Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild].Key, _data[childIndex].Key) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex].Key, _data[childIndex].Key) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem.Value;
}
public TValue Peek() { return _data[0].Value; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(TKey a, TKey b) {
return _isDescending ? b.CompareTo(a) : a.CompareTo(b);
}
public int Count => _data.Count;
public IEnumerator<TValue> GetEnumerator() {
return _data.Select(r => r.Value).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class PriorityQueue<T> : IEnumerable<T>
where T : IComparable<T> {
private readonly bool _isDescending;
private readonly List<T> _data;
public PriorityQueue(bool isDescending = true) : this(0, isDescending) {}
public PriorityQueue(int capacity, bool isDescending = true) {
_data = new List<T>(capacity);
_isDescending = isDescending;
}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? b.CompareTo(a) : a.CompareTo(b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
}
|
[["+", 0, 263, 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, 230, 0, 228], ["+", 0, 1, 0, 11, 12, 230, 39, 236, 141, 22], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 18], ["+", 12, 230, 39, 236, 237, 238, 0, 236, 141, 22], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 18], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 22], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 21], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 47], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 47], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 25], ["+", 8, 201, 0, 263, 8, 196, 0, 1, 0, 35]]
| 8
| 1,041
| 15
|
using System;
using System.Collections;
using System.Collections.Generic;
using static Exter;
using System.Linq;
#if DEBUG
#else
using console = System.Console;
#endif
public class App {
public static void Main(string[] args) {
int n, m;
{
var r = console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
n = r[0];
m = r[1];
}
var pq = new PriorityQueue<int>();
foreach (var v in console.ReadLine().Split().Select(v => int.Parse(v)))
pq.Push(v);
for (int i = 0; i < m; i++)
pq.Push(pq.Pop() / 2);
cout = pq.Sum();
}
}
public class PriorityQueue<T> : IEnumerable<T>
where T : IComparable {
List<T> buffer = new List<T>();
static void PushHeap(List<T> array, T elem) {
int n = array.Count;
array.Add(elem);
while (n != 0) {
int i = (n - 1) / 2;
if (array[n].CompareTo(array[i]) > 0) {
T tmp = array[n];
array[n] = array[i];
array[i] = tmp;
}
n = i;
}
}
static void PopHeap(List<T> array) {
int n = array.Count - 1;
array[0] = array[n];
array.RemoveAt(array.Count - 1);
for (int i = 0, j; (j = 2 * i + 1) < n;) {
if ((j != n - 1) && (array[j].CompareTo(array[j + 1]) < 0))
j++;
if (array[i].CompareTo(array[j]) < 0) {
T tmp = array[j];
array[j] = array[i];
array[i] = tmp;
}
i = j;
}
}
public int Count {
get { return buffer.Count; }
}
public void Push(T elem) { PushHeap(this.buffer, elem); }
public T Peek() { return buffer[0]; }
public T Pop() {
T a = buffer[0];
PopHeap(this.buffer);
return a;
}
public IEnumerator<T> GetEnumerator() {
var v = new List<T>(buffer);
while (v.Count != 0) {
yield return v[0];
PopHeap(v);
}
}
IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
}
public class Power {
public int Base;
private List<long> Value = new List<long>();
public Power(int v) {
if (v == 1)
new ArgumentOutOfRangeException();
long prev = -1;
long g = v;
Base = v;
while (g > prev) {
Value.Add(g);
prev = g;
g *= g;
}
}
public long GetEntry(int exponent) {
long s = 1;
for (int i = 0; (1 << i) <= exponent; i++) {
if ((exponent & (1 << i)) != 0) {
s *= Value[i];
}
}
return s;
}
}
public static class Exter {
public class Point {
public Point(int cx, int cy) {
x = cx;
y = cy;
}
public int x;
public int y;
}
public static IEnumerable<Result>
ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b,
Func<T1, T2, Result> f) {
foreach (var v in a) {
foreach (var w in b)
yield return f(v, w);
}
}
public static IEnumerable<Result>
ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b,
Func<T1, T2, Result> f, Func<T1, T2, bool> s) {
foreach (var v in a) {
foreach (var w in b)
if (s(v, w))
yield return f(v, w);
}
}
public static int ToInt(this long v) => (int)v;
public static int ToInt(this string v) => int.Parse(v);
public static int Max(params int[] p) => p.Max();
public static long Max(params long[] p) => p.Max();
public static int Min(params int[] p) => p.Min();
public static long Min(params long[] p) => p.Min();
public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static int GcdRecursive(int a,
int b) => b == 0 ? a : GcdRecursive(b, a % b);
public static object cout {
set {
console.Write(value.ToString());
console.WriteLine();
}
}
public static void ToCout<t>(this IEnumerable<t> v) {
cout = string.Join(",", v);
}
public static long[] readarr {
get {
preadarr =
console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
return preadarr;
}
}
public static long[] preadarr;
}
#if DEBUG
public static class console {
static int cursorLine = 0;
static readonly string[] cin = new string[] { "3 3", "2 13 8" };
static public string ReadLine() { return cin[cursorLine++]; }
static public void WriteLine() { Console.WriteLine(); }
static public void WriteLine<T>(T input) { Console.WriteLine(input); }
static public void Write<T>(T input) { Console.Write(input); }
static public void WriteLine(string s, params object[] arr) {
Console.WriteLine(s, arr);
}
}
#endif
|
using System;
using System.Collections;
using System.Collections.Generic;
using static Exter;
using System.Linq;
#if DEBUG
#else
using console = System.Console;
#endif
public class App {
public static void Main(string[] args) {
int n, m;
{
var r = console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
n = r[0];
m = r[1];
}
var pq = new PriorityQueue<int>();
foreach (var v in console.ReadLine().Split().Select(v => int.Parse(v)))
pq.Push(v);
for (int i = 0; i < m; i++)
pq.Push(pq.Pop() / 2);
long sum = 0;
while (pq.Count != 0)
sum += pq.Pop();
cout = sum;
}
}
public class PriorityQueue<T> : IEnumerable<T>
where T : IComparable {
List<T> buffer = new List<T>();
static void PushHeap(List<T> array, T elem) {
int n = array.Count;
array.Add(elem);
while (n != 0) {
int i = (n - 1) / 2;
if (array[n].CompareTo(array[i]) > 0) {
T tmp = array[n];
array[n] = array[i];
array[i] = tmp;
}
n = i;
}
}
static void PopHeap(List<T> array) {
int n = array.Count - 1;
array[0] = array[n];
array.RemoveAt(array.Count - 1);
for (int i = 0, j; (j = 2 * i + 1) < n;) {
if ((j != n - 1) && (array[j].CompareTo(array[j + 1]) < 0))
j++;
if (array[i].CompareTo(array[j]) < 0) {
T tmp = array[j];
array[j] = array[i];
array[i] = tmp;
}
i = j;
}
}
public int Count {
get { return buffer.Count; }
}
public void Push(T elem) { PushHeap(this.buffer, elem); }
public T Peek() { return buffer[0]; }
public T Pop() {
T a = buffer[0];
PopHeap(this.buffer);
return a;
}
public IEnumerator<T> GetEnumerator() {
var v = new List<T>(buffer);
while (v.Count != 0) {
yield return v[0];
PopHeap(v);
}
}
IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
}
public class Power {
public int Base;
private List<long> Value = new List<long>();
public Power(int v) {
if (v == 1)
new ArgumentOutOfRangeException();
long prev = -1;
long g = v;
Base = v;
while (g > prev) {
Value.Add(g);
prev = g;
g *= g;
}
}
public long GetEntry(int exponent) {
long s = 1;
for (int i = 0; (1 << i) <= exponent; i++) {
if ((exponent & (1 << i)) != 0) {
s *= Value[i];
}
}
return s;
}
}
public static class Exter {
public class Point {
public Point(int cx, int cy) {
x = cx;
y = cy;
}
public int x;
public int y;
}
public static IEnumerable<Result>
ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b,
Func<T1, T2, Result> f) {
foreach (var v in a) {
foreach (var w in b)
yield return f(v, w);
}
}
public static IEnumerable<Result>
ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b,
Func<T1, T2, Result> f, Func<T1, T2, bool> s) {
foreach (var v in a) {
foreach (var w in b)
if (s(v, w))
yield return f(v, w);
}
}
public static int ToInt(this long v) => (int)v;
public static int ToInt(this string v) => int.Parse(v);
public static int Max(params int[] p) => p.Max();
public static long Max(params long[] p) => p.Max();
public static int Min(params int[] p) => p.Min();
public static long Min(params long[] p) => p.Min();
public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static int GcdRecursive(int a,
int b) => b == 0 ? a : GcdRecursive(b, a % b);
public static object cout {
set {
console.Write(value.ToString());
console.WriteLine();
}
}
public static void ToCout<t>(this IEnumerable<t> v) {
cout = string.Join(",", v);
}
public static long[] readarr {
get {
preadarr =
console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
return preadarr;
}
}
public static long[] preadarr;
}
#if DEBUG
public static class console {
static int cursorLine = 0;
static readonly string[] cin = new string[] { "3 3", "2 13 8" };
static public string ReadLine() { return cin[cursorLine++]; }
static public void WriteLine() { Console.WriteLine(); }
static public void WriteLine<T>(T input) { Console.WriteLine(input); }
static public void Write<T>(T input) { Console.Write(input); }
static public void WriteLine(string s, params object[] arr) {
Console.WriteLine(s, arr);
}
}
#endif
|
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["+", 8, 196, 0, 52, 8, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 8, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 8, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 52, 8, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22]]
| 8
| 1,310
| 21
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var input1 = Console.ReadLine();
var N = int.Parse(input1.Split(' ')[0]);
var M = int.Parse(input1.Split(' ')[1]);
var input2 = Console.ReadLine().Split(' ');
var prices = new List<Int64>();
input2.ToList().ForEach(x => prices.Add(Int64.Parse(x)));
prices.Sort();
prices.Reverse();
while (M > 0) {
prices[0] = prices[0] / 2;
M--;
for (int i = 1; i < N; i++) {
if (prices[0] > prices[i]) {
prices.Sort();
prices.Reverse();
break;
}
prices[i] = prices[i] / 2;
M--;
if (M == 0)
break;
}
}
Console.WriteLine(prices.Sum());
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var input1 = Console.ReadLine();
var N = int.Parse(input1.Split(' ')[0]);
var M = int.Parse(input1.Split(' ')[1]);
var input2 = Console.ReadLine().Split(' ');
var prices = new List<Int64>();
input2.ToList().ForEach(x => prices.Add(Int64.Parse(x)));
prices.Sort();
prices.Reverse();
while (M > 0) {
prices[0] = prices[0] / 2;
M--;
if (M > 0) {
for (int i = 1; i < N; i++) {
if (prices[0] > prices[i]) {
prices.Sort();
prices.Reverse();
break;
}
prices[i] = prices[i] / 2;
M--;
if (M <= 0)
break;
}
}
}
Console.WriteLine(prices.Sum());
}
}
|
[["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 242
| 10
|
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace debug {
class main {
static void Main(string[] args) {
//問題クラスを展開
ProgramD a = new ProgramD();
a.main(); //実行する
}
}
class ProgramA {
public void main() {
string input = Console.ReadLine();
int a = int.Parse(input);
double b = (double)((a / 2 + 1) / a);
if (a % 2 == 0)
Console.WriteLine("0.5");
else
Console.WriteLine(b);
}
}
class ProgramB {
public void main() {
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
string[] a = Console.ReadLine().Split(' ');
int count = 0;
for (int i = 0; i < n; i++) {
long ai = long.Parse(a[i]);
if (k <= ai)
count++;
}
Console.WriteLine(count);
}
}
class ProgramC {
public void main() {
string input = Console.ReadLine();
int n = int.Parse(input);
string[] input_b = Console.ReadLine().Split(' ');
long[] b = new long[n];
long[] c = new long[n];
for (int i = 0; i < n; i++)
b[i] = long.Parse(input_b[i]);
for (int i = 1; i < n + 1; i++)
c[b[i - 1] - 1] = i;
for (int i = 0; i < n; i++)
Console.Write(c[i] + " ");
}
}
class ProgramD {
public void main() {
string[] input = Console.ReadLine().Split(' ');
long a = long.Parse(input[0]);
long b = long.Parse(input[1]);
long c = gcd(a, b); //最大公約数を求める
long count = 2; // 1と最後の素因数を求める
int flag = 0;
//素因数分解してみる(例えば、2で割った後は2より大きい素数で2つの数で表せるかどうかを随時判定
for (long i = 2; i <= Math.Sqrt(c); i++) {
while (c % i == 0) {
c /= i;
flag = 1;
}
if (flag == 1) {
count++;
flag = 0;
}
}
//ただし、計算結果でc=1ということは
if (c == 1)
count = 1;
Console.WriteLine(count);
}
/*最大公約数を求める関数*/
static long gcd(long p, long q) {
if (p < q) {
long temp = p;
p = q;
q = temp;
}
long r = 1;
while (r != 0) {
r = p % q;
p = q;
q = r;
}
return p;
}
}
class ProgramE {
public void main() {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
}
}
}
|
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace debug {
class main {
static void Main(string[] args) {
//問題クラスを展開
ProgramD a = new ProgramD();
a.main(); //実行する
}
}
class ProgramA {
public void main() {
string input = Console.ReadLine();
int a = int.Parse(input);
double b = (double)((a / 2 + 1) / a);
if (a % 2 == 0)
Console.WriteLine("0.5");
else
Console.WriteLine(b);
}
}
class ProgramB {
public void main() {
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
string[] a = Console.ReadLine().Split(' ');
int count = 0;
for (int i = 0; i < n; i++) {
long ai = long.Parse(a[i]);
if (k <= ai)
count++;
}
Console.WriteLine(count);
}
}
class ProgramC {
public void main() {
string input = Console.ReadLine();
int n = int.Parse(input);
string[] input_b = Console.ReadLine().Split(' ');
long[] b = new long[n];
long[] c = new long[n];
for (int i = 0; i < n; i++)
b[i] = long.Parse(input_b[i]);
for (int i = 1; i < n + 1; i++)
c[b[i - 1] - 1] = i;
for (int i = 0; i < n; i++)
Console.Write(c[i] + " ");
}
}
class ProgramD {
public void main() {
string[] input = Console.ReadLine().Split(' ');
long a = long.Parse(input[0]);
long b = long.Parse(input[1]);
long c = gcd(a, b); //最大公約数を求める
long count = 1; // 1はあらかじめカウント
int flag = 0;
//最大公約数が1なら答は1
if (c == 1) {
Console.WriteLine("1");
return;
}
//素因数分解してみる(例えば、2で割った後は2より大きい素数で2つの数で表せるかどうかを随時判定
for (long i = 2; i <= Math.Sqrt(c); i++) {
while (c % i == 0) {
c /= i;
flag = 1;
}
if (flag == 1) {
count++;
flag = 0;
}
}
//ただし、計算結果でcが1以外ということは最後の素数が計上されていない。
if (c != 1)
count++;
Console.WriteLine(count);
}
/*最大公約数を求める関数*/
static long gcd(long p, long q) {
if (p < q) {
long temp = p;
p = q;
q = temp;
}
long r = 1;
while (r != 0) {
r = p % q;
p = q;
q = r;
}
return p;
}
}
class ProgramE {
public void main() {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 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], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 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], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29]]
| 8
| 687
| 26
|
using System;
class ProgramD {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
ulong a = ulong.Parse(input[0]);
ulong b = ulong.Parse(input[1]);
if (a < b) {
ulong tmp = a;
a = b;
b = tmp;
}
ulong r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
ulong c = b;
ulong d = b;
ulong count = 2;
int frag = 0;
for (ulong i = 2; i < Math.Sqrt(c); i++) {
while (c % i == 0) {
c /= i;
frag = 1;
}
if (frag == 1) {
count++;
frag = 0;
}
}
if (d == 1)
count = 1;
Console.WriteLine(count);
}
}
|
using System;
class ProgramD {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
ulong a = ulong.Parse(input[0]);
ulong b = ulong.Parse(input[1]);
if (a < b) {
ulong tmp = a;
a = b;
b = tmp;
}
ulong r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
ulong c = b;
ulong d = b;
ulong count = 1;
int frag = 0;
for (ulong i = 2; i <= Math.Sqrt(c); i++) {
while (c % i == 0) {
c /= i;
frag = 1;
}
if (frag == 1) {
count++;
frag = 0;
}
}
if (c != 1)
count++;
if (d == 1)
count = 1;
Console.WriteLine(count);
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 203
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var A = sc.ReadLong();
var B = sc.ReadLong();
var gcd = Gcd(A, B);
var pf = PrimeFactors(gcd).Distinct();
var ans = pf.Count() + 1;
Console.WriteLine(ans);
}
static int INF = int.MaxValue;
static long LINF = long.MaxValue;
static Random Rand = new Random();
static Scanner sc = new Scanner();
static long Gcd(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
static bool IsPrime(long num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
static List<long> PrimeFactors(long n) {
var res = new List<long>();
var tmp = n;
for (long x = 2; x * x <= n; x++) {
while (tmp % x == 0) {
tmp /= x;
res.Add(x);
}
}
if (tmp != 1)
res.Add(tmp);
if (res.Count() == 0)
res.Add(n);
return res;
}
static IEnumerable<long> Divisor(long n) {
for (int i = 1; i * i <= n; i++) {
if (n % i == 0)
yield return i;
}
}
static Result[] ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b,
Func<T1, T2, Result> f) {
Result[] res = new Result[a.Count() * b.Count()];
var i = 0;
foreach (var v in a)
foreach (var w in b)
res[i++] = f(v, w);
return res;
}
static IEnumerable<Result> ListAll<T1, T2, Result>(IEnumerable<T1> a,
IEnumerable<T2> b,
Func<T1, T2, Result> f,
Func<T1, T2, bool> s) {
foreach (var v in a) {
foreach (var w in b)
if (s(v, w))
yield return f(v, w);
}
}
}
class Modulo {
public readonly int MOD;
private readonly List<int> Facs = new List<int>() { 1 };
public Modulo(int mod = 1000000007) { this.MOD = mod; }
public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); }
public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); }
public int Pow(int a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, n / 2);
int p2 = Mul(p1, p1);
return ((n % 2) == 0) ? p2 : Mul(p2, a);
}
}
public int Fac(int n) {
for (int i = this.Facs.Count; i <= n; i++) {
this.Facs.Add(Mul(i, Facs[i - 1]));
}
return this.Facs[n];
}
public int nPr(int n, int r) => Div(Fac(n), Fac(n - r));
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 Debug {
public static void Dump<T>(T[,] array) {
Console.WriteLine();
var h = array.GetLength(0);
var w = array.GetLength(1);
for (int r = 0; r < h; r++) {
for (int c = 0; c < w; c++) {
Console.Write(array[r, c]);
Console.Write(" ");
}
Console.WriteLine();
}
Console.WriteLine();
}
public static void Dump<T>(T[] array) {
Console.WriteLine();
Console.WriteLine(string.Join(" ", array));
Console.WriteLine();
}
}
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 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 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;
}
}
class HashMap<K, V> : Dictionary<K, V>
where V : new() {
private V DefaltValue = new V();
public HashMap() {}
public HashMap(V defaultValue) { this.DefaltValue = new V(); }
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue;
}
set { base[i] = value; }
}
}
class Vector<T> : List<T>
where T : new() {
public Vector() {}
public Vector(int count, T defaultValue) {
for (int i = 0; i < count; i++) {
this.Add(defaultValue);
}
}
}
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
public T Peek() { return this.Array[0]; }
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
var parent = (n - 1) / 2;
if (this.Array[n].CompareTo(this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var A = sc.ReadLong();
var B = sc.ReadLong();
var gcd = Gcd(A, B);
var pf = PrimeFactors(gcd).Distinct();
var ans = pf.Count() + 1;
Console.WriteLine(ans);
}
static int INF = int.MaxValue;
static long LINF = long.MaxValue;
static Random Rand = new Random();
static Scanner sc = new Scanner();
static long Gcd(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
static bool IsPrime(long num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
static List<long> PrimeFactors(long n) {
var res = new List<long>();
var tmp = n;
for (long x = 2; x * x <= n; x++) {
while (tmp % x == 0) {
tmp /= x;
res.Add(x);
}
}
if (tmp != 1)
res.Add(tmp);
return res;
}
static IEnumerable<long> Divisor(long n) {
for (int i = 1; i * i <= n; i++) {
if (n % i == 0)
yield return i;
}
}
static Result[] ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b,
Func<T1, T2, Result> f) {
Result[] res = new Result[a.Count() * b.Count()];
var i = 0;
foreach (var v in a)
foreach (var w in b)
res[i++] = f(v, w);
return res;
}
static IEnumerable<Result> ListAll<T1, T2, Result>(IEnumerable<T1> a,
IEnumerable<T2> b,
Func<T1, T2, Result> f,
Func<T1, T2, bool> s) {
foreach (var v in a) {
foreach (var w in b)
if (s(v, w))
yield return f(v, w);
}
}
}
class Modulo {
public readonly int MOD;
private readonly List<int> Facs = new List<int>() { 1 };
public Modulo(int mod = 1000000007) { this.MOD = mod; }
public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); }
public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); }
public int Pow(int a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, n / 2);
int p2 = Mul(p1, p1);
return ((n % 2) == 0) ? p2 : Mul(p2, a);
}
}
public int Fac(int n) {
for (int i = this.Facs.Count; i <= n; i++) {
this.Facs.Add(Mul(i, Facs[i - 1]));
}
return this.Facs[n];
}
public int nPr(int n, int r) => Div(Fac(n), Fac(n - r));
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 Debug {
public static void Dump<T>(T[,] array) {
Console.WriteLine();
var h = array.GetLength(0);
var w = array.GetLength(1);
for (int r = 0; r < h; r++) {
for (int c = 0; c < w; c++) {
Console.Write(array[r, c]);
Console.Write(" ");
}
Console.WriteLine();
}
Console.WriteLine();
}
public static void Dump<T>(T[] array) {
Console.WriteLine();
Console.WriteLine(string.Join(" ", array));
Console.WriteLine();
}
}
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 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 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;
}
}
class HashMap<K, V> : Dictionary<K, V>
where V : new() {
private V DefaltValue = new V();
public HashMap() {}
public HashMap(V defaultValue) { this.DefaltValue = new V(); }
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue;
}
set { base[i] = value; }
}
}
class Vector<T> : List<T>
where T : new() {
public Vector() {}
public Vector(int count, T defaultValue) {
for (int i = 0; i < count; i++) {
this.Add(defaultValue);
}
}
}
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
public T Peek() { return this.Array[0]; }
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
var parent = (n - 1) / 2;
if (this.Array[n].CompareTo(this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["-", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["-", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 2,115
| 17
|
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 gcd = Gcd(A, B);
var ans = PrimeFactors(gcd).Count() + 1;
Console.WriteLine(ans);
}
}
static int INF = int.MaxValue;
static long LINF = long.MaxValue;
static Scanner sc = new Scanner();
static long Gcd(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
static bool IsPrime(long num) {
checked {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
}
static IEnumerable<long> PrimeFactors(long n) {
long i = 2;
long tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
static IEnumerable<long> Factors(long n) {
for (int i = 1; i * i <= n; i++) {
if (n % i == 0)
yield return i;
}
}
}
class Modulo {
public readonly int MOD;
private readonly List<int> Facs = new List<int>() { 1 };
public Modulo(int mod = 1000000007) { this.MOD = mod; }
public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); }
public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); }
public int Pow(int a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, n / 2);
int p2 = Mul(p1, p1);
return ((n % 2) == 0) ? p2 : Mul(p2, a);
}
}
public int Fac(int n) {
for (int i = this.Facs.Count; i <= n; i++) {
this.Facs.Add(Mul(i, Facs[i - 1]));
}
return this.Facs[n];
}
public int nPr(int n, int r) => Div(Fac(n), Fac(n - r));
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 Debug {
public static void Dump<T>(T[,] array) {
Console.WriteLine();
var h = array.GetLength(0);
var w = array.GetLength(1);
for (int r = 0; r < h; r++) {
for (int c = 0; c < w; c++) {
Console.Write(array[r, c]);
Console.Write(" ");
}
Console.WriteLine();
}
Console.WriteLine();
}
public static void Dump<T>(T[] array) {
Console.WriteLine();
Console.WriteLine(string.Join(" ", array));
Console.WriteLine();
}
}
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 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 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;
}
}
class HashMap<K, V> : Dictionary<K, V>
where V : new() {
private V DefaltValue = new V();
public HashMap() {}
public HashMap(V defaultValue) { this.DefaltValue = new V(); }
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue;
}
set { base[i] = value; }
}
}
class Vector<T> : List<T>
where T : new() {
public Vector() {}
public Vector(int count, T defaultValue) {
for (int i = 0; i < count; i++) {
this.Add(defaultValue);
}
}
}
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
public T Peek() { return this.Array[0]; }
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
var parent = (n - 1) / 2;
if (this.Array[n].CompareTo(this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var A = sc.ReadLong();
var B = sc.ReadLong();
var gcd = Gcd(A, B);
var pf = PrimeFactors(gcd).Distinct();
var ans = pf.Count() + 1;
Console.WriteLine(ans);
}
static int INF = int.MaxValue;
static long LINF = long.MaxValue;
static Scanner sc = new Scanner();
static long Gcd(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
static bool IsPrime(long num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
static IEnumerable<long> PrimeFactors(long n) {
long i = 2;
long tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
static IEnumerable<long> Divisor(long n) {
for (int i = 1; i * i <= n; i++) {
if (n % i == 0)
yield return i;
}
}
}
class Modulo {
public readonly int MOD;
private readonly List<int> Facs = new List<int>() { 1 };
public Modulo(int mod = 1000000007) { this.MOD = mod; }
public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); }
public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); }
public int Pow(int a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, n / 2);
int p2 = Mul(p1, p1);
return ((n % 2) == 0) ? p2 : Mul(p2, a);
}
}
public int Fac(int n) {
for (int i = this.Facs.Count; i <= n; i++) {
this.Facs.Add(Mul(i, Facs[i - 1]));
}
return this.Facs[n];
}
public int nPr(int n, int r) => Div(Fac(n), Fac(n - r));
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 Debug {
public static void Dump<T>(T[,] array) {
Console.WriteLine();
var h = array.GetLength(0);
var w = array.GetLength(1);
for (int r = 0; r < h; r++) {
for (int c = 0; c < w; c++) {
Console.Write(array[r, c]);
Console.Write(" ");
}
Console.WriteLine();
}
Console.WriteLine();
}
public static void Dump<T>(T[] array) {
Console.WriteLine();
Console.WriteLine(string.Join(" ", array));
Console.WriteLine();
}
}
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 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 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;
}
}
class HashMap<K, V> : Dictionary<K, V>
where V : new() {
private V DefaltValue = new V();
public HashMap() {}
public HashMap(V defaultValue) { this.DefaltValue = new V(); }
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue;
}
set { base[i] = value; }
}
}
class Vector<T> : List<T>
where T : new() {
public Vector() {}
public Vector(int count, T defaultValue) {
for (int i = 0; i < count; i++) {
this.Add(defaultValue);
}
}
}
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
public T Peek() { return this.Array[0]; }
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
var parent = (n - 1) / 2;
if (this.Array[n].CompareTo(this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 287, 0, 292], ["-", 0, 195, 8, 196, 0, 287, 0, 196, 0, 45], ["-", 0, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 287, 0, 196, 0, 46], ["-", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22]]
| 8
| 1,894
| 19
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
class Pair : IComparable {
public int x;
public int y;
public Pair(int X, int Y) {
x = X;
y = Y;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return x.CompareTo(kore.x);
}
}
class Program {
static void Main(string[] args) {
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
long a = scan.Long();
long b = scan.Long();
long g = gcd(a, b);
int count = 0;
if (g == 1) {
Console.WriteLine(1);
return;
}
for (long i = 2; i * i < g; i++) {
if (g % i == 0) {
count++;
}
while (g % i == 0) {
g /= i;
}
}
Console.WriteLine(count + 2);
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static bool isOK(int index, int key, int[] moto) {
return moto[index] >= key;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
static int nibutan(int med, int[] a) // med以上が何個あるか
{
int mae = 0;
int ato = a.Length;
while (true) {
if (ato - mae <= 1) {
return mae;
}
int mid = (mae + ato) / 2;
if (a[mid] > med) {
ato = mid;
}
if (a[mid] <= med) {
mae = mid;
}
}
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static long[] SoinsuBunkai(long num) {
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1) {
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps) {
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。
n = DivideWith(n, i + p, primes);
if (n == 1)
break;
}
i += 30;
}
return primes.ToArray();
}
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(int n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(int h, int w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public int[] Integer(int n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
public Mlong modjyo(Mlong x) { return num * x.Pow(mod - 2); }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
if (n == 1) {
return this % mod;
}
if (n % 2 == 1) {
return (this * Pow(n - 1)) % mod;
}
Mlong buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
}
public class Mint {
private static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
if (n == 1) {
return this % mod;
}
if (n % 2 == 1) {
return (this * Pow(n - 1)) % mod;
}
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static Mint Comb(Mint n, Mint a) {
Mint buf1 = 1;
Mint buf2 = 1;
for (int i = 0; i < a; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
class Pair : IComparable {
public int x;
public int y;
public Pair(int X, int Y) {
x = X;
y = Y;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return x.CompareTo(kore.x);
}
}
class Program {
static void Main(string[] args) {
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
long a = scan.Long();
long b = scan.Long();
long g = gcd(a, b);
int count = 0;
if (g == 1) {
Console.WriteLine(1);
return;
}
for (long i = 2; i * i < g; i++) {
if (g % i == 0) {
count++;
}
while (g % i == 0) {
g /= i;
}
}
if (g != 1) {
count++;
}
Console.WriteLine(count + 1);
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static bool isOK(int index, int key, int[] moto) {
return moto[index] >= key;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
static int nibutan(int med, int[] a) // med以上が何個あるか
{
int mae = 0;
int ato = a.Length;
while (true) {
if (ato - mae <= 1) {
return mae;
}
int mid = (mae + ato) / 2;
if (a[mid] > med) {
ato = mid;
}
if (a[mid] <= med) {
mae = mid;
}
}
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static long[] SoinsuBunkai(long num) {
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1) {
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps) {
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。
n = DivideWith(n, i + p, primes);
if (n == 1)
break;
}
i += 30;
}
return primes.ToArray();
}
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(int n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(int h, int w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public int[] Integer(int n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
public Mlong modjyo(Mlong x) { return num * x.Pow(mod - 2); }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
if (n == 1) {
return this % mod;
}
if (n % 2 == 1) {
return (this * Pow(n - 1)) % mod;
}
Mlong buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
}
public class Mint {
private static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
if (n == 1) {
return this % mod;
}
if (n % 2 == 1) {
return (this * Pow(n - 1)) % mod;
}
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static Mint Comb(Mint n, Mint a) {
Mint buf1 = 1;
Mint buf2 = 1;
for (int i = 0; i < a; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 6,065
| 13
|
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 array = cin.ReadLongArray(2);
var gcd = Gcd(array[0], array[1]);
var max = gcd;
long i = 2;
var yakusuHash = new HashSet<long> { 1 };
while (i * i <= max) {
if (gcd % i == 0) {
yakusuHash.Add(i);
gcd = gcd / i;
if (gcd <= 1)
break;
} else {
i++;
}
}
WriteLine(yakusuHash.Count);
}
public long Gcd(long a, long b) {
if (a > b)
return Gcd(b, a);
while (true) {
var mod = b % a;
if (mod == 0)
return a;
b = a;
a = mod;
}
}
}
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 array = cin.ReadLongArray(2);
var gcd = Gcd(array[0], array[1]);
var max = gcd;
long i = 2;
var yakusuHash = new HashSet<long> { 1 };
while (true) {
if (gcd % i == 0) {
yakusuHash.Add(i);
gcd = gcd / i;
if (gcd <= 1)
break;
} else {
if (i * i > max)
break;
i++;
}
}
if (gcd != 1)
yakusuHash.Add(gcd);
WriteLine(yakusuHash.Count);
}
public long Gcd(long a, long b) {
if (a > b)
return Gcd(b, a);
while (true) {
var mod = b % a;
if (mod == 0)
return a;
b = a;
a = mod;
}
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
[["-", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 52, 15, 16, 31, 16, 17, 48], ["-", 8, 196, 0, 52, 15, 16, 31, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 57, 75, 196, 0, 57, 64, 93, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 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, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 583
| 29
|
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 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() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var input = Reads();
long a = input[0];
long b = input[1];
long gcd = Gcd(a, b);
long tmp = gcd;
var c = new List<long>();
bool tf;
long divide = 2;
while (divide * divide <= tmp) {
tf = false;
while (gcd % divide == 0) {
gcd = gcd / divide;
tf = true;
}
if (tf)
c.Add(divide);
divide++;
}
Console.WriteLine(c.Count + 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 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() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var input = Reads();
long a = input[0];
long b = input[1];
long gcd = Gcd(a, b);
long tmp = gcd;
var c = new List<long>();
bool tf;
long divide = 2;
while (divide * divide <= tmp) {
tf = false;
while (gcd % divide == 0) {
gcd = gcd / divide;
tf = true;
}
if (tf)
c.Add(divide);
divide++;
}
if (gcd == 1)
Console.WriteLine(c.Count + 1);
else
Console.WriteLine(c.Count + 2);
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, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 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, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 287
| 18
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
Scanner cin = new Scanner();
long a = cin.Long();
long b = cin.Long();
long gcd = GCD(a, b);
var gp = GetPrimeFactor(gcd);
Console.WriteLine(gp.Count() + 1);
}
public static List<long> GetPrimeFactor(long value) {
long max = (long)Math.Ceiling(Math.Sqrt(value));
var factors = new List<long>();
for (int i = 2; i <= max; ++i) {
if (value % i == 0) {
factors.Add(i);
while (value % i == 0) {
value /= i;
}
}
}
return factors;
}
public static long GCD(long a, long b) {
if (a > b) {
if (b == 0) {
return a;
}
return GCD(b, a % b);
} else {
if (a == 0) {
return b;
}
return GCD(a, b % a);
}
}
}
public class Scanner {
private readonly char[] delimiter_ = new char[] { ' ' };
private string[] buf_;
private int index_;
public Scanner() {
buf_ = new string[0];
index_ = 0;
}
public string Next() {
if (index_ < buf_.Length) {
return buf_[index_++];
}
string st = Console.ReadLine();
while (st == "") {
st = Console.ReadLine();
}
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;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
Scanner cin = new Scanner();
long a = cin.Long();
long b = cin.Long();
long gcd = GCD(a, b);
var gp = GetPrimeFactor(gcd);
gp.Add(1);
Console.WriteLine(gp.Count());
}
public static HashSet<long> GetPrimeFactor(long value) {
long temp = value;
long max = (long)Math.Ceiling(Math.Sqrt(temp));
var factors = new HashSet<long>();
for (int i = 2; i <= max; ++i) {
if (temp % i == 0) {
factors.Add(i);
while (temp % i == 0) {
temp /= i;
}
}
}
if (temp != 1) {
factors.Add(temp);
}
return factors;
}
public static long GCD(long a, long b) {
if (a > b) {
if (b == 0) {
return a;
}
return GCD(b, a % b);
} else {
if (a == 0) {
return b;
}
return GCD(a, b % a);
}
}
}
public class Scanner {
private readonly char[] delimiter_ = new char[] { ' ' };
private string[] buf_;
private int index_;
public Scanner() {
buf_ = new string[0];
index_ = 0;
}
public string Next() {
if (index_ < buf_.Length) {
return buf_[index_++];
}
string st = Console.ReadLine();
while (st == "") {
st = Console.ReadLine();
}
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;
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 235, 8, 201, 0, 195, 39, 236, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 39, 236, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 64, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 52, 8, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 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
| 627
| 41
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections; //ハッシュテーブル用
using System.Linq;
class Program {
// Hashtable ht = new Hashtable();
static List<int> s = new List<int>();
static List<int>[] sl;
static decimal result;
static decimal N, K;
// StringBuilder strresult= new StringBuilder("");//Append(str
// ○○)関数で文字を追加していく
static List<decimal> res = new List<decimal>();
static void Main() {
// Modular mo = new
// Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方:Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる(powべき乗、Fac累乗、nCr組み合わせも関数として存在)
// Node<> no = new
// Node<>();//UnionFind★Find関数で根っこの値を返す(根っこの値が一緒なら同グループ)、Unite関数で二つの木をくっつける
// Permutation<> pe = new
// Permutation<>();//配列&リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
// Treap<> tr = new
// Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
// PriorityQueue<int,int> pr = new
// PriorityQueue<int,int>();//優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
Read4();
//最大公約数出して、それの素な約数の数を……
decimal tmp = Gcd((long)N, (long)K);
PF(tmp);
result++;
for (int i = 0; i < res.Count; i++) {
Console.WriteLine(res[i].ToString());
}
Console.WriteLine(result.ToString());
}
public static void PF(decimal n) {
decimal i = 2;
decimal tmp = n;
while (i * i <= n) //※1
{
a1:
if (tmp % i == 0) {
tmp /= i;
for (int j = 0; j < res.Count; j++) {
if (res[j] == i) {
goto a1;
}
}
res.Add(i);
result++;
} else {
i++;
}
}
if (tmp != 1)
result++; //最後の素数も返す
}
static long Gcd(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
static void Read1() // 1項
{
string tmp = Console.ReadLine();
N = int.Parse(tmp);
}
static void Read2() //複数項(項目数N)
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read3() // 1行複数項
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < tmp.Length; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read4() // NK1行
{
string[] tmp = Console.ReadLine().Split(' ');
N = decimal.Parse(tmp[0]);
K = decimal.Parse(tmp[1]);
}
static void Read5() // N行K項
{}
}
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections; //ハッシュテーブル用
using System.Linq;
class Program {
// Hashtable ht = new Hashtable();
static List<int> s = new List<int>();
static List<int>[] sl;
static decimal result;
static decimal N, K;
// StringBuilder strresult= new StringBuilder("");//Append(str
// ○○)関数で文字を追加していく
static List<decimal> res = new List<decimal>();
static void Main() {
// Modular mo = new
// Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方:Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる(powべき乗、Fac累乗、nCr組み合わせも関数として存在)
// Node<> no = new
// Node<>();//UnionFind★Find関数で根っこの値を返す(根っこの値が一緒なら同グループ)、Unite関数で二つの木をくっつける
// Permutation<> pe = new
// Permutation<>();//配列&リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
// Treap<> tr = new
// Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
// PriorityQueue<int,int> pr = new
// PriorityQueue<int,int>();//優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
Read4();
//最大公約数出して、それの素な約数の数を……
decimal tmp = Gcd((long)N, (long)K);
PF(tmp);
result++;
Console.WriteLine(result.ToString());
}
public static void PF(decimal n) {
decimal i = 2;
decimal tmp = n;
while (i * i <= n) //※1
{
a1:
if (tmp % i == 0) {
tmp /= i;
for (int j = 0; j < res.Count; j++) {
if (res[j] == i) {
goto a1;
}
}
res.Add(i);
result++;
} else {
i++;
}
}
if (tmp != 1)
result++; //最後の素数も返す
}
static long Gcd(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
static void Read1() // 1項
{
string tmp = Console.ReadLine();
N = int.Parse(tmp);
}
static void Read2() //複数項(項目数N)
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read3() // 1行複数項
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < tmp.Length; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read4() // NK1行
{
string[] tmp = Console.ReadLine().Split(' ');
N = decimal.Parse(tmp[0]);
K = decimal.Parse(tmp[1]);
}
static void Read5() // N行K項
{}
}
|
[["-", 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], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["-", 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, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 213, 63, 214, 205, 204, 205, 22], ["-", 0, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["-", 63, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22]]
| 8
| 541
| 32
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using static Input;
using static Util;
class Program {
static long[] M;
static void INPUT() { M = LineLong(); }
static void OUT() {
var list = new List<long>();
var a = TEST(M[0], M[1]).OrderBy(__ => __).ToArray();
foreach (var i in a) {
var b = true;
foreach (var ii in list) {
if (i % ii == 0) {
b = false;
break;
}
}
if (b)
list.Add(i);
}
Console.WriteLine(list.Count + 1);
}
static void Main(string[] args) {
#if DEBUG
TESTINPUT();
// INPUT();
#else
INPUT();
#endif
OUT();
}
static void TESTINPUT() { M = new long[] { 10000000, 100 }; }
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
class Util {
public static IEnumerable<long> TEST(long a, long b) {
var l = Math.Min(a, b);
var h = Math.Max(a, b);
for (var i = 2L; i * i <= l; i++) {
if (l % i == 0) {
if (h % i == 0) {
yield return i;
}
var ii = l / i;
if (h % ii == 0 && ii != i) {
yield return ii;
}
}
}
yield break;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using static Input;
using static Util;
class Program {
static long[] M;
static void INPUT() { M = LineLong(); }
static void OUT() {
var list = new List<long>();
var a = TEST(M[0], M[1]).OrderBy(__ => __).ToArray();
foreach (var i in a) {
if (i == 1)
continue;
var b = true;
foreach (var ii in list) {
if (i % ii == 0) {
b = false;
break;
}
}
if (b)
list.Add(i);
}
Console.WriteLine(list.Count + 1);
}
static void Main(string[] args) {
#if DEBUG
TESTINPUT();
// INPUT();
#else
INPUT();
#endif
OUT();
}
static void TESTINPUT() { M = new long[] { 101, 202 }; }
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
class Util {
public static IEnumerable<long> TEST(long a, long b) {
var l = Math.Min(a, b);
var h = Math.Max(a, b);
for (var i = 1L; i * i <= l; i++) {
if (l % i == 0) {
if (h % i == 0) {
yield return i;
}
var ii = l / i;
if (h % ii == 0 && ii != i) {
yield return ii;
}
}
}
yield break;
}
}
|
[["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 210, 8, 196, 0, 57, 64, 116, 0, 35], ["-", 0, 1, 0, 11, 12, 227, 0, 229, 0, 203], ["+", 0, 1, 0, 11, 12, 227, 0, 229, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 633
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
partial class Program {
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <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;
}
}
static void Main(string[] args) {
//↓
var ab = ReadLongArray();
var a = ab[0];
var b = ab[1];
if (a < b) {
var c = a;
a = b;
b = c;
}
long gcd = 0;
while (true) {
var c = a % b;
if (c == 0) {
gcd = b;
break;
}
a = b;
b = c;
}
var count = 1;
var cd = gcd;
for (int i = 2; i < Math.Sqrt(cd); i++) {
var c = 0;
while (true) {
if (cd % i == 0) {
c++;
cd /= i;
} else {
break;
}
}
if (c > 0) {
count++;
}
}
Console.WriteLine(count + (cd == gcd ? 0 : 1));
//↑
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
partial class Program {
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <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;
}
}
static void Main(string[] args) {
//↓
var ab = ReadLongArray();
var a = ab[0];
var b = ab[1];
if (a < b) {
var c = a;
a = b;
b = c;
}
long gcd = 0;
while (true) {
var c = a % b;
if (c == 0) {
gcd = b;
break;
}
a = b;
b = c;
}
var count = 1;
var root = Math.Sqrt(gcd);
for (int i = 2; i < root; i++) {
var c = 0;
while (true) {
if (gcd % i == 0) {
c++;
gcd /= i;
} else {
break;
}
}
if (c > 0) {
count++;
}
}
if (gcd > root)
count++;
Console.WriteLine(count);
//↑
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 7, 15, 16, 12, 213, 3, 4, 0, 24], ["-", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 16, 12, 23, 0, 41, 15, 16, 31, 22], ["-", 0, 16, 12, 23, 0, 41, 15, 16, 17, 60], ["-", 0, 16, 12, 23, 0, 41, 15, 16, 12, 22], ["-", 0, 28, 0, 16, 12, 23, 0, 41, 0, 101], ["-", 0, 28, 0, 16, 12, 23, 0, 41, 64, 203], ["-", 0, 28, 0, 16, 12, 23, 0, 41, 0, 102], ["-", 0, 28, 0, 16, 12, 23, 0, 41, 75, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
| 8
| 870
| 37
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using Extensions;
using static System.Math;
using static Extensions.MathExtension;
using static Extensions.ConsoleInputExtension;
using static Extensions.ConsoleOutputExtension;
class Solver {
public void Solve() {
// Solve Code Here
long A = Cin, B = Cin;
long gcd = GCD(A, B);
var sqrt = Sqrt(gcd);
var longs = new List<long>();
for (long l = 1; l <= sqrt; l++) {
if (gcd % l == 0) {
longs.Add(l);
if (l != gcd / l)
longs.Add(gcd / l);
}
}
longs = longs.OrderBy(val => val).Skip(1).Take(longs.Count - 2).ToList();
int count = 1;
while (longs.Count > 0) {
count++;
var l = longs[0];
longs = longs.Where(val => GCD(val, l) == 1).ToList();
}
Coutln(count);
}
// Other Functions Here
}
// Other Classes Here
#if !DEBUG
class EntryPoint {
static void Main(string[] args) {
new Solver().Solve();
Flush();
}
}
#endif
class PriorityQueue<T> {
private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>();
public int Count { get; private set; } = 0;
public PriorityQueue() {
_list.Add(null);
_list.Add(null);
_list.Add(null);
}
public void Push(T item, int priority) {
var itemIndex = Count++;
_list[itemIndex] = Tuple.Create(priority, item);
while (_list.Count < Count + 2)
_list.Add(null);
int parentIndex;
while ((parentIndex = GetParentIndex(itemIndex)) != -1 &&
priority > _list[parentIndex].Item1) {
Swap(itemIndex, parentIndex);
itemIndex = parentIndex;
}
}
private int GetParentIndex(int index) {
if (index == 0)
return -1;
return ((index + 1) >> 1) - 1;
}
private Tuple<int, int> GetChildrenIndex(int index) {
var item2 = (index + 1) << 1;
var item1 = item2 - 1;
return item2 >= _list.Count ? null : Tuple.Create(item1, item2);
}
public T Pop() {
if (_list.Count <= 0 || _list[0] == null)
throw new IndexOutOfRangeException();
var item = _list[0].Item2;
_list[0] = null;
Tuple<int, int> childrenIndex;
int index = 0;
while ((childrenIndex = GetChildrenIndex(index)) != null &&
(_list[childrenIndex.Item1] != null ||
_list[childrenIndex.Item2] != null)) {
if ((_list[childrenIndex.Item1] != null &&
_list[childrenIndex.Item2] != null &&
_list[childrenIndex.Item1].Item1 >
_list[childrenIndex.Item2].Item1) ||
_list[childrenIndex.Item2] == null) {
_list[index] = _list[childrenIndex.Item1];
_list[childrenIndex.Item1] = null;
index = childrenIndex.Item1;
} else {
two:
_list[index] = _list[childrenIndex.Item2];
_list[childrenIndex.Item2] = null;
index = childrenIndex.Item2;
}
}
Count--;
return item;
}
public T Peek() { return _list[0].Item2; }
private void Swap(int index1, int index2) {
var tmp = _list[index1];
_list[index1] = _list[index2];
_list[index2] = tmp;
}
}
struct Rational {
private long _numerator;
private long _denominator;
public long Numerator => _numerator;
public long Denominator => _denominator;
public Rational(long numerator, long denominator) {
var gcd = GCD(numerator, denominator);
_numerator = numerator / gcd;
_denominator = denominator / gcd;
}
public static Rational operator +(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator +
b._numerator * a._denominator,
a._denominator * b._denominator);
}
public static Rational operator -(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator -
b._numerator * a._denominator,
a._denominator * b._denominator);
}
public static Rational operator *(Rational a, Rational b) {
return new Rational(a._numerator * b._numerator,
a._denominator * b._denominator);
}
public static Rational operator /(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator,
a._denominator * b._numerator);
}
public static explicit operator Rational(int i) { return new Rational(i, 1); }
public static explicit operator Rational(long l) {
return new Rational(l, 1);
}
public static explicit operator Rational(double d) {
long denominator = 1;
while (d % 1 != 0) {
denominator *= 2;
d *= 2;
}
return new Rational((long)d, denominator);
}
public static explicit operator Rational(float f) {
long denominator = 1;
while (f % 1 != 0) {
denominator *= 2;
f *= 2;
}
return new Rational((long)f, denominator);
}
}
struct ModInt {
public long Value { get; }
public static long Mod { get; set; } = 1000000000L + 7;
public ModInt(long l) {
long value = l % Mod;
while (value < 0)
value += Mod;
Value = value % Mod;
}
public static implicit operator long(ModInt m) { return m.Value; }
public static explicit operator ModInt(long l) { return new ModInt(l); }
public static ModInt operator +(ModInt a, ModInt b) {
return new ModInt(a.Value + b.Value);
}
public static ModInt operator -(ModInt a, ModInt b) {
return new ModInt(a.Value - b.Value);
}
public static ModInt operator *(ModInt a, ModInt b) {
return new ModInt(a.Value * b.Value);
}
public static ModInt operator /(ModInt a, ModInt b) {
return new ModInt(a * b.Inverse());
}
public override string ToString() { return Value.ToString(); }
}
static class ModIntMath {
public static ModInt Pow(this ModInt a, ModInt b) {
var pow = b.Value;
var m = a;
ModInt ans = new ModInt(1);
while (pow != 0) {
if ((pow & 1) == 1) {
ans *= m;
}
pow >>= 1;
m *= m;
}
return ans;
}
public static ModInt Inverse(this ModInt m) {
return m.Pow((ModInt)(ModInt.Mod - 2));
}
}
class UnionFind {
private readonly int[] _array;
public UnionFind(int N) {
_array = new int[N];
for (int i = 0; i < N; i++) {
_array[i] = i;
}
}
public int GetRootNode(int n) {
if (_array[n] == n)
return n;
return _array[n] = GetRootNode(_array[n]);
}
public void UnionGroup(int a, int b) {
var rootA = GetRootNode(a);
var rootB = GetRootNode(b);
if (rootA == rootB)
return;
_array[rootA] = rootB;
}
public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b);
public bool IsRoot(int n) => _array[n] == n;
}
namespace Extensions {
public class ConsoleInputExtension {
private static readonly ConsoleInputExtension _cin =
new ConsoleInputExtension();
public static ConsoleInputExtension Cin => _cin;
private static readonly Queue<string> _inputQueue = new Queue<string>();
private ConsoleInputExtension() {}
public static implicit operator string(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return _inputQueue.Dequeue();
}
public static implicit operator int(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return int.Parse(_inputQueue.Dequeue());
}
public static implicit operator long(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return long.Parse(_inputQueue.Dequeue());
}
public static implicit operator float(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return float.Parse(_inputQueue.Dequeue());
}
public static implicit operator double(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return double.Parse(_inputQueue.Dequeue());
}
}
public static class ConsoleOutputExtension {
private static StringBuilder _builder = new StringBuilder();
public static void Cout(object o) { _builder.Append(o); }
public static void CoutF(object o) {
_builder.Append(o);
Flush();
}
public static void Coutln(object o) {
_builder.Append(o);
_builder.Append('\n');
}
public static void Coutln() { _builder.Append('\n'); }
public static void CoutlnF(object o) {
_builder.Append(o);
_builder.Append('\n');
Flush();
}
public static void Flush() {
Console.Write(_builder.ToString());
_builder.Clear();
}
}
public static class MathExtension {
//最小公倍数
public static int LCM(int num1, int num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
public static long LCM(long num1, long num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
//最大公約数
public static int GCD(int num1, int num2) {
int a = Math.Max(num1, num2);
int b = Math.Min(num1, num2);
int mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
public static long GCD(long num1, long num2) {
long a = Math.Max(num1, num2);
long b = Math.Min(num1, num2);
long mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
}
public static class EnumerableExtension {
public delegate void Function<in T>(T val);
public static void ForEach<T>(this IEnumerable<T> enumerable,
Function<T> function) {
foreach (var x in enumerable) {
function(x);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using Extensions;
using static System.Math;
using static Extensions.MathExtension;
using static Extensions.ConsoleInputExtension;
using static Extensions.ConsoleOutputExtension;
class Solver {
public void Solve() {
// Solve Code Here
long A = Cin, B = Cin;
long gcd = GCD(A, B);
var sqrt = Sqrt(gcd);
var longs = new List<long>();
for (long l = 1; l <= sqrt; l++) {
if (gcd % l == 0) {
longs.Add(l);
if (l != gcd / l)
longs.Add(gcd / l);
}
}
if (longs.Count <= 2) {
Coutln(longs.Count);
return;
}
longs = longs.OrderBy(val => val).Skip(1).Take(longs.Count - 2).ToList();
int count = 1;
while (longs.Count > 0) {
count++;
var l = longs[0];
longs = longs.Where(val => GCD(val, l) == 1).ToList();
}
Coutln(count);
}
// Other Functions Here
}
// Other Classes Here
#if !DEBUG
class EntryPoint {
static void Main(string[] args) {
new Solver().Solve();
Flush();
}
}
#endif
class PriorityQueue<T> {
private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>();
public int Count { get; private set; } = 0;
public PriorityQueue() {
_list.Add(null);
_list.Add(null);
_list.Add(null);
}
public void Push(T item, int priority) {
var itemIndex = Count++;
_list[itemIndex] = Tuple.Create(priority, item);
while (_list.Count < Count + 2)
_list.Add(null);
int parentIndex;
while ((parentIndex = GetParentIndex(itemIndex)) != -1 &&
priority > _list[parentIndex].Item1) {
Swap(itemIndex, parentIndex);
itemIndex = parentIndex;
}
}
private int GetParentIndex(int index) {
if (index == 0)
return -1;
return ((index + 1) >> 1) - 1;
}
private Tuple<int, int> GetChildrenIndex(int index) {
var item2 = (index + 1) << 1;
var item1 = item2 - 1;
return item2 >= _list.Count ? null : Tuple.Create(item1, item2);
}
public T Pop() {
if (_list.Count <= 0 || _list[0] == null)
throw new IndexOutOfRangeException();
var item = _list[0].Item2;
_list[0] = null;
Tuple<int, int> childrenIndex;
int index = 0;
while ((childrenIndex = GetChildrenIndex(index)) != null &&
(_list[childrenIndex.Item1] != null ||
_list[childrenIndex.Item2] != null)) {
if ((_list[childrenIndex.Item1] != null &&
_list[childrenIndex.Item2] != null &&
_list[childrenIndex.Item1].Item1 >
_list[childrenIndex.Item2].Item1) ||
_list[childrenIndex.Item2] == null) {
_list[index] = _list[childrenIndex.Item1];
_list[childrenIndex.Item1] = null;
index = childrenIndex.Item1;
} else {
two:
_list[index] = _list[childrenIndex.Item2];
_list[childrenIndex.Item2] = null;
index = childrenIndex.Item2;
}
}
Count--;
return item;
}
public T Peek() { return _list[0].Item2; }
private void Swap(int index1, int index2) {
var tmp = _list[index1];
_list[index1] = _list[index2];
_list[index2] = tmp;
}
}
struct Rational {
private long _numerator;
private long _denominator;
public long Numerator => _numerator;
public long Denominator => _denominator;
public Rational(long numerator, long denominator) {
var gcd = GCD(numerator, denominator);
_numerator = numerator / gcd;
_denominator = denominator / gcd;
}
public static Rational operator +(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator +
b._numerator * a._denominator,
a._denominator * b._denominator);
}
public static Rational operator -(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator -
b._numerator * a._denominator,
a._denominator * b._denominator);
}
public static Rational operator *(Rational a, Rational b) {
return new Rational(a._numerator * b._numerator,
a._denominator * b._denominator);
}
public static Rational operator /(Rational a, Rational b) {
return new Rational(a._numerator * b._denominator,
a._denominator * b._numerator);
}
public static explicit operator Rational(int i) { return new Rational(i, 1); }
public static explicit operator Rational(long l) {
return new Rational(l, 1);
}
public static explicit operator Rational(double d) {
long denominator = 1;
while (d % 1 != 0) {
denominator *= 2;
d *= 2;
}
return new Rational((long)d, denominator);
}
public static explicit operator Rational(float f) {
long denominator = 1;
while (f % 1 != 0) {
denominator *= 2;
f *= 2;
}
return new Rational((long)f, denominator);
}
}
struct ModInt {
public long Value { get; }
public static long Mod { get; set; } = 1000000000L + 7;
public ModInt(long l) {
long value = l % Mod;
while (value < 0)
value += Mod;
Value = value % Mod;
}
public static implicit operator long(ModInt m) { return m.Value; }
public static explicit operator ModInt(long l) { return new ModInt(l); }
public static ModInt operator +(ModInt a, ModInt b) {
return new ModInt(a.Value + b.Value);
}
public static ModInt operator -(ModInt a, ModInt b) {
return new ModInt(a.Value - b.Value);
}
public static ModInt operator *(ModInt a, ModInt b) {
return new ModInt(a.Value * b.Value);
}
public static ModInt operator /(ModInt a, ModInt b) {
return new ModInt(a * b.Inverse());
}
public override string ToString() { return Value.ToString(); }
}
static class ModIntMath {
public static ModInt Pow(this ModInt a, ModInt b) {
var pow = b.Value;
var m = a;
ModInt ans = new ModInt(1);
while (pow != 0) {
if ((pow & 1) == 1) {
ans *= m;
}
pow >>= 1;
m *= m;
}
return ans;
}
public static ModInt Inverse(this ModInt m) {
return m.Pow((ModInt)(ModInt.Mod - 2));
}
}
class UnionFind {
private readonly int[] _array;
public UnionFind(int N) {
_array = new int[N];
for (int i = 0; i < N; i++) {
_array[i] = i;
}
}
public int GetRootNode(int n) {
if (_array[n] == n)
return n;
return _array[n] = GetRootNode(_array[n]);
}
public void UnionGroup(int a, int b) {
var rootA = GetRootNode(a);
var rootB = GetRootNode(b);
if (rootA == rootB)
return;
_array[rootA] = rootB;
}
public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b);
public bool IsRoot(int n) => _array[n] == n;
}
namespace Extensions {
public class ConsoleInputExtension {
private static readonly ConsoleInputExtension _cin =
new ConsoleInputExtension();
public static ConsoleInputExtension Cin => _cin;
private static readonly Queue<string> _inputQueue = new Queue<string>();
private ConsoleInputExtension() {}
public static implicit operator string(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return _inputQueue.Dequeue();
}
public static implicit operator int(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return int.Parse(_inputQueue.Dequeue());
}
public static implicit operator long(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return long.Parse(_inputQueue.Dequeue());
}
public static implicit operator float(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return float.Parse(_inputQueue.Dequeue());
}
public static implicit operator double(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return double.Parse(_inputQueue.Dequeue());
}
}
public static class ConsoleOutputExtension {
private static StringBuilder _builder = new StringBuilder();
public static void Cout(object o) { _builder.Append(o); }
public static void CoutF(object o) {
_builder.Append(o);
Flush();
}
public static void Coutln(object o) {
_builder.Append(o);
_builder.Append('\n');
}
public static void Coutln() { _builder.Append('\n'); }
public static void CoutlnF(object o) {
_builder.Append(o);
_builder.Append('\n');
Flush();
}
public static void Flush() {
Console.Write(_builder.ToString());
_builder.Clear();
}
}
public static class MathExtension {
//最小公倍数
public static int LCM(int num1, int num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
public static long LCM(long num1, long num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
//最大公約数
public static int GCD(int num1, int num2) {
int a = Math.Max(num1, num2);
int b = Math.Min(num1, num2);
int mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
public static long GCD(long num1, long num2) {
long a = Math.Max(num1, num2);
long b = Math.Min(num1, num2);
long mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
}
public static class EnumerableExtension {
public delegate void Function<in T>(T val);
public static void ForEach<T>(this IEnumerable<T> enumerable,
Function<T> function) {
foreach (var x in enumerable) {
function(x);
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 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, 214, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22]]
| 8
| 2,340
| 19
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
// static int[] dp;
// static decimal[,,] dp;
// static decimal N;
static void Main(string[] args) {
// 入力
long[] input =
Console.ReadLine().Split().Select(p => long.Parse(p)).ToArray();
long A = input[0];
long B = input[1];
HashSet<long> ret = new HashSet<long>();
long last = (long)Math.Ceiling(
Math.Min(Math.Sqrt((double)A), Math.Sqrt((double)B)));
for (int i = 2; i <= last + 1; i++) {
// iで割り切れるだけ割る
if (A % i == 0 && B % i == 0) {
ret.Add(i);
}
if (A % i == 0) {
while (A % i == 0) {
A /= i;
}
}
if (B % i == 0) {
while (B % i == 0) {
B /= i;
}
}
}
// 小さいほう(素数)が大きいほうを割り切れる場合
if (A < B) {
if (B % A == 0)
ret.Add(A);
} else {
if (A % B == 0)
ret.Add(B);
}
Console.WriteLine((ret.Count + 1) + "");
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
// static int[] dp;
// static decimal[,,] dp;
// static decimal N;
static void Main(string[] args) {
// 入力
long[] input =
Console.ReadLine().Split().Select(p => long.Parse(p)).ToArray();
long A = input[0];
long B = input[1];
HashSet<long> ret = new HashSet<long>();
long last = (long)Math.Ceiling(
Math.Min(Math.Sqrt((double)A), Math.Sqrt((double)B)));
for (int i = 2; i <= last + 1; i++) {
// iで割り切れるだけ割る
if (A % i == 0 && B % i == 0) {
ret.Add(i);
}
if (A % i == 0) {
while (A % i == 0) {
A /= i;
}
}
if (B % i == 0) {
while (B % i == 0) {
B /= i;
}
}
}
// 小さいほう(素数)が大きいほうを割り切れる場合
if (A > 1 && A < B) {
if (B % A == 0)
ret.Add(A);
} else if (B > 1) {
if (A % B == 0)
ret.Add(B);
}
Console.WriteLine((ret.Count + 1) + "");
}
}
|
[["+", 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, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25]]
| 8
| 279
| 10
|
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.IO;
using System.Text;
public class Solver {
public void Solve() {
long a = rl, b = rl;
long g = Gcd(a, b);
long p = 1;
long s = (long)Math.Sqrt(g);
if (g % 2 == 0) {
p++;
while (g % 2 == 0) {
g /= 2;
}
}
for (int i = 3; i <= s; i += 2) {
if (g % i == 0) {
p++;
while (g % i == 0) {
g /= i;
}
}
}
Write(p);
}
int ri {
get { return sc.Integer(); }
}
long rl {
get { return sc.Long(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
public Algorithm alg = new Algorithm();
private const long mod = 1000000007;
long Reverse(long n) { return Pow(n, mod - 2); }
int Sign(int n) { return n == 0 ? 0 : n > 0 ? 1 : -1; }
int Abs(int n) { return (n > 0) ? n : -n; }
int Gcd(params int[] n) {
int p = n[0];
for (int i = 1; i < n.Length; i++) {
p = Gcd(p, n[i]);
}
return p;
}
int Gcd(int a, int b) { return (a == 0) ? b : Gcd(b % a, a); }
int Lcm(params int[] n) {
int p = n[0];
for (int i = 1; i < n.Length; i++) {
p = Lcm(p, n[i]);
}
return p;
}
int Lcm(int a, int b) { return a * b / Gcd(a, b); }
int Max(params int[] n) {
int p = n[0];
for (int i = 1; i < n.Length; i++) {
p = (p > n[i]) ? p : n[i];
}
return p;
}
int Min(params int[] n) {
int p = n[0];
for (int i = 1; i < n.Length; i++) {
p = (p < n[i]) ? p : n[i];
}
return p;
}
long Mul(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = (p * n[i]) % mod;
}
return p;
}
long Pow(long n, long p) {
long t = n, q = 1;
while (p > 0) {
if (p % 2 == 1) {
q = (q * t) % mod;
}
t = (t * t) % mod;
p >>= 1;
}
return q;
}
long PowUpper(long n, long b) {
long p = 1;
while (p <= n) {
p *= b;
}
return p;
}
long Sign(long n) { return n == 0 ? 0 : n > 0 ? 1 : -1; }
long Abs(long n) { return (n > 0) ? n : -n; }
long Gcd(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = Gcd(p, n[i]);
}
return p;
}
long Gcd(long a, long b) { return (a == 0) ? b : Gcd(b % a, a); }
long Lcm(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = Lcm(p, n[i]);
}
return p;
}
long Lcm(long a, long b) { return (a / Gcd(a, b) * b) % mod; }
long Max(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = (p > n[i]) ? p : n[i];
}
return p;
}
long Min(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = (p < n[i]) ? p : n[i];
}
return p;
}
void Write<T>(T t) { Console.WriteLine(t.ToString()); }
void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
}
static class Program {
static public void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var solver = new Solver();
solver.Solve();
Console.Out.Flush();
}
}
public class Algorithm {
public int[] ZAlgorithm(string s) {
int[] p = new int[s.Length];
p[0] = s.Length;
int i = 1, j = 0;
while (i < s.Length) {
while (i + j < s.Length && s[j] == s[i + j])
++j;
p[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < s.Length && k + p[k] < j) {
p[i + k] = p[k];
++k;
}
i += k;
j -= k;
}
return p;
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(IComparer<T> comparer) {
_heap = new T[128];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int type = 0) {
_heap = new T[128];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
if (_count > _heap.Length) {
var newheap = new T[_heap.Length * 2];
for (int n = 0; n < _heap.Length; n++)
newheap[n] = _heap[n];
_heap = newheap;
}
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (int)Long(); }
public double Double() { return double.Parse(Scan()); }
}
|
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.IO;
using System.Text;
public class Solver {
public void Solve() {
long a = rl, b = rl;
long g = Gcd(a, b);
long p = 1;
long s = (long)Math.Sqrt(g);
if (g % 2 == 0) {
p++;
while (g % 2 == 0) {
g /= 2;
}
}
for (int i = 3; i <= s; i += 2) {
if (g % i == 0) {
p++;
while (g % i == 0) {
g /= i;
}
}
}
if (g > 1) {
p++;
}
Write(p);
}
int ri {
get { return sc.Integer(); }
}
long rl {
get { return sc.Long(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
public Algorithm alg = new Algorithm();
private const long mod = 1000000007;
long Reverse(long n) { return Pow(n, mod - 2); }
int Sign(int n) { return n == 0 ? 0 : n > 0 ? 1 : -1; }
int Abs(int n) { return (n > 0) ? n : -n; }
int Gcd(params int[] n) {
int p = n[0];
for (int i = 1; i < n.Length; i++) {
p = Gcd(p, n[i]);
}
return p;
}
int Gcd(int a, int b) { return (a == 0) ? b : Gcd(b % a, a); }
int Lcm(params int[] n) {
int p = n[0];
for (int i = 1; i < n.Length; i++) {
p = Lcm(p, n[i]);
}
return p;
}
int Lcm(int a, int b) { return a * b / Gcd(a, b); }
int Max(params int[] n) {
int p = n[0];
for (int i = 1; i < n.Length; i++) {
p = (p > n[i]) ? p : n[i];
}
return p;
}
int Min(params int[] n) {
int p = n[0];
for (int i = 1; i < n.Length; i++) {
p = (p < n[i]) ? p : n[i];
}
return p;
}
long Mul(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = (p * n[i]) % mod;
}
return p;
}
long Pow(long n, long p) {
long t = n, q = 1;
while (p > 0) {
if (p % 2 == 1) {
q = (q * t) % mod;
}
t = (t * t) % mod;
p >>= 1;
}
return q;
}
long PowUpper(long n, long b) {
long p = 1;
while (p <= n) {
p *= b;
}
return p;
}
long Sign(long n) { return n == 0 ? 0 : n > 0 ? 1 : -1; }
long Abs(long n) { return (n > 0) ? n : -n; }
long Gcd(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = Gcd(p, n[i]);
}
return p;
}
long Gcd(long a, long b) { return (a == 0) ? b : Gcd(b % a, a); }
long Lcm(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = Lcm(p, n[i]);
}
return p;
}
long Lcm(long a, long b) { return (a / Gcd(a, b) * b) % mod; }
long Max(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = (p > n[i]) ? p : n[i];
}
return p;
}
long Min(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = (p < n[i]) ? p : n[i];
}
return p;
}
void Write<T>(T t) { Console.WriteLine(t.ToString()); }
void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
}
static class Program {
static public void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var solver = new Solver();
solver.Solve();
Console.Out.Flush();
}
}
public class Algorithm {
public int[] ZAlgorithm(string s) {
int[] p = new int[s.Length];
p[0] = s.Length;
int i = 1, j = 0;
while (i < s.Length) {
while (i + j < s.Length && s[j] == s[i + j])
++j;
p[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < s.Length && k + p[k] < j) {
p[i + k] = p[k];
++k;
}
i += k;
j -= k;
}
return p;
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(IComparer<T> comparer) {
_heap = new T[128];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int type = 0) {
_heap = new T[128];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
if (_count > _heap.Length) {
var newheap = new T[_heap.Length * 2];
for (int n = 0; n < _heap.Length; n++)
newheap[n] = _heap[n];
_heap = newheap;
}
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (int)Long(); }
public double Double() { return double.Parse(Scan()); }
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 2,310
| 11
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var wrong_answer = new wrong_answer();
wrong_answer.Solve();
}
}
public class wrong_answer {
const int INF = 1 << 30;
const long INFL = 1L << 60;
const int MOD = 1000000007;
const int MOD2 = 998244353;
myinout IO = new myinout();
Math2 mmath = new Math2();
public void Solve() {
//ここから
var o = IO.intm;
var n = o[0];
var m = o[1];
var a = new long[m];
var b = new long[m];
var c = new long[m];
for (int i = 0; i < m; ++i) {
var oo = IO.longm;
a[i] = oo[0];
b[i] = oo[1];
c[i] = (int)IO.intm.Select(x => 1L << (x - 1)).Sum();
IO.wri(a[i]);
}
var dp = new long[1 << n];
for (int i = 1; i < (1 << n); ++i) {
dp[i] = INFL;
}
for (int i = 0; i < m; ++i) {
for (int j = 0; j < (1 << n); ++j) {
dp[j | c[i]] = Math.Min(dp[j] + a[i], dp[j | c[i]]);
// IO.wri(dp[j|c[i]]);
}
}
if (dp[(1 << n) - 1] == INFL)
IO.wri(-1);
else
IO.wri(dp[(1 << n) - 1]);
}
}
// b-aで降順
public class Math2 {
public long[] fact;
public long[] invfact;
public void factoricalmodset(long N, long MOD = 1000000007) {
fact = new long[N + 1];
invfact = new long[N + 1];
fact[0] = 1;
for (long i = 1; i <= N; ++i) {
fact[i] = fact[i - 1] * i % MOD;
}
invfact[N] = pow(fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invfact[i - 1] = invfact[i] * i % MOD;
}
}
public long nCr(long n, long r, long MOD = 1000000007) {
return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD);
}
public long pow(long i, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
n >>= 1;
}
return res;
}
public long gcd(long i, long y) {
while (y != 0) {
var r = i % y;
i = y;
y = r;
}
return i;
}
public long lcm(long i, long y) { return i * y / gcd(i, y); }
public Dictionary<long, int> primefactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> divisorenumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
public void swap<T>(ref T a, ref T b) {
var i = a;
a = b;
b = i;
}
}
class myinout {
// in
public string str => Console.ReadLine();
public string[] strm => str.Split(' ');
public long[] longm => strm.Select(long.Parse).ToArray();
public int[] intm => strm.Select(int.Parse).ToArray();
public char[] charm => str.ToArray();
public long long1 => longm[0];
public int int1 => intm[0];
public char char1 => charm[0];
// out
public void wri<T>(T i) { Console.WriteLine(i); }
public void yn(bool i) {
if (i)
wri("Yes");
else
wri("No");
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var wrong_answer = new wrong_answer();
wrong_answer.Solve();
}
}
public class wrong_answer {
const int INF = 1 << 30;
const long INFL = 1L << 60;
const int MOD = 1000000007;
const int MOD2 = 998244353;
myinout IO = new myinout();
Math2 mmath = new Math2();
public void Solve() {
//ここから
var o = IO.intm;
var n = o[0];
var m = o[1];
var a = new long[m];
var b = new long[m];
var c = new long[m];
for (int i = 0; i < m; ++i) {
var oo = IO.longm;
a[i] = oo[0];
b[i] = oo[1];
c[i] = (int)IO.intm.Select(x => 1L << (x - 1)).Sum();
// IO.wri(a[i]);
}
var dp = new long[1 << n];
for (int i = 1; i < (1 << n); ++i) {
dp[i] = INFL;
}
for (int i = 0; i < m; ++i) {
for (int j = 0; j < (1 << n); ++j) {
dp[j | c[i]] = Math.Min(dp[j] + a[i], dp[j | c[i]]);
// IO.wri(dp[j|c[i]]);
}
}
if (dp[(1 << n) - 1] == INFL)
IO.wri(-1);
else
IO.wri(dp[(1 << n) - 1]);
}
}
// b-aで降順
public class Math2 {
public long[] fact;
public long[] invfact;
public void factoricalmodset(long N, long MOD = 1000000007) {
fact = new long[N + 1];
invfact = new long[N + 1];
fact[0] = 1;
for (long i = 1; i <= N; ++i) {
fact[i] = fact[i - 1] * i % MOD;
}
invfact[N] = pow(fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invfact[i - 1] = invfact[i] * i % MOD;
}
}
public long nCr(long n, long r, long MOD = 1000000007) {
return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD);
}
public long pow(long i, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
n >>= 1;
}
return res;
}
public long gcd(long i, long y) {
while (y != 0) {
var r = i % y;
i = y;
y = r;
}
return i;
}
public long lcm(long i, long y) { return i * y / gcd(i, y); }
public Dictionary<long, int> primefactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> divisorenumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
public void swap<T>(ref T a, ref T b) {
var i = a;
a = b;
b = i;
}
}
class myinout {
// in
public string str => Console.ReadLine();
public string[] strm => str.Split(' ');
public long[] longm => strm.Select(long.Parse).ToArray();
public int[] intm => strm.Select(int.Parse).ToArray();
public char[] charm => str.ToArray();
public long long1 => longm[0];
public int int1 => intm[0];
public char char1 => charm[0];
// out
public void wri<T>(T i) { Console.WriteLine(i); }
public void yn(bool i) {
if (i)
wri("Yes");
else
wri("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, 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,052
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using System.Numerics;
using static System.Math;
using Number = System.Int32;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var m = ri;
var dp = new long[1 << n];
for (int i = 1; i < 1 << n; i++)
dp[i] = INF;
for (int i = 0; i < m; i++) {
var x = ri;
var k = ri;
var mask = 0;
for (int j = 0; j < k; j++)
mask |= (1 << (ri - 1));
for (int j = 0; j < 1 << n; j++) {
dp[j | mask] = Min(dp[j | mask], dp[j] + x);
}
}
Console.WriteLine(dp.Last());
}
const long INF = 1L << 60;
static int[] dx = { -1, 0, 1, 0 };
static int[] dy = { 0, 1, 0, -1 };
int ri {
get { return sc.Integer(); }
}
long rl {
get { return sc.Long(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public IO.StreamScanner sc =
new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < a.Length; ++i)
a[i] = f(i);
return a;
}
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
}
}
#region main
static class Ex {
static public string AsString(this IEnumerable<char> ie) {
return new string(ie.ToArray());
}
static public string AsJoinedString<T>(this IEnumerable<T> ie,
string st = " ") {
return string.Join(st, ie);
}
static public void Main() {
Console.SetOut(new Program.IO.Printer(
Console.OpenStandardOutput()) { AutoFlush = true });
var solver = new Program.Solver();
/*
var t = new System.Threading.Thread(solver.Solve, 50000000);
t.Start();
t.Join();
//*/
solver.Solve();
Console.Out.Flush();
}
}
#endregion
#region Ex
namespace Program.IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
}
#endregion
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using System.Numerics;
using static System.Math;
using Number = System.Int32;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var m = ri;
var dp = new long[1 << n];
for (int i = 1; i < 1 << n; i++)
dp[i] = INF;
for (int i = 0; i < m; i++) {
var x = ri;
var k = ri;
var mask = 0;
for (int j = 0; j < k; j++)
mask |= (1 << (ri - 1));
for (int j = 0; j < 1 << n; j++) {
dp[j | mask] = Min(dp[j | mask], dp[j] + x);
}
}
if (dp.Last() == INF)
Console.WriteLine(-1);
else
Console.WriteLine(dp.Last());
}
const long INF = 1L << 60;
static int[] dx = { -1, 0, 1, 0 };
static int[] dy = { 0, 1, 0, -1 };
int ri {
get { return sc.Integer(); }
}
long rl {
get { return sc.Long(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public IO.StreamScanner sc =
new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < a.Length; ++i)
a[i] = f(i);
return a;
}
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
}
}
#region main
static class Ex {
static public string AsString(this IEnumerable<char> ie) {
return new string(ie.ToArray());
}
static public string AsJoinedString<T>(this IEnumerable<T> ie,
string st = " ") {
return string.Join(st, ie);
}
static public void Main() {
Console.SetOut(new Program.IO.Printer(
Console.OpenStandardOutput()) { AutoFlush = true });
var solver = new Program.Solver();
/*
var t = new System.Threading.Thread(solver.Solve, 50000000);
t.Start();
t.Join();
//*/
solver.Solve();
Console.Out.Flush();
}
}
#endregion
#region Ex
namespace Program.IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
}
#endregion
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22]]
| 8
| 988
| 19
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections; //ハッシュテーブル用
using System.Linq;
class Program {
// Hashtable ht = new Hashtable();
static List<int> s = new List<int>();
static List<int> a = new List<int>();
static List<int> b = new List<int>();
static List<int> c = new List<int>();
static decimal result;
static int N, K;
// StringBuilder strresult= new StringBuilder("");//Append(str
// ○○)関数で文字を追加していく
static void Main() {
// Modular mo = new
// Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方:Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる(powべき乗、Fac累乗、nCr組み合わせも関数として存在)
// Node<> no = new
// Node<>();//UnionFind★Find関数で根っこの値を返す(根っこの値が一緒なら同グループ)、Unite関数で二つの木をくっつける
// Permutation<> pe = new
// Permutation<>();//配列&リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
// Treap<> tr = new
// Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
// PriorityQueue<int,int> pr = new
// PriorityQueue<int,int>();//優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
Read4();
Read5();
result = int.MaxValue - 1;
//鍵の適合パターンは最大でも2^12=4096個に過ぎない。
//鍵のパターンを2進数で表現する配列。
int size = (int)Math.Pow(2, N);
int[] check = new int[size];
int before = 0;
//鍵同士を組み合わせ、新たな鍵を作る繰り返し。新で出来る鍵は旧の両者より確定で大きいので、内側ループを0から回せば確実にソイツと全体を比較可能
for (int i = 0; i < size; i++) {
for (int j = 0; j < K; j++) {
if (c[j] == i) {
check[i] = a[j];
}
}
}
for (int j = 0; j < size; j++) {
for (int k = 0; k < size; k++) {
if (j == k) {
continue;
}
if (check[j] > 0 && check[k] > 0 &&
((check[j | k] > check[j] + check[k]) || (check[j | k] == 0)))
check[j | k] = check[j] + check[k];
}
}
result = check[size - 1];
if (result == 0) {
result = -1;
}
Console.WriteLine(result.ToString());
}
static void Read1() // 1項
{
string tmp = Console.ReadLine();
N = int.Parse(tmp);
}
static void Read2() //複数項(項目数N)
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read3() // 1行複数項
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < tmp.Length; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read4() // NK1行
{
string[] tmp = Console.ReadLine().Split(' ');
N = int.Parse(tmp[0]);
K = int.Parse(tmp[1]);
}
static void Read5() // N行K項
{
for (int i = 0; i < K; i++) {
string[] tmp = Console.ReadLine().Split(' ');
a.Add(int.Parse(tmp[0]));
b.Add(int.Parse(tmp[1]));
c.Add(0);
string[] tmp2 = Console.ReadLine().Split(' ');
for (int j = 0; j < b[i]; j++) {
c[i] += (int)Math.Pow(2, int.Parse(tmp2[j]) - 1);
}
}
}
}
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections; //ハッシュテーブル用
using System.Linq;
class Program {
// Hashtable ht = new Hashtable();
static List<int> s = new List<int>();
static List<int> a = new List<int>();
static List<int> b = new List<int>();
static List<int> c = new List<int>();
static decimal result;
static int N, K;
// StringBuilder strresult= new StringBuilder("");//Append(str
// ○○)関数で文字を追加していく
static void Main() {
// Modular mo = new
// Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方:Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる(powべき乗、Fac累乗、nCr組み合わせも関数として存在)
// Node<> no = new
// Node<>();//UnionFind★Find関数で根っこの値を返す(根っこの値が一緒なら同グループ)、Unite関数で二つの木をくっつける
// Permutation<> pe = new
// Permutation<>();//配列&リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
// Treap<> tr = new
// Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
// PriorityQueue<int,int> pr = new
// PriorityQueue<int,int>();//優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
Read4();
Read5();
result = int.MaxValue - 1;
//鍵の適合パターンは最大でも2^12=4096個に過ぎない。
//鍵のパターンを2進数で表現する配列。
int size = (int)Math.Pow(2, N);
int[] check = new int[size];
int before = 0;
//鍵同士を組み合わせ、新たな鍵を作る繰り返し。新で出来る鍵は旧の両者より確定で大きいので、外ループで後にhitする。内ループで全体と比較できるようにすれば漏れはないはず。
for (int i = 0; i < size; i++) {
for (int j = 0; j < K; j++) {
if (c[j] == i && (check[i] > a[j] || check[i] == 0)) {
check[i] = a[j];
}
}
}
for (int j = 0; j < size; j++) {
for (int k = 0; k < size; k++) {
if (j == k) {
continue;
}
if (check[j] > 0 && check[k] > 0 &&
((check[j | k] > check[j] + check[k]) || (check[j | k] == 0)))
check[j | k] = check[j] + check[k];
}
}
result = check[size - 1];
if (result == 0) {
result = -1;
}
Console.WriteLine(result.ToString());
}
static void Read1() // 1項
{
string tmp = Console.ReadLine();
N = int.Parse(tmp);
}
static void Read2() //複数項(項目数N)
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read3() // 1行複数項
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < tmp.Length; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read4() // NK1行
{
string[] tmp = Console.ReadLine().Split(' ');
N = int.Parse(tmp[0]);
K = int.Parse(tmp[1]);
}
static void Read5() // N行K項
{
for (int i = 0; i < K; i++) {
string[] tmp = Console.ReadLine().Split(' ');
a.Add(int.Parse(tmp[0]));
b.Add(int.Parse(tmp[1]));
c.Add(0);
string[] tmp2 = Console.ReadLine().Split(' ');
for (int j = 0; j < b[i]; j++) {
c[i] += (int)Math.Pow(2, int.Parse(tmp2[j]) - 1);
}
}
}
}
|
[["+", 0, 7, 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, 22], ["+", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 47], ["+", 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, 22], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 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, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 60], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25]]
| 8
| 700
| 19
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
Scanner cin = new Scanner();
int n = cin.Int();
int k = cin.Int();
int[] p = cin.ArrayInt(n);
var ss = new MultiSet<int>();
for (int i = 0; i < k; i++) {
ss.Add(p[i]);
}
int ren = 0;
int pp = -1;
var ni = new bool[n];
for (int i = 0; i < n; i++) {
if (p[i] >= pp) {
ren++;
if (ren >= k) {
ni[i] = true;
}
} else {
ren = 1;
}
pp = p[i];
}
int ans = 1;
bool isNoSort = ni[k - 1];
for (int i = k; i < n; i++) {
int min = ss.Min;
ss.Remove(p[i - k]);
ss.Add(p[i]);
int max = ss.Max;
if (p[i - k] != min || p[i] != max) {
if (ni[i]) {
if (isNoSort == false) {
++ans;
}
isNoSort = true;
} else {
++ans;
}
}
}
Console.WriteLine(ans);
}
}
public class MultiSet<T> {
private SortedSet<T> set_;
private Dictionary<T, int> counts_ = new Dictionary<T, int>();
private int count_;
public MultiSet() { set_ = new SortedSet<T>(); }
public MultiSet(IComparer<T> comparer) { set_ = new SortedSet<T>(comparer); }
public MultiSet(IEnumerable<T> collection) {
set_ = new SortedSet<T>(collection);
}
public MultiSet(IEnumerable<T> collection, IComparer<T> comparer) {
set_ = new SortedSet<T>(collection, comparer);
}
public IComparer<T> Comparer => set_.Comparer;
public int Count => count_;
public T Max => set_.Max;
public T Min => set_.Min;
public bool Add(T item) {
if (counts_.ContainsKey(item)) {
counts_[item] = 1;
} else {
counts_[item]++;
}
++count_;
return true;
}
public bool Remove(T item) {
if (counts_.ContainsKey(item) == false) {
return false;
}
counts_[item]--;
count_--;
if (counts_[item] == 0) {
counts_.Remove(item);
set_.Remove(item);
}
return true;
}
public void Clear() {
counts_.Clear();
count_ = 0;
set_.Clear();
}
public bool Contains(T item) => set_.Contains(item);
}
public class Scanner {
private readonly char[] delimiter_ = new char[] { ' ' };
private string[] buf_;
private int index_;
public Scanner() {
buf_ = new string[0];
index_ = 0;
}
public string Next() {
if (index_ < buf_.Length) {
return buf_[index_++];
}
string st = Console.ReadLine();
while (st == "") {
st = Console.ReadLine();
}
buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
if (buf_.Length == 0) {
return Next();
}
index_ = 0;
return buf_[index_++];
}
public int Int() { return int.Parse(Next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long Long() { return long.Parse(Next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double Double() { 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] = Double() + add;
}
return Array;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
Scanner cin = new Scanner();
int n = cin.Int();
int k = cin.Int();
int[] p = cin.ArrayInt(n);
var ss = new MultiSet<int>();
for (int i = 0; i < k; i++) {
ss.Add(p[i]);
}
int ren = 0;
int pp = -1;
var ni = new bool[n];
for (int i = 0; i < n; i++) {
if (p[i] >= pp) {
ren++;
if (ren >= k) {
ni[i] = true;
}
} else {
ren = 1;
}
pp = p[i];
}
int ans = 1;
bool isNoSort = ni[k - 1];
for (int i = k; i < n; i++) {
int min = ss.Min;
ss.Remove(p[i - k]);
ss.Add(p[i]);
int max = ss.Max;
if (p[i - k] != min || p[i] != max) {
if (ni[i]) {
if (isNoSort == false) {
++ans;
}
isNoSort = true;
} else {
++ans;
}
}
}
Console.WriteLine(ans);
}
}
public class MultiSet<T> {
private SortedSet<T> set_;
private Dictionary<T, int> counts_ = new Dictionary<T, int>();
private int count_;
public MultiSet() { set_ = new SortedSet<T>(); }
public MultiSet(IComparer<T> comparer) { set_ = new SortedSet<T>(comparer); }
public MultiSet(IEnumerable<T> collection) {
set_ = new SortedSet<T>(collection);
}
public MultiSet(IEnumerable<T> collection, IComparer<T> comparer) {
set_ = new SortedSet<T>(collection, comparer);
}
public IComparer<T> Comparer => set_.Comparer;
public int Count => count_;
public T Max => set_.Max;
public T Min => set_.Min;
public bool Add(T item) {
if (counts_.ContainsKey(item) == false) {
counts_[item] = 1;
} else {
counts_[item]++;
}
set_.Add(item);
++count_;
return true;
}
public bool Remove(T item) {
if (counts_.ContainsKey(item) == false) {
return false;
}
counts_[item]--;
count_--;
if (counts_[item] == 0) {
counts_.Remove(item);
set_.Remove(item);
}
return true;
}
public void Clear() {
counts_.Clear();
count_ = 0;
set_.Clear();
}
public bool Contains(T item) => set_.Contains(item);
}
public class Scanner {
private readonly char[] delimiter_ = new char[] { ' ' };
private string[] buf_;
private int index_;
public Scanner() {
buf_ = new string[0];
index_ = 0;
}
public string Next() {
if (index_ < buf_.Length) {
return buf_[index_++];
}
string st = Console.ReadLine();
while (st == "") {
st = Console.ReadLine();
}
buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
if (buf_.Length == 0) {
return Next();
}
index_ = 0;
return buf_[index_++];
}
public int Int() { return int.Parse(Next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long Long() { return long.Parse(Next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double Double() { 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] = Double() + add;
}
return Array;
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 211, 0, 147], ["+", 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
| 989
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Program {
public static void Main(string[] args) {
var tenkis = new string[] { "Sunny", "Cloudy", "Rainy" }.ToList();
var input = Console.ReadLine();
Console.WriteLine(tenkis[tenkis.IndexOf(input) % (tenkis.Count - 1)]);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Program {
public static void Main(string[] args) {
var tenkis = new string[] { "Sunny", "Cloudy", "Rainy" }.ToList();
var input = Console.ReadLine().Trim();
Console.WriteLine(tenkis[(tenkis.IndexOf(input) + 1) % (tenkis.Count)]);
}
}
|
[["+", 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], ["+", 206, 207, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203]]
| 8
| 89
| 10
|
using CompLib.String;
using CompLib.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
public class Program {
public void Solve() {
var sc = new Scanner();
int n = sc.NextInt();
string s = sc.Next();
int ans = 0;
for (int b = 0; b < s.Length; b++) {
var z = StringACL.ZAlgorithm(s.AsSpan(b));
for (int i = 0; i < s.Length - b; i++) {
ans = Math.Max(ans, Math.Min(z[i], b));
}
}
Console.WriteLine(ans);
}
public static void Main(string[] args) => new Program().Solve();
// public static void Main(string[] args) => new Thread(new Program().Solve, 1
// << 27).Start();
}
namespace CompLib.String {
public static partial class StringACL {
private const int ThresholdNative = 10;
private const int ThresholdDoubling = 40;
#region SuffixArray
public static int[] SuffixArray(int[] s, int upper) {
Debug.Assert(0 <= upper);
// C++みたいに内部で何もしないループをスキップするのか?
// してくれるなら #ifいらない
#if DEBUG
foreach (var d in s) {
Debug.Assert(0 <= d && d <= upper);
}
#endif
return SAIS(s, upper);
}
public static int[] SuffixArray<T>(T[] s, Comparison<T> cmp) {
int n = s.Length;
int[] idx = new int[n];
for (int i = 0; i < n; i++) {
idx[i] = i;
}
Array.Sort(idx, (l, r) => cmp(s[l], s[r]));
int[] s2 = new int[n];
int now = 0;
for (int i = 0; i < n; i++) {
if (0 < i && cmp(s[idx[i - 1]], s[idx[i]]) != 0)
now++;
s2[idx[i]] = now;
}
return SAIS(s2, now);
}
public static int[] SuffixArray<T>(T[] s) {
return SuffixArray(s, Comparer<T>.Default.Compare);
}
/// <summary>
/// 長さnの文字列のsuffixArrayを返す
/// </summary>
/// <remarks>
/// <para>{0,1,2,...,n-1}の順列、s[sa[i],n) < s[sa[i+1],n)</para>
/// <para>suffixArrayの辞書順</para>
/// </remarks>
/// <param name="s"></param>
/// <returns></returns>
public static int[] SuffixArray(string s) {
int n = s.Length;
int[] s2 = new int[n];
for (int i = 0; i < n; i++) {
s2[i] = s[i];
}
return SAIS(s2, 255);
}
// O(n^2)
private static int[] SANative(int[] s) {
int n = s.Length;
int[] sa = new int[n];
for (int i = 0; i < n; i++) {
sa[i] = i;
}
Array.Sort(sa, (l, r) => {
// 同じなら0
if (l == r)
return 0;
// 順番に見る
while (l < n && r < n) {
if (s[l] != s[r])
return s[l].CompareTo(s[r]);
l++;
r++;
}
// indexが大きい方が辞書順で小さい
return r.CompareTo(l);
});
return sa;
}
private static int[] SADoubling(int[] s) {
int n = s.Length;
int[] sa = new int[n];
int[] rnk = new int[n];
int[] tmp = new int[n];
Array.Copy(s, rnk, n);
for (int i = 0; i < n; i++) {
sa[i] = i;
}
for (int k = 1; k < n; k *= 2) {
Comparison<int> cmp = (int x, int y) => {
if (rnk[x] != rnk[y])
return rnk[x].CompareTo(rnk[y]);
int rx = x + k < n ? rnk[x + k] : -1;
int ry = y + k < n ? rnk[y + k] : -1;
return rx.CompareTo(ry);
};
Array.Sort(sa, cmp);
tmp[sa[0]] = 0;
for (int i = 1; i < n; i++) {
tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) < 0 ? 1 : 0);
}
var t = tmp;
tmp = rnk;
rnk = t;
}
return sa;
}
private static int[] SAIS(int[] s, int upper) {
int n = s.Length;
if (n == 0)
return new int[0];
if (n == 1)
return new int[1];
if (n == 2) {
if (s[0] < s[1]) {
return new int[] { 0, 1 };
} else {
return new int[] { 1, 0 };
}
}
if (n < ThresholdNative) {
return SANative(s);
}
if (n < ThresholdDoubling) {
return SADoubling(s);
}
int[] sa = new int[n];
bool[] ls = new bool[n];
for (int i = n - 2; i >= 0; i--) {
ls[i] = (s[i] == s[i + 1]) ? ls[i + 1] : (s[i] < s[i + 1]);
}
int[] sumL = new int[upper + 1];
int[] sumS = new int[upper + 1];
for (int i = 0; i < n; i++) {
if (!ls[i]) {
sumS[s[i]]++;
} else {
sumL[s[i] + 1]++;
}
}
for (int i = 0; i <= upper; i++) {
sumS[i] += sumL[i];
if (i < upper)
sumL[i + 1] += sumS[i];
}
Action<List<int>> induce = (List<int> lms) => {
for (int i = 0; i < n; i++) {
sa[i] = -1;
}
int[] buf = new int[upper + 1];
Array.Copy(sumS, buf, upper + 1);
foreach (var d in lms) {
if (d == n)
continue;
sa[buf[s[d]]++] = d;
}
Array.Copy(sumL, buf, upper + 1);
sa[buf[s[n - 1]]++] = n - 1;
for (int i = 0; i < n; i++) {
int v = sa[i];
if (v >= 1 && !ls[v - 1]) {
sa[buf[s[v - 1]]++] = v - 1;
}
}
Array.Copy(sumL, buf, upper + 1);
for (int i = n - 1; i >= 0; i--) {
int v = sa[i];
if (v >= 1 && ls[v - 1]) {
sa[--buf[s[v - 1] + 1]] = v - 1;
}
}
};
int[] lmsMap = new int[n + 1];
for (int i = 0; i <= n; i++) {
lmsMap[i] = -1;
}
int m = 0;
for (int i = 1; i < n; i++) {
if (!ls[i - 1] && ls[i]) {
lmsMap[i] = m++;
}
}
List<int> lmsL = new List<int>(m);
for (int i = 1; i < n; i++) {
if (!ls[i - 1] && ls[i]) {
lmsL.Add(i);
}
}
induce(lmsL);
if (m != 0) {
List<int> sortedLms = new List<int>(m);
foreach (var v in sa) {
if (lmsMap[v] != -1)
sortedLms.Add(v);
}
int[] recS = new int[m];
int recUpper = 0;
recS[lmsMap[sortedLms[0]]] = 0;
for (int i = 1; i < m; i++) {
int l = sortedLms[i - 1], r = sortedLms[i];
int endL = (lmsMap[l] + 1 < m) ? lmsL[lmsMap[l] + 1] : n;
int endR = (lmsMap[r] + 1 < m) ? lmsL[lmsMap[r] + 1] : n;
bool same = true;
if (endL - l != endR - r) {
same = false;
} else {
while (l < endL) {
if (s[l] != s[r]) {
break;
}
l++;
r++;
}
if (l == n || s[l] != s[r])
same = false;
}
if (!same)
recUpper++;
recS[lmsMap[sortedLms[i]]] = recUpper;
}
var recSa = SAIS(recS, recUpper);
for (int i = 0; i < m; i++) {
sortedLms[i] = lmsL[recSa[i]];
}
induce(sortedLms);
}
return sa;
}
#endregion // SuffixArray
#region LCPArray
/// <summary>
/// sのLCPArrayとして長さ n-1の配列を返す
/// </summary>
/// <remarks>
/// <para>res[i]はs[sa[i],n), s[sa[i+1],n)のLongest Common
/// Prefixの長さ</para> <para>O(n)</para>
/// </remarks>
/// <typeparam name="T"></typeparam>
/// <param name="s"></param>
/// <param name="sa"></param>
/// <param name="cmp"></param>
/// <returns></returns>
public static int[] LCPArray<T>(T[] s, int[] sa, Comparison<T> cmp) {
int n = s.Length;
Debug.Assert(n >= 1);
int[] rnk = new int[n];
for (int i = 0; i < n; i++) {
rnk[sa[i]] = i;
}
int[] lcp = new int[n - 1];
int h = 0;
for (int i = 0; i < n; i++) {
if (h > 0)
h--;
if (rnk[i] == 0)
continue;
int j = sa[rnk[i] - 1];
for (; j + h < n && i + h < n; h++) {
if (cmp(s[j + h], s[i + h]) != 0)
break;
}
lcp[rnk[i] - 1] = h;
}
return lcp;
}
/// <summary>
/// sのLCPArrayとして長さ n-1の配列を返す
/// </summary>
/// <remarks>
/// <para>res[i]はs[sa[i],n), s[sa[i+1],n)のLongest Common
/// Prefixの長さ</para> <para>O(n)</para>
/// </remarks>
/// <typeparam name="T"></typeparam>
/// <param name="s"></param>
/// <param name="sa"></param>
/// <returns></returns>
public static int[] LCPArray<T>(T[] s, int[] sa) {
return LCPArray(s, sa, Comparer<T>.Default.Compare);
}
/// <summary>
/// sのLCPArrayとして長さ n-1の配列を返す
/// </summary>
/// <remarks>
/// <para>res[i]はs[sa[i],n), s[sa[i+1],n)のLongest Common
/// Prefixの長さ</para> <para>O(n)</para>
/// </remarks>
/// <typeparam name="T"></typeparam>
/// <param name="s"></param>
/// <param name="sa"></param>
/// <returns></returns>
public static int[] LCPArray(string s, int[] sa) {
// int n = s.Length;
// int[] s2 = new int[n];
// for (int i = 0; i < n; i++)
//{
// s2[i] = s[i];
//}
return LCPArray(s.ToCharArray(), sa);
}
#endregion // LCPArray
#region ZAlgorithm
/// <summary>
/// 長さnの配列sについて sと s[i,n)のLCPの長さを返す
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="s"></param>
/// <param name="eq"></param>
/// <returns></returns>
public static int[] ZAlgorithm<T>(ReadOnlySpan<T> s,
EqualityComparer<T> eq) {
int n = s.Length;
if (n == 0)
return new int[0];
int[] z = new int[n];
z[0] = 0;
for (int i = 1, j = 0; i < n; i++) {
ref int k = ref z[i];
k = (j + z[j] <= i) ? 0 : Math.Min(j + z[j] - i, z[i - j]);
while (i + k < n && eq.Equals(s[k], s[i + k]))
k++;
if (j + z[j] < i + z[i])
j = i;
}
z[0] = n;
return z;
}
/// <summary>
/// 長さnの配列sについて sと s[i,n)のLCPの長さを返す
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="s"></param>
/// <returns></returns>
public static int[] ZAlgorithm<T>(ReadOnlySpan<T> s) {
return ZAlgorithm(s, EqualityComparer<T>.Default);
}
#endregion
}
}
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 CompLib.String;
using CompLib.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
public class Program {
public void Solve() {
var sc = new Scanner();
int n = sc.NextInt();
string s = sc.Next();
int ans = 0;
for (int b = 0; b < s.Length; b++) {
var span = s.AsSpan(b);
var z = StringACL.ZAlgorithm(span);
for (int i = 0; i < span.Length; i++) {
ans = Math.Max(ans, Math.Min(z[i], i));
}
}
Console.WriteLine(ans);
}
public static void Main(string[] args) => new Program().Solve();
// public static void Main(string[] args) => new Thread(new Program().Solve, 1
// << 27).Start();
}
namespace CompLib.String {
public static partial class StringACL {
private const int ThresholdNative = 10;
private const int ThresholdDoubling = 40;
#region SuffixArray
public static int[] SuffixArray(int[] s, int upper) {
Debug.Assert(0 <= upper);
// C++みたいに内部で何もしないループをスキップするのか?
// してくれるなら #ifいらない
#if DEBUG
foreach (var d in s) {
Debug.Assert(0 <= d && d <= upper);
}
#endif
return SAIS(s, upper);
}
public static int[] SuffixArray<T>(T[] s, Comparison<T> cmp) {
int n = s.Length;
int[] idx = new int[n];
for (int i = 0; i < n; i++) {
idx[i] = i;
}
Array.Sort(idx, (l, r) => cmp(s[l], s[r]));
int[] s2 = new int[n];
int now = 0;
for (int i = 0; i < n; i++) {
if (0 < i && cmp(s[idx[i - 1]], s[idx[i]]) != 0)
now++;
s2[idx[i]] = now;
}
return SAIS(s2, now);
}
public static int[] SuffixArray<T>(T[] s) {
return SuffixArray(s, Comparer<T>.Default.Compare);
}
/// <summary>
/// 長さnの文字列のsuffixArrayを返す
/// </summary>
/// <remarks>
/// <para>{0,1,2,...,n-1}の順列、s[sa[i],n) < s[sa[i+1],n)</para>
/// <para>suffixArrayの辞書順</para>
/// </remarks>
/// <param name="s"></param>
/// <returns></returns>
public static int[] SuffixArray(string s) {
int n = s.Length;
int[] s2 = new int[n];
for (int i = 0; i < n; i++) {
s2[i] = s[i];
}
return SAIS(s2, 255);
}
// O(n^2)
private static int[] SANative(int[] s) {
int n = s.Length;
int[] sa = new int[n];
for (int i = 0; i < n; i++) {
sa[i] = i;
}
Array.Sort(sa, (l, r) => {
// 同じなら0
if (l == r)
return 0;
// 順番に見る
while (l < n && r < n) {
if (s[l] != s[r])
return s[l].CompareTo(s[r]);
l++;
r++;
}
// indexが大きい方が辞書順で小さい
return r.CompareTo(l);
});
return sa;
}
private static int[] SADoubling(int[] s) {
int n = s.Length;
int[] sa = new int[n];
int[] rnk = new int[n];
int[] tmp = new int[n];
Array.Copy(s, rnk, n);
for (int i = 0; i < n; i++) {
sa[i] = i;
}
for (int k = 1; k < n; k *= 2) {
Comparison<int> cmp = (int x, int y) => {
if (rnk[x] != rnk[y])
return rnk[x].CompareTo(rnk[y]);
int rx = x + k < n ? rnk[x + k] : -1;
int ry = y + k < n ? rnk[y + k] : -1;
return rx.CompareTo(ry);
};
Array.Sort(sa, cmp);
tmp[sa[0]] = 0;
for (int i = 1; i < n; i++) {
tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) < 0 ? 1 : 0);
}
var t = tmp;
tmp = rnk;
rnk = t;
}
return sa;
}
private static int[] SAIS(int[] s, int upper) {
int n = s.Length;
if (n == 0)
return new int[0];
if (n == 1)
return new int[1];
if (n == 2) {
if (s[0] < s[1]) {
return new int[] { 0, 1 };
} else {
return new int[] { 1, 0 };
}
}
if (n < ThresholdNative) {
return SANative(s);
}
if (n < ThresholdDoubling) {
return SADoubling(s);
}
int[] sa = new int[n];
bool[] ls = new bool[n];
for (int i = n - 2; i >= 0; i--) {
ls[i] = (s[i] == s[i + 1]) ? ls[i + 1] : (s[i] < s[i + 1]);
}
int[] sumL = new int[upper + 1];
int[] sumS = new int[upper + 1];
for (int i = 0; i < n; i++) {
if (!ls[i]) {
sumS[s[i]]++;
} else {
sumL[s[i] + 1]++;
}
}
for (int i = 0; i <= upper; i++) {
sumS[i] += sumL[i];
if (i < upper)
sumL[i + 1] += sumS[i];
}
Action<List<int>> induce = (List<int> lms) => {
for (int i = 0; i < n; i++) {
sa[i] = -1;
}
int[] buf = new int[upper + 1];
Array.Copy(sumS, buf, upper + 1);
foreach (var d in lms) {
if (d == n)
continue;
sa[buf[s[d]]++] = d;
}
Array.Copy(sumL, buf, upper + 1);
sa[buf[s[n - 1]]++] = n - 1;
for (int i = 0; i < n; i++) {
int v = sa[i];
if (v >= 1 && !ls[v - 1]) {
sa[buf[s[v - 1]]++] = v - 1;
}
}
Array.Copy(sumL, buf, upper + 1);
for (int i = n - 1; i >= 0; i--) {
int v = sa[i];
if (v >= 1 && ls[v - 1]) {
sa[--buf[s[v - 1] + 1]] = v - 1;
}
}
};
int[] lmsMap = new int[n + 1];
for (int i = 0; i <= n; i++) {
lmsMap[i] = -1;
}
int m = 0;
for (int i = 1; i < n; i++) {
if (!ls[i - 1] && ls[i]) {
lmsMap[i] = m++;
}
}
List<int> lmsL = new List<int>(m);
for (int i = 1; i < n; i++) {
if (!ls[i - 1] && ls[i]) {
lmsL.Add(i);
}
}
induce(lmsL);
if (m != 0) {
List<int> sortedLms = new List<int>(m);
foreach (var v in sa) {
if (lmsMap[v] != -1)
sortedLms.Add(v);
}
int[] recS = new int[m];
int recUpper = 0;
recS[lmsMap[sortedLms[0]]] = 0;
for (int i = 1; i < m; i++) {
int l = sortedLms[i - 1], r = sortedLms[i];
int endL = (lmsMap[l] + 1 < m) ? lmsL[lmsMap[l] + 1] : n;
int endR = (lmsMap[r] + 1 < m) ? lmsL[lmsMap[r] + 1] : n;
bool same = true;
if (endL - l != endR - r) {
same = false;
} else {
while (l < endL) {
if (s[l] != s[r]) {
break;
}
l++;
r++;
}
if (l == n || s[l] != s[r])
same = false;
}
if (!same)
recUpper++;
recS[lmsMap[sortedLms[i]]] = recUpper;
}
var recSa = SAIS(recS, recUpper);
for (int i = 0; i < m; i++) {
sortedLms[i] = lmsL[recSa[i]];
}
induce(sortedLms);
}
return sa;
}
#endregion // SuffixArray
#region LCPArray
/// <summary>
/// sのLCPArrayとして長さ n-1の配列を返す
/// </summary>
/// <remarks>
/// <para>res[i]はs[sa[i],n), s[sa[i+1],n)のLongest Common
/// Prefixの長さ</para> <para>O(n)</para>
/// </remarks>
/// <typeparam name="T"></typeparam>
/// <param name="s"></param>
/// <param name="sa"></param>
/// <param name="cmp"></param>
/// <returns></returns>
public static int[] LCPArray<T>(T[] s, int[] sa, Comparison<T> cmp) {
int n = s.Length;
Debug.Assert(n >= 1);
int[] rnk = new int[n];
for (int i = 0; i < n; i++) {
rnk[sa[i]] = i;
}
int[] lcp = new int[n - 1];
int h = 0;
for (int i = 0; i < n; i++) {
if (h > 0)
h--;
if (rnk[i] == 0)
continue;
int j = sa[rnk[i] - 1];
for (; j + h < n && i + h < n; h++) {
if (cmp(s[j + h], s[i + h]) != 0)
break;
}
lcp[rnk[i] - 1] = h;
}
return lcp;
}
/// <summary>
/// sのLCPArrayとして長さ n-1の配列を返す
/// </summary>
/// <remarks>
/// <para>res[i]はs[sa[i],n), s[sa[i+1],n)のLongest Common
/// Prefixの長さ</para> <para>O(n)</para>
/// </remarks>
/// <typeparam name="T"></typeparam>
/// <param name="s"></param>
/// <param name="sa"></param>
/// <returns></returns>
public static int[] LCPArray<T>(T[] s, int[] sa) {
return LCPArray(s, sa, Comparer<T>.Default.Compare);
}
/// <summary>
/// sのLCPArrayとして長さ n-1の配列を返す
/// </summary>
/// <remarks>
/// <para>res[i]はs[sa[i],n), s[sa[i+1],n)のLongest Common
/// Prefixの長さ</para> <para>O(n)</para>
/// </remarks>
/// <typeparam name="T"></typeparam>
/// <param name="s"></param>
/// <param name="sa"></param>
/// <returns></returns>
public static int[] LCPArray(string s, int[] sa) {
// int n = s.Length;
// int[] s2 = new int[n];
// for (int i = 0; i < n; i++)
//{
// s2[i] = s[i];
//}
return LCPArray(s.ToCharArray(), sa);
}
#endregion // LCPArray
#region ZAlgorithm
/// <summary>
/// 長さnの配列sについて sと s[i,n)のLCPの長さを返す
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="s"></param>
/// <param name="eq"></param>
/// <returns></returns>
public static int[] ZAlgorithm<T>(ReadOnlySpan<T> s,
EqualityComparer<T> eq) {
int n = s.Length;
if (n == 0)
return new int[0];
int[] z = new int[n];
z[0] = 0;
for (int i = 1, j = 0; i < n; i++) {
ref int k = ref z[i];
k = (j + z[j] <= i) ? 0 : Math.Min(j + z[j] - i, z[i - j]);
while (i + k < n && eq.Equals(s[k], s[i + k]))
k++;
if (j + z[j] < i + z[i])
j = i;
}
z[0] = n;
return z;
}
/// <summary>
/// 長さnの配列sについて sと s[i,n)のLCPの長さを返す
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="s"></param>
/// <returns></returns>
public static int[] ZAlgorithm<T>(ReadOnlySpan<T> s) {
return ZAlgorithm(s, EqualityComparer<T>.Default);
}
#endregion
}
}
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();
}
}
|
[["-", 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, 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], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 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, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 2,924
| 21
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace AtCoder {
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.OrdinalIgnoreCase);
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 AtCoder {
public string GetStr() { return Console.ReadLine().Trim(); }
public char GetChar() { return Console.ReadLine().Trim()[0]; }
public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); }
public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); }
public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
public T[][] CreateJaggedArray<T>(int H, int W, T value) {
return Enumerable.Repeat(0, H)
.Select(s => Enumerable.Repeat(value, W).ToArray())
.ToArray();
}
public int[][] GetIntJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetIntArray().ToArray())
.ToArray();
}
public long[][] GetLongJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetLongArray().ToArray())
.ToArray();
}
public char[][] GetCharJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetStr().ToCharArray())
.ToArray();
}
public double[][] GetDoubleJaggedArray(int N) {
return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray();
}
Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M,
bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<int, List<int>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<int>());
}
for (int i = 0; i < M; i++) {
var input = GetIntArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
dic[a].Add(b);
if (isDirected == false)
dic[b].Add(a);
}
return dic;
}
Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M,
bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<int, List<Edge>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<Edge>());
}
for (int i = 0; i < M; i++) {
var input = GetIntArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
var c = input[2];
dic[a].Add(new Edge(b, c));
if (isDirected == false)
dic[b].Add(new Edge(a, c));
}
return dic;
}
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
void Multi<T>(out T a) => a = cv<T>(GetStr());
void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
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]);
}
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]);
}
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]);
}
void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e,
out Y f) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
f = cv<Y>(ar[5]);
}
}
class Edge {
public Edge(int to, long length) {
To = to;
Length = length;
}
public int To { get; set; }
public long Length { get; set; }
}
partial class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new AtCoder().Solve();
Console.Out.Flush();
Console.Read();
}
}
public partial class AtCoder {
int N;
string S;
public void Solve() {
N = GetInt();
S = GetStr();
int ok = 0;
int ng = N / 2 + 1;
while (Math.Abs(ok - ng) > 1) {
var mid = (ok + ng) / 2;
if (IsOK(mid))
ok = mid;
else
ng = mid;
}
Console.WriteLine(ok);
}
bool IsOK(int len) {
var set = new HashSet<string>();
for (int i = 0; i < N - len + 1; i++) {
var s = S.Substring(i, len);
if (set.Contains(s))
return true;
else
set.Add(s);
}
return false;
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace AtCoder {
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.OrdinalIgnoreCase);
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 AtCoder {
public string GetStr() { return Console.ReadLine().Trim(); }
public char GetChar() { return Console.ReadLine().Trim()[0]; }
public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); }
public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); }
public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
public T[][] CreateJaggedArray<T>(int H, int W, T value) {
return Enumerable.Repeat(0, H)
.Select(s => Enumerable.Repeat(value, W).ToArray())
.ToArray();
}
public int[][] GetIntJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetIntArray().ToArray())
.ToArray();
}
public long[][] GetLongJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetLongArray().ToArray())
.ToArray();
}
public char[][] GetCharJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetStr().ToCharArray())
.ToArray();
}
public double[][] GetDoubleJaggedArray(int N) {
return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray();
}
Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M,
bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<int, List<int>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<int>());
}
for (int i = 0; i < M; i++) {
var input = GetIntArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
dic[a].Add(b);
if (isDirected == false)
dic[b].Add(a);
}
return dic;
}
Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M,
bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<int, List<Edge>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<Edge>());
}
for (int i = 0; i < M; i++) {
var input = GetIntArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
var c = input[2];
dic[a].Add(new Edge(b, c));
if (isDirected == false)
dic[b].Add(new Edge(a, c));
}
return dic;
}
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
void Multi<T>(out T a) => a = cv<T>(GetStr());
void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
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]);
}
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]);
}
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]);
}
void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e,
out Y f) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
f = cv<Y>(ar[5]);
}
}
class Edge {
public Edge(int to, long length) {
To = to;
Length = length;
}
public int To { get; set; }
public long Length { get; set; }
}
partial class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new AtCoder().Solve();
Console.Out.Flush();
Console.Read();
}
}
public partial class AtCoder {
int N;
string S;
public void Solve() {
N = GetInt();
S = GetStr();
int ok = 0;
int ng = N / 2 + 1;
while (Math.Abs(ok - ng) > 1) {
var mid = (ok + ng) / 2;
if (IsOK(mid))
ok = mid;
else
ng = mid;
}
Console.WriteLine(ok);
}
bool IsOK(int len) {
var dic = new Dictionary<string, int>();
for (int i = 0; i < N - len + 1; i++) {
var s = S.Substring(i, len);
if (dic.ContainsKey(s) == false)
dic.Add(s, i);
else {
if (dic[s] + len <= i)
return true;
}
}
return false;
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 21], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 211, 0, 147], ["-", 0, 7, 8, 196, 0, 57, 64, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 37, 0, 211, 0, 146], ["-", 0, 7, 8, 196, 0, 57, 64, 37, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 21], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 0, 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, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 57, 75, 196, 0, 57, 64, 37, 0, 38], ["+", 75, 196, 0, 57, 64, 37, 0, 211, 0, 146], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 1,863
| 37
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC141E {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
int ans = 0;
for (int k = 1; k <= N / 2; k++) {
string n = s.Substring(N - k) + s.Substring(0, N - k);
int[] count = new int[N + 1];
for (int i = 0; i < N; i++) {
if (s[i] == n[i])
count[i + 1] = count[i] + 1;
}
int cand = Math.Min(count.Max(), k);
ans = Math.Max(ans, cand);
}
Console.WriteLine(ans);
Console.ReadKey();
}
static int[] ReadInt() {
int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
return ret;
}
static long[] ReadLong() {
long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
return ret;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC141E {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
int ans = 0;
for (int k = 1; k <= N / 2; k++) {
string n = s.Substring(N - k) + s.Substring(0, N - k);
int[] count = new int[N + 1];
for (int i = 0; i < N; i++) {
if (s[i] == n[i])
count[i + 1] = count[i] + 1;
if (i == k && count[i + 1] > 0)
count[i + 1] = 1;
}
int cand = Math.Min(count.Max(), k);
ans = Math.Max(ans, cand);
}
Console.WriteLine(ans);
Console.ReadKey();
}
static int[] ReadInt() {
int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
return ret;
}
static long[] ReadLong() {
long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
return ret;
}
}
}
|
[["+", 8, 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, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 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], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 11, 31, 204, 205, 22], ["+", 64, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 64, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 274
| 24
|
#if true
//#if false
#define UTAKA_DEBUG
#endif
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Net.Mime;
using System.Text;
namespace UtakaApp {
public partial class Program {
public const string ContestName = "abc141";
public const string ProblemName = "E";
public static void Main(string[] args) {
#if UTAKA_LOCAL
//#if false
new TestCaseCheckerForAtCoder().TestProblems();
#else
var console = new MyConsole();
new Program().Solve(System.Console.In, console);
console.Flush();
#endif
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
}
public void Solve(TextReader textReader, IConsole console) {
var cin = new ConsoleInput(textReader);
int N = cin.ReadInt;
string S = cin.Read;
long ans = 0;
int left = 0;
int right = N;
var rh = new StringRollingHash(S);
while (right - left > 1) {
int mid = left + (right - left) / 2;
if (IsOk(mid, rh, N)) {
left = mid;
} else {
right = mid;
}
}
console.WriteLine(left.ToString());
}
public bool IsOk(int d, StringRollingHash rh, int N) {
var map = new Dictionary<long, int>();
for (int i = 0; i + d <= N; i++) {
// var hashes = rh.GetHashes(i, i + d);
var hash = rh.GetHash(i, i + d, 0);
if (map.ContainsKey(hash)) {
var dist = i - map[hash];
if (dist >= d) {
return true;
}
} else {
map.Add(hash, i);
}
}
long a = long.MaxValue;
return false;
}
}
public class StringRollingHash {
// private static readonly long[] Mods = {9123372036854775547,
// 999999893, 999999937};
private static readonly long[] Mods = { 9123372036854775533 };
private static readonly long Base = 1013;
private readonly long[,] Hashes;
private readonly long[,] Powers;
private readonly string S;
public StringRollingHash(string s) {
int modCount = Mods.Length;
S = s;
Hashes = new long[modCount, s.Length + 1];
Powers = new long[modCount, s.Length + 1];
for (int i = 0; i < modCount; i++) {
Powers[i, 0] = 1;
for (int j = 0; j < s.Length; j++) {
Hashes[i, j + 1] = (Hashes[i, j] * Base + s[j]) % Mods[i];
Powers[i, j + 1] = Powers[i, j] * Base % Mods[i];
}
}
}
/// <summary>
/// Mods[i]におけるS[l,r)のハッシュを取得
/// </summary>
public long GetHash(int l, int r, int i) {
long res = (Hashes[i, r] - Hashes[i, l] * Powers[i, r - l]) % Mods[i];
if (res < 0) {
res += Mods[i];
}
return res;
}
/// <summary>
/// 全てのModsにおけるs[l,r)のハッシュを取得
/// </summary>
public long[] GetHashes(int l, int r) {
List<long> hashList = new List<long>();
for (int i = 0; i < Mods.Length; i++) {
hashList.Add(GetHash(l, r, i));
}
return hashList.ToArray();
}
/// <summary>
/// 全てのModsでS[l,r)が一致するか
/// 2つのhashを比較する
/// </summary>
public bool Match(StringRollingHash other, int l1, int l2, int len) {
// 範囲外
if (S.Length < l1 + len || other.S.Length < l2 + len) {
return false;
}
for (var i = 0; i < Mods.Length; i++) {
if (GetHash(l1, l1 + len, i) != other.GetHash(l2, l2 + len, i)) {
return false;
}
}
return true;
}
/// <summary>
/// 最長共通接頭辞の長さ
/// this.S[l1:]とother.S[l2:]
/// </summary>
public int GetLcp(StringRollingHash other, int l1, int l2) {
var len = Math.Min(S.Length - l1, other.S.Length - l2);
int low = -1, high = len + 1;
while (high - low > 1) {
var mid = low + (high - low) / 2;
if (!Match(other, l1, l2, mid)) {
high = mid;
} else {
low = mid;
}
}
return low;
}
/// <summary>
/// 最長共通接頭辞の長さ
/// </summary>
public int GetLcp(int l1, int l2) { return GetLcp(this, l1, l2); }
/// <summary>
/// this.S[l1:]がotherで始まっているか
/// </summary>
public bool BeginWith(StringRollingHash other, int l1) {
return Match(other, l1, 0, other.S.Length);
}
}
public partial class Program { public const int ModLarge = 1000000007; }
public class ConsoleInput {
private readonly TextReader _stream;
private readonly char _separator = ' ';
private readonly Queue<string> inputStream;
public ConsoleInput(TextReader stream, char separator = ' ') {
_separator = separator;
_stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0) {
return inputStream.Dequeue();
}
var tmp = _stream.ReadLine().Split(_separator);
for (var i = 0; i < tmp.Length; ++i) {
inputStream.Enqueue(tmp[i]);
}
return inputStream.Dequeue();
}
}
public string ReadLine => _stream.ReadLine();
public int ReadInt => int.Parse(Read);
public long ReadLong => long.Parse(Read);
public double ReadDouble => 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 interface IConsole {
void Flush();
void Write(string str);
void WriteLine(string str);
}
public class MyConsole : IConsole {
public MyConsole() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
public void Flush() { Console.Out.Flush(); }
public void Write(string str) { Console.Write(str); }
public void WriteLine(string str) { Console.WriteLine(str); }
}
#if UTAKA_LOCAL
public class DebugConsole : IConsole {
private readonly StringBuilder mSb;
public DebugConsole() { mSb = new StringBuilder(); }
public void Flush() {
// 何もしない
}
public void Write(string str) { mSb.Append(str); }
public void WriteLine(string str) { mSb.AppendLine(str); }
public string GetAllOutput() { return mSb.ToString(); }
}
#endif
#if UTAKA_LOCAL
public class TestCaseCheckerForAtCoder {
private string DirectoryPath =>
$"../../../../{Program.ContestName}/{Program.ProblemName}";
private string GetInputFilePath(int testCaseNumber) {
// return $"{DirectoryPath}/sample-{testCaseNumber}.in";
return $"{DirectoryPath}/in_{testCaseNumber}.txt";
}
private string GetOutputFilePath(int testCaseNumber) {
// return $"{DirectoryPath}/sample-{testCaseNumber}.out";
return $"{DirectoryPath}/out_{testCaseNumber}.txt";
}
public bool TestProblem(int testCaseNumber) {
var inputFilePath = GetInputFilePath(testCaseNumber);
var outputFilePath = GetOutputFilePath(testCaseNumber);
TextReader inputStream = new StreamReader(inputFilePath);
var debugConsoleWriter = new DebugConsole();
new Program().Solve(inputStream, debugConsoleWriter);
var output = debugConsoleWriter.GetAllOutput();
TextReader outputStream = new StreamReader(outputFilePath);
var outputAnswer = outputStream.ReadToEnd();
Dbg.WriteLine(output);
Dbg.WriteLine(outputAnswer);
var isCorrect = output == outputAnswer;
return isCorrect;
}
public void TestProblems() {
var isSuccessAll = true;
var testCaseNumber = 1;
while (true) {
var inputFileName = GetInputFilePath(testCaseNumber);
if (!File.Exists(inputFileName)) {
break;
}
Console.WriteLine(
$"TestCase {testCaseNumber} =====================================================");
var result = TestProblem(testCaseNumber);
if (result) {
Console.WriteLine("Success");
} else {
isSuccessAll = false;
Console.WriteLine("Failure *****");
}
testCaseNumber++;
}
if (isSuccessAll) {
Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!");
}
}
}
#endif
#if UTAKA_LOCAL
public static class Dbg {
public static void WriteLine(string str) { Console.WriteLine(str); }
public static void Write(string str) { Console.Write(str); }
}
#else
public static class Dbg {
public static void WriteLine(string str) {}
public static void Write(string str) {}
}
#endif
}
|
#if true
//#if false
#define UTAKA_DEBUG
#endif
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Net.Mime;
using System.Text;
namespace UtakaApp {
public partial class Program {
public const string ContestName = "abc141";
public const string ProblemName = "E";
public static void Main(string[] args) {
#if UTAKA_LOCAL
//#if false
new TestCaseCheckerForAtCoder().TestProblems();
#else
var console = new MyConsole();
new Program().Solve(System.Console.In, console);
console.Flush();
#endif
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
}
public void Solve(TextReader textReader, IConsole console) {
var cin = new ConsoleInput(textReader);
int N = cin.ReadInt;
string S = cin.Read;
long ans = 0;
int left = 0;
int right = N;
var rh = new StringRollingHash(S);
while (right - left > 1) {
int mid = left + (right - left) / 2;
if (IsOk(mid, rh, N)) {
left = mid;
} else {
right = mid;
}
}
console.WriteLine(left.ToString());
}
public bool IsOk(int d, StringRollingHash rh, int N) {
// var map = new Dictionary<long, int>();
var map = new Dictionary<string, int>();
for (int i = 0; i + d <= N; i++) {
// var hashes = rh.GetHashes(i, i + d);
// var hash = rh.GetHash(i, i + d, 0);
var hash = rh.GetAllHashString(i, i + d);
if (map.ContainsKey(hash)) {
var dist = i - map[hash];
if (dist >= d) {
return true;
}
} else {
map.Add(hash, i);
}
}
long a = long.MaxValue;
return false;
}
}
public class StringRollingHash {
private static readonly long[] Mods = { 999999893, 999999937 };
// private static readonly long[] Mods = {9123372036854775533};
private static readonly long Base = 1013;
private readonly long[,] Hashes;
private readonly long[,] Powers;
private readonly string S;
public StringRollingHash(string s) {
int modCount = Mods.Length;
S = s;
Hashes = new long[modCount, s.Length + 1];
Powers = new long[modCount, s.Length + 1];
for (int i = 0; i < modCount; i++) {
Powers[i, 0] = 1;
for (int j = 0; j < s.Length; j++) {
Hashes[i, j + 1] = (Hashes[i, j] * Base + s[j]) % Mods[i];
Powers[i, j + 1] = Powers[i, j] * Base % Mods[i];
}
}
}
/// <summary>
/// Mods[i]におけるS[l,r)のハッシュを取得
/// </summary>
public long GetHash(int l, int r, int i) {
long res = (Hashes[i, r] - Hashes[i, l] * Powers[i, r - l]) % Mods[i];
if (res < 0) {
res += Mods[i];
}
return res;
}
public string GetAllHashString(int l, int r) {
long[] a = GetHashes(l, r);
return $"{a[0]}{a[1]}";
}
/// <summary>
/// 全てのModsにおけるs[l,r)のハッシュを取得
/// </summary>
public long[] GetHashes(int l, int r) {
List<long> hashList = new List<long>();
for (int i = 0; i < Mods.Length; i++) {
hashList.Add(GetHash(l, r, i));
}
return hashList.ToArray();
}
/// <summary>
/// 全てのModsでS[l,r)が一致するか
/// 2つのhashを比較する
/// </summary>
public bool Match(StringRollingHash other, int l1, int l2, int len) {
// 範囲外
if (S.Length < l1 + len || other.S.Length < l2 + len) {
return false;
}
for (var i = 0; i < Mods.Length; i++) {
if (GetHash(l1, l1 + len, i) != other.GetHash(l2, l2 + len, i)) {
return false;
}
}
return true;
}
/// <summary>
/// 最長共通接頭辞の長さ
/// this.S[l1:]とother.S[l2:]
/// </summary>
public int GetLcp(StringRollingHash other, int l1, int l2) {
var len = Math.Min(S.Length - l1, other.S.Length - l2);
int low = -1, high = len + 1;
while (high - low > 1) {
var mid = low + (high - low) / 2;
if (!Match(other, l1, l2, mid)) {
high = mid;
} else {
low = mid;
}
}
return low;
}
/// <summary>
/// 最長共通接頭辞の長さ
/// </summary>
public int GetLcp(int l1, int l2) { return GetLcp(this, l1, l2); }
/// <summary>
/// this.S[l1:]がotherで始まっているか
/// </summary>
public bool BeginWith(StringRollingHash other, int l1) {
return Match(other, l1, 0, other.S.Length);
}
}
public partial class Program { public const int ModLarge = 1000000007; }
public class ConsoleInput {
private readonly TextReader _stream;
private readonly char _separator = ' ';
private readonly Queue<string> inputStream;
public ConsoleInput(TextReader stream, char separator = ' ') {
_separator = separator;
_stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0) {
return inputStream.Dequeue();
}
var tmp = _stream.ReadLine().Split(_separator);
for (var i = 0; i < tmp.Length; ++i) {
inputStream.Enqueue(tmp[i]);
}
return inputStream.Dequeue();
}
}
public string ReadLine => _stream.ReadLine();
public int ReadInt => int.Parse(Read);
public long ReadLong => long.Parse(Read);
public double ReadDouble => 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 interface IConsole {
void Flush();
void Write(string str);
void WriteLine(string str);
}
public class MyConsole : IConsole {
public MyConsole() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
public void Flush() { Console.Out.Flush(); }
public void Write(string str) { Console.Write(str); }
public void WriteLine(string str) { Console.WriteLine(str); }
}
#if UTAKA_LOCAL
public class DebugConsole : IConsole {
private readonly StringBuilder mSb;
public DebugConsole() { mSb = new StringBuilder(); }
public void Flush() {
// 何もしない
}
public void Write(string str) { mSb.Append(str); }
public void WriteLine(string str) { mSb.AppendLine(str); }
public string GetAllOutput() { return mSb.ToString(); }
}
#endif
#if UTAKA_LOCAL
public class TestCaseCheckerForAtCoder {
private string DirectoryPath =>
$"../../../../{Program.ContestName}/{Program.ProblemName}";
private string GetInputFilePath(int testCaseNumber) {
// return $"{DirectoryPath}/sample-{testCaseNumber}.in";
return $"{DirectoryPath}/in_{testCaseNumber}.txt";
}
private string GetOutputFilePath(int testCaseNumber) {
// return $"{DirectoryPath}/sample-{testCaseNumber}.out";
return $"{DirectoryPath}/out_{testCaseNumber}.txt";
}
public bool TestProblem(int testCaseNumber) {
var inputFilePath = GetInputFilePath(testCaseNumber);
var outputFilePath = GetOutputFilePath(testCaseNumber);
TextReader inputStream = new StreamReader(inputFilePath);
var debugConsoleWriter = new DebugConsole();
new Program().Solve(inputStream, debugConsoleWriter);
var output = debugConsoleWriter.GetAllOutput();
TextReader outputStream = new StreamReader(outputFilePath);
var outputAnswer = outputStream.ReadToEnd();
Dbg.WriteLine(output);
Dbg.WriteLine(outputAnswer);
var isCorrect = output == outputAnswer;
return isCorrect;
}
public void TestProblems() {
var isSuccessAll = true;
var testCaseNumber = 1;
while (true) {
var inputFileName = GetInputFilePath(testCaseNumber);
if (!File.Exists(inputFileName)) {
break;
}
Console.WriteLine(
$"TestCase {testCaseNumber} =====================================================");
var result = TestProblem(testCaseNumber);
if (result) {
Console.WriteLine("Success");
} else {
isSuccessAll = false;
Console.WriteLine("Failure *****");
}
testCaseNumber++;
}
if (isSuccessAll) {
Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!");
}
}
}
#endif
#if UTAKA_LOCAL
public static class Dbg {
public static void WriteLine(string str) { Console.WriteLine(str); }
public static void Write(string str) { Console.Write(str); }
}
#else
public static class Dbg {
public static void WriteLine(string str) {}
public static void Write(string str) {}
}
#endif
}
|
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 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, 213, 3, 4, 0, 21], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 229, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 229, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 229, 0, 21], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 259], ["+", 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], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 21], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["+", 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, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 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, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 37, 0, 283, 0, 295], ["+", 8, 196, 0, 37, 0, 283, 0, 284, 0, 45], ["+", 0, 37, 0, 283, 0, 284, 0, 204, 205, 22], ["+", 0, 283, 0, 284, 0, 204, 206, 207, 0, 70], ["+", 0, 284, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 283, 0, 284, 0, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 37, 0, 283, 0, 284, 0, 46], ["+", 0, 195, 8, 196, 0, 37, 0, 283, 0, 62]]
| 8
| 1,871
| 50
|
using System;
using System.Collections.Generic;
public class RollingHash {
const long base1 = 1009;
const long base2 = 1007;
const long mod1 = 1000000007;
const long mod2 = 1000000009;
long[] hash1, hash2, pow1, pow2;
public RollingHash(string s) {
int n = s.Length;
hash1 = new long[n + 1];
hash2 = new long[n + 1];
pow1 = new long[n + 1];
pow2 = new long[n + 1];
pow1[0] = 1;
pow2[0] = 1;
for (int i = 0; i < n; i++) {
hash1[i + 1] = (hash1[i] + s[i]) * base1 % mod1;
hash2[i + 1] = (hash2[i] + s[i]) * base2 % mod2;
pow1[i + 1] = pow1[i] * base1 % mod1;
pow2[i + 1] = pow2[i] * base2 % mod2;
}
}
public Tuple<long, long> get(int l, int r) {
long t1 = ((hash1[r] - hash1[l] * pow1[r - l]) % mod1 + mod1) % mod1;
long t2 = ((hash2[r] - hash2[l] * pow2[r - l]) % mod2 + mod2) % mod2;
return new Tuple<long, long>(t1, t2);
}
}
public class Hello {
public static void Main() {
int N = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
var dict = new Dictionary<Tuple<long, long>, Tuple<int, int>>();
var rh = new RollingHash(S);
int max = 0;
int left = 0;
int right = N;
while (right - left > 1) {
int l = left + (right - left) / 2;
bool flag = false;
for (int i = 0; i + l <= N; i++) {
if (l <= max)
break;
var hash = rh.get(i, i + l);
if (dict.ContainsKey(hash)) {
if (dict[hash].Item2 <= i) {
// 2つ目を発見
// max = l;
flag = true;
} else {
break;
}
} else {
dict[hash] = new Tuple<int, int>(l, i + l);
}
}
if (flag) {
left = l;
} else {
right = l;
}
}
Console.WriteLine(left);
}
}
|
using System;
using System.Collections.Generic;
public class RollingHash {
const long base1 = 1009;
const long base2 = 1007;
const long mod1 = 1000000007;
const long mod2 = 1000000009;
long[] hash1, hash2, pow1, pow2;
public RollingHash(string s) {
int n = s.Length;
hash1 = new long[n + 1];
hash2 = new long[n + 1];
pow1 = new long[n + 1];
pow2 = new long[n + 1];
pow1[0] = 1;
pow2[0] = 1;
for (int i = 0; i < n; i++) {
hash1[i + 1] = (hash1[i] + s[i]) * base1 % mod1;
hash2[i + 1] = (hash2[i] + s[i]) * base2 % mod2;
pow1[i + 1] = pow1[i] * base1 % mod1;
pow2[i + 1] = pow2[i] * base2 % mod2;
}
}
public Tuple<long, long> get(int l, int r) {
long t1 = ((hash1[r] - hash1[l] * pow1[r - l]) % mod1 + mod1) % mod1;
long t2 = ((hash2[r] - hash2[l] * pow2[r - l]) % mod2 + mod2) % mod2;
return new Tuple<long, long>(t1, t2);
}
}
public class Hello {
public static void Main() {
int N = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
var dict = new Dictionary<Tuple<long, long>, Tuple<int, int>>();
var rh = new RollingHash(S);
int left = 0;
int right = N + 1;
while (right - left > 1) {
int l = left + (right - left) / 2;
bool flag = false;
for (int i = 0; i + l <= N; i++) {
var hash = rh.get(i, i + l);
if (dict.ContainsKey(hash)) {
if (dict[hash].Item2 <= i) {
// 2つ目を発見
flag = true;
break;
}
} else {
dict[hash] = new Tuple<int, int>(l, i + l);
}
}
if (flag) {
left = l;
} else {
right = l;
}
}
Console.WriteLine(left);
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 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]]
| 8
| 537
| 18
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections; //ハッシュテーブル用
using System.Linq;
class Program {
// Hashtable ht = new Hashtable();
static List<int> s = new List<int>();
static List<int>[] sl;
static decimal result;
static int N, K, Q;
// StringBuilder strresult= new StringBuilder("");//Append(str
// ○○)関数で文字を追加していく
static void Main() {
// Modular mo = new
// Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方:Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる(powべき乗、Fac累乗、nCr組み合わせも関数として存在)
// Node<> no = new
// Node<>();//UnionFind★Find関数で根っこの値を返す(根っこの値が一緒なら同グループ)、Unite関数で二つの木をくっつける
// Permutation<> pe = new
// Permutation<>();//配列&リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
// Treap<> tr = new
// Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
// PriorityQueue<int,int> pr = new
// PriorityQueue<int,int>();//優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
Read1();
string tmp = Console.ReadLine();
int[,] check = new int[N, N];
//文字列をyでぶった切って比較する。
// checkによるスキップを効かせるために後ろから探査する。
for (int y = N - 1; y > 0; y--) {
//動的計画法を利用。
// xスタートとyスタートで比較した場合の共通部分長さcheck(x,y)を保存する。
for (int x = y - 1; x >= 0; x--) {
int i;
for (i = 0; i < y - x && i < N - y; i++) {
if (tmp[y + i] == tmp[x + i]) {
// iで一致してたらi+1のcheckを見る。
//これが0でないということはtmp[x+i+1]==tmp[y+i+1]であり、check[x+i+1,y+i+1]にはi+1以降の一致数が保存されているということ。
if (y + i + 1 < N &&
x + i + 1 <
N) { //尻の部分で配列からはみ出さないように。尻にはcheckがないが普通に一致をカウントするだけ。
if (check[x + i + 1, y + i + 1] > 0) {
i += check[x + i + 1, y + i + 1];
i++;
break;
} // breakする前に、自分が一致している分のi++を忘れずに。
}
} else {
break;
}
}
check[x, y] =
i; //要は、x,yに来ればiだけ共通部分スキップできるということ。
if (i > result) {
result = i;
}
}
}
Console.WriteLine(result.ToString());
}
static void Read1() // 1項
{
string tmp = Console.ReadLine();
N = int.Parse(tmp);
}
static void Read2() //複数項(項目数N)
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read3() // 1行複数項
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < tmp.Length; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read4() // NK1行
{
string[] tmp = Console.ReadLine().Split(' ');
N = int.Parse(tmp[0]);
K = int.Parse(tmp[1]);
}
static void Read5() // N行K項
{
sl = new List<int>[N];
for (int i = 0; i < N; i++) {
sl[i] = new List<int>();
string[] tmp = Console.ReadLine().Split(' ');
for (int j = 0; j < K; j++) {
sl[i].Add(int.Parse(tmp[j]));
}
}
}
}
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections; //ハッシュテーブル用
using System.Linq;
class Program {
// Hashtable ht = new Hashtable();
static List<int> s = new List<int>();
static List<int>[] sl;
static decimal result;
static int N, K, Q;
// StringBuilder strresult= new StringBuilder("");//Append(str
// ○○)関数で文字を追加していく
static void Main() {
// Modular mo = new
// Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方:Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる(powべき乗、Fac累乗、nCr組み合わせも関数として存在)
// Node<> no = new
// Node<>();//UnionFind★Find関数で根っこの値を返す(根っこの値が一緒なら同グループ)、Unite関数で二つの木をくっつける
// Permutation<> pe = new
// Permutation<>();//配列&リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
// Treap<> tr = new
// Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
// PriorityQueue<int,int> pr = new
// PriorityQueue<int,int>();//優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
Read1();
string tmp = Console.ReadLine();
int[,] check = new int[N, N];
//文字列をyでぶった切って比較する。
// checkによるスキップを効かせるために後ろから探査する。
for (int y = N - 1; y > 0; y--) {
//動的計画法を利用。
// xスタートとyスタートで比較した場合の共通部分長さcheck(x,y)を保存する。
//★yの切り口によってcheckの足しこみ境界が変わるのをどう処理する?
for (int x = y - 1; x >= 0; x--) {
int i;
for (i = 0; i < y - x && i < N - y; i++) {
if (tmp[y + i] == tmp[x + i]) {
// iで一致してたらi+1のcheckを見る。
//これが0でないということはtmp[x+i+1]==tmp[y+i+1]であり、check[x+i+1,y+i+1]にはi+1以降の一致数が保存されているということ。
if (y + i + 1 < N &&
x + i + 1 <
N) { //尻の部分で配列からはみ出さないように。尻にはcheckがないが普通に一致をカウントするだけ。
if (check[x + i + 1, y + i + 1] > 0) {
i += check[x + i + 1, y + i + 1];
if (i >= y - x) {
i = y - x - 1;
} // check加算時にy側まではみ出さないようにする。
i++;
break;
} // breakする前に、自分が一致している分のi++を忘れずに。
}
} else {
break;
}
}
check[x, y] =
i; //要は、x,yに来ればiだけ共通部分スキップできるということ。
if (i > result) {
result = i;
}
}
}
Console.WriteLine(result.ToString());
}
static void Read1() // 1項
{
string tmp = Console.ReadLine();
N = int.Parse(tmp);
}
static void Read2() //複数項(項目数N)
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read3() // 1行複数項
{
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < tmp.Length; i++) {
s.Add(int.Parse(tmp[i]));
}
}
static void Read4() // NK1行
{
string[] tmp = Console.ReadLine().Split(' ');
N = int.Parse(tmp[0]);
K = int.Parse(tmp[1]);
}
static void Read5() // N行K項
{
sl = new List<int>[N];
for (int i = 0; i < N; i++) {
sl[i] = new List<int>();
string[] tmp = Console.ReadLine().Split(' ');
for (int j = 0; j < K; j++) {
sl[i].Add(int.Parse(tmp[j]));
}
}
}
}
|
[["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 596
| 18
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var n = cin.nextInt();
if (n == 1) {
Console.WriteLine(0);
}
Console.WriteLine(Math.Pow(n, 3));
}
}
#region library
static class C {
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long UpperBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] < key)
l = mid + 1;
else
r = mid;
}
return l;
}
}
public static partial class MathEx {
public static int GCD(int n, int m) { return (int)GCD((long)n, m); }
public static long GCD(long n, long m) {
n = Math.Abs(n);
m = Math.Abs(m);
while (n != 0) {
m %= n;
if (m == 0)
return n;
n %= m;
}
return m;
}
public static long LCM(long n, long m) { return (n / GCD(n, m)) * m; }
public static bool[] Sieve(int max, List<int> primes = null) {
var isPrime = new bool[max + 1];
for (int i = 2; i < isPrime.Length; i++)
isPrime[i] = true;
for (int i = 2; i * i <= max; i++)
if (!isPrime[i])
continue;
else
for (int j = i * i; j <= max; j += i)
isPrime[j] = false;
if (primes != null)
for (int i = 0; i <= max; i++)
if (isPrime[i])
primes.Add(i);
return isPrime;
}
}
static class Subsequence {
/// <summary>
/// 最長増加部分列
/// </summary>
/// <param name="a">long[]</param>
/// <returns></returns>
public static long LIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[C.LowerBound(dp, a[i])] = a[i];
}
return C.LowerBound(dp, long.MaxValue - 1);
}
/// <summary>
/// 重複を許さない最長増加部分列
/// </summary>
/// <param name="a">long[]</param>
/// <returns></returns>
public static long UniqueLIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[C.UpperBound(dp, a[i])] = a[i];
}
return C.UpperBound(dp, long.MaxValue - 1);
}
}
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
public class ModInt {
public static long Mod;
public long num;
public ModInt(long n, int mod = (int)1e9 + 7) {
num = n;
Mod = mod;
}
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var n = cin.nextInt();
Console.WriteLine(n * n * n);
}
}
#region library
static class C {
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long UpperBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] < key)
l = mid + 1;
else
r = mid;
}
return l;
}
}
public static partial class MathEx {
public static int GCD(int n, int m) { return (int)GCD((long)n, m); }
public static long GCD(long n, long m) {
n = Math.Abs(n);
m = Math.Abs(m);
while (n != 0) {
m %= n;
if (m == 0)
return n;
n %= m;
}
return m;
}
public static long LCM(long n, long m) { return (n / GCD(n, m)) * m; }
public static bool[] Sieve(int max, List<int> primes = null) {
var isPrime = new bool[max + 1];
for (int i = 2; i < isPrime.Length; i++)
isPrime[i] = true;
for (int i = 2; i * i <= max; i++)
if (!isPrime[i])
continue;
else
for (int j = i * i; j <= max; j += i)
isPrime[j] = false;
if (primes != null)
for (int i = 0; i <= max; i++)
if (isPrime[i])
primes.Add(i);
return isPrime;
}
}
static class Subsequence {
/// <summary>
/// 最長増加部分列
/// </summary>
/// <param name="a">long[]</param>
/// <returns></returns>
public static long LIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[C.LowerBound(dp, a[i])] = a[i];
}
return C.LowerBound(dp, long.MaxValue - 1);
}
/// <summary>
/// 重複を許さない最長増加部分列
/// </summary>
/// <param name="a">long[]</param>
/// <returns></returns>
public static long UniqueLIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[C.UpperBound(dp, a[i])] = a[i];
}
return C.UpperBound(dp, long.MaxValue - 1);
}
}
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
public class ModInt {
public static long Mod;
public long num;
public ModInt(long n, int mod = (int)1e9 + 7) {
num = n;
Mod = mod;
}
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 1,767
| 26
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] A =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long[] B =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long[] C =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long result = 0;
long lastTime = 0;
B.Sum();
for (int p = 0; p < N; p++) {
// 1つ前に追加したのと比較したい→料理番号を保持してきたい
result += B[A[p] - 1];
if (A[p] == lastTime + 1) {
result += C[A[p] - 1 - 1];
}
lastTime = A[p];
}
Console.WriteLine(result);
}
}
}
// 文字列の入力
// string s = Console.ReadLine();
// 整数の入力
// long n = long.Parse(Console.ReadLine());
// 文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
// 整数配列の入力
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] A =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long[] B =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long[] C =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long result = 0;
result += B.Sum();
for (int p = 0; p < N; p++) {
// 1つ前に追加したのと比較したい→料理番号を保持してきたい
if (p + 1 < N) {
if (A[p] + 1 == A[p + 1]) {
result += C[A[p] - 1];
}
}
}
Console.WriteLine(result);
}
}
}
// 文字列の入力
// string s = Console.ReadLine();
// 整数の入力
// long n = long.Parse(Console.ReadLine());
// 文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
// 整数配列の入力
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 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, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 206, 207, 0, 28, 0, 16, 31, 204, 205, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["-", 206, 207, 0, 28, 0, 16, 31, 16, 17, 33], ["-", 206, 207, 0, 28, 0, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 264
| 41
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder_solve {
class Program {
public const ulong mod = 1000000007;
static void Main(string[] args)
{
var n = Input();
var a = Input3();
var b = Input3();
var c = Input3();
var ans = b[a[0] - 1];
for (int i = 1; i < n; i++) {
ans += b[a[i] - 1];
if (a[i] == a[i - 1] + 1)
ans += c[a[i - 1] - 1];
Console.WriteLine(ans);
}
Console.WriteLine(ans);
}
static public long Input() { return long.Parse(Console.ReadLine()); }
static public string[] Input2() { return Console.ReadLine().Split(); }
static public long[] Input3() {
string[] data = Console.ReadLine().Split();
long[] res = new long[data.LongLength];
for (long i = 0; i < data.LongLength; i++) {
res[i] = long.Parse(data[i]);
}
return res;
}
public static long Choose(long n, long a) {
long x = 1;
long y = 1;
for (long i = 0; i < a; i++) {
x *= n - i;
y *= i + 1;
}
return x / y;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder_solve {
class Program {
public const ulong mod = 1000000007;
static void Main(string[] args)
{
var n = Input();
var a = Input3();
var b = Input3();
var c = Input3();
var ans = b[a[0] - 1];
for (int i = 1; i < n; i++) {
ans += b[a[i] - 1];
if (a[i] == a[i - 1] + 1)
ans += c[a[i - 1] - 1];
// Console.WriteLine(ans);
}
Console.WriteLine(ans);
}
static public long Input() { return long.Parse(Console.ReadLine()); }
static public string[] Input2() { return Console.ReadLine().Split(); }
static public long[] Input3() {
string[] data = Console.ReadLine().Split();
long[] res = new long[data.LongLength];
for (long i = 0; i < data.LongLength; i++) {
res[i] = long.Parse(data[i]);
}
return res;
}
public static long Choose(long n, long a) {
long x = 1;
long y = 1;
for (long i = 0; i < a; i++) {
x *= n - i;
y *= i + 1;
}
return x / y;
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 337
| 7
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.