結果

問題 No.205 マージして辞書順最小
ユーザー tentententen
提出日時 2020-10-07 11:57:25
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,016 bytes
コンパイル時間 3,182 ms
コンパイル使用メモリ 74,580 KB
実行使用メモリ 56,480 KB
最終ジャッジ日時 2023-09-27 09:12:34
合計ジャッジ時間 6,719 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,732 KB
testcase_01 AC 126 ms
55,492 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 127 ms
55,840 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 177 ms
55,612 KB
testcase_11 AC 177 ms
55,936 KB
testcase_12 WA -
testcase_13 AC 162 ms
56,172 KB
testcase_14 AC 129 ms
56,108 KB
testcase_15 AC 126 ms
55,772 KB
testcase_16 AC 125 ms
55,492 KB
testcase_17 AC 126 ms
55,528 KB
testcase_18 AC 126 ms
55,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		PriorityQueue<StringBuilder> queue = new PriorityQueue<StringBuilder>(new Comparator<StringBuilder>() {
		    public int compare(StringBuilder s1, StringBuilder s2) {
		        if (s1.charAt(0) == s2.charAt(0)) {
		            if (s1.length() == 1) {
		                return 1;
		            } else if (s2.length() == 1) {
		                return -1;
		            } else {
		                return s1.compareTo(s2);
		            }
		        } else {
		            return s1.charAt(0) - s2.charAt(0);
		        }
		    }
		});
		while (0 < n--) {
		    queue.add(new StringBuilder(sc.next()));
		}
		StringBuilder ans = new StringBuilder();
		while (queue.size() > 0) {
		    StringBuilder sb = queue.poll();
		    ans.append(sb.charAt(0));
		    sb.deleteCharAt(0);
		    if (sb.length() > 0) {
		        queue.add(sb);
		    }
		}
		System.out.println(ans);
	}
}
0