結果

問題 No.800 四平方定理
ユーザー chika0707chika0707
提出日時 2019-03-17 22:07:03
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,317 ms / 2,000 ms
コード長 1,893 bytes
コンパイル時間 1,254 ms
コンパイル使用メモリ 66,280 KB
実行使用メモリ 84,732 KB
最終ジャッジ日時 2023-09-22 06:36:14
合計ジャッジ時間 20,309 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
21,308 KB
testcase_01 AC 74 ms
22,260 KB
testcase_02 AC 71 ms
22,292 KB
testcase_03 AC 72 ms
24,360 KB
testcase_04 AC 69 ms
21,340 KB
testcase_05 AC 70 ms
24,340 KB
testcase_06 AC 76 ms
24,388 KB
testcase_07 AC 72 ms
24,440 KB
testcase_08 AC 75 ms
22,348 KB
testcase_09 AC 73 ms
22,308 KB
testcase_10 AC 667 ms
53,140 KB
testcase_11 AC 685 ms
55,132 KB
testcase_12 AC 629 ms
55,680 KB
testcase_13 AC 607 ms
55,144 KB
testcase_14 AC 652 ms
55,260 KB
testcase_15 AC 664 ms
53,608 KB
testcase_16 AC 658 ms
53,188 KB
testcase_17 AC 654 ms
55,248 KB
testcase_18 AC 612 ms
55,200 KB
testcase_19 AC 633 ms
51,144 KB
testcase_20 AC 61 ms
19,024 KB
testcase_21 AC 62 ms
21,144 KB
testcase_22 AC 648 ms
55,296 KB
testcase_23 AC 1,270 ms
84,732 KB
testcase_24 AC 1,193 ms
82,020 KB
testcase_25 AC 1,255 ms
84,132 KB
testcase_26 AC 61 ms
21,076 KB
testcase_27 AC 61 ms
21,148 KB
testcase_28 AC 1,317 ms
83,664 KB
testcase_29 AC 1,275 ms
79,972 KB
testcase_30 AC 1,227 ms
83,992 KB
testcase_31 AC 1,135 ms
82,148 KB
testcase_32 AC 1,294 ms
84,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        int N = NextInt();
        long D = NextLong();
        Dictionary<long, long> xy = new Dictionary<long, long>();

        for (int x = 1; x <= N; x++)
            for (int y = x; y <= N; y++)
            {
                long c = (long)Math.Pow(x, 2) + (long)Math.Pow(y, 2);
                if (!xy.ContainsKey(c)) xy[c] = 0;
                if (x != y) xy[c] += 2;
                else xy[c]++;
            }
        long ans = 0;
        for (int z = 1; z <= N; z++)
            for (int w = 1; w <= N; w++)
            {
                long c = (long)Math.Pow(z, 2) - (long)Math.Pow(w, 2);
                if (xy.ContainsKey(D - c)) ans += xy[D - c];
            }
        Console.WriteLine(ans);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}
0