結果
| 問題 |
No.1512 作文
|
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2021-05-21 21:39:47 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 906 ms / 2,000 ms |
| コード長 | 1,044 bytes |
| コンパイル時間 | 2,483 ms |
| コンパイル使用メモリ | 84,488 KB |
| 実行使用メモリ | 73,960 KB |
| 最終ジャッジ日時 | 2024-10-10 08:11:44 |
| 合計ジャッジ時間 | 16,058 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 |
ソースコード
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Obj[] arr = new Obj[n];
for (int i = 0; i < n; i++) {
Obj o = new Obj();
o.s = sc.next().toCharArray();
arr[i] = o;
}
sc.close();
Arrays.sort(arr, (o1, o2) -> {
int s1 = o1.s.length;
int s2 = o2.s.length;
if (o1.s[s1 - 1] != o2.s[s2 - 1]) {
return o1.s[s1 - 1] - o2.s[s2 - 1];
}
return o1.s[0] - o2.s[0];
});
int[] dp = new int[26];
label:
for (int i = 0; i < n; i++) {
char[] t = arr[i].s;
for (int j = 1; j < t.length; j++) {
if (t[j - 1] > t[j]) {
continue label;
}
}
int d0 = t[0] - 'a';
int d1 = t[t.length - 1] - 'a';
for (int j = d0; j >= 0; j--) {
dp[d1] = Math.max(dp[d1], dp[j] + t.length);
}
}
int ans = 0;
for (int i = 0; i < dp.length; i++) {
ans = Math.max(ans, dp[i]);
}
System.out.println(ans);
}
static class Obj {
char[] s;
}
}
ks2m