結果

問題 No.715 集合と二人ゲーム
ユーザー bal4ubal4u
提出日時 2019-09-05 10:35:59
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,256 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 30,096 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 23:23:06
合計ジャッジ時間 4,627 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 0 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 0 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 0 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 0 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 0 ms
4,376 KB
testcase_47 AC 0 ms
4,376 KB
testcase_48 AC 0 ms
4,380 KB
testcase_49 AC 0 ms
4,380 KB
testcase_50 AC 22 ms
4,380 KB
testcase_51 AC 22 ms
4,376 KB
testcase_52 AC 22 ms
4,380 KB
testcase_53 AC 22 ms
4,380 KB
testcase_54 AC 22 ms
4,376 KB
testcase_55 AC 22 ms
4,376 KB
testcase_56 AC 21 ms
4,376 KB
testcase_57 AC 20 ms
4,376 KB
testcase_58 AC 22 ms
4,376 KB
testcase_59 AC 22 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:9:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:15:28: 備考: in expansion of macro ‘gc’
   15 |         int n = 0; int c = gc();
      |                            ^~

ソースコード

diff #

// yukicoder: 715 集合と二人ゲーム
// 2019.9.5 bal4u

#include <stdio.h>
#include <string.h>

//// 高速入力
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int N;
int a[500005];
#define TMAX 110
int g[TMAX]; char f[TMAX];

void Qsort(int *a, int l, int r) {
	int i, j, m, t;
	
	i = l, j = r, m = a[(l+r) >> 1];
	while (1) {
		while (a[i] < m) i++;
		while (m < a[j]) j--;
		if (i >= j)	break;
		t = a[i], a[i] = a[j], a[j] = t;
		i++, j--;
	}
	if (l+1 < i) Qsort(a, l, i-1);
	if (j+1 < r) Qsort(a, j+1, r);
}


void calc_grundy() {
	int i, j;
	
	g[0] = 0, g[1] = 1;
	for (i = 2; i < TMAX; i++) {
		memset(f, 0, sizeof(f));
		f[g[i-2]] = 1;
		for (j = 0; j <= i-3; j++) f[g[j]^g[i-j-3]] = 1;
		for (j = 0; f[j]; j++);
		g[i] = j;
	}
}

inline static int grundy(int w) { return (w < 68)? g[w]: g[68 + w%34]; }

int main()
{
	int i, j, g;
	
	calc_grundy();
	N = in(); for (i = 0; i < N; i++) a[i] = in();
	Qsort(a, 0, N-1);
	g = 0, j = 0, i = 1; while (1) {
		while (a[i] == a[i-1]+1) i++;
		g ^= grundy(i-j);
		if (i >= N) break;
		j = i++;
	}
	puts(g? "First": "Second");
	return 0;
}
0