結果

問題 No.800 四平方定理
ユーザー GrenacheGrenache
提出日時 2019-04-29 00:27:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 310 ms / 2,000 ms
コード長 967 bytes
コンパイル時間 4,493 ms
コンパイル使用メモリ 74,196 KB
実行使用メモリ 120,932 KB
最終ジャッジ日時 2023-08-23 12:23:35
合計ジャッジ時間 12,826 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
55,732 KB
testcase_01 AC 140 ms
59,784 KB
testcase_02 AC 139 ms
56,024 KB
testcase_03 AC 139 ms
55,704 KB
testcase_04 AC 135 ms
55,364 KB
testcase_05 AC 139 ms
55,956 KB
testcase_06 AC 144 ms
57,860 KB
testcase_07 AC 136 ms
57,712 KB
testcase_08 AC 138 ms
57,648 KB
testcase_09 AC 139 ms
57,696 KB
testcase_10 AC 228 ms
89,652 KB
testcase_11 AC 234 ms
93,748 KB
testcase_12 AC 235 ms
94,184 KB
testcase_13 AC 227 ms
91,452 KB
testcase_14 AC 230 ms
93,904 KB
testcase_15 AC 227 ms
94,096 KB
testcase_16 AC 233 ms
94,092 KB
testcase_17 AC 234 ms
93,724 KB
testcase_18 AC 239 ms
93,664 KB
testcase_19 AC 231 ms
94,028 KB
testcase_20 AC 128 ms
55,844 KB
testcase_21 AC 129 ms
53,928 KB
testcase_22 AC 239 ms
93,712 KB
testcase_23 AC 305 ms
120,624 KB
testcase_24 AC 306 ms
120,532 KB
testcase_25 AC 297 ms
120,920 KB
testcase_26 AC 127 ms
55,648 KB
testcase_27 AC 127 ms
55,848 KB
testcase_28 AC 310 ms
120,500 KB
testcase_29 AC 306 ms
120,424 KB
testcase_30 AC 301 ms
118,652 KB
testcase_31 AC 292 ms
116,480 KB
testcase_32 AC 303 ms
120,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.Scanner;


public class Main_yukicoder800 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int d = sc.nextInt();

		int[] xy = new int[n * n * 2 + 1];
		int[] wz = new int[n * n * 2 + 1];
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				xy[i * i + j * j]++;
				wz[i * i - j * j + (n * n - 1)]++;
			}
		}

		long ans = 0;
		for (int i = 1; i <= n * n * 2; i++) {
			if (xy[i] > 0) {
				int tmp = i - d + (n * n - 1);
				if (tmp >= 0 && tmp < n * n * 2 + 1) {
					ans += xy[i] * wz[tmp];
				}
			}
		}
		
		pr.println(ans);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}
0