結果
問題 | No.2195 AND Set |
ユーザー | tenten |
提出日時 | 2023-03-03 11:41:15 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,237 ms / 2,000 ms |
コード長 | 2,772 bytes |
コンパイル時間 | 3,176 ms |
コンパイル使用メモリ | 84,636 KB |
実行使用メモリ | 80,344 KB |
最終ジャッジ日時 | 2023-10-18 00:53:32 |
合計ジャッジ時間 | 21,907 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
53,436 KB |
testcase_01 | AC | 54 ms
53,388 KB |
testcase_02 | AC | 1,048 ms
75,312 KB |
testcase_03 | AC | 1,082 ms
78,740 KB |
testcase_04 | AC | 1,010 ms
74,348 KB |
testcase_05 | AC | 1,185 ms
76,652 KB |
testcase_06 | AC | 1,174 ms
76,448 KB |
testcase_07 | AC | 725 ms
70,416 KB |
testcase_08 | AC | 1,064 ms
76,968 KB |
testcase_09 | AC | 686 ms
63,696 KB |
testcase_10 | AC | 1,237 ms
80,344 KB |
testcase_11 | AC | 1,007 ms
80,292 KB |
testcase_12 | AC | 1,211 ms
80,192 KB |
testcase_13 | AC | 1,188 ms
80,260 KB |
testcase_14 | AC | 997 ms
80,064 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(); HashSet<Integer> exist = new HashSet<>(); int[] counts = new int[30]; StringBuilder sb = new StringBuilder(); while (n-- > 0) { int type = sc.nextInt(); if (type == 1) { int x = sc.nextInt(); if (exist.contains(x)) { continue; } exist.add(x); for (int i = 0; i < 30; i++) { counts[i] += x % 2; x >>= 1; } } else if (type == 2) { int x = sc.nextInt(); if (!exist.contains(x)) { continue; } exist.remove(x); for (int i = 0; i < 30; i++) { counts[i] -= x % 2; x >>= 1; } } else { if (exist.size() == 0) { sb.append("-1\n"); continue; } int ans = 0; for (int i = 29; i >= 0; i--) { ans <<= 1; if (counts[i] == exist.size()) { ans++; } } sb.append(ans).append("\n"); } } System.out.print(sb); } } 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(); } }