結果

問題 No.1946 ロッカーの問題
ユーザー nawawannawawan
提出日時 2022-05-20 22:37:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 248 ms / 3,000 ms
コード長 909 bytes
コンパイル時間 731 ms
コンパイル使用メモリ 85,560 KB
実行使用メモリ 5,728 KB
最終ジャッジ日時 2023-10-20 13:23:48
合計ジャッジ時間 2,948 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 248 ms
4,936 KB
testcase_03 AC 118 ms
5,728 KB
testcase_04 AC 246 ms
4,936 KB
testcase_05 AC 155 ms
4,408 KB
testcase_06 AC 184 ms
4,672 KB
testcase_07 AC 129 ms
4,408 KB
testcase_08 AC 33 ms
4,348 KB
testcase_09 AC 105 ms
5,464 KB
testcase_10 AC 86 ms
5,200 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 59 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 11 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 23 ms
4,408 KB
testcase_18 AC 46 ms
5,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <queue>
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    vector<int> temp(N + 1);
    for (int i = 0; i < M; i++)
    {
        cin >> A[i];
        temp[A[i]] = 1;
    }
    vector<int> cnt(N + 1);
    for (int i = 1; i <= N; i++)
    {
        for (int j = i; j <= N; j += i)
            cnt[i]++;
    }
    int ans = 0;
    for (int i = N; i >= 1; i--)
    {
        if (cnt[i] % 2 == temp[i])
            continue;
        else
        {
            ans++;
            for (int j = 1; j * j <= i; j++)
            {
                if (i % j == 0)
                {
                    cnt[j]--;
                    if (j * j != i)
                        cnt[i / j]--;
                }
            }
        }
    }
    cout << ans << endl;
}
0