結果

問題 No.205 マージして辞書順最小
ユーザー PG-practicePG-practice
提出日時 2019-09-28 16:34:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 735 ms / 5,000 ms
コード長 1,773 bytes
コンパイル時間 2,086 ms
コンパイル使用メモリ 79,952 KB
実行使用メモリ 68,704 KB
最終ジャッジ日時 2024-04-10 09:02:39
合計ジャッジ時間 10,499 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
54,248 KB
testcase_01 AC 132 ms
52,784 KB
testcase_02 AC 381 ms
58,748 KB
testcase_03 AC 440 ms
58,708 KB
testcase_04 AC 406 ms
58,824 KB
testcase_05 AC 385 ms
58,524 KB
testcase_06 AC 167 ms
54,640 KB
testcase_07 AC 712 ms
62,148 KB
testcase_08 AC 670 ms
61,120 KB
testcase_09 AC 735 ms
62,456 KB
testcase_10 AC 705 ms
68,704 KB
testcase_11 AC 691 ms
65,888 KB
testcase_12 AC 699 ms
62,424 KB
testcase_13 AC 523 ms
59,824 KB
testcase_14 AC 193 ms
58,048 KB
testcase_15 AC 125 ms
52,960 KB
testcase_16 AC 136 ms
54,396 KB
testcase_17 AC 142 ms
54,388 KB
testcase_18 AC 125 ms
53,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
//mport java.io.*;

// class MyComparator implements Comparator<String>{
//     @Override
//     int compare(String str1,String str2){
        
//     }
// }

public class Main{

    static int INFTY = Integer.MAX_VALUE;
    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());
            int n= sc.nextInt();
            sc.nextLine();
            String T = "";
            List<String> str = new LinkedList<>();

            for(int i=0;i<n;i++){
                String tmp = sc.nextLine();
                if(!tmp.equals("")){
                    str.add(tmp);
                }
            }
            
            while(true){
                int candidateIndex=0;
                if(str.size()==1 && str.get(0).equals("")){
                    break;
                }
                for(int i=0;i<str.size();i++){
                    if(str.get(i).length()==0){
                        str.remove(i);
                        i--;
                        continue;
                    }
                    if((!str.get(candidateIndex).matches("^"+str.get(i)+".*") && str.get(i).compareTo(str.get(candidateIndex))<=0) || str.get(i).matches("^"+str.get(candidateIndex)+".*")){
                        candidateIndex=i;
                    }   
                }
                T += str.get(candidateIndex).substring(0,1);
                
                str.set(candidateIndex,str.get(candidateIndex).substring(1,str.get(candidateIndex).length()));
            }
            System.out.println(T);
                
            }
}
0