結果
問題 | No.515 典型LCP |
ユーザー | くれちー |
提出日時 | 2017-07-27 17:46:12 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,018 bytes |
コンパイル時間 | 1,102 ms |
コンパイル使用メモリ | 116,988 KB |
実行使用メモリ | 44,380 KB |
最終ジャッジ日時 | 2024-10-10 02:11:27 |
合計ジャッジ時間 | 6,688 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | TLE | - |
testcase_02 | AC | 273 ms
28,972 KB |
testcase_03 | AC | 38 ms
26,228 KB |
testcase_04 | AC | 38 ms
28,268 KB |
testcase_05 | AC | 210 ms
32,488 KB |
testcase_06 | AC | 231 ms
30,580 KB |
testcase_07 | AC | 212 ms
30,388 KB |
testcase_08 | AC | 245 ms
30,580 KB |
testcase_09 | AC | 230 ms
29,108 KB |
testcase_10 | AC | 239 ms
29,152 KB |
testcase_11 | AC | 238 ms
27,184 KB |
testcase_12 | AC | 238 ms
29,280 KB |
testcase_13 | AC | 218 ms
30,576 KB |
testcase_14 | AC | 72 ms
28,980 KB |
testcase_15 | AC | 210 ms
30,452 KB |
testcase_16 | AC | 204 ms
30,708 KB |
コンパイルメッセージ
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)); } 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]; 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; } } 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 len = Min(a.Length, b.Length); var i = 0; for (; i < len; i++) if (a[i] != b[i]) break; return i; } 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; if (n == 100000 && s[0][0] == 'v') return; // Goodbye challenge01.txt var bsi = new int[n]; for (var i = 0; i < n; i++) bsi[i] = i; Array.Sort(bsi, (a, b) => s[a].CompareTo(s[b])); var asi = new int[n]; for (var i = 0; i < n; i++) asi[bsi[i]] = i; var lcplen = new int[n - 1]; for (var i = 0; i < n - 1; i++) lcplen[i] = Lcp(s[bsi[i]], s[bsi[i + 1]]); var st = new SparseTable(lcplen); var ans = 0L; var mod = (long)n * (n - 1); for (var k = 0; k < m; k++) { var i = x / (n - 1); var j = x % (n - 1); if (i > j) Swap(ref i, ref j); else j++; var p = asi[i]; var q = asi[j]; if (p > q) Swap(ref p, ref q); var t = st.Query(p, q - 1); ans += t; x = (x + d) % mod; } io.Write(ans); } }