結果

問題 No.1946 ロッカーの問題
ユーザー koryoukoryou
提出日時 2022-05-20 22:49:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,287 ms / 3,000 ms
コード長 2,923 bytes
コンパイル時間 988 ms
コンパイル使用メモリ 103,956 KB
実行使用メモリ 7,024 KB
最終ジャッジ日時 2023-10-20 13:39:12
合計ジャッジ時間 10,503 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,760 KB
testcase_01 AC 2 ms
5,760 KB
testcase_02 AC 1,287 ms
6,232 KB
testcase_03 AC 833 ms
7,024 KB
testcase_04 AC 1,281 ms
6,232 KB
testcase_05 AC 802 ms
6,372 KB
testcase_06 AC 962 ms
6,392 KB
testcase_07 AC 658 ms
6,356 KB
testcase_08 AC 175 ms
6,296 KB
testcase_09 AC 728 ms
6,840 KB
testcase_10 AC 567 ms
6,608 KB
testcase_11 AC 10 ms
5,828 KB
testcase_12 AC 312 ms
6,316 KB
testcase_13 AC 2 ms
5,760 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 45 ms
5,920 KB
testcase_16 AC 2 ms
5,760 KB
testcase_17 AC 253 ms
6,316 KB
testcase_18 AC 684 ms
6,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
#include <list>
#include <cassert>
#include <numeric>
#include <cstdint>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <random>
#include <bitset>
// #include <atcoder/all>
 
using ll = long long;
using ld = long double;
using namespace std;
// using namespace atcoder;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
using Priority = priority_queue<ll, vector<ll>, greater<ll>>;// 昇順
using Priority_pair = priority_queue<P, vector<P>, greater<P>>;
// using mint_17 = modint1000000007;
// using mint = modint998244353;

#define mod 1000000007
#define MAX_WIDTH 60
#define MAX_HEIGHT 60
#define INF 1e18
#define MOD 998244353
#define PI 3.141592653589793
#define rep(i, a, b) for(ll i=(a);i<(b);i++)
#define rrep(i, a, b) for(ll i=(a);i>=(b);i--)
#define fore(i, a) for(auto &i: a)
#define all(v) (v).begin(), (v).end()
#define YES(a) cout << ((a) ? "YES" : "NO") << endl
#define Yes(a) cout << ((a) ? "Yes" : "No") << endl
#define pb(a) push_back(a)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vp vector<pair<ll, ll>>
#define mll map<ll, ll>
#define msl map<string, ll>
#define COUT(n) cout << (n) << endl
#define isInGrid(n, h, w) (0 <= (n) && (n) < (h) && 0 <= (n) && (n) < (w))
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int vx[] = {1,0,-1,0}, vy[] = {0,1,0,-1};

ll N, M, A[200010];
ll cnt[200010];
bool is_open[200010];
void enum_divisors(long long N) {
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            cnt[i]++;
            cnt[i]%=2;
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) {
                cnt[N/i]++;
                cnt[N/i]%=2;
            }
        }
    }
}

void enum_divisors2(long long N) {
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            if(cnt[i] == 1) {
                cnt[i]--;
            } else {
                cnt[i] = 1;
            }
            if (N/i != i) {
                if(cnt[N/i] == 1) {
                    cnt[N/i]--;
                } else {
                    cnt[N/i] = 1;
                }
            }
        }
    }
}

int main() {
    cin >> N >> M;
    rep(i, 0, M) {
        cin >> A[i];
        is_open[A[i]] = true;
    }

    rep(i, 0, N+1) cnt[i] = 0;

    rep(i, 1, N+1) {
        enum_divisors(i);
    }

    // 0 close 1 open
    ll ans = 0;
    for(int i=N;i>0;i--) {
        if((is_open[i] && cnt[i] == 0) || (!is_open[i] && cnt[i] == 1)) {
            enum_divisors2(i);
            ans++;
        }
    }
    COUT(ans);

    return 0;
}
0