結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー karinohitokarinohito
提出日時 2021-07-15 15:55:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,916 bytes
コンパイル時間 1,619 ms
コンパイル使用メモリ 172,336 KB
実行使用メモリ 5,988 KB
最終ジャッジ日時 2023-10-14 02:18:48
合計ジャッジ時間 3,302 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,356 KB
testcase_05 AC 2 ms
4,356 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 32 ms
5,980 KB
testcase_17 AC 30 ms
5,900 KB
testcase_18 AC 35 ms
5,916 KB
testcase_19 AC 35 ms
5,988 KB
testcase_20 AC 13 ms
5,072 KB
testcase_21 AC 13 ms
5,192 KB
testcase_22 AC 14 ms
5,344 KB
testcase_23 AC 11 ms
4,352 KB
testcase_24 AC 23 ms
4,564 KB
testcase_25 WA -
testcase_26 AC 31 ms
5,984 KB
権限があれば一括ダウンロードができます

ソースコード

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 = "";
    string an3 = "";
    vector<char> S;
    ll itr=0;
    rep(i, N) {
        Ch = true;

        rep(k, 9) {
            if (K[i] >= (k + '1')||Cj[k] <= 0)continue;
            
            //an2 = anj + char(k + '1');
            for(ll j=itr;j<i;j++){
                if(j<an2.size()){
                    an2[j]=anj[j];
                }
                else{
                    an2.push_back(anj[j]);
                }
            }
            itr=i;
            an2.push_back(char(k + '1'));
            Cb = Cj;
            Cb[k]--;
            Ch = false;
            break;
        }

        if (Ch) {
            rep(k, 9) {
                if (Cb[k] <= 0)continue;
                    an2 .push_back(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.push_back(K[i]);
                Cj[k]--;
                Ch = false;
                break;
            }

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

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

}
0