結果
問題 | No.962 LCPs |
ユーザー | 37zigen |
提出日時 | 2020-04-07 01:41:52 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 130 ms / 2,000 ms |
コード長 | 3,128 bytes |
コンパイル時間 | 2,469 ms |
コンパイル使用メモリ | 77,748 KB |
実行使用メモリ | 49,872 KB |
最終ジャッジ日時 | 2024-07-07 10:38:35 |
合計ジャッジ時間 | 9,562 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
36,444 KB |
testcase_01 | AC | 43 ms
36,968 KB |
testcase_02 | AC | 49 ms
37,280 KB |
testcase_03 | AC | 50 ms
37,436 KB |
testcase_04 | AC | 47 ms
37,068 KB |
testcase_05 | AC | 49 ms
36,908 KB |
testcase_06 | AC | 48 ms
36,544 KB |
testcase_07 | AC | 49 ms
37,024 KB |
testcase_08 | AC | 50 ms
37,048 KB |
testcase_09 | AC | 49 ms
36,864 KB |
testcase_10 | AC | 49 ms
36,852 KB |
testcase_11 | AC | 47 ms
36,780 KB |
testcase_12 | AC | 47 ms
36,896 KB |
testcase_13 | AC | 45 ms
36,768 KB |
testcase_14 | AC | 45 ms
36,640 KB |
testcase_15 | AC | 43 ms
36,880 KB |
testcase_16 | AC | 47 ms
36,960 KB |
testcase_17 | AC | 130 ms
49,872 KB |
testcase_18 | AC | 123 ms
46,652 KB |
testcase_19 | AC | 125 ms
46,692 KB |
testcase_20 | AC | 109 ms
45,992 KB |
testcase_21 | AC | 115 ms
46,100 KB |
testcase_22 | AC | 102 ms
44,432 KB |
testcase_23 | AC | 106 ms
44,388 KB |
testcase_24 | AC | 124 ms
44,728 KB |
testcase_25 | AC | 104 ms
44,704 KB |
testcase_26 | AC | 104 ms
44,460 KB |
testcase_27 | AC | 109 ms
46,112 KB |
testcase_28 | AC | 102 ms
44,536 KB |
testcase_29 | AC | 102 ms
44,572 KB |
testcase_30 | AC | 106 ms
44,484 KB |
testcase_31 | AC | 116 ms
45,852 KB |
testcase_32 | AC | 105 ms
44,536 KB |
testcase_33 | AC | 120 ms
46,556 KB |
testcase_34 | AC | 105 ms
44,776 KB |
testcase_35 | AC | 107 ms
44,336 KB |
testcase_36 | AC | 109 ms
44,712 KB |
testcase_37 | AC | 109 ms
42,960 KB |
testcase_38 | AC | 108 ms
42,972 KB |
testcase_39 | AC | 108 ms
42,840 KB |
testcase_40 | AC | 105 ms
43,048 KB |
testcase_41 | AC | 107 ms
43,096 KB |
testcase_42 | AC | 109 ms
43,268 KB |
testcase_43 | AC | 106 ms
43,072 KB |
testcase_44 | AC | 101 ms
43,104 KB |
testcase_45 | AC | 106 ms
42,812 KB |
testcase_46 | AC | 101 ms
42,912 KB |
testcase_47 | AC | 80 ms
39,160 KB |
testcase_48 | AC | 84 ms
38,700 KB |
testcase_49 | AC | 85 ms
39,344 KB |
testcase_50 | AC | 87 ms
39,544 KB |
testcase_51 | AC | 82 ms
38,964 KB |
testcase_52 | AC | 81 ms
38,448 KB |
testcase_53 | AC | 84 ms
38,764 KB |
testcase_54 | AC | 81 ms
38,856 KB |
testcase_55 | AC | 78 ms
38,524 KB |
testcase_56 | AC | 85 ms
39,088 KB |
testcase_57 | AC | 99 ms
39,752 KB |
testcase_58 | AC | 97 ms
39,752 KB |
testcase_59 | AC | 100 ms
39,892 KB |
testcase_60 | AC | 92 ms
39,956 KB |
testcase_61 | AC | 103 ms
39,424 KB |
testcase_62 | AC | 105 ms
39,756 KB |
testcase_63 | AC | 126 ms
47,772 KB |
testcase_64 | AC | 88 ms
39,324 KB |
testcase_65 | AC | 126 ms
47,716 KB |
ソースコード
import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.NoSuchElementException; public class Main implements Runnable{ public static void main(String[] args) { new Thread(null,new Main(), "" ,Runtime.getRuntime().maxMemory()).start(); } public void run() { FastScanner sc=new FastScanner(); long ans=0; int N=sc.nextInt(); char[][] cs=new char[N][]; int[] LCP=new int[N]; for(int i=0;i<N;++i) { cs[i]=sc.next().toCharArray(); } long cur=0,single=0; for(int L=0;L<N;++L) { cur+=cs[L].length-LCP[L]; single+=cs[L].length-LCP[L]; LCP[L]=cs[L].length; for(int R=L+1;R<N;++R) { boolean update=false; while(LCP[R]<LCP[R-1]&&LCP[R]<cs[R].length&&cs[R][LCP[R]]==cs[R-1][LCP[R]]) { ++LCP[R]; cur+=(R-L+1); ++single; update=true; } if(!update)break; } ans+=cur; cur-=single; single-=LCP[L]; } System.out.println(ans); } void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));} } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }