結果

問題 No.1946 ロッカーの問題
ユーザー kokatsukokatsu
提出日時 2022-10-26 22:12:30
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 449 ms / 3,000 ms
コード長 726 bytes
コンパイル時間 1,808 ms
コンパイル使用メモリ 205,864 KB
実行使用メモリ 15,276 KB
最終ジャッジ日時 2023-09-04 18:42:27
合計ジャッジ時間 6,684 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 420 ms
4,772 KB
testcase_03 AC 449 ms
14,900 KB
testcase_04 AC 418 ms
4,816 KB
testcase_05 AC 285 ms
7,880 KB
testcase_06 AC 329 ms
7,944 KB
testcase_07 AC 241 ms
7,896 KB
testcase_08 AC 122 ms
10,680 KB
testcase_09 AC 392 ms
15,276 KB
testcase_10 AC 324 ms
12,716 KB
testcase_11 AC 11 ms
4,584 KB
testcase_12 AC 151 ms
8,432 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 28 ms
4,416 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 190 ms
10,944 KB
testcase_18 AC 442 ms
13,424 KB
権限があれば一括ダウンロードができます

ソースコード

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