結果

問題 No.1512 作文
ユーザー ks2mks2m
提出日時 2021-05-21 21:39:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 897 ms / 2,000 ms
コード長 1,044 bytes
コンパイル時間 3,010 ms
コンパイル使用メモリ 89,708 KB
実行使用メモリ 64,596 KB
最終ジャッジ日時 2024-04-18 14:56:13
合計ジャッジ時間 15,665 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
41,716 KB
testcase_01 AC 126 ms
41,292 KB
testcase_02 AC 131 ms
41,704 KB
testcase_03 AC 131 ms
41,392 KB
testcase_04 AC 727 ms
59,852 KB
testcase_05 AC 715 ms
59,736 KB
testcase_06 AC 704 ms
60,836 KB
testcase_07 AC 723 ms
59,688 KB
testcase_08 AC 721 ms
59,584 KB
testcase_09 AC 200 ms
42,316 KB
testcase_10 AC 201 ms
42,760 KB
testcase_11 AC 190 ms
42,200 KB
testcase_12 AC 195 ms
42,988 KB
testcase_13 AC 202 ms
42,560 KB
testcase_14 AC 305 ms
49,700 KB
testcase_15 AC 303 ms
49,712 KB
testcase_16 AC 303 ms
49,692 KB
testcase_17 AC 300 ms
49,504 KB
testcase_18 AC 305 ms
49,580 KB
testcase_19 AC 306 ms
49,352 KB
testcase_20 AC 310 ms
49,528 KB
testcase_21 AC 161 ms
41,980 KB
testcase_22 AC 135 ms
41,644 KB
testcase_23 AC 168 ms
41,884 KB
testcase_24 AC 164 ms
41,576 KB
testcase_25 AC 163 ms
42,448 KB
testcase_26 AC 129 ms
41,584 KB
testcase_27 AC 128 ms
41,384 KB
testcase_28 AC 126 ms
41,688 KB
testcase_29 AC 115 ms
41,400 KB
testcase_30 AC 119 ms
41,684 KB
testcase_31 AC 121 ms
41,552 KB
testcase_32 AC 138 ms
41,416 KB
testcase_33 AC 130 ms
41,556 KB
testcase_34 AC 168 ms
41,792 KB
testcase_35 AC 213 ms
44,136 KB
testcase_36 AC 212 ms
43,296 KB
testcase_37 AC 198 ms
42,424 KB
testcase_38 AC 215 ms
42,964 KB
testcase_39 AC 218 ms
42,500 KB
testcase_40 AC 897 ms
64,596 KB
testcase_41 AC 728 ms
60,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
	}
}
0