結果
問題 | No.800 四平方定理 |
ユーザー |
|
提出日時 | 2019-04-29 00:27:17 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 285 ms / 2,000 ms |
コード長 | 967 bytes |
コンパイル時間 | 4,132 ms |
コンパイル使用メモリ | 78,104 KB |
実行使用メモリ | 105,892 KB |
最終ジャッジ日時 | 2024-12-21 15:13:58 |
合計ジャッジ時間 | 11,703 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
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); } } }