結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー tian imtian im
提出日時 2021-09-06 19:48:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 983 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 164,900 KB
実行使用メモリ 6,084 KB
最終ジャッジ日時 2023-08-24 05:37:43
合計ジャッジ時間 4,561 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 61 ms
5,928 KB
testcase_17 AC 62 ms
5,856 KB
testcase_18 AC 59 ms
6,084 KB
testcase_19 AC 59 ms
6,000 KB
testcase_20 AC 60 ms
5,924 KB
testcase_21 AC 60 ms
5,784 KB
testcase_22 AC 60 ms
5,892 KB
testcase_23 AC 24 ms
4,376 KB
testcase_24 AC 51 ms
5,376 KB
testcase_25 AC 30 ms
5,864 KB
testcase_26 AC 60 ms
5,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int maxn = 500500;
char K[maxn];
int num[11], numK[maxn];

int main(void) {
    int n; scanf("%d%s", &n, K);
    int len = strlen(K);

    for (int i=1; i<=n; i++) scanf("%d", &num[i]);

    if (len > n) {
        printf("-1\n");
        return 0;
    }

    for (int i=0; i<len; i++) numK[i] = K[len-i-1] - '0';
    for (int i=len; i<n; i++) numK[i] = 0;

    for (int i=0; i<n; i++) num[numK[i]]--;
    for (int i=0; i<n; i++) {
        num[numK[i]]++;

        int f = 1;
        for (int j=0; j<10; j++) if (num[j] < 0) { f = 0; break; }
        if (!f) continue;

        if (num[numK[i]+1] == 0) continue;

        numK[i]++;
        num[numK[i]]--;
        for (int j=0; j<10; j++) {
            for (int u=0; u<num[j]; u++) {
                numK[--i] = j;
            }
        }
        for (int j=n-1; j>=0; j--) printf("%d", numK[j]);
        printf("\n");
        return 0;
    }

    printf("-1\n");

    return 0;
}
0