結果
| 問題 |
No.800 四平方定理
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-04-13 06:57:45 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 222 ms / 2,000 ms |
| コード長 | 1,304 bytes |
| コンパイル時間 | 1,455 ms |
| コンパイル使用メモリ | 30,080 KB |
| 実行使用メモリ | 62,720 KB |
| 最終ジャッジ日時 | 2024-09-15 06:49:29 |
| 合計ジャッジ時間 | 4,173 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
コンパイルメッセージ
main.c: In function 'in':
main.c:9:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
9 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:17:24: note: in expansion of macro 'gc'
17 | int n = 0, c = gc();
| ^~
ソースコード
// 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;
}
bal4u