結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー tailstails
提出日時 2020-10-23 20:44:04
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,084 bytes
コンパイル時間 485 ms
コンパイル使用メモリ 30,460 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 15:41:16
合計ジャッジ時間 1,172 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:20:1: 警告: 戻り値の型をデフォルトの ‘int’ にします [-Wimplicit-int]
   20 | main(){
      | ^~~~
main.c: 関数 ‘main’ 内:
main.c:26:17: 警告: 関数 ‘memset’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   26 |                 memset(hash, 0, sizeof(hash));
      |                 ^~~~~~
main.c:1:1: 備考: include ‘<string.h>’ or provide a declaration of ‘memset’
  +++ |+#include <string.h>
    1 | // https://yukicoder.me/submissions/349896
main.c:26:17: 警告: 組み込み関数 ‘memset’ の互換性がない暗黙的な宣言です [-Wbuiltin-declaration-mismatch]
   26 |                 memset(hash, 0, sizeof(hash));
      |                 ^~~~~~
main.c:26:17: 備考: include ‘<string.h>’ or provide a declaration of ‘memset’
main.c:48:9: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   48 |         write(1,wbuf,w-wbuf);
      |         ^~~~~
main.c:49:9: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
   49 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

// https://yukicoder.me/submissions/349896
// // yukicoder: 120 傾向と対策:門松列(その1)
// // 2019.6.3 bal4u
// を大いに参考にした(丸パクリともいう)

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

char*mmap();
#define RD(v) int v=0;{int c;while(c=*r++-48,c>=0)v=v*10+c;}

char wbuf[3000];

// 数値のハッシュ関数
#define HSIZ 1009
typedef struct { int v, f; } HASH;
HASH hash[HSIZ+5], *hashend = hash+HSIZ;
int ma1, ma2;

main(){
	char*r=mmap(0l,1536l*1024,1,2,0,0l);
	char*w=wbuf;
	RD(t);
	while(t--){
		int ma1=0,ma2=0;
		memset(hash, 0, sizeof(hash));
		RD(n);
		for(int i=n;i--;){
			RD(l);
			// insert
			HASH *p = hash + l % HSIZ;
			while (p->v && p->v!=l) {
				if (++p == hashend) p = hash;
			}
			p->v = l, p->f++;
			if (p->f > ma1) ma1++;
			else if (p->f > ma2) ma2++;
		}
		int ans;
		if (ma1 <= n/3) ans = n/3;
		else if ((n-ma1)/2 >= ma2) ans = (n-ma1)/2;
		else ans = n-ma1-ma2;
		//printf("%d\n", ans);
		if(ans>=10) *w++=0x30|ans/10;
		*w++=0x30|ans%10;
		*w++=10;
	}
	write(1,wbuf,w-wbuf);
	_exit(0);
}
0