結果

問題 No.1946 ロッカーの問題
ユーザー tentententen
提出日時 2023-02-24 15:45:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 785 ms / 3,000 ms
コード長 2,287 bytes
コンパイル時間 3,853 ms
コンパイル使用メモリ 89,012 KB
実行使用メモリ 138,640 KB
最終ジャッジ日時 2023-10-10 00:38:13
合計ジャッジ時間 11,897 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,760 KB
testcase_01 AC 41 ms
49,336 KB
testcase_02 AC 541 ms
111,768 KB
testcase_03 AC 774 ms
134,752 KB
testcase_04 AC 531 ms
112,096 KB
testcase_05 AC 378 ms
102,580 KB
testcase_06 AC 538 ms
110,728 KB
testcase_07 AC 365 ms
98,576 KB
testcase_08 AC 387 ms
79,116 KB
testcase_09 AC 737 ms
116,888 KB
testcase_10 AC 727 ms
111,648 KB
testcase_11 AC 120 ms
54,796 KB
testcase_12 AC 300 ms
79,236 KB
testcase_13 AC 40 ms
49,656 KB
testcase_14 AC 40 ms
49,752 KB
testcase_15 AC 106 ms
57,304 KB
testcase_16 AC 42 ms
49,232 KB
testcase_17 AC 468 ms
85,528 KB
testcase_18 AC 785 ms
138,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        HashSet<Integer> opens = new HashSet<>();
        for (int i = 0; i < m; i++) {
            opens.add(sc.nextInt());
        }
        ArrayList<ArrayList<Integer>> targets = new ArrayList<>();
        for (int i = 0; i <= n; i++) {
            targets.add(new ArrayList<>());
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j * i <= n; j++) {
                targets.get(j * i).add(i);
            }
        }
        int ans = 0;
        boolean[] isOpens = new boolean[n + 1];
        for (int i = n; i >= 1; i--) {
            if (isOpens[i] == opens.contains(i)) {
                ans++;
            } else {
                for (int x : targets.get(i)) {
                    isOpens[x] ^= true;
                }
            }
        }
        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();
    }
    
}
0