結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー asaringoasaringo
提出日時 2021-07-30 21:11:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 839 bytes
コンパイル時間 1,650 ms
コンパイル使用メモリ 169,540 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-14 02:38:22
合計ジャッジ時間 5,765 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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