結果
問題 | No.2319 Friends+ |
ユーザー | tenten |
提出日時 | 2023-05-30 13:03:02 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 907 ms / 3,000 ms |
コード長 | 3,296 bytes |
コンパイル時間 | 2,914 ms |
コンパイル使用メモリ | 92,652 KB |
実行使用メモリ | 203,072 KB |
最終ジャッジ日時 | 2024-06-08 20:06:48 |
合計ジャッジ時間 | 38,211 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
36,748 KB |
testcase_01 | AC | 44 ms
36,928 KB |
testcase_02 | AC | 822 ms
197,256 KB |
testcase_03 | AC | 811 ms
197,604 KB |
testcase_04 | AC | 720 ms
197,080 KB |
testcase_05 | AC | 722 ms
197,148 KB |
testcase_06 | AC | 718 ms
197,256 KB |
testcase_07 | AC | 907 ms
200,044 KB |
testcase_08 | AC | 896 ms
200,096 KB |
testcase_09 | AC | 888 ms
199,904 KB |
testcase_10 | AC | 890 ms
199,856 KB |
testcase_11 | AC | 887 ms
197,080 KB |
testcase_12 | AC | 81 ms
38,304 KB |
testcase_13 | AC | 78 ms
38,152 KB |
testcase_14 | AC | 75 ms
38,224 KB |
testcase_15 | AC | 82 ms
38,428 KB |
testcase_16 | AC | 82 ms
38,236 KB |
testcase_17 | AC | 44 ms
36,756 KB |
testcase_18 | AC | 723 ms
195,752 KB |
testcase_19 | AC | 750 ms
198,452 KB |
testcase_20 | AC | 761 ms
195,860 KB |
testcase_21 | AC | 736 ms
197,712 KB |
testcase_22 | AC | 707 ms
197,720 KB |
testcase_23 | AC | 733 ms
198,592 KB |
testcase_24 | AC | 750 ms
198,268 KB |
testcase_25 | AC | 732 ms
198,456 KB |
testcase_26 | AC | 872 ms
196,772 KB |
testcase_27 | AC | 719 ms
198,648 KB |
testcase_28 | AC | 736 ms
198,224 KB |
testcase_29 | AC | 772 ms
198,236 KB |
testcase_30 | AC | 693 ms
195,912 KB |
testcase_31 | AC | 731 ms
195,736 KB |
testcase_32 | AC | 739 ms
195,864 KB |
testcase_33 | AC | 681 ms
198,320 KB |
testcase_34 | AC | 698 ms
198,056 KB |
testcase_35 | AC | 711 ms
197,532 KB |
testcase_36 | AC | 797 ms
200,256 KB |
testcase_37 | AC | 651 ms
198,100 KB |
testcase_38 | AC | 665 ms
198,236 KB |
testcase_39 | AC | 678 ms
199,560 KB |
testcase_40 | AC | 679 ms
197,800 KB |
testcase_41 | AC | 676 ms
198,420 KB |
testcase_42 | AC | 678 ms
198,272 KB |
testcase_43 | AC | 690 ms
198,208 KB |
testcase_44 | AC | 738 ms
203,072 KB |
testcase_45 | AC | 662 ms
198,708 KB |
testcase_46 | AC | 640 ms
198,104 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 m = sc.nextInt(); BitSet.size = n; BitSet[] locations = new BitSet[n]; BitSet[] friends = new BitSet[n]; for (int i = 0; i < n; i++) { locations[i] = new BitSet(); friends[i] = new BitSet(); } int[] place = new int[n]; for (int i = 0; i < n; i++) { place[i] = sc.nextInt() - 1; locations[place[i]].add(i); } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; friends[a].add(b); friends[b].add(a); } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (q-- > 0) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; if (place[a] != place[b] && locations[place[b]].and(friends[a])) { sb.append("Yes\n"); locations[place[a]].draw(a); place[a] = place[b]; locations[place[a]].add(a); } else { sb.append("No\n"); } } System.out.print(sb); } static class BitSet { static int size; int count; long[] values; public BitSet() { count = (size + 60 - 1) / 60; values = new long[count]; } public void add(int idx) { values[idx / 60] |= (1L << (idx % 60)); } public void draw(int idx) { values[idx / 60] ^= (1L << (idx % 60)); } public boolean and(BitSet another) { for (int i = 0; i < count; i++) { if ((values[i] & another.values[i]) > 0) { return true; } } return false; } } } 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(); } }