結果

問題 No.938 賢人を探せ
ユーザー tailstails
提出日時 2021-01-19 09:23:21
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 776 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 29,944 KB
実行使用メモリ 10,324 KB
最終ジャッジ日時 2023-08-22 05:55:12
合計ジャッジ時間 3,000 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
10,324 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 4 ms
4,392 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 4 ms
4,724 KB
testcase_12 AC 4 ms
4,648 KB
testcase_13 AC 4 ms
4,672 KB
testcase_14 AC 4 ms
4,704 KB
testcase_15 AC 4 ms
4,560 KB
testcase_16 AC 4 ms
4,612 KB
testcase_17 AC 4 ms
4,616 KB
testcase_18 AC 4 ms
4,696 KB
testcase_19 AC 4 ms
4,664 KB
testcase_20 AC 4 ms
4,676 KB
testcase_21 AC 5 ms
4,616 KB
testcase_22 AC 6 ms
6,880 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘hashf’ 内:
main.c:26:20: 警告: 関数 ‘memcmp’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   26 |                 if(memcmp(hashtbl[h],s,p-s)==0 && hashtbl[h][p-s]<64){
      |                    ^~~~~~
main.c:1:1: 備考: include ‘<string.h>’ or provide a declaration of ‘memcmp’
  +++ |+#include <string.h>
    1 | #pragma GCC optimize("Ofast")
main.c:26:41: 警告: ‘memcmp’ argument 3 type is ‘long int’ where ‘long unsigned int’ is expected in a call to built-in function declared without prototype [-Wbuiltin-declaration-mismatch]
   26 |                 if(memcmp(hashtbl[h],s,p-s)==0 && hashtbl[h][p-s]<64){
      |                                        ~^~
<組み込み>: 備考: built-in ‘memcmp’ declared here
main.c: トップレベル:
main.c:35:1: 警告: 戻り値の型をデフォルトの ‘int’ にします [-Wimplicit-int]
   35 | main(){
      | ^~~~
main.c: 関数 ‘main’ 内:
main.c:36:17: 警告: 関数 ‘time’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   36 |         hashmul=time(0)|1;
      |                 ^~~~
main.c:1:1: 備考: ‘time’ is defined in header ‘<time.h>’; did you forget to ‘#include <time.h>’?
  +++ |+#include <time.h>
    1 | #pragma GCC optimize("Ofast")
main.c:53:9: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   53 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c:54:9: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
   54 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

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

char*mmap();

char wbuf[20<<20];

#define HASHSIZE (1<<20)
char* hashtbl[HASHSIZE];
int hashmul;

int hashf(char*s){
	int h=0;
	char*p=s;
	while(*p>=64){
		h=h*hashmul+*p;
		++p;
	}
	int a=h>>20|1;
	h&=HASHSIZE-1; 
	while(1){
		if(!hashtbl[h]){
			hashtbl[h]=s;
			return 1;
		}
		if(memcmp(hashtbl[h],s,p-s)==0 && hashtbl[h][p-s]<64){
			return 0;
		}
		h=h+a&HASHSIZE-1;
	}
}

char*bs[200000];

main(){
	hashmul=time(0)|1;
	char*rp=mmap(0l,1l<<28,1,2,0,0ll);
	while(*rp++!=10);
	int n=0;
	do{
		hashf(rp);
		while(*rp++>=64);
		bs[n++]=rp;
		while(*rp++>=64);
	}while(*rp);
	char*wp=wbuf;
	for(int i=0;i<n;++i){
		char*p=bs[i];
		if(hashf(p)){
			while((*wp++=*p++)>=64);
		}
	}
	write(1,wbuf,wp-wbuf);
	_exit(0);
}
0