結果

問題 No.3363 Two Closest Numbers
コンテスト
ユーザー tails
提出日時 2025-11-17 22:15:30
言語 C
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 2,621 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 28,672 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-11-17 22:15:33
合計ジャッジ時間 2,865 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 RE * 2
other AC * 26 RE * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:7:59: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
    7 | #define wt1(v) ({char wbuf[64],*wp=wbuf+sizeof wbuf;wt(v);write(1,wp,wbuf+sizeof wbuf-wp);})
      |                                                           ^~~~~
main.c:561:17: note: in expansion of macro ‘wt1’
  561 |                 wt1(y);
      |                 ^~~
main.c:563:1: warning: implicit declaration of function ‘exit’ [-Wimplicit-function-declaration]
  563 | exit(1);
      | ^~~~
main.c:1:1: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
  +++ |+#include <stdlib.h>
    1 | #pragma GCC optimize("Ofast")
main.c:563:1: warning: incompatible implicit declaration of built-in function ‘exit’ [-Wbuiltin-declaration-mismatch]
  563 | exit(1);
      | ^~~~
main.c:563:1: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
main.c:570:9: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
  570 |         _exit(0);
      |         ^~~~~
main.c:570:9: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]

ソースコード

diff #

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

#define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);})
#define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define wt(v) ({ulong _z=v;do*--wp=_z%10+48;while(_z/=10);})
#define wt1(v) ({char wbuf[64],*wp=wbuf+sizeof wbuf;wt(v);write(1,wp,wbuf+sizeof wbuf-wp);})
#define rep(v,e) for(typeof(e)v=0;v<e;++v)
#define repeat(e) for(typeof(e)_=e;_--;)
#define MD 998244353

typedef unsigned long ulong;

static int tbl[]={
0,
0,
0,
1,
0,
2,
1,
0,
0,
3,
2,
0,
1,
0,
0,
7,
0,
4,
3,
0,
2,
0,
0,
6,
1,
0,
0,
9,
0,
6,
7,
0,
0,
5,
4,
0,
3,
0,
0,
5,
2,
0,
0,
8,
0,
5,
6,
0,
1,
0,
0,
9,
0,
8,
9,
0,
0,
5,
6,
0,
7,
0,
0,
47,
0,
6,
5,
0,
4,
0,
0,
4,
3,
0,
0,
7,
0,
4,
5,
0,
2,
0,
0,
8,
0,
14,
8,
0,
0,
4,
5,
0,
6,
0,
0,
37,
1,
0,
0,
9,
0,
8,
9,
0,
0,
7,
8,
0,
9,
0,
0,
36,
0,
4,
5,
0,
6,
0,
0,
39,
7,
0,
0,
36,
0,
37,
47,
0,
0,
7,
6,
0,
5,
0,
0,
3,
4,
0,
0,
6,
0,
3,
4,
0,
3,
0,
0,
7,
0,
13,
7,
0,
0,
3,
4,
0,
5,
0,
0,
27,
2,
0,
0,
8,
0,
18,
8,
0,
0,
13,
14,
0,
8,
0,
0,
26,
0,
3,
4,
0,
5,
0,
0,
29,
6,
0,
0,
26,
0,
27,
37,
0,
1,
0,
0,
9,
0,
8,
9,
0,
0,
7,
8,
0,
9,
0,
0,
25,
0,
6,
7,
0,
8,
0,
0,
28,
9,
0,
0,
25,
0,
26,
36,
0,
0,
3,
4,
0,
5,
0,
0,
29,
6,
0,
0,
28,
0,
29,
39,
0,
7,
0,
0,
25,
0,
26,
36,
0,
0,
27,
37,
0,
47,
0,
0,
247,
0,
8,
7,
0,
6,
0,
0,
2,
5,
0,
0,
5,
0,
2,
3,
0,
4,
0,
0,
6,
0,
12,
6,
0,
0,
2,
3,
0,
4,
0,
0,
17,
3,
0,
0,
7,
0,
17,
7,
0,
0,
12,
13,
0,
7,
0,
0,
16,
0,
2,
3,
0,
4,
0,
0,
19,
5,
0,
0,
16,
0,
17,
27,
0,
2,
0,
0,
8,
0,
18,
8,
0,
0,
17,
18,
0,
8,
0,
0,
15,
0,
12,
13,
0,
14,
0,
0,
18,
8,
0,
0,
15,
0,
16,
26,
0,
0,
2,
3,
0,
4,
0,
0,
19,
5,
0,
0,
18,
0,
19,
29,
0,
6,
0,
0,
15,
0,
16,
26,
0,
0,
17,
27,
0,
37,
0,
0,
147,
1,
0,
0,
9,
0,
8,
9,
0,
0,
7,
8,
0,
9,
0,
0,
14,
0,
6,
7,
0,
8,
0,
0,
17,
9,
0,
0,
14,
0,
15,
25,
0,
0,
5,
6,
0,
7,
0,
0,
18,
8,
0,
0,
48,
0,
18,
28,
0,
9,
0,
0,
14,
0,
15,
25,
0,
0,
16,
26,
0,
36,
0,
0,
137,
0,
2,
3,
0,
4,
0,
0,
19,
5,
0,
0,
18,
0,
19,
29,
0,
6,
0,
0,
17,
0,
18,
28,
0,
0,
19,
29,
0,
39,
0,
0,
136,
7,
0,
0,
14,
0,
15,
25,
0,
0,
16,
26,
0,
36,
0,
0,
139,
0,
17,
27,
0,
37,
0,
0,
136,
47,
0,
0,
137,
0,
147,
247,
0,
};

int d[9];

int main(){
	rd_init();
	int n=rd();
	repeat(n){
		++d[*rp-'1'];
		rp+=2;
	}
	if(n&1){
		ulong y=0,z=0;
		int i=0;
		repeat(n+1>>1){
			while(!d[i]){
				++i;
			}
			--d[i];
			y=(y*10+i+1)%MD;
		}
		i=8;
		while(1){
			while(!d[i]){
				if(--i<0){
					goto hoge;
				}
			}
			--d[i];
			z=(z*10+i+1)%MD;
		}
		hoge:;
		y-=z;
		y+=y<MD?0:MD;
		wt1(y);
	}else{
exit(1);
		int j=0;
		rep(i,9){
			j|=(d[i]&1)<<i;
		}
		wt1(tbl[j]);
	}
	_exit(0);
}
0