結果
問題 | No.962 LCPs |
ユーザー | 37zigen |
提出日時 | 2020-04-07 01:41:52 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 154 ms / 2,000 ms |
コード長 | 3,128 bytes |
コンパイル時間 | 2,855 ms |
コンパイル使用メモリ | 74,504 KB |
実行使用メモリ | 61,412 KB |
最終ジャッジ日時 | 2023-09-21 16:58:47 |
合計ジャッジ時間 | 12,543 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
51,044 KB |
testcase_01 | AC | 45 ms
51,132 KB |
testcase_02 | AC | 51 ms
51,188 KB |
testcase_03 | AC | 50 ms
51,136 KB |
testcase_04 | AC | 50 ms
49,168 KB |
testcase_05 | AC | 49 ms
51,204 KB |
testcase_06 | AC | 47 ms
51,240 KB |
testcase_07 | AC | 50 ms
51,284 KB |
testcase_08 | AC | 50 ms
51,312 KB |
testcase_09 | AC | 49 ms
51,188 KB |
testcase_10 | AC | 49 ms
51,260 KB |
testcase_11 | AC | 48 ms
51,240 KB |
testcase_12 | AC | 46 ms
51,080 KB |
testcase_13 | AC | 45 ms
51,144 KB |
testcase_14 | AC | 47 ms
51,224 KB |
testcase_15 | AC | 44 ms
51,224 KB |
testcase_16 | AC | 48 ms
51,064 KB |
testcase_17 | AC | 154 ms
61,412 KB |
testcase_18 | AC | 131 ms
59,368 KB |
testcase_19 | AC | 118 ms
59,708 KB |
testcase_20 | AC | 118 ms
57,964 KB |
testcase_21 | AC | 117 ms
57,344 KB |
testcase_22 | AC | 113 ms
57,088 KB |
testcase_23 | AC | 109 ms
57,260 KB |
testcase_24 | AC | 110 ms
57,312 KB |
testcase_25 | AC | 113 ms
57,076 KB |
testcase_26 | AC | 99 ms
57,116 KB |
testcase_27 | AC | 116 ms
57,524 KB |
testcase_28 | AC | 107 ms
57,104 KB |
testcase_29 | AC | 110 ms
57,268 KB |
testcase_30 | AC | 110 ms
57,560 KB |
testcase_31 | AC | 115 ms
57,528 KB |
testcase_32 | AC | 112 ms
57,292 KB |
testcase_33 | AC | 125 ms
59,740 KB |
testcase_34 | AC | 110 ms
57,332 KB |
testcase_35 | AC | 114 ms
57,428 KB |
testcase_36 | AC | 110 ms
57,236 KB |
testcase_37 | AC | 104 ms
56,900 KB |
testcase_38 | AC | 107 ms
56,924 KB |
testcase_39 | AC | 109 ms
57,064 KB |
testcase_40 | AC | 110 ms
57,020 KB |
testcase_41 | AC | 111 ms
56,980 KB |
testcase_42 | AC | 113 ms
57,124 KB |
testcase_43 | AC | 111 ms
57,308 KB |
testcase_44 | AC | 111 ms
56,880 KB |
testcase_45 | AC | 110 ms
57,156 KB |
testcase_46 | AC | 109 ms
57,372 KB |
testcase_47 | AC | 91 ms
54,356 KB |
testcase_48 | AC | 90 ms
53,556 KB |
testcase_49 | AC | 92 ms
53,540 KB |
testcase_50 | AC | 90 ms
53,568 KB |
testcase_51 | AC | 81 ms
53,024 KB |
testcase_52 | AC | 89 ms
52,880 KB |
testcase_53 | AC | 90 ms
52,996 KB |
testcase_54 | AC | 88 ms
53,216 KB |
testcase_55 | AC | 89 ms
53,536 KB |
testcase_56 | AC | 88 ms
53,020 KB |
testcase_57 | AC | 103 ms
54,720 KB |
testcase_58 | AC | 101 ms
54,168 KB |
testcase_59 | AC | 103 ms
54,340 KB |
testcase_60 | AC | 111 ms
54,496 KB |
testcase_61 | AC | 112 ms
54,192 KB |
testcase_62 | AC | 111 ms
54,024 KB |
testcase_63 | AC | 130 ms
59,068 KB |
testcase_64 | AC | 80 ms
52,968 KB |
testcase_65 | AC | 131 ms
59,944 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());} }