結果

問題 No.1512 作文
ユーザー ks2mks2m
提出日時 2021-05-21 21:28:40
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 745 bytes
コンパイル時間 2,130 ms
コンパイル使用メモリ 77,340 KB
実行使用メモリ 65,856 KB
最終ジャッジ日時 2024-04-18 14:31:01
合計ジャッジ時間 14,923 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 135 ms
41,428 KB
testcase_02 AC 127 ms
41,288 KB
testcase_03 AC 135 ms
41,468 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 212 ms
42,440 KB
testcase_10 AC 268 ms
42,964 KB
testcase_11 AC 213 ms
42,292 KB
testcase_12 AC 264 ms
42,916 KB
testcase_13 AC 215 ms
42,280 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 170 ms
41,944 KB
testcase_22 AC 138 ms
41,328 KB
testcase_23 AC 170 ms
41,544 KB
testcase_24 AC 172 ms
41,612 KB
testcase_25 WA -
testcase_26 AC 135 ms
41,460 KB
testcase_27 AC 130 ms
41,268 KB
testcase_28 AC 135 ms
41,832 KB
testcase_29 AC 120 ms
40,228 KB
testcase_30 AC 139 ms
41,608 KB
testcase_31 AC 143 ms
41,660 KB
testcase_32 AC 143 ms
41,408 KB
testcase_33 AC 138 ms
41,432 KB
testcase_34 AC 171 ms
41,508 KB
testcase_35 AC 219 ms
43,376 KB
testcase_36 AC 220 ms
43,188 KB
testcase_37 AC 179 ms
42,816 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 773 ms
65,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
		String[] s = new String[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.next();
		}
		sc.close();

		int[] dp = new int[26];
		label:
		for (int i = 0; i < n; i++) {
			char[] t = s[i].toCharArray();
			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);
	}
}
0