結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー karinohitokarinohito
提出日時 2021-07-16 11:57:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,325 ms / 2,000 ms
コード長 1,697 bytes
コンパイル時間 2,159 ms
コンパイル使用メモリ 75,784 KB
実行使用メモリ 68,268 KB
最終ジャッジ日時 2023-10-14 02:22:28
合計ジャッジ時間 14,444 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,612 KB
testcase_01 AC 125 ms
55,700 KB
testcase_02 AC 126 ms
56,132 KB
testcase_03 AC 128 ms
55,648 KB
testcase_04 AC 125 ms
55,932 KB
testcase_05 AC 121 ms
56,128 KB
testcase_06 AC 122 ms
55,720 KB
testcase_07 AC 122 ms
55,996 KB
testcase_08 AC 126 ms
56,028 KB
testcase_09 AC 125 ms
55,720 KB
testcase_10 AC 131 ms
55,820 KB
testcase_11 AC 130 ms
55,848 KB
testcase_12 AC 131 ms
55,688 KB
testcase_13 AC 131 ms
55,420 KB
testcase_14 AC 131 ms
55,676 KB
testcase_15 AC 133 ms
55,672 KB
testcase_16 AC 946 ms
60,700 KB
testcase_17 AC 1,063 ms
60,584 KB
testcase_18 AC 349 ms
60,444 KB
testcase_19 AC 360 ms
60,836 KB
testcase_20 AC 1,311 ms
67,360 KB
testcase_21 AC 1,317 ms
67,552 KB
testcase_22 AC 1,325 ms
68,268 KB
testcase_23 AC 230 ms
58,660 KB
testcase_24 AC 1,167 ms
65,412 KB
testcase_25 AC 259 ms
59,788 KB
testcase_26 AC 302 ms
60,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    
      	Scanner sc = new Scanner(System.in);
      	int N=sc.nextInt();
      	int bign=-1;
      	int lc=-1;
		String K = sc.next();
      	int[] Cjust=new int[9];
     	for(var i=0;i<9;i++){
          	Cjust[i]=sc.nextInt();
        }
      	int[] Cbig=new int[9];
      	for (int i=0;i<9;i++){
        	Cbig[i]=Cjust[i];
        }
		sc.close();

      	if(N<(int)K.length()){
          System.out.println(-1);
        }
      	else if(N>(int)K.length()){
          for(int i=0;i<9;i++){
          	for(int num=0;num<Cjust[i];num++){
				System.out.print((char)(i+'1')); 
            }
          }
        }
      	else{
          for (int i=0;i<N;i++){
            char Ki=K.charAt(i);
            for (int c=(int)(Ki-'1')+1;c<9;c++){
            	if(Cjust[c]>0){
                  for(int d=Math.max(bign,0);d<i;d++){
                  	Cbig[(int)K.charAt(d)-'1']--;
                  }
                  bign=i;
                  lc=c;
                  break;
                }
            }
            if(K.charAt(i)!='0'&&Cjust[K.charAt(i)-'1']>0){
              Cjust[K.charAt(i)-'1']--;
            }
            else break;
        }
        if(bign==-1){
          System.out.println(-1); 
        }
        else{
          System.out.print(K.substring(0,bign));
          System.out.print((char)(lc+'1'));
          Cbig[lc]--;
          for(int j=0;j<9;j++){
            for(int k=0;k<Cbig[j];k++){
              System.out.print((char)(j+'1'));
            }
          }
          System.out.println("");
        } 
        }
	}
}
0