結果
| 問題 |
No.1972 Modulo Set
|
| コンテスト | |
| ユーザー |
tails
|
| 提出日時 | 2022-06-13 19:11:26 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 1,022 bytes |
| コンパイル時間 | 1,259 ms |
| コンパイル使用メモリ | 31,104 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-05 01:46:15 |
| 合計ジャッジ時間 | 1,856 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
コンパイルメッセージ
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
ソースコード
#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);
}
tails