結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー asaringoasaringo
提出日時 2021-07-30 21:40:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 991 bytes
コンパイル時間 1,897 ms
コンパイル使用メモリ 171,272 KB
実行使用メモリ 6,340 KB
最終ジャッジ日時 2023-10-14 03:55:46
合計ジャッジ時間 3,247 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 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 14 ms
4,348 KB
testcase_05 AC 14 ms
4,352 KB
testcase_06 AC 14 ms
4,352 KB
testcase_07 AC 14 ms
4,352 KB
testcase_08 AC 14 ms
4,348 KB
testcase_09 AC 14 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 15 ms
6,048 KB
testcase_24 WA -
testcase_25 AC 14 ms
5,996 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef pair<int,int> P ;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)

ll n ;
string S ;
vector<int> digit ;

ll powmod(ll x , ll n){
    ll res = 1 ;
    while(n > 0){
        if(n & 1) res *= x ;
        x *= x ;
        n >>= 1 ;
    }
    return res ;
}

int main(){
    cin >> n >> S ;
    rep(i,9){
        int c ;
        cin >> c ;
        rep(j,c) digit.push_back(i+1) ;
    }
    if(S.size() > 9){
        cout << -1 << endl ;
        return 0 ;
    }
    ll k = 0 ;
    rep(i,S.size()) k += (S[S.size()-1-i] - '0') * powmod(10,i) ;
    sort(digit.begin(),digit.end()) ;
    ll res = 1e16 ;
    do
    {
        ll val = 0 ;
        rep(i,n) val += digit[i] * powmod(10,i) ;
        if(val > k && val < res){
            res = val ;
        }
    } while (next_permutation(digit.begin(),digit.end()));
    if(res == 1e16) res = -1 ;
    cout << res << endl ;
}
0