結果

問題 No.800 四平方定理
ユーザー bal4ubal4u
提出日時 2019-04-13 06:57:45
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 1,304 bytes
コンパイル時間 1,569 ms
コンパイル使用メモリ 29,404 KB
実行使用メモリ 62,796 KB
最終ジャッジ日時 2023-10-13 09:42:04
合計ジャッジ時間 5,734 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 3 ms
4,352 KB
testcase_07 AC 3 ms
4,352 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 103 ms
31,996 KB
testcase_11 AC 106 ms
35,632 KB
testcase_12 AC 113 ms
35,172 KB
testcase_13 AC 104 ms
33,408 KB
testcase_14 AC 104 ms
35,752 KB
testcase_15 AC 108 ms
35,464 KB
testcase_16 AC 107 ms
36,000 KB
testcase_17 AC 108 ms
36,116 KB
testcase_18 AC 116 ms
35,976 KB
testcase_19 AC 123 ms
35,900 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 0 ms
4,348 KB
testcase_22 AC 127 ms
36,128 KB
testcase_23 AC 235 ms
62,752 KB
testcase_24 AC 209 ms
62,796 KB
testcase_25 AC 236 ms
62,592 KB
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 0 ms
4,348 KB
testcase_28 AC 203 ms
62,536 KB
testcase_29 AC 219 ms
62,604 KB
testcase_30 AC 210 ms
62,632 KB
testcase_31 AC 183 ms
58,276 KB
testcase_32 AC 214 ms
62,748 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:9:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:17:24: 備考: in expansion of macro ‘gc’
   17 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.800 四平方定理
// 2019.4.13 bal4u
// ハッシュテーブル x^2 + y^2 = w^2 + D - z^2

#include <stdio.h>

//// 高速入力
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()    // 非負整数の入力
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

//// ハッシュテーブル
#define HASHSIZ 19999999 //9999991
typedef struct { int s, cnt; } HASH;
HASH hash[HASHSIZ+5], *hashend = hash + HASHSIZ;

int lookup(int s)
{
	HASH *p = hash + s % HASHSIZ;
	while (p->s) {
		if (p->s == s) return p->cnt;
		if (++p == hashend) p = hash;
	}
	return 0;
}

void insert(int s)
{
	HASH *p = hash + s % HASHSIZ;
	while (p->s) {
		if (p->s == s) { p->cnt++; return; }
		if (++p == hashend) p = hash;
	}
	p->s = s, p->cnt = 1;
}

#define MAX 2000
int n2[MAX+5];

int main()
{
	int i, k, N, D, x, y, z, w, ans;

	for (i = 0; i < MAX; i++) {
		n2[i+1] = n2[i] + (i<<1) + 1;
	}
	
	N = in(), D = in();
	for (x = 1; x <= N; x++) for (y = 1; y <= N; y++) {
		insert(n2[x] + n2[y]);
	}

	ans = 0;
	for (w = 1; w <= N; w++) {
		k = D + n2[w];
		for (z = 1; z <= N; z++) {
			if (k - n2[z] > 1) ans += lookup(k - n2[z]);
		}
	}
	printf("%d\n", ans);
	return 0;
}
0