結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー asaringo
提出日時 2021-07-30 21:11:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 839 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 171,720 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-15 22:17:12
合計ジャッジ時間 5,544 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 5 RE * 17
権限があれば一括ダウンロードができます

ソースコード

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 , k ;
int C[10] ;
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 >> k ;
    rep(i,9){
        int c ;
        cin >> c ;
        rep(j,c) digit.push_back(i+1) ;
    }
    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