結果

問題 No.723 2つの数の和
ユーザー bluemeganebluemegane
提出日時 2018-09-05 20:09:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 777 bytes
コンパイル時間 785 ms
コンパイル使用メモリ 63,576 KB
実行使用メモリ 33,896 KB
最終ジャッジ日時 2023-08-09 20:04:53
合計ジャッジ時間 4,159 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
22,908 KB
testcase_01 AC 60 ms
22,928 KB
testcase_02 AC 59 ms
20,800 KB
testcase_03 AC 98 ms
28,952 KB
testcase_04 AC 107 ms
30,096 KB
testcase_05 AC 106 ms
31,812 KB
testcase_06 AC 105 ms
29,864 KB
testcase_07 AC 86 ms
24,064 KB
testcase_08 AC 87 ms
24,180 KB
testcase_09 AC 110 ms
30,056 KB
testcase_10 AC 85 ms
24,052 KB
testcase_11 AC 70 ms
23,684 KB
testcase_12 AC 90 ms
25,856 KB
testcase_13 AC 110 ms
30,180 KB
testcase_14 AC 78 ms
25,328 KB
testcase_15 AC 87 ms
26,080 KB
testcase_16 AC 94 ms
26,116 KB
testcase_17 AC 102 ms
29,480 KB
testcase_18 AC 94 ms
27,088 KB
testcase_19 AC 103 ms
29,004 KB
testcase_20 AC 59 ms
22,748 KB
testcase_21 AC 60 ms
20,872 KB
testcase_22 AC 59 ms
22,808 KB
testcase_23 AC 109 ms
33,896 KB
testcase_24 AC 80 ms
23,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        var d = new Dictionary<int, long>();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var a = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        for (int i = 0; i < n; i++)
        {
            var w = int.Parse(line[i]);
            if (d.ContainsKey(w)) d[w]++;
            else d[w] = 1;
        }
        var ans = 0L;
        foreach (var x in d)
        {
            var s = a - x.Key;
            if (x.Key == s) ans += x.Value * x.Value;
            else if (d.ContainsKey(s))
                ans += x.Value * d[s];
        }
        Console.WriteLine(ans);
    }
}
0