結果
問題 | No.1630 Sorting Integers (Greater than K) |
ユーザー | 沙耶花 |
提出日時 | 2021-07-30 20:48:19 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 65 ms / 2,000 ms |
コード長 | 1,214 bytes |
コンパイル時間 | 5,589 ms |
コンパイル使用メモリ | 260,972 KB |
実行使用メモリ | 5,540 KB |
最終ジャッジ日時 | 2023-10-14 03:05:57 |
合計ジャッジ時間 | 7,511 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,352 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 1 ms
4,352 KB |
testcase_03 | AC | 2 ms
4,352 KB |
testcase_04 | AC | 1 ms
4,352 KB |
testcase_05 | AC | 1 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,352 KB |
testcase_07 | AC | 1 ms
4,356 KB |
testcase_08 | AC | 2 ms
4,348 KB |
testcase_09 | AC | 1 ms
4,348 KB |
testcase_10 | AC | 2 ms
4,352 KB |
testcase_11 | AC | 2 ms
4,352 KB |
testcase_12 | AC | 2 ms
4,348 KB |
testcase_13 | AC | 2 ms
4,348 KB |
testcase_14 | AC | 2 ms
4,348 KB |
testcase_15 | AC | 1 ms
4,352 KB |
testcase_16 | AC | 58 ms
5,452 KB |
testcase_17 | AC | 41 ms
5,404 KB |
testcase_18 | AC | 61 ms
5,456 KB |
testcase_19 | AC | 65 ms
5,464 KB |
testcase_20 | AC | 19 ms
5,152 KB |
testcase_21 | AC | 17 ms
5,192 KB |
testcase_22 | AC | 15 ms
5,148 KB |
testcase_23 | AC | 11 ms
4,348 KB |
testcase_24 | AC | 36 ms
4,836 KB |
testcase_25 | AC | 13 ms
5,188 KB |
testcase_26 | AC | 61 ms
5,540 KB |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using mint = modint1000000007; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000005 string get(vector<int> c){ string ret = ""; for(int i=9;i>=0;i--){ rep(j,c[i])ret += '0' + i; } return ret; } int main(){ int n; cin>>n; string K; cin>>K; vector<int> c(10,0); rep(i,9)cin>>c[i+1]; if(n<K.size()){ cout<<-1<<endl; return 0; } { string t(n-K.size(),'0'); K = t+K; } if(get(c)<=K){ cout<<-1<<endl; return 0; } int ok = 0,ng = n+1; while(ng-ok>1){ int mid = (ok+ng)/2; vector<int> cc = c; string temp = ""; bool f = true; rep(i,mid){ if(cc[K[i]-'0']<=0){ f=false; break; } temp += K[i]; cc[K[i]-'0']--; } if(f){ string t2 = get(cc); temp += t2; if(temp <= K)f=false; } if(f)ok = mid; else ng= mid; } //cout<<ok<<endl; string ans = ""; rep(i,ok){ ans += K[i]; c[K[i]-'0']--; } if(ok!=n){ rep(i,10){ if(c[i]==0)continue; if(i<=K[ok]-'0')continue; ans += '0'+i; c[i]--; break; } rep(i,10){ rep(j,c[i])ans += '0'+i; } } cout<<ans<<endl; return 0; }