結果

問題 No.205 マージして辞書順最小
ユーザー GrenacheGrenache
提出日時 2015-05-08 23:06:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 201 ms / 5,000 ms
コード長 867 bytes
コンパイル時間 5,645 ms
コンパイル使用メモリ 73,824 KB
実行使用メモリ 44,780 KB
最終ジャッジ日時 2023-09-19 07:50:27
合計ジャッジ時間 8,007 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
39,764 KB
testcase_01 AC 124 ms
39,616 KB
testcase_02 AC 149 ms
41,480 KB
testcase_03 AC 146 ms
41,992 KB
testcase_04 AC 146 ms
41,048 KB
testcase_05 AC 145 ms
41,044 KB
testcase_06 AC 131 ms
39,376 KB
testcase_07 AC 194 ms
44,468 KB
testcase_08 AC 193 ms
44,444 KB
testcase_09 AC 195 ms
44,780 KB
testcase_10 AC 193 ms
40,764 KB
testcase_11 AC 201 ms
44,384 KB
testcase_12 AC 194 ms
44,412 KB
testcase_13 AC 192 ms
44,316 KB
testcase_14 AC 130 ms
39,668 KB
testcase_15 AC 124 ms
39,884 KB
testcase_16 AC 133 ms
39,016 KB
testcase_17 AC 128 ms
39,564 KB
testcase_18 AC 125 ms
39,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder150508;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String[] s = new String[n];
		int len = 0;
		for (int i = 0; i < n; i++) {
			s[i] = sc.next();
			len += s[i].length();
		}

		StringBuffer ret = new StringBuffer();
		for (int i = 0; i < len; i++) {
			String min = "";
			int mini = -1;
			for (int j = 0; j < n; j++) {
				int sh = Math.min(min.length(), s[j].length());
				int comp = min.substring(0, sh).compareTo(s[j].substring(0, sh));
				if (comp == 0) {
					if (min.length() < s[j].length()) {
						min = s[j];
						mini = j;
					}
				} else if (comp > 0){
					min = s[j];
					mini = j;
				}
			}
			ret.append(min.charAt(0));
			s[mini] = s[mini].substring(1);
		}
		
		System.out.println(ret);

		sc.close();
	}
}
0