結果

問題 No.1972 Modulo Set
ユーザー tailstails
提出日時 2022-06-13 19:11:26
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 513 ms
コンパイル使用メモリ 32,512 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-04-15 08:59:44
合計ジャッジ時間 1,985 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 11 ms
6,528 KB
testcase_24 AC 7 ms
5,888 KB
testcase_25 AC 8 ms
6,144 KB
testcase_26 AC 6 ms
5,376 KB
testcase_27 AC 11 ms
6,528 KB
testcase_28 AC 7 ms
5,888 KB
testcase_29 AC 9 ms
6,016 KB
testcase_30 AC 10 ms
6,272 KB
testcase_31 AC 4 ms
5,632 KB
testcase_32 AC 9 ms
6,272 KB
testcase_33 AC 11 ms
6,784 KB
testcase_34 AC 13 ms
6,656 KB
testcase_35 AC 13 ms
6,656 KB
testcase_36 AC 13 ms
6,656 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'main':
main.c:59:9: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
   59 |         write(1,wp,wbuf+sizeof wbuf-wp);
      |         ^~~~~
main.c:60:9: warning: implicit declaration of function '_exit'; did you mean '_Exit'? [-Wimplicit-function-declaration]
   60 |         _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)

typedef unsigned long ulong;

#define HASH_BITS 18
#define HASH_MASK ((1<<HASH_BITS)-1)
long hash[1<<HASH_BITS];

ulong hash_add(ulong x){
	ulong h=x&HASH_MASK;
	while(1){
		if(hash[h]==0){
			hash[h]=x;
			return h;
		}
		if(hash[h]==x){
			return h;
		}
		h=h+1&HASH_MASK;
	}
}

int b[2<<HASH_BITS];

int main(){
	char*mmap();
	char*rp=mmap(0l,1l<<25,1,2,0,0ll);
	ulong n=rd();
	ulong m=rd();
	ulong z=0;
	rep(i,n){
		ulong a=rd()%m;
		if(a==0){
			z|=1;
		}else if(a*2==m){
			z|=4;
		}else if(a*2<m){
			ulong h=hash_add(a);
			b[h<<1|0]+=1;
		}else{
			ulong h=hash_add(m-a);
			b[h<<1|1]+=1;
		}
	}
	z%=3;
	for(ulong h=0;h<2<<HASH_BITS;h+=2){
		ulong x=b[h|0];
		ulong y=b[h|1];
		z+=x>y?x:y;
	}

	char wbuf[64],*wp=wbuf+sizeof wbuf;
	wt(z);
	write(1,wp,wbuf+sizeof wbuf-wp);
	_exit(0);
}
0