結果
問題 | No.723 2つの数の和 |
ユーザー | tenten |
提出日時 | 2023-08-01 11:30:44 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 267 ms / 2,000 ms |
コード長 | 1,968 bytes |
コンパイル時間 | 2,791 ms |
コンパイル使用メモリ | 84,988 KB |
実行使用メモリ | 63,284 KB |
最終ジャッジ日時 | 2024-04-19 11:03:07 |
合計ジャッジ時間 | 7,734 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
50,128 KB |
testcase_01 | AC | 47 ms
50,656 KB |
testcase_02 | AC | 48 ms
50,516 KB |
testcase_03 | AC | 222 ms
58,656 KB |
testcase_04 | AC | 267 ms
58,692 KB |
testcase_05 | AC | 234 ms
58,736 KB |
testcase_06 | AC | 243 ms
58,752 KB |
testcase_07 | AC | 195 ms
56,800 KB |
testcase_08 | AC | 196 ms
57,036 KB |
testcase_09 | AC | 242 ms
58,852 KB |
testcase_10 | AC | 187 ms
56,592 KB |
testcase_11 | AC | 109 ms
52,348 KB |
testcase_12 | AC | 209 ms
58,644 KB |
testcase_13 | AC | 251 ms
59,244 KB |
testcase_14 | AC | 149 ms
55,300 KB |
testcase_15 | AC | 195 ms
56,248 KB |
testcase_16 | AC | 205 ms
58,352 KB |
testcase_17 | AC | 238 ms
58,748 KB |
testcase_18 | AC | 183 ms
56,476 KB |
testcase_19 | AC | 206 ms
56,532 KB |
testcase_20 | AC | 47 ms
50,292 KB |
testcase_21 | AC | 49 ms
50,020 KB |
testcase_22 | AC | 50 ms
50,192 KB |
testcase_23 | AC | 247 ms
63,284 KB |
testcase_24 | AC | 167 ms
55,376 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; 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 z = sc.nextInt(); counts.put(z, counts.getOrDefault(z, 0L) + 1); } long ans = 0; for (int z : counts.keySet()) { if (z * 2 == x) { ans += counts.get(z) * counts.get(z); } else { ans += counts.get(z) * counts.getOrDefault(x - z, 0L); } } System.out.println(ans); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } 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 int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }