結果

問題 No.1946 ロッカーの問題
ユーザー milanis48663220
提出日時 2022-05-20 21:52:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 194 ms / 3,000 ms
コード長 1,834 bytes
コンパイル時間 1,153 ms
コンパイル使用メモリ 118,052 KB
最終ジャッジ日時 2025-01-29 10:30:22
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

const int M = 200000;
vector<int> facs[M+1];

void init(){
    for(int x = 1; x <= M; x++){
        for(int i = 1; i*x <= M; i++){
            facs[i*x].push_back(x);
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    init();
    int n, m; cin >> n >> m;
    vector<bool> is_open(n+1);
    for(int i = 0; i < m; i++){
        int a; cin >> a;
        is_open[a] = true;
    }
    int ans = 0;
    for(int x = n; x >= 1; x--){
        if(is_open[x]){
            for(int a: facs[x]) is_open[a] = !is_open[a];
        }else{
            ans++;
        }
    }
    cout << ans << endl;
}
0