結果

問題 No.1946 ロッカーの問題
ユーザー monnumonnu
提出日時 2022-05-20 22:02:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 541 ms / 3,000 ms
コード長 1,206 bytes
コンパイル時間 3,811 ms
コンパイル使用メモリ 232,900 KB
実行使用メモリ 6,088 KB
最終ジャッジ日時 2023-10-20 12:41:06
合計ジャッジ時間 8,534 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 541 ms
5,956 KB
testcase_03 AC 409 ms
6,088 KB
testcase_04 AC 536 ms
5,956 KB
testcase_05 AC 347 ms
5,536 KB
testcase_06 AC 405 ms
5,680 KB
testcase_07 AC 289 ms
5,000 KB
testcase_08 AC 99 ms
4,464 KB
testcase_09 AC 350 ms
5,840 KB
testcase_10 AC 288 ms
5,532 KB
testcase_11 AC 8 ms
4,348 KB
testcase_12 AC 153 ms
4,488 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 27 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 135 ms
4,392 KB
testcase_18 AC 338 ms
5,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 3000
//#define MOD 1000000007
#define MOD 998244353
#define INF 1000000000
//#define INF 1000000000000000000

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> A(M);
  vector<int> wrong(N+1,0);
  for(int i=0;i<M;i++){
    cin>>A[i];
    wrong[A[i]]=1;
  }

  vector<int> open(N+1,0);
  for(int i=1;i<=N;i++){
    vector<int> divd;
    for(int j=1;j*j<=i;j++){
      if(i%j==0){
        divd.push_back(j);
        divd.push_back(i/j);
      }
    }
    sort(divd.begin(),divd.end());
    divd.erase(unique(divd.begin(),divd.end()),divd.end());

    for(int d:divd){
      open[d]=1-open[d];
    }
  }

  vector<int> ans;
  for(int i=N;i>0;i--){
    if(wrong[i]!=open[i]){
      ans.push_back(i);
      vector<int> divd;
      for(int j=1;j*j<=i;j++){
        if(i%j==0){
          divd.push_back(j);
          divd.push_back(i/j);
        }
      }
      sort(divd.begin(),divd.end());
      divd.erase(unique(divd.begin(),divd.end()),divd.end());

      for(int d:divd){
        wrong[d]=1-wrong[d];
      }
    }
  }

  cout<<ans.size()<<'\n';
}
0