結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー tailstails
提出日時 2021-07-31 07:59:46
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,106 bytes
コンパイル時間 1,170 ms
コンパイル使用メモリ 31,468 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 14:31:43
合計ジャッジ時間 2,512 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 0 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 0 ms
4,352 KB
testcase_05 AC 0 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 0 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 0 ms
4,348 KB
testcase_10 AC 0 ms
4,352 KB
testcase_11 AC 0 ms
4,352 KB
testcase_12 AC 0 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 3 ms
4,352 KB
testcase_18 AC 3 ms
4,352 KB
testcase_19 AC 3 ms
4,352 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 1 ms
4,352 KB
testcase_24 AC 3 ms
4,352 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:12:1: 警告: 戻り値の型をデフォルトの ‘int’ にします [-Wimplicit-int]
   12 | main(){
      | ^~~~
main.c: 関数 ‘main’ 内:
main.c:17:19: 警告: initialization of ‘char *’ from ‘long int’ makes pointer from integer without a cast [-Wint-conversion]
   17 |         char*klen=rp-kp-1;
      |                   ^~
main.c:23:16: 警告: ポインタと整数との比較を行なっています
   23 |         if(klen>n){
      |                ^
main.c:24:17: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   24 |                 write(1,"-1",2);
      |                 ^~~~~
main.c:25:17: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
   25 |                 _exit(0);
      |                 ^~~~~
      |                 _Exit
main.c:27:16: 警告: ポインタと整数との比較を行なっています
   27 |         if(klen<n){
      |                ^
main.c:30:25: 警告: 関数 ‘memset’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   30 |                         memset(wp,i+'1',c[i]);
      |                         ^~~~~~
main.c:1:1: 備考: include ‘<string.h>’ or provide a declaration of ‘memset’
  +++ |+#include <string.h>
    1 | #pragma GCC optimize("Ofast")
main.c:30:25: 警告: 組み込み関数 ‘memset’ の互換性がない暗黙的な宣言です [-Wbuiltin-declaration-mismatch]
   30 |                         memset(wp,i+'1',c[i]);
      |                         ^~~~~~
main.c:30:25: 備考: include ‘<string.h>’ or provide a declaration of ‘memset’
main.c:71:25: 警告: 組み込み関数 ‘memset’ の互換性がない暗黙的な宣言です [-Wbuiltin-declaration-mismatch]
   71 |                         memset(wp,i+'1',c[i]);
      |                         ^~~~~~
main.c:71:25: 備考: include ‘<string.h>’ or provide a declaration of ‘memset’

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

char*mmap();
char wbuf[1<<25];

#define rd_skip() while(*rp++>=48)
#define rd(v) long v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}
#define rep(v,e) for(long v=0;v<e;++v)
#define chmax(v,a) (v=v>=a?v:a)

main(){
	char*rp=mmap(0l,1l<<25,1,2,0,0ll);
	rd(n);
	char*kp=rp;
	rd_skip();
	char*klen=rp-kp-1;
	long c[9];
	rep(i,9){
		rd(ci);
		c[i]=ci;
	}
	if(klen>n){
		write(1,"-1",2);
		_exit(0);
	}
	if(klen<n){
		char*wp=wbuf;
		rep(i,9){
			memset(wp,i+'1',c[i]);
			wp+=c[i];
		}
		write(1,wbuf,wp-wbuf);
		_exit(0);
	}
	{
		char*wp=wbuf;
		long d=0;
		while(d<n&&c[kp[d]-'1']){
			--c[kp[d]-'1'];
			*wp++=kp[d++];
		}
		long imax=0;
		rep(i,9){
			if(c[i]){
				imax=i;
			}
		}
		if(d==n){
			--d;
			++c[*--wp-'1'];
		}
		while(d>=0&&imax<=kp[d]-'1'){
			chmax(imax,kp[d]-'1');
			--d;
			++c[*--wp-'1'];
		}
		if(d<0){
			write(1,"-1",2);
			_exit(0);
		}
		{
			long i=kp[d]+1-'1';
			while(!c[i]){
				++i;
			}
			*wp++=i+'1';
			--c[i];
		}
		rep(i,9){
			memset(wp,i+'1',c[i]);
			wp+=c[i];
		}
		write(1,wbuf,wp-wbuf);
		_exit(0);
	}
}
0