結果
| 問題 |
No.1630 Sorting Integers (Greater than K)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-30 21:34:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 985 bytes |
| コンパイル時間 | 1,757 ms |
| コンパイル使用メモリ | 172,968 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-15 23:13:23 |
| 合計ジャッジ時間 | 2,936 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 7 WA * 15 |
ソースコード
#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 ;
if(S.size() > 15){
cout << -1 << endl ;
return 0 ;
}
ll k = 0 ;
rep(i,S.size()) k += (S[n-1-i] - '0') * powmod(10,i) ;
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 ;
}