結果
問題 | No.515 典型LCP |
ユーザー | くれちー |
提出日時 | 2017-07-27 14:58:55 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,573 bytes |
コンパイル時間 | 1,050 ms |
コンパイル使用メモリ | 118,592 KB |
実行使用メモリ | 58,132 KB |
最終ジャッジ日時 | 2024-10-10 02:06:55 |
合計ジャッジ時間 | 5,612 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | -- | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using static System.Console; using static System.Convert; using static System.Math; using static Extentions; class IO { int idx; string[] input; public IO(TextReader reader) { input = reader.ReadToEnd().Split(new[] { " ", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries); } T Get<T>(Func<string, T> parser) => parser(input[idx++]); public string S => Get(s => s); public char C => Get(char.Parse); public int I => Get(int.Parse); public long L => Get(long.Parse); public double F => Get(double.Parse); public decimal D => Get(decimal.Parse); public BigInteger B => Get(BigInteger.Parse); T[] Gets<T>(int n, Func<string, T> parser) => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray(); public string[] Ss(int n) => Gets(n, s => s); public char[] Cs(int n) => Gets(n, char.Parse); public int[] Is(int n) => Gets(n, int.Parse); public long[] Ls(int n) => Gets(n, long.Parse); public double[] Fs(int n) => Gets(n, double.Parse); public decimal[] Ds(int n) => Gets(n, decimal.Parse); public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse); public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs)); public void Write(params object[] xs) => WriteLine(string.Join(" ", xs)); } static class Pair { public static Pair<T1, T2> Create<T1, T2>(T1 first, T2 second) => new Pair<T1, T2>(first, second); } struct Pair<T1, T2> { public T1 First; public T2 Second; public Pair(T1 first, T2 second) { First = first; Second = second; } } class SparseTable { int[] xs, logTable; int[,] table; int n; public SparseTable(int[] xs) { n = xs.Length; this.xs = xs; logTable = new int[n + 1]; for (var i = 2; i <= n; i++) logTable[i] = logTable[i >> 1] + 1; table = new int[n, logTable[n] + 1]; for (var i = 0; i < n; i++) table[i, 0] = i; for (var k = 1; (1 << k) <= n; k++) { for (var i = 0; i + (1 << k) <= n; i++) { var a = table[i, k - 1]; var b = table[i + (1 << (k - 1)), k - 1]; table[i, k] = xs[a] < xs[b] ? a : b; } } } public int Query(int i, int j) { var k = logTable[j - i + 1]; return Min(xs[table[i, k]], xs[table[j - (1 << k) + 1, k]]); } } static class Extentions { public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } public static IOrderedEnumerable<T> Shuffle<T>( this IEnumerable<T> seq, Random rand) => seq.OrderBy(x => rand.Next()); } static class Program { public static void Main() { var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" }; #if DEBUG sw.AutoFlush = true; #else sw.AutoFlush = false; #endif SetOut(sw); Solve(new IO(In)); Out.Flush(); } static int Lcp(string a, string b) { var cnt = 0; var len = Min(a.Length, b.Length); for (var i = 0; i < len; i++) if (a[i] == b[i]) cnt++; else break; return cnt; } static void Solve(IO io) { var n = io.I; var s = io.Ss(n); var m = io.I; var x = io.L; var d = io.L; var rand = new Random(); var ss = s.Select(Pair.Create).Shuffle(rand).ToArray(); Array.Sort(ss, (a, b) => a.First.CompareTo(b.First)); var tsi = ss.Select((a, i) => Pair.Create(a.Second, i)) .Shuffle(rand).ToArray(); Array.Sort(tsi, (a, b) => a.First.CompareTo(b.First)); var si = tsi.Select(a => a.Second).ToArray(); var lcplen = new int[n - 1]; for (var i = 0; i < n - 1; i++) lcplen[i] = Lcp(ss[i].First, ss[i + 1].First); var st = new SparseTable(lcplen); var ans = 0; for (var k = 0; k < m; k++) { var i = x / (n - 1) + 1; var j = x % (n - 1) + 1; if (i > j) Swap(ref i, ref j); else j = j + 1; var p = si[i - 1]; var q = si[j - 1]; if (p > q) Swap(ref p, ref q); var t = st.Query(p, q - 1); ans += t; x = (x + d) % ((long)n * (n - 1)); } io.Write(ans); } }