結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-21 22:29:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 982 bytes
コンパイル時間 1,946 ms
コンパイル使用メモリ 202,836 KB
実行使用メモリ 5,356 KB
最終ジャッジ日時 2023-09-11 17:31:49
合計ジャッジ時間 4,552 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,388 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 16 ms
4,808 KB
testcase_17 AC 16 ms
4,884 KB
testcase_18 AC 20 ms
5,180 KB
testcase_19 AC 19 ms
5,088 KB
testcase_20 AC 11 ms
4,952 KB
testcase_21 AC 11 ms
4,924 KB
testcase_22 AC 12 ms
4,816 KB
testcase_23 AC 11 ms
4,380 KB
testcase_24 AC 11 ms
4,376 KB
testcase_25 AC 12 ms
4,380 KB
testcase_26 AC 14 ms
5,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){

    string K, S="";
    ll N, M, ok=-1, s;
    cin >> N >> K;
    vector<ll> c(10), d;
    for (int i=1; i<=9; i++) cin >> c[i];
    d = c;
    M = K.size();

    if (M < N){
        for (int i=1; i<=9; i++) S += string(c[i], '0'+i);
        cout << S << endl;
        return 0;
    }
    else if (M > N){
        cout << -1 << endl;
        return 0;
    }

    for (int i=0; i<N; i++){
        s = K[i]-'0';
        for (int j=s+1; j<=9; j++) if (c[j]) ok=i;
        if (c[s]) c[s]--;
        else break;
    }

    if (ok == -1){
        cout << -1 << endl;
        return 0;
    }

    for (int i=0; i<ok; i++){
        S += K[i];
        d[K[i]-'0']--;
    }
    for (int i=K[ok]-'0'+1; i<=9; i++){
        if (d[i]){
            S += i+'0';
            d[i]--;
            break;
        }
    }

    for (int i=1; i<=9; i++) S += string(d[i], i+'0');

    cout << S << endl;

    return 0;
}
0