結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー karinohitokarinohito
提出日時 2021-07-13 22:45:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,566 bytes
コンパイル時間 1,834 ms
コンパイル使用メモリ 172,440 KB
実行使用メモリ 10,024 KB
最終ジャッジ日時 2023-10-14 02:18:25
合計ジャッジ時間 5,920 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//#include <atcoder/all>
#include<bits/stdc++.h>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)


int main() {
    ll N;
    string K;
    cin >> N >> K;
    vll Cj(9);
    rep(i, 9)cin >> Cj[i];
    vll Cb = Cj;
    if (N < K.size()) {
        cout << -1 << endl;
        return 0;
    }
    else while(N>K.size())K = '0' + K;

    bool Ch = true;
    string anj = "";
    string an2 = "";
    rep(i, N) {
        Ch = true;

        rep(k, 9) {
            if (K[i] >= (k + '1')||Cj[k] <= 0)continue;
            an2 = anj + char(k + '1');
            Cb = Cj;
            Cb[k]--;
            Ch = false;
            break;
        }

        if (Ch) {
            rep(k, 9) {
                if (Cb[k] <= 0)continue;
                    an2 = an2 + char(k + '1');
                    Cb[k]--;
                    break;
                }
        }

        Ch = true;
        rep(k, 9) {
            if (K[i] > (k + '1')||Cj[k] <= 0)continue;

            if (K[i] == (k + '1')) {
                anj = anj + K[i];
                Cj[k]--;
                Ch = false;
                break;
            }

        }
        if (Ch) {
            rep(j, 9) {
                rep(k, Cb[j]) {
                    an2 = an2 + char(j + '1');
                }
            }

            if (an2 > K)cout << an2 << endl;
            else cout << -1 << endl;
            return 0;
        }
    }
    cout << an2 << endl;

}
0