結果

問題 No.1946 ロッカーの問題
ユーザー tentententen
提出日時 2023-02-24 14:38:30
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,982 bytes
コンパイル時間 3,040 ms
コンパイル使用メモリ 92,000 KB
実行使用メモリ 73,168 KB
最終ジャッジ日時 2023-10-09 23:50:48
合計ジャッジ時間 7,482 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,824 KB
testcase_01 AC 44 ms
49,576 KB
testcase_02 AC 65 ms
53,240 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 43 ms
49,392 KB
testcase_14 AC 44 ms
49,920 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

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());
        }
        int ans = 0;
        boolean[] isOpens = new boolean[n + 1];
        for (int i = 1; i <= n; i++) {
            if (isOpens[i] == opens.contains(i)) {
                ans++;
            } else {
                for (int j = 1; j * i <= n; j++) {
                    isOpens[j * i] ^= 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