buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Collections.Generic;
using System.Linq;
class PaizaSample {
static void Main() {
string[] abc = Console.ReadLine().Split(' ');
int a = int.Parse(abc[0]);
int b = int.Parse(abc[1]);
int c = int.Parse(abc[2]);
bool flag = true;
int sum = 0;
while (true) {
if (flag) { //??????????????¨???
if (sum % 60 <= c && sum % 60 + a >= c) {
sum = sum - sum % 60 + c;
break;
} else {
sum += a;
}
flag = false;
} else { //???????????¨???
sum += b;
flag = true;
}
// Console.WriteLine(sum);
if (60 % a == 0 && sum == 60) //?????°????????¨???
{
sum = -1;
break;
}
}
Console.WriteLine(sum);
// Console.ReadKey();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class PaizaSample {
static void Main() {
string[] abc = Console.ReadLine().Split(' ');
int a = int.Parse(abc[0]);
int b = int.Parse(abc[1]);
int c = int.Parse(abc[2]);
bool flag = true;
int sum = 0;
while (true) {
if (flag) { //??????????????¨???
if (sum % 60 <= c && sum % 60 + a >= c) {
sum = sum - sum % 60 + c;
break;
} else {
sum += a;
}
flag = false;
} else { //???????????¨???
sum += b;
flag = true;
}
// Console.WriteLine(sum);
if (sum % 60 == 0 && sum > 0 && flag) //?????°????????¨???
{
sum = -1;
break;
}
}
Console.WriteLine(sum);
// Console.ReadKey();
}
}
|
[["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 203], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22]]
| 8
| 190
| 10
|
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
// using System.Numerics;
using Enu = System.Linq.Enumerable;
public class Program {
public void Solve() {
int N = Reader.Int(), Q = Reader.Int();
var HL = new HLDecomposition(N);
foreach (var e in Reader.IntTable(N - 1))
HL.AddEdge(e[0], e[1]);
HL.Build();
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
foreach (var q in Reader.IntTable(Q))
if (q[0] == 0)
Console.WriteLine(HL.Sum(q[1], q[2]));
else
HL.Add(q[1], q[2]);
Console.Out.Flush();
Console.ReadLine();
}
class HLDecomposition {
public readonly int N;
List<int>[] E;
int[] Y, X, Size, Parent, Up, UnderL, UnderR;
List<List<int>> Path = new List<List<int>>();
List<int> PathDepth = new List<int>();
RangeAddSum[] seg;
RangeAddSum segSub;
void Init() {
segSub = new RangeAddSum(Path.Count);
seg = new RangeAddSum[Path.Count];
for (int i = 0; i < seg.Length; i++)
seg[i] = new RangeAddSum(Path[i].Count);
}
public void Add(int a, long val) {
seg[Y[a]].Add(X[a], Path.Count - 1, val);
segSub.Add(UnderL[a], UnderR[a], val);
}
public long Sum(int a, int b) {
long res = 0;
for (int at = Y[a], L = 0, R, na = a, nb = b; a != -1; a = na, b = nb) {
if (Y[a] == Y[b]) {
at = Y[a];
L = Math.Min(X[a], X[b]);
R = Math.Max(X[a], X[b]);
na = -1;
} else if (PathDepth[Y[a]] >= PathDepth[Y[b]]) {
at = Y[a];
L = 0;
R = X[a];
na = Up[a];
} else {
at = Y[b];
L = 0;
R = X[b];
nb = Up[b];
}
res += seg[at].Sum(L, R);
long sub = segSub.Sum(at, at + 1);
res += sub * (R - L);
if (Y[a] != Y[b])
res += sub;
}
return res;
}
public HLDecomposition(int n) {
N = n;
Y = new int[N];
X = new int[N];
Size = new int[N];
Parent = new int[N];
Up = new int[N];
UnderL = new int[N];
UnderR = new int[N];
E = new List<int>[N];
for (int i = 0; i < N; i++)
E[i] = new List<int>();
}
public void AddEdge(int a, int b) {
E[a].Add(b);
E[b].Add(a);
}
public void Build(int root = 0) {
CountNodes();
CompressPath();
Init();
}
void CountNodes() {
var stack = new Stack<int>();
var nodes = new int[N];
int ni = N - 1;
stack.Push(0);
while (stack.Count > 0) {
int a = stack.Pop();
for (int ei = 0; ei < E[a].Count; ei++) {
int b = E[a][ei];
if (b == Parent[a]) {
E[a].RemoveAt(ei);
ei--;
} else {
Parent[b] = a;
stack.Push(b);
}
}
nodes[ni--] = a;
}
foreach (int a in nodes) {
Size[a] = 1;
var e = E[a];
for (int i = 0; i < e.Count; i++) {
int b = e[i];
Size[a] += Size[b];
if (Size[b] > Size[e[0]]) {
int t = e[0];
e[0] = b;
e[i] = t;
}
}
}
}
void CompressPath() {
var stack = new Stack<int>();
stack.Push(0);
while (stack.Count > 0) {
int a = stack.Pop();
if (a < 0) {
UnderR[~a] = Path.Count;
continue;
}
if (X[a] == 0) {
Path.Add(new List<int>());
PathDepth.Add(a == 0 ? 0 : PathDepth[Y[Parent[a]]] + 1);
}
int pathId = Y[a] = Path.Count - 1;
Path[pathId].Add(a);
Up[a] = Parent[Path[pathId][0]];
UnderL[a] = Path.Count;
stack.Push(~a);
if (E[a].Count == 0)
continue;
for (int i = E[a].Count - 1; i > 0; i--)
stack.Push(E[a][i]);
X[E[a][0]] = X[a] + 1;
stack.Push(E[a][0]);
}
}
public int LCA(int a, int b) {
int pa = Y[a], pb = Y[b];
if (pa == pb)
return (X[a] < X[b]) ? a : b;
if (PathDepth[pa] >= PathDepth[pb])
return LCA(Parent[Path[pa][0]], b);
return LCA(a, Parent[Path[pb][0]]);
}
}
class RangeAddSum {
readonly BinaryIndexedTree A, B;
public RangeAddSum(int n) {
A = new BinaryIndexedTree(n);
B = new BinaryIndexedTree(n);
}
public void Add(int L, int R, long val) {
A.Add(L, -val * (L - 1));
B.Add(L, val);
A.Add(R, val * (R - 1));
B.Add(R, -val);
}
public long Sum(int L, int R) { return Sum(R) - Sum(L); }
public long Sum(int R) { return A.Sum(R) + B.Sum(R) * (R - 1); }
}
class BinaryIndexedTree {
private readonly int N;
private readonly long[] A;
public BinaryIndexedTree(int N) {
this.N = N + 1;
A = new long[N + 2];
}
public void Add(int i, long val) {
for (++i; i <= N; i += i & -i)
A[i] += val;
}
public void Update(int i, long val) { Add(i, val - (Sum(i) - Sum(i - 1))); }
public long Sum(int i) // [0, i]
{
long sum = 0;
for (++i; i > 0; i &= i - 1)
sum += A[i];
return sum;
}
public long Sum(int L, int R) // [L, R)
{
return Sum(R - 1) - Sum(L - 1);
}
}
}
class Entry {
static void Main() { new Program().Solve(); }
}
class Reader {
static TextReader reader = Console.In;
static readonly char[] separator = { ' ' };
static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
static string[] A = new string[0];
static int i;
static void Init() { A = new string[0]; }
public static void Set(TextReader r) {
reader = r;
Init();
}
public static void Set(string file) {
reader = new StreamReader(file);
Init();
}
public static bool HasNext() { return CheckNext(); }
public static string String() { return Next(); }
public static int Int() { return int.Parse(Next()); }
public static long Long() { return long.Parse(Next()); }
public static double Double() { return double.Parse(Next()); }
public static int[] IntLine() {
return Array.ConvertAll(Split(Line()), int.Parse);
}
public static int[] IntArray(int N) { return Range(N, Int); }
public static int[][] IntTable(int H) { return Range(H, IntLine); }
public static string[] StringArray(int N) { return Range(N, Next); }
public static string[][] StringTable(int N) {
return Range(N, () => Split(Line()));
}
public static string Line() { return reader.ReadLine().Trim(); }
static string[] Split(string s) { return s.Split(separator, op); }
static T[] Range<T>(int N, Func<T> f) {
var r = new T[N];
for (int i = 0; i < N; r[i++] = f())
;
return r;
}
static string Next() {
CheckNext();
return A[i++];
}
static bool CheckNext() {
if (i < A.Length)
return true;
string line = reader.ReadLine();
if (line == null)
return false;
if (line == "")
return CheckNext();
A = Split(line);
i = 0;
return true;
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
// using System.Numerics;
using Enu = System.Linq.Enumerable;
public class Program {
public void Solve() {
int N = Reader.Int(), Q = Reader.Int();
var HL = new HLDecomposition(N);
foreach (var e in Reader.IntTable(N - 1))
HL.AddEdge(e[0], e[1]);
HL.Build();
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
foreach (var q in Reader.IntTable(Q))
if (q[0] == 0)
Console.WriteLine(HL.Sum(q[1], q[2]));
else
HL.Add(q[1], q[2]);
Console.Out.Flush();
Console.ReadLine();
}
class HLDecomposition {
public readonly int N;
List<int>[] E;
int[] Y, X, Size, Parent, Up, UnderL, UnderR;
List<List<int>> Path = new List<List<int>>();
List<int> PathDepth = new List<int>();
RangeAddSum[] seg;
RangeAddSum segSub;
void Init() {
segSub = new RangeAddSum(Path.Count);
seg = new RangeAddSum[Path.Count];
for (int i = 0; i < seg.Length; i++)
seg[i] = new RangeAddSum(Path[i].Count);
}
public void Add(int a, long val) {
seg[Y[a]].Add(X[a], Path[Y[a]].Count - 1, val);
segSub.Add(UnderL[a], UnderR[a], val);
}
public long Sum(int a, int b) {
long res = 0;
for (int at = Y[a], L = 0, R, na = a, nb = b; a != -1; a = na, b = nb) {
if (Y[a] == Y[b]) {
at = Y[a];
L = Math.Min(X[a], X[b]);
R = Math.Max(X[a], X[b]);
na = -1;
} else if (PathDepth[Y[a]] >= PathDepth[Y[b]]) {
at = Y[a];
L = 0;
R = X[a];
na = Up[a];
} else {
at = Y[b];
L = 0;
R = X[b];
nb = Up[b];
}
res += seg[at].Sum(L, R);
long sub = segSub.Sum(at, at + 1);
res += sub * (R - L);
if (Y[a] != Y[b])
res += sub;
}
return res;
}
public HLDecomposition(int n) {
N = n;
Y = new int[N];
X = new int[N];
Size = new int[N];
Parent = new int[N];
Up = new int[N];
UnderL = new int[N];
UnderR = new int[N];
E = new List<int>[N];
for (int i = 0; i < N; i++)
E[i] = new List<int>();
}
public void AddEdge(int a, int b) {
E[a].Add(b);
E[b].Add(a);
}
public void Build(int root = 0) {
CountNodes();
CompressPath();
Init();
}
void CountNodes() {
var stack = new Stack<int>();
var nodes = new int[N];
int ni = N - 1;
stack.Push(0);
while (stack.Count > 0) {
int a = stack.Pop();
for (int ei = 0; ei < E[a].Count; ei++) {
int b = E[a][ei];
if (b == Parent[a]) {
E[a].RemoveAt(ei);
ei--;
} else {
Parent[b] = a;
stack.Push(b);
}
}
nodes[ni--] = a;
}
foreach (int a in nodes) {
Size[a] = 1;
var e = E[a];
for (int i = 0; i < e.Count; i++) {
int b = e[i];
Size[a] += Size[b];
if (Size[b] > Size[e[0]]) {
int t = e[0];
e[0] = b;
e[i] = t;
}
}
}
}
void CompressPath() {
var stack = new Stack<int>();
stack.Push(0);
while (stack.Count > 0) {
int a = stack.Pop();
if (a < 0) {
UnderR[~a] = Path.Count;
continue;
}
if (X[a] == 0) {
Path.Add(new List<int>());
PathDepth.Add(a == 0 ? 0 : PathDepth[Y[Parent[a]]] + 1);
}
int pathId = Y[a] = Path.Count - 1;
Path[pathId].Add(a);
Up[a] = Parent[Path[pathId][0]];
UnderL[a] = Path.Count;
stack.Push(~a);
if (E[a].Count == 0)
continue;
for (int i = E[a].Count - 1; i > 0; i--)
stack.Push(E[a][i]);
X[E[a][0]] = X[a] + 1;
stack.Push(E[a][0]);
}
}
public int LCA(int a, int b) {
int pa = Y[a], pb = Y[b];
if (pa == pb)
return (X[a] < X[b]) ? a : b;
if (PathDepth[pa] >= PathDepth[pb])
return LCA(Parent[Path[pa][0]], b);
return LCA(a, Parent[Path[pb][0]]);
}
}
class RangeAddSum {
readonly BinaryIndexedTree A, B;
public RangeAddSum(int n) {
A = new BinaryIndexedTree(n);
B = new BinaryIndexedTree(n);
}
public void Add(int L, int R, long val) {
A.Add(L, -val * (L - 1));
B.Add(L, val);
A.Add(R, val * (R - 1));
B.Add(R, -val);
}
public long Sum(int L, int R) { return Sum(R) - Sum(L); }
public long Sum(int R) { return A.Sum(R) + B.Sum(R) * (R - 1); }
}
class BinaryIndexedTree {
private readonly int N;
private readonly long[] A;
public BinaryIndexedTree(int N) {
this.N = N + 1;
A = new long[N + 2];
}
public void Add(int i, long val) {
for (++i; i <= N; i += i & -i)
A[i] += val;
}
public void Update(int i, long val) { Add(i, val - (Sum(i) - Sum(i - 1))); }
public long Sum(int i) // [0, i]
{
long sum = 0;
for (++i; i > 0; i &= i - 1)
sum += A[i];
return sum;
}
public long Sum(int L, int R) // [L, R)
{
return Sum(R - 1) - Sum(L - 1);
}
}
}
class Entry {
static void Main() { new Program().Solve(); }
}
class Reader {
static TextReader reader = Console.In;
static readonly char[] separator = { ' ' };
static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
static string[] A = new string[0];
static int i;
static void Init() { A = new string[0]; }
public static void Set(TextReader r) {
reader = r;
Init();
}
public static void Set(string file) {
reader = new StreamReader(file);
Init();
}
public static bool HasNext() { return CheckNext(); }
public static string String() { return Next(); }
public static int Int() { return int.Parse(Next()); }
public static long Long() { return long.Parse(Next()); }
public static double Double() { return double.Parse(Next()); }
public static int[] IntLine() {
return Array.ConvertAll(Split(Line()), int.Parse);
}
public static int[] IntArray(int N) { return Range(N, Int); }
public static int[][] IntTable(int H) { return Range(H, IntLine); }
public static string[] StringArray(int N) { return Range(N, Next); }
public static string[][] StringTable(int N) {
return Range(N, () => Split(Line()));
}
public static string Line() { return reader.ReadLine().Trim(); }
static string[] Split(string s) { return s.Split(separator, op); }
static T[] Range<T>(int N, Func<T> f) {
var r = new T[N];
for (int i = 0; i < N; r[i++] = f())
;
return r;
}
static string Next() {
CheckNext();
return A[i++];
}
static bool CheckNext() {
if (i < A.Length)
return true;
string line = reader.ReadLine();
if (line == null)
return false;
if (line == "")
return CheckNext();
A = Split(line);
i = 0;
return true;
}
}
|
[["+", 0, 16, 31, 214, 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, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 16, 31, 214, 205, 204, 206, 207, 0, 73]]
| 8
| 2,215
| 6
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
long sum = 0;
for (int i = 0; i < N; i++) {
var d = rla();
sum += d[0] * d[1];
}
if (sum == 0) {
Console.WriteLine(0);
} else {
Console.WriteLine(1);
Console.WriteLine("{1} {0}", sum > 0 ? -1 : 1, sum > 0 ? sum : -sum);
}
}
int N;
public Sol() {
// L=ri();
rs();
N = ri();
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
long sum = 0;
for (int i = 0; i < N; i++) {
var d = rla();
sum += d[0] * d[1];
}
if (sum == 0) {
Console.WriteLine(0);
} else {
Console.WriteLine(1);
Console.WriteLine("{0} {1}", sum > 0 ? -1 : 1, sum > 0 ? sum : -sum);
}
}
int N;
public Sol() {
// L=ri();
rs();
N = ri();
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 394
| 2
|
#pragma warning disable
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
// using Pair = System.Collections.Generic.KeyValuePair<int, int>;
class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Program().Solve();
Console.Out.Flush();
}
Scanner cin = new Scanner();
int mod = 1000000007;
void Solve() {
int N = cin.Nextint;
var Q = cin.Scanint;
eratos(Q.Max());
if (!is_prime[Q[0]]) {
Console.WriteLine(0);
return;
}
var dp = new long[N, 2];
dp[0, 1] = 1;
for (int i = 1; i < N; i++) {
dp[i, 0] = dp[i - 1, 1];
if (is_prime[Q[i]] && Q[i - 1] < Q[i])
dp[i, 1] += dp[i - 1, 1];
if (is_prime[Q[i]] && i - 2 >= 0 && Q[i - 2] < Q[i])
dp[i, 1] += dp[i - 1, 0];
dp[i, 1] %= mod;
}
Console.WriteLine((dp[N, 0] + dp[N, 1]) % mod);
// long zero = 1; int zero_prime = 0;
// long one = 0; int one_prime = 0;
// for (int i = 1; i < N; i++)
//{
// long tmp = one;
// if (is_prime[Q[i]])
// {
// if (Q[i - 1] < Q[i] && Q[i - 2] < Q[i])
// {
// long tmp = one;
// one = (zero + one) % mod;
// zero = tmp;
// zero_prime = one_prime;
// one_prime = Q[i];
// }
// else if (zero_prime < Q[i])
// {
// long tmp = one;
// one = zero;
// zero = tmp;
// zero_prime = one_prime;
// one_prime = Q[i];
// }
// else if (one_prime < Q[i])
// {
// zero = one;
// one_prime = Q[i];
// }
// else
// {
// zero = one;
// one = 0;
// one_prime = 0;
// }
// }
// //Console.WriteLine(one + " " + zero);
//}
// Console.WriteLine((one + zero) % mod);
}
List<int> prime;
bool[] is_prime;
void eratos(int n) {
prime = new List<int>();
is_prime = new bool[n + 1];
for (int i = 0; i <= n; i++)
is_prime[i] = true;
is_prime[0] = is_prime[1] = false;
for (int i = 0; i <= n; i++) {
if (is_prime[i]) {
prime.Add(i);
for (int j = 2 * i; j <= n; j += i)
is_prime[j] = false;
}
}
}
// int[] P;
// void phi(int n)
//{
// P = new int[n + 1];
// for (int i = 0; i <= n; i++) P[i] = i;
// for (int i = 2; i <= n; i++)
// {
// if (is_prime[i])
// {
// P[i] -= P[i] / i;
// for (int j = 2 * i; j <= n; j += i) P[j] -= P[j] / i;
// }
// }
//}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] Scan {
get { return Console.ReadLine().Split(); }
}
public int[] Scanint {
get { return Array.ConvertAll(Scan, int.Parse); }
}
public long[] Scanlong {
get { return Array.ConvertAll(Scan, long.Parse); }
}
public double[] Scandouble {
get { return Array.ConvertAll(Scan, double.Parse); }
}
public string Next {
get {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return Next;
}
}
public int Nextint {
get { return int.Parse(Next); }
}
public long Nextlong {
get { return long.Parse(Next); }
}
public double Nextdouble {
get { return double.Parse(Next); }
}
}
|
#pragma warning disable
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
// using Pair = System.Collections.Generic.KeyValuePair<int, int>;
class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Program().Solve();
Console.Out.Flush();
}
Scanner cin = new Scanner();
int mod = 1000000007;
void Solve() {
int N = cin.Nextint;
var Q = cin.Scanint;
eratos(Q.Max());
if (!is_prime[Q[0]]) {
Console.WriteLine(0);
return;
}
var dp = new long[N, 2];
dp[0, 1] = 1;
for (int i = 1; i < N; i++) {
dp[i, 0] = dp[i - 1, 1];
if (is_prime[Q[i]] && Q[i - 1] < Q[i])
dp[i, 1] += dp[i - 1, 1];
if (is_prime[Q[i]] && i - 2 >= 0 && Q[i - 2] < Q[i])
dp[i, 1] += dp[i - 1, 0];
dp[i, 1] %= mod;
}
Console.WriteLine((dp[N - 1, 0] + dp[N - 1, 1]) % mod);
// long zero = 1; int zero_prime = 0;
// long one = 0; int one_prime = 0;
// for (int i = 1; i < N; i++)
//{
// long tmp = one;
// if (is_prime[Q[i]])
// {
// if (Q[i - 1] < Q[i] && Q[i - 2] < Q[i])
// {
// long tmp = one;
// one = (zero + one) % mod;
// zero = tmp;
// zero_prime = one_prime;
// one_prime = Q[i];
// }
// else if (zero_prime < Q[i])
// {
// long tmp = one;
// one = zero;
// zero = tmp;
// zero_prime = one_prime;
// one_prime = Q[i];
// }
// else if (one_prime < Q[i])
// {
// zero = one;
// one_prime = Q[i];
// }
// else
// {
// zero = one;
// one = 0;
// one_prime = 0;
// }
// }
// //Console.WriteLine(one + " " + zero);
//}
// Console.WriteLine((one + zero) % mod);
}
List<int> prime;
bool[] is_prime;
void eratos(int n) {
prime = new List<int>();
is_prime = new bool[n + 1];
for (int i = 0; i <= n; i++)
is_prime[i] = true;
is_prime[0] = is_prime[1] = false;
for (int i = 0; i <= n; i++) {
if (is_prime[i]) {
prime.Add(i);
for (int j = 2 * i; j <= n; j += i)
is_prime[j] = false;
}
}
}
// int[] P;
// void phi(int n)
//{
// P = new int[n + 1];
// for (int i = 0; i <= n; i++) P[i] = i;
// for (int i = 2; i <= n; i++)
// {
// if (is_prime[i])
// {
// P[i] -= P[i] / i;
// for (int j = 2 * i; j <= n; j += i) P[j] -= P[j] / i;
// }
// }
//}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] Scan {
get { return Console.ReadLine().Split(); }
}
public int[] Scanint {
get { return Array.ConvertAll(Scan, int.Parse); }
}
public long[] Scanlong {
get { return Array.ConvertAll(Scan, long.Parse); }
}
public double[] Scandouble {
get { return Array.ConvertAll(Scan, double.Parse); }
}
public string Next {
get {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return Next;
}
}
public int Nextint {
get { return int.Parse(Next); }
}
public long Nextlong {
get { return long.Parse(Next); }
}
public double Nextdouble {
get { return double.Parse(Next); }
}
}
|
[["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 730
| 4
|
using System.Collections.Generic;
using System.Linq;
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var n = int.Parse(line[0]);
var L = int.Parse(line[1]);
var a = new string[n];
for (int i = 0; i < n; i++)
a[i] = Console.ReadLine().Trim();
var used = new bool[n];
var ans1 = getAns1(a, n, used);
var ans = getAns2(a, used, ans1, n);
Console.WriteLine(ans);
}
static bool check(string s) {
var imax = s.Length / 2;
for (int i = 0; i < imax; i++)
if (s[i] != s[s.Length - 1 - i])
return false;
return true;
}
static string getAns2(string[] a, bool[] used, List<string> ans1, int n) {
var ans2 = new List<string>();
for (int i = 0; i < n; i++)
if (!used[i] && check(a[i]))
ans2.Add(a[i]);
ans2.Sort();
var ans3 = "";
for (int i = 0; i < ans1.Count(); i++)
ans3 += ans1[i];
var ans4 = getRev(ans3);
if (ans2.Count() > 0)
return ans3 + ans2[0] + ans4;
else
return ans3 + ans4;
}
static string getRev(string s) {
var a = s.ToCharArray();
Array.Reverse(a);
return new string(a);
}
static List<string> getAns1(string[] a, int n, bool[] used) {
var ans1 = new List<string>();
for (int i = 0; i < n; i++)
if (!used[i]) {
var w = getRev(a[i]);
for (int j = i + 1; j < n; j++)
if (!used[j] && w == a[j]) {
var t = a[i].CompareTo(w);
if (t <= 0)
ans1.Add(a[i]);
else
ans1.Add(w);
used[i] = true;
used[j] = true;
}
}
ans1.Sort();
return ans1;
}
}
|
using System.Collections.Generic;
using System.Linq;
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var n = int.Parse(line[0]);
var L = int.Parse(line[1]);
var a = new string[n];
for (int i = 0; i < n; i++)
a[i] = Console.ReadLine().Trim();
var used = new bool[n];
var ans1 = getAns1(a, n, used);
var ans = getAns2(a, used, ans1, n);
Console.WriteLine(ans);
}
static bool check(string s) {
var imax = s.Length / 2;
for (int i = 0; i < imax; i++)
if (s[i] != s[s.Length - 1 - i])
return false;
return true;
}
static string getAns2(string[] a, bool[] used, List<string> ans1, int n) {
var ans2 = new List<string>();
for (int i = 0; i < n; i++)
if (!used[i] && check(a[i]))
ans2.Add(a[i]);
ans2.Sort();
var ans3 = "";
for (int i = 0; i < ans1.Count(); i++)
ans3 += ans1[i];
var ans4 = getRev(ans3);
if (ans2.Count() > 0)
return ans3 + ans2[0] + ans4;
else
return ans3 + ans4;
}
static string getRev(string s) {
var a = s.ToCharArray();
Array.Reverse(a);
return new string(a);
}
static List<string> getAns1(string[] a, int n, bool[] used) {
var ans1 = new List<string>();
for (int i = 0; i < n; i++)
if (!used[i]) {
var w = getRev(a[i]);
for (int j = i + 1; j < n; j++)
if (!used[j] && w == a[j]) {
var t = a[i].CompareTo(w);
if (t <= 0)
ans1.Add(a[i]);
else
ans1.Add(w);
used[i] = true;
used[j] = true;
break;
}
}
ans1.Sort();
return ans1;
}
}
|
[["+", 0, 7, 8, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 7, 8, 57, 64, 196, 0, 93, 0, 35]]
| 8
| 552
| 2
|
using System;
class Example {
static void Main() {
int n = int.Parse(Console.ReadLine());
int a = 1, b = 1;
int t;
for (int i = 0; i < n - 1; i++) {
t = b;
a = a + b;
b = t;
}
Console.WriteLine(a);
}
}
|
using System;
class Example {
static void Main() {
int n = int.Parse(Console.ReadLine());
int a = 1, b = 1;
int t;
for (int i = 0; i < n - 1; i++) {
t = a;
a = a + b;
b = t;
}
Console.WriteLine(a);
}
}
|
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22]]
| 8
| 79
| 2
|
using System;
namespace _10_A {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
if (n < 2) {
Console.WriteLine(0);
} else {
int[] x = new int[n + 1];
x[0] = 1;
x[1] = 1;
for (int i = 2; i <= n; i++) {
x[i] = x[i - 1] + x[i - 2];
}
Console.WriteLine(x[n]);
}
}
}
}
|
using System;
namespace _10_A {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
if (n < 2) {
Console.WriteLine(1);
} else {
int[] x = new int[n + 1];
x[0] = 1;
x[1] = 1;
for (int i = 2; i <= n; i++) {
x[i] = x[i - 1] + x[i - 2];
}
Console.WriteLine(x[n]);
}
}
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 126
| 2
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static Dictionary<int, int> dp =
new Dictionary<int, int>() { { 1, 1 }, { 1, 1 } };
static void Main(string[] args) {
string[] inputs = Console.ReadLine().Split();
System.Console.WriteLine(Fib(int.Parse(inputs[0])));
}
static int Fib(int i) {
return dp.ContainsKey(i) ? dp[i] : dp[i] = Fib(i - 1) + Fib(i - 2);
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static Dictionary<int, int> dp =
new Dictionary<int, int>() { { 0, 1 }, { 1, 1 } };
static void Main(string[] args) {
string[] inputs = Console.ReadLine().Split();
System.Console.WriteLine(Fib(int.Parse(inputs[0])));
}
static int Fib(int i) {
return dp.ContainsKey(i) ? dp[i] : dp[i] = Fib(i - 1) + Fib(i - 2);
}
}
|
[["-", 0, 212, 0, 230, 10, 229, 0, 229, 0, 203], ["+", 0, 212, 0, 230, 10, 229, 0, 229, 0, 203]]
| 8
| 138
| 2
|
using System;
class AOJ {
public static void Main() {
var input = Console.ReadLine().Trim().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int large = Math.Max(a, b);
int small = Math.Min(a, b);
if (small == 0) {
Console.WriteLine(small);
return;
}
while (true) {
int mod = large % small;
if (mod == 0) {
Console.WriteLine(mod);
break;
}
large = small;
small = mod;
}
}
}
|
using System;
class AOJ {
public static void Main() {
var input = Console.ReadLine().Trim().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int large = Math.Max(a, b);
int small = Math.Min(a, b);
if (small == 0) {
Console.WriteLine(small);
return;
}
while (true) {
int mod = large % small;
if (mod == 0) {
Console.WriteLine(small);
break;
}
large = small;
small = mod;
}
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 140
| 2
|
using System;
class Gcd {
public static void Main(string[] args) {
string data = Console.ReadLine();
string[] xy = data.Split();
int x = int.Parse(xy[0]);
int y = int.Parse(xy[1]);
Console.WriteLine(gcd(x, y));
}
public static int gcd(int a, int b) {
if (a < b) {
int temp = a;
a = b;
b = temp;
}
int c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return c;
}
}
|
using System;
class Gcd {
public static void Main(string[] args) {
string data = Console.ReadLine();
string[] xy = data.Split();
int x = int.Parse(xy[0]);
int y = int.Parse(xy[1]);
Console.WriteLine(gcd(x, y));
}
public static int gcd(int a, int b) {
if (a < b) {
int temp = a;
a = b;
b = temp;
}
int c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return b;
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 22]]
| 8
| 143
| 2
|
using System;
class Program {
static void Main() {
string[] s = Console.ReadLine().Split(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
int x = 0;
if (a < b) {
x = a;
a = b;
b = x;
}
while (b != 0) {
x = b;
b = a % x;
}
Console.WriteLine(x);
}
}
|
using System;
class Program {
static void Main() {
string[] s = Console.ReadLine().Split(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
int x = 0;
if (a < b) {
x = a;
a = b;
b = x;
}
while (b != 0) {
x = b;
b = a % x;
a = x;
}
Console.WriteLine(x);
}
}
|
[["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
| 8
| 108
| 4
|
using System;
namespace Test {
class MainClass {
public static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var nums = new int[N];
for (int i = 0; i < nums.Length; i++) {
nums[i] = int.Parse(Console.ReadLine());
}
var result = 0;
for (int i = 0; i < nums.Length; i++) {
if (IsPrimeNum(nums[i]))
result++;
}
Console.WriteLine(result);
}
private static bool IsPrimeNum(int p) {
if (p == 2)
return true;
if ((p < 2) || ((p & 0x01) == 0))
return false;
var num = Math.Sqrt(p);
var i = 3;
while (i <= num) {
if ((num % i) == 0)
return false;
i = i + 2;
}
return true;
}
}
}
|
using System;
namespace Test {
class MainClass {
public static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var nums = new int[N];
for (int i = 0; i < nums.Length; i++) {
nums[i] = int.Parse(Console.ReadLine());
}
var result = 0;
for (int i = 0; i < nums.Length; i++) {
if (IsPrimeNum(nums[i]))
result++;
}
Console.WriteLine(result);
}
private static bool IsPrimeNum(int p) {
if (p == 2)
return true;
if ((p < 2) || ((p & 0x01) == 0))
return false;
var num = Math.Sqrt(p);
var i = 3;
while (i <= num) {
if ((p % i) == 0)
return false;
i = i + 2;
}
return true;
}
}
}
|
[["-", 0, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 31, 22]]
| 8
| 208
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AizuOnLine_Lesson {
class Program {
static void Main(string[] args) {
List<int> data = Program.GetData();
int result = 0;
foreach (int num in data) {
double sqrtNum = Math.Sqrt((double)num);
bool flag = true;
for (int i = 2; i < sqrtNum; i++) {
if (num % i == 0) {
flag = false;
break;
}
}
result = flag ? 1 : 0;
}
Console.WriteLine(result);
}
private static List<int> GetData() {
List<int> data = new List<int>();
int count = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < count; i++) {
data.Add(Convert.ToInt32(Console.ReadLine()));
}
return data;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AizuOnLine_Lesson {
class Program {
static void Main(string[] args) {
List<int> data = Program.GetData();
int result = 0;
foreach (int num in data) {
double sqrtNum = Math.Sqrt((double)num);
bool flag = true;
for (int i = 2; i <= sqrtNum; i++) {
if (num % i == 0) {
flag = false;
break;
}
}
result += flag ? 1 : 0;
}
Console.WriteLine(result);
}
private static List<int> GetData() {
List<int> data = new List<int>();
int count = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < count; i++) {
data.Add(Convert.ToInt32(Console.ReadLine()));
}
return data;
}
}
}
|
[["-", 0, 210, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 210, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107]]
| 8
| 199
| 4
|
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
class Program {
public static IO IO = new IO();
static void Main(string[] args) {
int n = IO.INT();
int[] m = IO.INT(n);
int p = 0;
for (int i = 0; i < n; i++) {
if (m[i] == 2) {
p++;
} else if (m[i] > 2 && (m[i] % 2 != 0)) {
bool f = true;
int q = (int)Math.Sqrt(m[i]);
for (int j = 3; j < q; j += 2) {
if (m[i] % j == 0) {
f = false;
break;
}
}
if (f) {
p++;
}
}
}
IO.WRITE(p);
IO.FLUSH();
}
}
namespace LIB {
public class IO {
private const int WMAX = 1000;
private StringBuilder S = new StringBuilder();
private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
private T[] R<T>(Func<string, T> f, char c) {
return STRING().Split(c).Select(f).ToArray();
}
private T[] R<T>(Func<string, T> f, int l) {
T[] r = new T[l];
for (int i = 0; i < l; i++) {
r[i] = R(f);
}
return r;
}
private T[][] R<T>(Func<string, T> f, int l, char c) {
T[][] r = new T[l][];
for (int i = 0; i < l; i++) {
r[i] = R<T>(f, c);
}
return r;
}
private void W<T>(Func<T, string> f, T v, bool lf = true) {
S.Append(f(v));
if (lf == true) {
S.Append('\n');
}
if (S.Length >= WMAX) {
FLUSH();
}
}
public string STRING() { return R(s => s); }
public string[] STRING(char c) { return R(s => s, c); }
public string[] STRING(int l) { return R(s => s, l); }
public string[][] STRING(int l, char c) { return R(s => s, l, c); }
public int INT() { return R(int.Parse); }
public int[] INT(char c) { return R(int.Parse, c); }
public int[] INT(int l) { return R(int.Parse, l); }
public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
public long LONG() { return R(long.Parse); }
public long[] LONG(char c) { return R(long.Parse, c); }
public long[] LONG(int l) { return R(long.Parse, l); }
public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
public double DOUBLE() { return R(double.Parse); }
public double[] DOUBLE(char c) { return R(double.Parse, c); }
public double[] DOUBLE(int l) { return R(double.Parse, l); }
public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
public void WRITE(string s, bool lf = true) { W(v => v, s, lf); }
public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void FLUSH() {
Console.Write(S);
S.Length = 0;
}
}
}
|
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
class Program {
public static IO IO = new IO();
static void Main(string[] args) {
int n = IO.INT();
int[] m = IO.INT(n);
int p = 0;
for (int i = 0; i < n; i++) {
if (m[i] == 2) {
p++;
} else if (m[i] > 2 && (m[i] % 2 != 0)) {
bool f = true;
int q = (int)Math.Sqrt(m[i]);
for (int j = 3; j <= q; j += 2) {
if (m[i] % j == 0) {
f = false;
break;
}
}
if (f) {
p++;
}
}
}
IO.WRITE(p);
IO.FLUSH();
}
}
namespace LIB {
public class IO {
private const int WMAX = 1000;
private StringBuilder S = new StringBuilder();
private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
private T[] R<T>(Func<string, T> f, char c) {
return STRING().Split(c).Select(f).ToArray();
}
private T[] R<T>(Func<string, T> f, int l) {
T[] r = new T[l];
for (int i = 0; i < l; i++) {
r[i] = R(f);
}
return r;
}
private T[][] R<T>(Func<string, T> f, int l, char c) {
T[][] r = new T[l][];
for (int i = 0; i < l; i++) {
r[i] = R<T>(f, c);
}
return r;
}
private void W<T>(Func<T, string> f, T v, bool lf = true) {
S.Append(f(v));
if (lf == true) {
S.Append('\n');
}
if (S.Length >= WMAX) {
FLUSH();
}
}
public string STRING() { return R(s => s); }
public string[] STRING(char c) { return R(s => s, c); }
public string[] STRING(int l) { return R(s => s, l); }
public string[][] STRING(int l, char c) { return R(s => s, l, c); }
public int INT() { return R(int.Parse); }
public int[] INT(char c) { return R(int.Parse, c); }
public int[] INT(int l) { return R(int.Parse, l); }
public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
public long LONG() { return R(long.Parse); }
public long[] LONG(char c) { return R(long.Parse, c); }
public long[] LONG(int l) { return R(long.Parse, l); }
public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
public double DOUBLE() { return R(double.Parse); }
public double[] DOUBLE(char c) { return R(double.Parse, c); }
public double[] DOUBLE(int l) { return R(double.Parse, l); }
public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
public void WRITE(string s, bool lf = true) { W(v => v, s, lf); }
public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void FLUSH() {
Console.Write(S);
S.Length = 0;
}
}
}
|
[["-", 75, 57, 64, 196, 0, 7, 15, 16, 17, 18], ["+", 75, 57, 64, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 975
| 2
|
using System;
using System.Collections.Generic;
class Program {
static private List<int> PrimeList;
static private int Max() { return PrimeList[PrimeList.Count - 1]; }
static private bool Prime(int n) {
if (n == 1)
return false;
int SqrtN = (int)Math.Sqrt(n) + 1;
foreach (int p in PrimeList) {
if (p > SqrtN)
break;
if (n % p == 0)
return false;
}
bool a = true;
int max = Max();
if (max < SqrtN) {
for (int i = max + 2; i < SqrtN; i += 2) {
bool isprime = true;
foreach (int p in PrimeList) {
if (i % p == 0) {
isprime = false;
break;
}
}
if (isprime) {
PrimeList.Add(i);
if (n % i == 0) {
a = false;
break;
}
}
}
}
return a;
}
static void Main() {
PrimeList = new List<int>();
PrimeList.Add(2);
PrimeList.Add(3);
int num = int.Parse(Console.ReadLine());
int n = 0;
for (int i = 0; i < num; i++) {
if (Prime(int.Parse(Console.ReadLine())))
n++;
}
Console.WriteLine(n.ToString());
}
}
|
using System;
using System.Collections.Generic;
class Program {
static private List<int> PrimeList;
static private int Max() { return PrimeList[PrimeList.Count - 1]; }
static private bool Prime(int n) {
if (n == 1)
return false;
int SqrtN = (int)Math.Sqrt(n);
foreach (int p in PrimeList) {
if (p > SqrtN)
break;
if (n % p == 0)
return false;
}
bool a = true;
int max = Max();
if (max < SqrtN) {
for (int i = max + 2; i <= SqrtN; i += 2) {
bool isprime = true;
foreach (int p in PrimeList) {
if (i % p == 0) {
isprime = false;
break;
}
}
if (isprime) {
PrimeList.Add(i);
if (n % i == 0) {
a = false;
break;
}
}
}
}
return a;
}
static void Main() {
PrimeList = new List<int>();
PrimeList.Add(2);
PrimeList.Add(3);
int num = int.Parse(Console.ReadLine());
int n = 0;
for (int i = 0; i < num; i++) {
if (Prime(int.Parse(Console.ReadLine())))
n++;
}
Console.WriteLine(n.ToString());
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 299
| 4
|
using System;
namespace Sample {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int count = 0;
int p;
while (n-- > 0) {
p = int.Parse(Console.ReadLine());
if (p == 2) {
count++;
continue;
}
for (int i = 2; i * i <= p; i++) {
if (p % i == 0)
continue;
}
count++;
}
Console.WriteLine(count);
}
}
}
|
using System;
namespace Sample {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int count = 0;
int p;
LOOP:
while (n-- > 0) {
p = int.Parse(Console.ReadLine());
if (p == 2) {
count++;
continue;
}
for (int i = 2; i * i <= p; i++) {
if (p % i == 0)
goto LOOP;
}
count++;
}
Console.WriteLine(count);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 97, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 97, 0, 102], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 126, 0, 127], ["+", 0, 7, 8, 196, 0, 57, 64, 126, 0, 22]]
| 8
| 117
| 5
|
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
int cnt = 0;
for (int i = 0; i < n; i++) {
int num = int.Parse(Console.ReadLine());
if (IsPrime(num))
cnt++;
}
Console.WriteLine(cnt);
}
static bool IsPrime(int x) {
if (x == 2)
return true;
if (x % 2 == 0)
return false;
for (int i = 2; i <= Math.Sqrt(x); i += 2) {
if (x % i == 0)
return false;
}
return true;
}
}
|
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
int cnt = 0;
for (int i = 0; i < n; i++) {
int num = int.Parse(Console.ReadLine());
if (IsPrime(num))
cnt++;
}
Console.WriteLine(cnt);
}
static bool IsPrime(int x) {
if (x == 2)
return true;
if (x % 2 == 0)
return false;
for (int i = 3; i <= Math.Sqrt(x); i += 2) {
if (x % i == 0)
return false;
}
return true;
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 172
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace StartFinish {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int countNumber = 0;
int[] array = new int[n];
for (int i = 0; i < n; i++) {
array[i] = int.Parse(Console.ReadLine());
}
for (int i = 0; i < n; i++) {
if (DeterminePrime(array[i])) {
countNumber++;
}
}
Console.WriteLine(countNumber);
}
static bool DeterminePrime(int x) {
if (x == 2) {
return true;
}
if (x % 2 == 0) {
return false;
}
for (int i = 3; i < Math.Sqrt(x); i += 2) {
if (x % i == 0) {
return false;
}
}
return true;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace StartFinish {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int countNumber = 0;
int[] array = new int[n];
for (int i = 0; i < n; i++) {
array[i] = int.Parse(Console.ReadLine());
}
for (int i = 0; i < n; i++) {
if (DeterminePrime(array[i])) {
countNumber++;
}
}
Console.WriteLine(countNumber);
}
static bool DeterminePrime(int x) {
if (x == 2) {
return true;
}
if (x % 2 == 0) {
return false;
}
for (int i = 3; i <= Math.Sqrt(x); i += 2) {
if (x % i == 0) {
return false;
}
}
return true;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 215
| 2
|
using System;
namespace ALDS1_1_C_PrimeNumbers {
class Program {
static void Main(string[] args) {
int dataCount = int.Parse(Console.ReadLine());
int count = 0;
for (int lp = 0; lp < dataCount; lp++) {
int inputNum = int.Parse(Console.ReadLine());
if (IsPrimeNumber(inputNum))
count++;
}
Console.WriteLine(count);
}
static bool IsPrimeNumber(int num) {
if (num < 2)
return false;
if (num == 2)
return true;
if (num % 2 == 0)
return false;
int lp = 3;
double limit = Math.Sqrt(num);
while (lp < limit) {
if (num % lp == 0)
return false;
lp += 2;
}
return true;
}
}
}
|
using System;
namespace ALDS1_1_C_PrimeNumbers {
class Program {
static void Main(string[] args) {
int dataCount = int.Parse(Console.ReadLine());
int count = 0;
for (int lp = 0; lp < dataCount; lp++) {
int inputNum = int.Parse(Console.ReadLine());
if (IsPrimeNumber(inputNum))
count++;
}
Console.WriteLine(count);
}
static bool IsPrimeNumber(int num) {
if (num < 2)
return false;
if (num == 2)
return true;
if (num % 2 == 0)
return false;
int lp = 3;
double limit = Math.Sqrt(num);
while (lp <= limit) {
if (num % lp == 0)
return false;
lp += 2;
}
return true;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
| 8
| 167
| 2
|
using System;
// using System.Collections.Generic;
// using System.Collections;
// using System.Linq;
namespace solution {
class Class1 {
static void Main() {
int n = int.Parse(Console.ReadLine());
int count = 0;
for (int i = 0; i < n; i++) {
int x = int.Parse(Console.ReadLine());
if (PrimeCheck(x) == true)
count++;
}
Console.WriteLine(count);
}
static bool PrimeCheck(int x) {
if (x == 2)
return true;
if (x % 2 == 0)
return false;
for (int i = 3; i < Math.Sqrt(x); i += 2) {
if (x % i == 0)
return false;
}
return true;
}
}
}
|
using System;
// using System.Collections.Generic;
// using System.Collections;
// using System.Linq;
namespace solution {
class Class1 {
static void Main() {
int n = int.Parse(Console.ReadLine());
int count = 0;
for (int i = 0; i < n; i++) {
int x = int.Parse(Console.ReadLine());
if (PrimeCheck(x) == true)
count++;
}
Console.WriteLine(count);
}
static bool PrimeCheck(int x) {
if (x == 2)
return true;
if (x % 2 == 0)
return false;
for (int i = 3; i <= Math.Sqrt(x); i += 2) {
if (x % i == 0)
return false;
}
return true;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 154
| 2
|
using System;
class Maximum_Profit {
public static void Main() {
int n;
n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(Console.ReadLine());
}
int max = a[1] - a[0];
int min = a[0];
for (int i = 1; i < n - 1; i++) {
max = Math.Max(max, a[i] - min);
min = Math.Min(min, a[i]);
}
Console.WriteLine(max);
}
}
|
using System;
class Maximum_Profit {
public static void Main() {
int n;
n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(Console.ReadLine());
}
int max = a[1] - a[0];
int min = a[0];
for (int i = 1; i <= n - 1; i++) {
max = Math.Max(max, a[i] - min);
min = Math.Min(min, a[i]);
}
Console.WriteLine(max);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 150
| 2
|
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using System.Text;
namespace AOJ {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
var dic = new Dictionary<int, int>();
for (int i = 0; i < n; ++i) {
dic.Add(i, int.Parse(Console.ReadLine()));
}
int maxProf = dic[1] - dic[0];
int min = dic[0];
for (int i = 0; i < n - 1; ++i) {
min = min < dic[i] ? min : dic[i];
maxProf = maxProf > dic[i] - min ? maxProf : dic[i] - min;
}
Console.WriteLine(maxProf);
}
}
}
|
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using System.Text;
namespace AOJ {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
var dic = new Dictionary<int, int>();
for (int i = 0; i < n; ++i) {
dic.Add(i, int.Parse(Console.ReadLine()));
}
int maxProf = dic[1] - dic[0];
int min = dic[0];
for (int i = 0; i < n - 1; ++i) {
min = min < dic[i] ? min : dic[i];
maxProf = maxProf > dic[i + 1] - min ? maxProf : dic[i + 1] - min;
}
Console.WriteLine(maxProf);
}
}
}
|
[["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 187
| 4
|
using System;
class AOJ {
static void Main() {
int R, n;
int min_R = (int)2e5, ans = (int)1e9;
n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++) {
R = int.Parse(Console.ReadLine());
if (i == 0)
min_R = R;
else {
ans = Math.Max(ans, R - min_R);
min_R = Math.Min(min_R, R);
}
}
Console.WriteLine(ans);
}
}
|
using System;
class AOJ {
static void Main() {
int R, n;
int min_R = (int)2e5, ans = (int)-1e9;
n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++) {
R = int.Parse(Console.ReadLine());
if (i == 0)
min_R = R;
else {
ans = Math.Max(ans, R - min_R);
min_R = Math.Min(min_R, R);
}
}
Console.WriteLine(ans);
}
}
|
[["+", 0, 200, 0, 212, 0, 74, 51, 241, 0, 33]]
| 8
| 120
| 1
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _20170409_AOJ {
class ALDS1_1D {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int min;
int maxD = -1;
min = int.Parse(Console.ReadLine());
for (int i = 1; i < n; i++) {
int t = int.Parse(Console.ReadLine());
maxD = Math.Max(maxD, t - min);
min = Math.Min(min, t);
}
Console.WriteLine(maxD);
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _20170409_AOJ {
class ALDS1_1D {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int min;
int maxD = int.MinValue;
min = int.Parse(Console.ReadLine());
for (int i = 1; i < n; i++) {
int t = int.Parse(Console.ReadLine());
maxD = Math.Max(maxD, t - min);
min = Math.Min(min, t);
}
Console.WriteLine(maxD);
Console.ReadLine();
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22]]
| 8
| 142
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Practice {
class Program {
static void Main(string[] args) {
SolveA(args);
// SolveB(args);
// SolveC(args);
// SolveD(args);
}
static void SolveA(string[] args) {
string sz = (Console.ReadLine());
int n = int.Parse(sz);
int[] r = new int[n];
for (int i = 0; i < n; ++i) {
r[i] = int.Parse(Console.ReadLine());
}
long minv = r[0];
long maxv = long.MinValue;
for (int i = 1; i < n - 1; ++i) {
maxv = Math.Max(maxv, r[i] - minv);
minv = Math.Min(minv, r[i]);
}
Console.WriteLine(maxv);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Practice {
class Program {
static void Main(string[] args) {
SolveA(args);
// SolveB(args);
// SolveC(args);
// SolveD(args);
}
static void SolveA(string[] args) {
string sz = (Console.ReadLine());
int n = int.Parse(sz);
int[] r = new int[n];
for (int i = 0; i < n; ++i) {
r[i] = int.Parse(Console.ReadLine());
}
long minv = r[0];
long maxv = long.MinValue;
for (int i = 1; i < n; ++i) {
maxv = Math.Max(maxv, r[i] - minv);
minv = Math.Min(minv, r[i]);
}
Console.WriteLine(maxv);
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 187
| 2
|
using System;
public class Bubble {
public static void Main(string[] args) {
int count = int.Parse(Console.ReadLine());
string data = Console.ReadLine();
string[] num = data.Split();
int[] target = new int[count];
int temp;
int sortCount = 0; //?????????????????°???
for (int d = 0; d < num.Length; d++) {
target[d] = int.Parse(num[d]);
}
for (int i = 0; i < count - 2; i++) {
for (int j = count - 1; j > i; j--) {
if (target[j] < target[j - 1]) {
temp = target[j - 1];
target[j - 1] = target[j];
target[j] = temp;
sortCount++;
}
}
}
Console.Write(target[0]);
for (int k = 1; k < target.Length; k++) {
Console.Write(" " + target[k]);
}
Console.Write("\r\n");
Console.WriteLine(sortCount);
}
}
|
using System;
public class Bubble {
public static void Main(string[] args) {
int count = int.Parse(Console.ReadLine());
string data = Console.ReadLine();
string[] num = data.Split();
int[] target = new int[count];
int temp;
int sortCount = 0; //?????????????????°???
for (int d = 0; d < num.Length; d++) {
target[d] = int.Parse(num[d]);
}
for (int i = 0; i < count - 1; i++) {
for (int j = count - 1; j > i; j--) {
if (target[j] < target[j - 1]) {
temp = target[j - 1];
target[j - 1] = target[j];
target[j] = temp;
sortCount++;
}
}
}
Console.Write(target[0]);
for (int k = 1; k < target.Length; k++) {
Console.Write(" " + target[k]);
}
Console.Write("\r\n");
Console.WriteLine(sortCount);
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 249
| 2
|
using System;
class main {
public static void Main(String[] args) {
int n = int.Parse(Console.ReadLine());
int[] ary = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int cnt = bubbleSort(ary, n);
for (int i = 0; i < ary.Length; i++) {
if (i != ary.Length - 1) {
Console.Write(ary[i]);
} else {
Console.WriteLine(ary[i]);
}
}
Console.WriteLine(cnt);
}
internal static int bubbleSort(int[] a, int n) {
bool flag = true;
int cnt = 0;
while (flag) {
flag = false;
for (int j = n - 1; j > 0; j--) {
if (a[j] < a[j - 1]) {
int temp = a[j];
a[j] = a[j - 1];
a[j - 1] = temp;
flag = true;
cnt++;
}
}
}
return cnt;
}
}
|
using System;
class main {
public static void Main(String[] args) {
int n = int.Parse(Console.ReadLine());
int[] ary = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int cnt = bubbleSort(ary, n);
for (int i = 0; i < ary.Length; i++) {
if (i != ary.Length - 1) {
Console.Write(ary[i] + " ");
} else {
Console.WriteLine(ary[i]);
}
}
Console.WriteLine(cnt);
}
internal static int bubbleSort(int[] a, int n) {
bool flag = true;
int cnt = 0;
while (flag) {
flag = false;
for (int j = n - 1; j > 0; j--) {
if (a[j] < a[j - 1]) {
int temp = a[j];
a[j] = a[j - 1];
a[j - 1] = temp;
flag = true;
cnt++;
}
}
}
return cnt;
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 12, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 16, 12, 5, 0, 222]]
| 8
| 238
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine()); //標準入力
int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = n - 1; j > i; j--) {
if (array[j - 1] >= array[j]) {
int tmp = array[j - 1];
array[j - 1] = array[j];
array[j] = tmp;
count++;
}
}
}
Console.WriteLine(
string.Join(" ", array.Select(i => i.ToString()).ToArray()));
Console.WriteLine(count);
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine()); //標準入力
int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = n - 1; j > i; j--) {
if (array[j - 1] > array[j]) {
int tmp = array[j - 1];
array[j - 1] = array[j];
array[j] = tmp;
count++;
}
}
}
Console.WriteLine(
string.Join(" ", array.Select(i => i.ToString()).ToArray()));
Console.WriteLine(count);
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47]]
| 8
| 211
| 2
|
using System;
class A {
public static void Main() {
int n, count = 0;
n = int.Parse(Console.ReadLine());
int[] array = new int[n];
string[] str = Console.ReadLine().Split(' ');
for (int i = 0; i < n; i++) {
array[i] = int.Parse(str[i]);
}
for (int i = 0; i < n - 1; i++) {
for (int j = n - 1; j > i; j--) {
if (array[j].CompareTo(array[j - 1]) < 0) {
Swap(ref array[j], ref array[j - 1]);
count++;
}
}
}
for (int i = 0; i < n - 1; i++) {
Console.Write(array[i] + " ");
}
Console.Write(array[n]);
Console.WriteLine("");
Console.WriteLine(count);
}
static void Swap(ref int x, ref int y) {
int temp;
temp = x;
x = y;
y = temp;
}
}
|
using System;
class A {
public static void Main() {
int n, count = 0;
n = int.Parse(Console.ReadLine());
int[] array = new int[n];
string[] str = Console.ReadLine().Split(' ');
for (int i = 0; i < n; i++) {
array[i] = int.Parse(str[i]);
}
for (int i = 0; i < n - 1; i++) {
for (int j = n - 1; j > i; j--) {
if (array[j].CompareTo(array[j - 1]) < 0) {
Swap(ref array[j], ref array[j - 1]);
count++;
}
}
}
for (int i = 0; i < n - 1; i++) {
Console.Write(array[i] + " ");
}
Console.Write(array[n - 1]);
Console.WriteLine("");
Console.WriteLine(count);
}
static void Swap(ref int x, ref int y) {
int temp;
temp = x;
x = y;
y = temp;
}
}
|
[["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 258
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace lec11A {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] array = new int[n];
for (int i = 0; i < n; i++) {
Clean(array, n);
string input = Console.ReadLine();
string[] split = input.Split(' ');
for (int j = 0; j < split.Length - 2; j++) {
int m = int.Parse(split[j + 2]);
array[m - 1] = 1;
}
for (int index = 0; index < n; index++) {
Console.Write(index);
if (index != n - 1) {
Console.Write(" ");
}
}
Console.WriteLine();
}
Console.ReadLine();
Console.ReadLine();
}
static void Clean(int[] A, int n) {
for (int i = 0; i < n; i++) {
A[i] = 0;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace lec11A {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] array = new int[n];
for (int i = 0; i < n; i++) {
Clean(array, n);
string input = Console.ReadLine();
string[] split = input.Split(' ');
for (int j = 0; j < split.Length - 2; j++) {
int m = int.Parse(split[j + 2]);
array[m - 1] = 1;
}
for (int index = 0; index < n; index++) {
Console.Write(array[index]);
if (index != n - 1) {
Console.Write(" ");
}
}
Console.WriteLine();
}
Console.ReadLine();
Console.ReadLine();
}
static void Clean(int[] A, int n) {
for (int i = 0; i < n; i++) {
A[i] = 0;
}
}
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73]]
| 8
| 258
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Competitive {
internal class Node {
public List<Edge> Edges;
public int Dist;
public int No;
public bool Visited;
public int Start;
public int End;
public Node(int no) {
this.No = no;
Dist = int.MaxValue;
Edges = new List<Edge>();
Visited = false;
}
}
internal class Edge {
public int From;
public int To;
public int Cost;
public Edge(int fr, int to, int cost = 0) {
From = fr;
To = to;
Cost = cost;
}
}
internal class Graph {
public List<Node> Nodes;
public Node this[int i] {
set { Nodes[i] = value; }
get { return Nodes[i]; }
}
public Graph(int N) {
Nodes = new List<Node>();
for (int i = 0; i < N; i++) {
Nodes.Add(new Node(i));
}
}
}
internal class Solution {
public int N;
public Graph G;
public int T;
public void Run() {
N = Input.ReadInt();
G = new Graph(N);
for (int i = 0; i < N; i++) {
var line = Input.ReadIntArray();
var o = line[1];
for (int j = 0; j < o; j++) {
int fr = i;
int to = line[2 + j] - 1;
G[i].Edges.Add(new Edge(fr, to));
}
}
RunGraph();
for (int i = 0; i < N; i++) {
Console.WriteLine("{0} {1} {2}", i, G[i].Start, G[i].End);
}
}
public void RunGraph() {
T = 0;
for (int i = 0; i < N; i++)
DFS(i);
}
public void DFS(int i) {
if (G[i].Visited)
return;
T++;
G[i].Start = T;
G[i].Visited = true;
foreach (var e in G[i].Edges) {
DFS(e.To);
}
T++;
G[i].End = T;
}
}
internal static class Input {
public static int ReadInt() {
string line = Console.ReadLine();
return int.Parse(line);
}
public static int[] ReadIntArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(int.Parse).ToArray();
}
public static double[] ReadDoubleArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(double.Parse).ToArray();
}
}
internal class Program {
public static void Main(string[] args) {
var s = new Solution();
s.Run();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Competitive {
internal class Node {
public List<Edge> Edges;
public int Dist;
public int No;
public bool Visited;
public int Start;
public int End;
public Node(int no) {
this.No = no;
Dist = int.MaxValue;
Edges = new List<Edge>();
Visited = false;
}
}
internal class Edge {
public int From;
public int To;
public int Cost;
public Edge(int fr, int to, int cost = 0) {
From = fr;
To = to;
Cost = cost;
}
}
internal class Graph {
public List<Node> Nodes;
public Node this[int i] {
set { Nodes[i] = value; }
get { return Nodes[i]; }
}
public Graph(int N) {
Nodes = new List<Node>();
for (int i = 0; i < N; i++) {
Nodes.Add(new Node(i));
}
}
}
internal class Solution {
public int N;
public Graph G;
public int T;
public void Run() {
N = Input.ReadInt();
G = new Graph(N);
for (int i = 0; i < N; i++) {
var line = Input.ReadIntArray();
var o = line[1];
for (int j = 0; j < o; j++) {
int fr = i;
int to = line[2 + j] - 1;
G[i].Edges.Add(new Edge(fr, to));
}
}
RunGraph();
for (int i = 0; i < N; i++) {
Console.WriteLine("{0} {1} {2}", i + 1, G[i].Start, G[i].End);
}
}
public void RunGraph() {
T = 0;
for (int i = 0; i < N; i++)
DFS(i);
}
public void DFS(int i) {
if (G[i].Visited)
return;
T++;
G[i].Start = T;
G[i].Visited = true;
foreach (var e in G[i].Edges) {
DFS(e.To);
}
T++;
G[i].End = T;
}
}
internal static class Input {
public static int ReadInt() {
string line = Console.ReadLine();
return int.Parse(line);
}
public static int[] ReadIntArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(int.Parse).ToArray();
}
public static double[] ReadDoubleArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(double.Parse).ToArray();
}
}
internal class Program {
public static void Main(string[] args) {
var s = new Solution();
s.Run();
}
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 635
| 2
|
using System;
using System.Collections.Generic;
public class Program {
const int MAX = 100;
const int INFINITY = (1 << 21);
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
static int[,] M;
public static void Main() {
// ??°???????????????
int n = int.Parse(Console.ReadLine());
M = new int[n, n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
M[i, j] = INFINITY;
// ?????????????????????
string readLine = null;
for (int i = 0; i < n; ++i) {
readLine = Console.ReadLine();
string[] splitedNums = readLine.Split(' ');
int u = int.Parse(splitedNums[0]);
int k = int.Parse(splitedNums[1]);
// ??£??\????????¨?????????????????????
for (int j = 0; j < k; ++j) {
int v = int.Parse(splitedNums[2 + j * 2]);
int c = int.Parse(splitedNums[2 + j * 2 + 1]);
M[u, v] = c;
}
}
// ??????????????¢?´¢
dijkstra(n);
}
//
// dijkstra - ????????????????????????????????????????????¢?´¢
//
//
static void dijkstra(int n) {
int minv;
int[] d = new int[MAX];
int[] color = new int[MAX];
for (int i = 0; i < MAX; ++i) {
d[i] = INFINITY;
color[i] = WHITE;
}
d[0] = 0;
color[0] = GRAY;
while (true) {
minv = INFINITY;
int u = -1;
for (int i = 0; i < n; ++i) {
if (minv > d[i] && color[i] != BLACK) {
u = i;
minv = d[i];
}
}
if (u == -1)
break;
color[u] = BLACK;
for (int v = 0; v < n; ++v) {
if (color[v] != BLACK && M[u, v] != INFINITY) {
if (d[v] > d[u] + M[u, v]) {
d[v] = d[u] + M[u, v];
color[v] = GRAY;
}
}
}
}
for (int i = 0; i < n; ++i) {
Console.WriteLine(
string.Format("d[{0}] = {1}", i, d[i] == INFINITY ? -1 : d[i]));
}
}
}
|
using System;
using System.Collections.Generic;
public class Program {
const int MAX = 100;
const int INFINITY = (1 << 21);
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
static int[,] M;
public static void Main() {
// ??°???????????????
int n = int.Parse(Console.ReadLine());
M = new int[n, n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
M[i, j] = INFINITY;
// ?????????????????????
string readLine = null;
for (int i = 0; i < n; ++i) {
readLine = Console.ReadLine();
string[] splitedNums = readLine.Split(' ');
int u = int.Parse(splitedNums[0]);
int k = int.Parse(splitedNums[1]);
// ??£??\????????¨?????????????????????
for (int j = 0; j < k; ++j) {
int v = int.Parse(splitedNums[2 + j * 2]);
int c = int.Parse(splitedNums[2 + j * 2 + 1]);
M[u, v] = c;
}
}
// ??????????????¢?´¢
dijkstra(n);
}
//
// dijkstra - ????????????????????????????????????????????¢?´¢
//
//
static void dijkstra(int n) {
int minv;
int[] d = new int[MAX];
int[] color = new int[MAX];
for (int i = 0; i < MAX; ++i) {
d[i] = INFINITY;
color[i] = WHITE;
}
d[0] = 0;
color[0] = GRAY;
while (true) {
minv = INFINITY;
int u = -1;
for (int i = 0; i < n; ++i) {
if (minv > d[i] && color[i] != BLACK) {
u = i;
minv = d[i];
}
}
if (u == -1)
break;
color[u] = BLACK;
for (int v = 0; v < n; ++v) {
if (color[v] != BLACK && M[u, v] != INFINITY) {
if (d[v] > d[u] + M[u, v]) {
d[v] = d[u] + M[u, v];
color[v] = GRAY;
}
}
}
}
for (int i = 0; i < n; ++i) {
Console.WriteLine(
string.Format("{0} {1}", i, d[i] == INFINITY ? -1 : d[i]));
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 551
| 2
|
using System;
using System.Collections.Generic;
namespace alds_12 {
public class Program {
public class pair<T, U> : IComparable
where T : IComparable<T> {
public pair() {}
public pair(T first, U second) {
this.First = first;
this.Second = second;
}
public int CompareTo(Object obj) {
pair<T, U> cast = (pair<T, U>)obj;
return First.CompareTo(cast.First);
}
public T First { get; set; }
public U Second { get; set; }
}
public class PriorityQueue<T>
where T : IComparable {
private T[] heap;
private int sz = 0;
private int count = 0;
public PriorityQueue(int max) { heap = new T[max]; }
private int Compare(T x, T y) { return 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 bool Empty() { return count == 0; }
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 (Count() > 0)
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 private readonly int MAX = 100;
static private readonly int INFINITY = (1 << 21);
static private readonly int WHITE = 0;
static private readonly int GRAY = 1;
static private readonly int BLACK = 2;
static private int n = -1;
static private List<pair<int, int>>[] adj = null;
static private PriorityQueue<pair<int, int>> pq = null;
private static void dijkstra() {
int[] d = new int[n];
int[] color = new int[n];
pq = new PriorityQueue<pair<int, int>>(n);
for (int i = 0; i < n; i++) {
d[i] = INFINITY;
color[i] = WHITE;
}
d[0] = 0;
pq.Push(new pair<int, int>(0, 0));
color[0] = GRAY;
while (!pq.Empty()) {
pair<int, int> f = pq.Peek();
pq.Pop();
int u = f.Second;
color[u] = BLACK;
if (d[u] < f.First * (-1)) {
continue;
}
for (int i = 0; i < adj[u].Count; i++) {
int v = adj[u][i].First;
if (color[v] == BLACK) {
continue;
}
if (d[v] > d[u] + adj[u][i].Second) {
d[v] = d[u] + adj[u][i].Second;
pq.Push(new pair<int, int>(d[v] * (-1), v));
color[v] = GRAY;
}
}
}
for (int i = 0; i < n; i++) {
Console.Write("{0} {1}\n", i, (d[i] == INFINITY ? -1 : d[i]));
}
}
public static void Main() {
n = int.Parse(Console.ReadLine());
adj = new List<pair<int, int>>[n];
int k, c, u, v;
for (int i = 0; i < n; i++) {
int s = 0;
string[] str = Console.ReadLine().Split(' ');
adj[i] = new List<pair<int, int>>();
u = int.Parse(str[s++]);
k = int.Parse(str[s++]);
// Console.Write("{0}, {1}\n", u, k);
for (int j = 0; j < k; j++) {
v = int.Parse(str[s++]);
c = int.Parse(str[s++]);
adj[u].Add(new pair<int, int>(v, c));
// Console.Write("{0}, {1}\n", v, c);
}
}
dijkstra();
}
}
}
|
using System;
using System.Collections.Generic;
namespace alds_12 {
public class Program {
public class pair<T, U> : IComparable
where T : IComparable<T> {
public pair() {}
public pair(T first, U second) {
this.First = first;
this.Second = second;
}
public int CompareTo(Object obj) {
pair<T, U> cast = (pair<T, U>)obj;
return First.CompareTo(cast.First);
}
public T First { get; set; }
public U Second { get; set; }
}
public class PriorityQueue<T>
where T : IComparable {
private T[] heap;
private int sz = 0;
private int count = 0;
public PriorityQueue() { heap = new T[50000]; }
private int Compare(T x, T y) { return 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;
// Console.Write ("Push {0}", 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 bool Empty() { return count == 0; }
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 (Count() > 0)
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 private readonly int MAX = 100;
static private readonly int INFINITY = (1 << 21);
static private readonly int WHITE = 0;
static private readonly int GRAY = 1;
static private readonly int BLACK = 2;
static private int n = -1;
static private List<pair<int, int>>[] adj = null;
static private PriorityQueue<pair<int, int>> pq = null;
private static void dijkstra() {
int[] d = new int[n];
int[] color = new int[n];
pq = new PriorityQueue<pair<int, int>>();
for (int i = 0; i < n; i++) {
d[i] = INFINITY;
color[i] = WHITE;
}
d[0] = 0;
pq.Push(new pair<int, int>(0, 0));
color[0] = GRAY;
while (!pq.Empty()) {
pair<int, int> f = pq.Peek();
pq.Pop();
int u = f.Second;
color[u] = BLACK;
if (d[u] < f.First * (-1)) {
continue;
}
for (int i = 0; i < adj[u].Count; i++) {
int v = adj[u][i].First;
if (color[v] == BLACK) {
continue;
}
if (d[v] > d[u] + adj[u][i].Second) {
d[v] = d[u] + adj[u][i].Second;
pq.Push(new pair<int, int>(d[v] * (-1), v));
color[v] = GRAY;
}
}
}
for (int i = 0; i < n; i++) {
Console.Write("{0} {1}\n", i, (d[i] == INFINITY ? -1 : d[i]));
}
}
public static void Main() {
n = int.Parse(Console.ReadLine());
adj = new List<pair<int, int>>[n];
int k, c, u, v;
for (int i = 0; i < n; i++) {
int s = 0;
string[] str = Console.ReadLine().Split(' ');
adj[i] = new List<pair<int, int>>();
u = int.Parse(str[s++]);
k = int.Parse(str[s++]);
// Console.Write("{0}, {1}\n", u, k);
for (int j = 0; j < k; j++) {
v = int.Parse(str[s++]);
c = int.Parse(str[s++]);
adj[u].Add(new pair<int, int>(v, c));
// Console.Write("{0}, {1}\n", v, c);
}
}
dijkstra();
}
}
}
|
[["-", 8, 201, 0, 263, 54, 55, 0, 220, 39, 199], ["-", 8, 201, 0, 263, 54, 55, 0, 220, 141, 22], ["-", 0, 11, 12, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 203], ["-", 0, 11, 12, 230, 3, 4, 0, 28, 0, 22]]
| 8
| 1,215
| 5
|
using System;
public class hello {
public static void Main() {
var s1 = Console.ReadLine().Trim();
var s2 = Console.ReadLine().Trim();
var findex = s1.IndexOf(s2);
if (findex > 0)
Console.WriteLine(findex);
while (0 <= findex) {
var nIndex = findex + 1;
if (nIndex < s1.Length) {
findex = s1.IndexOf(s2, nIndex);
if (findex > 0)
Console.WriteLine(findex);
} else
break;
}
}
}
|
using System;
public class hello {
public static void Main() {
var s1 = Console.ReadLine().Trim();
var s2 = Console.ReadLine().Trim();
var findex = s1.IndexOf(s2);
if (findex >= 0)
Console.WriteLine(findex);
while (0 <= findex) {
var nIndex = findex + 1;
if (nIndex < s1.Length) {
findex = s1.IndexOf(s2, nIndex);
if (findex > 0)
Console.WriteLine(findex);
} else
break;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 117
| 2
|
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
string[] inputs = Console.ReadLine().Split(' ');
int[] A = new int[n];
for (int i = 0; i < n; i++) {
A[i] = int.Parse(inputs[i]);
}
InsertionSort(ref A, n);
}
static void InsertionSort(ref int[] arr, int n) {
for (int i = 1; i < n; i++) {
int tmp = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > tmp) {
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = tmp;
Console.WriteLine(
String.Join(" ", arr.Select(val => val.ToString()).ToArray()));
}
}
}
|
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
string[] inputs = Console.ReadLine().Split(' ');
int[] A = new int[n];
for (int i = 0; i < n; i++) {
A[i] = int.Parse(inputs[i]);
}
InsertionSort(ref A, n);
}
static void InsertionSort(ref int[] arr, int n) {
for (int i = 0; i < n; i++) {
int tmp = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > tmp) {
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = tmp;
Console.WriteLine(
String.Join(" ", arr.Select(val => val.ToString()).ToArray()));
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 239
| 2
|
using System.Collections.Generic;
using System.Linq;
public class PictureMatching {
private static int[] item;
public static void Main(string[] args) {
Input();
Method();
}
private static void Input() {
System.Console.ReadLine();
item = ToIntArray(System.Console.ReadLine().Split(' '));
}
private static void Method() {
for (int i = 1; i < item.Length; i++) {
for (int j = i - 1; j >= 0; j--) {
if (item[j + 1] < item[j]) {
var temp = item[j + 1];
item[j + 1] = item[j];
item[j] = temp;
}
}
ConsoleWrite(item);
}
}
private static void ConsoleWrite(int[] nums) {
for (int i = 0; i < nums.Length; i++) {
System.Console.Write(nums[i]);
if (i != nums.Length - 1) {
System.Console.Write(" ");
}
}
System.Console.WriteLine("");
}
private static int[] ToIntArray(string[] str) {
IEnumerable<int> intArray = str.Select(x => int.Parse(x));
return intArray.ToArray();
}
}
|
using System.Collections.Generic;
using System.Linq;
public class PictureMatching {
private static int[] item;
public static void Main(string[] args) {
Input();
Method();
}
private static void Input() {
System.Console.ReadLine();
item = ToIntArray(System.Console.ReadLine().Split(' '));
}
private static void Method() {
ConsoleWrite(item);
for (int i = 1; i < item.Length; i++) {
for (int j = i - 1; j >= 0; j--) {
if (item[j + 1] < item[j]) {
var temp = item[j + 1];
item[j + 1] = item[j];
item[j] = temp;
}
}
ConsoleWrite(item);
}
}
private static void ConsoleWrite(int[] nums) {
for (int i = 0; i < nums.Length; i++) {
System.Console.Write(nums[i]);
if (i != nums.Length - 1) {
System.Console.Write(" ");
}
}
System.Console.WriteLine("");
}
private static int[] ToIntArray(string[] str) {
IEnumerable<int> intArray = str.Select(x => int.Parse(x));
return intArray.ToArray();
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 290
| 5
|
// Getting Started - Insertion Sort
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A
using System;
using System.Linq;
namespace ALDS1_1_A {
class Program {
public Program() {}
public static void Main() { new Program().Calc(); }
void Calc() {
var N = int.Parse(Input); // Number of elements
var A = Input // Array : N elements
.Split(' ')
.Select(i => int.Parse(i))
.ToArray();
for (int i = 1; i < N; i++) {
int target = A[i];
int j = i;
for (; j > 0 && target <= A[j - 1]; j--)
A[j] = A[j - 1];
A[j] = target;
Output(A.Select(s => s.ToString()).Aggregate((s, t) => s + " " + t));
}
}
String Input {
get { return Console.ReadLine(); }
}
void Output(String str) { Console.WriteLine(str); }
}
}
|
// Getting Started - Insertion Sort
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A
using System;
using System.Linq;
namespace ALDS1_1_A {
class Program {
public Program() {}
public static void Main() { new Program().Calc(); }
void Calc() {
var N = int.Parse(Input); // Number of elements
var A = Input // Array : N elements
.Split(' ')
.Select(i => int.Parse(i))
.ToArray();
for (int i = 0; i < N; i++) {
int target = A[i];
int j = i;
for (; j > 0 && target <= A[j - 1]; j--)
A[j] = A[j - 1];
A[j] = target;
Output(A.Select(s => s.ToString()).Aggregate((s, t) => s + " " + t));
}
}
String Input {
get { return Console.ReadLine(); }
}
void Output(String str) { Console.WriteLine(str); }
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 216
| 2
|
using System;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split(' ');
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(input[i]);
}
InsertionSort(a);
}
static void InsertionSort(int[] a) {
for (int i = 1; i < a.Length; i++) {
int v = a[i];
int j = i - 1;
while (j >= 0 && a[j] > v) {
a[j + 1] = a[j];
j--;
}
a[j + 1] = v;
for (int k = 0; k < a.Length; k++) {
Console.Write((k > 0 ? " " : "") + a[k]);
}
Console.WriteLine();
}
}
}
|
using System;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split(' ');
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(input[i]);
}
InsertionSort(a);
}
static void InsertionSort(int[] a) {
for (int i = 0; i < a.Length; i++) {
int v = a[i];
int j = i - 1;
while (j >= 0 && a[j] > v) {
a[j + 1] = a[j];
j--;
}
a[j + 1] = v;
for (int k = 0; k < a.Length; k++) {
Console.Write((k > 0 ? " " : "") + a[k]);
}
Console.WriteLine();
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 227
| 2
|
using System;
class InsertionSort {
public static void Main() {
int n = int.Parse(Console.ReadLine().Trim());
var input = Console.ReadLine().Trim().Split(' ');
var A = new int[n];
for (int i = 0; i < n; i++) {
A[i] = int.Parse(input[i]);
}
Sort(A, n);
}
static void Sort(int[] A, int n) {
int i, j, tmp;
for (i = 1; i < n; i++) {
tmp = A[i];
j = i - 1;
while (j >= 0 && A[j] > tmp) {
A[j + 1] = A[j];
j--;
}
A[j + 1] = tmp;
Trace(A);
}
}
static void Trace(int[] A) {
string tmp = "";
foreach (int a in A) {
tmp += a.ToString() + " ";
}
tmp = tmp.Trim();
Console.WriteLine(tmp);
}
}
|
using System;
class InsertionSort {
public static void Main() {
int n = int.Parse(Console.ReadLine().Trim());
var input = Console.ReadLine().Trim().Split(' ');
var A = new int[n];
for (int i = 0; i < n; i++) {
A[i] = int.Parse(input[i]);
}
Sort(A, n);
}
static void Sort(int[] A, int n) {
Trace(A);
int i, j, tmp;
for (i = 1; i < n; i++) {
tmp = A[i];
j = i - 1;
while (j >= 0 && A[j] > tmp) {
A[j + 1] = A[j];
j--;
}
A[j + 1] = tmp;
Trace(A);
}
}
static void Trace(int[] A) {
string tmp = "";
foreach (int a in A) {
tmp += a.ToString() + " ";
}
tmp = tmp.Trim();
Console.WriteLine(tmp);
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 246
| 5
|
using System;
using System.Linq;
namespace Sample101 {
struct Card {
public char suit;
public char value;
}
class Program {
static void BubbleSort(Card[] C) {
for (int i = 0; i < C.Length; i++) {
for (int j = C.Length - 1; j >= i + 1; j--) {
if (C[j].value < C[j - 1].value) {
var temp = C[j];
C[j] = C[j - 1];
C[j - 1] = temp;
}
}
}
}
static void SelectionSort(Card[] C) {
for (int i = 0; i < C.Length; i++) {
int minj = i;
for (int j = i; j < C.Length; j++) {
if (C[j].value < C[minj].value) {
minj = j;
}
}
var temp = C[i];
C[i] = C[minj];
C[minj] = temp;
}
}
static void Print(Card[] C) {
for (int i = 0; i < C.Length; i++) {
Console.Write(C[i].suit.ToString() + C[i].value.ToString());
if (i != C.Length - 1) {
Console.Write(" ");
}
}
Console.WriteLine();
}
static bool isStable(Card[] C1, Card[] C2) {
for (int i = 0; i < C1.Length; i++) {
if (C1[i].suit != C2[i].suit) {
return false;
}
}
return true;
}
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var line = Console.ReadLine().Split(' ');
// ソート対象のカードの束を二つ用意する
Card[] cards1 = new Card[N];
Card[] cards2 = new Card[N];
for (int i = 0; i < N; i++) {
cards1[i].suit = line[i][0];
cards1[i].value = line[i][1];
cards2[i].suit = line[i][0];
cards2[i].value = line[i][1];
}
// それぞれソートする
BubbleSort(cards1);
SelectionSort(cards2);
// バブルソートの結果
Print(cards1);
Console.WriteLine("Stable");
// 選択ソートの結果
Print(cards2);
if (isStable(cards1, cards2)) {
Console.WriteLine("Stable");
} else {
Console.WriteLine("Not Stable");
}
}
}
}
|
using System;
using System.Linq;
namespace Sample101 {
struct Card {
public char suit;
public char value;
}
class Program {
static void BubbleSort(Card[] C) {
for (int i = 0; i < C.Length; i++) {
for (int j = C.Length - 1; j >= i + 1; j--) {
if (C[j].value < C[j - 1].value) {
var temp = C[j];
C[j] = C[j - 1];
C[j - 1] = temp;
}
}
}
}
static void SelectionSort(Card[] C) {
for (int i = 0; i < C.Length; i++) {
int minj = i;
for (int j = i; j < C.Length; j++) {
if (C[j].value < C[minj].value) {
minj = j;
}
}
var temp = C[i];
C[i] = C[minj];
C[minj] = temp;
}
}
static void Print(Card[] C) {
for (int i = 0; i < C.Length; i++) {
Console.Write(C[i].suit.ToString() + C[i].value.ToString());
if (i != C.Length - 1) {
Console.Write(" ");
}
}
Console.WriteLine();
}
static bool isStable(Card[] C1, Card[] C2) {
for (int i = 0; i < C1.Length; i++) {
if (C1[i].suit != C2[i].suit) {
return false;
}
}
return true;
}
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var line = Console.ReadLine().Split(' ');
// ソート対象のカードの束を二つ用意する
Card[] cards1 = new Card[N];
Card[] cards2 = new Card[N];
for (int i = 0; i < N; i++) {
cards1[i].suit = line[i][0];
cards1[i].value = line[i][1];
cards2[i].suit = line[i][0];
cards2[i].value = line[i][1];
}
// それぞれソートする
BubbleSort(cards1);
SelectionSort(cards2);
// バブルソートの結果
Print(cards1);
Console.WriteLine("Stable");
// 選択ソートの結果
Print(cards2);
if (isStable(cards1, cards2)) {
Console.WriteLine("Stable");
} else {
Console.WriteLine("Not stable");
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 572
| 2
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Swap(string[] A, int from, int to) {
string temp = A[from];
A[from] = A[to];
A[to] = temp;
}
static void BubbleSort(string[] ary) {
bool swapped = true;
while (swapped) {
swapped = false;
for (int i = 0; i < ary.Length - 1; i++) {
if (ary[i].Substring(1, 1)[0] > ary[i + 1].Substring(1, 1)[0]) {
swapped = true;
Swap(ary, i, i + 1);
}
}
}
}
static void SelectionSort(string[] A) {
for (int i = 0; i < A.Length; i++) {
int minidx = i;
for (int j = i; j < A.Length; j++)
minidx = (A[j].Substring(1, 1)[0] < A[minidx].Substring(1, 1)[0])
? j
: minidx;
Swap(A, i, minidx);
}
}
static bool isSame(string[] A, string[] B) {
if (A.Length != B.Length)
return false;
for (int i = 0; i < A.Length; i++) {
if (A[i] != B[i])
return false;
}
return true;
}
static void OutputArray(string[] A) {
for (int i = 0; i < A.Length - 1; i++)
Console.Write("{0} ", A[i]);
Console.WriteLine(A[A.Length - 1]);
}
public static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] A = Console.ReadLine().Split(' ');
string[] B = new string[N];
string[] C = new string[N];
A.CopyTo(B, 0);
A.CopyTo(C, 0);
BubbleSort(B);
SelectionSort(C);
OutputArray(B);
Console.WriteLine((isSame(B, B)) ? "Stable" : "NotStable");
OutputArray(C);
Console.WriteLine((isSame(B, C)) ? "Stable" : "NotStable");
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Swap(string[] A, int from, int to) {
string temp = A[from];
A[from] = A[to];
A[to] = temp;
}
static void BubbleSort(string[] ary) {
bool swapped = true;
while (swapped) {
swapped = false;
for (int i = 0; i < ary.Length - 1; i++) {
if (ary[i].Substring(1, 1)[0] > ary[i + 1].Substring(1, 1)[0]) {
swapped = true;
Swap(ary, i, i + 1);
}
}
}
}
static void SelectionSort(string[] A) {
for (int i = 0; i < A.Length; i++) {
int minidx = i;
for (int j = i; j < A.Length; j++)
minidx = (A[j].Substring(1, 1)[0] < A[minidx].Substring(1, 1)[0])
? j
: minidx;
Swap(A, i, minidx);
}
}
static bool isSame(string[] A, string[] B) {
if (A.Length != B.Length)
return false;
for (int i = 0; i < A.Length; i++) {
if (A[i] != B[i])
return false;
}
return true;
}
static void OutputArray(string[] A) {
for (int i = 0; i < A.Length - 1; i++)
Console.Write("{0} ", A[i]);
Console.WriteLine(A[A.Length - 1]);
}
public static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] A = Console.ReadLine().Split(' ');
string[] B = new string[N];
string[] C = new string[N];
A.CopyTo(B, 0);
A.CopyTo(C, 0);
BubbleSort(B);
SelectionSort(C);
OutputArray(B);
Console.WriteLine((isSame(B, B)) ? "Stable" : "Not stable");
OutputArray(C);
Console.WriteLine((isSame(B, C)) ? "Stable" : "Not stable");
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
| 8
| 530
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
public class Hoge {
public static void Main() {
var n = int.Parse(System.Console.ReadLine());
if (n == 0) {
}
var cardsLine = System.Console.ReadLine().Split(' ');
var bubbleSortedList = BubbleSort((string[])cardsLine.Clone());
System.Console.WriteLine(String.Join(" ", bubbleSortedList.ToArray()));
var stable = IsStable(cardsLine, bubbleSortedList.ToArray());
System.Console.WriteLine("Stable");
var selectionSortedList = SelectionSort((string[])cardsLine.Clone());
System.Console.WriteLine(String.Join(" ", selectionSortedList.ToArray()));
stable = IsStable(cardsLine, selectionSortedList.ToArray());
System.Console.WriteLine(stable ? "Stable" : "Not stable");
}
// Define other methods and classes here
public static List<string> BubbleSort(string[] C) {
for (int i = 0; i < C.Length; i++) {
for (int j = C.Length - 1; i < j; j--) {
if (int.Parse((C[j]).ToCharArray() [1].ToString()) <
int.Parse((C[j - 1]).ToCharArray() [1].ToString())) {
var tmp = C[j];
C[j] = C[j - 1];
C[j - 1] = tmp;
}
}
}
return C.ToList();
}
public static List<string> SelectionSort(string[] C) {
for (int i = 0; i < C.Length; i++) {
var minj = i;
for (int j = i; j < C.Length; j++) {
if (int.Parse(C[j].ToCharArray() [1].ToString()) <
int.Parse(C[minj].ToCharArray() [1].ToString())) {
minj = j;
}
}
var tmp = C[i];
C[i] = C[minj];
C[minj] = tmp;
}
return C.ToList();
}
public static bool IsStable(string[] IN, string[] OUT) {
for (int i = 0; i < IN.Length; i++) {
if (!IN[i].Equals(OUT[i]))
return false;
}
return true;
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
public class Hoge {
public static void Main() {
var n = int.Parse(System.Console.ReadLine());
if (n == 0) {
}
var cardsLine = System.Console.ReadLine().Split(' ');
var bubbleSortedList = BubbleSort((string[])cardsLine.Clone());
System.Console.WriteLine(String.Join(" ", bubbleSortedList.ToArray()));
var stable = IsStable(cardsLine, bubbleSortedList.ToArray());
System.Console.WriteLine("Stable");
var selectionSortedList = SelectionSort((string[])cardsLine.Clone());
System.Console.WriteLine(String.Join(" ", selectionSortedList.ToArray()));
stable =
IsStable(bubbleSortedList.ToArray(), selectionSortedList.ToArray());
System.Console.WriteLine(stable ? "Stable" : "Not stable");
}
// Define other methods and classes here
public static List<string> BubbleSort(string[] C) {
for (int i = 0; i < C.Length; i++) {
for (int j = C.Length - 1; i < j; j--) {
if (int.Parse((C[j]).ToCharArray() [1].ToString()) <
int.Parse((C[j - 1]).ToCharArray() [1].ToString())) {
var tmp = C[j];
C[j] = C[j - 1];
C[j - 1] = tmp;
}
}
}
return C.ToList();
}
public static List<string> SelectionSort(string[] C) {
for (int i = 0; i < C.Length; i++) {
var minj = i;
for (int j = i; j < C.Length; j++) {
if (int.Parse(C[j].ToCharArray() [1].ToString()) <
int.Parse(C[minj].ToCharArray() [1].ToString())) {
minj = j;
}
}
var tmp = C[i];
C[i] = C[minj];
C[minj] = tmp;
}
return C.ToList();
}
public static bool IsStable(string[] IN, string[] OUT) {
for (int i = 0; i < IN.Length; i++) {
if (!IN[i].Equals(OUT[i]))
return false;
}
return true;
}
}
|
[["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 540
| 6
|
using System;
namespace AOJ.ALDS {
public class StableSort {
private struct Card {
public string Suit { get; set; }
public int Number { get; set; }
}
private static void BubbleSort(Card[] array, int N) {
for (int i = 0; i < N; i++) {
bool end = true;
for (int j = N - 1; j > i; j++) {
if (array[j].Number < array[j - 1].Number) {
var tmp = array[j];
array[j] = array[j - 1];
array[j - 1] = tmp;
end = false;
}
}
if (end) {
break;
}
}
}
private static void SelectionSort(Card[] array, int N) {
for (int i = 0; i < N; i++) {
int min_j = i;
for (int j = i; j < N; j++) {
if (array[j].Number < array[min_j].Number) {
min_j = j;
}
}
if (i != min_j) {
var tmp = array[i];
array[i] = array[min_j];
array[min_j] = tmp;
}
}
}
public static void Main() {
int counter = int.Parse(Console.ReadLine());
var input = Console.ReadLine().Trim().Split(' ');
var bubble = new Card[counter];
var select = new Card[counter];
for (int i = 0; i < counter; i++) {
bubble[i].Suit = input[i].Substring(0, 1);
bubble[i].Number = int.Parse(input[i].Substring(1, 1));
select[i] = bubble[i];
}
BubbleSort(bubble, counter);
SelectionSort(select, counter);
bool is_stable = true;
for (int i = 0; i < counter; i++) {
if (bubble[i].Suit != select[i].Suit ||
bubble[i].Number != select[i].Number) {
is_stable = false;
break;
}
}
string out_bubble = "";
foreach (var c in bubble) {
out_bubble += c.Suit + c.Number + " ";
}
out_bubble = out_bubble.Trim();
string out_sel = "";
foreach (var c in select) {
out_sel += c.Suit + c.Number + " ";
}
out_sel = out_sel.Trim();
Console.WriteLine(out_bubble);
Console.WriteLine("Stable");
Console.WriteLine(out_sel);
Console.WriteLine(is_stable ? "Stable" : "Not stable");
}
}
}
|
using System;
namespace AOJ.ALDS {
public class StableSort {
private struct Card {
public string Suit { get; set; }
public int Number { get; set; }
}
private static void BubbleSort(Card[] array, int N) {
for (int i = 0; i < N; i++) {
bool end = true;
for (int j = N - 1; j > i; j--) {
if (array[j].Number < array[j - 1].Number) {
var tmp = array[j];
array[j] = array[j - 1];
array[j - 1] = tmp;
end = false;
}
}
if (end) {
break;
}
}
}
private static void SelectionSort(Card[] array, int N) {
for (int i = 0; i < N; i++) {
int min_j = i;
for (int j = i; j < N; j++) {
if (array[j].Number < array[min_j].Number) {
min_j = j;
}
}
if (i != min_j) {
var tmp = array[i];
array[i] = array[min_j];
array[min_j] = tmp;
}
}
}
public static void Main() {
int counter = int.Parse(Console.ReadLine());
var input = Console.ReadLine().Trim().Split(' ');
var bubble = new Card[counter];
var select = new Card[counter];
for (int i = 0; i < counter; i++) {
bubble[i].Suit = input[i].Substring(0, 1);
bubble[i].Number = int.Parse(input[i].Substring(1, 1));
select[i] = bubble[i];
}
BubbleSort(bubble, counter);
SelectionSort(select, counter);
bool is_stable = true;
for (int i = 0; i < counter; i++) {
if (bubble[i].Suit != select[i].Suit ||
bubble[i].Number != select[i].Number) {
is_stable = false;
break;
}
}
string out_bubble = "";
foreach (var c in bubble) {
out_bubble += c.Suit + c.Number + " ";
}
out_bubble = out_bubble.Trim();
string out_sel = "";
foreach (var c in select) {
out_sel += c.Suit + c.Number + " ";
}
out_sel = out_sel.Trim();
Console.WriteLine(out_bubble);
Console.WriteLine("Stable");
Console.WriteLine(out_sel);
Console.WriteLine(is_stable ? "Stable" : "Not stable");
}
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 68]]
| 8
| 573
| 2
|
using System;
// using System.Collections.Generic;
namespace Project {
class MainClass {
public static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] card1 = Console.ReadLine().Split(' ');
string[] card2 = new string[N];
for (int i = 0; i < N; i++) {
card2[i] = card1[i];
}
Bubble(card1);
Selection(card2);
}
public static void Bubble(string[] card) {
for (int i = 0; i < card.Length; i++) {
for (int j = card.Length - 1; j > i; j--) {
if (card[j][1] < card[j - 1][1]) {
string tmp = card[j];
card[j] = card[j - 1];
card[j - 1] = tmp;
}
}
}
for (int i = 0; i < card.Length; i++) {
Console.Write(card[i]);
if (i == card.Length - 1)
Console.Write("\n");
else
Console.Write(" ");
}
Console.WriteLine("Stable");
}
public static void Selection(string[] card) {
bool b = true;
for (int i = 0; i < card.Length; i++) {
int min = i;
for (int j = i; j < card.Length; j++) {
if (card[j][1] < card[min][1]) {
min = j;
}
}
if (min != i) {
for (int j = i; j < min + 1; j++) {
if (card[j][1] == card[i][1])
b = false;
}
}
string tmp = card[min];
card[min] = card[i];
card[i] = tmp;
}
for (int i = 0; i < card.Length; i++) {
Console.Write(card[i]);
if (i == card.Length - 1)
Console.Write("\n");
else
Console.Write(" ");
}
if (b == true)
Console.WriteLine("Stable");
else
Console.WriteLine("Not stable");
}
}
}
|
using System;
// using System.Collections.Generic;
namespace Project {
class MainClass {
public static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] card1 = Console.ReadLine().Split(' ');
string[] card2 = new string[N];
for (int i = 0; i < N; i++) {
card2[i] = card1[i];
}
Bubble(card1);
Selection(card2);
}
public static void Bubble(string[] card) {
for (int i = 0; i < card.Length; i++) {
for (int j = card.Length - 1; j > i; j--) {
if (card[j][1] < card[j - 1][1]) {
string tmp = card[j];
card[j] = card[j - 1];
card[j - 1] = tmp;
}
}
}
for (int i = 0; i < card.Length; i++) {
Console.Write(card[i]);
if (i == card.Length - 1)
Console.Write("\n");
else
Console.Write(" ");
}
Console.WriteLine("Stable");
}
public static void Selection(string[] card) {
bool b = true;
for (int i = 0; i < card.Length; i++) {
int min = i;
for (int j = i; j < card.Length; j++) {
if (card[j][1] < card[min][1]) {
min = j;
}
}
if (min != i) {
for (int j = i + 1; j < min + 1; j++) {
if (card[j][1] == card[i][1])
b = false;
}
}
string tmp = card[min];
card[min] = card[i];
card[i] = tmp;
}
for (int i = 0; i < card.Length; i++) {
Console.Write(card[i]);
if (i == card.Length - 1)
Console.Write("\n");
else
Console.Write(" ");
}
if (b == true)
Console.WriteLine("Stable");
else
Console.WriteLine("Not stable");
}
}
}
|
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 507
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _20170409_AOJ {
class ALDS1_2C {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] sArr = Console.ReadLine().Split(' ');
string[] arr1 = new string[n];
sArr.CopyTo(arr1, 0);
BubbleSort(arr1, n);
WriteArr(arr1);
WriteStableOrNot(sArr, arr1);
string[] arr2 = new string[n];
sArr.CopyTo(arr2, 0);
SelectionSort(arr2, n);
WriteArr(arr2);
WriteStableOrNot(sArr, arr2);
Console.ReadLine();
}
static int GetNumber(string _s) { return int.Parse(_s.Substring(1, 1)); }
static void WriteStableOrNot(string[] _arr1, string[] _arr2) {
if (IsStableSort(_arr1, _arr2)) {
Console.WriteLine("Stable");
} else {
Console.WriteLine("Not Stable");
}
}
static void Swap<T>(T[] _arr, int _i, int _j) {
T tmp = _arr[_i];
_arr[_i] = _arr[_j];
_arr[_j] = tmp;
}
static bool IsStableSort(string[] _orig, string[] _sorted) {
for (int i = 1; i < _sorted.Length; i++) {
if (GetNumber(_sorted[i - 1]) == GetNumber(_sorted[i])) {
if (Array.IndexOf(_orig, _sorted[i - 1]) >
Array.IndexOf(_orig, _sorted[i])) {
return false;
}
}
}
return true;
}
static void BubbleSort(string[] _arr, int _n) {
for (int i = 0; i < _n; i++) {
for (int j = _n - 1; j > i; j--) {
if (GetNumber(_arr[j]) < GetNumber(_arr[j - 1])) {
Swap(_arr, j, j - 1);
}
}
}
}
static void SelectionSort(string[] _arr, int _n) {
for (int i = 0; i < _n; i++) {
int minj = i;
for (int j = i; j < _n; j++) {
if (GetNumber(_arr[j]) < GetNumber(_arr[minj])) {
minj = j;
}
}
Swap(_arr, i, minj);
}
}
static void WriteArr<T>(T[] _arr) {
int len = _arr.Length;
if (len > 0) {
Console.Write(_arr[0]);
}
if (len > 1) {
for (int i = 1; i < len; i++) {
Console.Write(string.Format(" {0}", _arr[i]));
}
}
Console.Write("\r\n");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _20170409_AOJ {
class ALDS1_2C {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] sArr = Console.ReadLine().Split(' ');
string[] arr1 = new string[n];
sArr.CopyTo(arr1, 0);
BubbleSort(arr1, n);
WriteArr(arr1);
WriteStableOrNot(sArr, arr1);
string[] arr2 = new string[n];
sArr.CopyTo(arr2, 0);
SelectionSort(arr2, n);
WriteArr(arr2);
WriteStableOrNot(sArr, arr2);
Console.ReadLine();
}
static int GetNumber(string _s) { return int.Parse(_s.Substring(1, 1)); }
static void WriteStableOrNot(string[] _arr1, string[] _arr2) {
if (IsStableSort(_arr1, _arr2)) {
Console.WriteLine("Stable");
} else {
Console.WriteLine("Not stable");
}
}
static void Swap<T>(T[] _arr, int _i, int _j) {
T tmp = _arr[_i];
_arr[_i] = _arr[_j];
_arr[_j] = tmp;
}
static bool IsStableSort(string[] _orig, string[] _sorted) {
for (int i = 1; i < _sorted.Length; i++) {
if (GetNumber(_sorted[i - 1]) == GetNumber(_sorted[i])) {
if (Array.IndexOf(_orig, _sorted[i - 1]) >
Array.IndexOf(_orig, _sorted[i])) {
return false;
}
}
}
return true;
}
static void BubbleSort(string[] _arr, int _n) {
for (int i = 0; i < _n; i++) {
for (int j = _n - 1; j > i; j--) {
if (GetNumber(_arr[j]) < GetNumber(_arr[j - 1])) {
Swap(_arr, j, j - 1);
}
}
}
}
static void SelectionSort(string[] _arr, int _n) {
for (int i = 0; i < _n; i++) {
int minj = i;
for (int j = i; j < _n; j++) {
if (GetNumber(_arr[j]) < GetNumber(_arr[minj])) {
minj = j;
}
}
Swap(_arr, i, minj);
}
}
static void WriteArr<T>(T[] _arr) {
int len = _arr.Length;
if (len > 0) {
Console.Write(_arr[0]);
}
if (len > 1) {
for (int i = 1; i < len; i++) {
Console.Write(string.Format(" {0}", _arr[i]));
}
}
Console.Write("\r\n");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 621
| 2
|
using System;
class C {
public static void Main() {
int n = int.Parse(Console.ReadLine());
string[] bublearray = new string[n];
string[] selectarray = new string[n];
string[] str = Console.ReadLine().Split(' ');
string[] str2 = new string[n];
for (int i = 0; i < n; i++) {
str2[i] = str[i];
}
bublearray = BubbleSort(str, n);
selectarray = SelectionSort(str2, n);
for (int i = 0; i < n - 1; i++) {
Console.Write(bublearray[i] + " ");
}
Console.Write(bublearray[n]);
Console.WriteLine("");
Console.WriteLine("Stable");
for (int i = 0; i < n - 1; i++) {
Console.Write(selectarray[i] + " ");
}
Console.Write(selectarray[n]);
Console.WriteLine("");
if (Judgh(bublearray, selectarray, n) == true)
Console.WriteLine("Stable");
else
Console.WriteLine("Not stable");
}
static bool Judgh(string[] b_array, string[] s_array, int n) {
bool judgh = true;
for (int i = 0; i < n; i++) {
if (b_array[i].CompareTo(s_array[i]) != 0)
judgh = false;
}
return judgh;
}
static string[] BubbleSort(string[] array, int n) {
string[] newarray = new string[n];
for (int i = 0; i < n; i++) {
newarray[i] = array[i].Substring(1);
}
for (int i = 1; i < n; i++) {
for (int j = n - 1; j >= i; j--) {
if (newarray[j].CompareTo(newarray[j - 1]) < 0) {
Swap(ref array[j], ref array[j - 1]);
Swap(ref newarray[j], ref newarray[j - 1]);
}
}
}
return array;
}
static string[] SelectionSort(string[] array, int n) {
string[] newarray = new string[n];
for (int i = 0; i < n; i++) {
newarray[i] = array[i].Substring(1);
}
for (int i = 0; i < n; i++) {
int min = i;
for (int j = i; j < n; j++) {
if (newarray[min].CompareTo(newarray[j]) > 0)
min = j;
}
if (min != i) {
Swap(ref array[i], ref array[min]);
Swap(ref newarray[i], ref newarray[min]);
}
}
return array;
}
static void Swap(ref string x, ref string y) {
string temp;
temp = x;
x = y;
y = temp;
}
}
|
using System;
class C {
public static void Main() {
int n = int.Parse(Console.ReadLine());
string[] bublearray = new string[n];
string[] selectarray = new string[n];
string[] str = Console.ReadLine().Split(' ');
string[] str2 = new string[n];
for (int i = 0; i < n; i++) {
str2[i] = str[i];
}
bublearray = BubbleSort(str, n);
selectarray = SelectionSort(str2, n);
for (int i = 0; i < n - 1; i++) {
Console.Write(bublearray[i] + " ");
}
Console.Write(bublearray[n - 1]);
Console.WriteLine("");
Console.WriteLine("Stable");
for (int i = 0; i < n - 1; i++) {
Console.Write(selectarray[i] + " ");
}
Console.Write(selectarray[n - 1]);
Console.WriteLine("");
if (Judgh(bublearray, selectarray, n) == true)
Console.WriteLine("Stable");
else
Console.WriteLine("Not stable");
}
static bool Judgh(string[] b_array, string[] s_array, int n) {
bool judgh = true;
for (int i = 0; i < n; i++) {
if (b_array[i].CompareTo(s_array[i]) != 0)
judgh = false;
}
return judgh;
}
static string[] BubbleSort(string[] array, int n) {
string[] newarray = new string[n];
for (int i = 0; i < n; i++) {
newarray[i] = array[i].Substring(1);
}
for (int i = 1; i < n; i++) {
for (int j = n - 1; j >= i; j--) {
if (newarray[j].CompareTo(newarray[j - 1]) < 0) {
Swap(ref array[j], ref array[j - 1]);
Swap(ref newarray[j], ref newarray[j - 1]);
}
}
}
return array;
}
static string[] SelectionSort(string[] array, int n) {
string[] newarray = new string[n];
for (int i = 0; i < n; i++) {
newarray[i] = array[i].Substring(1);
}
for (int i = 0; i < n; i++) {
int min = i;
for (int j = i; j < n; j++) {
if (newarray[min].CompareTo(newarray[j]) > 0)
min = j;
}
if (min != i) {
Swap(ref array[i], ref array[min]);
Swap(ref newarray[i], ref newarray[min]);
}
}
return array;
}
static void Swap(ref string x, ref string y) {
string temp;
temp = x;
x = y;
y = temp;
}
}
|
[["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 665
| 4
|
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
class Program {
public static IO IO = new IO();
static void Main(string[] args) {
int n = IO.INT();
int[] m = IO.INT(n);
List<int> g = new List<int>();
int c = 0;
g.Add(1);
for (int i = 0; 3 * g[i] - 1 < n; i++) {
g.Add(3 * g[i] + 1);
}
g.Reverse();
for (int k = 0; k < g.Count(); k++) {
int gg = g[k];
for (int i = gg; i < n; i++) {
int v = m[i];
int j;
for (j = i - gg; j >= 0 && m[j] > v; j -= gg) {
m[j + gg] = m[j];
c++;
}
m[j + gg] = v;
}
}
IO.WRITE(g.Count());
IO.WRITE(string.Join(" ", g.Select(s => s.ToString()).ToArray()));
IO.WRITE(c);
for (int i = 0; i < n; i++) {
IO.WRITE(m[i]);
}
IO.FLUSH();
}
}
namespace LIB {
public class IO {
private const int WMAX = 1000;
private StringBuilder S = new StringBuilder();
private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
private T[] R<T>(Func<string, T> f, char c) {
return STRING().Split(c).Select(f).ToArray();
}
private T[] R<T>(Func<string, T> f, int l) {
T[] r = new T[l];
for (int i = 0; i < l; i++) {
r[i] = R(f);
}
return r;
}
private T[][] R<T>(Func<string, T> f, int l, char c) {
T[][] r = new T[l][];
for (int i = 0; i < l; i++) {
r[i] = R<T>(f, c);
}
return r;
}
private void W<T>(Func<T, string> f, T v, bool lf = true) {
S.Append(f(v));
if (lf == true) {
S.Append('\n');
}
if (S.Length >= WMAX) {
FLUSH();
}
}
public string STRING() { return R(s => s); }
public string[] STRING(char c) { return R(s => s, c); }
public string[] STRING(int l) { return R(s => s, l); }
public string[][] STRING(int l, char c) { return R(s => s, l, c); }
public int INT() { return R(int.Parse); }
public int[] INT(char c) { return R(int.Parse, c); }
public int[] INT(int l) { return R(int.Parse, l); }
public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
public long LONG() { return R(long.Parse); }
public long[] LONG(char c) { return R(long.Parse, c); }
public long[] LONG(int l) { return R(long.Parse, l); }
public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
public double DOUBLE() { return R(double.Parse); }
public double[] DOUBLE(char c) { return R(double.Parse, c); }
public double[] DOUBLE(int l) { return R(double.Parse, l); }
public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
public void WRITE(string s, bool lf = true) { W(v => v, s, lf); }
public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void FLUSH() {
Console.Write(S);
S.Length = 0;
}
}
}
|
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
class Program {
public static IO IO = new IO();
static void Main(string[] args) {
int n = IO.INT();
int[] m = IO.INT(n);
List<int> g = new List<int>();
int c = 0;
g.Add(1);
for (int i = 0; 3 * g[i] + 1 < n; i++) {
g.Add(3 * g[i] + 1);
}
g.Reverse();
for (int k = 0; k < g.Count(); k++) {
int gg = g[k];
for (int i = gg; i < n; i++) {
int v = m[i];
int j;
for (j = i - gg; j >= 0 && m[j] > v; j -= gg) {
m[j + gg] = m[j];
c++;
}
m[j + gg] = v;
}
}
IO.WRITE(g.Count());
IO.WRITE(string.Join(" ", g.Select(s => s.ToString()).ToArray()));
IO.WRITE(c);
for (int i = 0; i < n; i++) {
IO.WRITE(m[i]);
}
IO.FLUSH();
}
}
namespace LIB {
public class IO {
private const int WMAX = 1000;
private StringBuilder S = new StringBuilder();
private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
private T[] R<T>(Func<string, T> f, char c) {
return STRING().Split(c).Select(f).ToArray();
}
private T[] R<T>(Func<string, T> f, int l) {
T[] r = new T[l];
for (int i = 0; i < l; i++) {
r[i] = R(f);
}
return r;
}
private T[][] R<T>(Func<string, T> f, int l, char c) {
T[][] r = new T[l][];
for (int i = 0; i < l; i++) {
r[i] = R<T>(f, c);
}
return r;
}
private void W<T>(Func<T, string> f, T v, bool lf = true) {
S.Append(f(v));
if (lf == true) {
S.Append('\n');
}
if (S.Length >= WMAX) {
FLUSH();
}
}
public string STRING() { return R(s => s); }
public string[] STRING(char c) { return R(s => s, c); }
public string[] STRING(int l) { return R(s => s, l); }
public string[][] STRING(int l, char c) { return R(s => s, l, c); }
public int INT() { return R(int.Parse); }
public int[] INT(char c) { return R(int.Parse, c); }
public int[] INT(int l) { return R(int.Parse, l); }
public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
public long LONG() { return R(long.Parse); }
public long[] LONG(char c) { return R(long.Parse, c); }
public long[] LONG(int l) { return R(long.Parse, l); }
public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
public double DOUBLE() { return R(double.Parse); }
public double[] DOUBLE(char c) { return R(double.Parse, c); }
public double[] DOUBLE(int l) { return R(double.Parse, l); }
public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
public void WRITE(string s, bool lf = true) { W(v => v, s, lf); }
public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void FLUSH() {
Console.Write(S);
S.Length = 0;
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 72]]
| 8
| 1,092
| 2
|
using System;
using System.Collections.Generic;
class Program {
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] array = new int[n];
for (int k = 0; k < n; k++) {
array[k] = int.Parse(Console.ReadLine());
}
int cnt = 0;
int m = 1; //?????£??????????????°???h=3???m?????????/??? h<n???
List<int> G = new List<
int>(); //?????£??????????´???????????????£???????????????????????????????????????????????£??????
for (int gap = 2; (int)((Math.Pow(3, gap) - 1) / 2) < n; gap++) {
m++;
}
for (int i = 0; i < m; i++) {
G[i] = (int)((Math.Pow(3, i + 1) - 1) / 2);
}
for (int j = 0; j < m; j++) {
cnt += sort(array, n, G[m - 1 - j]); //?????\?????????????????????
}
//?????????????????????m???????????????G[i]????????????????????§???????????????G?????¨????????´??????count?????????
//????????????????????????????????????
Console.WriteLine(m);
for (int o = 0; o < m - 1; o++) {
Console.Write(G[m - 1 - o] + " ");
}
Console.Write(G[0] + "\r\n"); //???????????§?????????
Console.WriteLine(cnt); //?????????
for (int l = 0; l < n; l++) {
Console.WriteLine(array[l]);
}
}
public static int sort(int[] A, int n, int g) {
int count = 0; //??????????????°
for (int k = 0; k < g; k++) {
for (int i = k + g; i < n; i += g) {
int v = A[i];
int j = i - g;
while (j >= 0 && A[j] > v) {
A[j + g] = A[j];
j = j - g;
count++; //????????????????????§????????????????????§??????????????¢??????
A[j + g] =
v; //????????????A[j]???????????????????§?????????????????????\????????????
//??????????????????????°?????????????????????´?????????????????£?????????????????????????´??????´???????????????????°?????????????????????????0
//?????????????????????????????\???
}
}
}
return count;
}
}
|
using System;
using System.Collections.Generic;
class Program {
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] array = new int[n];
for (int k = 0; k < n; k++) {
array[k] = int.Parse(Console.ReadLine());
}
int cnt = 0;
int m = 1; //?????£??????????????°???h=3???m?????????/??? h<n???
List<int> G = new List<
int>(); //?????£??????????´???????????????£???????????????????????????????????????????????£??????
for (int gap = 2; (int)((Math.Pow(3, gap) - 1) / 2) < n; gap++) {
m++;
}
for (int i = 0; i < m; i++) {
G.Add((int)((Math.Pow(3, i + 1) - 1) / 2));
}
for (int j = 0; j < m; j++) {
cnt += sort(array, n, G[m - 1 - j]); //?????\?????????????????????
}
//?????????????????????m???????????????G[i]????????????????????§???????????????G?????¨????????´??????count?????????
//????????????????????????????????????
Console.WriteLine(m);
for (int o = 0; o < m - 1; o++) {
Console.Write(G[m - 1 - o] + " ");
}
Console.Write(G[0] + "\r\n"); //???????????§?????????
Console.WriteLine(cnt); //?????????
for (int l = 0; l < n; l++) {
Console.WriteLine(array[l]);
}
}
public static int sort(int[] A, int n, int g) {
int count = 0; //??????????????°
for (int k = 0; k < g; k++) {
for (int i = k + g; i < n; i += g) {
int v = A[i];
int j = i - g;
while (j >= 0 && A[j] > v) {
A[j + g] = A[j];
j = j - g;
count++; //????????????????????§????????????????????§??????????????¢??????
A[j + g] =
v; //????????????A[j]???????????????????§?????????????????????\????????????
//??????????????????????°?????????????????????´?????????????????£?????????????????????????´??????´???????????????????°?????????????????????????0
//?????????????????????????????\???
}
}
}
return count;
}
}
|
[["-", 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, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 74, 51, 23, 0, 25]]
| 8
| 445
| 8
|
using System;
class Program {
public static void Main(string[] args) {
double n = double.Parse(Console.ReadLine());
int[] array = new int[(int)n];
for (int k = 0; k < array.Length; k++) {
array[k] = int.Parse(Console.ReadLine());
}
int cnt = 0;
int m = 1; //?????£??????????????°???h=3???m?????????/??? h<n???
for (int gap = 2; (Math.Pow(3, gap) - 1) / 2 < n; gap++) {
m++;
}
int[] G = new int
[m]; //?????£??????????´???????????????£???????????????????????????????????????????????£??????
for (int i = 0; i < G.Length;
i++) //??????.Length????????????????????? m=G.Length
{
G[m - 1 - i] = (int)((Math.Pow(3, i + 1) - 1) / 2);
}
for (int j = 0; j < G.Length; j++) {
cnt += sort(array, G[j]); //?????\?????????????????????
}
//?????????????????????m???????????????G[i]????????????????????§???????????????G?????¨????????´??????count?????????
//????????????????????????????????????
Console.WriteLine(m);
for (int o = 0; o < G.Length - 1; o++) {
Console.Write(G[o] + " ");
}
Console.Write(G[G.Length - 1] + "\r\n"); //???????????§?????????
Console.WriteLine(cnt); //?????????
for (int l = 0; l < array.Length; l++) {
Console.WriteLine(array[l]);
}
}
public static int sort(int[] A, int g) {
int count = 0; //??????????????°
int v = 0;
int j = 0;
for (int k = 0; k < g; k++) {
for (int i = k + g; i < A.Length; i += g) {
v = A[i];
j = i - g;
while (j >= 0 & A[j] > v) {
A[j + g] = A[j];
j = j - g;
count++; //????????????????????§????????????????????§??????????????¢??????
A[j + g] =
v; //????????????A[j]???????????????????§?????????????????????\????????????
//??????????????????????°?????????????????????´?????????????????£?????????????????????????´??????´???????????????????°?????????????????????????0
//?????????????????????????????\???
}
}
}
return count;
}
}
|
using System;
class Program {
public static void Main(string[] args) {
double n = double.Parse(Console.ReadLine());
int[] array = new int[(int)n];
for (int k = 0; k < array.Length; k++) {
array[k] = int.Parse(Console.ReadLine());
}
int cnt = 0;
int m = 1; //?????£??????????????°???h=3???m?????????/??? h<n???
for (int gap = 2; (Math.Pow(3, gap) - 1) / 2 < n; gap++) {
m++;
}
int[] G = new int
[m]; //?????£??????????´???????????????£???????????????????????????????????????????????£??????
for (int i = 0; i < G.Length;
i++) //??????.Length????????????????????? m=G.Length
{
G[m - 1 - i] = (int)((Math.Pow(3, i + 1) - 1) / 2);
}
for (int j = 0; j < G.Length; j++) {
cnt += sort(array, G[j]); //?????\?????????????????????
}
//?????????????????????m???????????????G[i]????????????????????§???????????????G?????¨????????´??????count?????????
//????????????????????????????????????
Console.WriteLine(m);
for (int o = 0; o < G.Length - 1; o++) {
Console.Write(G[o] + " ");
}
Console.Write(G[G.Length - 1] + "\r\n"); //???????????§?????????
Console.WriteLine(cnt); //?????????
for (int l = 0; l < array.Length; l++) {
Console.WriteLine(array[l]);
}
}
public static int sort(int[] A, int g) {
int count = 0; //??????????????°
int v = 0;
int j = 0;
for (int k = 0; k < g; k++) {
for (int i = k + g; i < A.Length; i += g) {
v = A[i];
j = i - g;
while (j >= 0 && A[j] > v) {
A[j + g] = A[j];
j = j - g;
count++; //????????????????????§????????????????????§??????????????¢??????
A[j + g] =
v; //????????????A[j]???????????????????§?????????????????????\????????????
//??????????????????????°?????????????????????´?????????????????£?????????????????????????´??????´???????????????????°?????????????????????????0
//?????????????????????????????\???
}
}
}
return count;
}
}
|
[["-", 0, 7, 8, 196, 0, 52, 15, 16, 17, 67], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 17, 98]]
| 8
| 449
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace Prac {
class Prog {
public static void Main() {
Stack<long> rpn = new Stack<long>();
var inputs = Console.ReadLine().Split(' ');
var operant = 0L;
foreach (var i in inputs) {
if (long.TryParse(i, out operant)) {
rpn.Push(operant);
} else {
switch (i) {
case "+":
rpn.Push(rpn.Pop() + rpn.Pop());
break;
case "*":
rpn.Push(rpn.Pop() * rpn.Pop());
break;
case "-":
rpn.Push(rpn.Pop() - rpn.Pop());
break;
}
}
}
Console.WriteLine(rpn.Pop());
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace Prac {
class Prog {
public static void Main() {
Stack<long> rpn = new Stack<long>();
var inputs = Console.ReadLine().Split(' ');
var operant = 0L;
foreach (var i in inputs) {
if (long.TryParse(i, out operant)) {
rpn.Push(operant);
} else {
switch (i) {
case "+":
rpn.Push(rpn.Pop() + rpn.Pop());
break;
case "*":
rpn.Push(rpn.Pop() * rpn.Pop());
break;
case "-":
rpn.Push(-(rpn.Pop() - rpn.Pop()));
break;
}
}
}
Console.WriteLine(rpn.Pop());
}
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 3, 4, 0, 28, 0, 241, 0, 23, 0, 24], ["+", 0, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 198
| 3
|
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
class Program {
public static IO IO = new IO();
static void Main(string[] args) {
string[] n = IO.STRING(' ');
STACK<string> s = new STACK<string>(n.Count());
for (int i = 0; i < n.Count(); i++) {
if (n[i] == "+") {
s.PUSH((int.Parse(s.POP()) + int.Parse(s.POP())).ToString());
} else if (n[i] == "-") {
int n1 = int.Parse(s.POP());
int n2 = int.Parse(s.POP());
s.PUSH((n2 - n1).ToString());
} else if (n[i] == "*") {
s.PUSH((int.Parse(s.POP()) * int.Parse(s.POP())).ToString());
} else {
s.PUSH(n[i]);
}
}
IO.WRITE(s.POP());
IO.FLUSH();
}
}
#region STACK
namespace LIB {
public class STACK<T> {
private int m, p;
private T[] s;
public STACK(int max) {
m = max;
s = new T[m];
CLEAR();
}
public void CLEAR() { p = 0; }
public int COUNT() { return p; }
public T PEEK() { return s[p]; }
public T POP() {
T r = PEEK();
p--;
return r;
}
public void PUSH(T v) {
s[p] = v;
p++;
}
}
}
#endregion
namespace LIB {
public class IO {
private const int WMAX = 1000;
private StringBuilder S = new StringBuilder();
private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
private T[] R<T>(Func<string, T> f, char c) {
return STRING().Split(c).Select(f).ToArray();
}
private T[] R<T>(Func<string, T> f, int l) {
T[] r = new T[l];
for (int i = 0; i < l; i++) {
r[i] = R(f);
}
return r;
}
private T[][] R<T>(Func<string, T> f, int l, char c) {
T[][] r = new T[l][];
for (int i = 0; i < l; i++) {
r[i] = R<T>(f, c);
}
return r;
}
private void W<T>(Func<T, string> f, T v, bool lf = true) {
S.Append(f(v));
if (lf == true) {
S.Append('\n');
}
if (S.Length >= WMAX) {
FLUSH();
}
}
public string STRING() { return R(s => s); }
public string[] STRING(char c) { return R(s => s, c); }
public string[] STRING(int l) { return R(s => s, l); }
public string[][] STRING(int l, char c) { return R(s => s, l, c); }
public int INT() { return R(int.Parse); }
public int[] INT(char c) { return R(int.Parse, c); }
public int[] INT(int l) { return R(int.Parse, l); }
public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
public long LONG() { return R(long.Parse); }
public long[] LONG(char c) { return R(long.Parse, c); }
public long[] LONG(int l) { return R(long.Parse, l); }
public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
public double DOUBLE() { return R(double.Parse); }
public double[] DOUBLE(char c) { return R(double.Parse, c); }
public double[] DOUBLE(int l) { return R(double.Parse, l); }
public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
public void WRITE(string s, bool lf = true) { W(v => v, s, lf); }
public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void FLUSH() {
Console.Write(S);
S.Length = 0;
}
}
}
|
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
class Program {
public static IO IO = new IO();
static void Main(string[] args) {
string[] n = IO.STRING(' ');
STACK<string> s = new STACK<string>(n.Count());
for (int i = 0; i < n.Count(); i++) {
if (n[i] == "+") {
s.PUSH((int.Parse(s.POP()) + int.Parse(s.POP())).ToString());
} else if (n[i] == "-") {
int n1 = int.Parse(s.POP());
int n2 = int.Parse(s.POP());
s.PUSH((n2 - n1).ToString());
} else if (n[i] == "*") {
s.PUSH((int.Parse(s.POP()) * int.Parse(s.POP())).ToString());
} else {
s.PUSH(n[i]);
}
}
IO.WRITE(s.POP());
IO.FLUSH();
}
}
#region STACK
namespace LIB {
public class STACK<T> {
private int m, p;
private T[] s;
public STACK(int max) {
m = max;
s = new T[m];
CLEAR();
}
public void CLEAR() { p = 0; }
public int COUNT() { return p; }
public T PEEK() { return s[p - 1]; }
public T POP() {
T r = PEEK();
p--;
return r;
}
public void PUSH(T v) {
s[p] = v;
p++;
}
}
}
#endregion
namespace LIB {
public class IO {
private const int WMAX = 1000;
private StringBuilder S = new StringBuilder();
private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
private T[] R<T>(Func<string, T> f, char c) {
return STRING().Split(c).Select(f).ToArray();
}
private T[] R<T>(Func<string, T> f, int l) {
T[] r = new T[l];
for (int i = 0; i < l; i++) {
r[i] = R(f);
}
return r;
}
private T[][] R<T>(Func<string, T> f, int l, char c) {
T[][] r = new T[l][];
for (int i = 0; i < l; i++) {
r[i] = R<T>(f, c);
}
return r;
}
private void W<T>(Func<T, string> f, T v, bool lf = true) {
S.Append(f(v));
if (lf == true) {
S.Append('\n');
}
if (S.Length >= WMAX) {
FLUSH();
}
}
public string STRING() { return R(s => s); }
public string[] STRING(char c) { return R(s => s, c); }
public string[] STRING(int l) { return R(s => s, l); }
public string[][] STRING(int l, char c) { return R(s => s, l, c); }
public int INT() { return R(int.Parse); }
public int[] INT(char c) { return R(int.Parse, c); }
public int[] INT(int l) { return R(int.Parse, l); }
public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
public long LONG() { return R(long.Parse); }
public long[] LONG(char c) { return R(long.Parse, c); }
public long[] LONG(int l) { return R(long.Parse, l); }
public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
public double DOUBLE() { return R(double.Parse); }
public double[] DOUBLE(char c) { return R(double.Parse, c); }
public double[] DOUBLE(int l) { return R(double.Parse, l); }
public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
public void WRITE(string s, bool lf = true) { W(v => v, s, lf); }
public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); }
public void FLUSH() {
Console.Write(S);
S.Length = 0;
}
}
}
|
[["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 1,176
| 2
|
using System;
public class Program {
public static int top;
public static int[] S = new int[1000];
public static int Main() {
int a, b;
top = 0;
string[] line = Console.ReadLine().Split(' ');
for (int i = 0; i < line.Length; i++) {
if (line[i] == "+") {
a = pop();
b = pop();
push(a + b);
} else if (line[i] == "-") {
a = pop();
b = pop();
push(a - b);
} else if (line[i] == "*") {
a = pop();
b = pop();
push(a * b);
} else {
push(int.Parse(line[i]));
}
}
Console.Write("{0}", pop());
return 0;
}
public static void push(int x) { S[++top] = x; }
public static int pop() {
top--;
return S[top + 1];
}
}
|
using System;
public class Program {
public static int top;
public static int[] S = new int[1000];
public static int Main() {
int a, b;
top = 0;
string[] line = Console.ReadLine().Split(' ');
for (int i = 0; i < line.Length; i++) {
if (line[i] == "+") {
a = pop();
b = pop();
push(a + b);
} else if (line[i] == "-") {
b = pop();
a = pop();
push(a - b);
} else if (line[i] == "*") {
a = pop();
b = pop();
push(a * b);
} else {
push(int.Parse(line[i]));
}
}
Console.WriteLine("{0}", pop());
return 0;
}
public static void push(int x) { S[++top] = x; }
public static int pop() {
top--;
return S[top + 1];
}
}
|
[["-", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22]]
| 8
| 246
| 6
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
string[] inputs = args[0].Split(new char[] { ' ' });
Stack<int> stack = new Stack<int>();
for (int i = 0; i < inputs.Length; i++) {
switch (inputs[i]) {
case "+":
stack.Push(stack.Pop() + stack.Pop());
break;
case "-":
stack.Push((stack.Pop() - stack.Pop()) * -1);
break;
case "*":
stack.Push(stack.Pop() * stack.Pop());
break;
default:
stack.Push(int.Parse(inputs[i]));
break;
}
}
System.Console.WriteLine(stack.Pop());
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
string[] inputs = Console.ReadLine().Split(new char[] { ' ' });
Stack<int> stack = new Stack<int>();
for (int i = 0; i < inputs.Length; i++) {
switch (inputs[i]) {
case "+":
stack.Push(stack.Pop() + stack.Pop());
break;
case "-":
stack.Push((stack.Pop() - stack.Pop()) * -1);
break;
case "*":
stack.Push(stack.Pop() * stack.Pop());
break;
default:
stack.Push(int.Parse(inputs[i]));
break;
}
}
System.Console.WriteLine(stack.Pop());
}
}
|
[["-", 0, 212, 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, 203], ["-", 0, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25]]
| 8
| 203
| 9
|
using System;
using System.Collections.Generic;
public static class Program {
public static void Main() {
var stack = new Stack<int>();
foreach (var s in Console.ReadLine().Split(' ')) {
switch (s) {
case "+":
stack.Push(stack.Pop() + stack.Pop());
break;
case "-":
int a = stack.Pop();
int b = stack.Pop();
stack.Push(a - b);
break;
case "*":
stack.Push(stack.Pop() * stack.Pop());
break;
default:
stack.Push(int.Parse(s));
break;
}
}
Console.WriteLine(stack.Pop());
}
}
|
using System;
using System.Collections.Generic;
public static class Program {
public static void Main() {
var stack = new Stack<int>();
foreach (var s in Console.ReadLine().Split(' ')) {
switch (s) {
case "+":
stack.Push(stack.Pop() + stack.Pop());
break;
case "-":
int a = stack.Pop();
int b = stack.Pop();
stack.Push(b - a);
break;
case "*":
stack.Push(stack.Pop() * stack.Pop());
break;
default:
stack.Push(int.Parse(s));
break;
}
}
Console.WriteLine(stack.Pop());
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 170
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace aizu1 {
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
int n = int.Parse(s.Split(' ')[0]);
int p = int.Parse(s.Split(' ')[1]);
int time = 0;
Queue<process> queue = new Queue<process>();
for (int i = 0; i < n; i++) {
queue.Enqueue(new process(Console.ReadLine()));
}
while (queue.Count != 0) {
process _process = queue.Dequeue();
if (_process.time <= p)
Console.WriteLine(_process.name + " " + (time + _process.time));
else {
_process.time -= p;
queue.Enqueue(_process);
}
time += p;
}
}
public struct process {
public string name;
public int time;
public process(string s) {
this.name = s.Split(' ')[0];
this.time = int.Parse(s.Split(' ')[1]);
}
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace aizu1 {
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
int n = int.Parse(s.Split(' ')[0]);
int p = int.Parse(s.Split(' ')[1]);
int time = 0;
Queue<process> queue = new Queue<process>();
for (int i = 0; i < n; i++) {
queue.Enqueue(new process(Console.ReadLine()));
}
while (queue.Count != 0) {
process _process = queue.Dequeue();
if (_process.time <= p)
Console.WriteLine(_process.name + " " + (time += _process.time));
else {
_process.time -= p;
queue.Enqueue(_process);
time += p;
}
}
}
public struct process {
public string name;
public int time;
public process(string s) {
this.name = s.Split(' ')[0];
this.time = int.Parse(s.Split(' ')[1]);
}
}
}
}
|
[["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 16, 12, 23, 0, 11, 0, 202, 0, 107], ["-", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 274
| 4
|
using System;
using System.IO;
namespace DefaultNamespace {
public class Class1 {
static int n; //????????°
static int quantum;
static int head = 0;
static int tail;
static string[] name;
static int[] time;
static string[] results;
static int totalTime = 0;
static int r = 0; // results??¨??????????????????
public static void Main(string[] args) {
string nQ = Console.ReadLine();
string[] nQua = nQ.Split();
n = int.Parse(nQua[0]);
quantum = int.Parse(nQua[1]);
name = new string[n + 1];
time = new int[n + 1];
results = new string[n];
tail = n;
for (int i = 0; i < n; i++) //????????????
{
string nT = Console.ReadLine();
string[] nameTime = nT.Split();
name[i] = nameTime[0];
time[i] = int.Parse(nameTime[1]);
}
// dequeue??§head???tail??¨????????£??????????????????
while (tail != head) {
if (time[head] - quantum <= 0) {
dequeue(time[head]);
} else
enqueue(time[head] - quantum);
}
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// output??????
for (int j = 0; j < results.Length; j++) {
Console.WriteLine(results[j]);
}
//???????????§??????
Console.Out.Flush();
}
//?????\??????????????????????????¨?????????????????¨???????????????????????????????¨???????????????????
// head ++
public static void dequeue(int time) {
totalTime += time;
result(totalTime);
head += isFull(head);
}
//?????\?????????????°??????\?????????
// head ++ tail++
public static void enqueue(int remain) {
totalTime += quantum;
time[tail] = remain;
name[tail] = name[head];
head += isFull(head);
tail += isFull(tail);
}
public static int isFull(
int a) // head tail????¢?????????????????????°???????????????????????????
{
if (a == n) {
return 0;
} else
return a + 1;
}
public static void result(int total) {
results[r] = name[head] + " " + total.ToString();
r++;
}
}
}
|
using System;
using System.IO;
namespace DefaultNamespace {
public class Class1 {
static int n; //????????°
static int quantum;
static int head = 0;
static int tail;
static string[] name;
static int[] time;
static string[] results;
static int totalTime = 0;
static int r = 0; // results??¨??????????????????
public static void Main(string[] args) {
string nQ = Console.ReadLine();
string[] nQua = nQ.Split();
n = int.Parse(nQua[0]);
quantum = int.Parse(nQua[1]);
name = new string[n + 1];
time = new int[n + 1];
results = new string[n];
tail = n;
for (int i = 0; i < n; i++) //????????????
{
string nT = Console.ReadLine();
string[] nameTime = nT.Split();
name[i] = nameTime[0];
time[i] = int.Parse(nameTime[1]);
}
// dequeue??§head???tail??¨????????£??????????????????
while (tail != head) {
if (time[head] - quantum <= 0) {
dequeue(time[head]);
} else
enqueue(time[head] - quantum);
}
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// output??????
for (int j = 0; j < results.Length; j++) {
Console.WriteLine(results[j]);
}
//???????????§??????
Console.Out.Flush();
}
//?????\??????????????????????????¨?????????????????¨???????????????????????????????¨???????????????????
// head ++
public static void dequeue(int time) {
totalTime += time;
result(totalTime);
head = isFull(head);
}
//?????\?????????????°??????\?????????
// head ++ tail++
public static void enqueue(int remain) {
totalTime += quantum;
time[tail] = remain;
name[tail] = name[head];
head = isFull(head);
tail = isFull(tail);
}
public static int isFull(
int a) // head tail????¢?????????????????????°???????????????????????????
{
if (a == n) {
return 0;
} else
return a + 1;
}
public static void result(int total) {
results[r] = name[head] + " " + total.ToString();
r++;
}
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32]]
| 8
| 457
| 6
|
using System;
using System.Collections.Generic;
public static class Program {
public static void Main(string[] args) {
// input
string[] firstStr = Console.ReadLine().Split(' ');
int processNum = int.Parse(firstStr[0]);
int quantum = int.Parse(firstStr[1]);
Queue<KeyValuePair<string, int>> queue =
new Queue<KeyValuePair<string, int>>();
for (int i = 0; i < processNum; i++) {
string[] inputLine = Console.ReadLine().Split(' ');
queue.Enqueue(
new KeyValuePair<string, int>(inputLine[0], int.Parse(inputLine[1])));
}
// logic
int totalProcessTime = 0;
while (queue.Count > 0) {
var process = queue.Dequeue();
string currentProcessName = process.Key;
int currentProcessTime = process.Value;
if (currentProcessTime > quantum) {
totalProcessTime += quantum;
queue.Enqueue(new KeyValuePair<string, int>(
currentProcessName, currentProcessTime - quantum));
} else {
totalProcessTime += currentProcessTime;
Console.WriteLine("process.Key" + " " + totalProcessTime.ToString());
}
}
}
}
|
using System;
using System.Collections.Generic;
public static class Program {
public static void Main(string[] args) {
// input
string[] firstStr = Console.ReadLine().Split(' ');
int processNum = int.Parse(firstStr[0]);
int quantum = int.Parse(firstStr[1]);
Queue<KeyValuePair<string, int>> queue =
new Queue<KeyValuePair<string, int>>();
for (int i = 0; i < processNum; i++) {
string[] inputLine = Console.ReadLine().Split(' ');
queue.Enqueue(
new KeyValuePair<string, int>(inputLine[0], int.Parse(inputLine[1])));
}
// logic
int totalProcessTime = 0;
while (queue.Count > 0) {
var process = queue.Dequeue();
string currentProcessName = process.Key;
int currentProcessTime = process.Value;
if (currentProcessTime > quantum) {
totalProcessTime += quantum;
queue.Enqueue(new KeyValuePair<string, int>(
currentProcessName, currentProcessTime - quantum));
} else {
totalProcessTime += currentProcessTime;
Console.WriteLine(process.Key + " " + totalProcessTime.ToString());
}
}
}
}
|
[["-", 0, 28, 0, 16, 31, 16, 31, 5, 0, 62], ["-", 0, 28, 0, 16, 31, 16, 31, 5, 0, 222], ["+", 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]]
| 8
| 257
| 6
|
using System;
namespace ALDS1_3_C {
class Program {
static int[] S = new int[2000000];
static int top;
static int last;
static void Main(string[] args) {
int n = getint("a");
for (int i = 0; i < n; i++) {
string[] d = getsplit();
if (d[0] == "insert") {
insert(getint(d[1]));
} else if (d[0] == "delete") {
delete (getint(d[1]));
} else if (d[0] == "deleteFirst") {
deleteFirst();
} else {
deleteLast();
}
}
int a = 0;
for (int i = top; i >= last; i--) {
if (S[i] != 0 && a == 1) {
Console.Write(" " + (S[i] - 1));
} else if (S[i] != 0) {
Console.Write(S[i] - 1);
a = 1;
}
}
Console.WriteLine();
}
public static string[] getsplit() {
string[] x = Console.ReadLine().Split(' ');
return x;
}
public static int getint(string a) {
if (a == "a") {
int x = int.Parse(Console.ReadLine());
return x;
} else {
int x = int.Parse(a);
return x;
}
}
static void insert(int x) {
S[top] = x + 1;
top++;
}
static void delete (int x) {
for (int i = top - 1; i >= last; i--) {
if (S[i] == x + 1) {
S[i] = 0;
}
}
}
static void deleteFirst() {
while (S[top - 1] == 0)
top--;
S[top - 1] = 0;
top--;
}
static void deleteLast() {
while (S[last] == 0)
last++;
S[last] = 0;
last++;
}
}
}
|
using System;
namespace ALDS1_3_C {
class Program {
static int[] S = new int[2000000];
static int top;
static int last;
static void Main(string[] args) {
int n = getint("a");
for (int i = 0; i < n; i++) {
string[] d = getsplit();
if (d[0] == "insert") {
insert(getint(d[1]));
} else if (d[0] == "delete") {
delete (getint(d[1]));
} else if (d[0] == "deleteFirst") {
deleteFirst();
} else {
deleteLast();
}
}
int a = 0;
for (int i = top; i >= last; i--) {
if (S[i] != 0 && a == 1) {
Console.Write(" " + (S[i] - 1));
} else if (S[i] != 0) {
Console.Write(S[i] - 1);
a = 1;
}
}
Console.WriteLine();
}
public static string[] getsplit() {
string[] x = Console.ReadLine().Split(' ');
return x;
}
public static int getint(string a) {
if (a == "a") {
int x = int.Parse(Console.ReadLine());
return x;
} else {
int x = int.Parse(a);
return x;
}
}
static void insert(int x) {
S[top] = x + 1;
top++;
}
static void delete (int x) {
for (int i = top - 1; i >= last; i--) {
if (S[i] == x + 1) {
S[i] = 0;
break;
}
}
}
static void deleteFirst() {
while (S[top - 1] == 0)
top--;
S[top - 1] = 0;
top--;
}
static void deleteLast() {
while (S[last] == 0)
last++;
S[last] = 0;
last++;
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35]]
| 8
| 453
| 2
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
public void Proc() {
string inpt = Console.ReadLine();
// string inpt = @"\\///\_/\/\\\\/_/\\///_\\\\\/_/\";
Stack<int> s1 = new Stack<int>();
Stack<KeyValuePair<int, int>> s2 = new Stack<KeyValuePair<int, int>>();
long totalMenseki = 0;
for (int i = 0; i < inpt.Length; i++) {
if (inpt[i] == '\\') {
s1.Push(i);
} else if (inpt[i] == '/' && s1.Count > 0) {
int from = s1.Pop();
int menseki = i - from;
totalMenseki += menseki;
while (s2.Count > 0) {
KeyValuePair<int, int> tmp = s2.Peek();
if (tmp.Key >= from) {
menseki += tmp.Value;
s2.Pop();
} else {
break;
}
}
s2.Push(new KeyValuePair<int, int>(i, menseki));
}
}
Console.WriteLine(totalMenseki);
StringBuilder ans = new StringBuilder();
ans.Append(s2.Count);
int[] ikeList = new int[s2.Count];
for (int i = 0; i < s2.Count; i++) {
KeyValuePair<int, int> tmp = s2.Pop();
ikeList[ikeList.Length - 1 - i] = tmp.Value;
}
foreach (int menseki in ikeList) {
ans.Append(" ");
ans.Append(menseki);
}
Console.WriteLine(ans.ToString());
}
static void Main(string[] args)
{
Program prg = new Program();
prg.Proc();
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
public void Proc() {
string inpt = Console.ReadLine();
// string inpt = @"\\///\_/\/\\\\/_/\\///_\\\\\/_/\";
Stack<int> s1 = new Stack<int>();
Stack<KeyValuePair<int, int>> s2 = new Stack<KeyValuePair<int, int>>();
long totalMenseki = 0;
for (int i = 0; i < inpt.Length; i++) {
if (inpt[i] == '\\') {
s1.Push(i);
} else if (inpt[i] == '/' && s1.Count > 0) {
int from = s1.Pop();
int menseki = i - from;
totalMenseki += menseki;
while (s2.Count > 0) {
KeyValuePair<int, int> tmp = s2.Peek();
if (tmp.Key >= from) {
menseki += tmp.Value;
s2.Pop();
} else {
break;
}
}
s2.Push(new KeyValuePair<int, int>(i, menseki));
}
}
Console.WriteLine(totalMenseki);
StringBuilder ans = new StringBuilder();
ans.Append(s2.Count);
int[] ikeList = new int[s2.Count];
for (int i = 0; i < ikeList.Length; i++) {
KeyValuePair<int, int> tmp = s2.Pop();
ikeList[ikeList.Length - 1 - i] = tmp.Value;
}
foreach (int menseki in ikeList) {
ans.Append(" ");
ans.Append(menseki);
}
Console.WriteLine(ans.ToString());
}
static void Main(string[] args)
{
Program prg = new Program();
prg.Proc();
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22]]
| 8
| 371
| 4
|
using System;
using System.Collections.Generic;
using System.Text;
namespace ALDS1_3_D_raiburari_ {
class Program {
class Pond {
public int ichi;
public int area;
public Pond(int ichi, int area) {
this.ichi = ichi;
this.area = area;
}
}
static void Main(string[] args) {
string c = Console.ReadLine();
c += "1";
int i = 0, kyori = 0, sum = 0;
Stack<int> s1 = new Stack<int>();
Stack<Pond> s2 = new Stack<Pond>();
while (true) {
if (c[i] == '\\') {
s1.Push(i);
} else if (c[i] == '/' && s1.Count > 0) {
int j = s1.Pop();
kyori = i - j;
sum += kyori;
while (s2.Count > 0 && s2.Peek().ichi > j) {
kyori += s2.Peek().ichi;
s2.Pop();
}
s2.Push(new Pond(j, kyori));
} else if (c[i] == '1') {
break;
}
i++;
}
int k = s2.Count;
Console.WriteLine(sum);
Console.Write(k);
StringBuilder sb = new StringBuilder();
for (int j = 0; j < k; j++) {
sb.Insert(0, " " + s2.Pop().area);
}
Console.WriteLine(sb);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
namespace ALDS1_3_D_raiburari_ {
class Program {
class Pond {
public int ichi;
public int area;
public Pond(int ichi, int area) {
this.ichi = ichi;
this.area = area;
}
}
static void Main(string[] args) {
string c = Console.ReadLine();
c += "w";
int i = 0, kyori = 0, sum = 0;
Stack<int> s1 = new Stack<int>();
Stack<Pond> s2 = new Stack<Pond>();
while (true) {
if (c[i] == '\\') {
s1.Push(i);
} else if (c[i] == '/' && s1.Count > 0) {
int j = s1.Pop();
kyori = i - j;
sum += kyori;
while (s2.Count > 0 && s2.Peek().ichi > j) {
kyori += s2.Peek().area;
s2.Pop();
}
s2.Push(new Pond(j, kyori));
} else if (c[i] == 'w') {
break;
}
i++;
}
int k = s2.Count;
Console.WriteLine(sum);
Console.Write(k);
StringBuilder sb = new StringBuilder();
for (int j = 0; j < k; j++) {
sb.Insert(0, " " + s2.Pop().area);
}
Console.WriteLine(sb);
}
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["-", 75, 57, 75, 57, 15, 16, 12, 252, 0, 253], ["+", 75, 57, 75, 57, 15, 16, 12, 252, 0, 253]]
| 8
| 329
| 6
|
using System;
using System.Collections.Generic;
using System.Text;
namespace ALDS1_3_D {
class Program {
static void Main(string[] args) {
Dictionary<int, Stack<int>> dic = new Dictionary<int, Stack<int>>();
Stack<KeyValuePair<int, int>> stk = new Stack<KeyValuePair<int, int>>();
string input = Console.ReadLine();
int height = 0;
for (int i = 0; i < input.Length; i++) {
if (input[i] == '\\') {
if (!dic.ContainsKey(height))
dic[height] = new Stack<int>();
dic[height].Push(i);
height--;
} else if (input[i] == '/') {
height++;
stk.Push(new KeyValuePair<int, int>(height, i));
}
}
List<int> areaList = new List<int>();
int total = 0;
int area = 0;
int from = input.Length;
while (stk.Count > 0) {
KeyValuePair<int, int> cur = stk.Pop();
int upH = cur.Key;
int upW = cur.Value;
if (!dic.ContainsKey(upH))
continue;
int downW = upW;
while (dic[upH].Count > 0) {
downW = dic[upH].Pop();
if (downW < upW)
break;
}
if (downW >= upW)
continue;
if (from > downW) {
from = downW;
if (area != 0) {
areaList.Add(area);
area = 0;
}
}
int tempArea = upW - downW;
total += tempArea;
area += tempArea;
}
areaList.Add(area);
StringBuilder sb = new StringBuilder();
sb.AppendLine(total.ToString());
sb.Append(areaList.Count);
for (int i = areaList.Count - 1; i >= 0; i--)
sb.AppendFormat(" {0}", areaList[i]);
Console.WriteLine(sb);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
namespace ALDS1_3_D {
class Program {
static void Main(string[] args) {
Dictionary<int, Stack<int>> dic = new Dictionary<int, Stack<int>>();
Stack<KeyValuePair<int, int>> stk = new Stack<KeyValuePair<int, int>>();
string input = Console.ReadLine();
int height = 0;
for (int i = 0; i < input.Length; i++) {
if (input[i] == '\\') {
if (!dic.ContainsKey(height))
dic[height] = new Stack<int>();
dic[height].Push(i);
height--;
} else if (input[i] == '/') {
height++;
stk.Push(new KeyValuePair<int, int>(height, i));
}
}
List<int> areaList = new List<int>();
int total = 0;
int area = 0;
int from = input.Length;
while (stk.Count > 0) {
KeyValuePair<int, int> cur = stk.Pop();
int upH = cur.Key;
int upW = cur.Value;
if (!dic.ContainsKey(upH))
continue;
int downW = upW;
while (dic[upH].Count > 0) {
downW = dic[upH].Pop();
if (downW < upW)
break;
}
if (downW >= upW)
continue;
if (from > downW) {
from = downW;
if (area != 0) {
areaList.Add(area);
area = 0;
}
}
int tempArea = upW - downW;
total += tempArea;
area += tempArea;
}
if (area != 0)
areaList.Add(area);
StringBuilder sb = new StringBuilder();
sb.AppendLine(total.ToString());
sb.Append(areaList.Count);
for (int i = areaList.Count - 1; i >= 0; i--)
sb.AppendFormat(" {0}", areaList[i]);
Console.WriteLine(sb);
}
}
}
|
[["+", 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
| 444
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Elementary_data_structures {
class Areas_on_the_Cross_Section_Diagram {
static void Main(string[] args) {
var token = Console.ReadLine();
short bottom = 0;
short top = 0;
short height = 0;
for (int i = 0; i < token.Length; i++) {
switch (token[i]) {
case '\\':
height--;
break;
case '/':
height++;
break;
}
if (height > top)
top = height;
if (height < bottom)
bottom = height;
}
height = (short)(top - bottom);
// \ = 1
// / = 2
// _ = 3
var csd = new byte[token.Length];
var depth = new short[token.Length];
short d = (short)(top - 1);
var inc = 0;
for (int i = 0; i < token.Length; i++) {
switch (token[i]) {
case '\\':
if (inc == -1 || inc == 0)
d++;
inc = -1;
csd[i] = 1;
break;
case '/':
if (inc == 1)
d--;
csd[i] = 2;
inc = 1;
break;
case '_':
if (inc == 1)
d--;
inc = 0;
csd[i] = 3;
break;
}
depth[i] = d;
}
// \ + water = 4
// water + / = 5
for (int i = 0; i < height; i++) {
var left = -1;
d = -1;
for (int j = 0; j < token.Length; j++) {
if (csd[j] == 1) {
left = j;
d = depth[j];
} else if (d == depth[j] && csd[j] == 2 && left != -1) {
csd[left] = 4;
csd[j] = 5;
left = -2;
}
}
if (left != -2)
break;
}
var areas = new List<int>();
var area = 0;
var pool = false;
d = 0;
for (int j = 0; j < token.Length; j++) {
if (pool && csd[j] == 5 && d == depth[j]) {
pool = false;
area++;
d = 0;
area /= 2;
areas.Add(area);
area = 0;
continue;
}
if (!pool && csd[j] == 4) {
pool = true;
d = depth[j];
}
if (pool)
switch (csd[j]) {
case 3:
area += (depth[j] - d + 1) * 2;
break;
case 4:
case 5:
area += (depth[j] - d) * 2 + 1;
break;
}
}
Console.WriteLine(areas.Sum());
var c = areas.Count;
if (c == 0)
Console.WriteLine(0);
else {
Console.Write(c + " ");
for (int i = 0; i < c - 1; i++) {
Console.Write(areas[i] + " ");
}
Console.WriteLine(areas[c - 1]);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Elementary_data_structures {
class Areas_on_the_Cross_Section_Diagram {
static void Main(string[] args) {
var token = Console.ReadLine();
short bottom = 0;
short top = 0;
short height = 0;
for (int i = 0; i < token.Length; i++) {
switch (token[i]) {
case '\\':
height--;
break;
case '/':
height++;
break;
}
if (height > top)
top = height;
if (height < bottom)
bottom = height;
}
height = (short)(top - bottom);
// \ = 1
// / = 2
// _ = 3
var csd = new byte[token.Length];
var depth = new short[token.Length];
short d = (short)(top - 1);
var inc = 0;
for (int i = 0; i < token.Length; i++) {
switch (token[i]) {
case '\\':
if (inc == -1 || inc == 0)
d++;
inc = -1;
csd[i] = 1;
break;
case '/':
if (inc == 1)
d--;
csd[i] = 2;
inc = 1;
break;
case '_':
if (inc == 1)
d--;
inc = 0;
csd[i] = 3;
break;
}
depth[i] = d;
}
// \ + water = 4
// water + / = 5
for (int i = 0; i < height; i++) {
var left = -1;
d = -1;
for (int j = 0; j < token.Length; j++) {
if (csd[j] == 1) {
left = j;
d = depth[j];
} else if (d == depth[j] && csd[j] == 2 && left != -1) {
csd[left] = 4;
csd[j] = 5;
left = -2;
}
}
if (left != -2 && d == -1)
break;
}
var areas = new List<int>();
var area = 0;
var pool = false;
d = 0;
for (int j = 0; j < token.Length; j++) {
if (pool && csd[j] == 5 && d == depth[j]) {
pool = false;
area++;
d = 0;
area /= 2;
areas.Add(area);
area = 0;
continue;
}
if (!pool && csd[j] == 4) {
pool = true;
d = depth[j];
}
if (pool)
switch (csd[j]) {
case 3:
area += (depth[j] - d + 1) * 2;
break;
case 4:
case 5:
area += (depth[j] - d) * 2 + 1;
break;
}
}
Console.WriteLine(areas.Sum());
var c = areas.Count;
if (c == 0)
Console.WriteLine(0);
else {
Console.Write(c + " ");
for (int i = 0; i < c - 1; i++) {
Console.Write(areas[i] + " ");
}
Console.WriteLine(areas[c - 1]);
}
}
}
}
|
[["+", 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, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 203]]
| 8
| 681
| 5
|
using System;
namespace Test {
class MainClass {
public static void Main(string[] args) {
Console.ReadLine();
var numsS =
Array.ConvertAll(Console.ReadLine().TrimEnd().Split(), int.Parse);
Console.ReadLine();
var numsT =
Array.ConvertAll(Console.ReadLine().TrimEnd().Split(), int.Parse);
int ans = 0;
for (int i = 0; i < numsT.Length; i++) {
for (int j = 0; j < numsS.Length; j++) {
if (numsT[i] == numsS[j]) {
ans++;
}
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
namespace Test {
class MainClass {
public static void Main(string[] args) {
Console.ReadLine();
var numsS =
Array.ConvertAll(Console.ReadLine().TrimEnd().Split(), int.Parse);
Console.ReadLine();
var numsT =
Array.ConvertAll(Console.ReadLine().TrimEnd().Split(), int.Parse);
int ans = 0;
for (int i = 0; i < numsT.Length; i++) {
for (int j = 0; j < numsS.Length; j++) {
if (numsT[i] == numsS[j]) {
ans++;
break;
}
}
}
Console.WriteLine(ans);
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35]]
| 8
| 152
| 2
|
using System;
namespace Test {
class MainClass {
public static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var numsS = new int[n + 1];
var nums =
Array.ConvertAll(Console.ReadLine().TrimEnd().Split(), int.Parse);
nums.CopyTo(numsS, 0);
Console.ReadLine();
var numsT =
Array.ConvertAll(Console.ReadLine().TrimEnd().Split(), int.Parse);
int ans = 0;
for (int i = 0; i < numsT.Length; i++) {
numsS[n] = numsT[i];
var j = 0;
while (numsS[j] != numsT[i]) {
j++;
}
if (numsS[n] != j)
ans++;
}
Console.WriteLine(ans);
}
}
}
|
using System;
namespace Test {
class MainClass {
public static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var numsS = new int[n + 1];
var nums =
Array.ConvertAll(Console.ReadLine().TrimEnd().Split(), int.Parse);
nums.CopyTo(numsS, 0);
Console.ReadLine();
var numsT =
Array.ConvertAll(Console.ReadLine().TrimEnd().Split(), int.Parse);
int ans = 0;
for (int i = 0; i < numsT.Length; i++) {
numsS[n] = numsT[i];
var j = 0;
while (numsS[j] != numsT[i]) {
j++;
}
if (n != j)
ans++;
}
Console.WriteLine(ans);
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73]]
| 8
| 189
| 3
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
public void Proc() {
// Linear Search
int itemCount = int.Parse(Console.ReadLine());
int[] itemList = new int[itemCount];
string[] inpt = Console.ReadLine().Split(' ');
for (int i = 0; i < itemCount; i++) {
itemList[i] = int.Parse(inpt[i]);
}
int searchCount = int.Parse(Console.ReadLine());
int[] searchList = new int[searchCount];
inpt = Console.ReadLine().Split(' ');
for (int i = 0; i < searchCount; i++) {
searchList[i] = int.Parse(inpt[i]);
}
// ?????????
Array.Sort<int>(itemList);
Array.Sort<int>(searchList);
int cnt = 0;
int idx = 0;
int sIdx = 0;
while (idx <= itemList.Length - 1 && sIdx <= searchList.Length - 1) {
if (itemList[idx] == searchList[sIdx]) {
cnt++;
idx++;
} else if (itemList[idx] > searchList[sIdx]) {
sIdx++;
} else {
idx++;
}
}
Console.WriteLine(cnt);
}
static void Main(string[] args)
{
Program prg = new Program();
prg.Proc();
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
public void Proc() {
// Linear Search
int itemCount = int.Parse(Console.ReadLine());
int[] itemList = new int[itemCount];
// int itemCount = int.Parse("500");
// string[] inpt = "0 933 743 262 529 700 508 752 256 256 119 711 351 843
// 705 108 393 330 366 169 932 917 847 972 868 980 223 549 592 164 169 551
// 427 190 624 635 920 944 310 862 484 363 301 710 236 876 431 929 397 675
// 491 190 344 134 425 629 30 727 126 743 334 104 760 749 620 256 932 572 613
// 490 509 119 405 695 49 327 719 497 824 596 649 356 184 93 245 7 306 509
// 754 352 665 783 738 801 690 330 337 195 656 963 11 427 42 106 968 212 1
// 510 480 658 571 331 814 847 564 197 625 438 931 18 487 151 187 913 179 995
// 750 750 913 562 134 273 547 521 830 140 557 678 726 503 597 408 893 988
// 238 85 93 188 720 211 746 387 710 209 887 668 103 473 900 674 105 183 952
// 370 787 302 410 905 110 400 996 142 585 860 47 924 731 158 386 219 400 415
// 55 682 874 61 6 602 268 365 470 518 723 89 106 319 130 655 732 993 974 595
// 810 673 55 730 95 245 705 694 948 873 353 474 760 741 756 644 143 640 737
// 679 135 149 529 210 607 417 255 787 373 626 445 112 172 595 153 53 183 717
// 655 17 176 77 776 399 654 728 2 161 455 870 316 694 381 930 480 604 386
// 359 207 954 79 702 365 453 732 836 432 563 17 107 583 910 467 116 546 719
// 528 71 107 256 520 353 528 154 430 477 48 520 204 414 810 719 925 298 131
// 701 709 751 22 817 652 924 695 471 153 625 978 616 142 597 88 732 917 404
// 743 395 749 407 936 302 767 45 563 340 398 896 51 807 767 997 978 650 809
// 330 360 716 161 293 209 753 98 130 634 543 889 88 31 692 401 674 294 693
// 165 949 765 737 458 841 48 943 229 215 389 209 388 754 243 501 271 516 564
// 277 912 5 611 212 782 92 123 201 324 4 437 602 804 363 391 273 575 906 759
// 626 896 859 763 358 577 484 747 156 948 605 454 194 359 430 323 883 24 447
// 202 847 876 49 792 588 304 133 558 842 414 567 728 506 391 0 992 118 398
// 718 868 975 579 119 363 596 379 916 466 840 232 430 414 155 571 311 179
// 796 300 216 903 993 55 728 481 905 29 37 897 286 657 377 682 554 506 757
// 529 580 641 866 852 933 660 490 616 732 606 114 185 647 227 435 58 183 110
// 742 374 604 671 872 605 480 671 979 717 481 680 791".Split(' ');
string[] inpt = Console.ReadLine().Split(' ');
for (int i = 0; i < itemCount; i++) {
itemList[i] = int.Parse(inpt[i]);
}
int searchCount = int.Parse(Console.ReadLine());
int[] searchList = new int[searchCount];
// int searchCount = int.Parse("30");
// inpt = "0 9 18 30 31 42 48 49 59 74 85 115 121 153 165 168 181 195 205
// 207 220 228 248 252 255 270 274 289 291 300".Split(' ');
inpt = Console.ReadLine().Split(' ');
for (int i = 0; i < searchCount; i++) {
searchList[i] = int.Parse(inpt[i]);
}
// ?????????
Array.Sort<int>(itemList);
Array.Sort<int>(searchList);
int cnt = 0;
int idx = 0;
int sIdx = 0;
while (idx <= itemList.Length - 1 && sIdx <= searchList.Length - 1) {
if (itemList[idx] == searchList[sIdx]) {
cnt++;
sIdx++;
idx++;
} else if (itemList[idx] > searchList[sIdx]) {
sIdx++;
} else {
idx++;
}
}
Console.WriteLine(cnt);
}
static void Main(string[] args)
{
Program prg = new Program();
prg.Proc();
}
}
|
[["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 304
| 3
|
using System;
public class Program {
public static bool search(int[] A, int n, int key) {
int i = 0;
A[n] = key;
while (A[i] != key)
i++;
return true;
}
public static int Main() {
int i, n, q, key, sum = 0;
int[] A = new int[10000 + 1];
n = int.Parse(Console.ReadLine());
string[] line = Console.ReadLine().Split(' ');
for (i = 0; i < n; i++) {
A[i] = int.Parse(line[i]);
}
q = int.Parse(Console.ReadLine());
string[] strKey = Console.ReadLine().Split(' ');
for (i = 0; i < q; i++) {
key = int.Parse(strKey[i]);
if (search(A, n, key))
sum++;
}
Console.WriteLine("{0}", sum);
return 0;
}
}
|
using System;
public class Program {
public static bool search(int[] A, int n, int key) {
int i = 0;
A[n] = key;
while (A[i] != key)
i++;
return i != n;
}
public static int Main() {
int i, n, q, key, sum = 0;
int[] A = new int[10000 + 1];
n = int.Parse(Console.ReadLine());
string[] line = Console.ReadLine().Split(' ');
for (i = 0; i < n; i++) {
A[i] = int.Parse(line[i]);
}
q = int.Parse(Console.ReadLine());
string[] strKey = Console.ReadLine().Split(' ');
for (i = 0; i < q; i++) {
key = int.Parse(strKey[i]);
if (search(A, n, key))
sum++;
}
Console.WriteLine("{0}", sum);
return 0;
}
}
|
[["-", 0, 195, 8, 196, 0, 37, 0, 211, 0, 146], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 12, 22]]
| 8
| 234
| 4
|
using System;
namespace ALDS1_4_A {
class Program {
static void Main(string[] args) {
Console.WriteLine();
string[] s = getsplit();
Console.WriteLine();
string[] t = getsplit();
int count = 0;
foreach (string T in t) {
foreach (string S in s) {
if (S == T) {
count++;
break;
}
}
}
Console.WriteLine(count);
}
public static int getint(string a) {
if (a == null) {
int x = int.Parse(Console.ReadLine());
return x;
} else {
int x = int.Parse(a);
return x;
}
}
public static string[] getsplit() {
string[] x = Console.ReadLine().Split(' ');
return x;
}
}
}
|
using System;
namespace ALDS1_4_A {
class Program {
static void Main(string[] args) {
Console.ReadLine();
string[] s = getsplit();
Console.ReadLine();
string[] t = getsplit();
int count = 0;
foreach (string T in t) {
foreach (string S in s) {
if (S == T) {
count++;
break;
}
}
}
Console.WriteLine(count);
}
public static int getint(string a) {
if (a == null) {
int x = int.Parse(Console.ReadLine());
return x;
} else {
int x = int.Parse(a);
return x;
}
}
public static string[] getsplit() {
string[] x = Console.ReadLine().Split(' ');
return x;
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22]]
| 8
| 177
| 4
|
using System;
using System.Collections.Generic;
namespace Project {
class MainClass {
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] tmpS = Console.ReadLine().Split(' ');
int[] S = new int[n];
for (int i = 0; i < n; i++) {
S[i] = int.Parse(tmpS[i]);
}
int q = int.Parse(Console.ReadLine());
string[] tmpT = Console.ReadLine().Split(' ');
int[] T = new int[q];
for (int i = 0; i < q; i++) {
T[i] = int.Parse(tmpT[i]);
}
int count = 0;
for (int j = 0; j < q; j++) {
for (int i = 0; i < n; i++) {
if (S[i] == T[j])
count++;
}
}
Console.WriteLine(count);
}
}
}
|
using System;
using System.Collections.Generic;
namespace Project {
class MainClass {
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] tmpS = Console.ReadLine().Split(' ');
int[] S = new int[n];
for (int i = 0; i < n; i++) {
S[i] = int.Parse(tmpS[i]);
}
int q = int.Parse(Console.ReadLine());
string[] tmpT = Console.ReadLine().Split(' ');
int[] T = new int[q];
for (int i = 0; i < q; i++) {
T[i] = int.Parse(tmpT[i]);
}
int count = 0;
for (int j = 0; j < q; j++) {
for (int i = 0; i < n; i++) {
if (S[i] == T[j]) {
count++;
break;
}
}
}
Console.WriteLine(count);
}
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 237
| 4
|
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.IO;
public class Playground {
private static int[] item1;
private static int[] item2;
public static void Main(string[] args) {
Input();
Method();
System.Console.ReadLine();
}
private static void Input() {
Console.ReadLine();
item1 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
Console.ReadLine();
item2 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static void Method() {
// int sum = item1.Aggregate(0, (cnt, elem) =>
// cnt + item2.Count(y => y == elem)
//);
int sum = 0;
foreach (var s in item1) {
foreach (var t in item2) {
if (s == t) {
sum++;
break;
}
}
}
System.Console.WriteLine(sum);
}
}
|
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.IO;
public class Playground {
private static int[] item1;
private static int[] item2;
public static void Main(string[] args) {
Input();
Method();
System.Console.ReadLine();
}
private static void Input() {
Console.ReadLine();
item1 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
Console.ReadLine();
item2 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static void Method() {
// int sum = item1.Aggregate(0, (cnt, elem) =>
// cnt + item2.Count(y => y == elem)
//);
int sum = 0;
foreach (var s in item2) {
foreach (var t in item1) {
if (s == t) {
sum++;
break;
}
}
}
System.Console.WriteLine(sum);
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["-", 8, 196, 0, 210, 8, 196, 0, 210, 12, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 210, 12, 22]]
| 8
| 196
| 4
|
using System;
class Program {
static void Main() {
string[] s;
int n = int.Parse(Console.ReadLine());
s = Console.ReadLine().Split(' ');
int[] S = new int[n];
for (int i = 0; i < n; i++)
S[i] = int.Parse(s[i]);
int q = int.Parse(Console.ReadLine());
s = Console.ReadLine().Split(' ');
int[] T = new int[q];
for (int i = 0; i < q; i++)
T[i] = int.Parse(s[i]);
int c = 0;
for (int i = 0; i < q; i++) {
for (int j = 0; j < n; j++) {
if (T[i] == S[j])
c++;
}
}
Console.WriteLine(c.ToString());
}
}
|
using System;
class Program {
static void Main() {
string[] s;
int n = int.Parse(Console.ReadLine());
s = Console.ReadLine().Split(' ');
int[] S = new int[n];
for (int i = 0; i < n; i++)
S[i] = int.Parse(s[i]);
int q = int.Parse(Console.ReadLine());
s = Console.ReadLine().Split(' ');
int[] T = new int[q];
for (int i = 0; i < q; i++)
T[i] = int.Parse(s[i]);
int c = 0;
for (int i = 0; i < q; i++) {
for (int j = 0; j < n; j++) {
if (T[i] == S[j]) {
c++;
break;
}
}
}
Console.WriteLine(c.ToString());
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 220
| 4
|
using System;
namespace A {
class A {
static void Main(string[] args) {
int n, q, i, count = 0;
string a;
string[] b = new string[10000];
int[] S = new int[1000000000];
int[] T = new int[1000000000];
LinerSearch search = new LinerSearch();
a = Console.ReadLine();
n = int.Parse(a);
b = Console.ReadLine().Split(' ');
for (i = 0; i < n; i++) {
S[i] = int.Parse(b[i]);
}
a = Console.ReadLine();
q = int.Parse(a);
b = Console.ReadLine().Split(' ');
for (i = 0; i < q; i++) {
T[i] = int.Parse(b[i]);
}
for (i = 0; i < q; i++) {
count = count + search.search(S, T[i], n);
}
Console.WriteLine(count);
}
}
class LinerSearch {
int i;
public int search(int[] A, int key, int a) {
for (i = 0; i < a; i++) {
if (A[i] == key) {
return 1;
}
}
return 0;
}
}
}
|
using System;
namespace A {
class A {
static void Main(string[] args) {
int n, q, i, count = 0;
string a;
string[] b = new string[30000];
int[] S = new int[10000];
int[] T = new int[10000];
LinerSearch search = new LinerSearch();
a = Console.ReadLine();
n = int.Parse(a);
b = Console.ReadLine().Split(' ');
for (i = 0; i < n; i++) {
S[i] = int.Parse(b[i]);
}
a = Console.ReadLine();
q = int.Parse(a);
b = Console.ReadLine().Split(' ');
for (i = 0; i < q; i++) {
T[i] = int.Parse(b[i]);
}
for (i = 0; i < q; i++) {
count = count + search.search(S, T[i], n);
}
Console.WriteLine(count);
}
}
class LinerSearch {
int i;
public int search(int[] A, int key, int a) {
for (i = 0; i < a; i++) {
if (A[i] == key) {
return 1;
}
}
return 0;
}
}
}
|
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203]]
| 8
| 297
| 6
|
using System;
using System.Linq;
using System.Collections.Generic;
public class BinarySearch {
public static void Main() {
Console.ReadLine();
var sList = ReadLineAndToIntList();
Console.ReadLine();
var tList = ReadLineAndToIntList();
int count = 0;
tList.ForEach(t => {
if (MyBinarySearch(sList, t) >= 0)
count++;
});
Console.WriteLine(count);
}
//??????????????????????????????
public static List<int> ReadLineAndToIntList() {
return Console.ReadLine().Split().Select(c => int.Parse(c)).ToList();
}
public static int MyBinarySearch(List<int> list, int target) {
int left = 0;
int right = list.Count() - 1;
while (left < right) {
int mid = (left + right) / 2;
if (list[mid] == target)
return mid;
else if (target < list[mid])
right = mid;
else
left = mid + 1;
}
return -1;
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
public class BinarySearch {
public static void Main() {
Console.ReadLine();
var sList = ReadLineAndToIntList();
Console.ReadLine();
var tList = ReadLineAndToIntList();
int count = 0;
tList.ForEach(t => {
if (MyBinarySearch(sList, t) >= 0)
count++;
});
Console.WriteLine(count);
}
//??????????????????????????????
public static List<int> ReadLineAndToIntList() {
return Console.ReadLine().Split().Select(c => int.Parse(c)).ToList();
}
public static int MyBinarySearch(List<int> list, int target) {
int left = 0;
int right = list.Count();
while (left < right) {
int mid = (left + right) / 2;
if (list[mid] == target)
return mid;
else if (target < list[mid])
right = mid;
else
left = mid + 1;
}
return -1;
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 217
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
public class BinarySearch {
public static void Main() {
Console.ReadLine();
var sList = ReadLineAndToIntList();
Console.ReadLine();
var tList = ReadLineAndToIntList();
int count = 0;
foreach (var s in sList) {
if (tList.BinarySearch(s) > -1)
count++;
}
Console.WriteLine(count);
}
//??????????????????????????????
public static List<int> ReadLineAndToIntList() {
return Console.ReadLine().Split().Select(c => int.Parse(c)).ToList();
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
public class BinarySearch {
public static void Main() {
Console.ReadLine();
var sList = ReadLineAndToIntList();
Console.ReadLine();
var tList = ReadLineAndToIntList();
int count = 0;
foreach (int t in tList) {
if (sList.BinarySearch(t) > -1)
count++;
}
Console.WriteLine(count);
}
//??????????????????????????????
public static List<int> ReadLineAndToIntList() {
return Console.ReadLine().Split().Select(c => int.Parse(c)).ToList();
}
}
|
[["-", 0, 195, 8, 196, 0, 210, 39, 216, 0, 217], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["-", 15, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 15, 16, 31, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 129
| 10
|
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.IO;
public class Playground {
private static int[] item1;
private static int[] item2;
public static void Main(string[] args) {
Input();
Method();
System.Console.ReadLine();
}
private static void Input() {
Console.ReadLine();
item1 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
Console.ReadLine();
item2 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static void Method() {
int sum = 0;
item2.Aggregate(
0, (cnt, elem) => cnt + (Array.BinarySearch(item1, elem) >= 0 ? 1 : 0));
System.Console.WriteLine(sum);
}
}
|
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.IO;
public class Playground {
private static int[] item1;
private static int[] item2;
public static void Main(string[] args) {
Input();
Method();
System.Console.ReadLine();
}
private static void Input() {
Console.ReadLine();
item1 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
Console.ReadLine();
item2 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static void Method() {
int sum = item2.Aggregate(
0, (cnt, elem) => cnt + (Array.BinarySearch(item1, elem) >= 0 ? 1 : 0));
System.Console.WriteLine(sum);
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
| 8
| 194
| 2
|
using System;
using System.Linq;
namespace ALDS1_4_D {
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[] bag = new int[N];
int total = 0;
for (int i = 0; i < N; i++) {
bag[i] = int.Parse(Console.ReadLine());
total += bag[i];
}
int min = total / k;
if (bag.Max() > min)
min = bag.Max() - 1;
int pos = 0;
int contain = 0;
while (total != contain) {
min++;
int[] track = new int[k];
pos = 0;
contain = 0;
for (int i = 0; i < k; i++) {
while (pos < N && track[i] + bag[pos] <= min) {
track[i] += bag[pos];
pos++;
}
contain += track[i];
}
}
Console.WriteLine(min);
}
}
}
|
using System;
using System.Linq;
namespace ALDS1_4_D {
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[] bag = new int[N];
int total = 0;
for (int i = 0; i < N; i++) {
bag[i] = int.Parse(Console.ReadLine());
total += bag[i];
}
int min = total / k - 1;
if (bag.Max() > min)
min = bag.Max() - 1;
int pos = 0;
int contain = 0;
while (total != contain) {
min++;
int[] track = new int[k];
pos = 0;
contain = 0;
for (int i = 0; i < k; i++) {
while (pos < N && track[i] + bag[pos] <= min) {
track[i] += bag[pos];
pos++;
}
contain += track[i];
}
}
Console.WriteLine(min);
}
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 256
| 2
|
using System;
namespace ASDS1_4_wariate_ {
class Program {
class hikkoshi {
public int P;
public int k;
public int[] A;
public hikkoshi(int P, int k, int[] A) {
this.P = P;
this.k = k;
this.A = A;
}
}
static void Main(string[] args) {
var input = getsplit();
int n = getint(input[0]);
int k = getint(input[1]);
var A = new int[n];
int sum = 0;
for (int i = 0; i < n; i++) {
A[i] = getint(Console.ReadLine());
sum += A[i];
}
Console.WriteLine(BinarySearch(sum, k, A));
}
static bool check(hikkoshi a) {
int stack = 0;
int track = 0;
foreach (var s in a.A) {
if (stack + s <= a.P) {
stack += s;
} else {
if (track == a.k - 1) {
return false;
} else {
track++;
stack = s;
}
}
}
return true;
}
static int BinarySearch(int sum, int k, int[] A) {
int left = 0;
int right = sum + 1;
int mid;
while (left < right) {
mid = (left + right) / 2;
hikkoshi Z = new hikkoshi(mid, k, A);
if (check(Z)) {
right = mid;
}
else {
left = mid + 1;
}
}
return right;
}
public static string[] getsplit() {
string[] x = Console.ReadLine().Split(' ');
return x;
}
public static int getint(string a) {
int x = int.Parse(a);
return x;
}
}
}
|
using System;
namespace ASDS1_4_wariate_ {
class Program {
class hikkoshi {
public int P;
public int k;
public int[] A;
public hikkoshi(int P, int k, int[] A) {
this.P = P;
this.k = k;
this.A = A;
}
}
static void Main(string[] args) {
var input = getsplit();
int n = getint(input[0]);
int k = getint(input[1]);
var A = new int[n];
int sum = 0;
for (int i = 0; i < n; i++) {
A[i] = getint(Console.ReadLine());
sum += A[i];
}
Console.WriteLine(BinarySearch(sum, k, A));
}
static bool check(hikkoshi a) {
int stack = 0;
int track = 0;
foreach (var s in a.A) {
if (stack + s <= a.P) {
stack += s;
} else {
if (s > a.P || track == a.k - 1) {
return false;
} else {
track++;
stack = s;
}
}
}
return true;
}
static int BinarySearch(int sum, int k, int[] A) {
int left = 0;
int right = sum + 1;
int mid;
while (left < right) {
mid = (left + right) / 2;
hikkoshi Z = new hikkoshi(mid, k, A);
if (check(Z)) {
right = mid;
}
else {
left = mid + 1;
}
}
return right;
}
public static string[] getsplit() {
string[] x = Console.ReadLine().Split(' ');
return x;
}
public static int getint(string a) {
int x = int.Parse(a);
return x;
}
}
}
|
[["+", 75, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 12, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 16, 12, 214, 141, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 106]]
| 8
| 387
| 6
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace aizu1 {
public class Solution {
public static void Main(string[] args) {
string[] s = Console.ReadLine().Split(' ');
int n = int.Parse(s[0]);
int k = int.Parse(s[1]);
int[] w = new int[n];
int maxWeight = 1;
int left = 0;
int right = 0;
for (int i = 0; i < n; i++) {
w[i] = int.Parse(Console.ReadLine());
right += w[i];
maxWeight = maxWeight > w[i] ? maxWeight : w[i];
}
if (k >= n)
left = maxWeight;
else {
while (left <= right) {
int mid = (left + right) / 2;
int j = 0;
for (int i = 0; i < k; i++) {
int tmp = 0;
while (j < n && tmp + w[j] <= mid) {
j++;
}
}
if (j == n)
right = mid - 1;
else
left = mid + 1;
}
}
Console.WriteLine(left);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace aizu1 {
public class Solution {
public static void Main(string[] args) {
string[] s = Console.ReadLine().Split(' ');
int n = int.Parse(s[0]);
int k = int.Parse(s[1]);
int[] w = new int[n];
int maxWeight = 1;
int left = 0;
int right = 0;
for (int i = 0; i < n; i++) {
w[i] = int.Parse(Console.ReadLine());
right += w[i];
maxWeight = maxWeight > w[i] ? maxWeight : w[i];
}
if (k >= n)
left = maxWeight;
else {
while (left <= right) {
int mid = (left + right) / 2;
int j = 0;
for (int i = 0; i < k; i++) {
int tmp = 0;
while (j < n && (tmp += w[j]) <= mid) {
j++;
}
}
if (j == n)
right = mid - 1;
else
left = mid + 1;
}
}
Console.WriteLine(left);
}
}
}
|
[["+", 0, 52, 15, 16, 12, 16, 31, 23, 0, 24], ["-", 0, 52, 15, 16, 12, 16, 31, 16, 17, 72], ["+", 12, 16, 31, 23, 0, 11, 0, 202, 0, 107], ["+", 0, 52, 15, 16, 12, 16, 31, 23, 0, 25]]
| 8
| 275
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Practice {
class Program {
static void Main(string[] args) {
SolveA(args);
// SolveB(args);
// SolveC(args);
// SolveD(args);
}
private static int s_compareTotal = 0;
static void SolveA(string[] args) {
int.Parse(Console.ReadLine());
int[] s = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
MergeSort(s, 0, s.Length);
// Console.WriteLine(string.Join(" ", Array.ConvertAll(s,
// a=>a.ToString())));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.Length; ++i) {
sb.Append(s[i]);
if (i != sb.Length - 1)
sb.Append(" ");
}
Console.WriteLine(sb.ToString());
Console.WriteLine(s_compareTotal);
}
static void Merge(int[] a, int left, int mid, int right) {
int n1 = mid - left;
int n2 = right - mid;
int[] L = new int[n1 + 1];
int[] R = new int[n2 + 1];
for (int i = 0; i < n1; ++i) {
L[i] = a[left + i];
}
for (int i = 0; i < n2; ++i) {
R[i] = a[mid + i];
}
L[n1] = int.MaxValue;
R[n2] = int.MaxValue;
{
int i = 0;
int j = 0;
for (int k = left; k < right; ++k) {
s_compareTotal++;
if (L[i] <= R[j]) {
a[k] = L[i];
i = i + 1;
} else {
a[k] = R[j];
j = j + 1;
}
}
}
}
static void MergeSort(int[] a, int left, int right) {
if (left + 1 < right) {
int mid = (left + right) / 2;
MergeSort(a, left, mid);
MergeSort(a, mid, right);
Merge(a, left, mid, right);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Practice {
class Program {
static void Main(string[] args) {
SolveA(args);
// SolveB(args);
// SolveC(args);
// SolveD(args);
}
private static int s_compareTotal = 0;
static void SolveA(string[] args) {
int.Parse(Console.ReadLine());
int[] s = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
MergeSort(s, 0, s.Length);
// Console.WriteLine(string.Join(" ", Array.ConvertAll(s,
// a=>a.ToString())));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.Length; ++i) {
sb.Append(s[i]);
if (i != s.Length - 1) {
sb.Append(" ");
}
}
Console.WriteLine(sb.ToString());
Console.WriteLine(s_compareTotal);
}
static void Merge(int[] a, int left, int mid, int right) {
int n1 = mid - left;
int n2 = right - mid;
int[] L = new int[n1 + 1];
int[] R = new int[n2 + 1];
for (int i = 0; i < n1; ++i) {
L[i] = a[left + i];
}
for (int i = 0; i < n2; ++i) {
R[i] = a[mid + i];
}
L[n1] = int.MaxValue;
R[n2] = int.MaxValue;
{
int i = 0;
int j = 0;
for (int k = left; k < right; ++k) {
s_compareTotal++;
if (L[i] <= R[j]) {
a[k] = L[i];
i = i + 1;
} else {
a[k] = R[j];
j = j + 1;
}
}
}
}
static void MergeSort(int[] a, int left, int right) {
if (left + 1 < right) {
int mid = (left + right) / 2;
MergeSort(a, left, mid);
MergeSort(a, mid, right);
Merge(a, left, mid, right);
}
}
}
}
|
[["-", 0, 57, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 470
| 4
|
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
int[] S =
Console.ReadLine().Split(' ').Select(val => int.Parse(val)).ToArray();
Sort.MergeSort(ref S, 0, n);
for (int i = 0; i < n; i++) {
if (i != 0)
Console.Write(" ");
Console.Write(S[i]);
}
Console.WriteLine("\n{0}", Sort.cnt);
}
}
class Sort {
public static int cnt = 0;
public static void Merge(ref int[] A, int left, int mid, int right) {
// Console.Error.WriteLine("left: {0}, mid: {1}, right: {2}", left, mid,
// right);
cnt++;
int n1 = mid - left;
int n2 = right - mid;
// Console.Error.WriteLine("n1:{0}, n2:{1}", n1, n2);
int[] L = new int[n1 + 1];
Array.Copy(A, left, L, 0, n1);
L[n1] = int.MaxValue;
// Console.Error.WriteLine("L: {0}", string.Join(" ", L));
int[] R = new int[n2 + 1];
Array.Copy(A, mid, R, 0, n2);
R[n2] = int.MaxValue;
// Console.Error.WriteLine("R: {0}", string.Join(" ", R));
int i = 0, j = 0;
for (int k = left; k < right; k++) {
// Console.Error.WriteLine("L[i]:{0}, R[j]: {1}", L[i], R[j]);
if (L[i] <= R[j]) {
A[k] = L[i];
i++;
} else {
A[k] = R[j];
j++;
}
// Console.Error.WriteLine("A[{0}] = {1}", k, A[k]);
}
// Console.Error.WriteLine(string.Join(" ", A));
}
public static void MergeSort(ref int[] A, int left, int right) {
if (left + 1 < right) {
int mid = (left + right) / 2;
MergeSort(ref A, left, mid);
MergeSort(ref A, mid, right);
Merge(ref A, left, mid, right);
}
}
}
|
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
int[] S =
Console.ReadLine().Split(' ').Select(val => int.Parse(val)).ToArray();
Sort.MergeSort(ref S, 0, n);
for (int i = 0; i < n; i++) {
if (i != 0)
Console.Write(" ");
Console.Write(S[i]);
}
Console.WriteLine("\n{0}", Sort.cnt);
}
}
class Sort {
public static int cnt = 0;
public static void Merge(ref int[] A, int left, int mid, int right) {
// Console.Error.WriteLine("left: {0}, mid: {1}, right: {2}", left, mid,
// right);
int n1 = mid - left;
int n2 = right - mid;
// Console.Error.WriteLine("n1:{0}, n2:{1}", n1, n2);
int[] L = new int[n1 + 1];
Array.Copy(A, left, L, 0, n1);
L[n1] = int.MaxValue;
// Console.Error.WriteLine("L: {0}", string.Join(" ", L));
int[] R = new int[n2 + 1];
Array.Copy(A, mid, R, 0, n2);
R[n2] = int.MaxValue;
// Console.Error.WriteLine("R: {0}", string.Join(" ", R));
int i = 0, j = 0;
for (int k = left; k < right; k++) {
cnt++;
// Console.Error.WriteLine("L[i]:{0}, R[j]: {1}", L[i], R[j]);
if (L[i] <= R[j]) {
A[k] = L[i];
i++;
} else {
A[k] = R[j];
j++;
}
// Console.Error.WriteLine("A[{0}] = {1}", k, A[k]);
}
// Console.Error.WriteLine(string.Join(" ", A));
}
public static void MergeSort(ref int[] A, int left, int right) {
if (left + 1 < right) {
int mid = (left + right) / 2;
MergeSort(ref A, left, mid);
MergeSort(ref A, mid, right);
Merge(ref A, left, mid, right);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 428
| 6
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
public void Proc() {
int procCnt = int.Parse(Console.ReadLine());
PPoint a = new PPoint(0, 0);
PPoint b = new PPoint(100, 0);
Console.WriteLine(a.X.ToString("0.00000000") + " " +
a.Y.ToString("0.00000000"));
this.Koch(procCnt, a, b);
Console.WriteLine(b.X.ToString("0.00000000") + " " +
b.Y.ToString("0.00000000"));
}
public void Koch(int depth, PPoint p1, PPoint p2) {
if (depth == 0) {
return;
}
PPoint s = new PPoint(0, 0);
PPoint t = new PPoint(0, 0);
PPoint u = new PPoint(0, 0);
double th = Math.PI * 60d / 180d;
s.X = (2 * p1.X + 1 * p2.X) / 3d;
s.Y = (2 * p1.Y + 1 * p2.Y) / 3d;
t.X = (1 * p1.X + 2 * p2.X) / 3d;
t.Y = (1 * p1.Y + 2 * p2.Y) / 3d;
u.X = (t.X - s.X) * Math.Cos(th) - (t.Y - s.Y) * Math.Sin(th) + s.X;
u.Y = (t.X - s.X) * Math.Sin(th) - (t.Y - s.Y) * Math.Cos(th) + s.Y;
Koch(depth - 1, p1, s);
Console.WriteLine(s.X.ToString("0.00000000") + " " +
s.Y.ToString("0.00000000"));
Koch(depth - 1, s, u);
Console.WriteLine(u.X.ToString("0.00000000") + " " +
u.Y.ToString("0.00000000"));
Koch(depth - 1, u, t);
Console.WriteLine(t.X.ToString("0.00000000") + " " +
t.Y.ToString("0.00000000"));
Koch(depth - 1, t, p2);
}
public class PPoint {
public double X = 0;
public double Y = 0;
public PPoint(double x, double y) {
this.X = x;
this.Y = y;
}
}
static void Main(string[] args)
{
Program prg = new Program();
prg.Proc();
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
public void Proc() {
int procCnt = int.Parse(Console.ReadLine());
PPoint a = new PPoint(0, 0);
PPoint b = new PPoint(100, 0);
Console.WriteLine(a.X.ToString("0.00000000") + " " +
a.Y.ToString("0.00000000"));
this.Koch(procCnt, a, b);
Console.WriteLine(b.X.ToString("0.00000000") + " " +
b.Y.ToString("0.00000000"));
}
public void Koch(int depth, PPoint p1, PPoint p2) {
if (depth == 0) {
return;
}
PPoint s = new PPoint(0, 0);
PPoint t = new PPoint(0, 0);
PPoint u = new PPoint(0, 0);
double th = Math.PI / 3;
s.X = (2 * p1.X + 1 * p2.X) / 3d;
s.Y = (2 * p1.Y + 1 * p2.Y) / 3d;
t.X = (1 * p1.X + 2 * p2.X) / 3d;
t.Y = (1 * p1.Y + 2 * p2.Y) / 3d;
u.X = (t.X - s.X) * Math.Cos(th) - (t.Y - s.Y) * Math.Sin(th) + s.X;
u.Y = (t.X - s.X) * Math.Sin(th) + (t.Y - s.Y) * Math.Cos(th) + s.Y;
Koch(depth - 1, p1, s);
Console.WriteLine(s.X.ToString("0.00000000") + " " +
s.Y.ToString("0.00000000"));
Koch(depth - 1, s, u);
Console.WriteLine(u.X.ToString("0.00000000") + " " +
u.Y.ToString("0.00000000"));
Koch(depth - 1, u, t);
Console.WriteLine(t.X.ToString("0.00000000") + " " +
t.Y.ToString("0.00000000"));
Koch(depth - 1, t, p2);
}
public class PPoint {
public double X = 0;
public double Y = 0;
public PPoint(double x, double y) {
this.X = x;
this.Y = y;
}
}
static void Main(string[] args)
{
Program prg = new Program();
prg.Proc();
}
}
|
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 250], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 250], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 72]]
| 8
| 570
| 6
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace aizu1 {
public class Solution {
static double cos = Math.Cos(60 * Math.PI / 180);
static double sin = Math.Sin(60 * Math.PI / 180);
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
curve kochCurve = new curve();
Console.WriteLine(kochCurve.kochCurving(n));
}
public class curve {
List<Point> list = new List<Point>();
public curve() {
list.Add(new Point { x = 0, y = 0 });
list.Add(new Point { x = 100, y = 0 });
}
public string kochCurving(int n) {
string res = "";
for (int i = 0; i < n; i++) {
for (int j = 0; j < list.Count() - 1; j++) {
Point p1 = list[j], p2 = list[j + 1];
divide(p1, p2, j);
getTraiangle(list[j + 1], list[j + 2], j + 1);
j += 3;
}
}
foreach (var p in list) {
res += p.ToString() + "/n";
}
return res;
}
public void divide(Point p1, Point p2, int index) {
list.Insert(index + 1, p1.getTriplePoint(p2));
list.Insert(index + 2, p2.getTriplePoint(p1));
}
public void getTraiangle(Point p1, Point p2, int index) {
list.Insert(index + 1, p1.getTrianglePoint(p2));
}
public class Point {
public double x { get; set; }
public double y { get; set; }
public Point getTriplePoint(Point other) {
double tmpX = x * 2 / 3 + other.x * 1 / 3;
double tmpY = y * 2 / 3 + other.y * 1 / 3;
return new Point { x = tmpX, y = tmpY };
}
public Point getTrianglePoint(Point other) {
return new Point { x = x + cos * (other.x - x) - sin * (other.y - y),
y = y + sin * (other.x - x) + cos * (other.y - y) };
}
public override string ToString() {
return string.Format("{0:F8} {1:F8}", x, y);
}
}
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace aizu1 {
public class Solution {
static double cos = Math.Cos(60 * Math.PI / 180);
static double sin = Math.Sin(60 * Math.PI / 180);
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
curve kochCurve = new curve();
Console.Write(kochCurve.kochCurving(n));
}
public class curve {
List<Point> list = new List<Point>();
public curve() {
list.Add(new Point { x = 0, y = 0 });
list.Add(new Point { x = 100, y = 0 });
}
public string kochCurving(int n) {
string res = "";
for (int i = 0; i < n; i++) {
for (int j = 0; j < list.Count() - 1; j++) {
Point p1 = list[j], p2 = list[j + 1];
divide(p1, p2, j);
getTraiangle(list[j + 1], list[j + 2], j + 1);
j += 3;
}
}
foreach (var p in list) {
res += p.ToString() + "\n";
}
return res;
}
public void divide(Point p1, Point p2, int index) {
list.Insert(index + 1, p1.getTriplePoint(p2));
list.Insert(index + 2, p2.getTriplePoint(p1));
}
public void getTraiangle(Point p1, Point p2, int index) {
list.Insert(index + 1, p1.getTrianglePoint(p2));
}
public class Point {
public double x { get; set; }
public double y { get; set; }
public Point getTriplePoint(Point other) {
double tmpX = x * 2 / 3 + other.x * 1 / 3;
double tmpY = y * 2 / 3 + other.y * 1 / 3;
return new Point { x = tmpX, y = tmpY };
}
public Point getTrianglePoint(Point other) {
return new Point { x = x + cos * (other.x - x) - sin * (other.y - y),
y = y + sin * (other.x - x) + cos * (other.y - y) };
}
public override string ToString() {
return string.Format("{0:F8} {1:F8}", x, y);
}
}
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 16, 12, 5, 0, 222], ["+", 0, 1, 0, 11, 12, 16, 12, 5, 0, 44]]
| 8
| 542
| 4
|
using System;
class Program {
static void CountingSort(int[] A, int[] B, int k) {
var C = new int[k + 1];
for (var j = 0; j < A.Length; j++) {
C[A[j]]++;
}
var remain = B.Length - 1;
for (; k >= 0; k--) {
while (C[k] > 0) {
B[remain] = k;
remain--;
C[k]--;
}
}
}
public static void Main() {
var n = int.Parse(Console.ReadLine());
var s = Console.ReadLine().Split(' ');
var A = new int[n];
var k = -1;
for (var i = 0; i < n; i++) {
A[i] = int.Parse(s[i]);
if (A[i] > k) {
k = A[i];
}
}
var B = new int[n];
CountingSort(A, B, k);
/*
for(var i=0; i<B.Length; i++){
Console.Write(B[i]);
if(i>=B.Length-1){
Console.WriteLine();
} else{
Console.Write(" ");
}
}
*/
var ss = new System.Text.StringBuilder();
for (var i = 0; i < B.Length; i++) {
ss.Append(B[i]);
if (i != 0) {
ss.Append(" ");
}
}
Console.WriteLine(ss);
}
}
|
using System;
class Program {
static void CountingSort(int[] A, int[] B, int k) {
var C = new int[k + 1];
for (var j = 0; j < A.Length; j++) {
C[A[j]]++;
}
var remain = B.Length - 1;
for (; k >= 0; k--) {
while (C[k] > 0) {
B[remain] = k;
remain--;
C[k]--;
}
}
}
public static void Main() {
var n = int.Parse(Console.ReadLine());
var s = Console.ReadLine().Split(' ');
var A = new int[n];
var k = -1;
for (var i = 0; i < n; i++) {
A[i] = int.Parse(s[i]);
if (A[i] > k) {
k = A[i];
}
}
var B = new int[n];
CountingSort(A, B, k);
/*
for(var i=0; i<B.Length; i++){
Console.Write(B[i]);
if(i>=B.Length-1){
Console.WriteLine();
} else{
Console.Write(" ");
}
}
*/
var ss = new System.Text.StringBuilder();
for (var i = 0; i < B.Length; i++) {
ss.Append(B[i]);
if (i < B.Length - 1) {
ss.Append(" ");
}
}
Console.WriteLine(ss);
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 297
| 8
|
using System;
using System.Linq;
using System.Text;
namespace ALDS1_6_A {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split(' ');
int[] A = new int[n + 1];
int[] B = new int[n + 1];
int[] C = new int[10001];
for (int i = 1; i <= n; i++) {
int temp = int.Parse(input[i - 1]);
A[i] = temp;
C[temp]++;
}
for (int i = 1; i < 10001; i++) {
C[i] += C[i - 1];
}
for (int i = n - 1; i >= 0; i--) {
int temp = A[i];
B[C[temp]] = temp;
C[temp]--;
}
StringBuilder sb = new StringBuilder();
foreach (int b in B.Skip(1))
sb.AppendFormat(" {0}", b);
Console.WriteLine(sb.ToString().TrimStart());
}
}
}
|
using System;
using System.Linq;
using System.Text;
namespace ALDS1_6_A {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split(' ');
int[] A = new int[n + 1];
int[] B = new int[n + 1];
int[] C = new int[10001];
for (int i = 1; i <= n; i++) {
int temp = int.Parse(input[i - 1]);
A[i] = temp;
C[temp]++;
}
for (int i = 1; i < 10001; i++) {
C[i] += C[i - 1];
}
for (int i = n; i > 0; i--) {
int temp = A[i];
B[C[temp]] = temp;
C[temp]--;
}
StringBuilder sb = new StringBuilder();
foreach (int b in B.Skip(1))
sb.AppendFormat(" {0}", b);
Console.WriteLine(sb.ToString().TrimStart());
}
}
}
|
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47]]
| 8
| 261
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static string ReadLine() { return Console.ReadLine(); }
static int ReadInt() { return int.Parse(ReadLine()); }
static int[] ReadInts() {
return ReadLine().Split().Select(int.Parse).ToArray();
}
static string[] ReadStrings() { return ReadLine().Split(); }
static void Swap(ref int a, ref int b) {
var t = a;
a = b;
b = t;
}
static int Partition(int[] xs) {
int n = xs.Length;
int pibot = xs[n - 1];
int less = 0; // pibot ??\????????????????´?????????????
for (int i = 0; i < n - 1; i++) {
if (xs[i] < pibot) {
Swap(ref xs[less], ref xs[i]);
less++;
}
}
// pibot ??????????????????
Swap(ref xs[less], ref xs[n - 1]);
return less;
}
static void Main() {
ReadInt();
var xs = ReadInts();
int p = Partition(xs);
var ys =
xs.Select((e, i) => i == p ? "[" + e.ToString() + "]" : e.ToString())
.ToArray();
Console.WriteLine(string.Join(" ", ys));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static string ReadLine() { return Console.ReadLine(); }
static int ReadInt() { return int.Parse(ReadLine()); }
static int[] ReadInts() {
return ReadLine().Split().Select(int.Parse).ToArray();
}
static string[] ReadStrings() { return ReadLine().Split(); }
static void Swap(ref int a, ref int b) {
var t = a;
a = b;
b = t;
}
static int Partition(int[] xs) {
int n = xs.Length;
int pibot = xs[n - 1];
int less = 0; // pibot ??\????????????????´?????????????
for (int i = 0; i < n - 1; i++) {
if (xs[i] <= pibot) {
Swap(ref xs[less], ref xs[i]);
less++;
}
}
// pibot ??????????????????
Swap(ref xs[less], ref xs[n - 1]);
return less;
}
static void Main() {
ReadInt();
var xs = ReadInts();
int p = Partition(xs);
var ys =
xs.Select((e, i) => i == p ? "[" + e.ToString() + "]" : e.ToString())
.ToArray();
Console.WriteLine(string.Join(" ", ys));
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 310
| 2
|
// Partition.cs
using System;
class Partition {
public static void Main() {
int n = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split(' ');
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(str[i]);
}
int r = a[a.Length - 1], p = 0, q = 0, swap;
for (int i = 0; i < n; i++) {
if (r >= a[i]) {
swap = a[p];
a[p] = a[i];
a[q] = swap;
p++;
q++;
} else if (i == n - 1) {
swap = a[p];
a[p] = a[i];
a[n - 1] = swap;
} else {
a[q] = a[i];
q++;
}
}
for (int i = 0; i < n; i++) {
if (a[i] == r) {
Console.Write("[" + a[i] + "] ");
} else if (i != n - 1) {
Console.Write(a[i] + " ");
} else {
Console.WriteLine(a[i]);
}
}
}
}
|
// Partition.cs
using System;
class Partition {
public static void Main() {
int n = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split(' ');
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(str[i]);
}
int r = a[a.Length - 1], p = 0, q = 0, swap;
for (int i = 0; i < n; i++) {
if (r >= a[i]) {
swap = a[p];
a[p] = a[i];
a[q] = swap;
p++;
q++;
} else if (i == n - 1) {
swap = a[p];
a[p] = a[i];
a[n - 1] = swap;
} else {
a[q] = a[i];
q++;
}
}
for (int i = 0; i < n; i++) {
if (a[i] == r && p - 1 == i) {
Console.Write("[" + a[i] + "] ");
} else if (i != n - 1) {
Console.Write(a[i] + " ");
} else {
Console.WriteLine(a[i]);
}
}
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 305
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Satoshi {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(s[i]);
}
int q = Partition(a, 0, n - 1);
var sb = new StringBuilder();
for (int i = 0; i < n; i++) {
if (i == q) {
sb.Append("[");
}
sb.Append(a[i]);
if (i == q) {
sb.Append("]");
}
if (i != q)
sb.Append(" ");
}
string ans = sb.ToString();
Console.WriteLine(ans);
}
public static int Partition(int[] a, int p, int r) {
int x = a[r];
int i = p - 1;
for (int j = p; j < r; j++) {
if (a[j] <= x) {
i++;
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
int temp = a[i + 1];
a[i + 1] = a[r];
a[r] = temp;
return i + 1;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Satoshi {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(s[i]);
}
int q = Partition(a, 0, n - 1);
var sb = new StringBuilder();
for (int i = 0; i < n; i++) {
if (i == q) {
sb.Append("[");
}
sb.Append(a[i]);
if (i == q) {
sb.Append("]");
}
if (i != n - 1)
sb.Append(" ");
}
string ans = sb.ToString();
Console.WriteLine(ans);
}
public static int Partition(int[] a, int p, int r) {
int x = a[r];
int i = p - 1;
for (int j = p; j < r; j++) {
if (a[j] <= x) {
i++;
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
int temp = a[i + 1];
a[i + 1] = a[r];
a[r] = temp;
return i + 1;
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 348
| 4
|
using System;
namespace ALDS1_6_B {
static class Swapper {
public static void Integer(ref int a, ref int b) {
if (a == b)
return;
a ^= b;
b ^= a;
a ^= b;
}
}
static class Algorithm {
public delegate void SwapperAction<T>(ref T a, ref T b);
public static int Partition<T>(T[] a, int s, int t, SwapperAction<T> swapper)
where T : IComparable {
int p = s;
T x = a[t];
for (int i = s; i < t; ++i) {
if (a[i].CompareTo(x) < 0)
swapper.Invoke(ref a[p++], ref a[i]);
}
swapper.Invoke(ref a[p], ref a[t]);
return p;
}
}
class Program {
static void Main(string[] args) {
Console.ReadLine();
var a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int q = Algorithm.Partition(a, 0, a.Length - 1, Swapper.Integer);
var strs = Array.ConvertAll(a, (s) => s.ToString());
strs[q] = '[' + strs[q] + ']';
Console.WriteLine(string.Join(" ", strs));
}
}
}
|
using System;
namespace ALDS1_6_B {
static class Swapper {
public static void Integer(ref int a, ref int b) {
if (a == b)
return;
a ^= b;
b ^= a;
a ^= b;
}
}
static class Algorithm {
public delegate void SwapperAction<T>(ref T a, ref T b);
public static int Partition<T>(T[] a, int s, int t, SwapperAction<T> swapper)
where T : IComparable {
int p = s;
T x = a[t];
for (int i = s; i < t; ++i) {
if (a[i].CompareTo(x) <= 0)
swapper.Invoke(ref a[p++], ref a[i]);
}
swapper.Invoke(ref a[p], ref a[t]);
return p;
}
}
class Program {
static void Main(string[] args) {
Console.ReadLine();
var a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int q = Algorithm.Partition(a, 0, a.Length - 1, Swapper.Integer);
var strs = Array.ConvertAll(a, (s) => s.ToString());
strs[q] = '[' + strs[q] + ']';
Console.WriteLine(string.Join(" ", strs));
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 303
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Program().Solve();
Console.Out.Flush();
}
Scanner cin = new Scanner();
void Solve() {
var T = new Two_D(1000, 1000);
int N = cin.Nextint;
for (int i = 0; i < N; i++) {
var c = cin.Scanint;
T.imos(c[0], c[1], c[2], c[3]);
}
T.build();
long ans = 0;
for (int i = 0; i < T.H; i++) {
for (int j = 0; j < T.W; j++) {
ans = Math.Max(ans, T.D[i, j]);
}
}
Console.WriteLine(ans);
}
}
class Two_D {
public long[,] D;
public int H;
public int W;
public Two_D(int H, int W) {
this.H = H + 10;
this.W = W + 10;
D = new long[this.H, this.W];
}
public void build() {
for (int i = 0; i < H; i++) {
for (int j = 1; j < W; j++) {
D[i, j] += D[i, j - 1];
}
}
for (int i = 1; i < H; i++) {
for (int j = 0; j < W; j++) {
D[i, j] += D[i - 1, j];
}
}
}
public void imos(int min_y, int min_x, int max_y, int max_x) {
D[min_y, min_x]++;
D[min_y, max_x + 1]--;
D[max_y + 1, min_x]--;
D[max_y + 1, max_x + 1]++;
}
// sum [(min_y, min_x), (max_y, max_x)]
public long query(int min_y, int min_x, int max_y, int max_x) {
long ret = D[max_y, max_x];
if (min_y > 0)
ret -= D[min_y - 1, max_x];
if (min_x > 0)
ret -= D[max_y, min_x - 1];
if (min_y > 0 && min_x > 0)
ret += D[min_y - 1, min_x - 1];
return ret;
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] Scan {
get { return Console.ReadLine().Split(); }
}
public int[] Scanint {
get { return Array.ConvertAll(Scan, int.Parse); }
}
public long[] Scanlong {
get { return Array.ConvertAll(Scan, long.Parse); }
}
public double[] Scandouble {
get { return Array.ConvertAll(Scan, double.Parse); }
}
public string Next {
get {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return Next;
}
}
public int Nextint {
get { return int.Parse(Next); }
}
public long Nextlong {
get { return long.Parse(Next); }
}
public double Nextdouble {
get { return double.Parse(Next); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Program().Solve();
Console.Out.Flush();
}
Scanner cin = new Scanner();
void Solve() {
var T = new Two_D(1000, 1000);
int N = cin.Nextint;
for (int i = 0; i < N; i++) {
var c = cin.Scanint;
T.imos(c[0], c[1], c[2] - 1, c[3] - 1);
}
T.build();
long ans = 0;
for (int i = 0; i < T.H; i++) {
for (int j = 0; j < T.W; j++) {
ans = Math.Max(ans, T.D[i, j]);
}
}
Console.WriteLine(ans);
}
}
class Two_D {
public long[,] D;
public int H;
public int W;
public Two_D(int H, int W) {
this.H = H + 10;
this.W = W + 10;
D = new long[this.H, this.W];
}
public void build() {
for (int i = 0; i < H; i++) {
for (int j = 1; j < W; j++) {
D[i, j] += D[i, j - 1];
}
}
for (int i = 1; i < H; i++) {
for (int j = 0; j < W; j++) {
D[i, j] += D[i - 1, j];
}
}
}
public void imos(int min_y, int min_x, int max_y, int max_x) {
D[min_y, min_x]++;
D[min_y, max_x + 1]--;
D[max_y + 1, min_x]--;
D[max_y + 1, max_x + 1]++;
}
// sum [(min_y, min_x), (max_y, max_x)]
public long query(int min_y, int min_x, int max_y, int max_x) {
long ret = D[max_y, max_x];
if (min_y > 0)
ret -= D[min_y - 1, max_x];
if (min_x > 0)
ret -= D[max_y, min_x - 1];
if (min_y > 0 && min_x > 0)
ret += D[min_y - 1, min_x - 1];
return ret;
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] Scan {
get { return Console.ReadLine().Split(); }
}
public int[] Scanint {
get { return Array.ConvertAll(Scan, int.Parse); }
}
public long[] Scanlong {
get { return Array.ConvertAll(Scan, long.Parse); }
}
public double[] Scandouble {
get { return Array.ConvertAll(Scan, double.Parse); }
}
public string Next {
get {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return Next;
}
}
public int Nextint {
get { return int.Parse(Next); }
}
public long Nextlong {
get { return long.Parse(Next); }
}
public double Nextdouble {
get { return double.Parse(Next); }
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 803
| 4
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
public Solve() {}
StringBuilder sb;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
string[] str = Console.ReadLine().Split(' ');
int v = int.Parse(str[0]);
int e = int.Parse(str[1]);
int r = int.Parse(str[2]);
int[] f = new int[e];
int[] t = new int[e];
long[] cost = new long[e];
for (int i = 0; i < e; i++) {
str = Console.ReadLine().Split(' ');
f[i] = int.Parse(str[0]);
t[i] = int.Parse(str[1]);
cost[i] = int.Parse(str[2]);
}
Dijkstra D = new Dijkstra(f, t, cost, v, r);
for (int i = 0; i < v; i++) {
sb.Append(D.GetCost(i) == -1 ? "INF\n" : (D.GetCost(i) + "\n"));
}
}
}
struct Edge {
public Vertex v;
public long cost;
public Edge(Vertex v0, long c) {
v = v0;
cost = c;
}
}
class Vertex {
public bool finished;
public List<Vertex> edges;
public List<long> costs;
public long cost;
public void AddEdge(Vertex v, long c) {
edges.Add(v);
costs.Add(c);
}
public Vertex() {
edges = new List<Vertex>();
costs = new List<long>();
cost = -1;
finished = false;
}
}
class Dijkstra {
int E;
Vertex[] point;
Vertex S;
public long GetCost(int i) { return point[i].cost; }
public Dijkstra(int[] f, int[] t, long[] cost, int n, int s) {
point = new Vertex[n];
for (int i = 0; i < n; i++) {
point[i] = new Vertex();
}
E = f.Length;
for (int i = 0; i < E; i++) {
point[f[i]].AddEdge(point[t[i]], cost[i]);
}
S = point[s];
calc();
}
void calc() {
Heap H = new Heap(2 * E);
S.cost = 0;
H.push(new Edge(S, 0));
while (!H.Empty()) {
Vertex v = H.pop().v;
if (v.finished) {
continue;
}
v.finished = true;
for (int i = 0; i < v.edges.Count; i++) {
Vertex vi = v.edges[i];
if (vi.cost == -1 || vi.cost > v.costs[i] + v.cost) {
vi.cost = v.costs[i] + v.cost;
H.push(new Edge(vi, vi.cost));
}
}
}
}
}
class Heap {
public int size;
Edge[] obj;
public Heap(int maxsize) {
size = 0;
obj = new Edge[maxsize];
}
public void push(Edge a) {
int i = size;
size++;
while (i > 0) {
int p = (i - 1) / 2;
if (obj[p].cost <= a.cost) {
obj[i] = a;
break;
}
obj[i] = obj[p];
i = p;
}
if (i == 0) {
obj[0] = a;
}
}
public bool Empty() { return size == 0; }
public Edge pop() {
Edge t = obj[0];
int i = 0;
size--;
while (2 * i + 1 < size) {
int p = 2 * i + 1;
if (p + 1 < size && obj[p + 1].cost < obj[p].cost) {
p++;
}
if (obj[p].cost < obj[size].cost) {
obj[i] = obj[p];
i = p;
} else {
obj[i] = obj[size];
break;
}
}
if (2 * i + 1 >= size) {
obj[i] = obj[size];
}
return t;
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
public Solve() {}
StringBuilder sb;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
string[] str = Console.ReadLine().Split(' ');
int v = int.Parse(str[0]);
int e = int.Parse(str[1]);
int r = int.Parse(str[2]);
int[] f = new int[e];
int[] t = new int[e];
long[] cost = new long[e];
for (int i = 0; i < e; i++) {
str = Console.ReadLine().Split(' ');
f[i] = int.Parse(str[0]);
t[i] = int.Parse(str[1]);
cost[i] = int.Parse(str[2]);
}
Dijkstra D = new Dijkstra(f, t, cost, v, r);
for (int i = 0; i < v; i++) {
sb.Append(D.GetCost(i) == -1 ? "INF\n" : (D.GetCost(i) + "\n"));
}
}
}
struct Edge {
public Vertex v;
public long cost;
public Edge(Vertex v0, long c) {
v = v0;
cost = c;
}
}
class Vertex {
public bool finished;
public List<Vertex> edges;
public List<long> costs;
public long cost;
public void AddEdge(Vertex v, long c) {
edges.Add(v);
costs.Add(c);
}
public Vertex() {
edges = new List<Vertex>();
costs = new List<long>();
cost = -1;
finished = false;
}
}
class Dijkstra {
int E;
Vertex[] point;
Vertex S;
public long GetCost(int i) { return point[i].cost; }
public Dijkstra(int[] f, int[] t, long[] cost, int n, int s) {
point = new Vertex[n];
for (int i = 0; i < n; i++) {
point[i] = new Vertex();
}
E = f.Length;
for (int i = 0; i < E; i++) {
point[f[i]].AddEdge(point[t[i]], cost[i]);
}
S = point[s];
calc();
}
void calc() {
Heap H = new Heap(2 * E + 1);
S.cost = 0;
H.push(new Edge(S, 0));
while (!H.Empty()) {
Vertex v = H.pop().v;
if (v.finished) {
continue;
}
v.finished = true;
for (int i = 0; i < v.edges.Count; i++) {
Vertex vi = v.edges[i];
if (vi.cost == -1 || vi.cost > v.costs[i] + v.cost) {
vi.cost = v.costs[i] + v.cost;
H.push(new Edge(vi, vi.cost));
}
}
}
}
}
class Heap {
public int size;
Edge[] obj;
public Heap(int maxsize) {
size = 0;
obj = new Edge[maxsize];
}
public void push(Edge a) {
int i = size;
size++;
while (i > 0) {
int p = (i - 1) / 2;
if (obj[p].cost <= a.cost) {
obj[i] = a;
break;
}
obj[i] = obj[p];
i = p;
}
if (i == 0) {
obj[0] = a;
}
}
public bool Empty() { return size == 0; }
public Edge pop() {
Edge t = obj[0];
int i = 0;
size--;
while (2 * i + 1 < size) {
int p = 2 * i + 1;
if (p + 1 < size && obj[p + 1].cost < obj[p].cost) {
p++;
}
if (obj[p].cost < obj[size].cost) {
obj[i] = obj[p];
i = p;
} else {
obj[i] = obj[size];
break;
}
}
if (2 * i + 1 >= size) {
obj[i] = obj[size];
}
return t;
}
}
|
[["+", 0, 230, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 230, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 1,025
| 2
|
using System.Collections.Generic;
using System.Linq;
using System;
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;
}
}
public class Edge : IComparable {
public int to { get; set; }
public int d { get; set; }
public int CompareTo(object obj) {
var x = (Edge)obj;
return this.d - x.d;
}
}
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var n = int.Parse(line[0]);
var m = int.Parse(line[1]);
var r = new List<Edge>[n];
var minc = new int[n];
for (int i = 0; i < n; i++)
minc[i] = -1;
for (int i = 0; i < n; i++)
r[i] = new List<Edge>();
for (int i = 0; i < m; i++) {
string[] line2 = Console.ReadLine().Trim().Split(' ');
var a = int.Parse(line2[0]);
var b = int.Parse(line2[1]);
var d = int.Parse(line2[2]);
r[a].Add(new Edge { to = b, d = d });
r[b].Add(new Edge { to = a, d = d });
}
goPrim(r, minc, 0, m);
Console.WriteLine(minc.Sum());
}
public static void goPrim(List<Edge>[] r, int[] minc, int targ, int m) {
var pq = new PriorityQueue<Edge>(m * 2 + 10000);
var n = minc.Length;
var count = 1;
minc[targ] = 0;
foreach (var x in r[targ])
pq.Push(x);
while (count++ < n) {
var e = pq.Pop();
if (minc[e.to] == -1) {
minc[e.to] = e.d;
foreach (var x in r[e.to])
if (minc[x.to] == -1)
pq.Push(x);
}
}
}
}
|
using System.Collections.Generic;
using System.Linq;
using System;
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;
}
}
public class Edge : IComparable {
public int to { get; set; }
public int d { get; set; }
public int CompareTo(object obj) {
var x = (Edge)obj;
return this.d - x.d;
}
}
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var n = int.Parse(line[0]);
var m = int.Parse(line[1]);
var r = new List<Edge>[n];
var minc = new int[n];
for (int i = 0; i < n; i++)
minc[i] = -1;
for (int i = 0; i < n; i++)
r[i] = new List<Edge>();
for (int i = 0; i < m; i++) {
string[] line2 = Console.ReadLine().Trim().Split(' ');
var a = int.Parse(line2[0]);
var b = int.Parse(line2[1]);
var d = int.Parse(line2[2]);
r[a].Add(new Edge { to = b, d = d });
r[b].Add(new Edge { to = a, d = d });
}
goPrim(r, minc, 0, m);
Console.WriteLine(minc.Sum());
}
public static void goPrim(List<Edge>[] r, int[] minc, int targ, int m) {
var pq = new PriorityQueue<Edge>(m * 2 + 10000);
var n = minc.Length;
var count = 1;
minc[targ] = 0;
foreach (var x in r[targ])
pq.Push(x);
while (count < n) {
var e = pq.Pop();
if (minc[e.to] == -1) {
minc[e.to] = e.d;
count++;
foreach (var x in r[e.to])
if (minc[x.to] == -1)
pq.Push(x);
}
}
}
}
|
[["-", 8, 196, 0, 52, 15, 16, 31, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29]]
| 8
| 1,039
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ITP1_10_A {
public class Program
{
public static void Main(string[] args) {
int[] line = ReadIntAr();
Console.WriteLine("{0}", Math.Sqrt(Math.Pow((line[2] - line[0]), 2) +
Math.Pow((line[3] - line[1]), 2)));
}
static string ReadSt() { return Console.ReadLine(); }
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static double ReadDouble() { return double.Parse(Console.ReadLine()); }
static string[] ReadStAr(char sep = ' ') {
return Console.ReadLine().Split(sep);
}
static int[] ReadIntAr(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] ReadLongAr(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] ReadDoubleAr(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ITP1_10_A {
public class Program
{
public static void Main(string[] args) {
double[] line = ReadDoubleAr();
Console.WriteLine("{0}", Math.Sqrt(Math.Pow((line[2] - line[0]), 2) +
Math.Pow((line[3] - line[1]), 2)));
}
static string ReadSt() { return Console.ReadLine(); }
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static double ReadDouble() { return double.Parse(Console.ReadLine()); }
static string[] ReadStAr(char sep = ' ') {
return Console.ReadLine().Split(sep);
}
static int[] ReadIntAr(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] ReadLongAr(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] ReadDoubleAr(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22]]
| 8
| 323
| 4
|
using System;
using System.Linq;
namespace ITP1_10_A {
class Program {
static void Main(string[] args) {
int[] input =
Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
double distance = Math.Sqrt(Math.Pow((input[3] - input[1]), 2) +
Math.Pow((input[2] - input[1]), 0));
Console.WriteLine(distance.ToString("f5"));
}
}
}
|
using System;
using System.Linq;
namespace ITP1_10_A {
class Program {
static void Main(string[] args) {
double[] input = Console.ReadLine()
.Split(' ')
.Select(x => Convert.ToDouble(x))
.ToArray();
double distance = Math.Sqrt(Math.Pow((input[3] - input[1]), 2) +
Math.Pow((input[2] - input[0]), 2));
Console.WriteLine(distance.ToString("f5"));
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 141, 22], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 121
| 8
|
using System;
public class Class1 {
public static void Main(String[] args) {
string data = Console.ReadLine();
string[] xxyy = data.Split();
double x1 = double.Parse(xxyy[0]);
double x2 = double.Parse(xxyy[1]);
double y1 = double.Parse(xxyy[2]);
double y2 = double.Parse(xxyy[3]);
double a = x2 - x1;
double b = y2 - y1;
double c = a * a + b * b;
Console.WriteLine(Math.Sqrt(c));
}
}
|
using System;
public class Class1 {
public static void Main(String[] args) {
string data = Console.ReadLine();
string[] xxyy = data.Split();
double x1 = double.Parse(xxyy[0]);
double y1 = double.Parse(xxyy[1]);
double x2 = double.Parse(xxyy[2]);
double y2 = double.Parse(xxyy[3]);
double a = x2 - x1;
double b = y2 - y1;
double c = a * a + b * b;
Console.WriteLine(Math.Sqrt(c));
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22]]
| 8
| 129
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication48 {
class Program {
static void Main(string[] args) {
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
double b = a[0] - a[2];
double c = a[1] - a[3];
b = b * b;
c = c * c;
double d = b + c;
d = Math.Sqrt(d);
Console.WriteLine(d);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication48 {
class Program {
static void Main(string[] args) {
double[] a = Console.ReadLine().Split().Select(double.Parse).ToArray();
double b = a[0] - a[2];
double c = a[1] - a[3];
b = b * b;
c = c * c;
double d = b + c;
d = Math.Sqrt(d);
Console.WriteLine(d);
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
| 8
| 126
| 4
|
using System;
using System.Linq;
namespace _10_A {
class Program {
static void Main(string[] args) {
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
Console.WriteLine(Math.Sqrt((x[0] - x[2]) * (x[0] - x[2]) +
(x[1] - x[3]) * (x[1] - x[3])));
Console.ReadLine();
}
}
}
|
using System;
using System.Linq;
namespace _10_A {
class Program {
static void Main() {
double[] x = Console.ReadLine().Split().Select(double.Parse).ToArray();
Console.WriteLine(Math.Sqrt((x[0] - x[2]) * (x[0] - x[2]) +
(x[1] - x[3]) * (x[1] - x[3])));
Console.ReadLine();
}
}
}
|
[["-", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["-", 54, 55, 0, 220, 39, 224, 225, 226, 0, 70], ["-", 54, 55, 0, 220, 39, 224, 225, 226, 0, 73], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
| 8
| 117
| 8
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
public class Program {
public void Proc() {
double[] inpt =
Reader.ReadLine().Split(' ').Select(a => double.Parse(a)).ToArray();
double ans = Math.Sqrt(Math.Pow(inpt[0] - inpt[2], 2) +
Math.Sqrt(Math.Pow(inpt[1] - inpt[3], 2)));
Console.WriteLine(ans.ToString("#0.0#############"));
}
public class Reader {
private static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine() {
if (IsDebug) {
if (sr == null) {
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
private static string InputText = @"
0 0 1 1
";
}
public static void Main(string[] args) {
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
public class Program {
public void Proc() {
double[] inpt =
Reader.ReadLine().Split(' ').Select(a => double.Parse(a)).ToArray();
double ans = Math.Sqrt(Math.Pow(inpt[0] - inpt[2], 2) +
Math.Pow(inpt[1] - inpt[3], 2));
Console.WriteLine(ans.ToString("#0.0#############"));
}
public class Reader {
private static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine() {
if (IsDebug) {
if (sr == null) {
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
private static string InputText = @"
1.123 0.0 1.123 100.0
";
}
public static void Main(string[] args) {
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
|
[["-", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 12, 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], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
| 8
| 239
| 7
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace LogicSummoner {
class Program {
static void Main(string[] args) {
var line = GetNumbersInt();
Console.WriteLine("{0:F8}",
Math.Sqrt((line[0] - line[2]) * (line[0] - line[2]) +
(line[1] - line[3]) * (line[1] - line[3])));
}
// static StreamReader Console = new StreamReader("input.txt");
static int GetNumber() { return int.Parse(Console.ReadLine().Trim()); }
static double GetDounble() { return double.Parse(Console.ReadLine().Trim()); }
static int[] GetNumbersInt(int n = 0) {
return Console.ReadLine()
.Trim()
.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => int.Parse(x))
.ToArray();
}
static long[] GetNumbersLong(int n = 0) {
return Console.ReadLine()
.Trim()
.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => long.Parse(x))
.ToArray();
}
static double[] GetNumbersDouble(int n = 0) {
return Console.ReadLine()
.Trim()
.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => double.Parse(x))
.ToArray();
}
static string[] GetStrings(int n = 0) {
return Console.ReadLine()
.Trim()
.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
.ToArray();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace LogicSummoner {
class Program {
static void Main(string[] args) {
var line = GetNumbersDouble();
Console.WriteLine("{0:F8}",
Math.Sqrt((line[0] - line[2]) * (line[0] - line[2]) +
(line[1] - line[3]) * (line[1] - line[3])));
}
// static StreamReader Console = new StreamReader("input.txt");
static int GetNumber() { return int.Parse(Console.ReadLine().Trim()); }
static double GetDounble() { return double.Parse(Console.ReadLine().Trim()); }
static int[] GetNumbersInt(int n = 0) {
return Console.ReadLine()
.Trim()
.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => int.Parse(x))
.ToArray();
}
static long[] GetNumbersLong(int n = 0) {
return Console.ReadLine()
.Trim()
.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => long.Parse(x))
.ToArray();
}
static double[] GetNumbersDouble(int n = 0) {
return Console.ReadLine()
.Trim()
.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => double.Parse(x))
.ToArray();
}
static string[] GetStrings(int n = 0) {
return Console.ReadLine()
.Trim()
.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
.ToArray();
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22]]
| 8
| 377
| 2
|
using System;
public class hello {
public static void Main() {
string[] s = Console.ReadLine().Trim().Split(' ');
var x1 = int.Parse(s[0]);
var y1 = int.Parse(s[1]);
var x2 = int.Parse(s[2]);
var y2 = int.Parse(s[3]);
var buf = Math.Pow((y2 - y1), 2) + Math.Pow((x2 - x1), 2);
var result = Math.Sqrt(buf);
Console.WriteLine(result);
}
}
|
using System;
public class hello {
public static void Main() {
string[] s = Console.ReadLine().Trim().Split(' ');
var x1 = double.Parse(s[0]);
var y1 = double.Parse(s[1]);
var x2 = double.Parse(s[2]);
var y2 = double.Parse(s[3]);
var buf = Math.Pow((y2 - y1), 2) + Math.Pow((x2 - x1), 2);
var result = Math.Sqrt(buf);
Console.WriteLine(result);
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 136
| 8
|
using System;
class Program {
static void Main() {
int[] num = Console.ReadLine().Split(' ').toIntArray();
Vector vec1 = new Vector(num[0], num[1]);
Vector vec2 = new Vector(num[2], num[3]);
Console.WriteLine(vec2.subVector(vec1).norm().ToString());
}
}
class Vector {
public double X;
public double Y;
public Vector(double x, double y) {
X = x;
Y = y;
}
public double norm() { return Math.Sqrt(X * X + Y * Y); }
public Vector addVector(Vector vec) {
return new Vector(X + vec.X, Y + vec.Y);
}
public Vector subVector(Vector vec) {
return new Vector(X - vec.X, Y - vec.Y);
}
}
static class Extensions_strArray {
static public int[] toIntArray(this string[] array) {
return Array.ConvertAll<string, int>(
array, delegate(string value) { return int.Parse(value); });
}
}
|
using System;
class Program {
static void Main() {
double[] num = Console.ReadLine().Split(' ').toDoubleArray();
Vector vec1 = new Vector(num[0], num[1]);
Vector vec2 = new Vector(num[2], num[3]);
Console.WriteLine(vec2.subVector(vec1).norm().ToString());
}
}
class Vector {
public double X;
public double Y;
public Vector(double x, double y) {
X = x;
Y = y;
}
public double norm() { return Math.Sqrt(X * X + Y * Y); }
public Vector addVector(Vector vec) {
return new Vector(X + vec.X, Y + vec.Y);
}
public Vector subVector(Vector vec) {
return new Vector(X - vec.X, Y - vec.Y);
}
}
static class Extensions_strArray {
static public double[] toDoubleArray(this string[] array) {
return Array.ConvertAll<string, double>(
array, delegate(string value) { return double.Parse(value); });
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["+", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["-", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22], ["-", 0, 213, 63, 214, 141, 236, 237, 238, 0, 199], ["+", 0, 213, 63, 214, 141, 236, 237, 238, 0, 199], ["-", 0, 196, 0, 37, 0, 213, 63, 214, 205, 199], ["+", 0, 196, 0, 37, 0, 213, 63, 214, 205, 199]]
| 8
| 243
| 12
|
using System;
namespace ConsoleApplication26 {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
double a = double.Parse(input[0]);
double b = double.Parse(input[1]);
double c = double.Parse(input[2]);
double h = b * Math.Sin(c * (Math.PI / 180));
double S = (a * (b * Math.Sin(c * (Math.PI / 180)))) / 2;
double x = Math.Sqrt(Math.Pow(h, 2) +
Math.Pow(a - a * Math.Cos(c * (Math.PI / 180)), 2));
double L = a + b + x;
Console.WriteLine("{0:f5}", S);
Console.WriteLine("{0:f5}", L);
Console.WriteLine("{0:f5}", h);
}
}
}
|
using System;
namespace ConsoleApplication26 {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
double a = double.Parse(input[0]);
double b = double.Parse(input[1]);
double c = double.Parse(input[2]);
double h = b * Math.Sin(c * (Math.PI / 180));
double S = (a * (b * Math.Sin(c * (Math.PI / 180)))) / 2;
double x = Math.Sqrt(Math.Pow(h, 2) +
Math.Pow(a - b * Math.Cos(c * (Math.PI / 180)), 2));
double L = a + b + x;
Console.WriteLine("{0:f5}", S);
Console.WriteLine("{0:f5}", L);
Console.WriteLine("{0:f5}", h);
}
}
}
|
[["-", 3, 4, 0, 28, 0, 16, 12, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 31, 22]]
| 8
| 212
| 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.