提出 #17896941
ソースコード 拡げる
using AtCoder;
using AtCoder.IO;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using static AtCoder.Global;
public partial class Program { static void Main() => new Program(new ConsoleReader(), new ConsoleWriter()).Run();[DebuggerBrowsable(DebuggerBrowsableState.Never)] public ConsoleReader cr;[DebuggerBrowsable(DebuggerBrowsableState.Never)] public ConsoleWriter cw; public Program(ConsoleReader r, ConsoleWriter w) { this.cr = r; this.cw = w; System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; } }
public partial class Program
{
public void Run()
{
var res = Calc();
if (res is double) cw.WriteLine(((double)res).ToString("0.####################", System.Globalization.CultureInfo.InvariantCulture));
else if (res is bool) cw.WriteLine(((bool)res) ? "Yes" : "No");
else if (res != null) cw.WriteLine(res.ToString());
cw.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
private object Calc()
{
static byte Conv(char c) => c switch
{
'A' => 0,
'T' => 1,
'G' => 2,
'C' => 3,
_ => throw new Exception(),
};
int N = cr;
ReadOnlySpan<byte> want = cr.Ascii.Select(Conv).ToArray();
var trie = new Trie();
int M, ml;
{
byte[][] origs = cr.Repeat(N).Select(cr => cr.Ascii.Select(Conv).ToArray());
M = want.Length;
ml = origs.Max(str => str.Length);
foreach (ReadOnlySpan<byte> o in origs) trie.Add(o);
}
GC.Collect();
var dp = NewArray(M, 1000000);
for (int i = Math.Min(ml, M); i > 0; i--)
if (trie.Contains(want[..i]))
for (--i; i >= 0; i--)
dp[i] = 1;
for (int l = 0; l < M; l++)
for (int r = Math.Min(l + ml, M); r > l; --r)
if (trie.Contains(want[l..r]))
for (--r; r > l; --r)
dp[r].UpdateMin(dp[l] + 1);
return dp[^1];
}
}
public class Trie<TValue>
{
readonly Trie<TValue>[] children;
public bool HasValue { private set; get; }
TValue _Value;
public TValue Value
{
set
{
_Value = value;
HasValue = true;
}
get => _Value;
}
public Trie() { children = new Trie<TValue>[4]; }
public Trie<TValue> Next(byte key) => children[key];
public Trie<TValue> GetChild(ReadOnlySpan<byte> key, bool force = false)
{
var trie = this;
foreach (var k in key)
{
var child = trie.Next(k);
if (child == null)
{
if (!force) return null;
child = trie.children[k] = new Trie<TValue>();
}
trie = child;
}
return trie;
}
public void Add(ReadOnlySpan<byte> key, TValue value)
=> GetChild(key, true).Value = value;
public bool Remove(ReadOnlySpan<byte> key)
{
var stack = new Stack<(byte k, Trie<TValue> trie)>(key.Length + 1);
var trie = this;
stack.Push((default, trie));
foreach (var k in key)
{
trie = trie.Next(k);
if (trie == null) return false;
stack.Push((k, trie));
}
var cur = stack.Pop();
if (!cur.trie.HasValue) return false;
cur.trie.HasValue = false;
while (stack.Count > 0 && !cur.trie.HasValue && cur.trie.children.All(t => t == null))
{
var prevK = cur.k;
cur = stack.Pop();
cur.trie.children[prevK] = null;
}
return true;
}
public TValue Get(ReadOnlySpan<byte> key)
{
if (TryGet(key, out var val)) return val;
throw new KeyNotFoundException();
}
public bool TryGet(ReadOnlySpan<byte> key, out TValue value)
{
var child = GetChild(key);
if (child == null || !child.HasValue)
{
value = default;
return false;
}
value = child.Value;
return true;
}
public MatchEnumerator MatchGreedy(ReadOnlySpan<byte> key)
=> new MatchEnumerator(this, key);
public ref struct MatchEnumerator
{
Trie<TValue> trie;
readonly ReadOnlySpan<byte> span;
public MatchEnumerator Current => this;
int len;
TValue value;
public MatchEnumerator(Trie<TValue> trie, ReadOnlySpan<byte> span)
{
this.trie = trie;
this.span = span;
len = -1;
value = default;
}
public bool MoveNext()
{
bool ok = false;
while (trie != null && !ok)
{
if (trie.HasValue)
{
value = trie.Value;
ok = true;
}
if (len + 1 < span.Length)
trie = trie.Next(span[++len]);
else
{
++len;
trie = null;
}
}
return ok;
}
public MatchEnumerator GetEnumerator() => this;
public void Deconstruct(out ReadOnlySpan<byte> key, out TValue value)
{
key = span[..len];
value = this.value;
}
}
}
public class Trie : Trie<bool>
{
public Trie() : base() { }
public void Add(ReadOnlySpan<byte> key) => Add(key, true);
public bool Contains(ReadOnlySpan<byte> key) => GetChild(key)?.Value == true;
}
#region Expanded
namespace AtCoder { public static class Extensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool UpdateMax<T>(this ref T r, T val) where T : struct, IComparable<T> { if (r.CompareTo(val) < 0) { r = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool UpdateMin<T>(this ref T r, T val) where T : struct, IComparable<T> { if (r.CompareTo(val) > 0) { r = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Fill<T>(this T[] arr, T value) { arr.AsSpan().Fill(value); return arr; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Sort<T>(this T[] arr) { Array.Sort(arr); return arr; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string[] Sort(this string[] arr) => Sort(arr, StringComparer.Ordinal); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Sort<T, U>(this T[] arr, Expression<Func<T, U>> selector) where U : IComparable<U> => Sort(arr, ExComparer<T>.CreateExp(selector)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Sort<T>(this T[] arr, Comparison<T> comparison) { Array.Sort(arr, comparison); return arr; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Sort<T>(this T[] arr, IComparer<T> comparer) { Array.Sort(arr, comparer); return arr; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Reverse<T>(this T[] arr) { Array.Reverse(arr); return arr; } public static (int index, T max) MaxBy<T>(this T[] arr) where T : IComparable<T> { T max = arr[0]; int maxIndex = 0; for (int i = 0; i < arr.Length; i++) { if (max.CompareTo(arr[i]) < 0) { max = arr[i]; maxIndex = i; } } return (maxIndex, max); } public static (int index, T max) MaxBy<T, TMax>(this T[] arr, Func<T, TMax> maxBySelector) where TMax : IComparable<TMax> { var maxItem = maxBySelector(arr[0]); var max = arr[0]; int maxIndex = 0; for (int i = 0; i < arr.Length; i++) { var nx = maxBySelector(arr[i]); if (maxItem.CompareTo(nx) < 0) { maxItem = nx; max = arr[i]; maxIndex = i; } } return (maxIndex, max); } public static (TSource item, TMax max) MaxBy<TSource, TMax> (this IEnumerable<TSource> source, Func<TSource, TMax> maxBySelector) where TMax : IComparable<TMax> { TMax max; TSource maxByItem; var e = source.GetEnumerator(); e.MoveNext(); maxByItem = e.Current; max = maxBySelector(maxByItem); while (e.MoveNext()) { var item = e.Current; var next = maxBySelector(item); if (max.CompareTo(next) < 0) { max = next; maxByItem = item; } } return (maxByItem, max); } public static (int index, T min) MinBy<T>(this T[] arr) where T : IComparable<T> { T min = arr[0]; int minIndex = 0; for (int i = 0; i < arr.Length; i++) { if (min.CompareTo(arr[i]) > 0) { min = arr[i]; minIndex = i; } } return (minIndex, min); } public static (int index, T min) MinBy<T, TMin>(this T[] arr, Func<T, TMin> minBySelector) where TMin : IComparable<TMin> { var minItem = minBySelector(arr[0]); var min = arr[0]; int minIndex = 0; for (int i = 0; i < arr.Length; i++) { var nx = minBySelector(arr[i]); if (minItem.CompareTo(nx) > 0) { minItem = nx; min = arr[i]; minIndex = i; } } return (minIndex, min); } public static (TSource item, TMin min) MinBy<TSource, TMin> (this IEnumerable<TSource> source, Func<TSource, TMin> minBySelector) where TMin : IComparable<TMin> { TMin min; TSource minByItem; var e = source.GetEnumerator(); e.MoveNext(); minByItem = e.Current; min = minBySelector(minByItem); while (e.MoveNext()) { var item = e.Current; var next = minBySelector(item); if (min.CompareTo(next) > 0) { min = next; minByItem = item; } } return (minByItem, min); } public static IEnumerable<(int index, TSource val)> Indexed<TSource>(this IEnumerable<TSource> source) => source.Select((v, i) => (i, v)); public static IEnumerable<int> WhereBy<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) => source.Select((v, i) => (i, v)).Where(t => predicate(t.v)).Select(t => t.i); public static Dictionary<TKey, int> GroupCount<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) => source.GroupBy(keySelector).ToDictionary(g => g.Key, g => g.Count()); public static Dictionary<TKey, int> GroupCount<TKey>(this IEnumerable<TKey> source) => source.GroupCount(i => i); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Span<T> AsSpan<T>(this List<T> list, int start = 0) => Unsafe.As<ArrayVal<T>>(list).arr.AsSpan(start, list.Count); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T Get<T>(this T[] arr, int index) { if (index < 0) return ref arr[arr.Length + index]; return ref arr[index]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TValue Get<TKey, TValue>(this IDictionary<TKey, TValue> dic, TKey key) { dic.TryGetValue(key, out var v); return v; } public static void Do<T>(this ReadOnlySpan<T> span, Action<T> action) { foreach (var item in span) action(item); } public static void Do<T>(this Span<T> span, Action<T> action) { foreach (var item in span) action(item); } } }
namespace AtCoder { public static class Global { public static int Gcd(params int[] nums) { var gcd = nums[0]; for (var i = 1; i < nums.Length; i++) gcd = Gcd(nums[i], gcd); return gcd; } public static int Gcd(int a, int b) => b > a ? Gcd(b, a) : (b == 0 ? a : Gcd(b, a % b)); public static int Lcm(int a, int b) => a / Gcd(a, b) * b; public static int Lcm(params int[] nums) { var lcm = nums[0]; for (var i = 1; i < nums.Length; i++) lcm = Lcm(lcm, nums[i]); return lcm; } public static long Gcd(params long[] nums) { var gcd = nums[0]; for (var i = 1; i < nums.Length; i++) gcd = Gcd(nums[i], gcd); return gcd; } public static long Gcd(long a, long b) => b > a ? Gcd(b, a) : (b == 0 ? a : Gcd(b, a % b)); public static long Lcm(long a, long b) => a / Gcd(a, b) * b; public static long Lcm(params long[] nums) { var lcm = nums[0]; for (var i = 1; i < nums.Length; i++) lcm = Lcm(lcm, nums[i]); return lcm; } public static T[] NewArray<T>(int len0, T value) => new T[len0].Fill(value); public static T[] NewArray<T>(int len0, Func<T> factory) { var arr = new T[len0]; for (int i = 0; i < arr.Length; i++) arr[i] = factory(); return arr; } public static T[][] NewArray<T>(int len0, int len1, T value) where T : struct { var arr = new T[len0][]; for (int i = 0; i < arr.Length; i++) arr[i] = NewArray(len1, value); return arr; } public static T[][] NewArray<T>(int len0, int len1, Func<T> factory) { var arr = new T[len0][]; for (int i = 0; i < arr.Length; i++) arr[i] = NewArray(len1, factory); return arr; } public static T[][][] NewArray<T>(int len0, int len1, int len2, T value) where T : struct { var arr = new T[len0][][]; for (int i = 0; i < arr.Length; i++) arr[i] = NewArray(len1, len2, value); return arr; } public static T[][][] NewArray<T>(int len0, int len1, int len2, Func<T> factory) { var arr = new T[len0][][]; for (int i = 0; i < arr.Length; i++) arr[i] = NewArray(len1, len2, factory); return arr; } public static T[][][][] NewArray<T>(int len0, int len1, int len2, int len3, T value) where T : struct { var arr = new T[len0][][][]; for (int i = 0; i < arr.Length; i++) arr[i] = NewArray(len1, len2, len3, value); return arr; } public static T[][][][] NewArray<T>(int len0, int len1, int len2, int len3, Func<T> factory) { var arr = new T[len0][][][]; for (int i = 0; i < arr.Length; i++) arr[i] = NewArray(len1, len2, len3, factory); return arr; } public static long Pow(long x, int y) { long res = 1; for (; y > 0; y >>= 1) { if ((y & 1) == 1) res *= x; x *= x; } return res; } public static BigInteger ParseBigInteger(ReadOnlySpan<char> s) { if (s[0] == '-') return -ParseBigInteger(s[1..]); BigInteger res; if (s.Length % 9 == 0) res = 0; else { res = new BigInteger(int.Parse(s.Slice(0, s.Length % 9))); s = s.Slice(s.Length % 9); } while (s.Length > 0) { var sp = s.Slice(0, 9); res *= 1000_000_000; res += int.Parse(sp); s = s.Slice(9); } return res; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int PopCount(int x) => BitOperations.PopCount((uint)x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int PopCount(long x) => BitOperations.PopCount((ulong)x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int PopCount(ulong x) => BitOperations.PopCount(x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int MSB(int x) => BitOperations.Log2((uint)x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int MSB(uint x) => BitOperations.Log2(x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int MSB(long x) => BitOperations.Log2((ulong)x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int MSB(ulong x) => BitOperations.Log2(x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LSB(int x) => BitOperations.TrailingZeroCount((uint)x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LSB(uint x) => BitOperations.TrailingZeroCount(x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LSB(long x) => BitOperations.TrailingZeroCount((ulong)x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LSB(ulong x) => BitOperations.TrailingZeroCount(x); public static Dictionary<T, int> Compress<T>(IEnumerable<T> orig) where T : IComparable<T> => Compress(orig, Comparer<T>.Default); public static Dictionary<T, int> Compress<T>(ReadOnlySpan<T> orig) where T : IComparable<T> => Compress(orig, Comparer<T>.Default); public static Dictionary<T, int> Compress<T>(T[] orig) where T : IComparable<T> => Compress(orig.AsSpan(), Comparer<T>.Default); public static Dictionary<T, int> Compress<T>(IEnumerable<T> orig, IComparer<T> comparer) { var ox = new HashSet<T>(orig).ToArray(); Array.Sort(ox, comparer); var zip = new Dictionary<T, int>(); for (int i = 0; i < ox.Length; i++) zip[ox[i]] = i; return zip; } public static Dictionary<T, int> Compress<T>(ReadOnlySpan<T> orig, IComparer<T> comparer) { var hs = new HashSet<T>(orig.Length); foreach (var v in orig) hs.Add(v); var ox = hs.ToArray(); Array.Sort(ox, comparer); var zip = new Dictionary<T, int>(); for (int i = 0; i < ox.Length; i++) zip[ox[i]] = i; return zip; } public static int[] Compressed<T>(ReadOnlySpan<T> orig) where T : IComparable<T> { static int[] Compressed(ReadOnlySpan<T> orig, Dictionary<T, int> zip) { var res = new int[orig.Length]; for (int i = 0; i < res.Length; i++) res[i] = zip[orig[i]]; return res; } return Compressed(orig, Compress(orig, Comparer<T>.Default)); } } }
namespace AtCoder.IO { [DebuggerStepThrough] public class ConsoleReader { const int BufSize = 1 << 12; private readonly byte[] buffer = new byte[BufSize]; private readonly Stream input; private readonly Encoding encoding; private int pos = 0; private int len = 0; public ConsoleReader(Stream input, Encoding encoding) { this.input = input; this.encoding = encoding; } public ConsoleReader() : this(Console.OpenStandardInput(), Console.InputEncoding) { } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void MoveNext() { if (++pos >= len) { len = input.Read(buffer, 0, buffer.Length); if (len == 0) { buffer[0] = 10; } pos = 0; } } public int Int { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { int res = 0; bool neg = false; while (buffer[pos] < 48) { neg = buffer[pos] == 45; MoveNext(); } do { res = checked(res * 10 + (buffer[pos] ^ 48)); MoveNext(); } while (48 <= buffer[pos]); return neg ? -res : res; } } public int Int0 => Int - 1; public long Long { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { long res = 0; bool neg = false; while (buffer[pos] < 48) { neg = buffer[pos] == 45; MoveNext(); } do { res = res * 10 + (buffer[pos] ^ 48); MoveNext(); } while (48 <= buffer[pos]); return neg ? -res : res; } } public long Long0 => Long - 1; public string String { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var sb = new List<byte>(); while (buffer[pos] <= 32) MoveNext(); do { sb.Add(buffer[pos]); MoveNext(); } while (32 < buffer[pos]); return encoding.GetString(sb.ToArray()); } } public string Ascii { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var sb = new StringBuilder(); while (buffer[pos] <= 32) MoveNext(); do { sb.Append((char)buffer[pos]); MoveNext(); } while (32 < buffer[pos]); return sb.ToString(); } } public string Line { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var sb = new List<byte>(); while (buffer[pos] <= 32) MoveNext(); do { sb.Add(buffer[pos]); MoveNext(); } while (buffer[pos] != 10 && buffer[pos] != 13); return encoding.GetString(sb.ToArray()); } } public char Char { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { while (buffer[pos] <= 32) MoveNext(); char res = (char)buffer[pos]; MoveNext(); return res; } } public double Double => double.Parse(Ascii); [DebuggerStepThrough] public ref struct RepeatReader { readonly ConsoleReader cr; readonly int count; public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; } public T[] Select<T>(Func<ConsoleReader, T> factory) { var arr = new T[count]; for (var i = 0; i < count; i++) arr[i] = factory(cr); return arr; } public T[] Select<T>(Func<ConsoleReader, int, T> factory) { var arr = new T[count]; for (var i = 0; i < count; i++) arr[i] = factory(cr, i); return arr; } public string[] Line { get { var arr = new string[count]; for (var i = 0; i < count; i++) arr[i] = cr.Line; return arr; } } public string[] String { get { var arr = new string[count]; for (var i = 0; i < count; i++) arr[i] = cr.String; return arr; } } public string[] Ascii { get { var arr = new string[count]; for (var i = 0; i < count; i++) arr[i] = cr.Ascii; return arr; } } public int[] Int { get { var arr = new int[count]; for (var i = 0; i < count; i++) arr[i] = cr.Int; return arr; } } public int[] Int0 { get { var arr = new int[count]; for (var i = 0; i < count; i++) arr[i] = cr.Int0; return arr; } } public long[] Long { get { var arr = new long[count]; for (var i = 0; i < count; i++) arr[i] = cr.Long; return arr; } } public long[] Long0 { get { var arr = new long[count]; for (var i = 0; i < count; i++) arr[i] = cr.Long0; return arr; } } public double[] Double { get { var arr = new double[count]; for (var i = 0; i < count; i++) arr[i] = cr.Double; return arr; } } public static implicit operator int[](RepeatReader rr) => rr.Int; public static implicit operator long[](RepeatReader rr) => rr.Long; public static implicit operator double[](RepeatReader rr) => rr.Double; public static implicit operator string[](RepeatReader rr) => rr.Ascii; } public RepeatReader Repeat(int count) => new RepeatReader(this, count); [DebuggerStepThrough] public ref struct SplitReader { readonly ConsoleReader cr; public SplitReader(ConsoleReader cr) { this.cr = cr; } public string[] String { get { while (cr.buffer[cr.pos] <= 32) cr.MoveNext(); var list = new List<string>(); do { if (cr.buffer[cr.pos] < 32) cr.MoveNext(); else list.Add(cr.String); } while (cr.buffer[cr.pos] != 10 && cr.buffer[cr.pos] != 13); return list.ToArray(); } } public string[] Ascii { get { while (cr.buffer[cr.pos] <= 32) cr.MoveNext(); var list = new List<string>(); do { if (cr.buffer[cr.pos] < 32) cr.MoveNext(); else list.Add(cr.Ascii); } while (cr.buffer[cr.pos] != 10 && cr.buffer[cr.pos] != 13); return list.ToArray(); } } public int[] Int { get { while (cr.buffer[cr.pos] <= 32) cr.MoveNext(); var list = new List<int>(); do { if (cr.buffer[cr.pos] < 32) cr.MoveNext(); else list.Add(cr.Int); } while (cr.buffer[cr.pos] != 10 && cr.buffer[cr.pos] != 13); return list.ToArray(); } } public int[] Int0 { get { while (cr.buffer[cr.pos] <= 32) cr.MoveNext(); var list = new List<int>(); do { if (cr.buffer[cr.pos] < 32) cr.MoveNext(); else list.Add(cr.Int0); } while (cr.buffer[cr.pos] != 10 && cr.buffer[cr.pos] != 13); return list.ToArray(); } } public long[] Long { get { while (cr.buffer[cr.pos] <= 32) cr.MoveNext(); var list = new List<long>(); do { if (cr.buffer[cr.pos] < 32) cr.MoveNext(); else list.Add(cr.Long); } while (cr.buffer[cr.pos] != 10 && cr.buffer[cr.pos] != 13); return list.ToArray(); } } public long[] Long0 { get { while (cr.buffer[cr.pos] <= 32) cr.MoveNext(); var list = new List<long>(); do { if (cr.buffer[cr.pos] < 32) cr.MoveNext(); else list.Add(cr.Long0); } while (cr.buffer[cr.pos] != 10 && cr.buffer[cr.pos] != 13); return list.ToArray(); } } public double[] Double { get { while (cr.buffer[cr.pos] <= 32) cr.MoveNext(); var list = new List<double>(); do { if (cr.buffer[cr.pos] < 32) cr.MoveNext(); else list.Add(cr.Double); } while (cr.buffer[cr.pos] != 10 && cr.buffer[cr.pos] != 13); return list.ToArray(); } } public static implicit operator int[](SplitReader sr) => sr.Int; public static implicit operator long[](SplitReader sr) => sr.Long; public static implicit operator double[](SplitReader sr) => sr.Double; public static implicit operator string[](SplitReader sr) => sr.Ascii; } public SplitReader Split => new SplitReader(this); public static implicit operator int(ConsoleReader cr) => cr.Int; public static implicit operator long(ConsoleReader cr) => cr.Long; public static implicit operator double(ConsoleReader cr) => cr.Double; public static implicit operator string(ConsoleReader cr) => cr.Ascii; } }
namespace AtCoder.IO { [DebuggerStepThrough] public class ConsoleWriter { [DebuggerBrowsable(DebuggerBrowsableState.Never)] public readonly StreamWriter sw; public ConsoleWriter() : this(Console.OpenStandardOutput(), Console.OutputEncoding) { } public ConsoleWriter(Stream output, Encoding encoding) { sw = new StreamWriter(output, encoding); } public void Flush() => sw.Flush(); public ConsoleWriter WriteLine(ReadOnlySpan<char> obj) { sw.WriteLine(obj); return this; } public ConsoleWriter WriteLine<T>(T obj) { sw.WriteLine(obj.ToString()); return this; } public ConsoleWriter WriteLineJoin<T>(Span<T> col) => WriteMany(' ', (ReadOnlySpan<T>)col); public ConsoleWriter WriteLineJoin<T>(ReadOnlySpan<T> col) => WriteMany(' ', col); public ConsoleWriter WriteLineJoin<T>(IEnumerable<T> col) => WriteMany(' ', col); public ConsoleWriter WriteLineJoin<T>(params T[] col) => WriteMany(' ', col); public ConsoleWriter WriteLineJoin(params object[] col) => WriteMany(' ', col); public ConsoleWriter WriteLineJoin<T1, T2>(T1 v1, T2 v2) { sw.Write(v1.ToString()); sw.Write(' '); sw.WriteLine(v2.ToString()); return this; } public ConsoleWriter WriteLineJoin<T1, T2, T3>(T1 v1, T2 v2, T3 v3) { sw.Write(v1.ToString()); sw.Write(' '); sw.Write(v2.ToString()); sw.Write(' '); sw.WriteLine(v3.ToString()); return this; } public ConsoleWriter WriteLineJoin<T1, T2, T3, T4>(T1 v1, T2 v2, T3 v3, T4 v4) { sw.Write(v1.ToString()); sw.Write(' '); sw.Write(v2.ToString()); sw.Write(' '); sw.Write(v3.ToString()); sw.Write(' '); sw.WriteLine(v4.ToString()); return this; } public ConsoleWriter WriteLines<T>(Span<T> col) => WriteMany('\n', (ReadOnlySpan<T>)col); public ConsoleWriter WriteLines<T>(ReadOnlySpan<T> col) => WriteMany('\n', col); public ConsoleWriter WriteLines<T>(IEnumerable<T> col) => WriteMany('\n', col); public ConsoleWriter WriteLineGrid<T>(IEnumerable<IEnumerable<T>> cols) { foreach (var col in cols) WriteLineJoin(col); return this; } private ConsoleWriter WriteMany<T>(char sep, ReadOnlySpan<T> col) { var en = col.GetEnumerator(); if (!en.MoveNext()) return this; sw.Write(en.Current.ToString()); while (en.MoveNext()) { sw.Write(sep); sw.Write(en.Current.ToString()); } sw.WriteLine(); return this; } private ConsoleWriter WriteMany<T>(char sep, IEnumerable<T> col) { var en = col.GetEnumerator(); if (!en.MoveNext()) return this; sw.Write(en.Current.ToString()); while (en.MoveNext()) { sw.Write(sep); sw.Write(en.Current.ToString()); } sw.WriteLine(); return this; } } }
namespace AtCoder { public static class ExComparer<T> { class ExpressionComparer<K> : IComparer<T> where K : IComparable<K> { private class ParameterReplaceVisitor : ExpressionVisitor { private readonly ParameterExpression from; private readonly ParameterExpression to; public ParameterReplaceVisitor(ParameterExpression from, ParameterExpression to) { this.from = from; this.to = to; } protected override Expression VisitParameter(ParameterExpression node) => node == from ? to : base.VisitParameter(node); } readonly Comparison<T> func; public ExpressionComparer(Expression<Func<T, K>> expression) { var paramA = expression.Parameters[0]; var paramB = Expression.Parameter(typeof(T)); var f2 = (Expression<Func<T, K>>)new ParameterReplaceVisitor(expression.Parameters[0], paramB).Visit(expression); var compExp = Expression.Lambda<Comparison<T>>(Expression.Call( expression.Body, typeof(K).GetMethod(nameof(IComparable<K>.CompareTo), new[] { typeof(K) }), f2.Body), paramA, paramB); this.func = compExp.Compile(); } public int Compare(T x, T y) => func(x, y); public override bool Equals(object obj) => obj is ExpressionComparer<K> c && this.func == c.func; public override int GetHashCode() => func.GetHashCode(); } class ReverseComparer : IComparer<T> { private static readonly Comparer<T> orig = Comparer<T>.Default; public int Compare(T y, T x) => orig.Compare(x, y); public override bool Equals(object obj) => obj is ReverseComparer; public override int GetHashCode() => GetType().GetHashCode(); } public static IComparer<T> CreateExp<K>(Expression<Func<T, K>> expression) where K : IComparable<K> => new ExpressionComparer<K>(expression); public static readonly IComparer<T> DefaultReverse = new ReverseComparer(); } }
namespace AtCoder { internal class ArrayVal<T> { public T[] arr; } }
#endregion Expanded
提出情報
コンパイルエラー
Program.cs(189,61): warning CS0649: Field 'ArrayVal<T>.arr' is never assigned to, and will always have its default value null [/imojudge/csharp/csharp.csproj]
ジャッジ結果
セット名 |
Set01 |
Set02 |
Set03 |
Set04 |
Set05 |
Set06 |
Set07 |
Set08 |
Set09 |
Set10 |
得点 / 配点 |
10 / 10 |
10 / 10 |
10 / 10 |
10 / 10 |
10 / 10 |
10 / 10 |
10 / 10 |
10 / 10 |
10 / 10 |
10 / 10 |
結果 |
|
|
|
|
|
|
|
|
|
|
セット名 |
テストケース |
Set01 |
01-01, 01-02, 01-03 |
Set02 |
02-01, 02-02, 02-03 |
Set03 |
03-01, 03-02, 03-03 |
Set04 |
04-01, 04-02, 04-03 |
Set05 |
05-01, 05-02, 05-03 |
Set06 |
06-01, 06-02, 06-03 |
Set07 |
07-01, 07-02, 07-03 |
Set08 |
08-01, 08-02, 08-03 |
Set09 |
09-01, 09-02, 09-03 |
Set10 |
10-01, 10-02, 10-03 |
ケース名 |
結果 |
実行時間 |
メモリ |
01-01 |
AC |
94 ms |
27336 KiB |
01-02 |
AC |
88 ms |
28188 KiB |
01-03 |
AC |
93 ms |
28220 KiB |
02-01 |
AC |
91 ms |
27348 KiB |
02-02 |
AC |
86 ms |
28292 KiB |
02-03 |
AC |
88 ms |
28500 KiB |
03-01 |
AC |
89 ms |
28536 KiB |
03-02 |
AC |
96 ms |
28444 KiB |
03-03 |
AC |
88 ms |
28336 KiB |
04-01 |
AC |
95 ms |
27664 KiB |
04-02 |
AC |
128 ms |
38216 KiB |
04-03 |
AC |
126 ms |
38912 KiB |
05-01 |
AC |
91 ms |
27648 KiB |
05-02 |
AC |
136 ms |
42120 KiB |
05-03 |
AC |
136 ms |
41188 KiB |
06-01 |
AC |
141 ms |
40920 KiB |
06-02 |
AC |
159 ms |
41040 KiB |
06-03 |
AC |
148 ms |
41212 KiB |
07-01 |
AC |
94 ms |
28264 KiB |
07-02 |
AC |
203 ms |
44864 KiB |
07-03 |
AC |
201 ms |
47648 KiB |
08-01 |
AC |
95 ms |
28412 KiB |
08-02 |
AC |
228 ms |
48524 KiB |
08-03 |
AC |
231 ms |
52392 KiB |
09-01 |
AC |
196 ms |
54696 KiB |
09-02 |
AC |
228 ms |
44820 KiB |
09-03 |
AC |
242 ms |
48852 KiB |
10-01 |
AC |
97 ms |
28756 KiB |
10-02 |
AC |
238 ms |
46232 KiB |
10-03 |
AC |
263 ms |
50756 KiB |