結果

問題 No.1512 作文
ユーザー ks2mks2m
提出日時 2021-05-21 21:32:39
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 921 bytes
コンパイル時間 2,915 ms
コンパイル使用メモリ 81,004 KB
実行使用メモリ 73,912 KB
最終ジャッジ日時 2024-04-18 14:42:14
合計ジャッジ時間 15,792 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
54,084 KB
testcase_01 AC 135 ms
54,024 KB
testcase_02 AC 136 ms
54,120 KB
testcase_03 AC 138 ms
53,776 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 184 ms
54,520 KB
testcase_10 AC 225 ms
54,400 KB
testcase_11 AC 194 ms
54,460 KB
testcase_12 AC 233 ms
54,424 KB
testcase_13 AC 183 ms
54,544 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 155 ms
54,136 KB
testcase_22 AC 135 ms
54,104 KB
testcase_23 AC 156 ms
54,360 KB
testcase_24 AC 159 ms
54,168 KB
testcase_25 AC 159 ms
54,276 KB
testcase_26 AC 126 ms
54,152 KB
testcase_27 AC 137 ms
53,972 KB
testcase_28 AC 131 ms
53,820 KB
testcase_29 AC 134 ms
53,936 KB
testcase_30 AC 137 ms
53,992 KB
testcase_31 AC 145 ms
54,196 KB
testcase_32 AC 147 ms
54,280 KB
testcase_33 AC 130 ms
54,144 KB
testcase_34 AC 167 ms
54,480 KB
testcase_35 AC 207 ms
56,252 KB
testcase_36 AC 214 ms
56,512 KB
testcase_37 AC 191 ms
54,220 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 858 ms
73,912 KB
testcase_41 AC 719 ms
70,064 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) -> o1.s[o1.s.length - 1] - o2.s[o2.s.length - 1]);
		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