結果

問題 No.1946 ロッカーの問題
ユーザー kokatsu
提出日時 2022-10-26 22:12:30
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 426 ms / 3,000 ms
コード長 726 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 210,888 KB
実行使用メモリ 15,096 KB
最終ジャッジ日時 2024-06-22 16:30:14
合計ジャッジ時間 6,723 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    int N, M;
    readf("%d %d\n", N, M);

    auto A = readln.chomp.split.to!(int[]);

    auto last = new bool[](N+1);
    foreach (a; A) last[a] = true;

    int res;
    auto isOpened = new bool[](N+1);
    foreach_reverse (i; 1 .. N+1) {
        int[] divisors;
        int d = 1;
        while (d * d <= i) {
            if (i % d == 0) {
                divisors ~= d;
                if (d * d != i) divisors ~= i / d;
            }

            ++d;
        }

        if (isOpened[i] == last[i]) {
            ++res;
        }
        else {
            foreach (divisor; divisors) {
                isOpened[divisor] = !isOpened[divisor];
            }
        }
    }

    res.writeln;
}
0