結果

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

ソースコード

diff #
プレゼンテーションモードにする

#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <assert.h>
#include <cstring>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define vi vector <int>
#define vec(...) vector<__VA_ARGS__>
#define _376o25z ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//eodefine
using namespace std;
const int mxn=400000;
int main(){
_376o25z;
int n; string s;
cin>>n>>s;
vi a(11),ina;
rep(i,n) cin>>a[i+1];
ina=a;
if(n>sz(s)){
string ans="";
while(true){
bool pok=0;
crep(j,1,10){
if(ina[j]>0){
ans+=char(j+'0');
ina[j]--;
pok=1;
break;
}
}
if(!pok) break;
}
cout<<ans<<"\n";
exit(0);
}
if(n<sz(s)){
cout<<"-1\n"; exit(0);
}
int m=sz(s);
int cand=-1;
rep(i,m){
int x=int(s[i]-'0');
crep(j,x+1,10){
if(a[j]>0) cand=i;
}
if(a[x]==0) break;
else a[x]--;
}
if(cand==-1) { cout<<cand<<"\n"; exit(0); }
string ans="";
rep(i,cand){
int x=int(s[i]-'0');
ans+=s[i];
ina[x]--;
}
int x=int(s[cand]-'0');
crep(j,x+1,10){
if(ina[j]>0){
ans+=char(j+'0');
ina[j]--;
break;
}
}
while(true){
bool pok=0;
crep(j,1,10){
if(ina[j]>0){
ans+=char(j+'0');
ina[j]--;
pok=1;
break;
}
}
if(!pok) break;
}
cout<<ans<<"\n";
//
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0