buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { static class Program { static void Main() { Solve(); Console.ReadKey(); } static void Solve() { var n = GetStr().ToCharArray().Select(s => int.Parse(s.ToString())).ToArray(); var a = n[0]; var b = n[1]; var c = n[2]; var d = n[3]; string ans = ""; if (a + b + c + d == 7) ans = a + "+" + b + "+" + c + "+" + d + "+=7"; if (a + b + c - d == 7) ans = a + "+" + b + "+" + c + "-" + d + "+=7"; if (a + b - c + d == 7) ans = a + "+" + b + "-" + c + "+" + d + "+=7"; if (a - b + c + d == 7) ans = a + "-" + b + "+" + c + "+" + d + "+=7"; if (a + b - c - d == 7) ans = a + "+" + b + "-" + c + "-" + d + "+=7"; if (a - b + c - d == 7) ans = a + "-" + b + "+" + c + "-" + d + "+=7"; if (a - b - c + d == 7) ans = a + "-" + b + "-" + c + "+" + d + "+=7"; if (a - b - c - d == 7) ans = a + "-" + b + "-" + c + "-" + d + "+=7"; Console.WriteLine(ans); } static public string GetStr() { return Console.ReadLine(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public string[] GetStrArray() { return Console.ReadLine().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } static string yesno(this bool b) { return b ? "yes" : "no"; } static string YesNo(this bool b) { return b ? "Yes" : "No"; } static string YESNO(this bool b) { return b ? "YES" : "NO"; } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { static class Program { static void Main() { Solve(); Console.ReadKey(); } static void Solve() { var n = GetStr().ToCharArray().Select(s => int.Parse(s.ToString())).ToArray(); var a = n[0]; var b = n[1]; var c = n[2]; var d = n[3]; string ans = ""; if (a + b + c + d == 7) ans = a + "+" + b + "+" + c + "+" + d + "=7"; if (a + b + c - d == 7) ans = a + "+" + b + "+" + c + "-" + d + "=7"; if (a + b - c + d == 7) ans = a + "+" + b + "-" + c + "+" + d + "=7"; if (a - b + c + d == 7) ans = a + "-" + b + "+" + c + "+" + d + "=7"; if (a + b - c - d == 7) ans = a + "+" + b + "-" + c + "-" + d + "=7"; if (a - b + c - d == 7) ans = a + "-" + b + "+" + c + "-" + d + "=7"; if (a - b - c + d == 7) ans = a + "-" + b + "-" + c + "+" + d + "=7"; if (a - b - c - d == 7) ans = a + "-" + b + "-" + c + "-" + d + "=7"; Console.WriteLine(ans); } static public string GetStr() { return Console.ReadLine(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public string[] GetStrArray() { return Console.ReadLine().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } static string yesno(this bool b) { return b ? "yes" : "no"; } static string YesNo(this bool b) { return b ? "Yes" : "No"; } static string YESNO(this bool b) { return b ? "YES" : "NO"; } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } } }
[["-", 64, 1, 0, 11, 12, 16, 12, 5, 0, 222], ["+", 64, 1, 0, 11, 12, 16, 12, 5, 0, 222]]
8
1,038
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static int A; static int B; static int C; static int D; static int[] H; static void Main(string[] args) { string s = Console.ReadLine(); A = int.Parse(s[0].ToString()); B = int.Parse(s[1].ToString()); C = int.Parse(s[2].ToString()); D = int.Parse(s[3].ToString()); H = new int[4] { A, B, C, D }; Saiki(0, A, A.ToString()); } static void Saiki(int i, int sum, string f) { if (i == 3) { if (sum == 7) { Console.WriteLine(f + "=7"); Environment.Exit(0); } } else { Saiki(i + 1, sum + H[i + 1], $"{f}+{H[i+1]}"); Saiki(i + 1, sum - H[i + 1], $"{f}-{H[i+1]}"); Console.WriteLine(f); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static int A; static int B; static int C; static int D; static int[] H; static void Main(string[] args) { string s = Console.ReadLine(); A = int.Parse(s[0].ToString()); B = int.Parse(s[1].ToString()); C = int.Parse(s[2].ToString()); D = int.Parse(s[3].ToString()); H = new int[4] { A, B, C, D }; Saiki(0, A, A.ToString()); } static void Saiki(int i, int sum, string f) { if (i == 3) { if (sum == 7) { Console.WriteLine(f + "=7"); Environment.Exit(0); } } else { Saiki(i + 1, sum + H[i + 1], $"{f}+{H[i+1]}"); Saiki(i + 1, sum - H[i + 1], $"{f}-{H[i+1]}"); } } } }
[["-", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
8
292
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Numerics; #if DEBUG using Microsoft.VisualStudio.TestTools.UnitTesting; #endif namespace competitive_programming { public class Program { static void Main(string[] args) { #if DEBUG var scanner = new IO.StreamScanner(File.Open("input.txt", FileMode.Open)); #else var scanner = new IO.StreamScanner(Console.OpenStandardInput()); #endif var str = scanner.ScanLine(); var a = int.Parse(str[0].ToString()); var b = int.Parse(str[1].ToString()); var c = int.Parse(str[2].ToString()); var d = int.Parse(str[3].ToString()); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { var val = Op(k, Op(i, a, b), Op(k, c, d)); if (val == 7) { IO.Printer.Out.WriteLine(a + Op(i) + b + Op(j) + c + Op(k) + d + "=7"); IO.Printer.Out.Flush(); return; } } } } IO.Printer.Out.Flush(); } static int Op(int op, int val1, int val2) { return op == 0 ? val1 + val2 : val1 - val2; } static string Op(int op) { return op == 0 ? "+" : "-"; } } } #if DEBUG #endif #region INOUT namespace IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Numerics; #if DEBUG using Microsoft.VisualStudio.TestTools.UnitTesting; #endif namespace competitive_programming { public class Program { static void Main(string[] args) { #if DEBUG var scanner = new IO.StreamScanner(File.Open("input.txt", FileMode.Open)); #else var scanner = new IO.StreamScanner(Console.OpenStandardInput()); #endif var str = scanner.ScanLine(); var a = int.Parse(str[0].ToString()); var b = int.Parse(str[1].ToString()); var c = int.Parse(str[2].ToString()); var d = int.Parse(str[3].ToString()); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { var val = a + b * (i == 0 ? 1 : -1) + c * (j == 0 ? 1 : -1) + d * (k == 0 ? 1 : -1); if (val == 7) { IO.Printer.Out.WriteLine(a + Op(i) + b + Op(j) + c + Op(k) + d + "=7"); IO.Printer.Out.Flush(); return; } } } } IO.Printer.Out.Flush(); } static int Op(int op, int val1, int val2) { return op == 0 ? val1 + val2 : val1 - val2; } static string Op(int op) { return op == 0 ? "+" : "-"; } } } #if DEBUG #endif #region INOUT namespace IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 16, 31, 16, 31, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 16, 31, 16, 31, 16, 12, 16, 17, 48], ["+", 12, 16, 12, 23, 0, 41, 15, 16, 31, 22], ["+", 12, 16, 12, 23, 0, 41, 15, 16, 17, 60], ["+", 12, 16, 12, 23, 0, 41, 15, 16, 12, 203], ["+", 31, 16, 12, 16, 12, 23, 0, 41, 0, 101], ["+", 31, 16, 12, 16, 12, 23, 0, 41, 64, 203], ["+", 31, 16, 12, 16, 12, 23, 0, 41, 0, 102], ["+", 12, 16, 12, 23, 0, 41, 75, 241, 0, 33], ["+", 12, 16, 12, 23, 0, 41, 75, 241, 0, 203], ["+", 31, 16, 31, 16, 12, 16, 12, 23, 0, 25], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 72], ["+", 0, 212, 0, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 48], ["+", 0, 212, 0, 16, 12, 16, 12, 23, 0, 24], ["+", 0, 16, 12, 16, 12, 23, 0, 41, 0, 101], ["+", 0, 16, 12, 16, 12, 23, 0, 41, 64, 203], ["+", 0, 16, 12, 16, 12, 23, 0, 41, 0, 102]]
8
1,210
50
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Runtime.CompilerServices; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static Ex; class AC { /*------------------------------------------------------------------*/ private string s; void Solve() { s = io.String; var abcd = s.ToCharArray().Select(x => x.ToInt()).ToArray(); var a = abcd[0]; var b = abcd[1]; var c = abcd[2]; var d = abcd[3]; var expr = new string[] { "+", "-" }; REP(2, 2, 2, (i, j, k) => { var sum = a; if (i.Eve()) sum += b; else sum -= b; if (j.Eve()) sum += c; else sum -= c; if (k.Eve()) sum += d; else sum -= d; if (sum == 7) { $"{a}{expr[i]}{b}{expr[j]}{c}{expr[k]}{d}=7".Prt(); EXIT(); } }); } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] args) => new AC().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => WriteLine(f ? "YES" : "NO"); public void Yn(bool f) => WriteLine(f ? "Yes" : "No"); public void yn(bool f) => WriteLine(f ? "yes" : "no"); #endregion public IO() { SetOut(_sw); } } static class Ex { #region マクロもどき public static void EXIT() => Environment.Exit(0); public static void LOG<T>(T x, [CallerLineNumber] int line = 0) => Error.WriteLine($"--- LOG[{line}]: {x} ---"); public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void FOR(int a, int b, int n, Action<int> f) { for (int i = a; i < b; i += n) f(i); } public static void REP(int a, Action<int> f) => FOR(0, a, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f); public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f); public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1, n, f); public static void REP(int a, int b, Action<int, int> f) => REP(a, i => REP(b, j => f(i, j))); public static void REP(int a, int b, int c, Action<int, int, int> f) => REP(a, i => REP(b, j => REP(c, k => f(i, j, k)))); public static void REPEQ(int a, int b, Action<int, int> f) => REPEQ(a, i => REPEQ(b, j => f(i, j))); public static void REPEQ(int a, int b, int c, Action<int, int, int> f) => REPEQ(a, i => REPEQ(b, j => REPEQ(c, k => f(i, j, k)))); public static T MIN<T>(params T[] xs) => xs.Min(); public static T MAX<T>(params T[] xs) => xs.Max(); public static IEnumerable<int> RANGE(int s, int e) => Enumerable.Range(s, e - s + 1); public static int LCM(int a, int b) => a * (b / GCD(a, b)); public static int GCD(int a, int b) => (a < b) ? GCD(b, a) : b == 0 ? a : GCD(b, a % b); public static int LCM(params int[] xs) => xs.Aggregate(LCM); public static int GCD(params int[] xs) => xs.Aggregate(GCD); public static long LCM(long a, long b) => a * (b / GCD(a, b)); public static long GCD(long a, long b) => (a < b) ? GCD(b, a) : b == 0L ? a : GCD(b, a % b); public static long LCM(params long[] xs) => xs.Aggregate(LCM); public static long GCD(params long[] xs) => xs.Aggregate(GCD); #endregion #region 拡張メソッド public static void Rep(this int x, Action<int> f) => REP(x, f); public static void RepEq(this int x, Action<int> f) => REPEQ(x, f); public static int ToInt(this string s) { double n; double.TryParse(s.TrimStart('0'), out n); return Convert.ToInt32(n); } public static int ToInt(this char c) => ToInt(c.ToString()); public static int ToInt(this char[] c) => ToInt(new string(c)); public static long ToLong(this string s) { double n; double.TryParse(s.TrimStart('0'), out n); return Convert.ToInt64(n); } public static long ToLong(this char c) => ToLong(c.ToString()); public static long ToLong(this char[] c) => ToLong(new string(c)); public static void Do<T>(this T x, Action<T> f) => f(x); public static TU Then<T, TU>(this T x, Func<T, TU> f) => f(x); public static void Log<T>(this T x, [CallerLineNumber] int line = 0) => Error.WriteLine($"--- LOG[{line}]: {x} ---"); public static void Fun<T>(this T[] xs, Action<int> f) => REP(xs.Length, f); public static void Fun<T>(this T[,] xxs, Action<int, int> f) => REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => f(i, j))); public static bool IsIn<T>(this T[] xs, int i) => 0 <= i && i < xs.Length; public static bool IsIn<T>(this T[,] xxs, int i, int j) => 0 <= i && i < xxs.GetLength(0) && 0 <= j && j < xxs.GetLength(1); public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) { foreach (var x in xs) f(x); } public class IndexedItem<T> { public int Idx; public T Val; public IndexedItem(int idx, T val) { Idx = idx; Val = val; } } public static IEnumerable<IndexedItem<T>> Indexed<T>( this IEnumerable<T> xs) => xs.Select((x, i) => new IndexedItem<T>(i, x)); public static void Set<T>(this T[] xs, T v) => REP(xs.Length, i => xs[i] = v); public static void Set<T>(this T[,] xxs, T v) => REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => xxs[i, j] = v)); public static T[] Sort<T>(this T[] xs) { Array.Sort(xs); return xs; } public static T[] SortR<T>(this T[] xs) { Array.Reverse(xs.Sort()); return xs; } public static string Pad0<T>(this T s, int n) => s.ToString().PadLeft(n, '0'); public static int RoundOff(this double v, int n) => (int) Round(v, n - 1, MidpointRounding.AwayFromZero); public static int RoundUp(this double v) => (int)Ceiling(v); public static int RoundDown(this double v) => (int)Floor(v); public static bool Odd(this int v) => (v & 1) != 0; public static bool Odd(this long v) => (v & 1) != 0; public static bool Eve(this int v) => !v.Odd(); public static bool Eve(this long v) => !v.Odd(); public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this T[] xs) => xs.Iter(x => WriteLine(x)); public static void Prt<T>(this List<T> xs) => xs.Iter(x => WriteLine(x)); public static void Prt<T>(this T[,] xs) => xs.GetLength(0).Rep(i => { xs.GetLength(1).Rep(j => Write($"{xs[i, j]} ")); WriteLine(); }); public static void Prt_<T>(this T[] xs) => WriteLine(string.Join(" ", xs)); public static string Reversed(this string s) => string.Join("", s.Reverse()); public static string Repeat(this string s, int n) => string.Concat(Enumerable.Repeat(s, n).ToArray()); #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Runtime.CompilerServices; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static Ex; class AC { /*------------------------------------------------------------------*/ private string s; void Solve() { s = io.String; var abcd = s.ToCharArray().Select(x => x.ToInt()).ToArray(); var a = abcd[0]; var b = abcd[1]; var c = abcd[2]; var d = abcd[3]; var expr = new string[] { "+", "-" }; var ans = ""; REP(2, 2, 2, (i, j, k) => { var sum = a; if (i.Eve()) sum += b; else sum -= b; if (j.Eve()) sum += c; else sum -= c; if (k.Eve()) sum += d; else sum -= d; if (sum == 7) { ans = $"{a}{expr[i]}{b}{expr[j]}{c}{expr[k]}{d}=7"; } }); ans.Prt(); } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] args) => new AC().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => WriteLine(f ? "YES" : "NO"); public void Yn(bool f) => WriteLine(f ? "Yes" : "No"); public void yn(bool f) => WriteLine(f ? "yes" : "no"); #endregion public IO() { SetOut(_sw); } } static class Ex { #region マクロもどき public static void EXIT() => Environment.Exit(0); public static void LOG<T>(T x, [CallerLineNumber] int line = 0) => Error.WriteLine($"--- LOG[{line}]: {x} ---"); public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void FOR(int a, int b, int n, Action<int> f) { for (int i = a; i < b; i += n) f(i); } public static void REP(int a, Action<int> f) => FOR(0, a, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f); public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f); public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1, n, f); public static void REP(int a, int b, Action<int, int> f) => REP(a, i => REP(b, j => f(i, j))); public static void REP(int a, int b, int c, Action<int, int, int> f) => REP(a, i => REP(b, j => REP(c, k => f(i, j, k)))); public static void REPEQ(int a, int b, Action<int, int> f) => REPEQ(a, i => REPEQ(b, j => f(i, j))); public static void REPEQ(int a, int b, int c, Action<int, int, int> f) => REPEQ(a, i => REPEQ(b, j => REPEQ(c, k => f(i, j, k)))); public static T MIN<T>(params T[] xs) => xs.Min(); public static T MAX<T>(params T[] xs) => xs.Max(); public static IEnumerable<int> RANGE(int s, int e) => Enumerable.Range(s, e - s + 1); public static int LCM(int a, int b) => a * (b / GCD(a, b)); public static int GCD(int a, int b) => (a < b) ? GCD(b, a) : b == 0 ? a : GCD(b, a % b); public static int LCM(params int[] xs) => xs.Aggregate(LCM); public static int GCD(params int[] xs) => xs.Aggregate(GCD); public static long LCM(long a, long b) => a * (b / GCD(a, b)); public static long GCD(long a, long b) => (a < b) ? GCD(b, a) : b == 0L ? a : GCD(b, a % b); public static long LCM(params long[] xs) => xs.Aggregate(LCM); public static long GCD(params long[] xs) => xs.Aggregate(GCD); #endregion #region 拡張メソッド public static void Rep(this int x, Action<int> f) => REP(x, f); public static void RepEq(this int x, Action<int> f) => REPEQ(x, f); public static int ToInt(this string s) { double n; double.TryParse(s.TrimStart('0'), out n); return Convert.ToInt32(n); } public static int ToInt(this char c) => ToInt(c.ToString()); public static int ToInt(this char[] c) => ToInt(new string(c)); public static long ToLong(this string s) { double n; double.TryParse(s.TrimStart('0'), out n); return Convert.ToInt64(n); } public static long ToLong(this char c) => ToLong(c.ToString()); public static long ToLong(this char[] c) => ToLong(new string(c)); public static void Do<T>(this T x, Action<T> f) => f(x); public static TU Then<T, TU>(this T x, Func<T, TU> f) => f(x); public static void Log<T>(this T x, [CallerLineNumber] int line = 0) => Error.WriteLine($"--- LOG[{line}]: {x} ---"); public static void Fun<T>(this T[] xs, Action<int> f) => REP(xs.Length, f); public static void Fun<T>(this T[,] xxs, Action<int, int> f) => REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => f(i, j))); public static bool IsIn<T>(this T[] xs, int i) => 0 <= i && i < xs.Length; public static bool IsIn<T>(this T[,] xxs, int i, int j) => 0 <= i && i < xxs.GetLength(0) && 0 <= j && j < xxs.GetLength(1); public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) { foreach (var x in xs) f(x); } public class IndexedItem<T> { public int Idx; public T Val; public IndexedItem(int idx, T val) { Idx = idx; Val = val; } } public static IEnumerable<IndexedItem<T>> Indexed<T>( this IEnumerable<T> xs) => xs.Select((x, i) => new IndexedItem<T>(i, x)); public static void Set<T>(this T[] xs, T v) => REP(xs.Length, i => xs[i] = v); public static void Set<T>(this T[,] xxs, T v) => REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => xxs[i, j] = v)); public static T[] Sort<T>(this T[] xs) { Array.Sort(xs); return xs; } public static T[] SortR<T>(this T[] xs) { Array.Reverse(xs.Sort()); return xs; } public static string Pad0<T>(this T s, int n) => s.ToString().PadLeft(n, '0'); public static int RoundOff(this double v, int n) => (int) Round(v, n - 1, MidpointRounding.AwayFromZero); public static int RoundUp(this double v) => (int)Ceiling(v); public static int RoundDown(this double v) => (int)Floor(v); public static bool Odd(this int v) => (v & 1) != 0; public static bool Odd(this long v) => (v & 1) != 0; public static bool Eve(this int v) => !v.Odd(); public static bool Eve(this long v) => !v.Odd(); public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this T[] xs) => xs.Iter(x => WriteLine(x)); public static void Prt<T>(this List<T> xs) => xs.Iter(x => WriteLine(x)); public static void Prt<T>(this T[,] xs) => xs.GetLength(0).Rep(i => { xs.GetLength(1).Rep(j => Write($"{xs[i, j]} ")); WriteLine(); }); public static void Prt_<T>(this T[] xs) => WriteLine(string.Join(" ", xs)); public static string Reversed(this string s) => string.Join("", s.Reverse()); public static string Repeat(this string s, int n) => string.Concat(Enumerable.Repeat(s, n).ToArray()); #endregion }
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 62], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
8
3,260
22
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { this.NumList = Reader.ReadLine().Select(a => int.Parse(a.ToString())).ToArray(); List<bool> ansList = GetAns(0, this.NumList[0], new List<bool>()); StringBuilder ans = new StringBuilder(); for (int i = 0; i < NumList.Length; i++) { ans.Append(NumList[i]); if (i < NumList.Length - 1) { ans.Append(ansList[i] ? "+" : "-"); } } Console.WriteLine(ans.ToString()); } private int[] NumList; private List<bool> GetAns(int idx, int subTotal, List<bool> subList) { if (idx >= 3) { if (subTotal == 7) { return subList; } else { return null; } } List<bool> subSubList = new List<bool>(subList); subSubList.Add(true); List<bool> tmp = GetAns(idx + 1, subTotal + NumList[idx + 1], subSubList); if (tmp != null) { return tmp; } subSubList = new List<bool>(subList); subSubList.Add(false); tmp = GetAns(idx + 1, subTotal - NumList[idx + 1], subSubList); return tmp; } 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 = @" 0290 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { this.NumList = Reader.ReadLine().Select(a => int.Parse(a.ToString())).ToArray(); List<bool> ansList = GetAns(0, this.NumList[0], new List<bool>()); StringBuilder ans = new StringBuilder(); for (int i = 0; i < NumList.Length; i++) { ans.Append(NumList[i]); if (i < NumList.Length - 1) { ans.Append(ansList[i] ? "+" : "-"); } } ans.Append("=7"); Console.WriteLine(ans.ToString()); } private int[] NumList; private List<bool> GetAns(int idx, int subTotal, List<bool> subList) { if (idx >= 3) { if (subTotal == 7) { return subList; } else { return null; } } List<bool> subSubList = new List<bool>(subList); subSubList.Add(true); List<bool> tmp = GetAns(idx + 1, subTotal + NumList[idx + 1], subSubList); if (tmp != null) { return tmp; } subSubList = new List<bool>(subList); subSubList.Add(false); tmp = GetAns(idx + 1, subTotal - NumList[idx + 1], subSubList); return tmp; } 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 = @" 0290 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
432
9
using System; namespace abc079_c { class Program { static void Main(string[] args) { string s = Console.ReadLine(); int[] n = new int[4]; for (int i = 0; i < 4; i++) { n[i] = int.Parse(s[i].ToString()); } if (n[0] + n[1] + n[2] + n[3] == 7) { Console.WriteLine(n[0] + "+" + n[1] + "+" + n[2] + "+" + n[3]); } else if (n[0] + n[1] + n[2] - n[3] == 7) { Console.WriteLine(n[0] + "+" + n[1] + "+" + n[2] + "-" + n[3]); } else if (n[0] + n[1] - n[2] + n[3] == 7) { Console.WriteLine(n[0] + "+" + n[1] + "-" + n[2] + "+" + n[3]); } else if (n[0] + n[1] - n[2] - n[3] == 7) { Console.WriteLine(n[0] + "+" + n[1] + "-" + n[2] + "-" + n[3]); } else if (n[0] - n[1] + n[2] + n[3] == 7) { Console.WriteLine(n[0] + "-" + n[1] + "+" + n[2] + "+" + n[3]); } else if (n[0] - n[1] + n[2] - n[3] == 7) { Console.WriteLine(n[0] + "-" + n[1] + "+" + n[2] + "-" + n[3]); } else if (n[0] - n[1] - n[2] + n[3] == 7) { Console.WriteLine(n[0] + "-" + n[1] + "-" + n[2] + "+" + n[3]); } else if (n[0] - n[1] - n[2] - n[3] == 7) { Console.WriteLine(n[0] + "-" + n[1] + "-" + n[2] + "-" + n[3]); } } } }
using System; namespace abc079_c { class Program { static void Main(string[] args) { string s = Console.ReadLine(); int[] n = new int[4]; for (int i = 0; i < 4; i++) { n[i] = int.Parse(s[i].ToString()); } if (n[0] + n[1] + n[2] + n[3] == 7) { Console.Write(n[0] + "+" + n[1] + "+" + n[2] + "+" + n[3]); } else if (n[0] + n[1] + n[2] - n[3] == 7) { Console.Write(n[0] + "+" + n[1] + "+" + n[2] + "-" + n[3]); } else if (n[0] + n[1] - n[2] + n[3] == 7) { Console.Write(n[0] + "+" + n[1] + "-" + n[2] + "+" + n[3]); } else if (n[0] + n[1] - n[2] - n[3] == 7) { Console.Write(n[0] + "+" + n[1] + "-" + n[2] + "-" + n[3]); } else if (n[0] - n[1] + n[2] + n[3] == 7) { Console.Write(n[0] + "-" + n[1] + "+" + n[2] + "+" + n[3]); } else if (n[0] - n[1] + n[2] - n[3] == 7) { Console.Write(n[0] + "-" + n[1] + "+" + n[2] + "-" + n[3]); } else if (n[0] - n[1] - n[2] + n[3] == 7) { Console.Write(n[0] + "-" + n[1] + "-" + n[2] + "+" + n[3]); } else if (n[0] - n[1] - n[2] - n[3] == 7) { Console.Write(n[0] + "-" + n[1] + "-" + n[2] + "-" + n[3]); } Console.WriteLine("=7"); } } }
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
588
25
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var hw = Ints; var H = hw[0]; var W = hw[1]; var c = new int [10][]; for (int i = 0; i < 10; ++i) c[i] = Ints; var A = new int [H][]; for (int i = 0; i < H; ++i) A[i] = Ints; for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10; ++j) { for (int k = 0; k < 10; ++k) { c[i][j] = Min(c[i][j], c[i][k] + c[k][j]); } } } long ans = 0; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (A[i][j] != -1) { ans += c[A[i][j]][1]; } } } Write(ans); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const int MOD = 1000000007; public const int MOD2 = 998244353; public static long Pow(long i, long N, long MOD = 1000000007) { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i % MOD; i = i * i % MOD; N >>= 1; } return res; } public static long GCD(long i, long N) { if (i > N) Swap(ref i, ref N); if (i == 0) return N; while (N != 0) { var r = i % N; i = N; N = r; } return i; } public static long LCM(long i, long N) => i * N / GCD(i, N); public static long Comb(long N, long R, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = N; i >= N - R + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long N, long R) { long Nume = 1; long Deno = 1; if (R > N - R) Swap(ref N, ref R); for (long i = 1; i <= R; ++i) { Deno *= i; Nume *= N - i + 1; } return Deno / Nume; } public static Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public static List<long> DivisorEnumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] HorizontalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Horizontalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var hw = Ints; var H = hw[0]; var W = hw[1]; var c = new int [10][]; for (int i = 0; i < 10; ++i) c[i] = Ints; var A = new int [H][]; for (int i = 0; i < H; ++i) A[i] = Ints; for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10; ++j) { for (int k = 0; k < 10; ++k) { c[j][k] = Min(c[j][k], c[j][i] + c[i][k]); } } } long ans = 0; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (A[i][j] != -1) { ans += c[A[i][j]][1]; } } } Write(ans); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const int MOD = 1000000007; public const int MOD2 = 998244353; public static long Pow(long i, long N, long MOD = 1000000007) { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i % MOD; i = i * i % MOD; N >>= 1; } return res; } public static long GCD(long i, long N) { if (i > N) Swap(ref i, ref N); if (i == 0) return N; while (N != 0) { var r = i % N; i = N; N = r; } return i; } public static long LCM(long i, long N) => i * N / GCD(i, N); public static long Comb(long N, long R, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = N; i >= N - R + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long N, long R) { long Nume = 1; long Deno = 1; if (R > N - R) Swap(ref N, ref R); for (long i = 1; i <= R; ++i) { Deno *= i; Nume *= N - i + 1; } return Deno / Nume; } public static Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public static List<long> DivisorEnumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] HorizontalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Horizontalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
[["-", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22]]
8
1,268
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { static class Program { static void Main() { Solve(); Console.ReadKey(); } static void Solve() { int H; int W; Multi(out H, out W); int[][] C = new int [10][]; C = C.Select(c => GetIntArray()).ToArray(); int[][] A = new int [H][]; A = A.Select(a => GetIntArray()).ToArray(); int num = int.MaxValue; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { for (int k = 0; k < 10; k++) { if (C[i][j] > C[i][k] + C[k][j]) { C[i][j] = C[i][k] + C[k][j]; num++; } } } } long ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (Math.Abs(A[i][j]) != 1) { ans += C[A[i][j]][1]; } } } Console.WriteLine(ans); } static public string GetStr() { return Console.ReadLine(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public string[] GetStrArray() { return Console.ReadLine().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } static string yesno(this bool b) { return b ? "yes" : "no"; } static string YesNo(this bool b) { return b ? "Yes" : "No"; } static string YESNO(this bool b) { return b ? "YES" : "NO"; } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { static class Program { static void Main() { Solve(); Console.ReadKey(); } static void Solve() { int H; int W; Multi(out H, out W); int[][] C = new int [10][]; C = C.Select(c => GetIntArray()).ToArray(); int[][] A = new int [H][]; A = A.Select(a => GetIntArray()).ToArray(); for (int k = 0; k < 10; k++) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (C[i][j] > C[i][k] + C[k][j]) { C[i][j] = C[i][k] + C[k][j]; } } } } long ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (Math.Abs(A[i][j]) != 1) { ans += C[A[i][j]][1]; } } } Console.WriteLine(ans); } static public string GetStr() { return Console.ReadLine(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public string[] GetStrArray() { return Console.ReadLine().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } static string yesno(this bool b) { return b ? "yes" : "no"; } static string YesNo(this bool b) { return b ? "Yes" : "No"; } static string YESNO(this bool b) { return b ? "YES" : "NO"; } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 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
926
28
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int h = l[0], w = l[1]; var cost = new int [10][]; var map = new int [h][]; for (var i = 0; i < 10; i++) cost[i] = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (var i = 0; i < h; i++) map[i] = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int k = 0; k < 10; k++) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { cost[i][j] = Math.Min(cost[i][j], cost[i][k] + cost[k][j]); } } } var total = 0L; for (var i = 0; i < h; i++) { for (var j = 0; j < w; j++) { total += cost[map[i][j]][1]; } } Console.WriteLine(total); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int h = l[0], w = l[1]; var cost = new int [10][]; var map = new int [h][]; for (var i = 0; i < 10; i++) cost[i] = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (var i = 0; i < h; i++) map[i] = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int k = 0; k < 10; k++) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { cost[i][j] = Math.Min(cost[i][j], cost[i][k] + cost[k][j]); } } } var total = 0L; for (var i = 0; i < h; i++) { for (var j = 0; j < w; j++) { if (map[i][j] != -1) total += cost[map[i][j]][1]; } } Console.WriteLine(total); } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 204, 205, 204, 205, 22], ["+", 15, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25]]
8
320
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var sc = new Scanner(); int h = sc.NextInt(); int w = sc.NextInt(); int[,] c = new int[10, 10]; for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) c[i, j] = sc.NextInt(); for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) for (int k = 0; k < 10; k++) if (c[i, j] > c[i, k] + c[k, j]) c[i, j] = c[i, k] + c[k, j]; int sum = 0; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { int a = sc.NextInt(); if (a >= 0) sum += c[a, 1]; } Console.WriteLine(sum); } static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); if (b == 0) return a; return Gcd(b, a % b); } } class Scanner { int index = -1; string[] buf; public Scanner() {} public int NextInt() { CheckNext(); return int.Parse(buf[index++]); } public long NextLong() { CheckNext(); return long.Parse(buf[index++]); } public double NextDouble() { CheckNext(); return double.Parse(buf[index++]); } public string NextString() { CheckNext(); return buf[index++]; } private void CheckNext() { if (index >= 0 && index < buf.Length) return; buf = Console.ReadLine().Split(' '); index = 0; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var sc = new Scanner(); int h = sc.NextInt(); int w = sc.NextInt(); int[,] c = new int[10, 10]; for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) c[i, j] = sc.NextInt(); for (int k = 0; k < 10; k++) for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) if (c[i, j] > c[i, k] + c[k, j]) c[i, j] = c[i, k] + c[k, j]; int sum = 0; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { int a = sc.NextInt(); if (a >= 0) sum += c[a, 1]; } Console.WriteLine(sum); } static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); if (b == 0) return a; return Gcd(b, a % b); } } class Scanner { int index = -1; string[] buf; public Scanner() {} public int NextInt() { CheckNext(); return int.Parse(buf[index++]); } public long NextLong() { CheckNext(); return long.Parse(buf[index++]); } public double NextDouble() { CheckNext(); return double.Parse(buf[index++]); } public string NextString() { CheckNext(); return buf[index++]; } private void CheckNext() { if (index >= 0 && index < buf.Length) return; buf = Console.ReadLine().Split(' '); index = 0; } }
[["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 8, 7, 10, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 7, 8, 7, 15, 16, 31, 22], ["+", 8, 196, 0, 7, 8, 7, 15, 16, 31, 22], ["-", 8, 196, 0, 7, 8, 7, 26, 223, 0, 22], ["+", 8, 196, 0, 7, 8, 7, 26, 223, 0, 22], ["-", 8, 7, 8, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 7, 8, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 8, 7, 8, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 7, 8, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 7, 8, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 7, 8, 7, 26, 223, 0, 22]]
8
468
18
using System; class Program { static void Main() { int answer = 0; string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 int h = int.Parse(input[0]); //行の長さ int w = int.Parse(input[1]); //列の長さ int[,] moveMatrix = new int[10, 10]; //行列 for (int i = 0; i < 10; i++) //それぞれの行 { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); for (int j = 0; j < 10; j++) moveMatrix[i, j] = nums[j]; //行の全ての成分 } int[] walls = new int[10]; //各壁の個数 for (int i = 0; i < h; i++) //それぞれの行 { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); for (int j = 0; j < w; j++) { if (nums[j] != -1) walls[nums[j]]++; //行の全ての成分 } } for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { for (int k = 0; k < 10; k++) { if (moveMatrix[i, j] > moveMatrix[i, k] + moveMatrix[k, j]) moveMatrix[i, j] = moveMatrix[i, k] + moveMatrix[k, j]; //距離の更新 } } } for (int i = 0; i < 10; i++) { answer += moveMatrix[i, 1] * walls[i]; } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
using System; class Program { static void Main() { int answer = 0; string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 int h = int.Parse(input[0]); //行の長さ int w = int.Parse(input[1]); //列の長さ int[,] moveMatrix = new int[10, 10]; //行列 for (int i = 0; i < 10; i++) //それぞれの行 { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); for (int j = 0; j < 10; j++) moveMatrix[i, j] = nums[j]; //行の全ての成分 } int[] walls = new int[10]; //各壁の個数 for (int i = 0; i < h; i++) //それぞれの行 { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); for (int j = 0; j < w; j++) { if (nums[j] != -1) walls[nums[j]]++; //行の全ての成分 } } for (int k = 0; k < 10; k++) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (moveMatrix[i, j] > moveMatrix[i, k] + moveMatrix[k, j]) moveMatrix[i, j] = moveMatrix[i, k] + moveMatrix[k, j]; //距離の更新 } } } for (int i = 0; i < 10; i++) { answer += moveMatrix[i, 1] * walls[i]; } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
[["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22]]
8
375
18
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int h = inpt[0]; int w = inpt[1]; for (int i = 0; i <= 9; i++) { inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); for (int j = 0; j < inpt.Length; j++) { ConvDic[i, j] = inpt[j]; } } int[] count = new int[10]; for (int i = 0; i < h; i++) { inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); for (int j = 0; j < w; j++) { if (inpt[j] >= 0) { count[inpt[j]]++; } } } for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { for (int k = 0; k < 10; k++) { ConvDic[i, j] = Math.Min(ConvDic[i, j], ConvDic[i, k] + ConvDic[k, j]); } } } int ans = 0; for (int i = 0; i < count.Length; i++) { ans += ConvDic[i, 1] * count[i]; } Console.WriteLine(ans); } private int[,] ConvDic = new int[10, 10]; public class Reader { private static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 2 4 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 2 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 2 9 9 9 0 9 9 2 9 9 9 9 9 9 9 0 -1 -1 -1 -1 8 1 1 8 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int h = inpt[0]; int w = inpt[1]; for (int i = 0; i <= 9; i++) { inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); for (int j = 0; j < inpt.Length; j++) { ConvDic[i, j] = inpt[j]; } } int[] count = new int[10]; for (int i = 0; i < h; i++) { inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); for (int j = 0; j < w; j++) { if (inpt[j] >= 0) { count[inpt[j]]++; } } } for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { for (int k = 0; k < 10; k++) { ConvDic[j, k] = Math.Min(ConvDic[j, k], ConvDic[j, i] + ConvDic[i, k]); } } } long ans = 0; for (int i = 0; i < count.Length; i++) { ans += ConvDic[i, 1] * count[i]; } Console.WriteLine(ans); } private int[,] ConvDic = new int[10, 10]; public class Reader { private static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 2 4 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 2 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 2 9 9 9 0 9 9 2 9 9 9 9 9 9 9 0 -1 -1 -1 -1 8 1 1 8 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
[["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 21], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 21], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
510
18
using System; namespace MyApp { class Contest { public static int Main() { string[] args = Console.ReadLine().Split(' '); int a = Convert.ToInt32(args[0]); int b = Convert.ToInt32(args[1]); if (a > b) { Console.WriteLine(">"); } if (a < b) { Console.WriteLine("<"); } if (a == b) { Console.WriteLine("="); } return 0; } } }
using System; namespace MyApp { class Contest { public static int Main() { string[] ar = Console.ReadLine().Split(' '); int a = Convert.ToInt32(ar[0].ToCharArray()[0]); int b = Convert.ToInt32(ar[1].ToCharArray()[0]); if (a > b) { Console.WriteLine(">"); } if (a < b) { Console.WriteLine("<"); } if (a == b) { Console.WriteLine("="); } return 0; } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 0, 204, 205, 213, 63, 214, 205, 204, 205, 22], ["+", 205, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 205, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 204, 205, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 204, 205, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 204, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 204, 205, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
117
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); string a = cin.next(); char ans = '='; if (a[0] - a[2] < 0) ans = '<'; else if (a[0] - a[2] > 0) ans = '>'; Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } public void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); string a = cin.next(); string b = cin.next(); char ans = '='; if (a[0] - b[0] < 0) ans = '<'; else if (a[0] - b[0] > 0) ans = '>'; Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } public void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 75, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 75, 57, 15, 16, 31, 16, 12, 204, 205, 22]]
8
747
17
using System; public class Program { public static void Main() { int tmp; string[] s = Console.ReadLine().Split(); int a = int.Parse(s[0]); int b = int.Parse(s[1]); int c = int.Parse(s[2]); tmp = a; if (a == b) { Console.WriteLine(c); } else if (a == c) { Console.WriteLine(b); } else { Console.WriteLine(c); } } }
using System; public class Program { public static void Main() { string[] s = Console.ReadLine().Split(); int a = int.Parse(s[0]); int b = int.Parse(s[1]); int c = int.Parse(s[2]); if (a == b) { Console.WriteLine(c); } else if (a == c) { Console.WriteLine(b); } else { Console.WriteLine(a); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
118
9
using System; using System.Collections.Generic; class TEST { static int height; static int width; static char[,] field; public static void Main() { string[] str = Console.ReadLine().Split( new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); height = int.Parse(str[0]); width = int.Parse(str[1]); // (int x, int y) pointer = (0, 0); field = new char[width, height]; string[,] field_output = new string[width, height]; for (int i = 0; i < height; i++) { int count = 0; foreach (char value in Console.ReadLine()) { field[count, i] = value; count++; } } for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { field_output[x, y] = NumOfBombs(x, y); } } for (int y = height - 1; y >= 0; y--) { for (int x = 0; x < width; x++) { Console.Write(field_output[x, y]); } Console.Write("\r\n"); } // Console.ReadKey(); } static string NumOfBombs(int x, int y) { if (field[x, y] == '#') return "#"; int bombcount = 0; int xs; int ys; for (int i = 0; i < 8; i++) { switch (i) { case 0: xs = 1; ys = 0; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; case 1: xs = 1; ys = -1; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; case 2: xs = 0; ys = -1; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; case 3: xs = -1; ys = -1; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; case 4: xs = -1; ys = 0; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; case 5: xs = -1; ys = 1; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; case 6: xs = 0; ys = 1; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; case 7: xs = 1; ys = 1; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; } } return bombcount.ToString(); } static bool IsValidPos(int nowx, int nowy, int x, int y) { if (nowx + x >= 0 && nowx + x < width) { if (nowy + y >= 0 && nowy + y < height) { return true; } } return false; } }
using System; using System.Collections.Generic; class TEST { static int height; static int width; static char[,] field; public static void Main() { string[] str = Console.ReadLine().Split( new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); height = int.Parse(str[0]); width = int.Parse(str[1]); // (int x, int y) pointer = (0, 0); field = new char[width, height]; string[,] field_output = new string[width, height]; for (int i = height - 1; i >= 0; i--) { int count = 0; foreach (char value in Console.ReadLine()) { field[count, i] = value; count++; } } for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { field_output[x, y] = NumOfBombs(x, y); } } for (int y = height - 1; y >= 0; y--) { for (int x = 0; x < width; x++) { Console.Write(field_output[x, y]); } Console.Write("\r\n"); } // Console.ReadKey(); } static string NumOfBombs(int x, int y) { if (field[x, y] == '#') return "#"; int bombcount = 0; int xs; int ys; for (int i = 0; i < 8; i++) { switch (i) { case 0: xs = 1; ys = 0; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; case 1: xs = 1; ys = -1; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; case 2: xs = 0; ys = -1; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; case 3: xs = -1; ys = -1; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; case 4: xs = -1; ys = 0; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; case 5: xs = -1; ys = 1; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; case 6: xs = 0; ys = 1; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; case 7: xs = 1; ys = 1; if (IsValidPos(x, y, xs, ys)) { if (field[x + xs, y + ys] == '#') { bombcount++; } } break; } } return bombcount.ToString(); } static bool IsValidPos(int nowx, int nowy, int x, int y) { if (nowx + x >= 0 && nowx + x < width) { if (nowy + y >= 0 && nowy + y < height) { return true; } } return false; } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
795
10
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = Reads(); var h = input[0]; var w = input[1]; var s = new char [h][]; for (int i = 0; i < h; i++) { s[i] = Console.ReadLine().ToCharArray(); } var dx = new long[8] { -1, -1, -1, 0, 0, 1, 1, 1 }; var dy = new long[8] { -1, 0, 1, -1, 1, -1, 0, 1 }; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { var count = 0; if (s[i][j] == '.') { for (int k = 0; k < 8; k++) { var ni = i + dx[k]; var nj = j + dy[k]; if (-1 < ni && ni < h && -1 < nj && nj < w) count++; } s[i][j] = (char)('0' + count); } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { Console.Write(s[i][j]); } Console.WriteLine(); } Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = Reads(); var h = input[0]; var w = input[1]; var s = new char [h][]; for (int i = 0; i < h; i++) { s[i] = Console.ReadLine().ToCharArray(); } var dx = new long[8] { -1, -1, -1, 0, 0, 1, 1, 1 }; var dy = new long[8] { -1, 0, 1, -1, 1, -1, 0, 1 }; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { var count = 0; if (s[i][j] == '.') { for (int k = 0; k < 8; k++) { var ni = i + dx[k]; var nj = j + dy[k]; if (-1 < ni && ni < h && -1 < nj && nj < w && s[ni][nj] == '#') count++; } s[i][j] = (char)('0' + count); } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { Console.Write(s[i][j]); } Console.WriteLine(); } Console.Out.Flush(); } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 15, 16, 12, 16, 31, 204, 205, 204, 205, 22], ["+", 12, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 104], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 253]]
8
429
12
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = Reads(); var h = input[0]; var w = input[1]; var s = new char [h][]; for (int i = 0; i < h; i++) { s[i] = Console.ReadLine().ToCharArray(); } Console.WriteLine(s[0][0]); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { var count = 0; if (s[i][j] == '.') { for (int k = -1; k <= 1; k++) { for (int l = -1; l <= 1; l++) { if (i + k < h && -1 < i + k && j + l < w && -1 < j + l && s[i + k][j + l] == '#') count++; } } s[i][j] = (char)('0' + count); } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { Console.Write(s[i][j]); } Console.WriteLine(); } Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = Reads(); var h = input[0]; var w = input[1]; var s = new char [h][]; for (int i = 0; i < h; i++) { s[i] = Console.ReadLine().ToCharArray(); } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { var count = 0; if (s[i][j] == '.') { for (int k = -1; k <= 1; k++) { for (int l = -1; l <= 1; l++) { if (i + k < h && -1 < i + k && j + l < w && -1 < j + l && s[i + k][j + l] == '#') count++; } } s[i][j] = (char)('0' + count); } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { Console.Write(s[i][j]); } Console.WriteLine(); } Console.Out.Flush(); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 204, 205, 204, 205, 22], ["-", 0, 28, 0, 204, 205, 204, 206, 207, 0, 70], ["-", 0, 204, 205, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 28, 0, 204, 205, 204, 206, 207, 0, 73], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
406
13
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramB { // 解説用 static readonly int[] dx = new int[] { -1, 0, 1, -1, 1, -1, 0, 1 }; static readonly int[] dy = new int[] { -1, -1, -1, 0, 0, 1, 1, 1 }; static void Main(string[] args) { var inputs = Console.ReadLine().Split(" "); var h = int.Parse(inputs[0]); var w = int.Parse(inputs[1]); var matrix = new char[h, w]; var count = new int[h, w]; Console.WriteLine("aaaa"); for (var i = 0; i < h; i++) { var list = Console.ReadLine().ToCharArray(); for (var j = 0; j < w; j++) { matrix[i, j] = list[j]; } } for (var i = 0; i < h; i++) { for (var j = 0; j < w; j++) { if (matrix[i, j] != '#') continue; // if (i - 1 >= 0 && j - 1 >= 0) count[i - 1, j - 1]++; // if (i - 1 >= 0) count[i - 1, j]++; // if (i - 1 >= 0 && j + 1 < w) count[i - 1, j + 1]++; // if (j - 1 >= 0) count[i, j - 1]++; // if (j + 1 < w) count[i, j + 1]++; // if (i + 1 < h && j - 1 >= 0) count[i + 1, j - 1]++; // if (i + 1 < h) count[i + 1, j]++; // if (i + 1 < h && j + 1 < w) count[i + 1, j + 1]++; // 解説版 for (var k = 0; k < 8; k++) { var ki = i + dy[k]; var kj = j + dx[k]; if (ki < 0 || h <= ki) continue; if (kj < 0 || w <= kj) continue; count[ki, kj]++; } } } for (var i = 0; i < h; i++) { var t = ""; for (var j = 0; j < w; j++) { t += matrix[i, j] == '#' ? "#" : count[i, j].ToString(); } Console.WriteLine(t); } } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramB { // 解説用 static readonly int[] dx = new int[] { -1, 0, 1, -1, 1, -1, 0, 1 }; static readonly int[] dy = new int[] { -1, -1, -1, 0, 0, 1, 1, 1 }; static void Main(string[] args) { var inputs = Console.ReadLine().Split(" "); var h = int.Parse(inputs[0]); var w = int.Parse(inputs[1]); var matrix = new char[h, w]; var count = new int[h, w]; for (var i = 0; i < h; i++) { var list = Console.ReadLine().ToCharArray(); for (var j = 0; j < w; j++) { matrix[i, j] = list[j]; } } for (var i = 0; i < h; i++) { for (var j = 0; j < w; j++) { if (matrix[i, j] != '#') continue; // if (i - 1 >= 0 && j - 1 >= 0) count[i - 1, j - 1]++; // if (i - 1 >= 0) count[i - 1, j]++; // if (i - 1 >= 0 && j + 1 < w) count[i - 1, j + 1]++; // if (j - 1 >= 0) count[i, j - 1]++; // if (j + 1 < w) count[i, j + 1]++; // if (i + 1 < h && j - 1 >= 0) count[i + 1, j - 1]++; // if (i + 1 < h) count[i + 1, j]++; // if (i + 1 < h && j + 1 < w) count[i + 1, j + 1]++; // 解説版 for (var k = 0; k < 8; k++) { var ki = i + dy[k]; var kj = j + dx[k]; if (ki < 0 || h <= ki) continue; if (kj < 0 || w <= kj) continue; count[ki, kj]++; } } } for (var i = 0; i < h; i++) { var t = ""; for (var j = 0; j < w; j++) { t += matrix[i, j] == '#' ? "#" : count[i, j].ToString(); } Console.WriteLine(t); } } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
426
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int h = sc.NextInt(); int w = sc.NextInt(); bool[,] bomb = new bool[h, w]; for (int i = 0; i < h; i++) { string str = sc.Next(); for (int j = 0; j < w; j++) { bomb[i, j] = str[j] == '#'; } } string[,] answer = new string[h, w]; for (int i = 0; i < h; i++) { string str = sc.Next(); for (int j = 0; j < w; j++) { if (bomb[i, j]) { answer[i, j] = "#"; continue; } int count = 0; for (int k = -1; k <= 1; k++) { for (int l = -1; l <= 1; l++) { if (i + k < 0 || i + k >= h || j + l < 0 || j + l >= w) { continue; } if (k == 0 && l == 0) { continue; } if (bomb[i + k, j + l]) { count++; } } } answer[i, j] = count.ToString(); } } for (int i = 0; i < h; i++) { string str = ""; for (int j = 0; j < w; j++) { str += answer[i, j]; } Console.WriteLine(str); } } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int h = sc.NextInt(); int w = sc.NextInt(); bool[,] bomb = new bool[h, w]; for (int i = 0; i < h; i++) { string str = sc.Next(); for (int j = 0; j < w; j++) { bomb[i, j] = str[j] == '#'; } } string[,] answer = new string[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (bomb[i, j]) { answer[i, j] = "#"; continue; } int count = 0; for (int k = -1; k <= 1; k++) { for (int l = -1; l <= 1; l++) { if (i + k < 0 || i + k >= h || j + l < 0 || j + l >= w) { continue; } if (k == 0 && l == 0) { continue; } if (bomb[i + k, j + l]) { count++; } } } answer[i, j] = count.ToString(); } } for (int i = 0; i < h; i++) { string str = ""; for (int j = 0; j < w; j++) { str += answer[i, j]; } Console.WriteLine(str); } } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35]]
8
670
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static bool[,] map; static void Main(string[] args) { int[] line = Console.ReadLine().Split().Select(int.Parse).ToArray(); map = new bool[line[0], line[1]]; for (int i = 0; i < line[0]; i++) { var a = Console.ReadLine(); for (int j = 0; j < a.Length; j++) { if (a[j] == '.') map[i, j] = false; else map[i, j] = true; } } for (int i = 0; i < line[0]; i++) { for (int j = 0; j < line[1]; j++) { if (j == line[1] - 1) { var a = check(i, j); if (a == "0") a = "#"; if (map[i, j] == false) Console.WriteLine("{0}", a); else Console.WriteLine("#"); } else { var a = check(i, j); if (a == "0") a = "#"; if (map[i, j] == false) Console.Write("{0}", a); else Console.Write("#"); } } } } private static string check(int y, int x) { int count = 0; for (int i = -1; i < 2; i++) { for (int j = 1; j > -2; j--) { if (i == 0 && j == 0) continue; try { if (map[y + j, x + i] == true) count++; } catch { } } } return count.ToString(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static bool[,] map; static void Main(string[] args) { int[] line = Console.ReadLine().Split().Select(int.Parse).ToArray(); map = new bool[line[0], line[1]]; for (int i = 0; i < line[0]; i++) { var a = Console.ReadLine(); for (int j = 0; j < a.Length; j++) { if (a[j] == '.') map[i, j] = false; else map[i, j] = true; } } for (int i = 0; i < line[0]; i++) { for (int j = 0; j < line[1]; j++) { if (j == line[1] - 1) { var a = check(i, j); if (map[i, j] == false) Console.WriteLine("{0}", a); else Console.WriteLine("#"); } else { var a = check(i, j); if (map[i, j] == false) Console.Write("{0}", a); else Console.Write("#"); } } } } private static string check(int y, int x) { int count = 0; for (int i = -1; i < 2; i++) { for (int j = 1; j > -2; j--) { if (i == 0 && j == 0) continue; try { if (map[y + j, x + i] == true) count++; } catch { } } } return count.ToString(); } }
[["-", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["-", 64, 196, 0, 57, 15, 16, 12, 5, 0, 62], ["-", 64, 196, 0, 57, 15, 16, 12, 5, 0, 222], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 1, 0, 11, 12, 5, 0, 62], ["-", 0, 57, 64, 1, 0, 11, 12, 5, 0, 222], ["-", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["-", 75, 196, 0, 57, 15, 16, 12, 5, 0, 62], ["-", 75, 196, 0, 57, 15, 16, 12, 5, 0, 222], ["-", 75, 196, 0, 57, 64, 1, 0, 11, 31, 22]]
8
428
28
using System; using System.Collections.Generic; using System.Linq; class Solution { static int h; static int w; static int Count(char[][] field, int x, int y) { int count = 0; for (int xx = x - 1; xx <= x + 1; xx++) { for (int yy = y - 1; yy <= y + 1; yy++) { if (0 <= xx && xx < w && 0 <= yy && yy < h) { if (field[yy][xx] == '#') { count++; } } } } return count; } static void Solve(char[][] field) { for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if (field[y][x] == '.') { var count = Count(field, x, y); if (count > 0) { field[y][x] = count.ToString()[0]; } } } } } static void Main() { var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); h = vals[0]; w = vals[1]; var field = new char [h][]; for (int i = 0; i < h; i++) { field[i] = Console.ReadLine().ToCharArray(); } Solve(field); for (int i = 0; i < h; i++) { Console.WriteLine(new string(field[i])); } } }
using System; using System.Collections.Generic; using System.Linq; class Solution { static int h; static int w; static int Count(char[][] field, int x, int y) { int count = 0; for (int xx = x - 1; xx <= x + 1; xx++) { for (int yy = y - 1; yy <= y + 1; yy++) { if (0 <= xx && xx < w && 0 <= yy && yy < h) { if (field[yy][xx] == '#') { count++; } } } } return count; } static void Solve(char[][] field) { for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if (field[y][x] == '.') { var count = Count(field, x, y); field[y][x] = count.ToString()[0]; } } } } static void Main() { var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); h = vals[0]; w = vals[1]; var field = new char [h][]; for (int i = 0; i < h; i++) { field[i] = Console.ReadLine().ToCharArray(); } Solve(field); for (int i = 0; i < h; i++) { Console.WriteLine(new string(field[i])); } } }
[["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
356
8
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Numerics; class Myon { // chokudaiさんのコードをコピペ static Scanner cin; public Myon() {} public static int Main() { // Console.SetOut(new Printer(Console.OpenStandardOutput())); cin = new Scanner(); new Myon().calc(); return 0; } public void calc() { int n = cin.nextInt(); // System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); // sw.Start(); int m = cin.nextInt(); List<int> a = new List<int>(m); List<int> b = new List<int>(m); for (int i = 0; i < m; i++) { a.Add(cin.nextInt()); b.Add(cin.nextInt()); } int ans = 0; List<int> bridge = new List<int>(); for (int i = 0; i < m; i++) { tempConnected = new bool[m + 1]; AddConnected(0, a, b, i); bool allconnected = true; for (int j = 1; j < m + 1; j++) if (!tempConnected[j]) { allconnected = false; break; } if (!allconnected) { // bridge.Add(i + 1); ans++; } } showL(ans); // sw.Stop(); // showL($"処理時間: {sw.ElapsedMilliseconds} [msec]"); } bool[] tempConnected; public void AddConnected(int index, List<int> a, List<int> b, int ignoreingBridge = -1) { // i番目のノードにつながるノードをconnectedにする for (int i = 0; i < a.Count; i++) { if (i == ignoreingBridge) continue; if (a[i] == index && !tempConnected[b[i]]) { tempConnected[b[i]] = true; AddConnected(b[i], a, b, ignoreingBridge); } else if (b[i] == index && !tempConnected[a[i]]) { tempConnected[a[i]] = true; AddConnected(a[i], a, b, ignoreingBridge); } } } public void backetSort(ref int[] a) { // max a << a.len に対して有効なソート //よってa = int[] とする long n = a.Length; var count = new int[n]; var loc = new long[n]; // loc[i] は i が終わる 位置 max index where c[index] // = loc[i] for (long i = 0; i < n; i++) count[a[i]]++; loc[0] = count[0] - 1; for (long i = 0; i < n - 1; i++) loc[i + 1] = loc[i] + count[i + 1]; long index = 0; for (int i = 0; i < n; i++) { while (index <= loc[i]) a[index++] = i; // incex <= loc[i] == index < loc[i] + 1 } } public static void showL<T>(T s) { Console.WriteLine(s); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { while (i >= s.Length) { string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; } return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } class SMath { /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 12 なら 2,2,3 です。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> Factorization(long n) { if (n <= 0) return null; List<long> output = new List<long>(); int i = 2; long max = (long)Math.Sqrt(n); ; while (n > 1) { if (i > max) { output.Add(n); break; } while (n % i == 0) { output.Add(i); n /= i; } i++; } return output; } /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 84 = (2^2 * 3 * 7) なら 2, 1, 0, 1  remainder = 1です。(打ち切られない) /// 13 = 0,0,...0 remainder = 2019 /// ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) /// </summary> /// <param name="n"></param> /// <param name="remainder"></param> /// <returns></returns> public static List<long> Factorization(long n, out long remainder) { // output[i] が i-1番目の素数の数を示す //ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) remainder = 1; if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; long max = (long)Math.Sqrt(n); bool[] isNOTPrime = new bool[max + 1]; while (n > 1) { if (tempn > max) { remainder = n; break; } if (!isNOTPrime[tempn]) { output.Add(0); while (n % tempn == 0) { output[output.Count - 1]++; n /= tempn; } for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } /// <summary> /// i番目の素数をoutput[i-1]に返します。 /// ただしnより大きい素数については判定しません。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> GetPrimeNumbers(long n) { if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; bool[] isNOTPrime = new bool[n + 1]; while (n > 1) { if (tempn > n) { break; } if (!isNOTPrime[tempn]) { output.Add(tempn); for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } private static long[][] combMemo; private static int maxn_combination = -1; public static long Combination(int n, int k) { if (n < 0 || k > n) return 0; if (n == k || k == 0) return 1; if (k > n / 2) return Combination(n, n - k); if (maxn_combination < n) { maxn_combination = n; combMemo = new long [n + 1][]; } if (combMemo[n] == null) combMemo[n] = new long[n / 2 + 1]; if (combMemo[n][k] != 0) return combMemo[n][k]; else { combMemo[n][k] = Combination(n - 1, k) + Combination(n - 1, k - 1); return combMemo[n][k]; } } public static long Gcd(long a, long b) { if (a <= 0) return -1; // if (a > b) return gcd(b, a); if (b == 0) return a; return Gcd(b, a % b); } public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Numerics; class Myon { // chokudaiさんのコードをコピペ static Scanner cin; public Myon() {} public static int Main() { // Console.SetOut(new Printer(Console.OpenStandardOutput())); cin = new Scanner(); new Myon().calc(); return 0; } public void calc() { int n = cin.nextInt(); // System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); // sw.Start(); int m = cin.nextInt(); List<int> a = new List<int>(m); List<int> b = new List<int>(m); for (int i = 0; i < m; i++) { a.Add(cin.nextInt()); b.Add(cin.nextInt()); } int ans = 0; List<int> bridge = new List<int>(); for (int i = 0; i < m; i++) { tempConnected = new bool[n]; AddConnected(1, a, b, i); bool allconnected = true; for (int j = 0; j < n; j++) if (!tempConnected[j]) { allconnected = false; break; } if (!allconnected) { bridge.Add(i + 1); ans++; } // else //{ // showL($"{i + 1} is not bridge"); //} } showL(ans); // sw.Stop(); // showL($"処理時間: {sw.ElapsedMilliseconds} [msec]"); } bool[] tempConnected; public void AddConnected(int index, List<int> a, List<int> b, int ignoreingBridge = -1) { // index番目のノードにつながるノードをconnectedにして、さらにaddconnectedを呼び出す for (int i = 0; i < a.Count; i++) { if (i == ignoreingBridge) continue; if (a[i] - 1 == index && !tempConnected[b[i] - 1]) { tempConnected[b[i] - 1] = true; AddConnected(b[i] - 1, a, b, ignoreingBridge); } else if (b[i] - 1 == index && !tempConnected[a[i] - 1]) { tempConnected[a[i] - 1] = true; AddConnected(a[i] - 1, a, b, ignoreingBridge); } } } public void backetSort(ref int[] a) { // max a << a.len に対して有効なソート //よってa = int[] とする long n = a.Length; var count = new int[n]; var loc = new long[n]; // loc[i] は i が終わる 位置 max index where c[index] // = loc[i] for (long i = 0; i < n; i++) count[a[i]]++; loc[0] = count[0] - 1; for (long i = 0; i < n - 1; i++) loc[i + 1] = loc[i] + count[i + 1]; long index = 0; for (int i = 0; i < n; i++) { while (index <= loc[i]) a[index++] = i; // incex <= loc[i] == index < loc[i] + 1 } } public static void showL<T>(T s) { Console.WriteLine(s); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { while (i >= s.Length) { string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; } return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } class SMath { /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 12 なら 2,2,3 です。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> Factorization(long n) { if (n <= 0) return null; List<long> output = new List<long>(); int i = 2; long max = (long)Math.Sqrt(n); ; while (n > 1) { if (i > max) { output.Add(n); break; } while (n % i == 0) { output.Add(i); n /= i; } i++; } return output; } /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 84 = (2^2 * 3 * 7) なら 2, 1, 0, 1  remainder = 1です。(打ち切られない) /// 13 = 0,0,...0 remainder = 2019 /// ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) /// </summary> /// <param name="n"></param> /// <param name="remainder"></param> /// <returns></returns> public static List<long> Factorization(long n, out long remainder) { // output[i] が i-1番目の素数の数を示す //ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) remainder = 1; if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; long max = (long)Math.Sqrt(n); bool[] isNOTPrime = new bool[max + 1]; while (n > 1) { if (tempn > max) { remainder = n; break; } if (!isNOTPrime[tempn]) { output.Add(0); while (n % tempn == 0) { output[output.Count - 1]++; n /= tempn; } for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } /// <summary> /// i番目の素数をoutput[i-1]に返します。 /// ただしnより大きい素数については判定しません。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> GetPrimeNumbers(long n) { if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; bool[] isNOTPrime = new bool[n + 1]; while (n > 1) { if (tempn > n) { break; } if (!isNOTPrime[tempn]) { output.Add(tempn); for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } private static long[][] combMemo; private static int maxn_combination = -1; public static long Combination(int n, int k) { if (n < 0 || k > n) return 0; if (n == k || k == 0) return 1; if (k > n / 2) return Combination(n, n - k); if (maxn_combination < n) { maxn_combination = n; combMemo = new long [n + 1][]; } if (combMemo[n] == null) combMemo[n] = new long[n / 2 + 1]; if (combMemo[n][k] != 0) return combMemo[n][k]; else { combMemo[n][k] = Combination(n - 1, k) + Combination(n - 1, k - 1); return combMemo[n][k]; } } public static long Gcd(long a, long b) { if (a <= 0) return -1; // if (a > b) return gcd(b, a); if (b == 0) return a; return Gcd(b, a % b); } public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } }
[["-", 12, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["-", 12, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["-", 12, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 75, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 75, 57, 15, 16, 31, 16, 31, 16, 12, 203]]
8
1,503
37
using System; using System.Collections.Generic; using System.Text; namespace AtTest.ForBlue.ABC_075 { class C { static int n; static Node[] nodes; static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { string[] input = Console.ReadLine().Split(' '); n = int.Parse(input[0]); int m = int.Parse(input[1]); nodes = new Node[n]; for (int i = 0; i < n; i++) { nodes[i] = new Node(); } for (int i = 0; i < m; i++) { string[] inText = Console.ReadLine().Split(' '); int a = int.Parse(inText[0]) - 1; int b = int.Parse(inText[1]) - 1; nodes[a].to.Add(b); nodes[b].to.Add(a); } long cnt = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < nodes[i].to.Count; j++) { int toTemp = nodes[i].to[0]; if (toTemp < i) continue; for (int k = 0; k < nodes.Length; k++) { nodes[k].wasVisited = false; } nodes[i].to.RemoveAt(0); nodes[toTemp].to.Remove(i); nodes[0].wasVisited = true; int visitCnt = 1; if (!DFS(0, ref visitCnt)) { // Console.WriteLine(i.ToString() + " " + toTemp.ToString()); cnt++; } nodes[i].to.Add(toTemp); nodes[toTemp].to.Add(i); } } Console.WriteLine(cnt); } static bool DFS(int index, ref int visitCnt) { if (visitCnt == n) //全部行った { return true; } //行ける場所探索 for (int i = 0; i < nodes[index].to.Count; i++) { if (!nodes[nodes[index].to[i]].wasVisited) { visitCnt++; nodes[nodes[index].to[i]].wasVisited = true; if (DFS(nodes[index].to[i], ref visitCnt)) { return true; } } } Console.WriteLine(visitCnt); return false; } } class Node { public List<int> to; public bool wasVisited; public Node() { to = new List<int>(); wasVisited = false; } } }
using System; using System.Collections.Generic; using System.Text; namespace AtTest.ForBlue.ABC_075 { class C { static int n; static Node[] nodes; static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { string[] input = Console.ReadLine().Split(' '); n = int.Parse(input[0]); int m = int.Parse(input[1]); nodes = new Node[n]; for (int i = 0; i < n; i++) { nodes[i] = new Node(); } for (int i = 0; i < m; i++) { string[] inText = Console.ReadLine().Split(' '); int a = int.Parse(inText[0]) - 1; int b = int.Parse(inText[1]) - 1; nodes[a].to.Add(b); nodes[b].to.Add(a); } long cnt = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < nodes[i].to.Count; j++) { int toTemp = nodes[i].to[0]; if (toTemp < i) continue; for (int k = 0; k < nodes.Length; k++) { nodes[k].wasVisited = false; } nodes[i].to.RemoveAt(0); nodes[toTemp].to.Remove(i); nodes[0].wasVisited = true; int visitCnt = 1; if (!DFS(0, ref visitCnt)) { // Console.WriteLine(i.ToString() + " " + toTemp.ToString()); cnt++; } nodes[i].to.Add(toTemp); nodes[toTemp].to.Add(i); } } Console.WriteLine(cnt); } static bool DFS(int index, ref int visitCnt) { if (visitCnt == n) //全部行った { return true; } //行ける場所探索 for (int i = 0; i < nodes[index].to.Count; i++) { if (!nodes[nodes[index].to[i]].wasVisited) { visitCnt++; nodes[nodes[index].to[i]].wasVisited = true; if (DFS(nodes[index].to[i], ref visitCnt)) { return true; } } } // Console.WriteLine(visitCnt); return false; } } class Node { public List<int> to; public bool wasVisited; public Node() { to = new List<int>(); wasVisited = false; } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
570
7
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.D { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var (N, K) = Read2Longs(); var points = new List<Point>(); for (int i = 0; i < N; i++) { var (x, y) = Read2Longs(); points.Add(new Point { X = x, Y = y }); } points = points.OrderBy(x => x.X).ToList(); var min = long.MaxValue; for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { // 点が明らかにK個以下なので if (j - i + 1 < K) continue; var ps = points.Skip(i).Take(j - i + 1).OrderBy(x => x.Y).ToList(); for (int ii = 0; ii < ps.Count - 1; ii++) { for (int jj = 0; jj < ps.Count; jj++) { // 点が明らかにK個以下なので if (jj - ii + 1 < K) continue; { var ps2 = ps.Skip(ii).Take(jj - ii + 1).ToList(); var rec = Math.Abs(ps.Max(x => x.X) - ps.Min(x => x.X)) * Math.Abs(ps.Max(x => x.Y) - ps.Min(x => x.Y)); min = Math.Min(min, rec); } } } } } return min; } [DebuggerDisplay("{X},{Y}")] class Point { public long X { get; set; } public long Y { get; set; } } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.D { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var (N, K) = Read2Longs(); var points = new List<Point>(); for (int i = 0; i < N; i++) { var (x, y) = Read2Longs(); points.Add(new Point { X = x, Y = y }); } points = points.OrderBy(x => x.X).ToList(); var min = long.MaxValue; for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { // 点が明らかにK個以下なので if (j - i + 1 < K) continue; var xPoints = points.Skip(i).Take(j - i + 1).OrderBy(x => x.Y).ToList(); for (int ii = 0; ii < xPoints.Count - 1; ii++) { for (int jj = 0; jj < xPoints.Count; jj++) { // 点が明らかにK個以下なので if (jj - ii + 1 < K) continue; { var xyPoints = xPoints.Skip(ii).Take(jj - ii + 1).ToList(); var rec = Math.Abs(xyPoints.Max(x => x.X) - xyPoints.Min(x => x.X)) * Math.Abs(xyPoints.Max(x => x.Y) - xyPoints.Min(x => x.Y)); min = Math.Min(min, rec); } } } } } return min; } [DebuggerDisplay("{X},{Y}")] class Point { public long X { get; set; } public long Y { get; set; } } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 16, 31, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 0, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22]]
8
696
18
using System; using System.Collections.Generic; namespace ABC { class ABC075D { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); //全点数 int K = int.Parse(str[1]); //包含してほしい点数 var PointXs = new List<UInt64>(N); var PointYs = new List<UInt64>(N); var xList = new List<UInt64>(N); var yList = new List<UInt64>(N); for (int i = 0; i < N; ++i) { string[] s = Console.ReadLine().Split(' '); UInt64 x = (UInt64) int.Parse(s[0]); PointXs.Add(x); xList.Add(x); UInt64 y = (UInt64) int.Parse(s[1]); PointYs.Add(y); yList.Add(y); } //座標をソート xList.Sort(); yList.Sort(); UInt64 minArea = UInt64.MaxValue; for (int xi = 0; xi < PointXs.Count; ++xi) //矩形の端点のx座標について. { for (int xj = xi + 1; xj < PointXs.Count; ++xj) //もう一方の端点のx座標について { var lx = xList[xi]; //矩形の左のX座標 var rx = xList[xj]; //右 for (int yi = 0; yi < PointYs.Count; ++yi) //矩形の端点のy座標について { for (int yj = yi + 1; yj < PointYs.Count; ++yj) //もう一方の端点のy座標について { var by = yList[yi]; //下 var uy = yList[yj]; //上 //その矩形が内包する点の数を計算 int num = 0; for (int i = 0; i < N; ++i) { if (lx <= PointXs[i] && PointXs[i] <= rx && by <= PointYs[i] && PointYs[i] <= uy) { ++num; } } if (num >= K) { UInt64 area = (rx - lx) * (uy - by); minArea = Math.Min(minArea, area); } } } } } Console.WriteLine("{0}", minArea); } } }
using System; using System.Collections.Generic; namespace ABC { class ABC075D { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); //全点数 int K = int.Parse(str[1]); //包含してほしい点数 var PointXs = new List<Int64>(N); var PointYs = new List<Int64>(N); var xList = new List<Int64>(N); var yList = new List<Int64>(N); for (int i = 0; i < N; ++i) { string[] s = Console.ReadLine().Split(' '); Int64 x = (Int64) int.Parse(s[0]); PointXs.Add(x); xList.Add(x); Int64 y = (Int64) int.Parse(s[1]); PointYs.Add(y); yList.Add(y); } //座標をソート xList.Sort(); yList.Sort(); UInt64 minArea = UInt64.MaxValue; for (int xi = 0; xi < N; ++xi) //矩形の端点のx座標について. { for (int xj = xi + 1; xj < N; ++xj) //もう一方の端点のx座標について { var lx = xList[xi]; //矩形の左のX座標 var rx = xList[xj]; //右 for (int yi = 0; yi < N; ++yi) //矩形の端点のy座標について { for (int yj = yi + 1; yj < N; ++yj) //もう一方の端点のy座標について { var by = yList[yi]; //下 var uy = yList[yj]; //上 //その矩形が内包する点の数を計算 int num = 0; for (int i = 0; i < N; ++i) { if (lx <= PointXs[i] && PointXs[i] <= rx && by <= PointYs[i] && PointYs[i] <= uy) { ++num; } } if (num >= K) { UInt64 area = (UInt64)((rx - lx) * (uy - by)); minArea = Math.Min(minArea, area); } } } } } Console.WriteLine("{0}", minArea); } } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 22], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 22], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 0, 74, 51, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 74, 51, 23, 0, 16, 12, 23, 0, 25]]
8
455
37
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif //#define TOPCODER using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; using System.Security.Cryptography; using static UtakaApp.Util; namespace UtakaApp { public partial class Program { /* https://atcoder.jp/contests/abc075/tasks/abc075_d */ public const string SiteName = "AtCoder"; public const string ContestName = "abc075"; public const string ProblemName = "D"; public void Solve() { int N = cin.ReadInt; int K = cin.ReadInt; long[] X = new long[N]; long[] Y = new long[N]; // Point[] points = new Point[N]; for (int i = 0; i < N; i++) { X[i] = cin.ReadLong; Y[i] = cin.ReadLong; } Array.Sort(X); Array.Sort(Y); var compX = new CoordinateCompression(X); var compY = new CoordinateCompression(Y); int[][] T = JagArray2D<int>(compY.Size + 1, compX.Size + 1); // int[][] T = JagArray2D<int>(N + 1, N + 1); for (int i = 0; i < N; i++) { int xInd = compX.ToIndex(X[i]); int yInd = compY.ToIndex(Y[i]); T[yInd + 1][xInd + 1]++; } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { T[i][j] += T[i][j - 1]; } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { T[i][j] += T[i - 1][j]; } } long minArea = long.MaxValue; for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { for (int k = i; k <= N; k++) { for (int l = j; l <= N; l++) { int count = T[k][l] + T[i - 1][j - 1] - T[k][j - 1] - T[i - 1][l]; if (count < K) continue; long area = (compY.GetValue(k - 1) - compY.GetValue(i - 1)) * (compX.GetValue(l - 1) - compX.GetValue(j - 1)); minArea = Math.Min(minArea, area); } } } } cou.WriteLine(minArea); } /// <summary> /// 座標圧縮 /// 1軸 /// 同じ値のものがあれば重複分は消える /// </summary> public class CoordinateCompression { public int Size; // 圧縮後のサイズ public long[] A; // 圧縮後の配列 同じ値については要素数は減っている public CoordinateCompression(long[] aIn) { // aInをコピー int n = aIn.Length; long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = aIn[i]; } // 昇順ソート Array.Sort(a); List<long> list = new List<long>(); list.Add(a[0]); for (int i = 1; i < n; i++) { if (a[i] != a[i - 1]) { list.Add(a[i]); } } A = list.ToArray(); Size = A.Length; } // 返り値がSizeだったら解無し public int ToIndex(long x) { int ng = -1; int ok = Size; while (ok - ng > 1) { int mid = ng + (ok - ng) / 2; if (A[mid] >= x) { ok = mid; } else { ng = mid; } } return ok; } public long GetValue(int i) { return A[i]; } } } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } #if !TOPCODER public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } #endif public void WriteEnumerable<T>(IEnumerable<T> A, string delimiter = " ") { if (!A.Any()) { return; } var sb = new StringBuilder(); foreach (T v in A) { sb.Append(v); sb.Append(delimiter); } if (sb.Length > 0) { sb.Length--; } cou.WriteLine(sb.ToString()); } } public static class Util { public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static int UpperBound<T>(List<T> list, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(list[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(List<T> list, T value) { return UpperBound(list, 0, list.Count, value, Comparer<T>.Default); } public static T[] Array1D<T>(int a, T defaultValue) where T : struct { var ret = new T[a]; for (int i = 0; i < a; i++) { ret[i] = defaultValue; } return ret; } public static T[] Array1D<T>(int a) where T : struct { var ret = new T[a]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue) where T : struct { T[,,] ret = new T[a, b, c]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { for (int k = 0; k < c; k++) { ret[i, j, k] = defaultValue; } } } return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { var row = new T[b]; ret[i] = row; for (int j = 0; j < b; j++) { row[j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; for (int k = 0; k < c; k++) { bRow[k] = defaultValue; } } } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d, T defaultValue) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; for (int l = 0; l < d; l++) { cRow[l] = defaultValue; } } } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e, T defaultValue) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; for (int m = 0; m < e; m++) { dRow[m] = defaultValue; } } } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; } } } } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray2D<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public static class UtakaExtentions { /// <summary> /// IList<T>をコピーします /// </summary> public static T[] Copy<T>(this IList<T> a) { T[] ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } /// <summary> /// 2次元ジャグ配列をコピーして返す。 /// </summary> public static T[][] Copy<T>(this T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } /// <summary> /// 昇順にソートされたlong配列で、threshold以上の値をカウントする /// </summary> public static int LargerCount(this long[] a, long threshold) { int ng = -1; int ok = a.Length; while (Math.Abs(ng - ok) > 1) { int mid = (ok + ng) / 2; if (threshold <= a[mid]) { ok = mid; } else { ng = mid; } } return a.Length - ok; } } public class IntLargeComparer : IComparer<int> { public static IntLargeComparer Instance = new IntLargeComparer(); public int Compare(int x, int y) { return y - x; } } public class LongLargeComparer : IComparer<long> { public static LongLargeComparer Instance = new LongLargeComparer(); public int Compare(long x, long y) { if (x > y) return -1; if (x < y) return 1; return 0; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public int[] ReadIntArrayMinus1(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt - 1; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; bool foundTargetTest = targetTestCaseNumber == testCaseNumber; if (targetTestCaseNumber >= 0 && !foundTargetTest) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } if (foundTargetTest) { break; } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif public static class Dbg { [Conditional("UTAKA_DEBUG")] public static void WriteLine(string str) { Console.WriteLine(str); } [Conditional("UTAKA_DEBUG")] public static void WriteLine() { Console.WriteLine(); } [Conditional("UTAKA_DEBUG")] public static void Write(string str) { Console.Write(str); } } }
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif //#define TOPCODER using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; using System.Security.Cryptography; using static UtakaApp.Util; namespace UtakaApp { public partial class Program { /* https://atcoder.jp/contests/abc075/tasks/abc075_d */ public const string SiteName = "AtCoder"; public const string ContestName = "abc075"; public const string ProblemName = "D"; public void Solve() { int N = cin.ReadInt; int K = cin.ReadInt; long[] X = new long[N]; long[] Y = new long[N]; // Point[] points = new Point[N]; for (int i = 0; i < N; i++) { X[i] = cin.ReadLong; Y[i] = cin.ReadLong; } var compX = new CoordinateCompression(X); var compY = new CoordinateCompression(Y); int[][] T = JagArray2D<int>(compY.Size + 1, compX.Size + 1); // int[][] T = JagArray2D<int>(N + 1, N + 1); for (int i = 0; i < N; i++) { int xInd = compX.ToIndex(X[i]); int yInd = compY.ToIndex(Y[i]); T[yInd + 1][xInd + 1]++; } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { T[i][j] += T[i][j - 1]; } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { T[i][j] += T[i - 1][j]; } } long minArea = long.MaxValue; for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { for (int k = i; k <= N; k++) { for (int l = j; l <= N; l++) { int count = T[k][l] + T[i - 1][j - 1] - T[k][j - 1] - T[i - 1][l]; if (count < K) continue; long area = (compY.GetValue(k - 1) - compY.GetValue(i - 1)) * (compX.GetValue(l - 1) - compX.GetValue(j - 1)); minArea = Math.Min(minArea, area); } } } } cou.WriteLine(minArea); } /// <summary> /// 座標圧縮 /// 1軸 /// 同じ値のものがあれば重複分は消える /// /// TODO:二次元座標に対応させる /// </summary> public class CoordinateCompression { public int Size; // 圧縮後のサイズ public long[] A; // 圧縮後の配列 同じ値については要素数は減っている /// <summary> /// NOTE: aInはソート済みでなくてもよい /// </summary> public CoordinateCompression(long[] aIn) { // aInをコピー int n = aIn.Length; long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = aIn[i]; } // 昇順ソート Array.Sort(a); List<long> list = new List<long>(); list.Add(a[0]); for (int i = 1; i < n; i++) { if (a[i] != a[i - 1]) { list.Add(a[i]); } } A = list.ToArray(); Size = A.Length; } /// <summary> /// 座標値からindexを返す /// Sizeを返した場合はすべての点が与えた座標e /// </summary> public int ToIndex(long x) { int ng = -1; int ok = Size; while (ok - ng > 1) { int mid = ng + (ok - ng) / 2; if (A[mid] >= x) { ok = mid; } else { ng = mid; } } return ok; } public long GetValue(int i) { return A[i]; } } } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } #if !TOPCODER public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } #endif public void WriteEnumerable<T>(IEnumerable<T> A, string delimiter = " ") { if (!A.Any()) { return; } var sb = new StringBuilder(); foreach (T v in A) { sb.Append(v); sb.Append(delimiter); } if (sb.Length > 0) { sb.Length--; } cou.WriteLine(sb.ToString()); } } public static class Util { public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static int UpperBound<T>(List<T> list, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(list[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(List<T> list, T value) { return UpperBound(list, 0, list.Count, value, Comparer<T>.Default); } public static T[] Array1D<T>(int a, T defaultValue) where T : struct { var ret = new T[a]; for (int i = 0; i < a; i++) { ret[i] = defaultValue; } return ret; } public static T[] Array1D<T>(int a) where T : struct { var ret = new T[a]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue) where T : struct { T[,,] ret = new T[a, b, c]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { for (int k = 0; k < c; k++) { ret[i, j, k] = defaultValue; } } } return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { var row = new T[b]; ret[i] = row; for (int j = 0; j < b; j++) { row[j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; for (int k = 0; k < c; k++) { bRow[k] = defaultValue; } } } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d, T defaultValue) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; for (int l = 0; l < d; l++) { cRow[l] = defaultValue; } } } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e, T defaultValue) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; for (int m = 0; m < e; m++) { dRow[m] = defaultValue; } } } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; } } } } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray2D<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public static class UtakaExtentions { /// <summary> /// IList<T>をコピーします /// </summary> public static T[] Copy<T>(this IList<T> a) { T[] ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } /// <summary> /// 2次元ジャグ配列をコピーして返す。 /// </summary> public static T[][] Copy<T>(this T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } /// <summary> /// 昇順にソートされたlong配列で、threshold以上の値をカウントする /// </summary> public static int LargerCount(this long[] a, long threshold) { int ng = -1; int ok = a.Length; while (Math.Abs(ng - ok) > 1) { int mid = (ok + ng) / 2; if (threshold <= a[mid]) { ok = mid; } else { ng = mid; } } return a.Length - ok; } } public class IntLargeComparer : IComparer<int> { public static IntLargeComparer Instance = new IntLargeComparer(); public int Compare(int x, int y) { return y - x; } } public class LongLargeComparer : IComparer<long> { public static LongLargeComparer Instance = new LongLargeComparer(); public int Compare(long x, long y) { if (x > y) return -1; if (x < y) return 1; return 0; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public int[] ReadIntArrayMinus1(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt - 1; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; bool foundTargetTest = targetTestCaseNumber == testCaseNumber; if (targetTestCaseNumber >= 0 && !foundTargetTest) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } if (foundTargetTest) { break; } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif public static class Dbg { [Conditional("UTAKA_DEBUG")] public static void WriteLine(string str) { Console.WriteLine(str); } [Conditional("UTAKA_DEBUG")] public static void WriteLine() { Console.WriteLine(); } [Conditional("UTAKA_DEBUG")] public static void Write(string str) { Console.Write(str); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
4,659
14
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; class Program { static void Main(string[] args) { string[] s1 = Console.ReadLine().Split(' '); char[] a = s1[0].ToCharArray(); char[] b = s1[1].ToCharArray(); if (a[0] > b[0]) { Console.WriteLine(">"); } else { Console.WriteLine("<"); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; class Program { static void Main(string[] args) { string[] s1 = Console.ReadLine().Split(' '); char[] a = s1[0].ToCharArray(); char[] b = s1[1].ToCharArray(); if (a[0] > b[0]) { Console.WriteLine(">"); } else if (a[0] < b[0]) { Console.WriteLine("<"); } else { Console.WriteLine("="); } } }
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 204, 205, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 12, 204, 205, 22], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
131
24
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { var n = Console.ReadLine().Split().Select(x => double.Parse(x)).ToList(); var length = n[0] - n[2]; Console.WriteLine(Math.Ceiling(length / n[1]) - 1); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { var n = Console.ReadLine().Split().Select(x => double.Parse(x)).ToList(); var length = n[0] - n[2]; Console.WriteLine(Math.Floor(length / (n[1] + n[2]))); } }
[["-", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
87
11
using System; class Program { static void Main(string[] args) { string[] num = Console.ReadLine().Split(' '); int x = int.Parse(num[0]); int y = int.Parse(num[1]); int z = int.Parse(num[2]); int reserve = x - (y + 1) * z; Console.WriteLine(reserve / y); } }
using System; class Program { static void Main(string[] args) { string[] num = Console.ReadLine().Split(' '); int x = int.Parse(num[0]); int y = int.Parse(num[1]); int z = int.Parse(num[2]); int reserve = x - z; Console.WriteLine(reserve / (y + z)); } }
[["-", 0, 212, 0, 16, 12, 16, 31, 23, 0, 24], ["-", 0, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 16, 12, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 212, 0, 16, 12, 16, 31, 23, 0, 25], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
97
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Atcoderrrrrrr { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int X = int.Parse(s[0]); int Y = int.Parse(s[1]); int Z = int.Parse(s[2]); int ans = 0; for (int i = 0; X > 0; i++) { X -= (Y + Z); if (X > 0) { ans++; } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Atcoderrrrrrr { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int X = int.Parse(s[0]); int Y = int.Parse(s[1]); int Z = int.Parse(s[2]); int ans = 0; for (int i = 0; X >= 0; i++) { if (i == 0) { X -= Z; } X -= (Y + Z); if (X >= 0) { ans++; } } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
8
150
16
using System; using System.Linq; namespace abc078_b { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine((x[0] - x[2]) / x[1]); } } }
using System; using System.Linq; namespace abc078_b { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine((x[0] - x[2]) / (x[1] + x[2])); } } }
[["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
75
7
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var k = long.Parse(line[0]); var a = long.Parse(line[1]); var b = long.Parse(line[2]); if (a <= b) { Console.WriteLine(-1); goto end; } var ans = (2L * k - 2L * b - 1L) / (a - b); Console.WriteLine(ans % 2 == 0 ? ans + 1 : ans); end:; } }
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var k = long.Parse(line[0]); var a = long.Parse(line[1]); var b = long.Parse(line[2]); if (a >= k) { Console.WriteLine(1); goto end; } if (a <= b) { Console.WriteLine(-1); goto end; } var ans = (2L * k - 2L * b - 1L) / (a - b); Console.WriteLine(ans % 2 == 0 ? ans + 1 : ans); end:; } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 126, 0, 127], ["+", 8, 196, 0, 57, 64, 196, 0, 126, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 126, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22]]
8
137
18
using System; using System.Linq; namespace relay2_a { class Program { static void Main(string[] args) { long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray(); long a = x[1] - x[2]; if (a <= 0) Console.WriteLine(-1); else { Console.WriteLine((x[0] - x[1] + a - 1) / a * 2 + 1); } } } }
using System; using System.Linq; namespace relay2_a { class Program { static void Main(string[] args) { long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray(); long a = x[1] - x[2]; if (x[0] <= x[1]) Console.WriteLine(1); else if (a <= 0) Console.WriteLine(-1); else { Console.WriteLine((x[0] - x[1] + a - 1) / a * 2 + 1); } } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24]]
8
110
20
//#pragma warning disable using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System; using System.Numerics; using System.Threading.Tasks; using static System.Math; using static System.Console; class Z { static void Main() => new K(); } class K { int F() => int.Parse(ReadLine()); long FL() => long.Parse(ReadLine()); int[] G() => ReadLine() .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); long[] GL() => ReadLine() .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(long.Parse) .ToArray(); public const int MOD = 1000000007; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Console.WriteLine(Solve()); Out.Flush(); } long Solve() { var I = GL(); long K = I[0], A = I[1], B = I[2], d = A - B; if (d <= 0 && A < K) return -1; var n = (K - B - 1) / d; return 2 * n + 1; } }
//#pragma warning disable using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System; using System.Numerics; using System.Threading.Tasks; using static System.Math; using static System.Console; class Z { static void Main() => new K(); } class K { int F() => int.Parse(ReadLine()); long FL() => long.Parse(ReadLine()); int[] G() => ReadLine() .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); long[] GL() => ReadLine() .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(long.Parse) .ToArray(); public const int MOD = 1000000007; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Console.WriteLine(Solve()); Out.Flush(); } long Solve() { var I = GL(); long K = I[0], A = I[1], B = I[2], d = A - B; if (A >= K) return 1; if (d <= 0) return -1; var n = (K - B - 1) / d; return 2 * n + 1; } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
307
13
//#pragma warning disable using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System; using System.Numerics; using System.Threading.Tasks; using static System.Math; using static System.Console; class Z { static void Main() => new K(); } class K { int F() => int.Parse(ReadLine()); long FL() => long.Parse(ReadLine()); int[] G() => ReadLine() .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); long[] GL() => ReadLine() .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(long.Parse) .ToArray(); public const int MOD = 1000000007; int N, Q; List<long> ps = new List<long>(); public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var I = G(); N = I[0]; Q = I[1]; var s = 1L; var p = 1L; while (s < MOD) { ps.Add(s); s += p; p *= N; } for (int i = 0; i < Q; i++) { I = G(); Console.WriteLine(Solve(I[0], I[1])); } Out.Flush(); } long Solve(long u, long v) { var a = F(u); var b = F(v); var c = new List<int>(); var i = 0; while (i < Min(a.Count, b.Count) && a[i] == b[i]) c.Add(a[i++]); // Console.WriteLine("{0} <-> {1}: {2}", string.Join("", a), string.Join("", // b), string.Join("", c)); return G(c); } long G(List<int> u) { var n = 0L; var p = 1L; foreach (var i in u.Reverse<int>()) { n += i * p; p *= N; } return n + ps[u.Count]; } List<int> F(long u) { var n = 0; while (n + 1 < ps.Count && ps[n + 1] <= u) n++; u -= ps[n]; var r = new List<int>(); while (u > 0) { r.Add((int)(u % N)); u /= N; } while (r.Count < n) r.Add(0); r.Reverse(); return r; } }
//#pragma warning disable using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System; using System.Numerics; using System.Threading.Tasks; using static System.Math; using static System.Console; class Z { static void Main() => new K(); } class K { int F() => int.Parse(ReadLine()); long FL() => long.Parse(ReadLine()); int[] G() => ReadLine() .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); long[] GL() => ReadLine() .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(long.Parse) .ToArray(); public const int MOD = 1000000007; int N, Q; List<long> ps = new List<long>(); public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var I = G(); N = I[0]; Q = I[1]; var s = 1L; var p = 1L; while (N != 1 && s < MOD) { ps.Add(s); s += p; p *= N; } for (int i = 0; i < Q; i++) { I = G(); Console.WriteLine(Solve(I[0], I[1])); } Out.Flush(); } long Solve(long u, long v) { if (N == 1) return Min(u, v); var a = F(u); var b = F(v); var c = new List<int>(); var i = 0; while (i < Min(a.Count, b.Count) && a[i] == b[i]) c.Add(a[i++]); // Console.WriteLine("{0} <-> {1}: {2}", string.Join("", a), string.Join("", // b), string.Join("", c)); return G(c); } long G(List<int> u) { var n = 0L; var p = 1L; foreach (var i in u.Reverse<int>()) { n += i * p; p *= N; } return n + ps[u.Count]; } List<int> F(long u) { var n = 0; while (n + 1 < ps.Count && ps[n + 1] <= u) n++; u -= ps[n]; var r = new List<int>(); while (u > 0) { r.Add((int)(u % N)); u /= N; } while (r.Count < n) r.Add(0); r.Reverse(); return r; } }
[["+", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 17, 79], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 12, 203], ["+", 0, 263, 8, 196, 0, 52, 15, 16, 17, 98], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 37, 0, 213, 63, 22], ["+", 0, 57, 64, 37, 0, 213, 3, 4, 0, 24], ["+", 64, 37, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 64, 37, 0, 213, 3, 4, 0, 21], ["+", 0, 57, 64, 37, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35]]
8
586
18
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { int N, P; sc.Make(out N, out P); var WB = sc.ArrLong2D(N); Array.Sort(WB, (a, b) => (b[0] + b[1]).CompareTo(a[0] + a[1])); var B = WB.Sum(A => A[1]); var W = 0L; for (int i = 0; i < N; i++) { B -= WB[i][1]; W += WB[i][0]; if ((B + W) * P <= W * 100) Fail(i + 1); } } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid()); public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; } public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; } public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { int N, P; sc.Make(out N, out P); var WB = sc.ArrLong2D(N); Array.Sort(WB, (a, b) => (b[0] * (100 - P) + b[1] * P) .CompareTo(a[0] * (100 - P) + a[1] * P)); var B = WB.Sum(A => A[1]); var W = 0L; for (int i = 0; i < N; i++) { B -= WB[i][1]; W += WB[i][0]; if ((B + W) * P <= W * 100) Fail(i + 1); } } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid()); public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; } public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; } public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
[["+", 63, 214, 205, 23, 0, 16, 31, 16, 17, 48], ["+", 205, 23, 0, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 31, 203], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["+", 205, 23, 0, 16, 31, 16, 12, 23, 0, 25], ["+", 63, 214, 205, 23, 0, 16, 12, 16, 17, 48], ["+", 63, 214, 205, 23, 0, 16, 12, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 0, 28, 0, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 16, 12, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 12, 22]]
8
1,981
16
using System; using System.Linq; using System.Collections.Generic; using System.Diagnostics; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; using static System.Console; namespace Program { public class Solver { Random rnd = new Random(); public void Solve() { var n = ri; var G = Enumerate(n, x => new List<int>()); for (int i = 1; i < n; i++) { var p = ri - 1; G[p].Add(i); } Func<int, int, KeyValuePair<int, long[,]>> dfs = null; dfs = (prev, cur) => { var size = 1; // dp[sz,deg] = sz 個の連結成分からなり、次数が deg var ret = new long[2, 3]; ret[1, 2] = 1; foreach (var t in G[cur]) { var sz = size; var res = dfs(cur, t); size += res.Key; ret = merge(new int[] { sz, res.Key }, ret, res.Value); } return new KeyValuePair<int, long[,]>(size, ret); }; var dp = dfs(-1, 0).Value; long ans = 0; var fact = new long[n + 1]; fact[0] = 1; for (int i = 0; i < n; i++) fact[i + 1] = fact[i] * (i + 1) % MOD; for (int i = 0; i <= n; i++) for (int d = 0; d <= 2; d++) { Console.WriteLine($"{i} {d} {dp[i, d]}"); var v = dp[i, d] * fact[i] % MOD; if (d != 2) v *= 2; if ((n - i) % 2 == 0) ans += v; else ans -= v; ans %= MOD; } Console.WriteLine((ans + MOD) % MOD); } const long MOD = (long)1e9 + 7; // merge b to a long[,] merge(int[] sz, long[,] a, long[,] b) { var ret = new long[sz[0] + sz[1] + 1, 3]; for (int i = 0; i <= sz[0]; i++) for (int j = 0; j <= sz[1]; j++) for (int d = 0; d <= 2; d++) for (int e = 0; e <= 2; e++) { var add = a[i, d] * b[j, e] % MOD; if (add == 0) continue; // Console.WriteLine($"{i} {j} {d} {e} {u} {v} {a[i, d, u]} {b[j, e, // v]}"); update(ref ret[i + j, d], add * (e == 2 ? 1 : 2)); if (d != 0 && e != 0) { // Console.WriteLine($"@ i:{i} j:{j} d:{d} e:{e} u:{u} v:{v} // a:{a[i, d, u]} b:{b[j, e, v]}"); update(ref ret[i + j - 1, d - 1], add); } } return ret; } void update(ref long u, long v) { u += v; u %= MOD; } const long INF = 1L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Program.Solver(); solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion
using System; using System.Linq; using System.Collections.Generic; using System.Diagnostics; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; using static System.Console; namespace Program { public class Solver { Random rnd = new Random(); public void Solve() { var n = ri; var G = Enumerate(n, x => new List<int>()); for (int i = 1; i < n; i++) { var p = ri - 1; G[p].Add(i); } Func<int, int, KeyValuePair<int, long[,]>> dfs = null; dfs = (prev, cur) => { var size = 1; // dp[sz,deg] = sz 個の連結成分からなり、次数が deg var ret = new long[2, 3]; ret[1, 2] = 1; foreach (var t in G[cur]) { var sz = size; var res = dfs(cur, t); size += res.Key; ret = merge(new int[] { sz, res.Key }, ret, res.Value); } return new KeyValuePair<int, long[,]>(size, ret); }; var dp = dfs(-1, 0).Value; long ans = 0; var fact = new long[n + 1]; fact[0] = 1; for (int i = 0; i < n; i++) fact[i + 1] = fact[i] * (i + 1) % MOD; for (int i = 0; i <= n; i++) for (int d = 0; d <= 2; d++) { // Console.WriteLine($"{i} {d} {dp[i, d]}"); var v = dp[i, d] * fact[i] % MOD; if (d != 2) v *= 2; if ((n - i) % 2 == 0) ans += v; else ans -= v; ans %= MOD; } Console.WriteLine((ans + MOD) % MOD); } const long MOD = (long)1e9 + 7; // merge b to a long[,] merge(int[] sz, long[,] a, long[,] b) { var ret = new long[sz[0] + sz[1] + 1, 3]; for (int i = 0; i <= sz[0]; i++) for (int j = 0; j <= sz[1]; j++) for (int d = 0; d <= 2; d++) for (int e = 0; e <= 2; e++) { var add = a[i, d] * b[j, e] % MOD; if (add == 0) continue; // Console.WriteLine($"{i} {j} {d} {e} {u} {v} {a[i, d, u]} {b[j, e, // v]}"); update(ref ret[i + j, d], add * (e == 2 ? 1 : 2)); if (d != 0 && e != 0) { // Console.WriteLine($"@ i:{i} j:{j} d:{d} e:{e} u:{u} v:{v} // a:{a[i, d, u]} b:{b[j, e, v]}"); update(ref ret[i + j - 1, d - 1], add); } } return ret; } void update(ref long u, long v) { u += v; u %= MOD; } const long INF = 1L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Program.Solver(); solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["-", 0, 28, 0, 283, 0, 284, 0, 204, 205, 22], ["-", 0, 283, 0, 284, 0, 204, 206, 207, 0, 70], ["-", 0, 284, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 283, 0, 284, 0, 204, 206, 207, 0, 21], ["-", 0, 283, 0, 284, 0, 204, 206, 207, 0, 73], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 7, 8, 7, 8, 196, 0, 1, 0, 35]]
8
1,437
24
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); string s = sc.Next(); List<string> list = new List<string>(); int[] pos = new int[] { 7, 5, 3, 0 }; for (int i = 0; i < Math.Pow(2, 4); i++) { string str = s; for (int j = 0; j < 4; j++) { if ((1 & (i >> j)) == 1) { // bitが立っている際のチェック処理 str.Remove(pos[j], 1); } } } string answer = list.Contains(s) ? "YES" : "NO"; Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); string s = sc.Next(); List<string> list = new List<string>(); int[] pos = new int[] { 8, 6, 4, 0 }; for (int i = 0; i < Math.Pow(2, 4); i++) { string str = "AKIHABARA"; for (int j = 0; j < 4; j++) { if ((1 & (i >> j)) == 1) { // bitが立っている際のチェック処理 str = str.Remove(pos[j], 1); } } list.Add(str); } string answer = list.Contains(s) ? "YES" : "NO"; Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 200, 0, 212, 0, 227, 0, 229, 0, 203], ["+", 0, 200, 0, 212, 0, 227, 0, 229, 0, 203], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 62], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
474
19
using System; using System.Linq; using System.Collections.Generic; using System.Diagnostics; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; namespace Program { public class Solver { Random rnd = new Random(); public void Solve() { var n = ri; var X = Enumerate(n, x => new long[] { rl, rl }) .OrderBy(x => x[0] + x[1]) .ToArray(); var dp = Enumerate(n + 1, x => INF); dp[0] = 0; foreach (var x in X) { for (int i = n - 1; i >= 0; i--) { if (dp[i] <= x[0]) dp[i + 1] = Min(dp[i + 1], dp[i] + x[1]); } } for (int i = n - 1; i >= 0; i--) if (dp[i] != INF) { Console.WriteLine(i); return; } } const long INF = 1L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = true }); var solver = new Program.Solver(); /* var t = new System.Threading.Thread(solver.Solve, 50000000); t.Start(); t.Join(); */ solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion
using System; using System.Linq; using System.Collections.Generic; using System.Diagnostics; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; namespace Program { public class Solver { Random rnd = new Random(); public void Solve() { var n = ri; var X = Enumerate(n, x => new long[] { rl, rl }) .OrderBy(x => x[0] + x[1]) .ToArray(); var dp = Enumerate(n + 1, x => INF); dp[0] = 0; foreach (var x in X) { Debug.WriteLine(x.AsJoinedString()); for (int i = n - 1; i >= 0; i--) { if (dp[i] <= x[0]) dp[i + 1] = Min(dp[i + 1], dp[i] + x[1]); } } for (int i = n; i >= 0; i--) if (dp[i] != INF) { Console.WriteLine(i); return; } } const long INF = 1L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = true }); var solver = new Program.Solver(); /* var t = new System.Threading.Thread(solver.Solve, 50000000); t.Start(); t.Join(); */ solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 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, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
994
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.DP { class CodeFestival2017Final_D { static void Main(string[] args) { Method(args); ReadLine(); } static void Method(string[] args) { int n = ReadInt(); int[][] hps = new int [n][]; for (int i = 0; i < n; i++) { hps[i] = ReadInts(); } hps = hps.OrderBy(a => a[0]).OrderBy(a => a[1]).ToArray(); int[] dp = new int[n + 1]; for (int i = 0; i <= n; i++) dp[i] = int.MaxValue; dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = n - 1; j >= 0; j--) { if (dp[j] == int.MaxValue) continue; if (dp[j] <= hps[i][0]) { dp[j + 1] = Min(dp[j + 1], dp[j] + hps[i][1]); } } } for (int i = n; i >= 0; i--) { if (dp[i] == int.MaxValue) continue; WriteLine(i); return; } } private static string Read() { return ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.DP { class CodeFestival2017Final_D { static void Main(string[] args) { Method(args); ReadLine(); } static void Method(string[] args) { int n = ReadInt(); int[][] hps = new int [n][]; for (int i = 0; i < n; i++) { hps[i] = ReadInts(); } hps = hps.OrderBy(a => a[0] + a[1]).ToArray(); int[] dp = new int[n + 1]; for (int i = 0; i <= n; i++) dp[i] = int.MaxValue; dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = n - 1; j >= 0; j--) { if (dp[j] == int.MaxValue) continue; if (dp[j] <= hps[i][0]) { dp[j + 1] = Min(dp[j + 1], dp[j] + hps[i][1]); } } } for (int i = n; i >= 0; i--) { if (dp[i] == int.MaxValue) continue; WriteLine(i); return; } } private static string Read() { return ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 12, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 72]]
8
472
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProgrammingContest { class MainClass : IDisposable { Scanner sc; Writer wr; string backPath = ".."; char dirSep = System.IO.Path.DirectorySeparatorChar; string inFilePath = null; string outFilePath = null; public MainClass() { this.inFilePath = this.backPath + this.dirSep + this.backPath + this.dirSep + "in.txt"; this.outFilePath = this.backPath + this.dirSep + this.backPath + this.dirSep + "out.txt"; } static void Main(string[] args) { using (var mainClass = new MainClass()) { // mainClass.MakeTestCase(); mainClass.Solve(); } } public void Dispose() { if (this.sc != null) { this.sc.Dispose(); this.sc = null; } if (this.wr != null) { this.wr.Dispose(); this.wr = null; } } void MakeTestCase() { Random rand = new Random(); this.wr = new Writer(inFilePath); } void Solve() { this.wr = new Writer(this.isReactive || true); // this.wr = new Writer(this.outFilePath); #if DEBUG if (!this.isReactive) this.sc = new Scanner(this.inFilePath); else this.sc = new Scanner(); #else this.sc = new Scanner(); #endif string S = sc.Next; string[] sa = "AKIHABARA".Split(new char[] { 'A' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < (1 << 4); i++) { string sbuf = string.Empty; for (int j = 0; j < 4; j++) { if ((i & (1 << j)) != 0) { sbuf += "A"; } if (j < 3) { sbuf += sa[j]; } } wr.WriteLine(sbuf); if (S == sbuf) { wr.WriteLine("YES"); return; } } wr.WriteLine("NO"); } bool isReactive = false; // TODO: reactive check !! } class Writer : IDisposable { private System.IO.TextWriter writer; private StringBuilder sb; private bool isReactive; public Writer(string path) : this(new System.IO.StreamWriter(path)) {} public Writer(bool isReactive) : this(null, isReactive) {} public Writer(System.IO.TextWriter writer = null, bool isReactive = false) { this.writer = (writer ?? Console.Out); this.isReactive = isReactive; if (!this.isReactive) this.sb = new StringBuilder(); } public void Dispose() { if (!this.isReactive) this.writer.Write(sb.ToString()); if (!this.writer.Equals(Console.Out)) this.writer.Dispose(); } public void Write(object val) { if (this.isReactive) { this.writer.Write(val.ToString()); this.writer.Flush(); } else this.sb.Append(val.ToString()); } public void Write(string format, params object[] vals) { if (this.isReactive) { this.writer.Write(format, vals); this.writer.Flush(); } else this.sb.AppendFormat(format, vals); } public void WriteLine(object val) { this.Write(val.ToString() + System.Environment.NewLine); } public void WriteLine(string format, params object[] vals) { this.Write(format + System.Environment.NewLine, vals); } } class Scanner : IDisposable { private Queue<string> buffer; private char[] sep; private System.IO.TextReader reader; public Scanner(string path) : this(new System.IO.StreamReader(path)) {} public Scanner(System.IO.TextReader reader = null) { this.buffer = new Queue<string>(); this.sep = new char[] { ' ' }; this.reader = (reader ?? Console.In); } private void CheckBuffer() { if (this.buffer.Count == 0) { string str = string.Empty; while (string.IsNullOrEmpty(str)) str = this.reader.ReadLine(); str.Split(this.sep).ToList().ForEach(el => this.buffer.Enqueue(el)); } } public void Dispose() { if (!this.reader.Equals(Console.In)) this.reader.Dispose(); } public string Next { get { this.CheckBuffer(); return this.buffer.Dequeue(); } } public int NextInt { get { return int.Parse(this.Next); } } public double NextDouble { get { return double.Parse(this.Next); } } public long NextLong { get { return long.Parse(this.Next); } } public bool IsEnd { get { this.CheckBuffer(); return this.buffer.Count == 0; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProgrammingContest { class MainClass : IDisposable { Scanner sc; Writer wr; string backPath = ".."; char dirSep = System.IO.Path.DirectorySeparatorChar; string inFilePath = null; string outFilePath = null; public MainClass() { this.inFilePath = this.backPath + this.dirSep + this.backPath + this.dirSep + "in.txt"; this.outFilePath = this.backPath + this.dirSep + this.backPath + this.dirSep + "out.txt"; } static void Main(string[] args) { using (var mainClass = new MainClass()) { // mainClass.MakeTestCase(); mainClass.Solve(); } } public void Dispose() { if (this.sc != null) { this.sc.Dispose(); this.sc = null; } if (this.wr != null) { this.wr.Dispose(); this.wr = null; } } void MakeTestCase() { Random rand = new Random(); this.wr = new Writer(inFilePath); } void Solve() { this.wr = new Writer(this.isReactive || true); // this.wr = new Writer(this.outFilePath); #if DEBUG if (!this.isReactive) this.sc = new Scanner(this.inFilePath); else this.sc = new Scanner(); #else this.sc = new Scanner(); #endif string S = sc.Next; string[] sa = "AKIHABARA".Split(new char[] { 'A' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < (1 << 4); i++) { string sbuf = string.Empty; for (int j = 0; j < 4; j++) { if ((i & (1 << j)) != 0) { sbuf += "A"; } if (j < 3) { sbuf += sa[j]; } } if (S == sbuf) { wr.WriteLine("YES"); return; } } wr.WriteLine("NO"); } bool isReactive = false; // TODO: reactive check !! } class Writer : IDisposable { private System.IO.TextWriter writer; private StringBuilder sb; private bool isReactive; public Writer(string path) : this(new System.IO.StreamWriter(path)) {} public Writer(bool isReactive) : this(null, isReactive) {} public Writer(System.IO.TextWriter writer = null, bool isReactive = false) { this.writer = (writer ?? Console.Out); this.isReactive = isReactive; if (!this.isReactive) this.sb = new StringBuilder(); } public void Dispose() { if (!this.isReactive) this.writer.Write(sb.ToString()); if (!this.writer.Equals(Console.Out)) this.writer.Dispose(); } public void Write(object val) { if (this.isReactive) { this.writer.Write(val.ToString()); this.writer.Flush(); } else this.sb.Append(val.ToString()); } public void Write(string format, params object[] vals) { if (this.isReactive) { this.writer.Write(format, vals); this.writer.Flush(); } else this.sb.AppendFormat(format, vals); } public void WriteLine(object val) { this.Write(val.ToString() + System.Environment.NewLine); } public void WriteLine(string format, params object[] vals) { this.Write(format + System.Environment.NewLine, vals); } } class Scanner : IDisposable { private Queue<string> buffer; private char[] sep; private System.IO.TextReader reader; public Scanner(string path) : this(new System.IO.StreamReader(path)) {} public Scanner(System.IO.TextReader reader = null) { this.buffer = new Queue<string>(); this.sep = new char[] { ' ' }; this.reader = (reader ?? Console.In); } private void CheckBuffer() { if (this.buffer.Count == 0) { string str = string.Empty; while (string.IsNullOrEmpty(str)) str = this.reader.ReadLine(); str.Split(this.sep).ToList().ForEach(el => this.buffer.Enqueue(el)); } } public void Dispose() { if (!this.reader.Equals(Console.In)) this.reader.Dispose(); } public string Next { get { this.CheckBuffer(); return this.buffer.Dequeue(); } } public int NextInt { get { return int.Parse(this.Next); } } public double NextDouble { get { return double.Parse(this.Next); } } public long NextLong { get { return long.Parse(this.Next); } } public bool IsEnd { get { this.CheckBuffer(); return this.buffer.Count == 0; } } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
1,070
7
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); int[] a = Array.ConvertAll(("0 " + Console.ReadLine()).Split(), int.Parse); long ans = a[1] - a[0]; Array.Sort(a); if (n != 1) { int i = 2; for (; i <= n; i += 2) { ans = Math.Min(ans, a[i] - a[i - 2]); } ans = Math.Min(ans, (12 - a[n]) + (12 - a[n - 1])); for (i -= 3 - ((n % 2) * 2); i > 1; i -= 2) { ans = Math.Min(ans, a[i] - a[i - 2]); } } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); int[] a = Array.ConvertAll(("0 " + Console.ReadLine()).Split(), int.Parse); Array.Sort(a); long ans = a[1] - a[0]; if (n != 1) { int i = 2; for (; i <= n; i += 2) { ans = Math.Min(ans, a[i] - a[i - 2]); } ans = Math.Min(ans, (12 - a[n]) + (12 - a[n - 1])); for (i -= 3 - ((n % 2) * 2); i > 1; i -= 2) { ans = Math.Min(ans, a[i] - a[i - 2]); } } Console.WriteLine(ans); } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
8
220
14
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; using System.Collections; namespace CompetitiveProgramming { public class CPair<T, U> : IComparable where T : IComparable<T> { public readonly T Item1; public readonly U Item2; public int CompareTo(object obj) { CPair<T, U> castedObj = (CPair<T, U>)obj; return this.Item1.CompareTo(castedObj.Item1); } public CPair(T t, U u) { Item1 = t; Item2 = u; } } class Pair : IComparable { public long x; public long a; public long b; public long c; public Pair(long X, long Y, long Z, long D) { x = X; a = Y; b = Z; c = D; } public Pair(long a, long x) { this.a = a; this.x = x; } public Pair(long a, long b, long c) { this.a = a; this.b = b; this.c = c; } public int CompareTo(object obj) { Pair kore = (Pair)obj; return x.CompareTo(kore.x); } public static bool operator <=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x <= p2.x; } else { return p1.a <= p2.a; } } public static bool operator >=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x >= p2.x; } else { return p1.a >= p2.a; } } } class Zettiti : IComparable { public long num; public Zettiti(long num) { this.num = num; } public int CompareTo(object obj) { Zettiti kore = (Zettiti)obj; long knum = Math.Abs(kore.num); long mynum = Math.Abs(num); return mynum.CompareTo(knum); } } class Program { static void Main(string[] args) { // Utils.BinarySearch.Search StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); string str = scan.Scan(); int moto = 111; for (int i = 1; i <= 9; i++) { if (str.Contains((moto * i).ToString())) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } static string dffs(int n, int m, Tuple<int, int>[] tuples, int cur, int sum, string now) { if (sum == n) return now; if (cur == m) return ""; string zan = now; for (int i = 0; i < (n - sum) / tuples[cur].Item1; i++) { zan += tuples[cur].Item2; } for (int i = (n - sum) / tuples[cur].Item1; i >= 0; i--) { string buf = dffs(n, m, tuples, cur + 1, sum + i * tuples[cur].Item1, zan); if (buf != "") return buf; zan = zan.Substring(0, zan.Length - 1); ; } return ""; } static bool isOK(long mid, long[] a, long[] f, long k) { long count = 0; for (long i = 0; i < a.Length; i++) { long togo = mid / f[i]; ; count += Math.Max(0, a[i] - togo); } return (count <= k); } static void Output<T>(List<T> list, string kugiri = "\n") { for (int i = 0; i < list.Count; i++) { Console.Write(list[i]); if (i != list.Count - 1) { Console.Write(kugiri); } } } static void Output<T>(T[] list, string kugiri = "\n") { for (int i = 0; i < list.Length; i++) { Console.Write(list[i]); if (i != list.Length - 1) { Console.Write(kugiri); } } } static void Output<T>(T[,] list, string kugiri1 = " ", string kugiri2 = "\n") { int len1 = list.GetLength(0); int len2 = list.GetLength(1); for (int i = 0; i < len1; i++) { for (int j = 0; j < len2; j++) { Console.Write(list[i, j]); if (j != len2 - 1) { Console.Write(kugiri1); } } if (i != len1 - 1) { Console.Write(kugiri2); } } } static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isok(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int binary_search(int key, int[] moto) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int[] Togo; static bool CheckBipartite(int now, int prev, List<int>[] g, int c = 0) // 0,-1が想定 { if (Togo == null) Togo = Enumerable.Repeat(-1, g.Length).ToArray(); foreach (var next in g[now]) { if (next == prev) continue; var nextc = Togo[next]; if (nextc >= 0 && nextc == c) return false; if (nextc >= 0) continue; Togo[next] = (c + 1) % 2; var res = CheckBipartite(next, now, g, (c + 1) % 2); if (res == false) return false; } return true; } static bool isOK(int index, int key, int[] moto) { return moto[index] > key; } public static int bitCount(int k) { uint i = (uint)k; i = i - ((i >> 1) & 0x55555555); i = (i & 0x33333333) + ((i >> 2) & 0x33333333); i = (i + (i >> 4)) & 0x0f0f0f0f; i = i + (i >> 8); i = i + (i >> 16); return (int)i & 0x3f; } static int check(long moto, long tai) { if (tai % moto != 0) { return 0; } while (tai > 1) { if (tai % moto == 0) { tai /= moto; } else if (tai > moto) { tai %= moto; } else { tai -= moto; } } if (tai == 1) { return 1; } else { return 0; } } static bool NextPermutation(int[] array) { var size = array.Length; var ok = false; // array[i]<array[i+1]を満たす最大のiを求める int i = size - 2; for (; 0 <= i; i--) { if (array[i] < array[i + 1]) { ok = true; break; } } //全ての要素が降順の場合、NextPermutationは存在しない if (ok == false) return false; // array[i]<array[j]を満たす最大のjを求める int j = size - 1; for (;; j--) { if (array[i] < array[j]) break; } // iとjの要素をswapする var tmp = array[i]; array[i] = array[j]; array[j] = tmp; // i以降の要素を反転させる Array.Reverse(array, i + 1, size - (i + 1)); return true; } static List<int[]> GetAllPermutation(int N) { var res = new List<int[]>(); var array = Enumerable.Range(0, N).ToArray(); do { var copy = new int[N]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static List<int[]> GetAllPermutation(int[] array) { var size = array.Length; var res = new List<int[]>(); do { var copy = new int[size]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static long Syakutori( int[] a, long k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上 { long sum = 0; int right = 0; long ans = 0; for (int left = 0; left < a.Length; left++) { while (right < a.Length && sum < k) { sum += a[right]; right++; } if (k <= sum) { ans += a.Length - right + 1; } if (left == right) { right++; } else { sum -= a[left]; } } return ans; } static int[] zalgo(String s) { int n = s.Length; int[] ret = new int[n]; ret[0] = n; int i = 1, j = 0; while (i < n) { while (i + j < n && s[j] == s[i + j]) ++j; ret[i] = j; if (j == 0) { ++i; continue; } int k = 1; while (i + k < n && k + ret[k] < j) { ret[i + k] = ret[k]; ++k; } i += k; j -= k; } return ret; } static int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } static long gcd(long a, long b) { if (a % b == 0) { return b; } return gcd(b, a % b); } public static List<long> FactorialMemo = new List<long>() { 1 }; static long Fact(int x) { for (int i = FactorialMemo.Count; i <= x; i++) FactorialMemo.Add(FactorialMemo.Last() * i); return FactorialMemo[x]; } static int[] yousogotoplus(int[] a, int[] b) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[i]; } return c; } static int[] yousogotoplus(int[] a, int[,] b, int l) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[l, i]; } return c; } static int[] yousogotoplus(int[,] a, int l) { int[] c = new int[a.GetLength(1)]; for (int i = 0; i < a.GetLength(1); i++) { c[i] = a[l, i]; } return c; } public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[LowerBound(dp, a[i])] = a[i]; } return LowerBound(dp, long.MaxValue - 1); } static long DivideWith(long m, long n, List<long> primes) { while (m % n == 0) { primes.Add(n); m = m / n; } return m; } static List<CPair<long, long>> SoinsuBunkai(long num) { List<CPair<long, long>> primes = new List<CPair<long, long>>(); List<long> yakusu = new List<long>(); List<long> yakusu2 = new List<long>(); for (int i = 2; i * i <= num; i++) { if (num % i != 0) { continue; } yakusu.Add(i); if (i * i != num) { yakusu2.Add(num / i); } } for (int i = 0; i < yakusu.Count; i++) { if (num % yakusu[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu[i] == 0; j++) { num /= yakusu[i]; } primes.Add(new CPair<long, long>(yakusu[i], j)); } for (int i = yakusu2.Count - 1; i > 0; i--) { if (num % yakusu2[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu2[i] == 0; j++) { num /= yakusu2[i]; } primes.Add(new CPair<long, long>(yakusu2[i], j)); } return primes; } static IEnumerable<int> Primes(int maxnum) { // var sieve = new BitArray(maxnum + 1, true); bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray(); int squareroot = (int)Math.Sqrt(maxnum); for (int i = 2; i <= squareroot; i++) { if (sieve[i] == false) continue; for (int n = i * 2; n <= maxnum; n += i) sieve[n] = false; } for (int i = 2; i <= maxnum; i++) if (sieve[i] == true) yield return i; } /* static long[] SoinsuBunkai(long num) { if (num == 1) return new long[] { 1 }; List<long> primes = new List<long>(); long n = DivideWith(num, 2, primes); n = DivideWith(n, 3, primes); n = DivideWith(n, 5, primes); long i = 0; while (n > 1) { int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 }; foreach (var p in ps) { // 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break; } i += 30; } return primes.ToArray(); }*/ public static int h; public static int w; public static int BFS(int height, int width, char[,] map) { int[] dx = new int[] { -1, 0, 0, 1 }; int[] dy = new int[] { 0, 1, -1, 0 }; bool[,] visited = new bool[h, w]; int[,] len = new int[h, w]; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(new Tuple<int, int>(height, width)); int max = 0; visited[height, width] = true; while (queue.Count > 0) { var now = queue.Dequeue(); for (int i = 0; i < 4; i++) { int ny = now.Item1 + dy[i]; int nx = now.Item2 + dx[i]; if (ny >= h || ny < 0 || nx >= w || nx < 0) continue; if (visited[ny, nx] || map[ny, nx] == '#') continue; visited[ny, nx] = true; len[ny, nx] = len[now.Item1, now.Item2] + 1; max = Math.Max(max, len[ny, nx]); queue.Enqueue(new Tuple<int, int>(ny, nx)); } } return max; } static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Initialize<T>(ref T[] array, T initialvalue) { array = Array.ConvertAll(array, x => initialvalue); } static int[] Manacher(string S) { int i = 0, j = 0; int[] R = new int[S.Length]; while (i < S.Length) { while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j]) ++j; R[i] = j; int k = 1; while (i - k >= 0 && k + R[i - k] < j) { R[i + k] = R[i - k]; ++k; } i += k; j -= k; } return R; } /* static Pair[] a; static int SaikiZentansaku(List<int>now,int count,int last,int n,int m) { List<int> next = new List<int>(); for (int i = 0; i < now.Count; i++) { next.Add(now[i]); } next.Add(last); var kore = next.ToArray(); int ans = 0; if(count==n) { for (int i = 0; i < a.Length; i++) { int A = a[i].a; int b = a[i].b; int c = a[i].c; int d = a[i].x; if (kore[b] - kore[A] == c) { ans += d; } } return ans; } for (int i = last; i <= m; i++) { ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m)); } return ans; }*/ } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private long len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public char[] Char(long n) { char[] kore = new char[n]; for (long i = 0; i < n; i++) { kore[i] = Char(); } return kore; } public char[,] Char(long n, long m) { char[,] kore = new char[n, m]; for (long i = 0; i < n; i++) { for (int j = 0; j < m; j++) { kore[i, j] = Char(); } } return kore; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string[] Scan(long n) { string[] str = new string[n]; for (long i = 0; i < n; i++) { str[i] = Scan(); } return str; } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public long[] Long(long n, bool minus1 = false) { long[] kore = new long[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); if (minus1) kore[i]--; } return kore; } public Mlong[] MLong(long n) { Mlong[] kore = new Mlong[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public long[,] Long(long h, long w, bool minus1 = false) { long[,] kore = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = Long(); if (minus1) kore[i, j]--; } } return kore; } public int Integer() { return (int)Long(); } public Mint[] MInteger(long n) { Mint[] kore = new Mint[n]; for (int i = 0; i < n; i++) { kore[i] = Integer(); } return kore; } public int[] Integer(long n, bool minus1 = false) { int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = (int)Long(); if (minus1) kore[i]--; } return kore; } public int[,] Integer(long h, long w, bool minus1 = false) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = (int)Long(); if (minus1) kore[i, j]--; } } return kore; } public int[] StringToInt(int n) { char[] s = Scan().ToCharArray(); int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = s[i] - '0'; } return kore; } public int[,] StringToInt(int h, int w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { char[] s = Scan().ToCharArray(); for (int j = 0; j < w; j++) { kore[i, j] = s[j] - '0'; } } return kore; } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } public int Size(int x) { return -data[Root(x)]; } } public class Mlong : IComparable { public static long mod = 1000000007; public long num; public Mlong(long num) { if (num < 0) { num += mod; } this.num = num % mod; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mlong operator +(Mlong x, Mlong y) { return new Mlong((x.num + y.num) % mod); } public static Mlong operator -(Mlong x, Mlong y) { return new Mlong((x.num - y.num + mod) % mod); } public static Mlong operator *(Mlong x, Mlong y) { return new Mlong((long)(((1L * x.num) * y.num) % mod)); } public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); } static long GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; } public static implicit operator Mlong(long x) { return new Mlong(x); } public static Mlong operator %(Mlong x, Mlong y) { return new Mlong(x.num % y.num); } public static explicit operator long(Mlong x) { return x.num; } public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; } public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; } public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; } public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; } public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; } public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; } public Mlong Pow(Mlong n) { Mlong pow = this; Mlong res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n = n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); } public static List<Mlong> FactorialMemo = new List<Mlong>() { 1 }; static Mlong Factorial(int x) { for (int i = FactorialMemo.Count; i <= x; i++) FactorialMemo.Add(FactorialMemo.Last() * i); return FactorialMemo[x]; } public static Mlong Comb(Mlong n, Mlong a) { Mlong buf1 = 1; Mlong buf2 = 1; for (long i = 0; i < a.num; i++) { buf1 *= n - i; buf2 *= (i + 1); } return buf1.modjyo(buf2); } public static Mlong Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mlong x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mlong kore = (Mlong)obj; return num.CompareTo(kore.num); } } public class Mint : IComparable { public static int mod = 1000000007; public int num; public Mint(int Num) { num = Num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mint operator +(Mint x, Mint y) { return new Mint((x.num + y.num) % mod); } public static Mint operator -(Mint x, Mint y) { return new Mint((x.num - y.num + mod) % mod); } public static Mint operator *(Mint x, Mint y) { return new Mint((int)(((1L * x.num) * y.num) % mod)); } public Mint hutujyo(Mint x) { return new Mint(num / x.num); } static int GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return (int)(x2 + mod); div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return (int)(x1 + mod); div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; } /* public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }*/ public static implicit operator Mint(int x) { return new Mint(x); } public static Mint[] Toarray(int[] x) { Mint[] buf = new Mint[x.Length]; for (int i = 0; i < x.Length; i++) { buf[i] = x[i]; } return buf; } public static explicit operator int(Mint x) { return x.num; } public static Mint operator %(Mint x, Mint y) { return new Mint(x.num % y.num); } public static bool operator ==(Mint x, Mint y) { return x.num == y.num; } public static bool operator !=(Mint x, Mint y) { return x.num != y.num; } public static bool operator<(Mint x, Mint y) { return x.num < y.num; } public static bool operator>(Mint x, Mint y) { return x.num > y.num; } public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; } public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; } public Mint Pow(Mint n) { Mint pow = this; Mint res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mint Pow(Mint a, Mint n) { return a.Pow(n); } public static List<Mint> FactorialMemo = new List<Mint>() { 1 }; static Mint Factorial(int x) { for (int i = FactorialMemo.Count; i <= x; i++) FactorialMemo.Add(FactorialMemo.Last() * i); return FactorialMemo[x]; } public static Mint Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mint x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mint kore = (Mint)obj; return num.CompareTo(kore.num); } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } public class Tree { public Node[] Nodes; public List<int[]> hen; public class Node { public int? parent = null; public List<int[]> children = new List<int[]>(); public int parentcolor = -1; } public Tree(int kosu) { Nodes = new Node[kosu]; for (int i = 0; i < Nodes.Length; i++) { Nodes[i] = new Node(); } hen = new List<int[]>(); } public void Connect(int oya, int ko, int id) { hen.Add(new int[] { oya, ko, 0 }); Nodes[oya].children.Add(new int[] { ko, id }); Nodes[ko].parent = oya; } } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } // return ret; return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public bool Any() { return _root != null; } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public T max() { SB_BinarySearchTree<T>.Node ima = _root; while (ima.RChild != null) { ima = ima.RChild; } return ima.Value; } public T min() { SB_BinarySearchTree<T>.Node ima = _root; while (ima.LChild != null) { ima = ima.LChild; } return ima.Value; } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public class RollingHashSlow { public const long B = (long)1e5 + 7; public const long MOD = (long)1e9 + 7; public string S { get; set; } public int N { get; set; } public long[] Power { get; set; } public long[] Hash { get; set; } public RollingHashSlow(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new long[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = (this.Power[i] * B) % MOD; } // ハッシュを前計算する this.Hash = new long[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD; } } // S[l, r) のハッシュ値を求める public long Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD); if (hash < 0) hash += MOD; return hash; } } class RollingHashFast { public const ulong B = (ulong)1e9 + 7; public string S { get; set; } public int N { get; set; } public ulong[] Power { get; set; } public ulong[] Hash { get; set; } public RollingHashFast(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new ulong[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = this.Power[i] * B; } // ハッシュを前計算する this.Hash = new ulong[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = this.Hash[i] * B + S[i]; } } // [l, r) のハッシュ値を求める public ulong Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]); return hash; } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } // [s, t) public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class WarshallFloyd { public int V { get; set; } public long[,] DP { get; set; } public long INF = long.MaxValue; public bool[] Negative; public WarshallFloyd(int v) { this.V = v; this.DP = new long[V, V]; for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { this.DP[i, j] = INF; } this.DP[i, i] = 0; } } public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; } public long[,] CalcMinCost() { this.Negative = new bool[V]; for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]); } } } for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; if (DP[i, j] > DP[i, k] + DP[k, j]) { this.Negative[i] = true; this.Negative[j] = true; this.Negative[k] = true; } } } } return DP; } public long GetMinCost(int a, int b) { return DP[a, b]; } public bool IsINF(int a, int b) { return DP[a, b] >= INF; } public bool IsNegative(params int[] vs) { if (vs.Length == 0) vs = Enumerable.Range(0, V).ToArray(); foreach (var v in vs) { if (Negative[v]) return true; } return false; } } /// <summary> /// Get min cost between two points /// </summary> public class Dijkstra { private int maxIndex = -1; private const int INF = Int32.MaxValue; private int[,] _edgeArray; /// <summary> /// Dijkstra, get min cost between two points /// should not contain negatie cost path /// </summary> /// <param name="size">max index of vertices</param> public Dijkstra(int size) { maxIndex = size + 1; _edgeArray = new int[maxIndex, maxIndex]; for (int i = 0; i < _edgeArray.GetLength(0); i++) { for (int j = 0; j < _edgeArray.GetLength(1); j++) { _edgeArray[i, j] = INF; if (i == j) _edgeArray[i, j] = 0; } } } // Add a path(no direction) with its cost public void AddPath(int s, int t, int cost) { _edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost); _edgeArray[t, s] = _edgeArray[s, t]; } // Get the min cost between s and t // return Int32.MaxValue if no path public int GetMinCost(int s, int t) { int[] cost = new int[maxIndex]; for (int i = 0; i < cost.Length; i++) cost[i] = INF; cost[s] = 0; var priorityQueue = new PriorityQueue<CPair<int, int>>(); priorityQueue.Enqueue(new CPair<int, int>(0, s)); while (priorityQueue.Count() > 0) { var costDestinationPair = priorityQueue.Dequeue(); if (cost[costDestinationPair.Item2] < costDestinationPair.Item1) continue; for (int i = 0; i < maxIndex; i++) { int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF ? INF : costDestinationPair.Item1 + _edgeArray[costDestinationPair.Item2, i]; if (newCostToi < cost[i]) { cost[i] = newCostToi; priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i)); } } } return cost[t]; } } class Deque<T> : IEnumerable<T> { public T this[int i] { get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; } set { if (i < 0) throw new ArgumentOutOfRangeException(); this.Buffer[(this.FirstIndex + i) % this.Capacity] = value; } } private T[] Buffer; private int Capacity; private int FirstIndex; private int LastIndex { get { return (this.FirstIndex + this.Length) % this.Capacity; } } public int Length; public Deque(int capacity = 16) { this.Capacity = capacity; this.Buffer = new T[this.Capacity]; this.FirstIndex = 0; } public void PushBack(T data) { if (this.Length == this.Capacity) this.Resize(); this.Buffer[this.LastIndex] = data; this.Length++; } public void PushFront(T data) { if (this.Length == this.Capacity) this.Resize(); var index = this.FirstIndex - 1; if (index < 0) index = this.Capacity - 1; this.Buffer[index] = data; this.Length++; this.FirstIndex = index; } public T PopBack() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[this.Length - 1]; this.Length--; return data; } public T PopFront() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[0]; this.FirstIndex++; this.FirstIndex %= this.Capacity; this.Length--; return data; } private void Resize() { var newArray = new T[this.Capacity * 2]; for (int i = 0; i < this.Length; i++) { newArray[i] = this[i]; } this.FirstIndex = 0; this.Capacity *= 2; this.Buffer = newArray; } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } public class PotentializedUnionFind { int _count; int[] par, sizes, rank; long[] weight; public PotentializedUnionFind(int N) { _count = N; par = new int[N]; sizes = new int[N]; rank = new int[N]; weight = new long[N]; for (int i = 0; i < N; ++i) { par[i] = i; sizes[i] = 1; rank[i] = 0; } } int Root(int X) { if (par[X] == X) { return X; } else { int r = Root(par[X]); weight[X] += weight[par[X]]; return (par[X] = r); } } public bool Merge(int X, int Y, long W) { W += GetWeight(X); W -= GetWeight(Y); X = Root(X); Y = Root(Y); if (X == Y) return false; --_count; if (rank[X] < rank[Y]) { par[X] = Y; sizes[Y] += sizes[X]; weight[X] = -W; } else { par[Y] = X; sizes[X] += sizes[Y]; if (rank[X] == rank[Y]) ++rank[X]; weight[Y] = W; } return true; } public bool IsSame(int X, int Y) => Root(X) == Root(Y); public int Count => _count; public bool IsParent(int X) => X == Root(X); public int GetParent(int X) => Root(X); public int Size(int X) => sizes[Root(X)]; public long GetWeight(int X) { Root(X); return weight[X]; } public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X); } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } public class SortedMultiSet<T> : IEnumerable<T> { private SortedDictionary<T, int> _dict; public SortedMultiSet() { _dict = new SortedDictionary<T, int>(); } public SortedMultiSet(IEnumerable<T> items) : this() { Add(items); } public bool Contains(T item) { return _dict.ContainsKey(item); } public void Add(T item) { if (_dict.ContainsKey(item)) _dict[item]++; else _dict[item] = 1; } public void Add(IEnumerable<T> items) { foreach (var item in items) Add(item); } public void Remove(T item) { if (!_dict.ContainsKey(item)) throw new ArgumentException(); if (--_dict[item] == 0) _dict.Remove(item); } // Return the last value in the multiset public T Peek() { if (!_dict.Any()) throw new NullReferenceException(); return _dict.Last().Key; } // Return the last value in the multiset and remove it. public T Pop() { T item = Peek(); Remove(item); return item; } public IEnumerator<T> GetEnumerator() { foreach (var kvp in _dict) for (int i = 0; i < kvp.Value; i++) yield return kvp.Key; } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } class Treap<T> : IEnumerable<T> where T : IComparable { public int Length { get { return this.Root == null ? 0 : this.NodeCount(this.Root); } } public T this[int i] { get { if (this.Root.Count < i - 1) throw new IndexOutOfRangeException(); return this.Root.Get(i); } } public Node Root; private IComparer<T> Cmp = Comparer<T>.Default; public Treap(IComparer<T> cmp = null) { if (cmp != null) this.Cmp = cmp; } public Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if (l.Priority > r.Priority) { l.R = this.Merge(l.R, r); return this.Update(l); } else { r.L = this.Merge(l, r.L); return this.Update(r); } } // 左にk個、右に残り(n-k)個に分割する public (Node, Node) Split(int k) { return this.Split(this.Root, k); } public (Node, Node) Split(Node t, int k) { if (t == null) return (null, null); if (k <= this.NodeCount(t.L)) { var s = this.Split(t.L, k); t.L = s.Item2; return (s.Item1, this.Update(t)); } else { var s = this.Split(t.R, k - this.NodeCount(t.L) - 1); t.R = s.Item1; return (this.Update(t), s.Item2); } } public int NodeCount(Node node) { return node == null ? 0 : node.Count; } public int LowerBouond(T value) { return this.LowerBouond(this.Root, value); } public int LowerBouond(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) <= 0) return this.LowerBouond(node.L, value); else return this.NodeCount(node.L) + 1 + this.LowerBouond(node.R, value); } public int UpperBound(T value) { return this.UpperBound(this.Root, value); } public int UpperBound(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) >= 0) return this.NodeCount(node.L) + 1 + this.UpperBound(node.R, value); else return this.UpperBound(node.L, value); } public int ValueCount(T value) { return this.UpperBound(value) - this.LowerBouond(value); } public void Insert(T value) { var sub = this.Split(this.Root, this.LowerBouond(value)); var newNode = new Node(value); var merged = this.Merge(sub.Item1, newNode); this.Root = this.Merge(merged, sub.Item2); } public void Erase(T value) { if (this.ValueCount(value) == 0) return; var sub = this.Split(this.Root, this.LowerBouond(value)); this.Root = this.Merge(sub.Item1, this.Split(sub.Item2, 1).Item2); } public void InsertAt(Node node, int k) { var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public void InsertAt(T value, int k) { var node = new Node(value); var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public Node EraseAt(int k) { var sub = this.Split(this.Root, k); var sub2 = this.Split(sub.Item2, 1); var res = sub2.Item1; this.Root = this.Merge(sub.Item1, sub2.Item2); return res; } public Node Update(Node node) { node.Count = this.NodeCount(node.L) + this.NodeCount(node.R) + 1; return node; } public class Node { private static Random Rand = new Random(); public T Value; public Node L = null; public Node R = null; public int Count; public double Priority; public Node(T value, double priority) { this.Value = value; this.Priority = priority; this.Count = 1; } public Node(T value) : this(value, Rand.NextDouble()) {} public T Get(int i) { return this.GetNode(i).Value; } public Node GetNode(int i) { var lcount = 0; if (this.L != null) lcount = this.L.Count; if (lcount == i) return this; else if (lcount < i) return this.R.GetNode(i - lcount - 1); else return this.L.GetNode(i); } } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) yield return this.Root.Get(i); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } public static class ObjectExtension { // ディープコピーの複製を作る拡張メソッド public static T DeepClone<T>(this T src) { using (var memoryStream = new System.IO.MemoryStream()) { var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); binaryFormatter.Serialize(memoryStream, src); // シリアライズ memoryStream.Seek(0, System.IO.SeekOrigin.Begin); return (T)binaryFormatter.Deserialize(memoryStream); // デシリアライズ } } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; using System.Collections; namespace CompetitiveProgramming { public class CPair<T, U> : IComparable where T : IComparable<T> { public readonly T Item1; public readonly U Item2; public int CompareTo(object obj) { CPair<T, U> castedObj = (CPair<T, U>)obj; return this.Item1.CompareTo(castedObj.Item1); } public CPair(T t, U u) { Item1 = t; Item2 = u; } } class Pair : IComparable { public long x; public long a; public long b; public long c; public Pair(long X, long Y, long Z, long D) { x = X; a = Y; b = Z; c = D; } public Pair(long a, long x) { this.a = a; this.x = x; } public Pair(long a, long b, long c) { this.a = a; this.b = b; this.c = c; } public int CompareTo(object obj) { Pair kore = (Pair)obj; return x.CompareTo(kore.x); } public static bool operator <=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x <= p2.x; } else { return p1.a <= p2.a; } } public static bool operator >=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x >= p2.x; } else { return p1.a >= p2.a; } } } class Zettiti : IComparable { public long num; public Zettiti(long num) { this.num = num; } public int CompareTo(object obj) { Zettiti kore = (Zettiti)obj; long knum = Math.Abs(kore.num); long mynum = Math.Abs(num); return mynum.CompareTo(knum); } } class Program { static void Main(string[] args) { // Utils.BinarySearch.Search StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); string str = scan.Scan(); int moto = 111; if (str.Contains("000")) { Console.WriteLine("Yes"); return; } for (int i = 1; i <= 9; i++) { if (str.Contains((moto * i).ToString())) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } static string dffs(int n, int m, Tuple<int, int>[] tuples, int cur, int sum, string now) { if (sum == n) return now; if (cur == m) return ""; string zan = now; for (int i = 0; i < (n - sum) / tuples[cur].Item1; i++) { zan += tuples[cur].Item2; } for (int i = (n - sum) / tuples[cur].Item1; i >= 0; i--) { string buf = dffs(n, m, tuples, cur + 1, sum + i * tuples[cur].Item1, zan); if (buf != "") return buf; zan = zan.Substring(0, zan.Length - 1); ; } return ""; } static bool isOK(long mid, long[] a, long[] f, long k) { long count = 0; for (long i = 0; i < a.Length; i++) { long togo = mid / f[i]; ; count += Math.Max(0, a[i] - togo); } return (count <= k); } static void Output<T>(List<T> list, string kugiri = "\n") { for (int i = 0; i < list.Count; i++) { Console.Write(list[i]); if (i != list.Count - 1) { Console.Write(kugiri); } } } static void Output<T>(T[] list, string kugiri = "\n") { for (int i = 0; i < list.Length; i++) { Console.Write(list[i]); if (i != list.Length - 1) { Console.Write(kugiri); } } } static void Output<T>(T[,] list, string kugiri1 = " ", string kugiri2 = "\n") { int len1 = list.GetLength(0); int len2 = list.GetLength(1); for (int i = 0; i < len1; i++) { for (int j = 0; j < len2; j++) { Console.Write(list[i, j]); if (j != len2 - 1) { Console.Write(kugiri1); } } if (i != len1 - 1) { Console.Write(kugiri2); } } } static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isok(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int binary_search(int key, int[] moto) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int[] Togo; static bool CheckBipartite(int now, int prev, List<int>[] g, int c = 0) // 0,-1が想定 { if (Togo == null) Togo = Enumerable.Repeat(-1, g.Length).ToArray(); foreach (var next in g[now]) { if (next == prev) continue; var nextc = Togo[next]; if (nextc >= 0 && nextc == c) return false; if (nextc >= 0) continue; Togo[next] = (c + 1) % 2; var res = CheckBipartite(next, now, g, (c + 1) % 2); if (res == false) return false; } return true; } static bool isOK(int index, int key, int[] moto) { return moto[index] > key; } public static int bitCount(int k) { uint i = (uint)k; i = i - ((i >> 1) & 0x55555555); i = (i & 0x33333333) + ((i >> 2) & 0x33333333); i = (i + (i >> 4)) & 0x0f0f0f0f; i = i + (i >> 8); i = i + (i >> 16); return (int)i & 0x3f; } static int check(long moto, long tai) { if (tai % moto != 0) { return 0; } while (tai > 1) { if (tai % moto == 0) { tai /= moto; } else if (tai > moto) { tai %= moto; } else { tai -= moto; } } if (tai == 1) { return 1; } else { return 0; } } static bool NextPermutation(int[] array) { var size = array.Length; var ok = false; // array[i]<array[i+1]を満たす最大のiを求める int i = size - 2; for (; 0 <= i; i--) { if (array[i] < array[i + 1]) { ok = true; break; } } //全ての要素が降順の場合、NextPermutationは存在しない if (ok == false) return false; // array[i]<array[j]を満たす最大のjを求める int j = size - 1; for (;; j--) { if (array[i] < array[j]) break; } // iとjの要素をswapする var tmp = array[i]; array[i] = array[j]; array[j] = tmp; // i以降の要素を反転させる Array.Reverse(array, i + 1, size - (i + 1)); return true; } static List<int[]> GetAllPermutation(int N) { var res = new List<int[]>(); var array = Enumerable.Range(0, N).ToArray(); do { var copy = new int[N]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static List<int[]> GetAllPermutation(int[] array) { var size = array.Length; var res = new List<int[]>(); do { var copy = new int[size]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static long Syakutori( int[] a, long k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上 { long sum = 0; int right = 0; long ans = 0; for (int left = 0; left < a.Length; left++) { while (right < a.Length && sum < k) { sum += a[right]; right++; } if (k <= sum) { ans += a.Length - right + 1; } if (left == right) { right++; } else { sum -= a[left]; } } return ans; } static int[] zalgo(String s) { int n = s.Length; int[] ret = new int[n]; ret[0] = n; int i = 1, j = 0; while (i < n) { while (i + j < n && s[j] == s[i + j]) ++j; ret[i] = j; if (j == 0) { ++i; continue; } int k = 1; while (i + k < n && k + ret[k] < j) { ret[i + k] = ret[k]; ++k; } i += k; j -= k; } return ret; } static int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } static long gcd(long a, long b) { if (a % b == 0) { return b; } return gcd(b, a % b); } public static List<long> FactorialMemo = new List<long>() { 1 }; static long Fact(int x) { for (int i = FactorialMemo.Count; i <= x; i++) FactorialMemo.Add(FactorialMemo.Last() * i); return FactorialMemo[x]; } static int[] yousogotoplus(int[] a, int[] b) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[i]; } return c; } static int[] yousogotoplus(int[] a, int[,] b, int l) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[l, i]; } return c; } static int[] yousogotoplus(int[,] a, int l) { int[] c = new int[a.GetLength(1)]; for (int i = 0; i < a.GetLength(1); i++) { c[i] = a[l, i]; } return c; } public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[LowerBound(dp, a[i])] = a[i]; } return LowerBound(dp, long.MaxValue - 1); } static long DivideWith(long m, long n, List<long> primes) { while (m % n == 0) { primes.Add(n); m = m / n; } return m; } static List<CPair<long, long>> SoinsuBunkai(long num) { List<CPair<long, long>> primes = new List<CPair<long, long>>(); List<long> yakusu = new List<long>(); List<long> yakusu2 = new List<long>(); for (int i = 2; i * i <= num; i++) { if (num % i != 0) { continue; } yakusu.Add(i); if (i * i != num) { yakusu2.Add(num / i); } } for (int i = 0; i < yakusu.Count; i++) { if (num % yakusu[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu[i] == 0; j++) { num /= yakusu[i]; } primes.Add(new CPair<long, long>(yakusu[i], j)); } for (int i = yakusu2.Count - 1; i > 0; i--) { if (num % yakusu2[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu2[i] == 0; j++) { num /= yakusu2[i]; } primes.Add(new CPair<long, long>(yakusu2[i], j)); } return primes; } static IEnumerable<int> Primes(int maxnum) { // var sieve = new BitArray(maxnum + 1, true); bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray(); int squareroot = (int)Math.Sqrt(maxnum); for (int i = 2; i <= squareroot; i++) { if (sieve[i] == false) continue; for (int n = i * 2; n <= maxnum; n += i) sieve[n] = false; } for (int i = 2; i <= maxnum; i++) if (sieve[i] == true) yield return i; } /* static long[] SoinsuBunkai(long num) { if (num == 1) return new long[] { 1 }; List<long> primes = new List<long>(); long n = DivideWith(num, 2, primes); n = DivideWith(n, 3, primes); n = DivideWith(n, 5, primes); long i = 0; while (n > 1) { int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 }; foreach (var p in ps) { // 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break; } i += 30; } return primes.ToArray(); }*/ public static int h; public static int w; public static int BFS(int height, int width, char[,] map) { int[] dx = new int[] { -1, 0, 0, 1 }; int[] dy = new int[] { 0, 1, -1, 0 }; bool[,] visited = new bool[h, w]; int[,] len = new int[h, w]; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(new Tuple<int, int>(height, width)); int max = 0; visited[height, width] = true; while (queue.Count > 0) { var now = queue.Dequeue(); for (int i = 0; i < 4; i++) { int ny = now.Item1 + dy[i]; int nx = now.Item2 + dx[i]; if (ny >= h || ny < 0 || nx >= w || nx < 0) continue; if (visited[ny, nx] || map[ny, nx] == '#') continue; visited[ny, nx] = true; len[ny, nx] = len[now.Item1, now.Item2] + 1; max = Math.Max(max, len[ny, nx]); queue.Enqueue(new Tuple<int, int>(ny, nx)); } } return max; } static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Initialize<T>(ref T[] array, T initialvalue) { array = Array.ConvertAll(array, x => initialvalue); } static int[] Manacher(string S) { int i = 0, j = 0; int[] R = new int[S.Length]; while (i < S.Length) { while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j]) ++j; R[i] = j; int k = 1; while (i - k >= 0 && k + R[i - k] < j) { R[i + k] = R[i - k]; ++k; } i += k; j -= k; } return R; } /* static Pair[] a; static int SaikiZentansaku(List<int>now,int count,int last,int n,int m) { List<int> next = new List<int>(); for (int i = 0; i < now.Count; i++) { next.Add(now[i]); } next.Add(last); var kore = next.ToArray(); int ans = 0; if(count==n) { for (int i = 0; i < a.Length; i++) { int A = a[i].a; int b = a[i].b; int c = a[i].c; int d = a[i].x; if (kore[b] - kore[A] == c) { ans += d; } } return ans; } for (int i = last; i <= m; i++) { ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m)); } return ans; }*/ } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private long len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public char[] Char(long n) { char[] kore = new char[n]; for (long i = 0; i < n; i++) { kore[i] = Char(); } return kore; } public char[,] Char(long n, long m) { char[,] kore = new char[n, m]; for (long i = 0; i < n; i++) { for (int j = 0; j < m; j++) { kore[i, j] = Char(); } } return kore; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string[] Scan(long n) { string[] str = new string[n]; for (long i = 0; i < n; i++) { str[i] = Scan(); } return str; } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public long[] Long(long n, bool minus1 = false) { long[] kore = new long[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); if (minus1) kore[i]--; } return kore; } public Mlong[] MLong(long n) { Mlong[] kore = new Mlong[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public long[,] Long(long h, long w, bool minus1 = false) { long[,] kore = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = Long(); if (minus1) kore[i, j]--; } } return kore; } public int Integer() { return (int)Long(); } public Mint[] MInteger(long n) { Mint[] kore = new Mint[n]; for (int i = 0; i < n; i++) { kore[i] = Integer(); } return kore; } public int[] Integer(long n, bool minus1 = false) { int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = (int)Long(); if (minus1) kore[i]--; } return kore; } public int[,] Integer(long h, long w, bool minus1 = false) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = (int)Long(); if (minus1) kore[i, j]--; } } return kore; } public int[] StringToInt(int n) { char[] s = Scan().ToCharArray(); int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = s[i] - '0'; } return kore; } public int[,] StringToInt(int h, int w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { char[] s = Scan().ToCharArray(); for (int j = 0; j < w; j++) { kore[i, j] = s[j] - '0'; } } return kore; } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } public int Size(int x) { return -data[Root(x)]; } } public class Mlong : IComparable { public static long mod = 1000000007; public long num; public Mlong(long num) { if (num < 0) { num += mod; } this.num = num % mod; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mlong operator +(Mlong x, Mlong y) { return new Mlong((x.num + y.num) % mod); } public static Mlong operator -(Mlong x, Mlong y) { return new Mlong((x.num - y.num + mod) % mod); } public static Mlong operator *(Mlong x, Mlong y) { return new Mlong((long)(((1L * x.num) * y.num) % mod)); } public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); } static long GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; } public static implicit operator Mlong(long x) { return new Mlong(x); } public static Mlong operator %(Mlong x, Mlong y) { return new Mlong(x.num % y.num); } public static explicit operator long(Mlong x) { return x.num; } public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; } public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; } public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; } public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; } public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; } public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; } public Mlong Pow(Mlong n) { Mlong pow = this; Mlong res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n = n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); } public static List<Mlong> FactorialMemo = new List<Mlong>() { 1 }; static Mlong Factorial(int x) { for (int i = FactorialMemo.Count; i <= x; i++) FactorialMemo.Add(FactorialMemo.Last() * i); return FactorialMemo[x]; } public static Mlong Comb(Mlong n, Mlong a) { Mlong buf1 = 1; Mlong buf2 = 1; for (long i = 0; i < a.num; i++) { buf1 *= n - i; buf2 *= (i + 1); } return buf1.modjyo(buf2); } public static Mlong Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mlong x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mlong kore = (Mlong)obj; return num.CompareTo(kore.num); } } public class Mint : IComparable { public static int mod = 1000000007; public int num; public Mint(int Num) { num = Num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mint operator +(Mint x, Mint y) { return new Mint((x.num + y.num) % mod); } public static Mint operator -(Mint x, Mint y) { return new Mint((x.num - y.num + mod) % mod); } public static Mint operator *(Mint x, Mint y) { return new Mint((int)(((1L * x.num) * y.num) % mod)); } public Mint hutujyo(Mint x) { return new Mint(num / x.num); } static int GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return (int)(x2 + mod); div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return (int)(x1 + mod); div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; } /* public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }*/ public static implicit operator Mint(int x) { return new Mint(x); } public static Mint[] Toarray(int[] x) { Mint[] buf = new Mint[x.Length]; for (int i = 0; i < x.Length; i++) { buf[i] = x[i]; } return buf; } public static explicit operator int(Mint x) { return x.num; } public static Mint operator %(Mint x, Mint y) { return new Mint(x.num % y.num); } public static bool operator ==(Mint x, Mint y) { return x.num == y.num; } public static bool operator !=(Mint x, Mint y) { return x.num != y.num; } public static bool operator<(Mint x, Mint y) { return x.num < y.num; } public static bool operator>(Mint x, Mint y) { return x.num > y.num; } public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; } public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; } public Mint Pow(Mint n) { Mint pow = this; Mint res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mint Pow(Mint a, Mint n) { return a.Pow(n); } public static List<Mint> FactorialMemo = new List<Mint>() { 1 }; static Mint Factorial(int x) { for (int i = FactorialMemo.Count; i <= x; i++) FactorialMemo.Add(FactorialMemo.Last() * i); return FactorialMemo[x]; } public static Mint Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mint x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mint kore = (Mint)obj; return num.CompareTo(kore.num); } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } public class Tree { public Node[] Nodes; public List<int[]> hen; public class Node { public int? parent = null; public List<int[]> children = new List<int[]>(); public int parentcolor = -1; } public Tree(int kosu) { Nodes = new Node[kosu]; for (int i = 0; i < Nodes.Length; i++) { Nodes[i] = new Node(); } hen = new List<int[]>(); } public void Connect(int oya, int ko, int id) { hen.Add(new int[] { oya, ko, 0 }); Nodes[oya].children.Add(new int[] { ko, id }); Nodes[ko].parent = oya; } } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } // return ret; return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public bool Any() { return _root != null; } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public T max() { SB_BinarySearchTree<T>.Node ima = _root; while (ima.RChild != null) { ima = ima.RChild; } return ima.Value; } public T min() { SB_BinarySearchTree<T>.Node ima = _root; while (ima.LChild != null) { ima = ima.LChild; } return ima.Value; } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public class RollingHashSlow { public const long B = (long)1e5 + 7; public const long MOD = (long)1e9 + 7; public string S { get; set; } public int N { get; set; } public long[] Power { get; set; } public long[] Hash { get; set; } public RollingHashSlow(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new long[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = (this.Power[i] * B) % MOD; } // ハッシュを前計算する this.Hash = new long[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD; } } // S[l, r) のハッシュ値を求める public long Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD); if (hash < 0) hash += MOD; return hash; } } class RollingHashFast { public const ulong B = (ulong)1e9 + 7; public string S { get; set; } public int N { get; set; } public ulong[] Power { get; set; } public ulong[] Hash { get; set; } public RollingHashFast(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new ulong[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = this.Power[i] * B; } // ハッシュを前計算する this.Hash = new ulong[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = this.Hash[i] * B + S[i]; } } // [l, r) のハッシュ値を求める public ulong Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]); return hash; } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } // [s, t) public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class WarshallFloyd { public int V { get; set; } public long[,] DP { get; set; } public long INF = long.MaxValue; public bool[] Negative; public WarshallFloyd(int v) { this.V = v; this.DP = new long[V, V]; for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { this.DP[i, j] = INF; } this.DP[i, i] = 0; } } public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; } public long[,] CalcMinCost() { this.Negative = new bool[V]; for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]); } } } for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; if (DP[i, j] > DP[i, k] + DP[k, j]) { this.Negative[i] = true; this.Negative[j] = true; this.Negative[k] = true; } } } } return DP; } public long GetMinCost(int a, int b) { return DP[a, b]; } public bool IsINF(int a, int b) { return DP[a, b] >= INF; } public bool IsNegative(params int[] vs) { if (vs.Length == 0) vs = Enumerable.Range(0, V).ToArray(); foreach (var v in vs) { if (Negative[v]) return true; } return false; } } /// <summary> /// Get min cost between two points /// </summary> public class Dijkstra { private int maxIndex = -1; private const int INF = Int32.MaxValue; private int[,] _edgeArray; /// <summary> /// Dijkstra, get min cost between two points /// should not contain negatie cost path /// </summary> /// <param name="size">max index of vertices</param> public Dijkstra(int size) { maxIndex = size + 1; _edgeArray = new int[maxIndex, maxIndex]; for (int i = 0; i < _edgeArray.GetLength(0); i++) { for (int j = 0; j < _edgeArray.GetLength(1); j++) { _edgeArray[i, j] = INF; if (i == j) _edgeArray[i, j] = 0; } } } // Add a path(no direction) with its cost public void AddPath(int s, int t, int cost) { _edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost); _edgeArray[t, s] = _edgeArray[s, t]; } // Get the min cost between s and t // return Int32.MaxValue if no path public int GetMinCost(int s, int t) { int[] cost = new int[maxIndex]; for (int i = 0; i < cost.Length; i++) cost[i] = INF; cost[s] = 0; var priorityQueue = new PriorityQueue<CPair<int, int>>(); priorityQueue.Enqueue(new CPair<int, int>(0, s)); while (priorityQueue.Count() > 0) { var costDestinationPair = priorityQueue.Dequeue(); if (cost[costDestinationPair.Item2] < costDestinationPair.Item1) continue; for (int i = 0; i < maxIndex; i++) { int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF ? INF : costDestinationPair.Item1 + _edgeArray[costDestinationPair.Item2, i]; if (newCostToi < cost[i]) { cost[i] = newCostToi; priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i)); } } } return cost[t]; } } class Deque<T> : IEnumerable<T> { public T this[int i] { get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; } set { if (i < 0) throw new ArgumentOutOfRangeException(); this.Buffer[(this.FirstIndex + i) % this.Capacity] = value; } } private T[] Buffer; private int Capacity; private int FirstIndex; private int LastIndex { get { return (this.FirstIndex + this.Length) % this.Capacity; } } public int Length; public Deque(int capacity = 16) { this.Capacity = capacity; this.Buffer = new T[this.Capacity]; this.FirstIndex = 0; } public void PushBack(T data) { if (this.Length == this.Capacity) this.Resize(); this.Buffer[this.LastIndex] = data; this.Length++; } public void PushFront(T data) { if (this.Length == this.Capacity) this.Resize(); var index = this.FirstIndex - 1; if (index < 0) index = this.Capacity - 1; this.Buffer[index] = data; this.Length++; this.FirstIndex = index; } public T PopBack() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[this.Length - 1]; this.Length--; return data; } public T PopFront() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[0]; this.FirstIndex++; this.FirstIndex %= this.Capacity; this.Length--; return data; } private void Resize() { var newArray = new T[this.Capacity * 2]; for (int i = 0; i < this.Length; i++) { newArray[i] = this[i]; } this.FirstIndex = 0; this.Capacity *= 2; this.Buffer = newArray; } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } public class PotentializedUnionFind { int _count; int[] par, sizes, rank; long[] weight; public PotentializedUnionFind(int N) { _count = N; par = new int[N]; sizes = new int[N]; rank = new int[N]; weight = new long[N]; for (int i = 0; i < N; ++i) { par[i] = i; sizes[i] = 1; rank[i] = 0; } } int Root(int X) { if (par[X] == X) { return X; } else { int r = Root(par[X]); weight[X] += weight[par[X]]; return (par[X] = r); } } public bool Merge(int X, int Y, long W) { W += GetWeight(X); W -= GetWeight(Y); X = Root(X); Y = Root(Y); if (X == Y) return false; --_count; if (rank[X] < rank[Y]) { par[X] = Y; sizes[Y] += sizes[X]; weight[X] = -W; } else { par[Y] = X; sizes[X] += sizes[Y]; if (rank[X] == rank[Y]) ++rank[X]; weight[Y] = W; } return true; } public bool IsSame(int X, int Y) => Root(X) == Root(Y); public int Count => _count; public bool IsParent(int X) => X == Root(X); public int GetParent(int X) => Root(X); public int Size(int X) => sizes[Root(X)]; public long GetWeight(int X) { Root(X); return weight[X]; } public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X); } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } public class SortedMultiSet<T> : IEnumerable<T> { private SortedDictionary<T, int> _dict; public SortedMultiSet() { _dict = new SortedDictionary<T, int>(); } public SortedMultiSet(IEnumerable<T> items) : this() { Add(items); } public bool Contains(T item) { return _dict.ContainsKey(item); } public void Add(T item) { if (_dict.ContainsKey(item)) _dict[item]++; else _dict[item] = 1; } public void Add(IEnumerable<T> items) { foreach (var item in items) Add(item); } public void Remove(T item) { if (!_dict.ContainsKey(item)) throw new ArgumentException(); if (--_dict[item] == 0) _dict.Remove(item); } // Return the last value in the multiset public T Peek() { if (!_dict.Any()) throw new NullReferenceException(); return _dict.Last().Key; } // Return the last value in the multiset and remove it. public T Pop() { T item = Peek(); Remove(item); return item; } public IEnumerator<T> GetEnumerator() { foreach (var kvp in _dict) for (int i = 0; i < kvp.Value; i++) yield return kvp.Key; } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } class Treap<T> : IEnumerable<T> where T : IComparable { public int Length { get { return this.Root == null ? 0 : this.NodeCount(this.Root); } } public T this[int i] { get { if (this.Root.Count < i - 1) throw new IndexOutOfRangeException(); return this.Root.Get(i); } } public Node Root; private IComparer<T> Cmp = Comparer<T>.Default; public Treap(IComparer<T> cmp = null) { if (cmp != null) this.Cmp = cmp; } public Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if (l.Priority > r.Priority) { l.R = this.Merge(l.R, r); return this.Update(l); } else { r.L = this.Merge(l, r.L); return this.Update(r); } } // 左にk個、右に残り(n-k)個に分割する public (Node, Node) Split(int k) { return this.Split(this.Root, k); } public (Node, Node) Split(Node t, int k) { if (t == null) return (null, null); if (k <= this.NodeCount(t.L)) { var s = this.Split(t.L, k); t.L = s.Item2; return (s.Item1, this.Update(t)); } else { var s = this.Split(t.R, k - this.NodeCount(t.L) - 1); t.R = s.Item1; return (this.Update(t), s.Item2); } } public int NodeCount(Node node) { return node == null ? 0 : node.Count; } public int LowerBouond(T value) { return this.LowerBouond(this.Root, value); } public int LowerBouond(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) <= 0) return this.LowerBouond(node.L, value); else return this.NodeCount(node.L) + 1 + this.LowerBouond(node.R, value); } public int UpperBound(T value) { return this.UpperBound(this.Root, value); } public int UpperBound(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) >= 0) return this.NodeCount(node.L) + 1 + this.UpperBound(node.R, value); else return this.UpperBound(node.L, value); } public int ValueCount(T value) { return this.UpperBound(value) - this.LowerBouond(value); } public void Insert(T value) { var sub = this.Split(this.Root, this.LowerBouond(value)); var newNode = new Node(value); var merged = this.Merge(sub.Item1, newNode); this.Root = this.Merge(merged, sub.Item2); } public void Erase(T value) { if (this.ValueCount(value) == 0) return; var sub = this.Split(this.Root, this.LowerBouond(value)); this.Root = this.Merge(sub.Item1, this.Split(sub.Item2, 1).Item2); } public void InsertAt(Node node, int k) { var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public void InsertAt(T value, int k) { var node = new Node(value); var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public Node EraseAt(int k) { var sub = this.Split(this.Root, k); var sub2 = this.Split(sub.Item2, 1); var res = sub2.Item1; this.Root = this.Merge(sub.Item1, sub2.Item2); return res; } public Node Update(Node node) { node.Count = this.NodeCount(node.L) + this.NodeCount(node.R) + 1; return node; } public class Node { private static Random Rand = new Random(); public T Value; public Node L = null; public Node R = null; public int Count; public double Priority; public Node(T value, double priority) { this.Value = value; this.Priority = priority; this.Count = 1; } public Node(T value) : this(value, Rand.NextDouble()) {} public T Get(int i) { return this.GetNode(i).Value; } public Node GetNode(int i) { var lcount = 0; if (this.L != null) lcount = this.L.Count; if (lcount == i) return this; else if (lcount < i) return this.R.GetNode(i - lcount - 1); else return this.L.GetNode(i); } } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) yield return this.Root.Get(i); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } public static class ObjectExtension { // ディープコピーの複製を作る拡張メソッド public static T DeepClone<T>(this T src) { using (var memoryStream = new System.IO.MemoryStream()) { var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); binaryFormatter.Serialize(memoryStream, src); // シリアライズ memoryStream.Seek(0, System.IO.SeekOrigin.Begin); return (T)binaryFormatter.Deserialize(memoryStream); // デシリアライズ } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 15, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 15, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
13,950
24
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math; public class Hello { public static void Main() { string[] input = ReadLine().Split(' '); /* int n = int.Parse(input[0]); int m = int.Parse(input[1]); int b = int.Parse(input[2]);*/ // string temp = ReadLine(); int a = int.Parse(ReadLine()); // int b = int.Parse(ReadLine()); // string a = ReadLine(); // string b = ReadLine(); int b = a / 10; a = a % 1000; if (a % 111 == 0 || b % 111 == 0) { WriteLine("Yes"); } else { WriteLine("No"); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math; public class Hello { public static void Main() { // string[] input = ReadLine().Split(' '); /* int n = int.Parse(input[0]); int m = int.Parse(input[1]); int b = int.Parse(input[2]);*/ // string temp = ReadLine(); int a = int.Parse(ReadLine()); // int b = int.Parse(ReadLine()); // string a = ReadLine(); // string b = ReadLine(); int b = a / 10; a = a % 1000; if (a % 111 == 0 || b % 111 == 0) { WriteLine("Yes"); } else { WriteLine("No"); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 212, 0, 213, 63, 214, 205, 213, 63, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
8
119
16
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; /*Please dont change namespace, Dcoder and class must not be public*/ // Compiler version 4.0, .NET Framework 4.5 namespace Dcoder { public class Program { public static void Main(string[] args) { string s = Console.ReadLine(); if (s[0] == s[1] && s[1] == s[2]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } if (s[1] == s[2] && s[2] == s[3]) { Console.WriteLine("Yes"); } else Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; /*Please dont change namespace, Dcoder and class must not be public*/ // Compiler version 4.0, .NET Framework 4.5 namespace Dcoder { public class Program { public static void Main(string[] args) { string s = Console.ReadLine(); if (s[0] == s[1] && s[1] == s[2]) { Console.WriteLine("Yes"); } else if (s[1] == s[2] && s[2] == s[3]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 46]]
8
142
13
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Program().Solve(new MyInputStream(Console.In, ' ')); Console.Out.Flush(); } public void Solve(MyInputStream cin) { var val = cin.Read(); var x = val[0]; var c = 0; var max = 0; for (int i = 1; i < val.Length; ++i) if (val[i] == x) c++; else { max = Max(c, max); c = 0; x = val[i]; } if (max >= 2) WriteLine("Yes"); else WriteLine("No"); } } public class MyInputStream { private readonly System.IO.TextReader _stream; private char separator = ' '; private Queue<string> inputStream; public MyInputStream(System.IO.TextReader s, char separator = ' ') { this.separator = separator; this._stream = s; inputStream = new Queue<string>(); } public string Read() { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } public string ReadLine() { return _stream.ReadLine(); } public int ReadInt() { return int.Parse(Read()); } public long ReadLong() { return long.Parse(Read()); } public double ReadDouble() { return double.Parse(Read()); } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read(); return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt(); return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong(); return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Program().Solve(new MyInputStream(Console.In, ' ')); Console.Out.Flush(); } public void Solve(MyInputStream cin) { var val = cin.Read(); var x = val[0]; var c = 0; var max = 0; for (int i = 1; i < val.Length; ++i) if (val[i] == x) c++; else { max = Max(c, max); c = 0; x = val[i]; } max = Max(c, max); if (max >= 2) WriteLine("Yes"); else WriteLine("No"); } } public class MyInputStream { private readonly System.IO.TextReader _stream; private char separator = ' '; private Queue<string> inputStream; public MyInputStream(System.IO.TextReader s, char separator = ' ') { this.separator = separator; this._stream = s; inputStream = new Queue<string>(); } public string Read() { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } public string ReadLine() { return _stream.ReadLine(); } public int ReadInt() { return int.Parse(Read()); } public long ReadLong() { return long.Parse(Read()); } public double ReadDouble() { return double.Parse(Read()); } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read(); return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt(); return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong(); return ret; } } }
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
567
9
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; using static System.Console; // using System.Numerics; // using static System.Math; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; void solve() { var S = cin.next; if (S[0] == S[1] && S[1] == S[2] && S[2] == S[3]) { WriteLine("Yes"); } else { WriteLine("No"); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return 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 = ReadLine(); while (st == "") st = 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.Text; using System.Globalization; using System.Diagnostics; using static System.Console; // using System.Numerics; // using static System.Math; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; void solve() { var S = cin.next; if ((S[0] == S[1] && S[1] == S[2]) || (S[1] == S[2] && S[2] == S[3])) { WriteLine("Yes"); } else { WriteLine("No"); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return 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 = ReadLine(); while (st == "") st = 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); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 17, 60], ["+", 31, 23, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
8
409
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { public class QuestionA { public static void Main(string[] args) { // 整数の入力 long n = long.Parse(Console.ReadLine()); long[] L = { 2, 1 }; long next = 0; for (int i = 2; i <= n; ++i) { next = L[0] + L[1]; L[0] = L[1]; L[1] = next; } Console.WriteLine(next); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { public class QuestionA { public static void Main(string[] args) { // 整数の入力 long n = long.Parse(Console.ReadLine()); long[] L = { 2, 1 }; long next = 0; if (n == 1) { Console.WriteLine(1); return; } for (int i = 2; i <= n; ++i) { next = L[0] + L[1]; L[0] = L[1]; L[1] = next; } Console.WriteLine(next); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
133
17
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Program { public static Scanner input; static void Main() { input = new Scanner(); string s = input.String(); int n = input.Int(); var arr = new long[n]; for (int a = 0; a <= n; a++) { if (a == 0) { arr[a] = 2; } else if (a == 1) { arr[a] = 1; } else { arr[a] = arr[a - 2] + arr[a - 1]; } } WriteLine(arr[n]); } } class Scanner { public Scanner() {} public void skip() { ReadLine(); return; } public string String() { return ReadLine(); } public string[] splitString() { return ReadLine().Split(); } public string[] linesString(int len) { var arr = new string[len]; for (int a = 0; a < len; a++) { arr[a] = ReadLine(); } return arr; } public string[][] jaggedArrayString(int len) { var arr = new string[len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split(); } return arr; } public int Int() { return int.Parse(ReadLine()); } public int[] splitInt() { return ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } public int[] linesInt(int len) { var arr = new int[len]; for (int a = 0; a < len; a++) { arr[a] = int.Parse(ReadLine()); } return arr; } public int[][] jaggedArrayInt(int len) { var arr = new int [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } return arr; } public long Long() { return long.Parse(ReadLine()); } public long[] splitLong() { return ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } public long[] linesLong(int len) { var arr = new long[len]; for (int a = 0; a < len; a++) { arr[a] = long.Parse(ReadLine()); } return arr; } public long[][] jaggedArrayLong(int len) { var arr = new long [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } return arr; } public double Double() { return double.Parse(ReadLine()); } public double[] splitDouble() { return ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } public double[] linesDouble(int len) { var arr = new double[len]; for (int a = 0; a < len; a++) { arr[a] = double.Parse(ReadLine()); } return arr; } public double[][] jaggedArrayDouble(int len) { var arr = new double [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } return arr; } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Program { public static Scanner input; static void Main() { input = new Scanner(); int n = input.Int(); var arr = new long[n + 1]; for (int a = 0; a <= n; a++) { if (a == 0) { arr[a] = 2; } else if (a == 1) { arr[a] = 1; } else { arr[a] = arr[a - 2] + arr[a - 1]; } } WriteLine(arr[n]); } } class Scanner { public Scanner() {} public void skip() { ReadLine(); return; } public string String() { return ReadLine(); } public string[] splitString() { return ReadLine().Split(); } public string[] linesString(int len) { var arr = new string[len]; for (int a = 0; a < len; a++) { arr[a] = ReadLine(); } return arr; } public string[][] jaggedArrayString(int len) { var arr = new string[len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split(); } return arr; } public int Int() { return int.Parse(ReadLine()); } public int[] splitInt() { return ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } public int[] linesInt(int len) { var arr = new int[len]; for (int a = 0; a < len; a++) { arr[a] = int.Parse(ReadLine()); } return arr; } public int[][] jaggedArrayInt(int len) { var arr = new int [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } return arr; } public long Long() { return long.Parse(ReadLine()); } public long[] splitLong() { return ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } public long[] linesLong(int len) { var arr = new long[len]; for (int a = 0; a < len; a++) { arr[a] = long.Parse(ReadLine()); } return arr; } public long[][] jaggedArrayLong(int len) { var arr = new long [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } return arr; } public double Double() { return double.Parse(ReadLine()); } public double[] splitDouble() { return ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } public double[] linesDouble(int len) { var arr = new double[len]; for (int a = 0; a < len; a++) { arr[a] = double.Parse(ReadLine()); } return arr; } public double[][] jaggedArrayDouble(int len) { var arr = new double [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } return arr; } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203]]
8
860
11
using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; public static class TemplateExtension { public static X[] MakeArray<X>(this int count, Func<int, X> func) { var xs = new X[count]; for (var i = 0; i < count; i++) { xs[i] = func(i); } return xs; } public static int[] Range(this int count, int start = 0) { return count.MakeArray(i => i + start); } public static string Intercalate<X>(this IEnumerable<X> @this, string separator) { return string.Join(separator, @this); } public sealed class ValueIndexPair<T> : Tuple<T, int> { public T Value { get { return Item1; } } public int Index { get { return Item2; } } public ValueIndexPair(T value, int index) : base(value, index) {} } public static IEnumerable<ValueIndexPair<X>> Indexed<X>(this IEnumerable<X> @this) { var i = 0; foreach (var x in @this) { yield return new ValueIndexPair<X>(x, i); i++; } } } public sealed class Scanner { readonly TextReader reader; readonly StringBuilder sb = new StringBuilder(); /// <summary> /// Reads next word separated by spaces. /// </summary> public string Word() { sb.Clear(); while (true) { var r = reader.Read(); if (r == '\r') { if (reader.Peek() == '\n') reader.Read(); break; } else if (r == -1 || r == ' ' || r == '\n') { break; } else { sb.Append((char)r); } } return sb.ToString(); } /// <summary> /// Reads next word as <see cref="int"/>. /// </summary> public int N() { return int.Parse(Word()); } /// <summary> /// Reads next word as <see cref="long"/>. /// </summary> public long L() { return long.Parse(Word()); } /// <summary> /// Reads next word as <see cref="double"/>. /// </summary> public double F() { return double.Parse(Word()); } public int[] Ns(int count) { return count.MakeArray(_ => N()); } public long[] Ls(int count) { return count.MakeArray(_ => L()); } public double[] Fs(int count) { return count.MakeArray(_ => F()); } /// <summary> /// Reads next line and splits it by spaces. /// </summary> public X[] Words<X>(Func<string, X> func) { return reader.ReadLine().Split(' ').Select(func).ToArray(); } public Scanner(TextReader reader) { this.reader = reader; } } public partial class Program { readonly TextReader input; readonly TextWriter output; readonly Scanner scanner; void WriteLine(int value) { output.WriteLine(value); } void WriteLine(long value) { output.WriteLine(value); } void WriteLine(double value) { output.WriteLine(value); } void WriteLine(char value) { output.WriteLine(value); } void WriteLine(string value) { output.WriteLine(value); } public Program(TextReader input, TextWriter output) { this.input = input; this.output = output; scanner = new Scanner(input); } public static void Main(string[] args) { #if DEBUG using (var writer = new VainZero.IO.DebugTextWriter(Console.Out)) #else var writer = Console.Out; #endif { new Program(Console.In, writer).EntryPoint(); } } } public sealed partial class Program { int n, m; List<int>[] es; bool[] color; bool[] done; // 2部グラフだったら color に色を付けつつ true を返す。 bool Dfs(int u, bool c) { if (done[u]) { return color[u] == c; } done[u] = true; color[u] = c; foreach (var v in es[u]) { if (!Dfs(v, !c)) return false; } return true; } long Solve() { done = n.MakeArray(u => false); color = n.MakeArray(u => default(bool)); var isBipartite = Dfs(0, false); // 単純グラフ上に存在できる辺の個数。 var k = n * (n - 1) / 2; if (isBipartite) { var p = color.Count(c => c); var q = n - p; // 同じ色の点の間に存在できる辺の個数。 var l = (p * (p - 1) / 2) + (q * (q - 1) / 2); // l から、同じ色の点の間にすでに存在する辺の個数を引く。 for (var u = 0; u < n; u++) { foreach (var v in es[u]) { if (u >= v) continue; if (color[u] == color[v]) { l--; } } } throw new Exception(); // return k - (m + l); } else { return k - m; } } void Read() { var a = scanner; n = a.N(); m = a.N(); es = n.MakeArray(u => new List<int>()); for (var i = 0; i < m; i++) { var u = a.N() - 1; var v = a.N() - 1; es[u].Add(v); es[v].Add(u); } } public void EntryPoint() { Read(); WriteLine(Solve()); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; public static class TemplateExtension { public static X[] MakeArray<X>(this int count, Func<int, X> func) { var xs = new X[count]; for (var i = 0; i < count; i++) { xs[i] = func(i); } return xs; } public static int[] Range(this int count, int start = 0) { return count.MakeArray(i => i + start); } public static string Intercalate<X>(this IEnumerable<X> @this, string separator) { return string.Join(separator, @this); } public sealed class ValueIndexPair<T> : Tuple<T, int> { public T Value { get { return Item1; } } public int Index { get { return Item2; } } public ValueIndexPair(T value, int index) : base(value, index) {} } public static IEnumerable<ValueIndexPair<X>> Indexed<X>(this IEnumerable<X> @this) { var i = 0; foreach (var x in @this) { yield return new ValueIndexPair<X>(x, i); i++; } } } public sealed class Scanner { readonly TextReader reader; readonly StringBuilder sb = new StringBuilder(); /// <summary> /// Reads next word separated by spaces. /// </summary> public string Word() { sb.Clear(); while (true) { var r = reader.Read(); if (r == '\r') { if (reader.Peek() == '\n') reader.Read(); break; } else if (r == -1 || r == ' ' || r == '\n') { break; } else { sb.Append((char)r); } } return sb.ToString(); } /// <summary> /// Reads next word as <see cref="int"/>. /// </summary> public int N() { return int.Parse(Word()); } /// <summary> /// Reads next word as <see cref="long"/>. /// </summary> public long L() { return long.Parse(Word()); } /// <summary> /// Reads next word as <see cref="double"/>. /// </summary> public double F() { return double.Parse(Word()); } public int[] Ns(int count) { return count.MakeArray(_ => N()); } public long[] Ls(int count) { return count.MakeArray(_ => L()); } public double[] Fs(int count) { return count.MakeArray(_ => F()); } /// <summary> /// Reads next line and splits it by spaces. /// </summary> public X[] Words<X>(Func<string, X> func) { return reader.ReadLine().Split(' ').Select(func).ToArray(); } public Scanner(TextReader reader) { this.reader = reader; } } public partial class Program { readonly TextReader input; readonly TextWriter output; readonly Scanner scanner; void WriteLine(int value) { output.WriteLine(value); } void WriteLine(long value) { output.WriteLine(value); } void WriteLine(double value) { output.WriteLine(value); } void WriteLine(char value) { output.WriteLine(value); } void WriteLine(string value) { output.WriteLine(value); } public Program(TextReader input, TextWriter output) { this.input = input; this.output = output; scanner = new Scanner(input); } public static void Main(string[] args) { #if DEBUG using (var writer = new VainZero.IO.DebugTextWriter(Console.Out)) #else var writer = Console.Out; #endif { new Program(Console.In, writer).EntryPoint(); } } } public sealed partial class Program { int n, m; List<int>[] es; bool[] color; bool[] done; // 2部グラフだったら color に色を付けつつ true を返す。 bool Dfs(int u, bool c) { if (done[u]) { return color[u] == c; } done[u] = true; color[u] = c; foreach (var v in es[u]) { if (!Dfs(v, !c)) return false; } return true; } long Solve() { done = n.MakeArray(u => false); color = n.MakeArray(u => default(bool)); var isBipartite = Dfs(0, false); // 単純グラフ上に存在できる辺の個数。 var k = (long)n * (n - 1) / 2; if (isBipartite) { var p = (long)color.Count(c => c); var q = n - p; // 同じ色の点の間に存在できる辺の個数。 var l = (p * (p - 1) / 2) + (q * (q - 1) / 2); // l から、同じ色の点の間にすでに存在する辺の個数を引く。 for (var u = 0; u < n; u++) { foreach (var v in es[u]) { if (u >= v) continue; if (color[u] == color[v]) { l--; } } } return k - (m + l); } else { return k - m; } } void Read() { var a = scanner; n = a.N(); m = a.N(); es = n.MakeArray(u => new List<int>()); for (var i = 0; i < m; i++) { var u = a.N() - 1; var v = a.N() - 1; es[u].Add(v); es[v].Add(u); } } public void EntryPoint() { Read(); WriteLine(Solve()); } }
[["+", 0, 212, 0, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 212, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 212, 0, 16, 31, 16, 31, 74, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 293, 0, 294], ["-", 0, 57, 64, 196, 0, 293, 0, 230, 0, 228], ["-", 0, 57, 64, 196, 0, 293, 0, 230, 39, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 37, 0, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 37, 0, 16, 17, 33], ["+", 0, 37, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 37, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 37, 0, 16, 12, 23, 0, 16, 12, 22]]
8
1,180
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest._700problems { class CodeFestival2017B_D { static void Main(string[] args) { Method(args); ReadLine(); } static void Method(string[] args) { int n = ReadInt() + 3; string str = Read(); str += "001"; List<List<int>> blockList = new List<List<int>>(); int cnt = 1; bool nowZero = str[0] == '0'; List<int> tmpList = new List<int>(); for (int i = 1; i < n; i++) { if (nowZero == (str[i] == '0')) { cnt++; } else { if (nowZero && cnt >= 2) { if (tmpList.Count >= 2) { blockList.Add(tmpList); } tmpList = new List<int>(); } if (!nowZero) { tmpList.Add(cnt); } cnt = 1; nowZero = !nowZero; } } /*for(int i = 0; i < blockList.Count; i++) { for(int j = 0; j < blockList[i].Count; j++) { Write(blockList[i][j]); } WriteLine(); }*/ int res = 0; for (int i = 0; i < blockList.Count; i++) { int[,] dp = new int[blockList[i].Count, 4]; //全消し/1残し/1消費/手つかず for (int j = 1; j < blockList[i].Count; j++) { dp[j, 2] = Max(dp[j - 1, 1] + 1, Max(dp[j - 1, 2] + blockList[i][j - 1] - 1, dp[j - 1, 3] + blockList[i][j - 1])); dp[j, 3] = Max(Max(dp[j - 1, 0], dp[j - 1, 1]), Max(dp[j - 1, 2], dp[j - 1, 3])); if (blockList[i][j] == 1) { dp[j, 0] = dp[j, 2]; dp[j, 1] = dp[j, 3]; } else { dp[j, 0] = Max(dp[j - 1, 1], Max(dp[j - 1, 2], dp[j - 1, 3])) + blockList[i][j]; dp[j, 1] = Max(dp[j - 1, 1], Max(dp[j - 1, 2], dp[j - 1, 3])) + blockList[i][j] - 1; } } int last = blockList[i].Count - 1; int tmp = Max(Max(dp[last, 0], dp[last, 1]), Max(dp[last, 2], dp[last, 3])); // WriteLine(tmp); res += tmp; } WriteLine(res); } private static string Read() { return ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest._700problems { class CodeFestival2017B_D { static void Main(string[] args) { Method(args); ReadLine(); } static void Method(string[] args) { int n = ReadInt() + 3; string str = Read(); str += "001"; List<List<int>> blockList = new List<List<int>>(); int cnt = 1; bool nowZero = str[0] == '0'; List<int> tmpList = new List<int>(); for (int i = 1; i < n; i++) { if (nowZero == (str[i] == '0')) { cnt++; } else { if (nowZero && cnt >= 2) { if (tmpList.Count >= 2) { blockList.Add(tmpList); } tmpList = new List<int>(); } if (!nowZero) { tmpList.Add(cnt); } cnt = 1; nowZero = !nowZero; } } /*for(int i = 0; i < blockList.Count; i++) { for(int j = 0; j < blockList[i].Count; j++) { Write(blockList[i][j]); } WriteLine(); }*/ int res = 0; for (int i = 0; i < blockList.Count; i++) { int[,] dp = new int[blockList[i].Count, 4]; //全消し/1残し/1消費/手つかず for (int j = 1; j < blockList[i].Count; j++) { dp[j, 2] = Max(dp[j - 1, 1] + 1, Max(dp[j - 1, 2] + blockList[i][j - 1] - 1, dp[j - 1, 3] + blockList[i][j - 1])); dp[j, 3] = Max(Max(dp[j - 1, 0], dp[j - 1, 1]), Max(dp[j - 1, 2], dp[j - 1, 3])); if (blockList[i][j] == 1) { dp[j, 0] = dp[j, 2]; dp[j, 1] = dp[j, 3]; dp[j, 2] = dp[j, 3]; } else { dp[j, 0] = Max(dp[j - 1, 1], Max(dp[j - 1, 2], dp[j - 1, 3])) + blockList[i][j]; dp[j, 1] = Max(dp[j - 1, 1], Max(dp[j - 1, 2], dp[j - 1, 3])) + blockList[i][j] - 1; } } int last = blockList[i].Count - 1; int tmp = Max(Max(dp[last, 0], dp[last, 1]), Max(dp[last, 2], dp[last, 3])); // WriteLine(tmp); res += tmp; } WriteLine(res); } private static string Read() { return ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 21], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
782
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProgrammingContest { class MainClass { Scanner sc; static void Main(string[] args) { new MainClass().Solve(); } void Solve() { #if DEBUG string backPath = ".."; char dirSep = System.IO.Path.DirectorySeparatorChar; string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt"; sc = new Scanner(new System.IO.StreamReader(inFilePath)); #else sc = new Scanner(); #endif const string target = "101"; int n = sc.NextInt + 2; string s = "0" + sc.Next + "0"; int[] dp = new int[n]; List<int>[] lists = new List<int> [n].Select(list => new List<int>()).ToArray(); for (int i = 0; i + 2 < n; i++) { if (s.Substring(i, 3).Equals(target)) { int l = i - 1; while (s[l] == '1') { // 01...101 // [l, i + 2] l--; } int r = i + 3; while (s[r] == '1') { // 101...10 // [i, r] r++; } lists[l].Add(i + 1); // 01...101 lists[i].Add(r); // 101...10 } } for (int i = 0; i < n - 1; i++) { dp[i + 1] = Math.Max(dp[i + 1], dp[i]); foreach (int val in lists[i]) { dp[val] = Math.Max(dp[val], dp[i] + (val - i - 2)); } } Write(dp.Last()); } void Write(object val) { Console.WriteLine(val.ToString()); } void Write(string format, params object[] vals) { Console.WriteLine(format, vals); } } class Scanner { Queue<String> buffer; char[] sep; System.IO.TextReader reader; public Scanner(System.IO.TextReader reader = null) { this.buffer = new Queue<string>(); this.sep = new char[] { ' ' }; this.reader = (reader ?? Console.In); } private void CheckBuffer() { if (this.buffer.Count == 0 && this.reader.Peek() >= 0) { string[] sreArray = this.reader.ReadLine().Split(this.sep); foreach (String elStr in sreArray) { this.buffer.Enqueue(elStr); } } } public String Next { get { this.CheckBuffer(); return this.buffer.Dequeue(); } } public int NextInt { get { return int.Parse(this.Next); } } public double NextDouble { get { return double.Parse(this.Next); } } public long NextLong { get { return long.Parse(this.Next); } } public bool IsEmpty { get { this.CheckBuffer(); return this.buffer.Count == 0; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProgrammingContest { class MainClass { Scanner sc; static void Main(string[] args) { new MainClass().Solve(); } void Solve() { #if DEBUG string backPath = ".."; char dirSep = System.IO.Path.DirectorySeparatorChar; string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt"; sc = new Scanner(new System.IO.StreamReader(inFilePath)); #else sc = new Scanner(); #endif const string target = "101"; int n = sc.NextInt + 2; string s = "0" + sc.Next + "0"; int[] dp = new int[n]; List<int>[] lists = new List<int> [n].Select(list => new List<int>()).ToArray(); for (int i = 0; i + 2 < n; i++) { if (s.Substring(i, 3).Equals(target)) { int l = i - 1; while (s[l] == '1') { // 01...101 // [l, i + 2] l--; } int r = i + 3; while (s[r] == '1') { // 101...10 // [i, r] r++; } lists[l + 1].Add(i + 3); // 01...101 lists[l + 2].Add(i + 3); // 01...101 lists[i].Add(r); // 101...10 lists[i].Add(r - 1); // 101...10 } } for (int i = 0; i < n - 1; i++) { dp[i + 1] = Math.Max(dp[i + 1], dp[i]); foreach (int val in lists[i]) { dp[val] = Math.Max(dp[val], dp[i] + (val - i - 2)); } } Write(dp.Last()); } void Write(object val) { Console.WriteLine(val.ToString()); } void Write(string format, params object[] vals) { Console.WriteLine(format, vals); } } class Scanner { Queue<String> buffer; char[] sep; System.IO.TextReader reader; public Scanner(System.IO.TextReader reader = null) { this.buffer = new Queue<string>(); this.sep = new char[] { ' ' }; this.reader = (reader ?? Console.In); } private void CheckBuffer() { if (this.buffer.Count == 0 && this.reader.Peek() >= 0) { string[] sreArray = this.reader.ReadLine().Split(this.sep); foreach (String elStr in sreArray) { this.buffer.Enqueue(elStr); } } } public String Next { get { this.CheckBuffer(); return this.buffer.Dequeue(); } } public int NextInt { get { return int.Parse(this.Next); } } public double NextDouble { get { return double.Parse(this.Next); } } public long NextLong { get { return long.Parse(this.Next); } } public bool IsEmpty { get { this.CheckBuffer(); return this.buffer.Count == 0; } } } }
[["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 1, 0, 213, 63, 214, 205, 204, 205, 22], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
688
30
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; namespace FertiLib.Contest.A { static class Program { public static void Solve(Scanner cin) { int n = cin.ReadInt(); var s = cin.ReadString(); Console.WriteLine(s.Count(x => x == '1')); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Extention { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); public static int UpperBound<T>(this IList<T> list, T value) => list.BinarySearch(value, true, 0, list.Count, Comparer<T>.Default); public static int LowerBound<T>(this IList<T> list, T value) => list.BinarySearch(value, false, 0, list.Count, Comparer<T>.Default); public static int BinarySearch<T>(this IList<T> list, T value, bool isUpperBound, int index, int length, Comparer<T> comparer) { var ng = index - 1; var ok = index + length; while (ok - ng > 1) { var mid = ng + (ok - ng) / 2; var res = comparer.Compare(list[mid], value); if (res < 0 || (isUpperBound && res == 0)) ng = mid; else ok = mid; } return ok; } } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; namespace FertiLib.Contest.A { static class Program { public static void Solve(Scanner cin) { var s = cin.ReadString(); Console.WriteLine(s.Count(x => x == '1')); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Extention { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); public static int UpperBound<T>(this IList<T> list, T value) => list.BinarySearch(value, true, 0, list.Count, Comparer<T>.Default); public static int LowerBound<T>(this IList<T> list, T value) => list.BinarySearch(value, false, 0, list.Count, Comparer<T>.Default); public static int BinarySearch<T>(this IList<T> list, T value, bool isUpperBound, int index, int length, Comparer<T> comparer) { var ng = index - 1; var ok = index + length; while (ok - ng > 1) { var mid = ng + (ok - ng) / 2; var res = comparer.Compare(list[mid], value); if (res < 0 || (isUpperBound && res == 0)) ng = mid; else ok = mid; } return ok; } } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
8
2,856
9
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static void Main(string[] args) { string s = ReadLine(); if (s.Substring(0, 4) == "YAKI") { WriteLine("Yes"); } else { WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static void Main(string[] args) { string s = ReadLine(); if (s.Length < 4) { WriteLine("No"); } else if (s.Substring(0, 4) == "YAKI") { WriteLine("Yes"); } else { WriteLine("No"); } } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 75, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 75, 57, 15, 16, 31, 213, 63, 214, 0, 131]]
8
97
18
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { var s = sc.Str; if (s.Substring(0, 4) == "YAKI") { Prt("Yes"); } else { Prt("No"); } sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG(string a) { Console.WriteLine(a); } static void DBG<T>(IEnumerable<T> a) { DBG(string.Join(" ", a)); } static void DBG(params object[] a) { DBG(string.Join(" ", a)); } static void Prt(string a) { sw.WriteLine(a); } static void Prt<T>(IEnumerable<T> a) { Prt(string.Join(" ", a)); } static void Prt(params object[] a) { Prt(string.Join(" ", a)); } // for AOJ // static string Join<T>(string sep, IEnumerable<T> a) { return // string.Join(sep, a.Select(x => x.ToString()).ToArray()); } static void // DBG<T>(IEnumerable<T> a) { DBG(Join(" ", a)); } static void DBG(params // object[] a) { DBG(Join(" ", a)); } static void Prt<T>(IEnumerable<T> a) { // Prt(Join(" ", a)); } static void Prt(params object[] a) { Prt(Join(" ", // a)); } } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } public void Multi<T, U, V, W, X, Y, Z>(out T a, out U b, out V c, out W d, out X e, out Y f, out Z g) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); g = cv<Z>(ar[6]); } } static class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double [n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } static long[] facts; public static long[] setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod; return facts; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; if (facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } public static long[][] getcombs(int n) { var ret = new long [n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { var s = sc.Str; if (s.Length < 4) { Prt("No"); } else if (s.Substring(0, 4) == "YAKI") { Prt("Yes"); } else { Prt("No"); } sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG(string a) { Console.WriteLine(a); } static void DBG<T>(IEnumerable<T> a) { DBG(string.Join(" ", a)); } static void DBG(params object[] a) { DBG(string.Join(" ", a)); } static void Prt(string a) { sw.WriteLine(a); } static void Prt<T>(IEnumerable<T> a) { Prt(string.Join(" ", a)); } static void Prt(params object[] a) { Prt(string.Join(" ", a)); } // for AOJ // static string Join<T>(string sep, IEnumerable<T> a) { return // string.Join(sep, a.Select(x => x.ToString()).ToArray()); } static void // DBG<T>(IEnumerable<T> a) { DBG(Join(" ", a)); } static void DBG(params // object[] a) { DBG(Join(" ", a)); } static void Prt<T>(IEnumerable<T> a) { // Prt(Join(" ", a)); } static void Prt(params object[] a) { Prt(Join(" ", // a)); } } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } public void Multi<T, U, V, W, X, Y, Z>(out T a, out U b, out V c, out W d, out X e, out Y f, out Z g) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); g = cv<Z>(ar[6]); } } static class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double [n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } static long[] facts; public static long[] setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod; return facts; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; if (facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } public static long[][] getcombs(int n) { var ret = new long [n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } }
[["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 75, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 75, 57, 15, 16, 31, 213, 63, 214, 0, 131]]
8
3,811
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication76 { class Program { static void Main(string[] args) { string a = Console.ReadLine(); if (a[0] == 'Y' && a[1] == 'A' && a[2] == 'K' && a[3] == 'I') Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication76 { class Program { static void Main(string[] args) { string a = Console.ReadLine(); if (a.Length < 4) Console.WriteLine("No"); else if (a[0] == 'Y' && a[1] == 'A' && a[2] == 'K' && a[3] == 'I') Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 31, 16, 31, 16, 31, 16, 31, 204, 205, 22]]
8
112
18
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using static System.Console; using static System.Math; using static CS_Contest.Utils; using System.Numerics; using System.Linq.Expressions; // using static CS_Contest.Library; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } private class Calc { public void Solve() { var S = ReadLine(); if (S.Substring(0, 4) == "YAKI") Yes(); else No(); return; } } } public static class Utils { public static int ModValue = (int)(1000000007); public static long INF = long.MaxValue; public static long Mod(long x) => x % ModValue; public static long ModPow(long x, long n) { long tmp = 1; while (n != 0) { if (n % 2 == 1) { tmp = Mod(tmp * x); } x = Mod(x * x); n /= 2; } return tmp; } public static long DivMod(long x, long y) => Mod(x * ModPow(y, (long)(1e9 + 5))); public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static int ReadInt() => int.Parse(ReadLine()); public static List<int> ReadInts(char s = ' ') => ReadLine().Split(s).Where(x => x != "").Select(int.Parse).ToList(); public static long ReadLong() => long.Parse(ReadLine()); public static List<long> ReadLongs(char s = ' ') => ReadLine().Split(s).Select(long.Parse).ToList(); public static void ReadMulti(out int x, out int y) { var i = ReadInts(' '); x = i[0]; y = i[1]; } public static void ReadMulti(out long x, out long y) { var i = ReadLongs(' '); x = i[0]; y = i[1]; } public static void ReadMulti(out int x, out int y, out int z) { var i = ReadInts(' '); x = i[0]; y = i[1]; z = i[2]; } public static void ReadMulti(out int x, out int y, out int z, out int v) { var i = ReadInts(' '); x = i[0]; y = i[1]; z = i[2]; v = i[3]; } public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static long GCD(long m, long n) { long tmp; if (m < n) { tmp = n; n = m; m = tmp; } while (m % n != 0) { tmp = n; n = m % n; m = tmp; } return n; } public static long LCM(long m, long n) => m * (n / GCD(m, n)); public static void REP(int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static void RREP(int n, Action<int> act) { for (var i = n - 1; i >= 0; i--) { act(i); } } public static void Yes() => "Yes".WL(); public static void No() => "No".WL(); public static void YES() => "YES".WL(); public static void NO() => "NO".WL(); public static void YesNo(bool cond) { if (cond) Yes(); else No(); } public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1); public struct IndexT<T> { public T Value { get; set; } public int Index { get; set; } public IndexT(T v, int i) { Value = v; Index = i; } public override string ToString() { return Value + " " + Index; } } public static IEnumerable<IndexT<T>> ToIndexEnumerable<T>( this IEnumerable<T> list) => list.Select((x, i) => new IndexT<T>(x, i)); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static IndexT<T> IndexOfMin<T>(this IEnumerable<T> ie) where T : IComparable<T> => ie.ToIndexEnumerable().Aggregate((src, acu) => (src.Value.CompareTo(acu.Value)<0) ? src : acu); public static Tuple<TKey, TSource> ToTuple<TKey, TSource>(this KeyValuePair<TKey, TSource> kvp) => new Tuple<TKey, TSource>(kvp.Key, kvp.Value); public static IEnumerable<Tuple<TKey, TSource>> ToTupleList<TKey, TSource>(this Dictionary<TKey, TSource> d) => d.Select(_ => _.ToTuple()); public static IEnumerable<T> When<T>(this IEnumerable<T> iEnumerable, Func<T, bool> condition, Func<T, T> filterFunc) { var rt = iEnumerable.ToArray(); var index = 0; foreach (var item in iEnumerable) { rt[index] = condition(item) ? filterFunc(item) : item; index++; } return rt; } public static T[] Range<T>(int range, Func<int, T> func) { var rt = new T[range]; for (var i = 0; i < range; i++) rt[i] = func(i); return rt; } public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using static System.Console; using static System.Math; using static CS_Contest.Utils; using System.Numerics; using System.Linq.Expressions; // using static CS_Contest.Library; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } private class Calc { public void Solve() { var S = ReadLine(); if (S.Length < 4) { No(); return; } if (S.Substring(0, 4) == "YAKI") Yes(); else No(); return; } } } public static class Utils { public static int ModValue = (int)(1000000007); public static long INF = long.MaxValue; public static long Mod(long x) => x % ModValue; public static long ModPow(long x, long n) { long tmp = 1; while (n != 0) { if (n % 2 == 1) { tmp = Mod(tmp * x); } x = Mod(x * x); n /= 2; } return tmp; } public static long DivMod(long x, long y) => Mod(x * ModPow(y, (long)(1e9 + 5))); public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static int ReadInt() => int.Parse(ReadLine()); public static List<int> ReadInts(char s = ' ') => ReadLine().Split(s).Where(x => x != "").Select(int.Parse).ToList(); public static long ReadLong() => long.Parse(ReadLine()); public static List<long> ReadLongs(char s = ' ') => ReadLine().Split(s).Select(long.Parse).ToList(); public static void ReadMulti(out int x, out int y) { var i = ReadInts(' '); x = i[0]; y = i[1]; } public static void ReadMulti(out long x, out long y) { var i = ReadLongs(' '); x = i[0]; y = i[1]; } public static void ReadMulti(out int x, out int y, out int z) { var i = ReadInts(' '); x = i[0]; y = i[1]; z = i[2]; } public static void ReadMulti(out int x, out int y, out int z, out int v) { var i = ReadInts(' '); x = i[0]; y = i[1]; z = i[2]; v = i[3]; } public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static long GCD(long m, long n) { long tmp; if (m < n) { tmp = n; n = m; m = tmp; } while (m % n != 0) { tmp = n; n = m % n; m = tmp; } return n; } public static long LCM(long m, long n) => m * (n / GCD(m, n)); public static void REP(int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static void RREP(int n, Action<int> act) { for (var i = n - 1; i >= 0; i--) { act(i); } } public static void Yes() => "Yes".WL(); public static void No() => "No".WL(); public static void YES() => "YES".WL(); public static void NO() => "NO".WL(); public static void YesNo(bool cond) { if (cond) Yes(); else No(); } public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1); public struct IndexT<T> { public T Value { get; set; } public int Index { get; set; } public IndexT(T v, int i) { Value = v; Index = i; } public override string ToString() { return Value + " " + Index; } } public static IEnumerable<IndexT<T>> ToIndexEnumerable<T>( this IEnumerable<T> list) => list.Select((x, i) => new IndexT<T>(x, i)); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static IndexT<T> IndexOfMin<T>(this IEnumerable<T> ie) where T : IComparable<T> => ie.ToIndexEnumerable().Aggregate((src, acu) => (src.Value.CompareTo(acu.Value)<0) ? src : acu); public static Tuple<TKey, TSource> ToTuple<TKey, TSource>(this KeyValuePair<TKey, TSource> kvp) => new Tuple<TKey, TSource>(kvp.Key, kvp.Value); public static IEnumerable<Tuple<TKey, TSource>> ToTupleList<TKey, TSource>(this Dictionary<TKey, TSource> d) => d.Select(_ => _.ToTuple()); public static IEnumerable<T> When<T>(this IEnumerable<T> iEnumerable, Func<T, bool> condition, Func<T, T> filterFunc) { var rt = iEnumerable.ToArray(); var index = 0; foreach (var item in iEnumerable) { rt[index] = condition(item) ? filterFunc(item) : item; index++; } return rt; } public static T[] Range<T>(int range, Func<int, T> func) { var rt = new T[range]; for (var i = 0; i < range; i++) rt[i] = func(i); return rt; } public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131]]
8
1,464
16
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; namespace Program { class MainClass { //////////////////////////////////////////////////////////// string S; void Solve() { S = io.String; bool ans = S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I'; io.o(ans ? "Yes" : "No"); } //////////////////////////////////////////////////////////// public static void Main() { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } // void Stream() { Test(); io.writeFlush(); } void Test() {} #region MockMacro // cannot use break,continue,goto void FOR(int a, int b, Action<int> act) { for (int i = a; i < b; ++i) act(i); } void FORR(int a, int b, Action<int> act) { for (int i = a - 1; i >= b; --i) act(i); } #endregion //////////////////////////////////////////////////////////// } #region default class IO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string[] arr => Console.ReadLine().Split(' '); public char[] arrChar => Array.ConvertAll(arr, char.Parse); public int[] arrInt => Array.ConvertAll(arr, int.Parse); public long[] arrLong => Array.ConvertAll(arr, long.Parse); public double[] arrDouble => Array.ConvertAll(arr, double.Parse); public T i<T>() { return suitType<T>(String); } public void i<T>(out T v) { v = suitType<T>(String); } public void i<T, U>(out T v1, out U v2) { i(out v1); i(out v2); } public void i<T, U, V>(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { i(out v1); i(out v2); i(out v3); i(out v4); } public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4, out X v5) { i(out v1); i(out v2); i(out v3); i(out v4); i(out v5); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) a[i] = suitType<T>(String); } public void ini<T, U>(out T[] a, out U[] b, int n) { a = new T[n]; b = new U[n]; for (int i = 0; i < n; ++i) { a[i] = i<T>(); b[i] = i<U>(); } } public void ini<T, U, V>(out T[] a, out U[] b, out V[] c, int n) { a = new T[n]; b = new U[n]; c = new V[n]; for (int i = 0; i < n; ++i) { a[i] = i<T>(); b[i] = i<U>(); c[i] = i<V>(); } } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) a[i, j] = i<T>(); } public void o<T>(T v) { Console.WriteLine(v); } public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); } public void o<T>(T[,] a) { int a0 = a.GetLength(0), a1 = a.GetLength(1); for (int i = 0; i < a0; ++i) { for (int j = 0; j < a1 - 1; ++j) Console.Write(a[i, j] + " "); Console.WriteLine(a[i, a1 - 1]); } } public void ol<T>(params T[] a) { o(connect<T>(a)); } public void or<T>(T a) { Console.Write(a); } public void br() { o(""); } public void writeFlush() { Console.Out.Flush(); } private string connect<T>(params T[] s) { return string.Join(" ", s); } private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } private T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } private T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } } class PQueue<T> where T : IComparable { public List<T> heap; private Comparison<T> comp; private IComparer<T> comparer; private int size; private int type; // type=0->min public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; } public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) { this.comparer = comparer; } public PQueue(Comparison<T> comparison) : this(16, comparison) {} public PQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.comp = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (Compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } public bool Empty() { return !Any(); } public bool Contains(T v) { return heap.Contains(v); } private int Compare(T x, T y) { return type == 0 ? x.CompareTo(y) : y.CompareTo(x); } } #endregion #region other class Mat { public long mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { long ret = 1; for (long i = 1; i <= n; i++) ret = (ret * i) % mod; return ret; } public long ModC(long n, long r) { if (r == 0 || n == r) return 1; if (n == 0) return 0; if (n < 0 || n < r) throw new ArgumentException("n,r invalid"); else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public long[,] C(int N) { long[,] Co = new long[N + 1, N + 1]; (N + 1).REP(i => (i + 1).REP(j => Co[i, j] = (j == 0 || j == i) ? 1L : Co[i - 1, j - 1] + Co[i - 1, j])); return Co; } public long DupC(long n, long r) { return ModC(n + r - 1, r); } public long P(long n, long r) { return Fact(n) / (Fact(n - r)); } // test public bool isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false; return true; } public long LCM(long a, long b) { return a * (b / GCD(a, b)); } public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); } public long GCD(long a, long b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public long GCD(params long[] array) { return array.Aggregate((v, n) => GCD(v, n)); } public T Max<T>(params T[] a) { return a.Max(); } public T Min<T>(params T[] a) { return a.Min(); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int mDis(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); } public int[] DigArr(int n) { int[] ret = new int[Digit(n)]; ret.Length.REP(i => ret[i] = DigVal(n, i + 1)); return ret; } public long DigArr2Num(IEnumerable<int> enu) { return enu.Aggregate((v, n) => v * 10 + n); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } public int DigVal(int n, int dig) { return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1); } public long Tousa(long a, long d, long n) { return a + (n - 1) * d; } public long TousaSum(long a, long d, long n) { return n * (2 * a + (n - 1) * d) / 2; } public long[] EnuDivsor(long N) { var ret = new SortedSet<long>(); for (long i = 1; i * i <= N; i++) if (N % i == 0) { ret.Add(i); ret.Add(N / i); } return ret.ToArray(); } public Dictionary<long, long> PrimeFactor(long n) { var ret = new Dictionary<long, long>(); for (int i = 2; i * i <= n; ++i) { if (!ret.ContainsKey(i)) ret[i] = 0; while (n % i == 0) { ++ret[i]; n /= i; } } return ret.Where(kp => kp.Value != 0) .ToDictionary(kp => kp.Key, kp => kp.Value); } public IEnumerable<int[]> enuP(int[] Arr, int Use = -1) { //列挙順列 Use = (Use != -1) ? Use : Arr.Length; if (Use == 0 || Arr.Length < Use) yield break; var s = new Stack<List<int>>(); for (int i = Arr.Length - 1; i >= 0; i--) s.Push(new List<int>() { i }); while (s.Count > 0) { var cur = s.Pop(); if (cur.Count == Use) { var ret = new List<int>(); cur.ForEach(X => ret.Add(Arr[X])); yield return ret.ToArray(); } else for (int i = Arr.Length - 1; i >= 0; i--) if (!cur.Contains(i)) s.Push(new List<int>(cur) { i }); } } public IEnumerable<int[]> enuC(int[] Arr, int Use = -1) { //列挙組み合わせ Use = (Use != -1) ? Use : Arr.Length; if (Use == 0 || Arr.Length < Use) yield break; var s = new Stack<Tuple<int, List<int>>>(); Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] }))); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item2.Count == Use) yield return cur.Item2.ToArray(); else for (int i = Arr.GetUpperBound(0); i > cur.Item1; i--) s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] })); } } public IEnumerable<int[]> enuDupP(int[] Arr, int Use = -1) { //列挙重複順列 Use = (Use != -1) ? Use : Arr.Length; if (Use == 0) yield break; var s = new Stack<List<int>>(); Arr.Length.REPR(i => s.Push(new List<int>() { Arr[i] })); while (s.Count > 0) { var cur = s.Pop(); if (cur.Count == Use) yield return cur.ToArray(); else Arr.Length.REPR(i => s.Push(new List<int>(cur) { Arr[i] })); } } public IEnumerable<int[]> enuDupC(int[] Arr, int Use = -1) { //列挙組み合わせ Use = (Use != -1) ? Use : Arr.Length; if (Use == 0) yield break; var s = new Stack<Tuple<int, List<int>>>(); Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] }))); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item2.Count == Use) yield return cur.Item2.ToArray(); else for (int i = Arr.GetUpperBound(0); i >= cur.Item1; i--) s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] })); } } public IEnumerable<string[]> enuPart(string str) { var s = new Stack<Tuple<string, List<string>, int>>(); s.Push(Tuple.Create(str[0].ToString(), new List<string>(), 1)); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item3 >= str.Length) yield return (new List<string>(cur.Item2) { cur.Item1 }).ToArray(); else { s.Push(Tuple.Create(cur.Item1 + str[cur.Item3], new List<string>(cur.Item2), cur.Item3 + 1)); s.Push(Tuple.Create(str[cur.Item3].ToString(), new List<string>(cur.Item2) { cur.Item1 }, cur.Item3 + 1)); } } } } #endregion #region Data class AssociativeArray<T> : IEnumerable { public Dictionary<T, int> dic; public AssociativeArray() { dic = new Dictionary<T, int>(); } public AssociativeArray(params T[] a) { dic = new Dictionary<T, int>(); Add(a); } public void Add(T a) { if (!conK(a)) dic[a] = 0; dic[a]++; } public void Add(params T[] a) { a.Length.REP(i => { if (!conK(a[i])) dic[a[i]] = 0; dic[a[i]]++; }); } public void Set(T k, int v) { if (!dic.ContainsKey(k)) dic[k] = 0; dic[k] = v; } public void Remove(params T[] a) { a.Length.REP(i => { if (conK(a[i])) dic.Remove(a[i]); }); } public T[] Keys() { return dic.Keys.ToArray<T>(); } public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; } public int ValSum => dic.Values.Sum(); public int KeyNum => dic.Keys.Count; public int MaxVal => dic.Values.Max(); public int MinVal => dic.Values.Min(); public T MaxKey => MaxK(); public T MinKey => MinK(); public T MaxK() { var maxV = MaxVal; return dic.First(d => d.Value == maxV).Key; } public T MinK() { var minV = MinVal; return dic.First(d => d.Value == minV).Key; } public T[] MaxKeys() { var maxV = MaxVal; return dic.Where(kp => kp.Value == maxV) .ToDictionary(kp => kp.Key, kp => kp.Value) .Keys.ToArray(); } public T[] MinKeys() { var minV = MinVal; return dic.Where(kp => kp.Value == minV) .ToDictionary(kp => kp.Key, kp => kp.Value) .Keys.ToArray(); } public bool conK(T k) { return dic.ContainsKey(k); } public bool anyK(params T[] k) { return k.Any(key => conK(key)); } public bool allK(params T[] k) { return k.All(key => conK(key)); } public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + " : " + v.Value); } } public IEnumerator GetEnumerator() { foreach (var kp in dic) yield return kp; } public T[] ValueSortedKey(bool inc = true) { // test return (inc ? (dic.OrderBy(kp => kp.Value)) : (dic.OrderByDescending(kp => kp.Value))) .ThenBy(kp => kp.Key) .ToDictionary(kp => kp.Key, kp => kp.Value) .Keys.ToArray(); } //:sort->array } class TreeDis { // TODO:shortestPath public List<Tuple<long, long>>[] g; public long[] a2other; private int type; public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs public void Init(long n) { g = new List<Tuple<long, long>>[n + 1]; g.Length.REP(i => g[i] = new List<Tuple<long, long>>()); } public void Run(long[] a, long[] b) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], 1L)); g[b[i]].Add(Tuple.Create(a[i], 1L)); }); } public void Run(long[] a, long[] b, long[] w) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], w[i])); g[b[i]].Add(Tuple.Create(a[i], w[i])); }); } public long[] a2iArr(long a) { a2other = new long[g.Count()]; if (type == 0) BFS(a); else DFS(a); return a2other; } private void BFS(long a) { var q = new Queue<Tuple<long, long>>(); q.Enqueue(Tuple.Create(a, -1L)); while (q.Count > 0) { var c = q.Dequeue(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; q.Enqueue(Tuple.Create(v.Item1, c.Item1)); } } } private void DFS(long a) { var s = new Stack<Tuple<long, long>>(); s.Push(Tuple.Create(a, -1L)); while (s.Count > 0) { var c = s.Pop(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; s.Push(Tuple.Create(v.Item1, c.Item1)); } } } } class ShortestPath { protected int I = -1; protected int V; protected int E; public long INF = (long)1e15; protected bool isNonDir = true; public long[] cost; public List<Tuple<int, long>>[] Adj; public void Init(int n) { I = n + 1; V = n; Adj = new List<Tuple<int, long>>[I]; I.REP(i => Adj[i] = new List<Tuple<int, long>>()); } public void AddPath(int f, int t, long c) { E++; if (isNonDir) { Adj[f].Add(Tuple.Create(t, c)); Adj[t].Add(Tuple.Create(f, c)); } else { Adj[f].Add(Tuple.Create(t, c)); } } public void AddPath(int[] f, int[] t, long[] c) { f.Length.REP(i => AddPath(f[i], t[i], c[i])); } } class Dijkstra : ShortestPath { //隣接対応後検証不足,有向とか public long MinCost(int f, int t) { cost = new long[I]; cost.Set(INF); cost[f] = 0; var pq = new PQueue<Tuple<int, long>>(); pq.Enqueue(Tuple.Create(f, 0L)); //(from,cost) while (pq.Count > 0) { var cur = pq.Dequeue(); if (cost[cur.Item1] < cur.Item2) continue; Adj[cur.Item1].Count.REP(i => { var tmp = Adj[cur.Item1][i]; if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) { cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2; pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1])); } }); } return cost[t]; } } class BellmanFord : ShortestPath { private bool[] neg; public BellmanFord() {} public BellmanFord(bool isNonDir) { this.isNonDir = isNonDir; } public long MinCost(int f, int t) { cost = new long[I]; cost.Set(INF); cost[f] = 0; neg = new bool[I]; for (int i = 0; i < I - 1; i++) { I.REP(j => Adj[j].Count.REP(k => { var cur = Adj[j][k]; if (cost[cur.Item1] > cost[j] + cur.Item2) cost[cur.Item1] = cost[j] + cur.Item2; })); } for (int i = 0; i < I; i++) { I.REP(j => Adj[j].Count.REP(k => { var cur = Adj[j][k]; if (cost[cur.Item1] > cost[j] + cur.Item2) { cost[cur.Item1] = cost[j] + cur.Item2; neg[cur.Item1] = true; } if (neg[j]) neg[cur.Item1] = true; })); } return cost[t]; } public bool loopExist() { return neg[I - 1]; } } class WF : ShortestPath { public WF() {} // } class WarshallFloyd { private int E; private bool isNonDir; public long INF = (long)1e15; public long[,] BefG; public long[,] G; public WarshallFloyd(bool isNonDir = true) { this.isNonDir = isNonDir; } public void Init(int n) { E = n + 1; G = new long[E, E]; BefG = new long[E, E]; for (int i = 0; i < E; ++i) for (int j = 0; j < E; ++j) { G[i, j] = INF; BefG[i, j] = INF; } for (int i = 0; i < E; ++i) { G[i, i] = 0; BefG[i, i] = 0; } } public void AddPath(int f, int t, long c) { if (isNonDir) { G[f, t] = c; G[t, f] = c; BefG[f, t] = c; BefG[t, f] = c; } else { G[f, t] = c; BefG[f, t] = c; } } public void AddPath(int[] f, int[] t) { for (int i = 0; i < f.Length; ++i) AddPath(f[i], t[i], 1); } public void AddPath(int[] f, int[] t, long[] c) { for (int i = 0; i < f.Length; ++i) AddPath(f[i], t[i], c[i]); } public void Run() { G = MinCostArr(); } public long[,] MinCostArr() { for (int i = 1; i < E; ++i) for (int j = 1; j < E; ++j) for (int k = 1; k < E; ++k) G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]); return G; } //使う?使わない? public int[] MinPath(int from, int to) { var ret = new List<int>(); var cur = from; while (cur != to) { ret.Add(cur); for (int i = 1; i < E; ++i) { if (BefG[cur, i] + G[i, to] == G[cur, to]) { if (i == cur) continue; cur = i; break; } } } ret.Add(cur); return ret.ToArray(); } public bool isMinPath(int a, int b, long c) { for (int i = 1; i < E; ++i) if (G[i, a] + c == G[i, b]) return true; return false; } //全地点間を繋ぐ最小コスト public long MinCost() { long orig = 0; for (int i = 1; i < E; ++i) for (int j = i + 1; j < E; ++j) { bool isOrig = true; for (int k = 1; k < E; ++k) { if (k == i || k == j) continue; if (G[i, j] == G[i, k] + G[k, j]) { isOrig = false; break; } } if (isOrig) orig += G[i, j]; } return orig; } } class oldUnionFind { public long[] parent; public long[] depth; private long I; public void Init(long n) { I = n + 1; parent = new long[I]; depth = new long[I]; for (int i = 0; i < I; ++i) parent[i] = i; } public long Find(long x) { return (parent[x] == x) ? x : parent[x] = Find(parent[x]); } public void Unite(long x, long y) { x = Find(x); y = Find(y); if (x == y) return; if (depth[x] < depth[y]) parent[x] = y; else { parent[y] = x; if (depth[x] == depth[y]) depth[x]++; } } public bool Same(long a, long b) { return Find(a) == Find(b); } public long Size(long x) { return depth[Find(x)]; } // refactor } class UnionFind { // intでよくないか? int[] dat; public void Init(int n) { dat = new int[n + 1]; for (int i = 0; i <= n; ++i) dat[i] = -1; } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return; if (dat[y] < dat[x]) swap(ref x, ref y); dat[x] += dat[y]; dat[y] = x; } public bool Find(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return dat[x] < 0 ? x : dat[x] = Root(dat[x]); } public int Size(int x) { return -dat[Root(x)]; } void swap(ref int a, ref int b) { int tmp = b; b = a; a = tmp; } } class Kruskal : ShortestPath { public long Run() { var L = new List<Tuple<int, int, long>>(); for (int i = 0; i < I; ++i) foreach (var t in Adj[i]) L.Add(Tuple.Create(i, t.Item1, t.Item2)); L = L.OrderBy(t => t.Item3).ToList(); var uf = new UnionFind(); uf.Init(V); long ret = 0; foreach (var t in L) if (!uf.Find(t.Item1, t.Item2)) { ret += t.Item3; uf.Unite(t.Item1, t.Item2); } return ret; } } #endregion #region Ex static class StringEX { public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } public static int toInt(this string s) { int n; return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0; } public static int toInt(this char c) { return toInt(c.ToString()); } public static int toInt(this char[] c) { return toInt(new string(c)); } public static long toLong(this string s) { long n; return (long.TryParse(s.TrimStart('0'), out n)) ? n : (long)0; } public static long toLong(this char c) { return toLong(c.ToString()); } public static long toLong(this char[] c) { return toLong(new string(c)); } public static string toString(this char[] c) { return new string(c); } } static class NumericEx { public static string pad0<T>(this T v, int n) { return v.ToString().PadLeft(n, '0'); } public static double RoundOff(this double v, int n) { return Math.Round(v, n - 1, MidpointRounding.AwayFromZero); } public static bool Odd(this int v) { return v % 2 != 0; } public static bool Odd(this long v) { return v % 2 != 0; } public static void REP(this int v, Action<int> act) { for (int i = 0; i < v; ++i) act(i); } public static void REPR(this int v, Action<int> act) { for (int i = v - 1; i >= 0; --i) act(i); } } static class ArrayEX { public static T[] Sort<T>(this T[] a) { Array.Sort(a); return a; } public static T[] SortR<T>(this T[] a) { Array.Sort(a); Array.Reverse(a); return a; } public static void Set<T>(this T[] a, T v) { a.Length.REP(i => a[i] = v); } public static void Set<T>(this T[,] a, T v) { a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v)); } public static int[] toIntArr(this string[] a) { return Array.ConvertAll(a, int.Parse); } public static long[] toLongArr(this string[] a) { return Array.ConvertAll(a, long.Parse); } public static double[] toDoubleArr(this string[] a) { return Array.ConvertAll(a, double.Parse); } public static char[] toCharArr(this string[] a) { return Array.ConvertAll(a, char.Parse); } } static class BitEx { public static bool Any(this BitArray b) { foreach (bool f in b) if (f) return true; return false; } public static bool All(this BitArray b) { foreach (bool f in b) if (!f) return false; return true; } public static bool None(this BitArray b) { return !Any(b); } public static void Flip(this BitArray b, int index) { b.Set(index, !b.Get(index)); } } static class IEnumerableEx {} #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; namespace Program { class MainClass { //////////////////////////////////////////////////////////// string S; void Solve() { S = io.String; if (S.Length < 4) { io.o("No"); return; } bool ans = S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I'; io.o(ans ? "Yes" : "No"); } //////////////////////////////////////////////////////////// public static void Main() { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } // void Stream() { Test(); io.writeFlush(); } void Test() {} #region MockMacro // cannot use break,continue,goto void FOR(int a, int b, Action<int> act) { for (int i = a; i < b; ++i) act(i); } void FORR(int a, int b, Action<int> act) { for (int i = a - 1; i >= b; --i) act(i); } #endregion //////////////////////////////////////////////////////////// } #region default class IO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string[] arr => Console.ReadLine().Split(' '); public char[] arrChar => Array.ConvertAll(arr, char.Parse); public int[] arrInt => Array.ConvertAll(arr, int.Parse); public long[] arrLong => Array.ConvertAll(arr, long.Parse); public double[] arrDouble => Array.ConvertAll(arr, double.Parse); public T i<T>() { return suitType<T>(String); } public void i<T>(out T v) { v = suitType<T>(String); } public void i<T, U>(out T v1, out U v2) { i(out v1); i(out v2); } public void i<T, U, V>(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { i(out v1); i(out v2); i(out v3); i(out v4); } public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4, out X v5) { i(out v1); i(out v2); i(out v3); i(out v4); i(out v5); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) a[i] = suitType<T>(String); } public void ini<T, U>(out T[] a, out U[] b, int n) { a = new T[n]; b = new U[n]; for (int i = 0; i < n; ++i) { a[i] = i<T>(); b[i] = i<U>(); } } public void ini<T, U, V>(out T[] a, out U[] b, out V[] c, int n) { a = new T[n]; b = new U[n]; c = new V[n]; for (int i = 0; i < n; ++i) { a[i] = i<T>(); b[i] = i<U>(); c[i] = i<V>(); } } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) a[i, j] = i<T>(); } public void o<T>(T v) { Console.WriteLine(v); } public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); } public void o<T>(T[,] a) { int a0 = a.GetLength(0), a1 = a.GetLength(1); for (int i = 0; i < a0; ++i) { for (int j = 0; j < a1 - 1; ++j) Console.Write(a[i, j] + " "); Console.WriteLine(a[i, a1 - 1]); } } public void ol<T>(params T[] a) { o(connect<T>(a)); } public void or<T>(T a) { Console.Write(a); } public void br() { o(""); } public void writeFlush() { Console.Out.Flush(); } private string connect<T>(params T[] s) { return string.Join(" ", s); } private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } private T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } private T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } } class PQueue<T> where T : IComparable { public List<T> heap; private Comparison<T> comp; private IComparer<T> comparer; private int size; private int type; // type=0->min public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; } public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) { this.comparer = comparer; } public PQueue(Comparison<T> comparison) : this(16, comparison) {} public PQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.comp = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (Compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } public bool Empty() { return !Any(); } public bool Contains(T v) { return heap.Contains(v); } private int Compare(T x, T y) { return type == 0 ? x.CompareTo(y) : y.CompareTo(x); } } #endregion #region other class Mat { public long mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { long ret = 1; for (long i = 1; i <= n; i++) ret = (ret * i) % mod; return ret; } public long ModC(long n, long r) { if (r == 0 || n == r) return 1; if (n == 0) return 0; if (n < 0 || n < r) throw new ArgumentException("n,r invalid"); else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public long[,] C(int N) { long[,] Co = new long[N + 1, N + 1]; (N + 1).REP(i => (i + 1).REP(j => Co[i, j] = (j == 0 || j == i) ? 1L : Co[i - 1, j - 1] + Co[i - 1, j])); return Co; } public long DupC(long n, long r) { return ModC(n + r - 1, r); } public long P(long n, long r) { return Fact(n) / (Fact(n - r)); } // test public bool isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false; return true; } public long LCM(long a, long b) { return a * (b / GCD(a, b)); } public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); } public long GCD(long a, long b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public long GCD(params long[] array) { return array.Aggregate((v, n) => GCD(v, n)); } public T Max<T>(params T[] a) { return a.Max(); } public T Min<T>(params T[] a) { return a.Min(); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int mDis(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); } public int[] DigArr(int n) { int[] ret = new int[Digit(n)]; ret.Length.REP(i => ret[i] = DigVal(n, i + 1)); return ret; } public long DigArr2Num(IEnumerable<int> enu) { return enu.Aggregate((v, n) => v * 10 + n); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } public int DigVal(int n, int dig) { return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1); } public long Tousa(long a, long d, long n) { return a + (n - 1) * d; } public long TousaSum(long a, long d, long n) { return n * (2 * a + (n - 1) * d) / 2; } public long[] EnuDivsor(long N) { var ret = new SortedSet<long>(); for (long i = 1; i * i <= N; i++) if (N % i == 0) { ret.Add(i); ret.Add(N / i); } return ret.ToArray(); } public Dictionary<long, long> PrimeFactor(long n) { var ret = new Dictionary<long, long>(); for (int i = 2; i * i <= n; ++i) { if (!ret.ContainsKey(i)) ret[i] = 0; while (n % i == 0) { ++ret[i]; n /= i; } } return ret.Where(kp => kp.Value != 0) .ToDictionary(kp => kp.Key, kp => kp.Value); } public IEnumerable<int[]> enuP(int[] Arr, int Use = -1) { //列挙順列 Use = (Use != -1) ? Use : Arr.Length; if (Use == 0 || Arr.Length < Use) yield break; var s = new Stack<List<int>>(); for (int i = Arr.Length - 1; i >= 0; i--) s.Push(new List<int>() { i }); while (s.Count > 0) { var cur = s.Pop(); if (cur.Count == Use) { var ret = new List<int>(); cur.ForEach(X => ret.Add(Arr[X])); yield return ret.ToArray(); } else for (int i = Arr.Length - 1; i >= 0; i--) if (!cur.Contains(i)) s.Push(new List<int>(cur) { i }); } } public IEnumerable<int[]> enuC(int[] Arr, int Use = -1) { //列挙組み合わせ Use = (Use != -1) ? Use : Arr.Length; if (Use == 0 || Arr.Length < Use) yield break; var s = new Stack<Tuple<int, List<int>>>(); Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] }))); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item2.Count == Use) yield return cur.Item2.ToArray(); else for (int i = Arr.GetUpperBound(0); i > cur.Item1; i--) s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] })); } } public IEnumerable<int[]> enuDupP(int[] Arr, int Use = -1) { //列挙重複順列 Use = (Use != -1) ? Use : Arr.Length; if (Use == 0) yield break; var s = new Stack<List<int>>(); Arr.Length.REPR(i => s.Push(new List<int>() { Arr[i] })); while (s.Count > 0) { var cur = s.Pop(); if (cur.Count == Use) yield return cur.ToArray(); else Arr.Length.REPR(i => s.Push(new List<int>(cur) { Arr[i] })); } } public IEnumerable<int[]> enuDupC(int[] Arr, int Use = -1) { //列挙組み合わせ Use = (Use != -1) ? Use : Arr.Length; if (Use == 0) yield break; var s = new Stack<Tuple<int, List<int>>>(); Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] }))); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item2.Count == Use) yield return cur.Item2.ToArray(); else for (int i = Arr.GetUpperBound(0); i >= cur.Item1; i--) s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] })); } } public IEnumerable<string[]> enuPart(string str) { var s = new Stack<Tuple<string, List<string>, int>>(); s.Push(Tuple.Create(str[0].ToString(), new List<string>(), 1)); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item3 >= str.Length) yield return (new List<string>(cur.Item2) { cur.Item1 }).ToArray(); else { s.Push(Tuple.Create(cur.Item1 + str[cur.Item3], new List<string>(cur.Item2), cur.Item3 + 1)); s.Push(Tuple.Create(str[cur.Item3].ToString(), new List<string>(cur.Item2) { cur.Item1 }, cur.Item3 + 1)); } } } } #endregion #region Data class AssociativeArray<T> : IEnumerable { public Dictionary<T, int> dic; public AssociativeArray() { dic = new Dictionary<T, int>(); } public AssociativeArray(params T[] a) { dic = new Dictionary<T, int>(); Add(a); } public void Add(T a) { if (!conK(a)) dic[a] = 0; dic[a]++; } public void Add(params T[] a) { a.Length.REP(i => { if (!conK(a[i])) dic[a[i]] = 0; dic[a[i]]++; }); } public void Set(T k, int v) { if (!dic.ContainsKey(k)) dic[k] = 0; dic[k] = v; } public void Remove(params T[] a) { a.Length.REP(i => { if (conK(a[i])) dic.Remove(a[i]); }); } public T[] Keys() { return dic.Keys.ToArray<T>(); } public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; } public int ValSum => dic.Values.Sum(); public int KeyNum => dic.Keys.Count; public int MaxVal => dic.Values.Max(); public int MinVal => dic.Values.Min(); public T MaxKey => MaxK(); public T MinKey => MinK(); public T MaxK() { var maxV = MaxVal; return dic.First(d => d.Value == maxV).Key; } public T MinK() { var minV = MinVal; return dic.First(d => d.Value == minV).Key; } public T[] MaxKeys() { var maxV = MaxVal; return dic.Where(kp => kp.Value == maxV) .ToDictionary(kp => kp.Key, kp => kp.Value) .Keys.ToArray(); } public T[] MinKeys() { var minV = MinVal; return dic.Where(kp => kp.Value == minV) .ToDictionary(kp => kp.Key, kp => kp.Value) .Keys.ToArray(); } public bool conK(T k) { return dic.ContainsKey(k); } public bool anyK(params T[] k) { return k.Any(key => conK(key)); } public bool allK(params T[] k) { return k.All(key => conK(key)); } public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + " : " + v.Value); } } public IEnumerator GetEnumerator() { foreach (var kp in dic) yield return kp; } public T[] ValueSortedKey(bool inc = true) { // test return (inc ? (dic.OrderBy(kp => kp.Value)) : (dic.OrderByDescending(kp => kp.Value))) .ThenBy(kp => kp.Key) .ToDictionary(kp => kp.Key, kp => kp.Value) .Keys.ToArray(); } //:sort->array } class TreeDis { // TODO:shortestPath public List<Tuple<long, long>>[] g; public long[] a2other; private int type; public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs public void Init(long n) { g = new List<Tuple<long, long>>[n + 1]; g.Length.REP(i => g[i] = new List<Tuple<long, long>>()); } public void Run(long[] a, long[] b) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], 1L)); g[b[i]].Add(Tuple.Create(a[i], 1L)); }); } public void Run(long[] a, long[] b, long[] w) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], w[i])); g[b[i]].Add(Tuple.Create(a[i], w[i])); }); } public long[] a2iArr(long a) { a2other = new long[g.Count()]; if (type == 0) BFS(a); else DFS(a); return a2other; } private void BFS(long a) { var q = new Queue<Tuple<long, long>>(); q.Enqueue(Tuple.Create(a, -1L)); while (q.Count > 0) { var c = q.Dequeue(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; q.Enqueue(Tuple.Create(v.Item1, c.Item1)); } } } private void DFS(long a) { var s = new Stack<Tuple<long, long>>(); s.Push(Tuple.Create(a, -1L)); while (s.Count > 0) { var c = s.Pop(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; s.Push(Tuple.Create(v.Item1, c.Item1)); } } } } class ShortestPath { protected int I = -1; protected int V; protected int E; public long INF = (long)1e15; protected bool isNonDir = true; public long[] cost; public List<Tuple<int, long>>[] Adj; public void Init(int n) { I = n + 1; V = n; Adj = new List<Tuple<int, long>>[I]; I.REP(i => Adj[i] = new List<Tuple<int, long>>()); } public void AddPath(int f, int t, long c) { E++; if (isNonDir) { Adj[f].Add(Tuple.Create(t, c)); Adj[t].Add(Tuple.Create(f, c)); } else { Adj[f].Add(Tuple.Create(t, c)); } } public void AddPath(int[] f, int[] t, long[] c) { f.Length.REP(i => AddPath(f[i], t[i], c[i])); } } class Dijkstra : ShortestPath { //隣接対応後検証不足,有向とか public long MinCost(int f, int t) { cost = new long[I]; cost.Set(INF); cost[f] = 0; var pq = new PQueue<Tuple<int, long>>(); pq.Enqueue(Tuple.Create(f, 0L)); //(from,cost) while (pq.Count > 0) { var cur = pq.Dequeue(); if (cost[cur.Item1] < cur.Item2) continue; Adj[cur.Item1].Count.REP(i => { var tmp = Adj[cur.Item1][i]; if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) { cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2; pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1])); } }); } return cost[t]; } } class BellmanFord : ShortestPath { private bool[] neg; public BellmanFord() {} public BellmanFord(bool isNonDir) { this.isNonDir = isNonDir; } public long MinCost(int f, int t) { cost = new long[I]; cost.Set(INF); cost[f] = 0; neg = new bool[I]; for (int i = 0; i < I - 1; i++) { I.REP(j => Adj[j].Count.REP(k => { var cur = Adj[j][k]; if (cost[cur.Item1] > cost[j] + cur.Item2) cost[cur.Item1] = cost[j] + cur.Item2; })); } for (int i = 0; i < I; i++) { I.REP(j => Adj[j].Count.REP(k => { var cur = Adj[j][k]; if (cost[cur.Item1] > cost[j] + cur.Item2) { cost[cur.Item1] = cost[j] + cur.Item2; neg[cur.Item1] = true; } if (neg[j]) neg[cur.Item1] = true; })); } return cost[t]; } public bool loopExist() { return neg[I - 1]; } } class WF : ShortestPath { public WF() {} // } class WarshallFloyd { private int E; private bool isNonDir; public long INF = (long)1e15; public long[,] BefG; public long[,] G; public WarshallFloyd(bool isNonDir = true) { this.isNonDir = isNonDir; } public void Init(int n) { E = n + 1; G = new long[E, E]; BefG = new long[E, E]; for (int i = 0; i < E; ++i) for (int j = 0; j < E; ++j) { G[i, j] = INF; BefG[i, j] = INF; } for (int i = 0; i < E; ++i) { G[i, i] = 0; BefG[i, i] = 0; } } public void AddPath(int f, int t, long c) { if (isNonDir) { G[f, t] = c; G[t, f] = c; BefG[f, t] = c; BefG[t, f] = c; } else { G[f, t] = c; BefG[f, t] = c; } } public void AddPath(int[] f, int[] t) { for (int i = 0; i < f.Length; ++i) AddPath(f[i], t[i], 1); } public void AddPath(int[] f, int[] t, long[] c) { for (int i = 0; i < f.Length; ++i) AddPath(f[i], t[i], c[i]); } public void Run() { G = MinCostArr(); } public long[,] MinCostArr() { for (int i = 1; i < E; ++i) for (int j = 1; j < E; ++j) for (int k = 1; k < E; ++k) G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]); return G; } //使う?使わない? public int[] MinPath(int from, int to) { var ret = new List<int>(); var cur = from; while (cur != to) { ret.Add(cur); for (int i = 1; i < E; ++i) { if (BefG[cur, i] + G[i, to] == G[cur, to]) { if (i == cur) continue; cur = i; break; } } } ret.Add(cur); return ret.ToArray(); } public bool isMinPath(int a, int b, long c) { for (int i = 1; i < E; ++i) if (G[i, a] + c == G[i, b]) return true; return false; } //全地点間を繋ぐ最小コスト public long MinCost() { long orig = 0; for (int i = 1; i < E; ++i) for (int j = i + 1; j < E; ++j) { bool isOrig = true; for (int k = 1; k < E; ++k) { if (k == i || k == j) continue; if (G[i, j] == G[i, k] + G[k, j]) { isOrig = false; break; } } if (isOrig) orig += G[i, j]; } return orig; } } class oldUnionFind { public long[] parent; public long[] depth; private long I; public void Init(long n) { I = n + 1; parent = new long[I]; depth = new long[I]; for (int i = 0; i < I; ++i) parent[i] = i; } public long Find(long x) { return (parent[x] == x) ? x : parent[x] = Find(parent[x]); } public void Unite(long x, long y) { x = Find(x); y = Find(y); if (x == y) return; if (depth[x] < depth[y]) parent[x] = y; else { parent[y] = x; if (depth[x] == depth[y]) depth[x]++; } } public bool Same(long a, long b) { return Find(a) == Find(b); } public long Size(long x) { return depth[Find(x)]; } // refactor } class UnionFind { // intでよくないか? int[] dat; public void Init(int n) { dat = new int[n + 1]; for (int i = 0; i <= n; ++i) dat[i] = -1; } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return; if (dat[y] < dat[x]) swap(ref x, ref y); dat[x] += dat[y]; dat[y] = x; } public bool Find(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return dat[x] < 0 ? x : dat[x] = Root(dat[x]); } public int Size(int x) { return -dat[Root(x)]; } void swap(ref int a, ref int b) { int tmp = b; b = a; a = tmp; } } class Kruskal : ShortestPath { public long Run() { var L = new List<Tuple<int, int, long>>(); for (int i = 0; i < I; ++i) foreach (var t in Adj[i]) L.Add(Tuple.Create(i, t.Item1, t.Item2)); L = L.OrderBy(t => t.Item3).ToList(); var uf = new UnionFind(); uf.Init(V); long ret = 0; foreach (var t in L) if (!uf.Find(t.Item1, t.Item2)) { ret += t.Item3; uf.Unite(t.Item1, t.Item2); } return ret; } } #endregion #region Ex static class StringEX { public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } public static int toInt(this string s) { int n; return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0; } public static int toInt(this char c) { return toInt(c.ToString()); } public static int toInt(this char[] c) { return toInt(new string(c)); } public static long toLong(this string s) { long n; return (long.TryParse(s.TrimStart('0'), out n)) ? n : (long)0; } public static long toLong(this char c) { return toLong(c.ToString()); } public static long toLong(this char[] c) { return toLong(new string(c)); } public static string toString(this char[] c) { return new string(c); } } static class NumericEx { public static string pad0<T>(this T v, int n) { return v.ToString().PadLeft(n, '0'); } public static double RoundOff(this double v, int n) { return Math.Round(v, n - 1, MidpointRounding.AwayFromZero); } public static bool Odd(this int v) { return v % 2 != 0; } public static bool Odd(this long v) { return v % 2 != 0; } public static void REP(this int v, Action<int> act) { for (int i = 0; i < v; ++i) act(i); } public static void REPR(this int v, Action<int> act) { for (int i = v - 1; i >= 0; --i) act(i); } } static class ArrayEX { public static T[] Sort<T>(this T[] a) { Array.Sort(a); return a; } public static T[] SortR<T>(this T[] a) { Array.Sort(a); Array.Reverse(a); return a; } public static void Set<T>(this T[] a, T v) { a.Length.REP(i => a[i] = v); } public static void Set<T>(this T[,] a, T v) { a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v)); } public static int[] toIntArr(this string[] a) { return Array.ConvertAll(a, int.Parse); } public static long[] toLongArr(this string[] a) { return Array.ConvertAll(a, long.Parse); } public static double[] toDoubleArr(this string[] a) { return Array.ConvertAll(a, double.Parse); } public static char[] toCharArr(this string[] a) { return Array.ConvertAll(a, char.Parse); } } static class BitEx { public static bool Any(this BitArray b) { foreach (bool f in b) if (f) return true; return false; } public static bool All(this BitArray b) { foreach (bool f in b) if (!f) return false; return true; } public static bool None(this BitArray b) { return !Any(b); } public static void Flip(this BitArray b, int index) { b.Set(index, !b.Get(index)); } } static class IEnumerableEx {} #endregion }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
8,210
21
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // ?uj // var n = inta(); var al = "abcdefghijklmnopqrstuvwxyz"; var count = new int[26]; for (int i = 0; i < n[0]; i++) { var s = rstr(); for (int j = 0; j < n[1]; j++) { count[al.IndexOf(s[j].ToString())]++; } } var countnum = new int[5]; if (n[0] % 2 == 1 && n[1] % 2 == 1) { countnum[1] = 1; } if (n[0] % 2 == 1) { countnum[2] += n[1] / 2; n[0]--; } if (n[1] % 2 == 1) { countnum[2] += n[0] / 2; n[1]--; } countnum[4] = n[0] * n[1] / 4; // WriteLine($"{countnum[1]} {countnum[2]} {countnum[4]}"); var countnumal = new int[5]; for (int i = 0; i < 26; i++) { var t = count[i] / 4; countnumal[4] += t; count[i] -= 4 * t; t = count[i] / 2; countnumal[2] += t; count[i] -= 2 * t; t = count[i]; countnumal[1] += t; count[i] -= t; } // WriteLine($"{countnumal[1]} {countnumal[2]} {countnumal[4]}"); for (int i = 1; i < 5; i++) { countnum[i] -= countnumal[i]; } countnum[2] += countnum[4] * 2; countnum[4] = 0; if (countnum[1] == 0 && countnum[2] == 0 && countnum[4] == 0) { WriteLine("Yes"); } else { WriteLine("No"); } // WriteLine($"{countnum[1]} {countnum[2]} {countnum[4]}"); } // 1?c?ca?U?A?I”??A?בO?|‘S’E?e?O?・?a?A static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //?ei“Ca static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // ?uj // var n = inta(); var al = "abcdefghijklmnopqrstuvwxyz"; var count = new int[26]; for (int i = 0; i < n[0]; i++) { var s = rstr(); for (int j = 0; j < n[1]; j++) { count[al.IndexOf(s[j].ToString())]++; } } var countnum = new int[5]; if (n[0] % 2 == 1 && n[1] % 2 == 1) { countnum[1] = 1; } if (n[0] % 2 == 1) { countnum[2] += n[1] / 2; n[0]--; } if (n[1] % 2 == 1) { countnum[2] += n[0] / 2; n[1]--; } countnum[4] = n[0] * n[1] / 4; // WriteLine($"{countnum[1]} {countnum[2]} {countnum[4]}"); var countnumal = new int[5]; for (int i = 0; i < 26; i++) { var t = count[i] / 4; countnumal[4] += t; count[i] -= 4 * t; t = count[i] / 2; countnumal[2] += t; count[i] -= 2 * t; t = count[i]; countnumal[1] += t; count[i] -= t; } // WriteLine($"{countnumal[1]} {countnumal[2]} {countnumal[4]}"); for (int i = 1; i < 5; i++) { countnum[i] -= countnumal[i]; } if (countnum[2] > 0) { countnum[4] += countnum[2] / 2; countnum[2] = 0; } if (countnum[1] == 0 && countnum[2] == 0 && countnum[4] == 0) { WriteLine("Yes"); } else { WriteLine("No"); } // WriteLine($"{countnum[1]} {countnum[2]} {countnum[4]}"); } // 1?c?ca?U?A?I”??A?בO?|‘S’E?e?O?・?a?A static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //?ei“Ca static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
1,644
17
using System.Linq; using System.Collections.Generic; using System; public class Hello { public static void Main() { var d = new Dictionary<char, int>(); string[] line = Console.ReadLine().Trim().Split(' '); var h = int.Parse(line[0]); var w = int.Parse(line[1]); for (int i = 0; i < h; i++) { var s = Console.ReadLine().Trim(); for (int j = 0; j < w; j++) if (d.ContainsKey(s[j])) d[s[j]]++; else d[s[j]] = 1; } var a = new int[d.Count()]; var p = 0; foreach (var x in d) a[p++] = x.Value; var kg = 0; if (h % 2 == 0) kg++; if (w % 2 == 0) kg++; bool ret; if (kg == 2) ret = checkGG(a); else if (kg == 1) ret = checkKG(h, w, a); else ret = checkKK(h, w, a); Console.WriteLine(ret ? "Yes" : "No"); } public static bool checkKK(int h, int w, int[] a) { if (h == 1 && w == 1) return true; var c4 = 0; var c2 = 0; for (int i = 0; i < a.Length; i++) { c4 += a[i] / 4; a[i] %= 4; c2 += a[i] / 2; a[i] %= 2; } if (h == 1 | w == 1) { c2 += 2 * c4; return c2 == h / 2 + w / 2; } else { var ww = (h * w - (h + w - 1)) / 4; if (c4 >= ww) c2 += (c4 - ww) * 2; else return false; var ww2 = (h + w - 1) / 2; return c2 == ww2; } } public static bool checkKG(int h, int w, int[] a) { var c4 = 0; for (int i = 0; i < a.Length; i++) { if (a[i] % 2 == 1) return false; c4 += a[i] / 4; a[i] %= 4; } var zc4 = h / 2 + w / 2 - 1; return c4 >= zc4; } public static bool checkGG(int[] a) { for (int i = 0; i < a.Length; i++) if (a[i] % 4 != 0) return false; return true; } }
using System.Linq; using System.Collections.Generic; using System; public class Hello { public static void Main() { var d = new Dictionary<char, int>(); string[] line = Console.ReadLine().Trim().Split(' '); var h = int.Parse(line[0]); var w = int.Parse(line[1]); for (int i = 0; i < h; i++) { var s = Console.ReadLine().Trim(); for (int j = 0; j < w; j++) if (d.ContainsKey(s[j])) d[s[j]]++; else d[s[j]] = 1; } var a = new int[d.Count()]; var p = 0; foreach (var x in d) a[p++] = x.Value; var kg = 0; if (h % 2 == 0) kg++; if (w % 2 == 0) kg++; bool ret; if (kg == 2) ret = checkGG(a); else if (kg == 1) ret = checkKG(h, w, a); else ret = checkKK(h, w, a); Console.WriteLine(ret ? "Yes" : "No"); } public static bool checkKK(int h, int w, int[] a) { if (h == 1 && w == 1) return true; var c4 = 0; var c2 = 0; for (int i = 0; i < a.Length; i++) { c4 += a[i] / 4; a[i] %= 4; c2 += a[i] / 2; a[i] %= 2; } if (h == 1 | w == 1) { c2 += 2 * c4; return c2 == h / 2 + w / 2; } else { var ww = (h * w - (h + w - 1)) / 4; if (c4 >= ww) c2 += (c4 - ww) * 2; else return false; var ww2 = (h + w - 1) / 2; return c2 == ww2; } } public static bool checkKG(int h, int w, int[] a) { var c4 = 0; for (int i = 0; i < a.Length; i++) { if (a[i] % 2 == 1) return false; c4 += a[i] / 4; a[i] %= 4; } int zc4; if (h % 2 == 0) zc4 = (h * w - h) / 4; else zc4 = (h * w - w) / 4; return c4 >= zc4; } public static bool checkGG(int[] a) { for (int i = 0; i < a.Length; i++) if (a[i] % 4 != 0) return false; return true; } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 212, 0, 16, 31, 16, 31, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 72], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 48], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 64, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["-", 0, 212, 0, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 75, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 0, 57, 75, 1, 0, 11, 12, 16, 17, 85], ["+", 0, 57, 75, 1, 0, 11, 12, 16, 12, 203]]
8
601
35
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using static System.Console; using static System.Math; using System.Numerics; using CS_Contest.Graph; using CS_Contest.Loop; using CS_Contest.Utils; using static Nakov.IO.Cin; using static CS_Contest.IO.IO; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; using ti3=Tuple<int,int,int>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } public class Calc { public void Solve() { int H = NextInt(), W = NextInt(); var dic = new Map<char, int>(); H.REP(i => ReadLine().Foreach(c => dic[c]++)); Func<bool> getRes = () => { if (H%2 == 0 && W%2 == 0) { //偶数x偶数 return dic.All(x => x.Value % 4 == 0); } var map = new Map<int, int>(); dic.Foreach(v => map[v.Value % 4] = (map[v.Value % 4] + 1) % 4); if (H%2 == 1 && W%2 == 1) { //奇数x奇数 if (map[3] == 1) return false; if (map[1] != 1) return false; return map[2] <= (H - 1) / 2 + (W - 1) / 2; } if (W % 2 == 1) Utils.Utils.Swap(ref W, ref H); if (map[1] == 1 || map[3] == 1) return false; return map[2] <= W / 2; }; (getRes()?"Yes":"No").WL(); return; } } } } namespace Nakov.IO { using System; using System.Text; using System.Globalization; public static class Cin { public static string NextToken() { StringBuilder tokenChars = new StringBuilder(); bool tokenFinished = false; bool skipWhiteSpaceMode = true; while (!tokenFinished) { int nextChar = Console.Read(); if (nextChar == -1) { tokenFinished = true; } else { char ch = (char)nextChar; if (char.IsWhiteSpace(ch)) { if (!skipWhiteSpaceMode) { tokenFinished = true; if (ch == '\r' && (Environment.NewLine == "\r\n")) { Console.Read(); } } } else { skipWhiteSpaceMode = false; tokenChars.Append(ch); } } } string token = tokenChars.ToString(); return token; } public static int NextInt() { string token = Cin.NextToken(); return int.Parse(token); } public static long NextLong() { string token = Cin.NextToken(); return long.Parse(token); } public static double NextDouble(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); double result = double.Parse(token, CultureInfo.InvariantCulture); return result; } else { double result = double.Parse(token); return result; } } public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); decimal result = decimal.Parse(token, CultureInfo.InvariantCulture); return result; } else { decimal result = decimal.Parse(token); return result; } } } } namespace CS_Contest.Graph { using Ll=List<long>; using Li=List<int>; public struct WeightedUnionFind { private readonly int N; public int[] Parent { get; private set; } public long[] Cost { get; private set; } public int[] Rank { get; private set; } public WeightedUnionFind(int n) { N = n; Parent = Enumerable.Range(0, N).ToArray(); Cost = new long[N]; Rank = new int[N]; } public int Root(int u, out long cost) { if (Parent[u] == u) { cost = Cost[u]; return u; } var v = Root(Parent[u], out cost); cost += Cost[u]; Parent[u] = v; Cost[u] = cost; return v; } public void Unite(int lv, int rv, long cost) { long lc, rc; lv = Root(lv, out lc); rv = Root(rv, out rc); cost = -rc + cost + lc; if (Rank[lv] < Rank[rv]) { Unite(rv, lv, -cost); return; } Parent[rv] = lv; Cost[rv] = cost; Rank[lv] += Rank[rv] + 1; } public bool IsValid() { for (var i = 0; i < N; i++) { long _; Root(i, out _); } for (var i = 0; i < N; i++) { if (Parent[i] == i && Cost[i] != 0L) { return false; } } return true; } } /// <summary> /// UnionFind /// </summary> public struct UnionFind { private readonly int[] _data; public UnionFind(int size) { _data = new int[size]; for (var i = 0; i < size; i++) _data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return x != y; if (_data[y] < _data[x]) { var tmp = y; y = x; x = tmp; } _data[x] += _data[y]; _data[y] = x; return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return _data[x] < 0 ? x : _data[x] = Root(_data[x]); } } public class BellmanFord : CostGraph { public BellmanFord(int size) : base(size) { } public List<long> Distance { get; set; } private bool[] _negative; public bool HasCycle => _negative[Size - 1]; public void Run(int s) { Distance = new Ll(); Size.REP(i => Distance.Add(Inf)); Distance[s] = 0; _negative = new bool[Size]; (Size - 1).REP(i => Size.REP(j => Adjacency[j].Count.REP(k => { var src = Adjacency[j][k]; if (Distance[src.To] > Distance[j] + src.Cost) Distance[src.To] = Distance[j] + src.Cost; } ))); for (int i = 0; i < Size; i++) { Size.REP(j => { Adjacency[j].Count.REP(k => { var src = Adjacency[j][k]; if (Distance[src.To] > Distance[j] + src.Cost) { Distance[src.To] = Distance[j] + src.Cost; _negative[src.To] = true; } if (_negative[j]) _negative[src.To] = true; }); }); } } } public class CostGraph { public struct Edge { public int To { get; set; } public long Cost { get; set; } public Edge(int to, long cost) { To = to; Cost = cost; } } public int Size { get; set; } public List<List<Edge>> Adjacency { get; set; } public const long Inf = (long)1e15; public CostGraph(int size) { Size = size; Adjacency = new List<List<Edge>>(); Size.REP(_ => Adjacency.Add(new List<Edge>())); } public void Add(int s, int t, long c, bool dir = true) { Adjacency[s].Add(new Edge(t, c)); if (!dir) Adjacency[t].Add(new Edge(s, c)); } } /// <summary> /// 優先度付きキュー /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) { } public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) { } public PriorityQueue(Comparison<T> comparison) : this(16, comparison) { } public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count => size; public bool Any() { return size > 0; } } public class Dijkstra : CostGraph { public Dijkstra(int size) : base(size) { } public int[] PreviousNodeList { get; set; } public long[] Distance { get; set; } public void Run(int s) { PreviousNodeList = new int[Size]; Distance = new long[Size]; Size.REP(_ => Distance[_] = Inf); var pq = new PriorityQueue<Edge>((x, y) => x.Cost.CompareTo(y.Cost)); Distance[s] = 0; pq.Enqueue(new Edge(s, 0)); while (pq.Any()) { var src = pq.Dequeue(); if (Distance[src.To] < src.Cost) continue; for (var i = 0; i < Adjacency[src.To].Count; i++) { var tmp = Adjacency[src.To][i]; var cost = tmp.Cost + src.Cost; if (cost >= Distance[tmp.To]) continue; Distance[tmp.To] = cost; pq.Enqueue(new Edge(tmp.To, cost)); PreviousNodeList[tmp.To] = src.To; } } } } public class WarshallFloyd : CostGraph { public WarshallFloyd(int size) : base(size) { } public List<Ll> Run() { var rt = new List<Ll>(); Size.REP(_ => rt.Add(new Ll())); Size.REP(i => Size.REP(k => rt[i].Add(i == k ? 0 : Inf))); Adjacency.ForeachWith( (i, item) => { foreach (var k in item) { rt[i][k.To] = k.Cost; } }); Size.REP(i => Size.REP(j => Size.REP(k => { rt[j][k] = Min(rt[j][k], rt[j][i] + rt[i][k]); }))); return rt; } } } namespace CS_Contest.Loop { public static class Loop { public static void REP(this int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static void RREP(this int @n, Action<int> act) { for (var i = n - 1; i >= 0; i--) act(i); } public static void REP(this long n, Action<long> act) { for (var i = 0; i < n; i++) act(i); } public static void FOR(this Tuple<int, int, int> t, Action<int> action) { for (var i = t.Item1; i < t.Item2; i += t.Item3) action(i); } public static void FOR(this Tuple<int, int> t, Action<int> action) => new Tuple<int, int, int>(t.Item1, t.Item2, 1).FOR(action); public static void FOR(this Tuple<long, long, long> t, Action<long> action) { for (var i = t.Item1; i < t.Item2; i += t.Item3) action(i); } public static void FOR(this Tuple<long, long> t, Action<long> act) => new Tuple<long, long, long>(t.Item1, t.Item2, 1).FOR(act); public static void ForeachWith<T>(this IEnumerable<T> ie, Action<int, T> act) { var i = 0; foreach (var item in ie) { act(i, item); i++; } } public static void Foreach<T>(this IEnumerable<T> ie, Action<T> act) { foreach (var item in ie) { act(item); } } } } namespace CS_Contest.IO { using Li = List<int>; using Ll = List<long>; public static class IO { public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static Li NextIntList() => ReadLine().Split().Select(int.Parse).ToList(); public static Ll NextLongList() => ReadLine().Split().Select(long.Parse).ToList(); public static T Tee<T>(this T t, Func<T, string> formatter = null) { if (formatter == null) formatter = arg => arg.ToString(); formatter(t).WL(); return t; } public static void JoinWL<T>(this IEnumerable<T> @this, string sp = " ") => @this.StringJoin(sp).WL(); public static void W(this object @this) => Write(@this); } } namespace CS_Contest.Utils { using Li=List<int>; using Ll=List<long>; public static class Utils { public static List<T> Repeat<T>(Func<int, T> result, int range) => Enumerable.Range(0, range).Select(result).ToList(); public static long[,] CombinationTable(int n) { var rt = new long[n + 1, n + 1]; for (var i = 0; i <= n; i++) { for (var j = 0; j <= i; j++) { if (j == 0 || i == j) rt[i, j] = 1L; else rt[i, j] = (rt[i - 1, j - 1] + rt[i - 1, j]); } } return rt; } public static long ModValue = (long)1e9 + 7; public static long INF = long.MaxValue; public static long Mod(long x) => x % ModValue; public static long ModPow(long x, long n) { long tmp = 1; while (n != 0) { if (n % 2 == 1) { tmp = Mod(tmp * x); } x = Mod(x * x); n /= 2; } return tmp; } public static long DivMod(long x, long y) => Mod(x * ModPow(y, (long)(1e9 + 5))); public static void Add<T1, T2>(this List<Tuple<T1, T2>> list, T1 t1, T2 t2) => list.Add(new Tuple<T1, T2>(t1, t2)); public static bool IsPrime(int n) { if (n == 2) return true; if (n < 2||n%2==0) return false; var i = 3; int sq = (int)Sqrt(n); while (i <= sq) { if (n % i == 0) return false; i += 2; } return true; } public static IEnumerable<int> Primes(int maxnum) { yield return 2; yield return 3; var sieve = new BitArray(maxnum + 1); int squareroot = (int)Math.Sqrt(maxnum); for (int i = 2; i <= squareroot; i++) { if (sieve[i] == false) { for (int n = i * 2; n <= maxnum; n += i) sieve[n] = true; } for (var n = i * i + 1; n <= maxnum && n < (i + 1) * (i + 1); n++) { if (!sieve[n]) yield return n; } } } public static T Min<T>(params T[] a) where T : IComparable<T> => a.Min(); public static T Max<T>(params T[] a) where T : IComparable<T> => a.Max(); public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } public static Dictionary<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) { var dic = new Dictionary<TKey, int>(); foreach (var item in l) { if (dic.ContainsKey(item)) dic[item]++; else dic.Add(item, 1); } return dic; } public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target)); public static IEnumerable<T> SkipAt<T>(this IEnumerable<T> @this, int at) { var enumerable = @this as T[] ?? @this.ToArray(); for (var i = 0; i < enumerable.Count(); i++) { if(i==at) continue; yield return enumerable.ElementAt(i); } } } public class Map<TKey, TValue> : Dictionary<TKey, TValue> { public Map() : base() { } public Map(int capacity) : base(capacity) { } public new TValue this[TKey index] { get { TValue v; return this.TryGetValue(index, out v) ? v : base[index] = default(TValue); } set { base[index] = value; } } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using static System.Console; using static System.Math; using System.Numerics; using CS_Contest.Graph; using CS_Contest.Loop; using CS_Contest.Utils; using static Nakov.IO.Cin; using static CS_Contest.IO.IO; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; using ti3=Tuple<int,int,int>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } public class Calc { public void Solve() { int H = NextInt(), W = NextInt(); var dic = new Map<char, int>(); H.REP(i => ReadLine().Foreach(c => dic[c]++)); Func<bool> getRes = () => { if (H%2 == 0 && W%2 == 0) { //偶数x偶数 return dic.All(x => x.Value % 4 == 0); } var map = new Map<int, int>(); dic.Foreach(v => map[v.Value % 4]++); if (H%2 == 1 && W%2 == 1) { //奇数x奇数 if (map[3] >= 1) return false; if (map[1] != 1) return false; return map[2] <= (H - 1) / 2 + (W - 1) / 2; } if (W % 2 == 1) Utils.Utils.Swap(ref W, ref H); if (map[1] >= 1 || map[3] >= 1) return false; return map[2] <= W / 2; }; (getRes()?"Yes":"No").WL(); return; } } } } namespace Nakov.IO { using System; using System.Text; using System.Globalization; public static class Cin { public static string NextToken() { StringBuilder tokenChars = new StringBuilder(); bool tokenFinished = false; bool skipWhiteSpaceMode = true; while (!tokenFinished) { int nextChar = Console.Read(); if (nextChar == -1) { tokenFinished = true; } else { char ch = (char)nextChar; if (char.IsWhiteSpace(ch)) { if (!skipWhiteSpaceMode) { tokenFinished = true; if (ch == '\r' && (Environment.NewLine == "\r\n")) { Console.Read(); } } } else { skipWhiteSpaceMode = false; tokenChars.Append(ch); } } } string token = tokenChars.ToString(); return token; } public static int NextInt() { string token = Cin.NextToken(); return int.Parse(token); } public static long NextLong() { string token = Cin.NextToken(); return long.Parse(token); } public static double NextDouble(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); double result = double.Parse(token, CultureInfo.InvariantCulture); return result; } else { double result = double.Parse(token); return result; } } public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); decimal result = decimal.Parse(token, CultureInfo.InvariantCulture); return result; } else { decimal result = decimal.Parse(token); return result; } } } } namespace CS_Contest.Graph { using Ll=List<long>; using Li=List<int>; public struct WeightedUnionFind { private readonly int N; public int[] Parent { get; private set; } public long[] Cost { get; private set; } public int[] Rank { get; private set; } public WeightedUnionFind(int n) { N = n; Parent = Enumerable.Range(0, N).ToArray(); Cost = new long[N]; Rank = new int[N]; } public int Root(int u, out long cost) { if (Parent[u] == u) { cost = Cost[u]; return u; } var v = Root(Parent[u], out cost); cost += Cost[u]; Parent[u] = v; Cost[u] = cost; return v; } public void Unite(int lv, int rv, long cost) { long lc, rc; lv = Root(lv, out lc); rv = Root(rv, out rc); cost = -rc + cost + lc; if (Rank[lv] < Rank[rv]) { Unite(rv, lv, -cost); return; } Parent[rv] = lv; Cost[rv] = cost; Rank[lv] += Rank[rv] + 1; } public bool IsValid() { for (var i = 0; i < N; i++) { long _; Root(i, out _); } for (var i = 0; i < N; i++) { if (Parent[i] == i && Cost[i] != 0L) { return false; } } return true; } } /// <summary> /// UnionFind /// </summary> public struct UnionFind { private readonly int[] _data; public UnionFind(int size) { _data = new int[size]; for (var i = 0; i < size; i++) _data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return x != y; if (_data[y] < _data[x]) { var tmp = y; y = x; x = tmp; } _data[x] += _data[y]; _data[y] = x; return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return _data[x] < 0 ? x : _data[x] = Root(_data[x]); } } public class BellmanFord : CostGraph { public BellmanFord(int size) : base(size) { } public List<long> Distance { get; set; } private bool[] _negative; public bool HasCycle => _negative[Size - 1]; public void Run(int s) { Distance = new Ll(); Size.REP(i => Distance.Add(Inf)); Distance[s] = 0; _negative = new bool[Size]; (Size - 1).REP(i => Size.REP(j => Adjacency[j].Count.REP(k => { var src = Adjacency[j][k]; if (Distance[src.To] > Distance[j] + src.Cost) Distance[src.To] = Distance[j] + src.Cost; } ))); for (int i = 0; i < Size; i++) { Size.REP(j => { Adjacency[j].Count.REP(k => { var src = Adjacency[j][k]; if (Distance[src.To] > Distance[j] + src.Cost) { Distance[src.To] = Distance[j] + src.Cost; _negative[src.To] = true; } if (_negative[j]) _negative[src.To] = true; }); }); } } } public class CostGraph { public struct Edge { public int To { get; set; } public long Cost { get; set; } public Edge(int to, long cost) { To = to; Cost = cost; } } public int Size { get; set; } public List<List<Edge>> Adjacency { get; set; } public const long Inf = (long)1e15; public CostGraph(int size) { Size = size; Adjacency = new List<List<Edge>>(); Size.REP(_ => Adjacency.Add(new List<Edge>())); } public void Add(int s, int t, long c, bool dir = true) { Adjacency[s].Add(new Edge(t, c)); if (!dir) Adjacency[t].Add(new Edge(s, c)); } } /// <summary> /// 優先度付きキュー /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) { } public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) { } public PriorityQueue(Comparison<T> comparison) : this(16, comparison) { } public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count => size; public bool Any() { return size > 0; } } public class Dijkstra : CostGraph { public Dijkstra(int size) : base(size) { } public int[] PreviousNodeList { get; set; } public long[] Distance { get; set; } public void Run(int s) { PreviousNodeList = new int[Size]; Distance = new long[Size]; Size.REP(_ => Distance[_] = Inf); var pq = new PriorityQueue<Edge>((x, y) => x.Cost.CompareTo(y.Cost)); Distance[s] = 0; pq.Enqueue(new Edge(s, 0)); while (pq.Any()) { var src = pq.Dequeue(); if (Distance[src.To] < src.Cost) continue; for (var i = 0; i < Adjacency[src.To].Count; i++) { var tmp = Adjacency[src.To][i]; var cost = tmp.Cost + src.Cost; if (cost >= Distance[tmp.To]) continue; Distance[tmp.To] = cost; pq.Enqueue(new Edge(tmp.To, cost)); PreviousNodeList[tmp.To] = src.To; } } } } public class WarshallFloyd : CostGraph { public WarshallFloyd(int size) : base(size) { } public List<Ll> Run() { var rt = new List<Ll>(); Size.REP(_ => rt.Add(new Ll())); Size.REP(i => Size.REP(k => rt[i].Add(i == k ? 0 : Inf))); Adjacency.ForeachWith( (i, item) => { foreach (var k in item) { rt[i][k.To] = k.Cost; } }); Size.REP(i => Size.REP(j => Size.REP(k => { rt[j][k] = Min(rt[j][k], rt[j][i] + rt[i][k]); }))); return rt; } } } namespace CS_Contest.Loop { public static class Loop { public static void REP(this int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static void RREP(this int @n, Action<int> act) { for (var i = n - 1; i >= 0; i--) act(i); } public static void REP(this long n, Action<long> act) { for (var i = 0; i < n; i++) act(i); } public static void FOR(this Tuple<int, int, int> t, Action<int> action) { for (var i = t.Item1; i < t.Item2; i += t.Item3) action(i); } public static void FOR(this Tuple<int, int> t, Action<int> action) => new Tuple<int, int, int>(t.Item1, t.Item2, 1).FOR(action); public static void FOR(this Tuple<long, long, long> t, Action<long> action) { for (var i = t.Item1; i < t.Item2; i += t.Item3) action(i); } public static void FOR(this Tuple<long, long> t, Action<long> act) => new Tuple<long, long, long>(t.Item1, t.Item2, 1).FOR(act); public static void ForeachWith<T>(this IEnumerable<T> ie, Action<int, T> act) { var i = 0; foreach (var item in ie) { act(i, item); i++; } } public static void Foreach<T>(this IEnumerable<T> ie, Action<T> act) { foreach (var item in ie) { act(item); } } } } namespace CS_Contest.IO { using Li = List<int>; using Ll = List<long>; public static class IO { public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static Li NextIntList() => ReadLine().Split().Select(int.Parse).ToList(); public static Ll NextLongList() => ReadLine().Split().Select(long.Parse).ToList(); public static T Tee<T>(this T t, Func<T, string> formatter = null) { if (formatter == null) formatter = arg => arg.ToString(); formatter(t).WL(); return t; } public static void JoinWL<T>(this IEnumerable<T> @this, string sp = " ") => @this.StringJoin(sp).WL(); public static void W(this object @this) => Write(@this); } } namespace CS_Contest.Utils { using Li=List<int>; using Ll=List<long>; public static class Utils { public static List<T> Repeat<T>(Func<int, T> result, int range) => Enumerable.Range(0, range).Select(result).ToList(); public static long[,] CombinationTable(int n) { var rt = new long[n + 1, n + 1]; for (var i = 0; i <= n; i++) { for (var j = 0; j <= i; j++) { if (j == 0 || i == j) rt[i, j] = 1L; else rt[i, j] = (rt[i - 1, j - 1] + rt[i - 1, j]); } } return rt; } public static long ModValue = (long)1e9 + 7; public static long INF = long.MaxValue; public static long Mod(long x) => x % ModValue; public static long ModPow(long x, long n) { long tmp = 1; while (n != 0) { if (n % 2 == 1) { tmp = Mod(tmp * x); } x = Mod(x * x); n /= 2; } return tmp; } public static long DivMod(long x, long y) => Mod(x * ModPow(y, (long)(1e9 + 5))); public static void Add<T1, T2>(this List<Tuple<T1, T2>> list, T1 t1, T2 t2) => list.Add(new Tuple<T1, T2>(t1, t2)); public static bool IsPrime(int n) { if (n == 2) return true; if (n < 2||n%2==0) return false; var i = 3; int sq = (int)Sqrt(n); while (i <= sq) { if (n % i == 0) return false; i += 2; } return true; } public static IEnumerable<int> Primes(int maxnum) { yield return 2; yield return 3; var sieve = new BitArray(maxnum + 1); int squareroot = (int)Math.Sqrt(maxnum); for (int i = 2; i <= squareroot; i++) { if (sieve[i] == false) { for (int n = i * 2; n <= maxnum; n += i) sieve[n] = true; } for (var n = i * i + 1; n <= maxnum && n < (i + 1) * (i + 1); n++) { if (!sieve[n]) yield return n; } } } public static T Min<T>(params T[] a) where T : IComparable<T> => a.Min(); public static T Max<T>(params T[] a) where T : IComparable<T> => a.Max(); public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } public static Dictionary<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) { var dic = new Dictionary<TKey, int>(); foreach (var item in l) { if (dic.ContainsKey(item)) dic[item]++; else dic.Add(item, 1); } return dic; } public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target)); public static IEnumerable<T> SkipAt<T>(this IEnumerable<T> @this, int at) { var enumerable = @this as T[] ?? @this.ToArray(); for (var i = 0; i < enumerable.Count(); i++) { if(i==at) continue; yield return enumerable.ElementAt(i); } } } public class Map<TKey, TValue> : Dictionary<TKey, TValue> { public Map() : base() { } public Map(int capacity) : base(capacity) { } public new TValue this[TKey index] { get { TValue v; return this.TryGetValue(index, out v) ? v : base[index] = default(TValue); } set { base[index] = value; } } } }
[["-", 0, 28, 0, 218, 8, 11, 0, 202, 0, 32], ["-", 0, 218, 8, 11, 12, 16, 31, 23, 0, 24], ["-", 12, 16, 31, 23, 0, 16, 31, 204, 205, 22], ["-", 31, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 206, 207, 0, 28, 0, 16, 31, 214, 205, 22], ["-", 206, 207, 0, 28, 0, 16, 31, 214, 0, 131], ["-", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 109], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 31, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["-", 8, 11, 12, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 218, 8, 11, 12, 16, 31, 23, 0, 25], ["-", 0, 28, 0, 218, 8, 11, 12, 16, 17, 109], ["-", 0, 28, 0, 218, 8, 11, 12, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 218, 8, 223, 0, 29], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20]]
8
4,352
22
using System; using System.Linq; using System.Collections.Generic; namespace codefes2017c { class Program { static void Main(string[] args) { int h = nextInt(); int w = nextInt(); string[] m = new string[h]; var dic = new Dictionary<char, int>(); for (int i = 0; i < h; i++) { string s = Console.ReadLine(); foreach (char c in s) { if (!dic.ContainsKey(c)) dic.Add(c, 0); dic[c]++; } } var keys = new List<char>(dic.Keys); int cnt = 0; if (h % 2 == 1 && w % 2 == 1) { cnt = 0; foreach (char key in keys) { if (dic[key] % 2 == 1) { dic[key] -= 1; cnt++; } } if (cnt != 1) { Console.WriteLine("No"); Environment.Exit(0); } } cnt = 0; for (int i = 0; i < (h / 2) * (w / 2); i++) { foreach (char key in keys) { if (dic[key] > 0 && dic[key] / 4 > 0) { dic[key] -= 4; cnt++; break; } } } if (cnt != (h / 2) * (w / 2)) { Console.WriteLine("No"); Environment.Exit(0); } cnt = 0; for (int i = 0; i < ((h % 2) * w) / 2 + ((w % 2) * h) / 2; i++) { foreach (char key in keys) { if (dic[key] % 2 == 0) { dic[key] -= 2; cnt++; break; } } } if (cnt != ((h % 2) * w) / 2 + ((w % 2) * h) / 2) { Console.WriteLine("No"); Environment.Exit(0); } Console.WriteLine("Yes"); } static int[] stdin_int = new int[0]; static int currentPos = 0; static int nextInt() { if (currentPos == stdin_int.Length) { stdin_int = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); currentPos = 0; } return stdin_int[currentPos++]; } } }
using System; using System.Linq; using System.Collections.Generic; namespace codefes2017c { class Program { static void Main(string[] args) { int h = nextInt(); int w = nextInt(); string[] m = new string[h]; var dic = new Dictionary<char, int>(); for (int i = 0; i < h; i++) { string s = Console.ReadLine(); foreach (char c in s) { if (!dic.ContainsKey(c)) dic.Add(c, 0); dic[c]++; } } var keys = new List<char>(dic.Keys); int cnt = 0; if (h % 2 == 1 && w % 2 == 1) { cnt = 0; foreach (char key in keys) { if (dic[key] % 2 == 1) { dic[key] -= 1; cnt++; } } if (cnt != 1) { Console.WriteLine("No"); Environment.Exit(0); } } cnt = 0; for (int i = 0; i < (h / 2) * (w / 2); i++) { foreach (char key in keys) { if (dic[key] > 0 && dic[key] / 4 > 0) { dic[key] -= 4; cnt++; break; } } } if (cnt != (h / 2) * (w / 2)) { Console.WriteLine("No"); Environment.Exit(0); } cnt = 0; for (int i = 0; i < ((h % 2) * w) / 2 + ((w % 2) * h) / 2; i++) { foreach (char key in keys) { if (dic[key] > 0 && dic[key] % 2 == 0) { dic[key] -= 2; cnt++; break; } } } if (cnt != ((h % 2) * w) / 2 + ((w % 2) * h) / 2) { Console.WriteLine("No"); Environment.Exit(0); } Console.WriteLine("Yes"); } static int[] stdin_int = new int[0]; static int currentPos = 0; static int nextInt() { if (currentPos == stdin_int.Length) { stdin_int = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); currentPos = 0; } return stdin_int[currentPos++]; } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 15, 16, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73]]
8
541
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { private int H, W; private int[] Count = new int[200]; public void Solve() { var l = Console.ReadLine().Split(' '); H = int.Parse(l[0]); W = int.Parse(l[1]); for (int i = 0; i < H; i++) { foreach (char c in Console.ReadLine()) { Count[c]++; } } int two = 0, one = 0; foreach (int i in Count) { if (i % 2 == 1) { one++; } if (i % 4 == 2 || i % 4 == 3) { two++; } } if (H % 2 == 1 && W % 2 == 1) { if (one != 1) { Console.WriteLine("No"); return; } } else { if (one != 0) { Console.WriteLine("No"); return; } } int tt = 0; if (H % 2 == 1) { tt += W / 2; } if (W % 2 == 1) { tt += H / 2; } if (tt < two || (tt - two) % 2 == 1) { Console.WriteLine("No"); } Console.WriteLine("Yes"); } static void Main() { new Program().Solve(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { private int H, W; private int[] Count = new int[200]; public void Solve() { var l = Console.ReadLine().Split(' '); H = int.Parse(l[0]); W = int.Parse(l[1]); for (int i = 0; i < H; i++) { foreach (char c in Console.ReadLine()) { Count[c]++; } } int two = 0, one = 0; foreach (int i in Count) { if (i % 2 == 1) { one++; } if (i % 4 == 2 || i % 4 == 3) { two++; } } if (H % 2 == 1 && W % 2 == 1) { if (one != 1) { Console.WriteLine("No"); return; } } else { if (one != 0) { Console.WriteLine("No"); return; } } int tt = 0; if (H % 2 == 1) { tt += W / 2; } if (W % 2 == 1) { tt += H / 2; } if (two > tt) { Console.WriteLine("No"); return; } if ((tt - two) % 2 == 1) { Console.WriteLine("No"); return; } Console.WriteLine("Yes"); } static void Main() { new Program().Solve(); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24]]
8
320
23
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; ReadData re; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); re = new ReadData(); Calc(); Console.Write(sb.ToString()); } void Calc() { int N = re.i(); int[] S = new int[N]; int[] U = new int[N]; for (int i = 0; i < N; i++) { int X = re.i(); int last = 0; for (int j = 1; j < 30; j++) { if (((1 << j) & X) != 0) { last = j; } } U[i] = last; S[i] = last; if (X != (1 << last)) { S[i]++; } } long[] DPL = new long[N]; long[] DPR = new long[N]; if (S[0] != U[0]) { DPL[0] = 1; DPR[0] = 1; } DPL[0] += U[0]; DPR[0] += S[0]; for (int i = 1; i < N; i++) { if (S[i] != U[i]) { DPL[i] = 1; DPR[i] = 1; } DPL[i] += Math.Min(Math.Max(U[i] - U[i - 1], U[i - 1] - U[i]) + DPL[i - 1], Math.Max(U[i] - S[i - 1], S[i - 1] - U[i]) + DPR[i - 1]); DPR[i] += Math.Min(Math.Max(S[i] - U[i - 1], U[i - 1] - S[i]) + DPL[i - 1], Math.Max(S[i] - S[i - 1], S[i - 1] - S[i]) + DPR[i - 1]); } long count = Math.Min(DPL[N - 1] + U[N - 1], DPR[N - 1] + S[N - 1]); count /= 2; sb.Append(count + "\n"); } } class ReadData { string[] str; int counter; public ReadData() { counter = 0; } public string s() { if (counter == 0) { str = Console.ReadLine().Split(' '); counter = str.Length; } counter--; return str[str.Length - counter - 1]; } public int i() { return int.Parse(s()); } public long l() { return long.Parse(s()); } public double d() { return double.Parse(s()); } public int[] ia(int N) { int[] ans = new int[N]; for (int j = 0; j < N; j++) { ans[j] = i(); } return ans; } public int[] ia() { str = Console.ReadLine().Split(' '); counter = 0; int[] ans = new int[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = int.Parse(str[j]); } return ans; } public long[] la(int N) { long[] ans = new long[N]; for (int j = 0; j < N; j++) { ans[j] = l(); } return ans; } public long[] la() { str = Console.ReadLine().Split(' '); counter = 0; long[] ans = new long[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = long.Parse(str[j]); } return ans; } public double[] da(int N) { double[] ans = new double[N]; for (int j = 0; j < N; j++) { ans[j] = d(); } return ans; } public double[] da() { str = Console.ReadLine().Split(' '); counter = 0; double[] ans = new double[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = double.Parse(str[j]); } return ans; } public List<int>[] g(int N, int[] f, int[] t) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < f.Length; j++) { ans[f[j]].Add(t[j]); ans[t[j]].Add(f[j]); } return ans; } public List<int>[] g(int N, int M) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } public List<int>[] g() { int N = i(); int M = i(); List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } } public static class Define { public const long mod = 1000000007; } public static class Debug { public static void Print(double[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(double[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(double[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(long[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(long[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(long[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(int[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(int[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(int[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; ReadData re; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); re = new ReadData(); Calc(); Console.Write(sb.ToString()); } void Calc() { int N = re.i(); int[] S = new int[N]; int[] U = new int[N]; for (int i = 0; i < N; i++) { int X = re.i(); int last = 0; for (int j = 1; j < 30; j++) { if (((1 << j) & X) != 0) { last = j; } } U[i] = last; S[i] = last; if (X != (1 << last)) { S[i]++; } } long[] DPL = new long[N]; long[] DPR = new long[N]; if (S[0] != U[0]) { DPL[0] = 1; DPR[0] = 1; } DPL[0] += U[0]; DPR[0] += S[0]; for (int i = 1; i < N; i++) { if (S[i] != U[i]) { DPL[i] = 1; DPR[i] = 1; } DPL[i] += Math.Min(Math.Max(U[i] - S[i - 1], S[i - 1] - U[i]) + DPL[i - 1], Math.Max(U[i] - U[i - 1], U[i - 1] - U[i]) + DPR[i - 1]); DPR[i] += Math.Min(Math.Max(S[i] - S[i - 1], S[i - 1] - S[i]) + DPL[i - 1], Math.Max(S[i] - U[i - 1], U[i - 1] - S[i]) + DPR[i - 1]); } long count = Math.Min(DPL[N - 1] + S[N - 1], DPR[N - 1] + U[N - 1]); count /= 2; sb.Append(count + "\n"); } } class ReadData { string[] str; int counter; public ReadData() { counter = 0; } public string s() { if (counter == 0) { str = Console.ReadLine().Split(' '); counter = str.Length; } counter--; return str[str.Length - counter - 1]; } public int i() { return int.Parse(s()); } public long l() { return long.Parse(s()); } public double d() { return double.Parse(s()); } public int[] ia(int N) { int[] ans = new int[N]; for (int j = 0; j < N; j++) { ans[j] = i(); } return ans; } public int[] ia() { str = Console.ReadLine().Split(' '); counter = 0; int[] ans = new int[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = int.Parse(str[j]); } return ans; } public long[] la(int N) { long[] ans = new long[N]; for (int j = 0; j < N; j++) { ans[j] = l(); } return ans; } public long[] la() { str = Console.ReadLine().Split(' '); counter = 0; long[] ans = new long[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = long.Parse(str[j]); } return ans; } public double[] da(int N) { double[] ans = new double[N]; for (int j = 0; j < N; j++) { ans[j] = d(); } return ans; } public double[] da() { str = Console.ReadLine().Split(' '); counter = 0; double[] ans = new double[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = double.Parse(str[j]); } return ans; } public List<int>[] g(int N, int[] f, int[] t) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < f.Length; j++) { ans[f[j]].Add(t[j]); ans[t[j]].Add(f[j]); } return ans; } public List<int>[] g(int N, int M) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } public List<int>[] g() { int N = i(); int M = i(); List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } } public static class Define { public const long mod = 1000000007; } public static class Debug { public static void Print(double[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(double[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(double[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(long[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(long[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(long[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(int[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(int[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(int[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } }
[["-", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22]]
8
2,123
20
using System; using System.Linq; class Program { static void Main() { // string[] input = Console.ReadLine().Split(); int a = int.Parse(Console.ReadLine()); int b = int.Parse(Console.ReadLine()); // string a = Console.ReadLine(); Console.WriteLine((a + b) / 2); Console.ReadLine(); } }
using System; using System.Linq; class Program { static void Main() { // string[] input = Console.ReadLine().Split(); int a = int.Parse(Console.ReadLine()); int b = int.Parse(Console.ReadLine()); // string a = Console.ReadLine(); Console.WriteLine(b * 2 - a); Console.ReadLine(); } }
[["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
68
8
using System; using System.Linq; public class main { static public void Main() { int n, k; n = int.Parse(Console.ReadLine()); k = int.Parse(Console.ReadLine()); int show = 1; for (int i = 0; i < n; i++) { Console.WriteLine(show); if (show < k) { show = show * 2; } else { show += k; } } Console.WriteLine(show); } }
using System; using System.Linq; public class main { static public void Main() { int n, k; n = int.Parse(Console.ReadLine()); k = int.Parse(Console.ReadLine()); int show = 1; for (int i = 0; i < n; i++) { if (show < k) { show = show * 2; } else { show += k; } } Console.WriteLine(show); } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
108
7
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; using System.Numerics; namespace AtCoder { public class Program { public static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); // Out.Flush(); Read(); } static void Solve() { var Sd = ReadLine(); var T = ReadLine(); var N = Sd.Length; for (var i = 0; i < N - T.Length + 1; ++i) { var cdt = Sd.ToCharArray(); var flg = true; for (var j = 0; j < T.Length; ++j) { if (Sd[i + j] == T[j] || Sd[i + j] == '?') cdt[i + j] = T[j]; else { flg = false; break; } } if (flg) { cdt = cdt.Select(c => c == '?' ? 'a' : c).ToArray(); WriteLine(string.Join("", cdt)); return; } } WriteLine("UNRESTORABLE"); } static long Mod = (long)1e9 + 7; static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static public (T1 a, T2 b) Slice<T1, T2>() { var t = ReadLine().Split(); return ((T1)Convert.ChangeType(t[0], typeof(T1)), (T2)Convert.ChangeType(t[1], typeof(T2))); } static public (T a, T b) Slice2<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T))); } static public (T a, T b, T c) Slice3<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T)), (T)Convert.ChangeType(t[2], typeof(T))); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; using System.Numerics; namespace AtCoder { public class Program { public static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); // Out.Flush(); Read(); } static void Solve() { var Sd = ReadLine().Reverse().ToArray(); var T = ReadLine().Reverse().ToArray(); var N = Sd.Length; for (var i = 0; i < N - T.Length + 1; ++i) { var cdt = Sd.ToArray(); var flg = true; for (var j = 0; j < T.Length; ++j) { if (Sd[i + j] == T[j] || Sd[i + j] == '?') cdt[i + j] = T[j]; else { flg = false; break; } } if (flg) { cdt = cdt.Select(c => c == '?' ? 'a' : c).ToArray(); WriteLine(string.Join("", cdt.Reverse().ToArray())); return; } } WriteLine("UNRESTORABLE"); } static long Mod = (long)1e9 + 7; static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static public (T1 a, T2 b) Slice<T1, T2>() { var t = ReadLine().Split(); return ((T1)Convert.ChangeType(t[0], typeof(T1)), (T2)Convert.ChangeType(t[1], typeof(T2))); } static public (T a, T b) Slice2<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T))); } static public (T a, T b, T c) Slice3<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T)), (T)Convert.ChangeType(t[2], typeof(T))); } } }
[["+", 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], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 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
550
26
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class78 { static void Main() { char[] S = Console.ReadLine().ToCharArray(); string T = Console.ReadLine(); for (int i = 0; i <= S.Length - T.Length; i++) { bool frag = true; for (int j = 0; j < T.Length; j++) { if (S[i + j] != T[j]) if (S[i + j] != '?') frag = false; } if (frag) { for (int j = 0; j < T.Length; j++) { S[i + j] = T[j]; } for (int j = 0; j < S.Length; j++) if (S[j] == '?') S[j] = 'a'; Console.WriteLine(S); return; } } Console.WriteLine("UNRESTORABLE"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class78 { static void Main() { char[] S = Console.ReadLine().ToCharArray(); string T = Console.ReadLine(); for (int i = S.Length - T.Length; i >= 0; i--) { bool frag = true; for (int j = 0; j < T.Length; j++) { if (S[i + j] != T[j]) if (S[i + j] != '?') frag = false; } if (frag) { for (int j = 0; j < T.Length; j++) { S[i + j] = T[j]; } for (int j = 0; j < S.Length; j++) if (S[j] == '?') S[j] = 'a'; Console.WriteLine(S); return; } } Console.WriteLine("UNRESTORABLE"); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
232
10
// // ABC076C // URL : // using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.ComponentModel; namespace AtCoder.Template.ABC076C { class Solver { public static readonly long MOD_CONST = 1000000007; //(long)Math.Pow(10, 9) + 7; public static void Main(string[] args) { //出力高速化 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } public void Solve() { string S = Console.ReadLine(); string T = Console.ReadLine(); // Sの中にTを当てはめてみる for (int i = 0; i <= S.Length - T.Length; ++i) { var sub = S.Substring(i, T.Length); if (IsSameIgnoreQ(sub, T)) { // Sの中にTを入れる場所があった //その場所にTを入れる var newS = OverrideString(S, i, T); var ans = newS.Replace('?', 'a'); //辞書式最小なので'?'->'a'に変換 Console.WriteLine(ans); return; } } Console.WriteLine("UNRESTORABLE"); } /// <summary> /// 与えられた文字列が?の部分を無視して、一致するかどうか /// </summary> /// <param name="s">?が入った文字列</param> /// <param name="t">もう一つの比較対象。?はない</param> /// <returns></returns> public bool IsSameIgnoreQ(string s, string t) { int MIN = Math.Min(s.Length, t.Length); for (int i = 0; i < MIN; ++i) { if (s[i] == '?') { continue; } if (s[i] != t[i]) { return false; } } return true; } /// <summary> /// s[pos]から文字列tで上書き /// </summary> /// <param name="s"></param> /// <param name="pos"></param> /// <param name="t"></param> /// <returns></returns> public string OverrideString(string s, int pos, string t) { StringBuilder ans = new StringBuilder(s); for (int i = pos; i < pos + t.Length; ++i) { ans[i] = t[i - pos]; } return ans.ToString(); } //--------------------------------------------------------------------------------- #region MyLib /// <summary> /// リストから、重複したものを除外したリストを新規に作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="src"></param> /// <param name="dst"></param> public static void getDistinctList<T>(List<T> src, out List<T> dst) { var iter = src.Distinct(); dst = new List<T>(); foreach (var item in iter) { dst.Add(item); } } /// <summary> /// グラフ系 /// </summary> public class Node { public Node(long val) { this.Value = val; this.Children = new List<Node>(); } public Node(long val, List<Node> children) { this.Value = val; this.Children = children; } public long Value { get; set; } public List<Node> Children { get; set; } } /// <summary> /// Clamping /// </summary> /// <typeparam name="T">比較型</typeparam> /// <param name="x">clampしたい値</param> /// <param name="min">最小値</param> /// <param name="max">最大値</param> /// <returns>clamp済みの値</returns> public static T Clamp<T>(T x, T min, T max) where T : IComparable<T> { if (x.CompareTo(min) < 0) { return min; } else if (x.CompareTo(max) > 0) { return max; } else return x; // return Math.Max(Math.Min(x, max), min); } /// <summary> /// 指定された底log_baseでの, 対数を計算 /// </summary> /// <param name="x"></param> /// <param name="log_base">指定の底</param> /// <returns></returns> public static double LogBase(double x, double log_base) { // log_b(N) = log_a(N) / log_a(B)より return Math.Log(x) / Math.Log(log_base); } /// <summary> /// 初項a, 公差d, 項数nの数列の和 /// </summary> /// <param name="n">求めたいところ</param> /// <returns>初項からxまで足した値</returns> static long SumSeries(long a, long d, long n) { return (2 * a + (n - 1) * d) * n / 2; } /// <summary> /// 累積和の配列を計算する /// Sum[ a[0], a[i] )がs[i+1]に入っている /// s[0] : 0 //一切和を取らない場合 /// s[1] : ls[0] //a[0] + s[0] = a[0] /// s[2] : ls[1] + s[1] //a[1] + a[0] /// ... /// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0] /// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0] /// /// 例: [1, 7)の和(a[1] + ... + a[6]) /// s[1] = a[0] //[0, 1) /// s[7] = a[0] + a[1] + ... + a[6] //[0, 7) /// よってs[7] - s[1]); /// </summary> /// <param name="ls">計算したい配列</param> /// <returns>累積和配列</returns> static List<long> AggregateSumList(List<long> a) { var s = new List<long>(a.Count + 1); if (a.Count == 0) { return s; } s.Add(0); // s[0] = 0 for (int i = 0; i < a.Count; ++i) { s.Add(a[i] + s[i]); } return s; } /// <summary> /// 与えられた数が素数かどうかを計算する /// </summary> /// <param name="num">対象数</param> /// <returns>true:素数, false:素数ではない(合成数)</returns> public static bool isPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } /// <summary> /// 素因数分解 /// </summary> /// <param name="n"></param> /// <returns>keyが素数、valueがその素数の登場回数</returns> public static Dictionary<long, long> PrimeFactorization(long n) { var result = new Dictionary<long, long>(); //初めの素数2から割っていく for (long p = 2; p * p <= n; p++) { //割り切れないなら、素因数に含まれてない if (n % p != 0) continue; long count = 0; // 割り続ける while (n % p == 0) { count++; n /= p; } result[p] = count; } // 素数が残っている場合 if (n != 1) result[n] = 1; return result; } /// <summary> /// 順列mPnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Permutation(long m, long n) { long ret = 1; for (var i = 0; i < n; ++i) { ret *= m - i; } return ret; } /// <summary> /// 組み合わせmCnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Combination(long m, long n) { if (m == n || n == 0) { return 1; } long ans = 1; for (var i = 1; i <= n; ++i) { ans = ans * (m - i + 1) / i; } return ans; } static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } static long Lcm(long m, long n) { var gcd = Gcd(m, n); // return (m * n) / gcd; return m / gcd * n; //桁あふれ対策 } #endregion MyLib } }
// // ABC076C // URL : // using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.ComponentModel; namespace AtCoder.Template.ABC076C { class Solver { public static readonly long MOD_CONST = 1000000007; //(long)Math.Pow(10, 9) + 7; public static void Main(string[] args) { //出力高速化 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } public void Solve() { string S = Console.ReadLine(); string T = Console.ReadLine(); // Sの中にTを当てはめてみる for (int i = S.Length - T.Length; i >= 0; --i) { var sub = S.Substring(i, T.Length); if (IsSameIgnoreQ(sub, T)) { // Sの中にTを入れる場所があった //その場所にTを入れる var newS = OverrideString(S, i, T); var ans = newS.Replace('?', 'a'); //辞書式最小なので'?'->'a'に変換 Console.WriteLine(ans); return; } } Console.WriteLine("UNRESTORABLE"); } /// <summary> /// 与えられた文字列が?の部分を無視して、一致するかどうか /// </summary> /// <param name="s">?が入った文字列</param> /// <param name="t">もう一つの比較対象。?はない</param> /// <returns></returns> public bool IsSameIgnoreQ(string s, string t) { int MIN = Math.Min(s.Length, t.Length); for (int i = 0; i < MIN; ++i) { if (s[i] == '?') { continue; } if (s[i] != t[i]) { return false; } } return true; } /// <summary> /// s[pos]から文字列tで上書き /// </summary> /// <param name="s"></param> /// <param name="pos"></param> /// <param name="t"></param> /// <returns></returns> public string OverrideString(string s, int pos, string t) { StringBuilder ans = new StringBuilder(s); for (int i = pos; i < pos + t.Length; ++i) { ans[i] = t[i - pos]; } return ans.ToString(); } //--------------------------------------------------------------------------------- #region MyLib /// <summary> /// リストから、重複したものを除外したリストを新規に作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="src"></param> /// <param name="dst"></param> public static void getDistinctList<T>(List<T> src, out List<T> dst) { var iter = src.Distinct(); dst = new List<T>(); foreach (var item in iter) { dst.Add(item); } } /// <summary> /// グラフ系 /// </summary> public class Node { public Node(long val) { this.Value = val; this.Children = new List<Node>(); } public Node(long val, List<Node> children) { this.Value = val; this.Children = children; } public long Value { get; set; } public List<Node> Children { get; set; } } /// <summary> /// Clamping /// </summary> /// <typeparam name="T">比較型</typeparam> /// <param name="x">clampしたい値</param> /// <param name="min">最小値</param> /// <param name="max">最大値</param> /// <returns>clamp済みの値</returns> public static T Clamp<T>(T x, T min, T max) where T : IComparable<T> { if (x.CompareTo(min) < 0) { return min; } else if (x.CompareTo(max) > 0) { return max; } else return x; // return Math.Max(Math.Min(x, max), min); } /// <summary> /// 指定された底log_baseでの, 対数を計算 /// </summary> /// <param name="x"></param> /// <param name="log_base">指定の底</param> /// <returns></returns> public static double LogBase(double x, double log_base) { // log_b(N) = log_a(N) / log_a(B)より return Math.Log(x) / Math.Log(log_base); } /// <summary> /// 初項a, 公差d, 項数nの数列の和 /// </summary> /// <param name="n">求めたいところ</param> /// <returns>初項からxまで足した値</returns> static long SumSeries(long a, long d, long n) { return (2 * a + (n - 1) * d) * n / 2; } /// <summary> /// 累積和の配列を計算する /// Sum[ a[0], a[i] )がs[i+1]に入っている /// s[0] : 0 //一切和を取らない場合 /// s[1] : ls[0] //a[0] + s[0] = a[0] /// s[2] : ls[1] + s[1] //a[1] + a[0] /// ... /// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0] /// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0] /// /// 例: [1, 7)の和(a[1] + ... + a[6]) /// s[1] = a[0] //[0, 1) /// s[7] = a[0] + a[1] + ... + a[6] //[0, 7) /// よってs[7] - s[1]); /// </summary> /// <param name="ls">計算したい配列</param> /// <returns>累積和配列</returns> static List<long> AggregateSumList(List<long> a) { var s = new List<long>(a.Count + 1); if (a.Count == 0) { return s; } s.Add(0); // s[0] = 0 for (int i = 0; i < a.Count; ++i) { s.Add(a[i] + s[i]); } return s; } /// <summary> /// 与えられた数が素数かどうかを計算する /// </summary> /// <param name="num">対象数</param> /// <returns>true:素数, false:素数ではない(合成数)</returns> public static bool isPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } /// <summary> /// 素因数分解 /// </summary> /// <param name="n"></param> /// <returns>keyが素数、valueがその素数の登場回数</returns> public static Dictionary<long, long> PrimeFactorization(long n) { var result = new Dictionary<long, long>(); //初めの素数2から割っていく for (long p = 2; p * p <= n; p++) { //割り切れないなら、素因数に含まれてない if (n % p != 0) continue; long count = 0; // 割り続ける while (n % p == 0) { count++; n /= p; } result[p] = count; } // 素数が残っている場合 if (n != 1) result[n] = 1; return result; } /// <summary> /// 順列mPnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Permutation(long m, long n) { long ret = 1; for (var i = 0; i < n; ++i) { ret *= m - i; } return ret; } /// <summary> /// 組み合わせmCnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Combination(long m, long n) { if (m == n || n == 0) { return 1; } long ans = 1; for (var i = 1; i <= n; ++i) { ans = ans * (m - i + 1) / i; } return ans; } static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } static long Lcm(long m, long n) { var gcd = Gcd(m, n); // return (m * n) / gcd; return m / gcd * n; //桁あふれ対策 } #endregion MyLib } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 26, 241, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 241, 0, 68]]
8
1,177
10
using System; using System.Collections.Generic; public class Hello { public static void Main() { string sdash = Console.ReadLine(); string t = Console.ReadLine(); bool ok = true; var list = new List<string>(); for (int i = 0; i < sdash.Length - t.Length + 1; i++) { string test = sdash.Substring(i, t.Length); ok = true; for (int j = 0; j < t.Length; j++) { if (test[j] == '?') continue; if (test[j] != t[j]) { ok = false; break; } } if (ok) list.Add(sdash.Substring(0, i) + t + sdash.Substring(i + t.Length)); } list.Sort(); Console.WriteLine(list[0].Replace('?', 'a')); } }
using System; using System.Collections.Generic; public class Hello { public static void Main() { string sdash = Console.ReadLine(); string t = Console.ReadLine(); bool ok = true; var list = new List<string>(); for (int i = 0; i < sdash.Length - t.Length + 1; i++) { string test = sdash.Substring(i, t.Length); ok = true; for (int j = 0; j < t.Length; j++) { if (test[j] == '?') continue; if (test[j] != t[j]) { ok = false; break; } } if (ok) list.Add(sdash.Substring(0, i) + t + sdash.Substring(i + t.Length)); } if (list.Count == 0) { Console.WriteLine("UNRESTORABLE"); return; } list.Sort(); Console.WriteLine(list[0].Replace('?', 'a')); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22]]
8
208
21
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var S = sc.ReadStr(); var T = sc.ReadStr(); var N = S.Length; var M = T.Length; var ans = new string('z', 50); for (int i = 0; i < N - M + 1; i++) { var ok = true; for (int j = 0; j < M; j++) { if (S[i + j] != T[j] && S[i + j] != '?') ok = false; } if (ok) { var res = S.Substring(0, i) + T + S.Substring(i + M); res = res.Replace('?', 'a'); if (string.CompareOrdinal(ans, res) > 0) ans = res; } } if (ans == S) Console.WriteLine("UNRESTORABLE"); else Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var S = sc.ReadStr(); var T = sc.ReadStr(); var N = S.Length; var M = T.Length; var ans = new string('z', 50); var ng = true; for (int i = 0; i < N - M + 1; i++) { var ok = true; for (int j = 0; j < M; j++) { if (S[i + j] != T[j] && S[i + j] != '?') ok = false; } if (ok) { var res = S.Substring(0, i) + T + S.Substring(i + M); res = res.Replace('?', 'a'); if (string.CompareOrdinal(ans, res) > 0) ans = res; ng = false; } } if (ng) Console.WriteLine("UNRESTORABLE"); else Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 15, 22]]
8
1,254
13
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { char[] Sdash = Console.ReadLine().ToCharArray(); char[] T = Console.ReadLine().ToCharArray(); List<int> list = new List<int>(); int nowplace = 0; while (nowplace <= Sdash.Length - T.Length) { if (Sdash[nowplace] == T[0]) { list.Add(nowplace); } nowplace++; } bool ans = false; int ansplace = -1; for (int i = list.Count - 1; i >= 0; i--) { bool okay = true; for (int j = 0; j < T.Length; j++) { if (Sdash[list[i] + j] != '?' && Sdash[list[i] + j] != T[j]) { okay = false; } } if (okay) { ans = true; ansplace = list[i]; break; } } if (ans) { for (int i = 0; i < Sdash.Length; i++) { if (i < ansplace && Sdash[i] == '?') { Sdash[i] = 'a'; } else if (ansplace <= i && i < ansplace + T.Length) { Sdash[i] = T[i - ansplace]; } else if (Sdash[i] == '?') { Sdash[i] = 'a'; } } Console.WriteLine(Sdash); } else { Console.WriteLine("UNRESTORABLE"); } } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { char[] Sdash = Console.ReadLine().ToCharArray(); char[] T = Console.ReadLine().ToCharArray(); List<int> list = new List<int>(); int nowplace = 0; while (nowplace <= Sdash.Length - T.Length) { if (Sdash[nowplace] == T[0] || Sdash[nowplace] == '?') { list.Add(nowplace); } nowplace++; } bool ans = false; int ansplace = -1; for (int i = list.Count - 1; i >= 0; i--) { bool okay = true; for (int j = 0; j < T.Length; j++) { if (Sdash[list[i] + j] != '?' && Sdash[list[i] + j] != T[j]) { okay = false; } } if (okay) { ans = true; ansplace = list[i]; break; } } if (ans) { for (int i = 0; i < Sdash.Length; i++) { if (i < ansplace && Sdash[i] == '?') { Sdash[i] = 'a'; } else if (ansplace <= i && i < ansplace + T.Length) { Sdash[i] = T[i - ansplace]; } else if (Sdash[i] == '?') { Sdash[i] = 'a'; } } Console.WriteLine(Sdash); } else { Console.WriteLine("UNRESTORABLE"); } } }
[["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 104], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 253]]
8
343
9
using System; namespace kozaiyApp { public class dubiousDocument2 { static void Main(string[] args) { string ans = "UNRESTORABLE"; char[] S = Console.ReadLine().ToCharArray(); // 一部'?'の状態 char[] T = Console.ReadLine().ToCharArray(); if (S.Length < T.Length) { Console.WriteLine(ans); return; } // Sが7文字、Tが5文字の場合、iが2が最終回 for (int i = 0; i <= S.Length - T.Length; i++) { // S差替え済み if (ans == "SUCCESS") break; for (int j = 0; j < T.Length; j++) { if (S[j + i] == T[j] || S[j + i] == '?') { // Tの最後の一文字まで合致(j最終回) if (j == T.Length - 1) { // SをTに差替える for (int t = 0; t < T.Length; t++) { S[i + t] = T[t]; } ans = "SUCCESS"; } continue; // 続ける } else { break; // 抜ける } } } // Tが合致しなかったので終了 if (ans == "UNRESTORABLE") { Console.WriteLine(ans); return; } // Sの'?'を'a'に差替え for (int i = 0; i < S.Length; i++) { if (S[i] == '?') { S[i] = 'a'; } } ans = string.Join("", S); Console.WriteLine(ans); } } }
using System; namespace kozaiyApp { public class dubiousDocument2 { static void Main(string[] args) { string ans = "UNRESTORABLE"; char[] S = Console.ReadLine().ToCharArray(); // 一部'?'の状態 char[] T = Console.ReadLine().ToCharArray(); if (S.Length < T.Length) { Console.WriteLine(ans); return; } // Sが7文字、Tが5文字の場合、i=2からはじまり、i=0まで for (int i = S.Length - T.Length; i >= 0; i--) { // S差替え済み if (ans == "SUCCESS") break; for (int j = 0; j < T.Length; j++) { if (S[j + i] == T[j] || S[j + i] == '?') { // Tの最後の一文字まで合致(j最終回) if (j == T.Length - 1) { // SをTに差替える for (int t = 0; t < T.Length; t++) { S[i + t] = T[t]; } ans = "SUCCESS"; } continue; // 続ける } else { break; // 抜ける } } } // Tが合致しなかったので終了 if (ans == "UNRESTORABLE") { Console.WriteLine(ans); return; } // Sの'?'を'a'に差替え for (int i = 0; i < S.Length; i++) { if (S[i] == '?') { S[i] = 'a'; } } ans = string.Join("", S); Console.WriteLine(ans); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
300
10
//参考1:char<=>string //https://qiita.com/shusakuorz/items/d24bd33ff7ea0c2b0024 //参考2:.Replaceメソッド https://www.sejuku.net/blog/47953 using System; public class ABC76C { public static int index_key; public static bool isMatch(string ss, string tt) { int i, j; for (i = 0; i < (ss.Length - tt.Length + 1); i++) { //~~~~~~ for (j = 0; j < tt.Length; j++) { if (ss[i + j] != tt[j] && ss[i + j] != '?') { break; } } if (j == tt.Length) { index_key = i; return true; } } //~~~~~~ return false; } public static string restoration(string ss, string tt) { String ss_a = ss.Replace("?", "a"); //?をaに置き換える // for(int i = 0; i < ss.Length ; i++){ // if(ss[i] == '?'){ // ss[i] = 'a'; //これはエラー // } //} char[] cs = ss_a.ToCharArray(); char[] ct = tt.ToCharArray(); for (int i = 0; i < tt.Length; i++) { cs[i + index_key] = ct[i]; } string cnt = new String(cs); return cnt; } public static void Main() { string s = Console.ReadLine(); string t = Console.ReadLine(); if (!isMatch(s, t)) { Console.WriteLine("UNRESTORABLE"); } else { Console.WriteLine(restoration(s, t)); } } }
//参考1:char<=>string //https://qiita.com/shusakuorz/items/d24bd33ff7ea0c2b0024 //参考2:.Replaceメソッド https://www.sejuku.net/blog/47953 using System; public class ABC76C { public static int index_key; public static bool isMatch(string ss, string tt) { int i, j; index_key = -1; for (i = 0; i < (ss.Length - tt.Length + 1); i++) { //~~~~~~ for (j = 0; j < tt.Length; j++) { if (ss[i + j] != tt[j] && ss[i + j] != '?') { break; } } if (j == tt.Length) { index_key = i; } } //~~~~~~ if (index_key != -1) { return true; } return false; } public static string restoration(string ss, string tt) { String ss_a = ss.Replace("?", "a"); //?をaに置き換える // for(int i = 0; i < ss.Length ; i++){ // if(ss[i] == '?'){ // ss[i] = 'a'; //これはエラー // } //} char[] cs = ss_a.ToCharArray(); char[] ct = tt.ToCharArray(); for (int i = 0; i < tt.Length; i++) { cs[i + index_key] = ct[i]; } string cnt = new String(cs); return cnt; } public static void Main() { string s = Console.ReadLine(); string t = Console.ReadLine(); if (!isMatch(s, t)) { Console.WriteLine("UNRESTORABLE"); } else { Console.WriteLine(restoration(s, t)); } } }
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
288
16
using System; using System.Collections.Generic; using System.Linq; namespace abc076_c { class Program { static void Main(string[] args) { var S = GetStr(); var T = GetStr(); var ri = new List<int>(); for (int i = 0; i < S.Length - T.Length + 1; i++) { int c = 0; for (int j = 0; j < T.Length; j++) if (S[i + j] == T[j] || S[i + j] == '?') c++; if (c == T.Length) ri.Add(i); } if (ri.Count == 0) Console.WriteLine("UNRESTORABLE"); else { var rl = new List<string>(); foreach (var rii in ri) { string r = ""; for (int i = 0; i < S.Length; i++) { if (rii == i) { r += T; i += T.Length; } else if (S[i] == '?') r += "a"; else r += S[i]; } rl.Add(r); } Console.WriteLine(rl.OrderBy(x => x).First()); } } public static string GetStr() => Console.ReadLine(); public static int GetInt() => int.Parse(Console.ReadLine()); public static long GetLong() => long.Parse(Console.ReadLine()); public static double GetDouble() => double.Parse(Console.ReadLine()); public static decimal GetDecimal() => decimal.Parse(Console.ReadLine()); public static List<string> GetStrList() => Console.ReadLine().Split(' ').ToList(); public static List<int> GetIntList() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); public static List<long> GetLongList() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); public static List<double> GetDoubleList() => Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList(); public static List<decimal> GetDecimalList() => Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList(); } }
using System; using System.Collections.Generic; using System.Linq; namespace abc076_c { class Program { static void Main(string[] args) { var S = GetStr(); var T = GetStr(); var ri = new List<int>(); if (S.Length < T.Length) { Console.WriteLine("UNRESTORABLE"); return; } for (int i = 0; i < S.Length - T.Length + 1; i++) { int c = 0; for (int j = 0; j < T.Length; j++) if (S[i + j] == T[j] || S[i + j] == '?') c++; if (c == T.Length) ri.Add(i); } if (ri.Count == 0) { Console.WriteLine("UNRESTORABLE"); return; } var rl = new List<string>(); foreach (var rii in ri) { string r = ""; for (int i = 0; i < S.Length; i++) { if (rii == i) { r += T; i += T.Length - 1; } else if (S[i] == '?') r += "a"; else r += S[i]; } rl.Add(r); } Console.WriteLine(rl.OrderBy(x => x).First()); } public static string GetStr() => Console.ReadLine(); public static int GetInt() => int.Parse(Console.ReadLine()); public static long GetLong() => long.Parse(Console.ReadLine()); public static double GetDouble() => double.Parse(Console.ReadLine()); public static decimal GetDecimal() => decimal.Parse(Console.ReadLine()); public static List<string> GetStrList() => Console.ReadLine().Split(' ').ToList(); public static List<int> GetIntList() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); public static List<long> GetLongList() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); public static List<double> GetDoubleList() => Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList(); public static List<decimal> GetDecimalList() => Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList(); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
548
32
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; using ll = System.Int64; public class Contest { static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) Swap1(ref a, ref b); } // b の方が小さければ交換 static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } // b の方が大きければ a を更新 static T[][] InitMat<T>(long len1, long len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; } static T[][][] InitMat<T>(long len1, long len2, long len3, T val) { T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2, len3, val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public static void Main() { Solve_A(); } public static void Solve_A() { string ss, t; MyIO.ReadMulti(out ss); MyIO.ReadMulti(out t); StringBuilder s = new StringBuilder(ss); for (int i = 0; i < s.Length; i++) { if ((s[i] == t[0] || s[i] == '?') && i + t.Length <= s.Length) { bool c = true; for (int j = 1; j < t.Length; j++) { if (!(s[i + j] == t[j] || s[i + j] == '?')) { c = false; break; } } if (c) { for (int j = 0; j < t.Length; j++) { if (s[i + j] == '?') s[i + j] = t[j]; } } } } for (int i = 0; i < s.Length; i++) { if (s[i] == '?') s[i] = 'a'; } MyIO.WriteMulti(0 <= s.ToString().IndexOf(t) ? s.ToString() : "UNRESTORABLE"); } public static void Solve_B() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_C() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_D() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_E() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_F() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } } #region MyIO public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(long n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(long n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; using ll = System.Int64; public class Contest { static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) Swap1(ref a, ref b); } // b の方が小さければ交換 static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } // b の方が大きければ a を更新 static T[][] InitMat<T>(long len1, long len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; } static T[][][] InitMat<T>(long len1, long len2, long len3, T val) { T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2, len3, val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public static void Main() { Solve_A(); } public static void Solve_A() { string ss, t; MyIO.ReadMulti(out ss); MyIO.ReadMulti(out t); StringBuilder s = new StringBuilder(ss); if (ss.IndexOf(t) < 0) { for (int i = s.Length - t.Length; 0 <= i; i--) { if (s[i] == t[0] || s[i] == '?') { bool c = true; for (int j = 1; j < t.Length; j++) { if (!(s[i + j] == t[j] || s[i + j] == '?')) { c = false; break; } } if (c) { for (int j = 0; j < t.Length; j++) { if (s[i + j] == '?') s[i + j] = t[j]; } break; } } } } for (int i = 0; i < s.Length; i++) { if (s[i] == '?') s[i] = 'a'; } MyIO.WriteMulti(0 <= s.ToString().IndexOf(t) ? s.ToString() : "UNRESTORABLE"); } public static void Solve_B() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_C() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_D() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_E() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_F() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } } #region MyIO public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(long n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(long n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } } #endregion
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 15, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 12, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 16, 12, 214, 141, 22], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 31, 203], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 35], ["+", 0, 57, 64, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 7, 26, 223, 0, 68], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 72], ["-", 15, 16, 12, 16, 31, 16, 12, 214, 205, 22], ["-", 15, 16, 12, 16, 31, 16, 12, 214, 0, 131], ["-", 15, 16, 12, 16, 31, 16, 12, 214, 141, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 16, 12, 16, 12, 214, 205, 22], ["-", 0, 57, 15, 16, 12, 16, 12, 214, 0, 131], ["-", 0, 57, 15, 16, 12, 16, 12, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
8
2,600
41
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; namespace UtakaApp { public partial class Program { //========================================================================================= // Answer //========================================================================================= public const string SiteName = "AtCoder"; public const string ContestName = "abc076"; public const string ProblemName = "C"; public void Solve() { string S = cin.Read; string T = cin.Read; int N = S.Length; for (int i = N - T.Length; i >= 0; i--) { bool isOk = true; for (int j = 0; j < T.Length; j++) { int index = i + j; if (S[index] == '?') { continue; } if (S[index] == T[j]) { continue; } isOk = false; break; } if (isOk) { char[] chars = S.ToCharArray(); for (int j = 0; j < N - j - T.Length; j++) { int index = i + j; chars[index] = T[j]; } for (int j = 0; j < N; j++) { if (chars[j] == '?') { if (i <= j && j < i + T.Length) { int index = j - i; chars[j] = T[index]; } else { chars[j] = 'a'; } } } string ans = new string(chars); cou.WriteLine(ans); return; } } cou.WriteLine("UNRESTORABLE"); } } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } //========================================================================================= // Library //========================================================================================= /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[,] Array2D<T>(int a, int b) where T : struct { var ret = new T[a, b]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = Enumerable.Repeat(defaultValue, b).ToArray(); } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; if (targetTestCaseNumber >= 0 && targetTestCaseNumber != testCaseNumber) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif #if UTAKA_LOCAL public static class Dbg { public static void WriteLine(string str) { Console.WriteLine(str); } public static void Write(string str) { Console.Write(str); } } #else public static class Dbg { public static void WriteLine(string str) {} public static void Write(string str) {} } #endif }
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; namespace UtakaApp { public partial class Program { //========================================================================================= // Answer //========================================================================================= public const string SiteName = "AtCoder"; public const string ContestName = "abc076"; public const string ProblemName = "C"; public void Solve() { string S = cin.Read; string T = cin.Read; int N = S.Length; for (int i = N - T.Length; i >= 0; i--) { bool isOk = true; for (int j = 0; j < T.Length; j++) { int index = i + j; if (S[index] == '?') { continue; } if (S[index] == T[j]) { continue; } isOk = false; break; } if (isOk) { char[] chars = S.ToCharArray(); for (int j = 0; j < T.Length; j++) { int index = i + j; chars[index] = T[j]; } for (int j = 0; j < N; j++) { if (chars[j] == '?') { // if (i <= j && j < i + T.Length) // { // int index = j - i; // chars[j] = T[index]; // } // else { chars[j] = 'a'; } } } string ans = new string(chars); cou.WriteLine(ans); return; } } cou.WriteLine("UNRESTORABLE"); } } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } //========================================================================================= // Library //========================================================================================= /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[,] Array2D<T>(int a, int b) where T : struct { var ret = new T[a, b]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = Enumerable.Repeat(defaultValue, b).ToArray(); } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; if (targetTestCaseNumber >= 0 && targetTestCaseNumber != testCaseNumber) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif #if UTAKA_LOCAL public static class Dbg { public static void WriteLine(string str) { Console.WriteLine(str); } public static void Write(string str) { Console.Write(str); } } #else public static class Dbg { public static void WriteLine(string str) {} public static void Write(string str) {} } #endif }
[["-", 0, 7, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 7, 15, 16, 12, 16, 31, 16, 17, 33], ["-", 0, 7, 15, 16, 12, 16, 31, 16, 12, 22], ["-", 64, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 64, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["-", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 64, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 17, 72], ["-", 15, 16, 12, 16, 12, 16, 12, 214, 205, 22], ["-", 15, 16, 12, 16, 12, 16, 12, 214, 0, 131], ["-", 15, 16, 12, 16, 12, 16, 12, 214, 141, 22], ["-", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["-", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 64, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["-", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95]]
8
2,006
38
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static string S; static string T; static void INPUT() { S = NextString(); T = NextString(); } static void OUT() { var t = T.ToCharArray(); for (var idx = 0; idx <= S.Length - T.Length; idx++) { var ca = S.Substring(idx).ToCharArray(); var b = true; for (var i = 0; i < t.Length; i++) { if (ca[i] != '?' && t[i] != ca[i]) { b = false; break; } } if (b) { Console.WriteLine(S.Substring(0, idx).Replace('?', 'a') + T + S.Substring(idx + T.Length).Replace('?', 'a')); return; } } Console.WriteLine("UNRESTORABLE"); } static void Main(string[] args) { #if DEBUG TESTINPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() { S = "?tc????"; T = "coder"; } } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static string S; static string T; static void INPUT() { S = NextString(); T = NextString(); } static void OUT() { var t = T.ToCharArray(); for (var idx = S.Length - T.Length; idx >= 0; idx--) { var ca = S.Substring(idx).ToCharArray(); var b = true; for (var i = 0; i < t.Length; i++) { if (ca[i] != '?' && t[i] != ca[i]) { b = false; break; } } if (b) { Console.WriteLine(S.Substring(0, idx).Replace('?', 'a') + T + S.Substring(idx + T.Length).Replace('?', 'a')); return; } } Console.WriteLine("UNRESTORABLE"); } static void Main(string[] args) { #if DEBUG TESTINPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() { S = "?tc????tc????"; T = "coder"; } } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68], ["-", 8, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
594
12
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace ConsoleApp1 { class Program { static void Main(string[] args) { A(); } static void A() { var s = Read().ToArray(); var T = Read().ToArray(); for (var i = 0; i <= s.Length - T.Length; i++) { var f = true; for (var j = 0; j < T.Length; j++) { if (s[i + j] != '?' && s[i + j] != T[j]) { f = false; break; } } if (!f) continue; for (var a = 0; a < T.Length; a++) { s[i + a] = T[a]; } Println(Join(s).Replace('?', 'a')); return; } Println("UNRESTORABLE"); } static List<long> ReadLines(long n) { var l = new List<long>(); for (long i = 0; i < n; i++) { l.Add(ReadLong()); } return l; } static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int SumDigits(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b); static long Lcm(long a, long b) => a / Gcd(a, b) * b; static bool IsPrime(int x) { if (x <= 1 || (x != 2 && x % 2 == 0)) return false; if (x == 2) return true; for (int i = 3; i < x; i += 2) if (x % i == 0) return false; return true; } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static List<string> ReadSplit() => Read().Split().ToList(); static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList(); static void Print(object value) => Console.Write(value.ToString()); static void Println(object value) => Console.WriteLine(value.ToString()); static string Join<T>(IEnumerable<T> list) => string.Join("", list); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace ConsoleApp1 { class Program { static void Main(string[] args) { A(); } static void A() { var s = Read().ToArray(); var T = Read().ToArray(); var k = -1; for (var i = 0; i <= s.Length - T.Length; i++) { var f = true; for (var j = 0; j < T.Length; j++) { if (s[i + j] != '?' && s[i + j] != T[j]) { f = false; break; } } if (f) k = i; } if (k == -1) { Println("UNRESTORABLE"); return; } for (var a = 0; a < T.Length; a++) { s[k + a] = T[a]; } Println(Join(s).Replace('?', 'a')); } static List<long> ReadLines(long n) { var l = new List<long>(); for (long i = 0; i < n; i++) { l.Add(ReadLong()); } return l; } static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int SumDigits(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b); static long Lcm(long a, long b) => a / Gcd(a, b) * b; static bool IsPrime(int x) { if (x <= 1 || (x != 2 && x % 2 == 0)) return false; if (x == 2) return true; for (int i = 3; i < x; i += 2) if (x % i == 0) return false; return true; } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static List<string> ReadSplit() => Read().Split().ToList(); static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList(); static void Print(object value) => Console.Write(value.ToString()); static void Println(object value) => Console.WriteLine(value.ToString()); static string Join<T>(IEnumerable<T> list) => string.Join("", list); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 15, 241, 0, 111], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 7, 8, 196, 0, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
796
42
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC076C { class Program { static void Solve(Input input) { var s = input.Next(); var t = input.Next(); bool tContains = false; for (int i = 0; i < s.Length; i++) { bool restorable = false; for (int j = 0; j < t.Length; j++) { if (i + j >= s.Length) { restorable = false; break; } if (s[i + j] == '?') continue; if (s[i + j] != t[j]) { restorable = false; break; } // 全部?ははじきたいので、ここでセットする restorable = true; } if (restorable) { s = s.Replace(s.Substring(i, t.Length), t); tContains = true; } } if (tContains) { s = s.Replace('?', 'a'); } else { s = "UNRESTORABLE"; } Console.WriteLine(s); } #region Competitive Template static readonly int MOD = (int)1e9 + 7; public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; Queue<string> q { get; set; } StreamReader sr; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> /// <param name="path"></param> public Input(string path = "") { q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { return ""; } } return q.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> /// <param name="n"></param> /// <returns></returns> bool accumulate(int n) { while (q.Count() < n) { if (!read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="n"></param> /// <param name="offset"></param> /// <param name="parse"></param> /// <param name="add"></param> /// <returns></returns> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(q.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="v"></param> /// <returns></returns> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="v"></param> /// <returns></returns> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC076C { class Program { static void Solve(Input input) { var s = input.Next(); var t = input.Next(); bool tContains = false; for (int i = s.Length - t.Length; i >= 0; i--) { bool restorable = true; for (int j = 0; j < t.Length; j++) { if (i + j >= s.Length) { restorable = false; break; } if (s[i + j] == '?') continue; if (s[i + j] != t[j]) { restorable = false; break; } } if (restorable) { s = s.Substring(0, i) + s.Substring(i).Replace(s.Substring(i, t.Length), t); tContains = true; break; } } if (tContains) { s = s.Replace('?', 'a'); } else { s = "UNRESTORABLE"; } Console.WriteLine(s); } #region Competitive Template static readonly int MOD = (int)1e9 + 7; public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; Queue<string> q { get; set; } StreamReader sr; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> /// <param name="path"></param> public Input(string path = "") { q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { return ""; } } return q.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> /// <param name="n"></param> /// <returns></returns> bool accumulate(int n) { while (q.Count() < n) { if (!read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="n"></param> /// <param name="offset"></param> /// <param name="parse"></param> /// <param name="add"></param> /// <returns></returns> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(q.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="v"></param> /// <returns></returns> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="v"></param> /// <returns></returns> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 12, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 16, 12, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68], ["-", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 146], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 11, 12, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 11, 12, 16, 31, 213, 3, 4, 0, 21], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 16, 31, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
8
1,305
36
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; public static partial class Program { public static void Main() { var s = CRL(); var t = CRL(); const string unres = "UNRESTORABLE"; if (s.Length < t.Length) { CWL(unres); return; } for (int sIdx = 0; sIdx <= s.Length - t.Length; sIdx++) { var sb = new StringBuilder(s); var conf = false; for (int tIdx = 0; tIdx < t.Length; tIdx++) { if (s[sIdx + tIdx] == '?') { sb[sIdx + tIdx] = t[tIdx]; continue; } if (s[sIdx + tIdx] != t[tIdx]) { conf = true; break; } } if (conf) { continue; } CWL(sb.ToString().Replace("?", "a")); return; } CWL(unres); } } public static partial class Program { //テンプレここから private static long ToInt(this string str) => long.Parse(str); private static long[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray(); public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToInt(); public static string CRL() => Console.ReadLine(); public static void CWL(object obj) => Console.WriteLine(obj); public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b)); public static long Sign(this long i) => Math.Sign(i); public static bool IsEven(this long i) => i % 2 == 0; public static bool IsEven(this int i) => i % 2 == 0; public static long[] dx = new long[] { 0, -1, 0, 1 }; public static long[] dy = new long[] { -1, 0, 1, 0 }; public static long mod = 1000000007; public static string alphabet = "abcdefghijklmnopqrstuvwxyz"; public static long ToLong(this char c) => c.ToString().ToInt(); //テンプレここまで }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; public static partial class Program { public static void Main() { var s = CRL(); var t = CRL(); const string unres = "UNRESTORABLE"; if (s.Length < t.Length) { CWL(unres); return; } for (int sIdx = s.Length - t.Length; sIdx >= 0; sIdx--) { var sb = new StringBuilder(s); var conf = false; for (int tIdx = 0; tIdx < t.Length; tIdx++) { if (s[sIdx + tIdx] == '?') { sb[sIdx + tIdx] = t[tIdx]; continue; } if (s[sIdx + tIdx] != t[tIdx]) { conf = true; break; } } if (conf) { continue; } CWL(sb.ToString().Replace("?", "a")); return; } CWL(unres); } } public static partial class Program { //テンプレここから private static long ToInt(this string str) => long.Parse(str); private static long[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray(); public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToInt(); public static string CRL() => Console.ReadLine(); public static void CWL(object obj) => Console.WriteLine(obj); public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b)); public static long Sign(this long i) => Math.Sign(i); public static bool IsEven(this long i) => i % 2 == 0; public static bool IsEven(this int i) => i % 2 == 0; public static long[] dx = new long[] { 0, -1, 0, 1 }; public static long[] dy = new long[] { -1, 0, 1, 0 }; public static long mod = 1000000007; public static string alphabet = "abcdefghijklmnopqrstuvwxyz"; public static long ToLong(this char c) => c.ToString().ToInt(); //テンプレここまで }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
504
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { #region C問題 // var data = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var t = data[0]; // var s = data[1]; // int[,] friens = new int[t, t]; // int tomo = 0; // for (int i = 0; i < s; i++) // { // var friend = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // friens[friend[0] - 1, friend[1] - 1] = 1; // friens[friend[1] - 1, friend[0] - 1] = 1; // } // for (int i = 0; i < t; i++) // { // var x = new List<int>(); // var y = new List<int>(); // var a = new List<int>(); // for (int j = 0; j < t; j++) // { // if (friens[i, j] == 1) // { // x.Add(j); // } // } // foreach (var z in x) // { // for (int l = 0; l < t; l++) // { // if (friens[z, l] == 1) // { // y.Add(l); // } // } // foreach (var m in y) // { // if (m != i && friens[m, i] != 1) // { // a.Add(m); // } // } // } // Console.WriteLine(a.Distinct().Count()); // } // var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var b = a[0]; // var c = a[1]; // int[] d = new int[b]; // int[] e = new int[b]; // int[] f = new int[b]; // int tmp = 0; // int tokuten = 0; // for (int i = 0; i < b; i++) // { // var g = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // d[i] = g[0]; // e[i] = g[1]; // f[i] = g[2]; // } // for (int j = 1; j <= c; j++) // { // for (int k = 0; k < b; k++) // { // if (d[k] <= j && e[k] >= j) // { // } // else // { // tmp += f[k]; // } // } // tokuten = Math.Max(tokuten ,tmp); // tmp = 0; // } // Console.WriteLine(tokuten); // var a = int.Parse(Console.ReadLine()); // var b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // Dictionary<int,int> c = new Dictionary<int,int>(); // int d = 0; // int cnt = 0; ////for (int i = 0; i < a; i++) ////{ //// c.Add(b[i], 1); ////} // for (int i = 0; i < a; i++) //{ // d = b[i]; // while (d % 2 == 0) // { // d /= 2; // } // if (c.ContainsKey(d)) // { // } // else // { // c.Add(d, 1); // cnt++; // } //} // Console.WriteLine(cnt); // var one = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // var N = one[0]; // var M = one[1]; // List<int[]> ID= new List<int[]>(); // List<string> Out = new List<string>(); // int cnt = 1; // long now = -1; // for (int i = 0; i < M; i++) //{ // var morethanone = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // ID.Add(morethanone); //} // var sortedID = ID.OrderBy(data => data[0]).ThenBy(data => data[1]); // var Rank = new Dictionary<string, int>(); // foreach (var item in sortedID) //{ // if (now != -1 && item[0] != now) // { // cnt = 1; // } // now = item[0]; // Rank.Add(item[0].ToString() + item[1].ToString(), cnt); // cnt++; //} // for (int i = 0; i < M; i++) //{ // var tmp = ID[i]; // string key = tmp[0].ToString() + tmp[1].ToString(); // string Output = tmp[0].ToString().PadLeft(6, '0') + // Rank[key].ToString().PadLeft(6, '0'); Console.WriteLine(Output); //} // var N = int.Parse(Console.ReadLine()); // List<int[]> Z = new List<int[]>(); // List<int[]> dis = new List<int[]>(); // int X = 0; // int Y = 0; // int H = 0; // for (int i = 0; i < N; i++) //{ // var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // Z.Add(line); //} // row // for (int i = 0; i < N; i++) //{ // var linedata = Z[i]; // //height // for (int j = 0; j < 201; j++) // { // //x // for (int k = 0; k < 101; k++) // { // for (int l = 0; l < 101; l++) // { // if ((j + linedata[2]) - Math.Abs(k - linedata[0]) - Math.Abs(l // - linedata[1]) == linedata[2]) // { // X = k; // Y = l; // H = j; // dis.Add(new {x = X,y =Y, h =H}); // } // } // } // } //} // var a = dis.GroupBy(n => n) // var b = a.OrderByDescending(n => n.cnt); // var a = Console.ReadLine().ToCharArray(); // var b = Console.ReadLine().ToCharArray(); ////char[] c = new char[a.Count()]; ////char[] d = new char[a.Count()]; // var c = new Dictionary<char, char>(); // var d = new Dictionary<char, char>(); // for (int i = 0; i < a.Count(); i++) //{ // if (!c.ContainsKey(a[i])) // { // c.Add(a[i], b[i]); // } // else if (c[a[i]] != b[i]) // { // Console.WriteLine("No"); // return; // } //} // for (int i = 0; i < b.Count(); i++) //{ // if (!d.ContainsKey(b[i])) // { // d.Add(b[i], a[i]); // } // else if (d[b[i]] != a[i]) // { // Console.WriteLine("No"); // return; // } //} // Console.WriteLine("Yes"); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int min = int.MaxValue; // int min2 = int.MaxValue; // int amari = int.MaxValue; // for (int i = 0; i < line1[0]; i++) //{ // if (Math.Abs(line2[i]-line1[1]) <= min) // { // min2 = min; // min = Math.Abs(line2[i] - line1[1]); // } // else if (Math.Abs(line2[i] - line1[1]) < min2) // { // min2 = Math.Abs(line2[i] - line1[1]); // } //} // if (min2 != int.MaxValue) //{ // while (amari != 0) // { // amari = min2 % min; // min2 = min; // min = amari; // } // Console.WriteLine(min2); //} // else //{ // Console.WriteLine(min); //} // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int N = line1[0]; // int K = line1[1]; // int Kgaguu = 0; // int amari0 = 0; // for (int i = 1; i <= N; i++) //{ // if (i % K == 0) // { // amari0++; // } // else if (K % 2 == 0 && i % K == K /2) // { // Kgaguu++; // } //} // Console.WriteLine(amari0 * amari0 * amari0 + Kgaguu * Kgaguu * Kgaguu); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int N = line1[0]; // int K = line1[1]; // var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // long mintmp = int.MaxValue; // long min = int.MaxValue; // for (int i = 0; i < N-K+1; i++) //{ // var left = line2[i]; // var right = line2[i + K - 1]; // mintmp = Math.Min(Math.Min(Math.Abs(left) + Math.Abs(right - left), min), // Math.Abs(right) + Math.Abs(left - right)); // min = Math.Min(mintmp, min); //} ////for (int i = 0; i < N; i++) ////{ //// if (i != 0 || i != N-1) //// { //// var tmp = new node(); //// tmp._to1 = line2[i - 1]; //// tmp._to2 = line2[i + 1]; //// tmp.me = line2[i]; //// tmp.flg = false; //// node.Add(tmp); //// } ////} // Console.WriteLine(min); // var S = Console.ReadLine().ToCharArray(); // var K = decimal.Parse(Console.ReadLine()); // int cnt = 0; // bool ren = false; // int ans = 0; // for (int i = 0; i < S.Count(); i++) //{ // if (i == 0 && int.Parse(S[i].ToString()) == 1) // { // ren = true; // cnt++; // continue; // } // if (ren && int.Parse(S[i].ToString()) == 1) // { // ren = true; // cnt++; // continue; // } // if (int.Parse(S[i].ToString()) != 1) // { // ans = int.Parse(S[i].ToString()); // break; // } //} // if (cnt >= K) //{ // Console.WriteLine(1); //} // else //{ // Console.WriteLine(ans); //} // Console.WriteLine(1 % -2); // int input = int.Parse(Console.ReadLine()); // for (int i = 0; i < input; i++) //{ // Console.WriteLine("Hello"); //} // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int N = line1[0]; // int M = line1[1]; // int[] tree = new int[N]; // int min = int.MaxValue; // for (int i = 0; i < N; i++) //{ // tree[i] = int.Parse(Console.ReadLine()); //} // var sortedTree = tree.OrderBy(n => n).ToArray(); // for (int i = 0; i < N - K + 1; i++) //{ // min = Math.Min(sortedTree[i + K -1] - sortedTree[i], min); //} // Console.WriteLine(min); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int N = line1[0]; // int M = line1[1]; // var time1 = 1/Math.Pow(0.5, M); // var time2 = 100 * (N - M) * time1; // Console.WriteLine(time1 * 1900 * M + time2); // var N = int.Parse(Console.ReadLine()); // var A = Array.ConvertAll(Console.ReadLine().Split(), long.Parse).OrderBy(n => // n).ToArray(); var B = Array.ConvertAll(Console.ReadLine().Split(), // long.Parse).OrderBy(n => n).ToArray(); var C = // Array.ConvertAll(Console.ReadLine().Split(), long.Parse).OrderBy(n => // n).ToArray(); // long x = 0; // for (int i = 0; i < N; i++) //{ // var a = LowerBound(A, B[i]); // var b = N - UpperBound(C, B[i]); // x += a * b; //} // Console.WriteLine(x); #endregion var S = Console.ReadLine().ToArray(); var T = Console.ReadLine().ToCharArray(); var N = S.Length - 1; var K = T.Length - 1; int cnt; bool flg = false; for (int i = 0; i < N - K + 1; i++) { cnt = 0; for (int j = i; j <= i + K; j++) { if (S[j] == '?' || S[j] == T[j - i]) { cnt++; } } if (cnt == K + 1) { for (int j = i; j <= i + K; j++) { S[j] = T[j - i]; flg = true; } } } for (int i = 0; i < N + 1; i++) { if (S[i] == '?') { S[i] = 'a'; } } if (flg) { var st = new string(S); Console.WriteLine(st); } else { Console.WriteLine("UNRESTORABLE"); } } public static long LowerBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static long UpperBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { #region C問題 // var data = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var t = data[0]; // var s = data[1]; // int[,] friens = new int[t, t]; // int tomo = 0; // for (int i = 0; i < s; i++) // { // var friend = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // friens[friend[0] - 1, friend[1] - 1] = 1; // friens[friend[1] - 1, friend[0] - 1] = 1; // } // for (int i = 0; i < t; i++) // { // var x = new List<int>(); // var y = new List<int>(); // var a = new List<int>(); // for (int j = 0; j < t; j++) // { // if (friens[i, j] == 1) // { // x.Add(j); // } // } // foreach (var z in x) // { // for (int l = 0; l < t; l++) // { // if (friens[z, l] == 1) // { // y.Add(l); // } // } // foreach (var m in y) // { // if (m != i && friens[m, i] != 1) // { // a.Add(m); // } // } // } // Console.WriteLine(a.Distinct().Count()); // } // var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var b = a[0]; // var c = a[1]; // int[] d = new int[b]; // int[] e = new int[b]; // int[] f = new int[b]; // int tmp = 0; // int tokuten = 0; // for (int i = 0; i < b; i++) // { // var g = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // d[i] = g[0]; // e[i] = g[1]; // f[i] = g[2]; // } // for (int j = 1; j <= c; j++) // { // for (int k = 0; k < b; k++) // { // if (d[k] <= j && e[k] >= j) // { // } // else // { // tmp += f[k]; // } // } // tokuten = Math.Max(tokuten ,tmp); // tmp = 0; // } // Console.WriteLine(tokuten); // var a = int.Parse(Console.ReadLine()); // var b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // Dictionary<int,int> c = new Dictionary<int,int>(); // int d = 0; // int cnt = 0; ////for (int i = 0; i < a; i++) ////{ //// c.Add(b[i], 1); ////} // for (int i = 0; i < a; i++) //{ // d = b[i]; // while (d % 2 == 0) // { // d /= 2; // } // if (c.ContainsKey(d)) // { // } // else // { // c.Add(d, 1); // cnt++; // } //} // Console.WriteLine(cnt); // var one = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // var N = one[0]; // var M = one[1]; // List<int[]> ID= new List<int[]>(); // List<string> Out = new List<string>(); // int cnt = 1; // long now = -1; // for (int i = 0; i < M; i++) //{ // var morethanone = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // ID.Add(morethanone); //} // var sortedID = ID.OrderBy(data => data[0]).ThenBy(data => data[1]); // var Rank = new Dictionary<string, int>(); // foreach (var item in sortedID) //{ // if (now != -1 && item[0] != now) // { // cnt = 1; // } // now = item[0]; // Rank.Add(item[0].ToString() + item[1].ToString(), cnt); // cnt++; //} // for (int i = 0; i < M; i++) //{ // var tmp = ID[i]; // string key = tmp[0].ToString() + tmp[1].ToString(); // string Output = tmp[0].ToString().PadLeft(6, '0') + // Rank[key].ToString().PadLeft(6, '0'); Console.WriteLine(Output); //} // var N = int.Parse(Console.ReadLine()); // List<int[]> Z = new List<int[]>(); // List<int[]> dis = new List<int[]>(); // int X = 0; // int Y = 0; // int H = 0; // for (int i = 0; i < N; i++) //{ // var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // Z.Add(line); //} // row // for (int i = 0; i < N; i++) //{ // var linedata = Z[i]; // //height // for (int j = 0; j < 201; j++) // { // //x // for (int k = 0; k < 101; k++) // { // for (int l = 0; l < 101; l++) // { // if ((j + linedata[2]) - Math.Abs(k - linedata[0]) - Math.Abs(l // - linedata[1]) == linedata[2]) // { // X = k; // Y = l; // H = j; // dis.Add(new {x = X,y =Y, h =H}); // } // } // } // } //} // var a = dis.GroupBy(n => n) // var b = a.OrderByDescending(n => n.cnt); // var a = Console.ReadLine().ToCharArray(); // var b = Console.ReadLine().ToCharArray(); ////char[] c = new char[a.Count()]; ////char[] d = new char[a.Count()]; // var c = new Dictionary<char, char>(); // var d = new Dictionary<char, char>(); // for (int i = 0; i < a.Count(); i++) //{ // if (!c.ContainsKey(a[i])) // { // c.Add(a[i], b[i]); // } // else if (c[a[i]] != b[i]) // { // Console.WriteLine("No"); // return; // } //} // for (int i = 0; i < b.Count(); i++) //{ // if (!d.ContainsKey(b[i])) // { // d.Add(b[i], a[i]); // } // else if (d[b[i]] != a[i]) // { // Console.WriteLine("No"); // return; // } //} // Console.WriteLine("Yes"); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int min = int.MaxValue; // int min2 = int.MaxValue; // int amari = int.MaxValue; // for (int i = 0; i < line1[0]; i++) //{ // if (Math.Abs(line2[i]-line1[1]) <= min) // { // min2 = min; // min = Math.Abs(line2[i] - line1[1]); // } // else if (Math.Abs(line2[i] - line1[1]) < min2) // { // min2 = Math.Abs(line2[i] - line1[1]); // } //} // if (min2 != int.MaxValue) //{ // while (amari != 0) // { // amari = min2 % min; // min2 = min; // min = amari; // } // Console.WriteLine(min2); //} // else //{ // Console.WriteLine(min); //} // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int N = line1[0]; // int K = line1[1]; // int Kgaguu = 0; // int amari0 = 0; // for (int i = 1; i <= N; i++) //{ // if (i % K == 0) // { // amari0++; // } // else if (K % 2 == 0 && i % K == K /2) // { // Kgaguu++; // } //} // Console.WriteLine(amari0 * amari0 * amari0 + Kgaguu * Kgaguu * Kgaguu); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int N = line1[0]; // int K = line1[1]; // var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // long mintmp = int.MaxValue; // long min = int.MaxValue; // for (int i = 0; i < N-K+1; i++) //{ // var left = line2[i]; // var right = line2[i + K - 1]; // mintmp = Math.Min(Math.Min(Math.Abs(left) + Math.Abs(right - left), min), // Math.Abs(right) + Math.Abs(left - right)); // min = Math.Min(mintmp, min); //} ////for (int i = 0; i < N; i++) ////{ //// if (i != 0 || i != N-1) //// { //// var tmp = new node(); //// tmp._to1 = line2[i - 1]; //// tmp._to2 = line2[i + 1]; //// tmp.me = line2[i]; //// tmp.flg = false; //// node.Add(tmp); //// } ////} // Console.WriteLine(min); // var S = Console.ReadLine().ToCharArray(); // var K = decimal.Parse(Console.ReadLine()); // int cnt = 0; // bool ren = false; // int ans = 0; // for (int i = 0; i < S.Count(); i++) //{ // if (i == 0 && int.Parse(S[i].ToString()) == 1) // { // ren = true; // cnt++; // continue; // } // if (ren && int.Parse(S[i].ToString()) == 1) // { // ren = true; // cnt++; // continue; // } // if (int.Parse(S[i].ToString()) != 1) // { // ans = int.Parse(S[i].ToString()); // break; // } //} // if (cnt >= K) //{ // Console.WriteLine(1); //} // else //{ // Console.WriteLine(ans); //} // Console.WriteLine(1 % -2); // int input = int.Parse(Console.ReadLine()); // for (int i = 0; i < input; i++) //{ // Console.WriteLine("Hello"); //} // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int N = line1[0]; // int M = line1[1]; // int[] tree = new int[N]; // int min = int.MaxValue; // for (int i = 0; i < N; i++) //{ // tree[i] = int.Parse(Console.ReadLine()); //} // var sortedTree = tree.OrderBy(n => n).ToArray(); // for (int i = 0; i < N - K + 1; i++) //{ // min = Math.Min(sortedTree[i + K -1] - sortedTree[i], min); //} // Console.WriteLine(min); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int N = line1[0]; // int M = line1[1]; // var time1 = 1/Math.Pow(0.5, M); // var time2 = 100 * (N - M) * time1; // Console.WriteLine(time1 * 1900 * M + time2); // var N = int.Parse(Console.ReadLine()); // var A = Array.ConvertAll(Console.ReadLine().Split(), long.Parse).OrderBy(n => // n).ToArray(); var B = Array.ConvertAll(Console.ReadLine().Split(), // long.Parse).OrderBy(n => n).ToArray(); var C = // Array.ConvertAll(Console.ReadLine().Split(), long.Parse).OrderBy(n => // n).ToArray(); // long x = 0; // for (int i = 0; i < N; i++) //{ // var a = LowerBound(A, B[i]); // var b = N - UpperBound(C, B[i]); // x += a * b; //} // Console.WriteLine(x); #endregion var S = Console.ReadLine().ToCharArray().Reverse().ToArray(); var T = Console.ReadLine().ToCharArray().Reverse().ToArray(); var N = S.Length - 1; var K = T.Length - 1; int cnt; bool flg = false; for (int i = 0; i < N - K + 1; i++) { cnt = 0; for (int j = i; j <= i + K; j++) { if (S[j] == '?' || S[j] == T[j - i]) { cnt++; } } if (cnt == K + 1) { for (int j = i; j <= i + K; j++) { S[j] = T[j - i]; flg = true; } break; } } for (int i = 0; i < N + 1; i++) { if (S[i] == '?') { S[i] = 'a'; } } if (flg) { var st = new string(S.Reverse().ToArray()); Console.WriteLine(st); } else { Console.WriteLine("UNRESTORABLE"); } } public static long LowerBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static long UpperBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } } }
[["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 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
912
26
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { Scanner cin = new Scanner(); string S = Console.ReadLine(); string T = Console.ReadLine(); bool flag; for (int i = 0; i < S.Length - T.Length + 1; i++) { flag = true; for (int j = 0; j < T.Length; j++) { if (S[i + j] != T[j] && S[i + j] != '?') flag = false; } if (flag) { string ans = S.Substring(0, i) + T + S.Substring(i + T.Length); ans = ans.Replace("?", "a"); Console.WriteLine(ans); return; } } Console.WriteLine("UNRESTORABLE"); Console.ReadLine(); } static int BinarySearch<T>(T[] array, T target) where T : IComparable<T> // 2分探索 { int min = 0; int max = array.Length - 1; while (true) { // 範囲内に見つからなかった if (max < min) return -1; // 範囲内の中央値と比較する int mid = min + (max - min) / 2; switch (target.CompareTo(array[mid])) { case -1: // 中央値より小さい max = mid - 1; break; case 1: // 中央値より大きい min = mid + 1; break; case 0: // 見つかった return mid; } } } static void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } } class Scanner //標準入力 { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { Scanner cin = new Scanner(); string S = Console.ReadLine(); string T = Console.ReadLine(); bool flag; for (int i = S.Length - T.Length; i >= 0; i--) { flag = true; for (int j = 0; j < T.Length; j++) { if (S[i + j] != T[j] && S[i + j] != '?') flag = false; } if (flag) { string ans = S.Substring(0, i) + T + S.Substring(i + T.Length); ans = ans.Replace("?", "a"); Console.WriteLine(ans); return; } } Console.WriteLine("UNRESTORABLE"); Console.ReadLine(); } static int BinarySearch<T>(T[] array, T target) where T : IComparable<T> // 2分探索 { int min = 0; int max = array.Length - 1; while (true) { // 範囲内に見つからなかった if (max < min) return -1; // 範囲内の中央値と比較する int mid = min + (max - min) / 2; switch (target.CompareTo(array[mid])) { case -1: // 中央値より小さい max = mid - 1; break; case 1: // 中央値より大きい min = mid + 1; break; case 0: // 見つかった return mid; } } } static void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } } class Scanner //標準入力 { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
717
12
using System; using System.Collections; using System.Collections.Generic; using System.Linq; public class Test { public static void Main() { string str = Console.ReadLine(); string T = Console.ReadLine(); bool isFind = false; char[] c1 = str.ToCharArray(); char[] c2 = T.ToCharArray(); List<string> list = new List<string>(); string s; for (int i = 0; i < c1.Length - c2.Length + 1; i++) { isFind = true; s = ""; c1 = str.ToCharArray(); for (int j = 0; j < c2.Length; j++) { // Console.WriteLine("c1 = " + c1[i+j] + " c2 =" + c2[j] + " j="+j ); if (c1[i + j] == c2[j] || c1[i + j] == '?') { } else { isFind = false; } } if (isFind) { for (int k = 0; k < c2.Length; k++) { c1[i + k] = c2[k]; } for (int x = 0; x < c1.Length; x++) { if (c1[x] == '?') s += "a"; else s += c1[x].ToString(); } list.Add(s); } } list.Sort(); if (isFind) { Console.WriteLine(list[0]); } else Console.WriteLine("UNRESTORABLE"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; public class Test { public static void Main() { string str = Console.ReadLine(); string T = Console.ReadLine(); bool isFind = false; char[] c1 = str.ToCharArray(); char[] c2 = T.ToCharArray(); List<string> list = new List<string>(); string s; for (int i = 0; i < c1.Length - c2.Length + 1; i++) { isFind = true; s = ""; c1 = str.ToCharArray(); for (int j = 0; j < c2.Length; j++) { // Console.Write("c1 = " + c1[i+j] + " c2 =" + c2[j] + " j="+j ); if (c1[i + j] == c2[j] || c1[i + j] == '?') { // Console.Write(" ok "); } else { isFind = false; } // Console.WriteLine(); } if (isFind) { for (int k = 0; k < c2.Length; k++) { c1[i + k] = c2[k]; } for (int x = 0; x < c1.Length; x++) { if (c1[x] == '?') s += "a"; else s += c1[x].ToString(); } list.Add(s); // Console.WriteLine(list[list.Count()-1]); } } list.Sort(); if (list.Count() > 0) { Console.WriteLine(list[0]); } else Console.WriteLine("UNRESTORABLE"); } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 15, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
311
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice { class Program { static void Main(string[] args) { SolveA(); // SolveB(); // SolveC(); // SolveD(); } private const long MOD = 1000000007; private const string kUnrestorable = "UNRESTORABLE"; static void SolveA() { string s = Console.ReadLine(); string t = Console.ReadLine(); if (t.Length > s.Length) { Console.WriteLine(kUnrestorable); return; } bool isMatch = true; var sList = new List<char[]>(); for (int start = 0; start + t.Length <= s.Length; ++start) { var work = s.ToCharArray(); isMatch = true; for (int i = 0; i < t.Length; ++i) { if (s[start + i] == '?') { work[start + i] = t[i]; } else if (s[start + i] == t[i]) { } else { isMatch = false; break; } } if (isMatch) { for (int i = 0; i < work.Length; ++i) { if (work[i] == '?') { work[i] = 'a'; } } sList.Add(work); } } if (sList.Count >= 1) { sList.Sort(); Console.WriteLine(new string(sList[0])); } else { Console.WriteLine(kUnrestorable); } } #region よく使う便利関数 private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } #endregion } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice { class Program { static void Main(string[] args) { SolveA(); // SolveB(); // SolveC(); // SolveD(); } private const long MOD = 1000000007; private const string kUnrestorable = "UNRESTORABLE"; static void SolveA() { string s = Console.ReadLine(); string t = Console.ReadLine(); if (t.Length > s.Length) { Console.WriteLine(kUnrestorable); return; } bool isMatch = true; var sList = new List<string>(); for (int start = 0; start + t.Length <= s.Length; ++start) { var work = s.ToCharArray(); isMatch = true; for (int i = 0; i < t.Length; ++i) { if (s[start + i] == '?') { work[start + i] = t[i]; } else if (s[start + i] == t[i]) { } else { isMatch = false; break; } } if (isMatch) { for (int i = 0; i < work.Length; ++i) { if (work[i] == '?') { work[i] = 'a'; } } sList.Add(new string(work)); } } if (sList.Count >= 1) { sList.Sort(); Console.WriteLine(sList[0]); } else { Console.WriteLine(kUnrestorable); } } #region よく使う便利関数 private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } #endregion } }
[["-", 0, 230, 39, 236, 237, 238, 0, 224, 39, 199], ["-", 39, 236, 237, 238, 0, 224, 225, 226, 0, 70], ["-", 39, 236, 237, 238, 0, 224, 225, 226, 0, 73], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 230, 0, 228], ["+", 0, 213, 3, 4, 0, 28, 0, 230, 39, 199], ["+", 3, 4, 0, 28, 0, 230, 3, 4, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 230, 0, 228], ["-", 0, 213, 3, 4, 0, 28, 0, 230, 39, 199], ["-", 3, 4, 0, 28, 0, 230, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 230, 3, 4, 0, 25]]
8
626
12
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; using System.Text; static class MainClass { public static void Main() { var str = Console.ReadLine().ToList(); var strt = Console.ReadLine(); var len = str.Count; var tlen = strt.Length; var kouho = new List<string>(); var newkouho = new List<string>(); for (int i = 0; i <= len - tlen; i++) { var tistr = str.DeepClone(); if (str[i] == '?' || str[i] == strt[0]) { var isOk = true; for (int j = 0; j < tlen; j++) { if (str[i + j] != strt[j] && str[i + j] != '?') { isOk = false; break; } else { tistr[i + j] = strt[j]; } } if (isOk) { var sb = new StringBuilder(); tistr.ForEach(x => { sb.Append(x); }); kouho.Add(sb.ToString()); } } } if (kouho.Count == 0) { Console.WriteLine("UNRESTORABLE"); } else { foreach (var item in kouho) { for (int i = 0; i < len; i++) { if (item[i] == '?') { newkouho.Add(item.Replace('?', 'a')); } } } newkouho.Sort(); Console.WriteLine(newkouho.First()); Console.ReadLine(); } } #region 二分探索 public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } #endregion #region bit全探索 /// <summary> /// Bit全探索用のライブラリ /// </summary> /// <param name="len">作る配列の長さ(lenが0以下だと(ry)</param> /// <returns>できた配列</returns> public static List<List<bool>> CreateBits(int len) { return CreateBitsPri(new List<List<bool>>(), len, 0); } private static List<List<bool>> CreateBitsPri(List<List<bool>> bits, int len, int count) { if (count == 0) { var lss = new List<bool>(); lss.Add(true); bits.Add(lss); var lx = new List<bool>(); lx.Add(false); bits.Add(lx); count++; return CreateBitsPri(bits, len, count); } if (len - count == 0) return bits; count++; var ls = new List<List<bool>>(); foreach (var item in bits) { var x = item.ToList(); x.Add(true); item.Add(false); ls.Add(item); ls.Add(x); } return CreateBitsPri(ls, len, count); } #endregion #region 文字列処理 public static int ToInt32(this string str) { return int.Parse(str); } public static List<string> SplittedStringToList(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); } public static List<int> SplittedStringToInt32List(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => int.Parse(x)) .ToList(); } #endregion #region エラトステネスの篩 public static List<int> GeneratePrimes(int max) { var range = Enumerable.Range(2, max - 1).ToList(); var count = range.Count(); var ls = new List<int>(); while (true) { int num = 0; try { num = range.First(); ls.Add(num); } catch { break; } for (int i = 1; i * num <= max; i++) { range.Remove(i * num); } if (range.Count <= 0) { break; } } return ls; } #endregion #region DeepClone public static T DeepClone<T>(this T src) { using (var memoryStream = new MemoryStream()) { var binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(memoryStream, src); memoryStream.Seek(0, SeekOrigin.Begin); return (T)binaryFormatter.Deserialize(memoryStream); } } #endregion }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; using System.Text; static class MainClass { public static void Main() { var str = Console.ReadLine().ToList(); var strt = Console.ReadLine(); var len = str.Count; var tlen = strt.Length; var kouho = new List<string>(); var newkouho = new List<string>(); for (int i = 0; i <= len - tlen; i++) { var tistr = str.DeepClone(); if (str[i] == '?' || str[i] == strt[0]) { var isOk = true; for (int j = 0; j < tlen; j++) { if (str[i + j] != strt[j] && str[i + j] != '?') { isOk = false; break; } else { tistr[i + j] = strt[j]; } } if (isOk) { var sb = new StringBuilder(); tistr.ForEach(x => { sb.Append(x); }); kouho.Add(sb.ToString()); } } } if (kouho.Count == 0) { Console.WriteLine("UNRESTORABLE"); } else { foreach (var item in kouho) { for (int i = 0; i < len; i++) { if (item[i] == '?') { newkouho.Add(item.Replace('?', 'a')); } else { if (!newkouho.Contains(item) && !item.Contains('?')) newkouho.Add(item); } } } newkouho.Sort(); Console.WriteLine(newkouho.First()); Console.ReadLine(); } } #region 二分探索 public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } #endregion #region bit全探索 /// <summary> /// Bit全探索用のライブラリ /// </summary> /// <param name="len">作る配列の長さ(lenが0以下だと(ry)</param> /// <returns>できた配列</returns> public static List<List<bool>> CreateBits(int len) { return CreateBitsPri(new List<List<bool>>(), len, 0); } private static List<List<bool>> CreateBitsPri(List<List<bool>> bits, int len, int count) { if (count == 0) { var lss = new List<bool>(); lss.Add(true); bits.Add(lss); var lx = new List<bool>(); lx.Add(false); bits.Add(lx); count++; return CreateBitsPri(bits, len, count); } if (len - count == 0) return bits; count++; var ls = new List<List<bool>>(); foreach (var item in bits) { var x = item.ToList(); x.Add(true); item.Add(false); ls.Add(item); ls.Add(x); } return CreateBitsPri(ls, len, count); } #endregion #region 文字列処理 public static int ToInt32(this string str) { return int.Parse(str); } public static List<string> SplittedStringToList(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); } public static List<int> SplittedStringToInt32List(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => int.Parse(x)) .ToList(); } #endregion #region エラトステネスの篩 public static List<int> GeneratePrimes(int max) { var range = Enumerable.Range(2, max - 1).ToList(); var count = range.Count(); var ls = new List<int>(); while (true) { int num = 0; try { num = range.First(); ls.Add(num); } catch { break; } for (int i = 1; i * num <= max; i++) { range.Remove(i * num); } if (range.Count <= 0) { break; } } return ls; } #endregion #region DeepClone public static T DeepClone<T>(this T src) { using (var memoryStream = new MemoryStream()) { var binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(memoryStream, src); memoryStream.Seek(0, SeekOrigin.Begin); return (T)binaryFormatter.Deserialize(memoryStream); } } #endregion }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 75, 196, 0, 57, 15, 16, 31, 241, 0, 111], ["+", 15, 16, 31, 241, 0, 213, 63, 214, 205, 22], ["+", 15, 16, 31, 241, 0, 213, 63, 214, 0, 131], ["+", 15, 16, 31, 241, 0, 213, 63, 214, 141, 22], ["+", 15, 16, 31, 241, 0, 213, 3, 4, 0, 24], ["+", 31, 241, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 15, 16, 31, 241, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 98], ["+", 75, 196, 0, 57, 15, 16, 12, 241, 0, 111], ["+", 15, 16, 12, 241, 0, 213, 63, 214, 205, 22], ["+", 15, 16, 12, 241, 0, 213, 63, 214, 0, 131], ["+", 15, 16, 12, 241, 0, 213, 63, 214, 141, 22], ["+", 15, 16, 12, 241, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 15, 16, 12, 241, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
8
1,186
30
using System; using System.Linq; using System.Diagnostics; using System.Collections.Generic; using static System.Math; class P { static void Main() { char[] s = Console.ReadLine().ToArray(); string t = Console.ReadLine(); bool flag = false; for (int i = 0; i <= s.Length - t.Length; i++) { if (flag) goto end; for (int j = 0; j < t.Length; j++) { if (s[i + j] != '?' && s[i + j] != t[j]) goto end; } for (int j = 0; j < t.Length; j++) { if (s[i + j] == '?') { s[i + j] = t[j]; } } flag = true; end:; } if (flag) Console.WriteLine(string.Join("", s).Replace('?', 'a')); else Console.WriteLine("UNRESTORABLE"); } }
using System; using System.Linq; using System.Diagnostics; using System.Collections.Generic; using static System.Math; class P { static void Main() { char[] s = Console.ReadLine().ToArray(); string t = Console.ReadLine(); bool flag = false; for (int i = s.Length - t.Length; i >= 0; i--) { if (flag) goto end; for (int j = 0; j < t.Length; j++) { if (s[i + j] != '?' && s[i + j] != t[j]) goto end; } for (int j = 0; j < t.Length; j++) { s[i + j] = t[j]; } flag = true; end:; } if (flag) Console.WriteLine(string.Join("", s).Replace('?', 'a')); else Console.WriteLine("UNRESTORABLE"); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 104], ["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
233
25
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; class Simple { string S, T; void Solve() { // input S = io.String; T = io.String; // cal if (T.Length > S.Length) { Console.WriteLine("UNRESTORABLE"); return; } var X = S.Select(c => c == '?' ? 'a' : c).ToArray(); for (int i = 0; i < S.Length - T.Length + 1; ++i) { var f = true; for (int j = 0; j < T.Length; ++j) { if (S[i + j] == '?' || S[i + j] == T[j]) { // } else { f = false; break; } } if (f) { for (int j = 0; j < T.Length; ++j) if (S[i + j] == '?' || S[i + j] == T[j]) X[i + j] = T[j]; // ret Console.WriteLine(new string(X)); return; } } // ret Console.WriteLine("UNRESTORABLE"); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) { new Simple().Stream(); } void Stream() { Solve(); io.writeFlush(); } } class SimpleIO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void writeFlush() { Console.Out.Flush(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; class Simple { string S, T; void Solve() { // input S = io.String; T = io.String; S = new string(S.Reverse().ToArray()); T = new string(T.Reverse().ToArray()); // cal if (T.Length > S.Length) { Console.WriteLine("UNRESTORABLE"); return; } var X = S.Select(c => c == '?' ? 'a' : c).ToArray(); for (int i = 0; i < S.Length - T.Length + 1; ++i) { var f = true; for (int j = 0; j < T.Length; ++j) { if (S[i + j] == '?' || S[i + j] == T[j]) { // } else { f = false; break; } } if (f) { for (int j = 0; j < T.Length; ++j) if (S[i + j] == '?' || S[i + j] == T[j]) X[i + j] = T[j]; // ret Console.WriteLine(new string(X.Reverse().ToArray())); return; } } // ret Console.WriteLine("UNRESTORABLE"); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) { new Simple().Stream(); } void Stream() { Solve(); io.writeFlush(); } } class SimpleIO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void writeFlush() { Console.Out.Flush(); } }
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 230, 0, 228], ["+", 8, 196, 0, 1, 0, 11, 12, 230, 39, 199], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 24], ["+", 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], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
539
40
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; class Program { static void Main(string[] args) { string s = Console.ReadLine(); string t = Console.ReadLine(); char[] cs = s.ToCharArray(); char[] ct = t.ToCharArray(); List<string> sarray = new List<string>(); for (int i = 0; i < cs.Length - ct.Length + 1; i++) { if (match(ct, cs, i)) { char[] ans = cs; for (int j = i; j < i + ct.Length; j++) { ans[j] = ct[j - i]; } for (int j = 0; j < ans.Length; j++) { if (ans[j] == '?') ans[j] = 'a'; } sarray.Add(new String(ans)); } } sarray.Sort(); if (sarray.Count == 0) { Console.WriteLine("UNRESTORABLE"); } else { Console.WriteLine("{0}", sarray[0]); } } static bool match(char[] ct, char[] cs, int k) { for (int i = 0; i < ct.Length; i++) { if (cs[i + k] != '?' && cs[i + k] != ct[i]) return false; } return true; } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; class Program { static void Main(string[] args) { string s = Console.ReadLine(); string t = Console.ReadLine(); char[] cs = s.ToCharArray(); char[] ct = t.ToCharArray(); List<string> sarray = new List<string>(); for (int i = 0; i < cs.Length - ct.Length + 1; i++) { if (match(ct, cs, i)) { char[] ans = new char[cs.Length]; cs.CopyTo(ans, 0); for (int j = i; j < i + ct.Length; j++) { ans[j] = ct[j - i]; } for (int j = 0; j < ans.Length; j++) { if (ans[j] == '?') ans[j] = 'a'; } sarray.Add(new String(ans)); } } sarray.Sort(); if (sarray.Count == 0) { Console.WriteLine("UNRESTORABLE"); } else { Console.WriteLine("{0}", sarray[0]); } } static bool match(char[] ct, char[] cs, int k) { for (int i = 0; i < ct.Length; i++) { if (cs[i + k] != '?' && cs[i + k] != ct[i]) return false; } return true; } }
[["+", 0, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 227, 39, 224, 225, 226, 0, 214, 0, 131], ["+", 0, 227, 39, 224, 225, 226, 0, 214, 141, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
8
339
15
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; ReadData re; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); re = new ReadData(); Calc(); Console.Write(sb.ToString()); } void Calc() { string s = re.s(); char[] S = new char[s.Length]; for (int i = 0; i < S.Length; i++) { S[i] = s[i]; } string s2 = re.s(); bool b = false; for (int i = s.Length - 1; i >= 0; i--) { bool c = true; for (int j = 0; j < s2.Length; j++) { c &= i - s2.Length + 1 + j >= 0 && S[i - s2.Length + 1 + j] == s2[j]; } if (c) { b = true; } } for (int i = s.Length - 1; i >= 0; i--) { if (b) { if (S[i] == '?') { S[i] = 'a'; } } else { bool c = true; for (int j = 0; j < s2.Length; j++) { c &= i - s2.Length + 1 + j >= 0 && (S[i - s2.Length + 1 + j] == '?' || S[i - s2.Length + 1 + j] == s2[j]); } if (c) { b = true; for (int j = 0; j < s2.Length; j++) { S[i - s2.Length + 1 + j] = s2[j]; } } } } if (b) { for (int i = 0; i < S.Length; i++) { sb.Append(S[i]); } sb.Append("\n"); } else { sb.Append("UNRESTORABLE\n"); } } } class ReadData { string[] str; int counter; public ReadData() { counter = 0; } public string s() { if (counter == 0) { str = Console.ReadLine().Split(' '); counter = str.Length; } counter--; return str[str.Length - counter - 1]; } public int i() { return int.Parse(s()); } public long l() { return long.Parse(s()); } public double d() { return double.Parse(s()); } public int[] ia(int N) { int[] ans = new int[N]; for (int j = 0; j < N; j++) { ans[j] = i(); } return ans; } public int[] ia() { str = Console.ReadLine().Split(' '); counter = 0; int[] ans = new int[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = int.Parse(str[j]); } return ans; } public long[] la(int N) { long[] ans = new long[N]; for (int j = 0; j < N; j++) { ans[j] = l(); } return ans; } public long[] la() { str = Console.ReadLine().Split(' '); counter = 0; long[] ans = new long[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = long.Parse(str[j]); } return ans; } public double[] da(int N) { double[] ans = new double[N]; for (int j = 0; j < N; j++) { ans[j] = d(); } return ans; } public double[] da() { str = Console.ReadLine().Split(' '); counter = 0; double[] ans = new double[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = double.Parse(str[j]); } return ans; } public List<int>[] g(int N, int[] f, int[] t) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < f.Length; j++) { ans[f[j]].Add(t[j]); ans[t[j]].Add(f[j]); } return ans; } public List<int>[] g(int N, int M) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } public List<int>[] g() { int N = i(); int M = i(); List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } } public static class Define { public const long mod = 1000000007; } public static class Debug { public static void Print(double[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(double[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(double[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(long[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(long[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(long[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(int[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(int[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(int[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; ReadData re; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); re = new ReadData(); Calc(); Console.Write(sb.ToString()); } void Calc() { string s = re.s(); char[] S = new char[s.Length]; for (int i = 0; i < S.Length; i++) { S[i] = s[i]; } string s2 = re.s(); bool b = false; for (int i = s.Length - 1; i >= 0; i--) { bool c = true; for (int j = 0; j < s2.Length; j++) { c &= i - s2.Length + 1 + j >= 0 && S[i - s2.Length + 1 + j] == s2[j]; } if (c) { b = true; } } for (int i = s.Length - 1; i >= 0; i--) { if (b) { if (S[i] == '?') { S[i] = 'a'; } } else { bool c = true; for (int j = 0; j < s2.Length; j++) { c &= i - s2.Length + 1 + j >= 0 && (S[i - s2.Length + 1 + j] == '?' || S[i - s2.Length + 1 + j] == s2[j]); } if (c) { b = true; for (int j = 0; j < s2.Length; j++) { S[i - s2.Length + 1 + j] = s2[j]; } } else if (S[i] == '?') { S[i] = 'a'; } } } if (b) { for (int i = 0; i < S.Length; i++) { sb.Append(S[i]); } sb.Append("\n"); } else { sb.Append("UNRESTORABLE\n"); } } } class ReadData { string[] str; int counter; public ReadData() { counter = 0; } public string s() { if (counter == 0) { str = Console.ReadLine().Split(' '); counter = str.Length; } counter--; return str[str.Length - counter - 1]; } public int i() { return int.Parse(s()); } public long l() { return long.Parse(s()); } public double d() { return double.Parse(s()); } public int[] ia(int N) { int[] ans = new int[N]; for (int j = 0; j < N; j++) { ans[j] = i(); } return ans; } public int[] ia() { str = Console.ReadLine().Split(' '); counter = 0; int[] ans = new int[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = int.Parse(str[j]); } return ans; } public long[] la(int N) { long[] ans = new long[N]; for (int j = 0; j < N; j++) { ans[j] = l(); } return ans; } public long[] la() { str = Console.ReadLine().Split(' '); counter = 0; long[] ans = new long[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = long.Parse(str[j]); } return ans; } public double[] da(int N) { double[] ans = new double[N]; for (int j = 0; j < N; j++) { ans[j] = d(); } return ans; } public double[] da() { str = Console.ReadLine().Split(' '); counter = 0; double[] ans = new double[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = double.Parse(str[j]); } return ans; } public List<int>[] g(int N, int[] f, int[] t) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < f.Length; j++) { ans[f[j]].Add(t[j]); ans[t[j]].Add(f[j]); } return ans; } public List<int>[] g(int N, int M) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } public List<int>[] g() { int N = i(); int M = i(); List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } } public static class Define { public const long mod = 1000000007; } public static class Debug { public static void Print(double[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(double[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(double[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(long[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(long[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(long[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(int[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(int[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(int[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } }
[["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 57, 75, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 204, 205, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 57, 15, 16, 12, 252, 0, 104], ["+", 0, 57, 75, 57, 15, 16, 12, 252, 0, 253], ["+", 0, 57, 75, 196, 0, 57, 75, 57, 0, 25], ["+", 75, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 252, 0, 104], ["+", 64, 196, 0, 1, 0, 11, 12, 252, 0, 253], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 57, 75, 57, 64, 196, 0, 46]]
8
2,041
23
using System; using System.Linq; class Program { static void Main(string[] args) { string sp = Cin.Next(); string t = Cin.Next(); Console.WriteLine(TryChange(sp, t)); } private static string TryChange(string sp, string t) { char[] tmpSt = sp.ToCharArray(); for (int i = 0; i < sp.Length; i++) { if (CanChange(sp, t, ref tmpSt, i)) { return new string(tmpSt).Replace('?', 'a'); } } return "UNRESTORABLE"; } private static bool CanChange(string sp, string t, ref char[] tmpSt, int i) { for (int ti = 0; ti < t.Length; ti++) { if (i + ti >= sp.Length) return false; if (sp[i + ti] == t[ti] || sp[i + ti] == '?') { tmpSt[i + ti] = t[ti]; } else { tmpSt = sp.ToCharArray(); return false; } } return true; } } public class Cin { private static string[] s = new string[0]; private static int i = 0; private static char[] cs = new char[] { ' ' }; public static string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return Next(); } public static int Ni() { return int.Parse(Next()); } public static long NextLong() { return long.Parse(Next()); } public static double NextDouble() { return double.Parse(Next()); } }
using System; using System.Linq; class Program { static void Main(string[] args) { string sp = Cin.Next(); string t = Cin.Next(); Console.WriteLine(TryChange(sp, t)); } private static string TryChange(string sp, string t) { char[] tmpSt = sp.ToCharArray(); for (int i = sp.Length - t.Length; i >= 0; i--) { if (CanChange(sp, t, ref tmpSt, i)) { return new string(tmpSt).Replace('?', 'a'); } } return "UNRESTORABLE"; } private static bool CanChange(string sp, string t, ref char[] tmpSt, int i) { for (int ti = 0; ti < t.Length; ti++) { if (i + ti >= sp.Length) return false; if (sp[i + ti] == t[ti] || sp[i + ti] == '?') { tmpSt[i + ti] = t[ti]; } else { tmpSt = sp.ToCharArray(); return false; } } return true; } } public class Cin { private static string[] s = new string[0]; private static int i = 0; private static char[] cs = new char[] { ' ' }; public static string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return Next(); } public static int Ni() { return int.Parse(Next()); } public static long NextLong() { return long.Parse(Next()); } public static double NextDouble() { return double.Parse(Next()); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 200, 0, 212, 0, 16, 31, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 16, 31, 214, 141, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 12, 214, 205, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
408
14
//#pragma warning disable using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System; using System.Numerics; using System.Threading.Tasks; using static System.Math; using static System.Console; class Z { static void Main() => new K(); } class K { int F() => int.Parse(ReadLine()); long FL() => long.Parse(ReadLine()); int[] G() => ReadLine() .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); long[] GL() => ReadLine() .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(long.Parse) .ToArray(); public const int MOD = 1000000007; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } void Solve() { Console.WriteLine(Calc(ReadLine(), ReadLine()) ?? "UNRESTORABLE"); } string Calc(string S, string T) { int N = S.Length, M = T.Length; if (N < M) return null; string ans = null; for (var i = 0; i <= N - M; i++) { var flag = true; var u = S.Replace('?', 'a').ToArray(); for (var j = 0; flag && j < M; j++) { u[i + j] = T[j]; flag &= S[i + j] == '?' || S[i + j] == T[j]; } if (!flag) continue; var U = new string(u); Console.WriteLine(U); if (ans == null) ans = U; else if (ans.CompareTo(U) > 0) ans = U; } return ans; } }
//#pragma warning disable using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System; using System.Numerics; using System.Threading.Tasks; using static System.Math; using static System.Console; class Z { static void Main() => new K(); } class K { int F() => int.Parse(ReadLine()); long FL() => long.Parse(ReadLine()); int[] G() => ReadLine() .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); long[] GL() => ReadLine() .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(long.Parse) .ToArray(); public const int MOD = 1000000007; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } void Solve() { Console.WriteLine(Calc(ReadLine(), ReadLine()) ?? "UNRESTORABLE"); } string Calc(string S, string T) { int N = S.Length, M = T.Length; if (N < M) return null; string ans = null; for (var i = 0; i <= N - M; i++) { var flag = true; var u = S.Replace('?', 'a').ToArray(); for (var j = 0; flag && j < M; j++) { u[i + j] = T[j]; flag &= S[i + j] == '?' || S[i + j] == T[j]; } if (!flag) continue; var U = new string(u); // Console.WriteLine(U); if (ans == null) ans = U; else if (ans.CompareTo(U) > 0) ans = U; } return ans; } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
441
7
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; using System.Numerics; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static long Mod = (long)1e9 + 7; static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); Read(); } static void Solve() { var N = Sarray()[0]; var Ti = Sarray(); var Vi = Sarray(); Vi = Vi.Concat(new long[] { 0 }).ToArray(); for (var i = N - 1; 0 <= i; --i) Vi[i] = Min(Vi[i], Vi[i + 1] + Ti[i]); double Vl = 0, Vr = 0, sum = 0; for (var i = 0; i < N; ++i) { double men = 0; var t = Ti[i]; if (Vi[i] <= Vi[i + 1]) { Vr = Min(Vl + t, Vi[i]); var Adt = Vr - Vl; var Cst = t - Adt; men = (Vl + Vr) * Adt / 2 + Cst * Vr; } else { Vr = Vi[i + 1]; double Vm = Vi[i]; var Adt = Vm - Vl; var Dst = Vm - Vr; if (t < Adt + Dst) { Adt = (t + Vr - Vl) / 2.0; // Vl+Adt=Dst+Vr,Adt+Dst=t Dst = t - Adt; Vm = Vl + Adt; } men = (Vl + Vm) * Adt / 2.0 + Vm * (t - Adt - Dst) + (Vm + Vr) * Dst / 2.0; } Vl = Vr; sum += men; } WriteLine($"{sum:f4}"); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; using System.Numerics; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static long Mod = (long)1e9 + 7; static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); Read(); } static void Solve() { var N = Sarray()[0]; var Ti = Sarray(); var Vi = Sarray(); Vi = Vi.Concat(new long[] { 0 }).ToArray(); for (var i = N - 1; 0 <= i; --i) Vi[i] = Min(Vi[i], Vi[i + 1] + Ti[i]); double Vl = 0, Vr = 0, sum = 0; for (var i = 0; i < N; ++i) { double men = 0; var t = Ti[i]; if (Vi[i] + 0.1 < Vl) throw new Exception(); if (Vi[i] <= Vi[i + 1]) { Vr = Min(Vl + t, Vi[i]); var Adt = Vr - Vl; var Cst = t - Adt; men = (Vl + Vr) * Adt / 2.0 + Cst * Vr; } else { Vr = Min(Vi[i + 1], Vl + t); double Vm = Vi[i]; double Adt = Vm - Vl; double Dst = Vm - Vr; if (t < Adt + Dst) { Adt = (t + Vr - Vl) / 2.0; // Vl+Adt'=Dst'+Vr,Adt'+Dst'=t Dst = t - Adt; Vm = Vl + Adt; } men = (Vl + Vm) * Adt / 2.0 + Vm * (t - Adt - Dst) + (Vm + Vr) * Dst / 2.0; } Vl = Vr; sum += men; } WriteLine($"{sum:f5}"); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 250], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 293, 0, 294], ["+", 8, 196, 0, 57, 64, 293, 0, 230, 0, 228], ["+", 8, 196, 0, 57, 64, 293, 0, 230, 39, 22], ["+", 0, 57, 64, 293, 0, 230, 3, 4, 0, 24], ["+", 0, 57, 64, 293, 0, 230, 3, 4, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 293, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 250], ["+", 75, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 75, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199]]
8
476
32
using System; namespace ABC076D { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] t = new int[N + 1]; int[] v = new int[N + 1]; string[] bufs = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { t[i] = int.Parse(bufs[i]); } t[N] = 999; bufs = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { v[i] = int.Parse(bufs[i]); } v[N] = 0; // END Initialize // // Recurrsive Speed Limit for (int i = N - 1; i >= 0; i--) { if (v[i] > v[i + 1] + t[i]) { v[i] = v[i + 1] + t[i]; } } double curv = 0.0; int curt = 0; double dist = 0.0; for (int i = 0; i < N; i++) { double upTime = v[i] - curv; double downTime = v[i] - v[i + 1]; double flatTime = t[i] - upTime - Math.Max(downTime, 0.0); if (flatTime < 0) { flatTime = 0; double cross = ((v[i + 1] + t[i]) - curv) / 2.0; upTime = cross; downTime = t[i] - cross; } if (upTime > 0) { dist += upTime * (2 * curv + upTime) / 2.0; curv += upTime; } dist += flatTime * v[i]; if (downTime > 0) { dist += downTime * (curv + v[i + 1]) / 2.0; curv = v[i + 1]; } curt += t[i]; } Console.WriteLine(dist.ToString("F4")); } } }
using System; namespace ABC076D { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] t = new int[N + 1]; int[] v = new int[N + 1]; string[] bufs = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { t[i] = int.Parse(bufs[i]); } t[N] = 999; bufs = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { v[i] = int.Parse(bufs[i]); } v[N] = 0; // END Initialize // // Recurrsive Speed Limit for (int i = N - 1; i >= 0; i--) { if (v[i] > v[i + 1] + t[i]) { v[i] = v[i + 1] + t[i]; } } double curv = 0.0; int curt = 0; double dist = 0.0; for (int i = 0; i < N; i++) { double upTime = Math.Min(v[i] - curv, t[i]); double downTime = Math.Max((curv + upTime) - v[i + 1], 0.0); double flatTime = t[i] - upTime - downTime; if (flatTime < 0) { flatTime = 0; double cross = ((v[i + 1] + t[i]) - curv) / 2.0; upTime = cross; downTime = t[i] - cross; } if (upTime > 0) { dist += upTime * (2 * curv + upTime) / 2.0; curv += upTime; } dist += flatTime * v[i]; if (downTime > 0) { dist += downTime * (curv + v[i + 1]) / 2.0; curv = v[i + 1]; } curt += t[i]; } Console.WriteLine(dist.ToString("F4")); } } }
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 16, 31, 204, 205, 22], ["-", 0, 212, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 212, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 250], ["-", 0, 212, 0, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 212, 0, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 212, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 212, 0, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 212, 0, 16, 12, 213, 3, 4, 0, 21], ["-", 0, 16, 12, 213, 3, 4, 0, 28, 0, 250], ["-", 0, 212, 0, 16, 12, 213, 3, 4, 0, 25]]
8
442
33
using System; using System.Collections.Generic; using System.Linq; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var s = Console.ReadLine(); Calculation.Calc(s); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Calculation { internal static void Calc(string s) { for (int i = 1; i < s.Length; i++) { if (new string(s[i - 1], s[i]) == "AC") { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); return; } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } ///// <summary>nCr, 組み合わせ</summary> // public static long Combination(int n, int r) { // if (r == 0) { // return 1; // } // // 分子 // var moleculeArr = Enumerable // .Range(0, Math.Min(n - r, r)) // .Select(i => n - i) // .ToArray(); // var moleculeArrLength = moleculeArr.Length; // // 分母 // var denominatorArr = Enumerable // .Range(1, Math.Max(n - r, r)) // .ToArray(); // for (var m = 0; m < moleculeArrLength; m++) { // while (true) { // var mVal = moleculeArr[m]; // var gcds = denominatorArr.Select(b => Gcd(mVal, b)); // var maxGcd = gcds.Max(); // var maxI = gcds.ToList().IndexOf(maxGcd); // if (maxGcd == 1) { // break; // } // denominatorArr[maxI] /= (int)maxGcd; // moleculeArr[m] /= (int)maxGcd; // } // } // return FullPower(moleculeArr); //} #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { long value = item1.Value + item2; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { long value = Math.BigMul(item1.Value, item2); return new ModInt(value, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } }
using System; using System.Collections.Generic; using System.Linq; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var s = Console.ReadLine(); Calculation.Calc(s); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Calculation { internal static void Calc(string s) { for (int i = 1; i < s.Length; i++) { var msg = new string(new char[] { s[i - 1], s[i] }); if (msg == "AC") { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); return; } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } ///// <summary>nCr, 組み合わせ</summary> // public static long Combination(int n, int r) { // if (r == 0) { // return 1; // } // // 分子 // var moleculeArr = Enumerable // .Range(0, Math.Min(n - r, r)) // .Select(i => n - i) // .ToArray(); // var moleculeArrLength = moleculeArr.Length; // // 分母 // var denominatorArr = Enumerable // .Range(1, Math.Max(n - r, r)) // .ToArray(); // for (var m = 0; m < moleculeArrLength; m++) { // while (true) { // var mVal = moleculeArr[m]; // var gcds = denominatorArr.Select(b => Gcd(mVal, b)); // var maxGcd = gcds.Max(); // var maxI = gcds.ToList().IndexOf(maxGcd); // if (maxGcd == 1) { // break; // } // denominatorArr[maxI] /= (int)maxGcd; // moleculeArr[m] /= (int)maxGcd; // } // } // return FullPower(moleculeArr); //} #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { long value = item1.Value + item2; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { long value = Math.BigMul(item1.Value, item2); return new ModInt(value, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 230, 3, 4, 0, 28, 0, 227, 0, 228], ["+", 3, 4, 0, 28, 0, 227, 39, 224, 39, 199], ["+", 0, 28, 0, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 28, 0, 227, 39, 224, 225, 226, 0, 73], ["+", 3, 4, 0, 28, 0, 227, 0, 229, 0, 45], ["+", 3, 4, 0, 28, 0, 227, 0, 229, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22]]
8
1,565
15
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { string s = Console.ReadLine(); Console.WriteLine(s.Contains("AC")); } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { string s = Console.ReadLine(); Console.WriteLine(s.Contains("AC") ? "Yes" : "No"); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
49
8
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using static System.Console; using static System.Math; using static CS_Contest.Utils; using System.Numerics; using System.Linq.Expressions; using Nakov.IO; // using static CS_Contest.Library; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } public class Calc { public void Solve() { var S = ReadLine(); if (S.Contains('A') && S.Contains('C')) { "Yes".WL(); } else { "No".WL(); } return; } } } public static class Utils { public static long ModValue = (long)1e9 + 7; public static long INF = long.MaxValue; public static long Mod(long x) => x % ModValue; public static long ModPow(long x, long n) { long tmp = 1; while (n != 0) { if (n % 2 == 1) { tmp = Mod(tmp * x); } x = Mod(x * x); n /= 2; } return tmp; } public static long DivMod(long x, long y) => Mod(x * ModPow(y, (long)(1e9 + 5))); public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static Li ReadInt() => ReadLine().Split().Select(int.Parse).ToList(); public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static long GCD(long m, long n) { long tmp; if (m < n) { tmp = n; n = m; m = tmp; } while (m % n != 0) { tmp = n; n = m % n; m = tmp; } return n; } public static long LCM(long m, long n) => m * (n / GCD(m, n)); public static void REP(int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1); public struct IndexT<T> { public T Value { get; set; } public int Index { get; set; } public IndexT(T v, int i) { Value = v; Index = i; } public override string ToString() { return Value + " " + Index; } } public static IEnumerable<IndexT<T>> ToIndexEnumerable<T>( this IEnumerable<T> list) => list.Select((x, i) => new IndexT<T>(x, i)); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static IndexT<T> IndexOf<T>(this IEnumerable<T> ie, Func<IndexT<T>, IndexT<T>, IndexT<T>> func) => ie.ToIndexEnumerable().Aggregate(func); public static T[] Range<T>(int range, Func<int, T> func) { var rt = new T[range]; for (var i = 0; i < range; i++) rt[i] = func(i); return rt; } public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target)); } } namespace Nakov.IO { using System; using System.Text; using System.Globalization; public static class Cin { public static string NextToken() { StringBuilder tokenChars = new StringBuilder(); bool tokenFinished = false; bool skipWhiteSpaceMode = true; while (!tokenFinished) { int nextChar = Console.Read(); if (nextChar == -1) { tokenFinished = true; } else { char ch = (char)nextChar; if (char.IsWhiteSpace(ch)) { if (!skipWhiteSpaceMode) { tokenFinished = true; if (ch == '\r' && (Environment.NewLine == "\r\n")) { Console.Read(); } } } else { skipWhiteSpaceMode = false; tokenChars.Append(ch); } } } string token = tokenChars.ToString(); return token; } public static int NextInt() { string token = Cin.NextToken(); return int.Parse(token); } public static double NextDouble(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); double result = double.Parse(token, CultureInfo.InvariantCulture); return result; } else { double result = double.Parse(token); return result; } } public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); decimal result = decimal.Parse(token, CultureInfo.InvariantCulture); return result; } else { decimal result = decimal.Parse(token); return result; } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using static System.Console; using static System.Math; using static CS_Contest.Utils; using System.Numerics; using System.Linq.Expressions; using Nakov.IO; // using static CS_Contest.Library; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } public class Calc { public void Solve() { var S = ReadLine(); if (S.Contains("AC")) { "Yes".WL(); } else { "No".WL(); } return; } } } public static class Utils { public static long ModValue = (long)1e9 + 7; public static long INF = long.MaxValue; public static long Mod(long x) => x % ModValue; public static long ModPow(long x, long n) { long tmp = 1; while (n != 0) { if (n % 2 == 1) { tmp = Mod(tmp * x); } x = Mod(x * x); n /= 2; } return tmp; } public static long DivMod(long x, long y) => Mod(x * ModPow(y, (long)(1e9 + 5))); public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static Li ReadInt() => ReadLine().Split().Select(int.Parse).ToList(); public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static long GCD(long m, long n) { long tmp; if (m < n) { tmp = n; n = m; m = tmp; } while (m % n != 0) { tmp = n; n = m % n; m = tmp; } return n; } public static long LCM(long m, long n) => m * (n / GCD(m, n)); public static void REP(int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1); public struct IndexT<T> { public T Value { get; set; } public int Index { get; set; } public IndexT(T v, int i) { Value = v; Index = i; } public override string ToString() { return Value + " " + Index; } } public static IEnumerable<IndexT<T>> ToIndexEnumerable<T>( this IEnumerable<T> list) => list.Select((x, i) => new IndexT<T>(x, i)); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static IndexT<T> IndexOf<T>(this IEnumerable<T> ie, Func<IndexT<T>, IndexT<T>, IndexT<T>> func) => ie.ToIndexEnumerable().Aggregate(func); public static T[] Range<T>(int range, Func<int, T> func) { var rt = new T[range]; for (var i = 0; i < range; i++) rt[i] = func(i); return rt; } public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target)); } } namespace Nakov.IO { using System; using System.Text; using System.Globalization; public static class Cin { public static string NextToken() { StringBuilder tokenChars = new StringBuilder(); bool tokenFinished = false; bool skipWhiteSpaceMode = true; while (!tokenFinished) { int nextChar = Console.Read(); if (nextChar == -1) { tokenFinished = true; } else { char ch = (char)nextChar; if (char.IsWhiteSpace(ch)) { if (!skipWhiteSpaceMode) { tokenFinished = true; if (ch == '\r' && (Environment.NewLine == "\r\n")) { Console.Read(); } } } else { skipWhiteSpaceMode = false; tokenChars.Append(ch); } } } string token = tokenChars.ToString(); return token; } public static int NextInt() { string token = Cin.NextToken(); return int.Parse(token); } public static double NextDouble(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); double result = double.Parse(token, CultureInfo.InvariantCulture); return result; } else { double result = double.Parse(token); return result; } } public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); decimal result = decimal.Parse(token, CultureInfo.InvariantCulture); return result; } else { decimal result = decimal.Parse(token); return result; } } } }
[["-", 31, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["-", 31, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["-", 12, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["-", 12, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 15, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 15, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
1,285
15
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } } class Program { public static void Main() { int n = int.Parse(ReadLine()); int[] a = ReadIntArray(); int c_all = 1, c_odd = 1; for (int i = 0; i < n; i++) { c_all *= 3; if ((a[i] & 1) == 1) // Even { c_odd *= 1; } else { c_odd *= 2; } } WriteLine($"{c_all}, {c_odd}"); int ans = c_all - c_odd; // Complement WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } } class Program { public static void Main() { int n = int.Parse(ReadLine()); int[] a = ReadIntArray(); int c_all = 1, c_odd = 1; for (int i = 0; i < n; i++) { c_all *= 3; if ((a[i] & 1) == 1) // Even { c_odd *= 1; } else { c_odd *= 2; } } int ans = c_all - c_odd; // Complement WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
186
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class407 { static void Main() { string S = Console.ReadLine(); string x1 = string.Join("", S.Where(_ => _ != 'x')); string x2 = string.Join("", x1.Reverse()); if (x1 != x2) { Console.WriteLine(-1); return; } List<char> s = S.ToList(); int l = 0; int count = 0; for (int i = 0; i < S.Length; i++) { if (s[i] == 'x' && s[S.Length - 1 - i] != 'x') { s.Insert(S.Length - i, 'x'); count++; } else if (s[S.Length - 1 - i + l] == 'x' && s[i] != 'x') { s.Insert(i + l, 'x'); count++; l++; } } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class407 { static void Main() { string S = Console.ReadLine(); string x1 = string.Join("", S.Where(_ => _ != 'x')); string x2 = string.Join("", x1.Reverse()); if (x1 != x2) { Console.WriteLine(-1); return; } List<char> s = S.ToList(); int l = 0; int count = 0; for (int i = 0; i < s.Count; i++) { if (s[i] == 'x' && s[s.Count - 1 - i] != 'x') { s.Insert(s.Count - i, 'x'); count++; } else if (s[s.Count - 1 - i] == 'x' && s[i] != 'x') { s.Insert(i, 'x'); count++; l++; } } Console.WriteLine(count); } } }
[["-", 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], ["-", 0, 28, 0, 16, 31, 16, 31, 214, 205, 22], ["+", 0, 28, 0, 16, 31, 16, 31, 214, 205, 22], ["-", 0, 28, 0, 16, 31, 16, 31, 214, 141, 22], ["+", 0, 28, 0, 16, 31, 16, 31, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["-", 0, 16, 31, 16, 31, 16, 31, 214, 205, 22], ["-", 0, 16, 31, 16, 31, 16, 31, 214, 141, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
253
20