結果
問題 | No.723 2つの数の和 |
ユーザー | tenten |
提出日時 | 2022-10-06 13:06:47 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 281 ms / 2,000 ms |
コード長 | 1,455 bytes |
コンパイル時間 | 2,029 ms |
コンパイル使用メモリ | 75,120 KB |
実行使用メモリ | 63,120 KB |
最終ジャッジ日時 | 2023-08-30 23:45:46 |
合計ジャッジ時間 | 8,286 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
49,336 KB |
testcase_01 | AC | 42 ms
49,528 KB |
testcase_02 | AC | 43 ms
49,904 KB |
testcase_03 | AC | 241 ms
58,800 KB |
testcase_04 | AC | 261 ms
58,372 KB |
testcase_05 | AC | 250 ms
58,920 KB |
testcase_06 | AC | 251 ms
58,680 KB |
testcase_07 | AC | 212 ms
55,900 KB |
testcase_08 | AC | 215 ms
56,140 KB |
testcase_09 | AC | 280 ms
58,504 KB |
testcase_10 | AC | 207 ms
56,700 KB |
testcase_11 | AC | 111 ms
52,668 KB |
testcase_12 | AC | 220 ms
58,140 KB |
testcase_13 | AC | 281 ms
58,608 KB |
testcase_14 | AC | 174 ms
56,060 KB |
testcase_15 | AC | 217 ms
55,996 KB |
testcase_16 | AC | 232 ms
58,368 KB |
testcase_17 | AC | 247 ms
58,528 KB |
testcase_18 | AC | 192 ms
54,568 KB |
testcase_19 | AC | 222 ms
56,080 KB |
testcase_20 | AC | 42 ms
49,300 KB |
testcase_21 | AC | 42 ms
49,368 KB |
testcase_22 | AC | 43 ms
49,384 KB |
testcase_23 | AC | 278 ms
63,120 KB |
testcase_24 | AC | 192 ms
56,524 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int x = sc.nextInt(); HashMap<Integer, Long> counts = new HashMap<>(); for (int i = 0; i < n; i++) { int y = sc.nextInt(); counts.put(y, counts.getOrDefault(y, 0L) + 1); } long ans = 0; for (int y : counts.keySet()) { if (y * 2 == x) { ans += counts.get(y) * counts.get(y); } else { ans += counts.get(y) * counts.getOrDefault(x - y, 0L); } } System.out.println(ans); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }