結果

問題 No.1512 作文
ユーザー 小野寺健小野寺健
提出日時 2021-05-22 13:23:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,123 ms / 2,000 ms
コード長 1,395 bytes
コンパイル時間 5,130 ms
コンパイル使用メモリ 79,492 KB
実行使用メモリ 91,908 KB
最終ジャッジ日時 2024-04-18 17:38:16
合計ジャッジ時間 19,501 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
41,436 KB
testcase_01 AC 132 ms
41,552 KB
testcase_02 AC 131 ms
41,168 KB
testcase_03 AC 130 ms
41,580 KB
testcase_04 AC 918 ms
73,492 KB
testcase_05 AC 865 ms
73,428 KB
testcase_06 AC 872 ms
73,216 KB
testcase_07 AC 853 ms
73,228 KB
testcase_08 AC 911 ms
73,488 KB
testcase_09 AC 188 ms
42,108 KB
testcase_10 AC 200 ms
42,412 KB
testcase_11 AC 198 ms
42,020 KB
testcase_12 AC 199 ms
42,456 KB
testcase_13 AC 262 ms
42,452 KB
testcase_14 AC 271 ms
48,196 KB
testcase_15 AC 268 ms
48,520 KB
testcase_16 AC 292 ms
48,456 KB
testcase_17 AC 325 ms
48,212 KB
testcase_18 AC 269 ms
48,040 KB
testcase_19 AC 274 ms
48,852 KB
testcase_20 AC 269 ms
48,652 KB
testcase_21 AC 160 ms
41,836 KB
testcase_22 AC 132 ms
41,428 KB
testcase_23 AC 161 ms
41,640 KB
testcase_24 AC 159 ms
41,584 KB
testcase_25 AC 158 ms
41,492 KB
testcase_26 AC 129 ms
41,168 KB
testcase_27 AC 128 ms
41,532 KB
testcase_28 AC 125 ms
41,772 KB
testcase_29 AC 137 ms
41,312 KB
testcase_30 AC 130 ms
41,620 KB
testcase_31 AC 134 ms
41,900 KB
testcase_32 AC 135 ms
41,532 KB
testcase_33 AC 134 ms
41,320 KB
testcase_34 AC 167 ms
41,804 KB
testcase_35 AC 215 ms
43,484 KB
testcase_36 AC 212 ms
43,284 KB
testcase_37 AC 197 ms
42,660 KB
testcase_38 AC 211 ms
42,728 KB
testcase_39 AC 223 ms
42,356 KB
testcase_40 AC 1,123 ms
91,172 KB
testcase_41 AC 819 ms
91,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

public class No1512 {
	
	private static class MyComparator implements Comparator<String> {
		@Override
		public int compare(String s1, String s2) {
			if (s1.charAt(0) < s2.charAt(0)) {
				return -1;
			} else if (s1.charAt(0) > s2.charAt(0)) {
				return 1;
			} else {
				return s1.charAt(s1.length()-1) - s2.charAt(s2.length()-1);
			}
		}
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<String> S = new ArrayList<String>();
		for (int i=0; i < N; i++) {
			String s = scan.next();
			boolean reverse = false;
			char prev = 0;
			for (int j=0; j < s.length(); j++) {
				char c = s.charAt(j);
				if (prev > c) {
					reverse = true;
					break;
				}
				prev = c;
			}
			if (!reverse) {
				S.add(s);
			}
		}
		scan.close();
		Collections.sort(S, new MyComparator());
		int[][] DP = new int[S.size()+1][26];
		for (int i=0; i < S.size(); i++) {
			String s = S.get(i);
			int e = s.charAt(s.length()-1) - 'a';
			int n = DP[i][s.charAt(0) - 'a'] + s.length();
			for (int j = 0; j < e; j++) {
				DP[i+1][j] = DP[i][j];
			}
			for (int j=e; j < 26; j++) {
				DP[i+1][j] = Math.max(DP[i][j], n);
			}
		}
		System.out.println(DP[S.size()][25]);
	}

}
0