結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー ktr216ktr216
提出日時 2021-07-30 22:06:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,361 bytes
コンパイル時間 1,462 ms
コンパイル使用メモリ 167,132 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 04:56:18
合計ジャッジ時間 3,534 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 30 ms
4,352 KB
testcase_17 AC 35 ms
4,348 KB
testcase_18 AC 17 ms
4,352 KB
testcase_19 AC 18 ms
4,352 KB
testcase_20 AC 40 ms
4,352 KB
testcase_21 AC 40 ms
4,348 KB
testcase_22 AC 36 ms
4,356 KB
testcase_23 AC 11 ms
4,352 KB
testcase_24 AC 34 ms
4,348 KB
testcase_25 AC 16 ms
4,356 KB
testcase_26 AC 18 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
using namespace std;

typedef long long ll;

int main() {
    int N;
    string K;
    cin >> N >> K;
    vector<int> a(10, 0), b(10, 0), c(10, 0);
    rep(i, 1, 10) cin >> c[i];
    if (N < K.size()) {
        cout << -1 << endl;
        return 0;
    }
    if (N > K.size()) {
        rep(i, 1, 10) {
            rep(j, 0, c[i]) cout << i;
        }
        cout << endl;
        return 0;
    }
    rep(i, 0, K.size()) a[K[i] - '0']++;
    //cout << "a "; rep(i, 0, 10) cout << a[i] << " "; cout << endl;
    for (int i = K.size() - 1; i >= 0; i--) {
        int d = K[i] - '0';
        a[d]--;
        b[d]++;
        //cout << "a "; rep(i, 0, 10) cout << a[i] << " "; cout << endl;
        //cout << "b "; rep(i, 0, 10) cout << b[i] << " "; cout << endl;
        bool f = false;
        rep(j, 0, 10) {
            if (a[j] > c[j]) f = true;
        }
        if (f) continue;
        int x = -1;
        rep(j, d + 1, 10) {
            if (a[j] < c[j]) {
                x = j;
                break;
            }
        }
        if (x == -1) continue;
        rep(j, 0, i) cout << K[j];
        cout << x;
        a[x]++;
        rep(j, 1, 10) {
            rep(k, 0, c[j] - a[j]) cout << j;
        }
        cout << endl;
        return 0;
    }
    cout << -1 << endl;
}
0