結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー abc3abc3
提出日時 2021-07-30 22:38:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,824 bytes
コンパイル時間 2,303 ms
コンパイル使用メモリ 206,816 KB
実行使用メモリ 7,596 KB
最終ジャッジ日時 2023-10-14 06:15:51
合計ジャッジ時間 4,092 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,356 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 22 ms
7,284 KB
testcase_17 AC 21 ms
7,284 KB
testcase_18 AC 25 ms
7,576 KB
testcase_19 AC 25 ms
7,552 KB
testcase_20 AC 17 ms
7,536 KB
testcase_21 AC 17 ms
7,316 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 15 ms
6,084 KB
testcase_25 AC 17 ms
6,528 KB
testcase_26 AC 20 ms
7,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

   #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    typedef unsigned long long ull;
    using P=pair<ll,ll>;
    const int INF=1001001001;
    const int mod=1e9+7;
    
    void solve(){
        int n;
        string x;
        cin>>n>>x;

        vector<int>s(n);
        rep(i,n){s[i]=x[i]-'0';}

        vector<int>cnt(10);
        string mx;
        for(int i=1;i<=9;i++){
            cin>>cnt[i];
            rep(j,cnt[i]){
               mx+=(char)('0'+i); 
            }
        }
        sort(mx.rbegin(),mx.rend());
        if(mx<=x){cout<<-1<<endl;return;}
        
        auto c2=cnt;
        int lst=0;
        rep(i,n){
            bool ok=false;
            for(int j=s[i]+1;j<=9;j++){
                if(c2[j]!=0){ok=true;}
            }
            if(ok){chmax(lst,i);}
            if(c2[s[i]]==0){break;}
            c2[s[i]]--;
        }
        string ans;
        rep(i,lst){
           ans+=x[i];
           cnt[s[i]]--;
        }
        for(int i=s[lst]+1;i<=9;i++){
            if(cnt[i]!=0){
                ans+=(char)(i+'0');
                cnt[i]--;
                break;
            }
        }
        for(int i=1;i<=9;i++){
            if(cnt[i]!=0){
                ans+=string(cnt[i],(char)(i+'0'));
            }
        }
        cout<<ans<<endl;
    }  

    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        solve(); 
        
        return 0;
    }
0