結果

問題 No.1946 ロッカーの問題
ユーザー karinohitokarinohito
提出日時 2022-05-21 00:44:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,222 ms / 3,000 ms
コード長 1,166 bytes
コンパイル時間 2,066 ms
コンパイル使用メモリ 203,612 KB
実行使用メモリ 6,364 KB
最終ジャッジ日時 2023-10-20 15:19:32
合計ジャッジ時間 11,137 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1,219 ms
6,364 KB
testcase_03 AC 806 ms
6,364 KB
testcase_04 AC 1,222 ms
6,364 KB
testcase_05 AC 759 ms
5,572 KB
testcase_06 AC 900 ms
5,836 KB
testcase_07 AC 618 ms
5,308 KB
testcase_08 AC 169 ms
4,348 KB
testcase_09 AC 675 ms
6,100 KB
testcase_10 AC 535 ms
5,572 KB
testcase_11 AC 9 ms
4,348 KB
testcase_12 AC 299 ms
4,516 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 43 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 235 ms
4,780 KB
testcase_18 AC 651 ms
6,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)


bool chmax(ll& p, ll q) {
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

bool chmin(ll& p, ll q) {
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}


int main() {
    
    ll N,M;
    cin>>N>>M;
    vll A(N+1,0);
    for(ll i=1;i<=N;i++){
        for(ll j=1;j*j<=i;j++){
            if(i%j==0){
                 A[j]=1-A[j]; 
                 if(j*j!=i){
                     A[i/j]=1-A[i/j];
                 }
            }
          
        }
    }

    vll D(N+1,0);
    rep(i,M){
        ll P;
        cin>>P;
        D[P]=1;
    }
    ll an=0;
    for(ll i=N;i>0;i--){
        if(A[i]!=D[i]){
            an++;
            for(ll j=1;j*j<=i;j++){
                if(i%j==0){
                    D[j]=1-D[j];
                    if(i!=j*j){
                        D[i/j]=1-D[i/j];
                    }
                }
            }
        }
    }
    cout<<an<<endl;
    

    

    
}
0