結果

問題 No.1946 ロッカーの問題
ユーザー tentententen
提出日時 2022-09-27 11:33:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 760 ms / 3,000 ms
コード長 1,595 bytes
コンパイル時間 2,187 ms
コンパイル使用メモリ 74,080 KB
実行使用メモリ 57,712 KB
最終ジャッジ日時 2023-08-24 03:43:54
合計ジャッジ時間 7,993 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,284 KB
testcase_01 AC 45 ms
49,184 KB
testcase_02 AC 50 ms
50,084 KB
testcase_03 AC 657 ms
57,712 KB
testcase_04 AC 50 ms
49,204 KB
testcase_05 AC 96 ms
52,836 KB
testcase_06 AC 107 ms
52,588 KB
testcase_07 AC 112 ms
52,872 KB
testcase_08 AC 299 ms
55,700 KB
testcase_09 AC 589 ms
57,616 KB
testcase_10 AC 511 ms
55,572 KB
testcase_11 AC 90 ms
51,996 KB
testcase_12 AC 206 ms
53,444 KB
testcase_13 AC 45 ms
49,592 KB
testcase_14 AC 44 ms
49,276 KB
testcase_15 AC 45 ms
49,248 KB
testcase_16 AC 45 ms
49,244 KB
testcase_17 AC 404 ms
55,792 KB
testcase_18 AC 760 ms
56,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[] isOpen = new boolean[n + 1];
        for (int i = 0; i < m; i++) {
            isOpen[sc.nextInt()] = true;
        }
        int ans = 0;
        for (int i = n; i >= 1; i--) {
            if (!isOpen[i]) {
                ans++;
                continue;
            }
            for (int j = 2; j <= Math.sqrt(i); j++) {
                if (i % j == 0) {
                    isOpen[j] ^= true;
                    if (j * j < i) {
                        isOpen[i / j] ^= true;
                    }
                }
            }
            isOpen[1] ^= true;
        }
        System.out.println(ans);
    }
}
    
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0