結果

問題 No.1946 ロッカーの問題
ユーザー taisii2
提出日時 2022-05-20 22:29:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 779 ms / 3,000 ms
コード長 632 bytes
コンパイル時間 1,718 ms
コンパイル使用メモリ 177,576 KB
実行使用メモリ 34,172 KB
最終ジャッジ日時 2024-09-20 08:43:02
合計ジャッジ時間 6,017 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> T(N + 1);
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j += i) {
      T[j].push_back(i);
    }
  }
  vector<int> A(M);
  set<int> st;
  for (int i = 0; i < M; i++) {
    cin >> A[i];
    st.insert(A[i]);
  }
  int ans = 0;
  for (int i = N - 1; i >= 0; i--) {
    int idx = i + 1;
    if (st.count(idx)) {
      for (int j : T[idx]) {
        if (st.count(j)) {
          st.erase(j);
        } else {
          st.insert(j);
        }
      }
    } else {
      ans++;
    }
  }
  cout << ans << endl;
}
0