結果

問題 No.1946 ロッカーの問題
ユーザー keisuke6keisuke6
提出日時 2022-05-20 22:20:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 696 ms / 3,000 ms
コード長 692 bytes
コンパイル時間 1,728 ms
コンパイル使用メモリ 171,328 KB
実行使用メモリ 6,396 KB
最終ジャッジ日時 2023-10-20 13:05:11
合計ジャッジ時間 6,102 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 694 ms
6,396 KB
testcase_03 AC 222 ms
6,396 KB
testcase_04 AC 696 ms
6,396 KB
testcase_05 AC 435 ms
5,604 KB
testcase_06 AC 514 ms
5,868 KB
testcase_07 AC 357 ms
5,340 KB
testcase_08 AC 55 ms
4,348 KB
testcase_09 AC 193 ms
6,132 KB
testcase_10 AC 157 ms
5,604 KB
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 148 ms
4,548 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 28 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 24 ms
4,812 KB
testcase_18 AC 49 ms
6,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> Yakusuu(int N){
  vector<int> A={};
  for(int i=1;i*i<=N;i++)if(N%i == 0) A.push_back(i);
  int s = A.size();
  for(int i=s-1;i>=0;i--){
    if(A[i]*A[i] == N) continue;
    A.push_back(N/A[i]);
  }
  return A;
}
signed main(){
  int N,M;
  cin>>N>>M;
  vector<int> A(N,0);
  for(int i=1;i<=N;i++){
    A[i-1] = (N/i)%2;
  }
  vector<int> S(N,0);
  for(int i=0;i<M;i++){
    int a;
    cin>>a;
    S[a-1] = 1;
  }
  int ans = 0;
  for(int i=N;i>=1;i--){
    if(A[i-1] != S[i-1]){
      ans++;
      vector<int> x=Yakusuu(i);
      for(int j=0;j<x.size();j++)A[x[j]-1]=1-A[x[j]-1];
    }
  }
  cout<<ans<<endl;
}
0