結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー karinohitokarinohito
提出日時 2021-07-13 22:37:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,492 bytes
コンパイル時間 1,855 ms
コンパイル使用メモリ 173,720 KB
実行使用メモリ 13,932 KB
最終ジャッジ日時 2023-10-14 02:17:42
合計ジャッジ時間 6,075 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
13,932 KB
testcase_01 AC 5 ms
9,256 KB
testcase_02 AC 6 ms
9,532 KB
testcase_03 AC 6 ms
9,392 KB
testcase_04 AC 6 ms
9,456 KB
testcase_05 AC 6 ms
9,504 KB
testcase_06 AC 6 ms
9,372 KB
testcase_07 AC 5 ms
9,348 KB
testcase_08 AC 6 ms
9,556 KB
testcase_09 AC 5 ms
9,588 KB
testcase_10 AC 6 ms
9,328 KB
testcase_11 AC 6 ms
9,328 KB
testcase_12 AC 6 ms
9,328 KB
testcase_13 AC 6 ms
9,460 KB
testcase_14 AC 5 ms
9,476 KB
testcase_15 AC 7 ms
9,324 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++)
using Graph = vector<vector<ll>>;
ll MM = 52 * 52 * 52;
Graph G(MM);
Graph invG(MM);

string P(string K) {
    reverse(all(K));
    ll i = 0;
    while (i < K.size()) {
        if (K[i] != '9') {
            K[i]++;
            reverse(all(K));
            return K;
        }
        else {
            K[i] = 0;
            i++;
        }
    }
    K = K + '1';
    reverse(all(K));
    return K;
}

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

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

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

            if (anj != "NOT") {
                an2 = anj + char(k + '1');

                Cb = Cj;

                Cb[k]--;
                Ch = false;
                break;
            }



        }
        if (Ch) {
            if (anj != "NOT") {
                rep(k, 9) {
                    if (Cb[k] <= 0)continue;

                    if (anj != "NOT") {
                        an2 = an2 + char(k + '1');

                    

                        Cb[k]--;
                        Ch = false;
                        break;
                    }



                }

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

            if (K[i] == (k + '1')) {
                if (anj != "NOT") {
                    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