結果

問題 No.1946 ロッカーの問題
ユーザー yansi819yansi819
提出日時 2024-04-16 09:59:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 821 ms / 3,000 ms
コード長 972 bytes
コンパイル時間 5,016 ms
コンパイル使用メモリ 261,992 KB
実行使用メモリ 39,312 KB
最終ジャッジ日時 2024-04-16 09:59:56
合計ジャッジ時間 12,908 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 747 ms
37,752 KB
testcase_03 AC 821 ms
39,312 KB
testcase_04 AC 742 ms
37,752 KB
testcase_05 AC 481 ms
28,684 KB
testcase_06 AC 564 ms
31,324 KB
testcase_07 AC 421 ms
24,684 KB
testcase_08 AC 177 ms
16,056 KB
testcase_09 AC 684 ms
35,504 KB
testcase_10 AC 553 ms
30,664 KB
testcase_11 AC 11 ms
5,376 KB
testcase_12 AC 232 ms
17,572 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 31 ms
6,484 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 294 ms
20,428 KB
testcase_18 AC 775 ms
38,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

vector<ll> make_divisors(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i * i != n) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}

int main() {
  ll N, M; cin >> N >> M;
  vector<ll> A(M);
  for (auto &x: A) cin >> x;
  vector<vector<ll>> DIV {{}};
  vector<ll> ALL(N + 1, 0);
  vector<ll> DOOR(N + 1, 0);
  for (ll i = 1; i <= N; i++) {
    DIV.push_back(make_divisors(i));
    for (auto div: DIV[i]) {
      ALL[div] = (ALL[div] + 1) % 2;
    }
  }
  for (auto a: A) DOOR[a] = 1;
  ll cnt = 0;
  for (ll i = N; i >= 1; i--) {
    if (ALL[i] != DOOR[i]) {
      cnt++;
      for (auto div: DIV[i]) {
        DOOR[div] = (DOOR[div] + 1) % 2;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
0