結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー bal4ubal4u
提出日時 2021-08-10 14:01:51
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,230 bytes
コンパイル時間 2,422 ms
コンパイル使用メモリ 30,332 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 21:35:53
合計ジャッジ時間 3,212 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 WA -
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 6 ms
4,348 KB
testcase_17 AC 7 ms
4,348 KB
testcase_18 AC 6 ms
4,348 KB
testcase_19 AC 5 ms
4,348 KB
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 5 ms
4,348 KB
testcase_22 AC 5 ms
4,348 KB
testcase_23 WA -
testcase_24 AC 5 ms
4,348 KB
testcase_25 AC 5 ms
4,348 KB
testcase_26 AC 6 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:11:28: note: in expansion of macro 'gc'
   11 |         int n = 0; int c = gc();
      |                            ^~
main.c: In function 'outs':
main.c:8:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
    8 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:24:33: note: in expansion of macro 'pc'
   24 | void outs(char *s) { while (*s) pc(*s++); }
      |                                 ^~

ソースコード

diff #

// yuki 1630 Sorting Integers (Greater than K)
// 2021.8.10

#include <stdio.h>
typedef long long ll;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int ins(char *s) { // 文字列の入力 スペース以下の文字で入力終了
	char *p = s--;
	do *++s = gc();
	while (*s > ' ');
	*s = 0;
	return s - p;
}

void outs(char *s) { while (*s) pc(*s++); }

int N;
char K[500005]; int w;
int f[10];
int main() {
	int i, j, k;

	N = in(), w = ins(K);
	for (i = 1; i <= 9; ++i) f[i] = in();
	if (w == N) {
		for (i = 0; i < w; ++i) {
			k = K[i] & 0xf;
			if (f[k]) f[k]--;
			else {
				for (j = k+1; j <= 9; ++j) if (f[j]) {
					K[i] = j+'0', f[j]--, K[i+1] = 0;
					outs(K);
					goto NT;
				}
				N = i;
				break;
			}
		}
		for (i = N-2; i >= 0; --i) {
			f[K[i+1] & 0xf]++;
			if (K[i] < K[i+1]) {
				k = K[i] & 0xf, f[k]++;
				for (j = k+1; ; ++j) if (f[j]) {
					K[i] = j+'0', f[j]--, K[i+1] = 0;
					outs(K);
					goto NT;
				}
			}
		}
		goto ERR;
	}
NT:	for (i = 1; i <= 9; ++i)
		while (f[i]--) pc('0'+i);
	pc('\n');
	return 0;
ERR:puts("-1");
	return 0;
}
0