結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー boutarouboutarou
提出日時 2021-07-31 10:37:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,374 bytes
コンパイル時間 3,629 ms
コンパイル使用メモリ 204,444 KB
実行使用メモリ 5,296 KB
最終ジャッジ日時 2023-10-14 14:34:53
合計ジャッジ時間 5,132 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 9 ms
5,072 KB
testcase_21 AC 9 ms
5,128 KB
testcase_22 AC 9 ms
5,112 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 7 ms
4,348 KB
testcase_25 AC 3 ms
4,352 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n; cin >> n;
    string k; cin >> k;
    vector<int> c(10);
    rep(i, 9) cin >> c[i + 1];
    vector<int> c2 = c;
    if (n < (int)k.size()) {
        cout << -1 << endl;
        return 0;
    }

    // fill 0
    string zero = "";
    rep(i, n - k.size()) zero += "0";
    k = zero + k;

    // Kより数字を大きくする桁を考える
    int big = -1;
    rep(i, n) {
        bool ok = false;
        for (int j = k[i] - '0' + 1; j <= 9; j++) {
            if (c[j] > 0) ok = true;
        }
        if (!ok) {
            big = i - 1;
            break;
        }
        if (c[k[i] - '0'] == 0) {
            big = i;
            break;
        }
        c[k[i] - '0']--;
    }

    if (big < 0) {
        cout << -1 << endl;
        return 0;
    }
    string ans = "";
    rep(i, big) {
        ans += k[i];
        c2[k[i] - '0']--;
    }
    for (int i = k[big] - '0' + 1; i <= 9; i++) {
        if (c2[i] > 0) {
            c2[i]--;
            ans += to_string(i);
            break;
        }
    }
    rep(i, 10) {
        rep(j, c2[i]) {
            ans += to_string(i);
        }
    }
    cout << ans << endl;

    return 0;
}
0