結果
問題 | No.1630 Sorting Integers (Greater than K) |
ユーザー | merlin |
提出日時 | 2021-07-30 21:41:31 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,815 bytes |
コンパイル時間 | 2,376 ms |
コンパイル使用メモリ | 74,192 KB |
実行使用メモリ | 56,472 KB |
最終ジャッジ日時 | 2023-10-14 03:58:23 |
合計ジャッジ時間 | 6,580 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
47,216 KB |
testcase_01 | AC | 45 ms
49,524 KB |
testcase_02 | AC | 45 ms
49,216 KB |
testcase_03 | AC | 44 ms
49,220 KB |
testcase_04 | AC | 45 ms
49,124 KB |
testcase_05 | AC | 45 ms
49,212 KB |
testcase_06 | AC | 45 ms
49,340 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 45 ms
49,784 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 183 ms
55,520 KB |
testcase_19 | WA | - |
testcase_20 | AC | 176 ms
55,920 KB |
testcase_21 | AC | 175 ms
53,956 KB |
testcase_22 | AC | 181 ms
55,780 KB |
testcase_23 | RE | - |
testcase_24 | WA | - |
testcase_25 | AC | 177 ms
55,892 KB |
testcase_26 | AC | 214 ms
56,204 KB |
ソースコード
import java.io.*; import java.util.*; class Main { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); String s[]=bu.readLine().split(" "); int n=Integer.parseInt(s[0]); char a[]=s[1].toCharArray(); int i,j,c[]=new int[9],m=a.length; s=bu.readLine().split(" "); for(i=0;i<9;i++) c[i]=Integer.parseInt(s[i]); if(m>n) {System.out.print(c[-1]); return;} StringBuilder ans=new StringBuilder(); boolean pos=true; if(n>m) { for(i=0;i<9;i++) while(c[i]-->0) ans.append(i+1); System.out.print(ans); return; } for(i=0;i<a.length;i++) { int ch=-1,cur=a[i]-'0'-1; for(j=0;j<9;j++) if(c[j]>0 && j>=cur) {ch=j; break;} if(ch==-1) {pos=false; break;} ans.append(ch+1); c[ch]--; if(ch>cur) break; } if(!pos) {System.out.print(-1); return;} if(ans.length()<n) { for(i=0;i<9;i++) while(c[i]-->0) ans.append(i+1); System.out.print(ans); return; } char a2[]=ans.toString().toCharArray(); if(!equal(a2,a)) {System.out.print(ans); return;} int max=n-1; for(i=n-2;i>=0;i--) if(a2[i]<a2[max]) break; else if(a2[i]>a2[max]) max=i; if(i==-1) {System.out.print(-1); return;} char t=a2[max]; a2[max]=a2[i]; a2[i]=t; Arrays.sort(a2,i+1,n); System.out.print(new String(a2)); } static boolean equal(char a[],char b[]) { for(int i=0;i<a.length;i++) if(a[i]!=b[i]) return false; return true; } }