結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー ace_amuroace_amuro
提出日時 2022-05-17 22:39:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 577 ms
コンパイル使用メモリ 73,540 KB
実行使用メモリ 15,320 KB
最終ジャッジ日時 2023-10-14 01:07:57
合計ジャッジ時間 2,526 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,632 KB
testcase_01 AC 3 ms
7,736 KB
testcase_02 AC 2 ms
7,648 KB
testcase_03 AC 3 ms
5,660 KB
testcase_04 AC 3 ms
7,640 KB
testcase_05 AC 2 ms
7,712 KB
testcase_06 AC 3 ms
7,580 KB
testcase_07 AC 2 ms
7,608 KB
testcase_08 AC 2 ms
7,856 KB
testcase_09 AC 3 ms
7,648 KB
testcase_10 AC 2 ms
7,684 KB
testcase_11 AC 3 ms
7,624 KB
testcase_12 AC 3 ms
7,600 KB
testcase_13 AC 2 ms
7,564 KB
testcase_14 AC 2 ms
7,600 KB
testcase_15 AC 2 ms
7,676 KB
testcase_16 AC 42 ms
13,144 KB
testcase_17 AC 42 ms
12,732 KB
testcase_18 AC 42 ms
15,320 KB
testcase_19 AC 43 ms
15,268 KB
testcase_20 AC 40 ms
12,208 KB
testcase_21 AC 40 ms
12,212 KB
testcase_22 AC 37 ms
6,128 KB
testcase_23 AC 4 ms
5,948 KB
testcase_24 AC 34 ms
12,096 KB
testcase_25 AC 7 ms
10,052 KB
testcase_26 AC 42 ms
14,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
const int MR=1e6+10;
typedef long long LL;
int n,k[MR],a[MR],b[10],c[10];
int v[MR];
char s[MR];
int main() {
	scanf("%d%s",&n,s);
	for(int i=1;i<=9;i++) scanf("%d",c+i);
	int m=strlen(s);
	if(m>n){
		printf("-1\n");
		return 0;
	}
	if(m<n){
		for(int i=1;i<=9;i++){
			for(int j=1;j<=c[i];j++){
				printf("%d",i);
			}
		}
		printf("\n");
		return 0;
	}
	for(int i=1;i<=n;i++) k[i]=s[i-1]-'0';
	for(int i=1;i<=9;i++) b[i]=c[i];
	for(int i=1;i<=n;i++){
		for(int j=k[i]+1;j<=9;j++){
			if(b[j]>0) {
				v[i]=j;
				break;
			}
		}
		if(b[k[i]]){
			b[k[i]]--;
		}
		else break;
	}
	//for(int i=1;i<=n;i++) printf("%d",v[i]);printf("\n");
	int cur=-1;
	for(int i=n;i>=1;i--){
		if(v[i]){
			cur=i;
			break;
		}
	}
	if(cur==-1){
		printf("-1\n");
		return 0;
	}
	for(int i=1;i<cur;i++){
		a[i]=k[i];
		c[k[i]]--;
	}
	a[cur]=v[cur];
	c[a[cur]]--;
	for(int i=1;i<=9;i++){
		for(int j=1;j<=c[i];j++){
			cur++;
			a[cur]=i;
		}
	}
	for(int i=1;i<=n;i++) printf("%d",a[i]);printf("\n");
    return 0;
}
0