結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー ace_amuroace_amuro
提出日時 2022-05-17 22:26:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,084 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 74,164 KB
実行使用メモリ 11,480 KB
最終ジャッジ日時 2023-10-14 00:37:10
合計ジャッジ時間 4,393 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,600 KB
testcase_01 AC 2 ms
5,524 KB
testcase_02 AC 2 ms
5,796 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 2 ms
5,572 KB
testcase_05 AC 2 ms
5,524 KB
testcase_06 AC 2 ms
5,524 KB
testcase_07 AC 2 ms
5,524 KB
testcase_08 AC 2 ms
5,568 KB
testcase_09 WA -
testcase_10 AC 2 ms
5,576 KB
testcase_11 AC 2 ms
5,528 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 3 ms
5,576 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 41 ms
11,208 KB
testcase_19 WA -
testcase_20 AC 40 ms
11,308 KB
testcase_21 AC 40 ms
11,260 KB
testcase_22 AC 37 ms
4,348 KB
testcase_23 AC 4 ms
4,352 KB
testcase_24 AC 34 ms
11,152 KB
testcase_25 WA -
testcase_26 AC 40 ms
11,176 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],c[10];
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';
	int cur=0;
	for(int i=1;i<=n;i++){
		if(c[k[i]]){
			a[i]=k[i];
			c[k[i]]--;
		}
		else{
			bool flag=0;
			for(int j=k[i]+1;j<=9;j++){
				if(c[j]>0){
					a[i]=j;
					c[j]--;
					flag=1;
					break;
				}
			}
			if(flag){
				cur=i;
			}
			else{
				cur=-1;
			}
			break;
		}
	}
	if(cur==-1){
		printf("-1\n");
		return 0;
	}
	if(cur==0){
		next_permutation(a+1,a+1+n);
	}
	else if(cur>0){
		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