結果
問題 | No.1512 作文 |
ユーザー | tenten |
提出日時 | 2022-08-05 12:48:06 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 901 ms / 2,000 ms |
コード長 | 2,702 bytes |
コンパイル時間 | 2,211 ms |
コンパイル使用メモリ | 79,092 KB |
実行使用メモリ | 136,220 KB |
最終ジャッジ日時 | 2024-09-15 08:32:26 |
合計ジャッジ時間 | 11,936 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
50,516 KB |
testcase_01 | AC | 54 ms
50,584 KB |
testcase_02 | AC | 52 ms
50,244 KB |
testcase_03 | AC | 53 ms
50,304 KB |
testcase_04 | AC | 527 ms
91,376 KB |
testcase_05 | AC | 523 ms
91,716 KB |
testcase_06 | AC | 513 ms
91,276 KB |
testcase_07 | AC | 520 ms
92,884 KB |
testcase_08 | AC | 515 ms
91,332 KB |
testcase_09 | AC | 106 ms
51,776 KB |
testcase_10 | AC | 93 ms
51,944 KB |
testcase_11 | AC | 96 ms
51,908 KB |
testcase_12 | AC | 109 ms
54,060 KB |
testcase_13 | AC | 108 ms
51,932 KB |
testcase_14 | AC | 147 ms
55,572 KB |
testcase_15 | AC | 135 ms
54,972 KB |
testcase_16 | AC | 136 ms
55,688 KB |
testcase_17 | AC | 136 ms
54,988 KB |
testcase_18 | AC | 136 ms
55,736 KB |
testcase_19 | AC | 136 ms
55,660 KB |
testcase_20 | AC | 147 ms
54,988 KB |
testcase_21 | AC | 59 ms
50,548 KB |
testcase_22 | AC | 56 ms
50,244 KB |
testcase_23 | AC | 60 ms
50,132 KB |
testcase_24 | AC | 63 ms
50,404 KB |
testcase_25 | AC | 61 ms
50,412 KB |
testcase_26 | AC | 53 ms
50,532 KB |
testcase_27 | AC | 54 ms
50,312 KB |
testcase_28 | AC | 54 ms
49,944 KB |
testcase_29 | AC | 54 ms
50,084 KB |
testcase_30 | AC | 52 ms
50,392 KB |
testcase_31 | AC | 53 ms
50,140 KB |
testcase_32 | AC | 57 ms
50,320 KB |
testcase_33 | AC | 54 ms
50,512 KB |
testcase_34 | AC | 60 ms
50,468 KB |
testcase_35 | AC | 107 ms
51,976 KB |
testcase_36 | AC | 103 ms
51,844 KB |
testcase_37 | AC | 101 ms
51,788 KB |
testcase_38 | AC | 119 ms
51,964 KB |
testcase_39 | AC | 123 ms
52,132 KB |
testcase_40 | AC | 901 ms
136,220 KB |
testcase_41 | AC | 718 ms
116,636 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { static ArrayList<Word> words = new ArrayList<>(); static int[][] dp; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); while (n-- > 0) { Word tmp = new Word(sc.next()); if (tmp.isGood()) { words.add(tmp); } } Collections.sort(words); dp = new int[words.size()][26]; for (int[] arr : dp) { Arrays.fill(arr, -1); } System.out.println(dfw(words.size() - 1, 25)); } static int dfw(int idx, int c) { if (idx < 0) { return 0; } if (dp[idx][c] < 0) { Word current = words.get(idx); if (current.right <= c) { dp[idx][c] = Math.max(dfw(idx - 1, c), dfw(idx - 1, current.left) + current.length()); } else { dp[idx][c] = dfw(idx - 1, c); } } return dp[idx][c]; } static class Word implements Comparable<Word> { String name; int left; int right; boolean good; public Word(String name) { this.name = name; char prev = 'a'; good = true; for (char c : name.toCharArray()) { if (prev > c) { good = false; break; } prev = c; } left = name.charAt(0) - 'a'; right = prev - 'a'; } public int compareTo(Word another) { if (right == another.right) { return left - another.left; } else { return right - another.right; } } public int length() { return name.length(); } public boolean isGood() { return good; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }