結果

問題 No.1913 Periodic Comparison
ユーザー tailstails
提出日時 2022-04-25 14:13:36
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,473 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 34,480 KB
実行使用メモリ 13,936 KB
最終ジャッジ日時 2023-09-09 16:54:07
合計ジャッジ時間 8,999 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,668 KB
testcase_01 AC 4 ms
6,668 KB
testcase_02 AC 4 ms
6,704 KB
testcase_03 AC 4 ms
6,644 KB
testcase_04 AC 4 ms
6,592 KB
testcase_05 AC 4 ms
6,624 KB
testcase_06 AC 4 ms
6,660 KB
testcase_07 AC 4 ms
6,664 KB
testcase_08 AC 12 ms
9,728 KB
testcase_09 AC 24 ms
13,844 KB
testcase_10 AC 11 ms
9,568 KB
testcase_11 AC 23 ms
13,856 KB
testcase_12 AC 12 ms
10,932 KB
testcase_13 AC 10 ms
9,340 KB
testcase_14 AC 21 ms
11,340 KB
testcase_15 AC 23 ms
13,936 KB
testcase_16 AC 23 ms
11,436 KB
testcase_17 AC 12 ms
9,736 KB
testcase_18 AC 10 ms
9,348 KB
testcase_19 AC 23 ms
13,936 KB
testcase_20 AC 17 ms
11,396 KB
testcase_21 AC 25 ms
13,784 KB
testcase_22 AC 10 ms
9,428 KB
testcase_23 AC 7 ms
8,232 KB
testcase_24 AC 23 ms
13,856 KB
testcase_25 AC 13 ms
11,000 KB
testcase_26 AC 21 ms
11,332 KB
testcase_27 AC 11 ms
9,560 KB
testcase_28 AC 11 ms
6,504 KB
testcase_29 AC 23 ms
13,844 KB
testcase_30 AC 24 ms
11,400 KB
testcase_31 AC 7 ms
8,236 KB
testcase_32 AC 9 ms
8,728 KB
testcase_33 AC 12 ms
9,492 KB
testcase_34 AC 26 ms
13,788 KB
testcase_35 AC 23 ms
13,912 KB
testcase_36 AC 12 ms
10,920 KB
testcase_37 AC 23 ms
13,896 KB
testcase_38 AC 4 ms
6,612 KB
testcase_39 AC 4 ms
6,608 KB
testcase_40 AC 14 ms
10,788 KB
testcase_41 AC 16 ms
13,840 KB
testcase_42 AC 13 ms
11,644 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘mkwd’ 内:
main.c:16:20: 警告: 複数文字からなる文字定数 [-Wmultichar]
   16 |         unsigned v='0000';
      |                    ^~~~~~
main.c: 関数 ‘dame’ 内:
main.c:42:9: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   42 |         write(1,"-1",2);
      |         ^~~~~
main.c:43:9: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
   43 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

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

#define rd() ({long _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 rep(v,e) for(long v=0;v<e;++v)
#define rrep(v,e) for(long v=e;v--;)

typedef unsigned long ulong;
char wbuf[1<<25];

unsigned wd[10000];
char wdlz[10000];

void mkwd(){
	unsigned v='0000';
	long i=0;
	rep(a,10){
		rep(b,10){
			rep(c,10){
				rep(d,10){
					wd[i++]=v;
					v+=1<<24;
				}
				v+=(1<<16)-(10<<24);
			}
			v+=(1<<8)-(10<<16);
		}
		v+=(1<<0)-(10<<8);
	}
	rep(j,1000) wdlz[j]=1;
	rep(j,100) wdlz[j]=2;
	rep(j,10) wdlz[j]=3;
}

int x[200000];
int a[200000];
int v[1000001];
int q[0x40000];

void dame(){
	write(1,"-1",2);
	_exit(0);
}

int main(){
	mkwd();

	long n;
	{
		char*mmap();
		char*rp=mmap(0l,1l<<25,1,2,0,0ll);
		n=rd();
		rep(i,n) x[i]=rd();
		rep(i,n){
			long y=rd();
			if(v[y]) dame();
			v[y]=~i;
		}
	}
	{
		long qr=0,qw=n;
		rrep(t,1000001){
			if(qr==qw) dame();
			long u=~q[qr++&0x3ffff];
			if(v[t]){
				if(u>=0) dame();
				u=~v[t];
			}
			if(u>=0&&!x[u]){
				a[u]=t;
			}
			else{
				if(u>=0){
					--x[u];
				}
				q[qw++&0x3ffff]=~u;
			}
		}
		if(qr!=qw) dame();
	}
	{
		char*wp=wbuf+sizeof wbuf;
		rrep(i,n){
			*--wp=' ';
			unsigned v=a[i];
			if(v>=10000){
				wp-=4;
				*(unsigned*)wp=wd[v%10000];
				v/=10000;
			}
			wp-=4;
			*(unsigned*)wp=wd[v];
			wp+=wdlz[v];
		}
		write(1,wp,wbuf+sizeof wbuf-wp);
	}
	_exit(0);
}
0