結果

問題 No.1946 ロッカーの問題
ユーザー shinchanshinchan
提出日時 2022-05-20 21:59:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 548 ms / 3,000 ms
コード長 1,270 bytes
コンパイル時間 2,371 ms
コンパイル使用メモリ 210,408 KB
実行使用メモリ 14,324 KB
最終ジャッジ日時 2023-10-20 12:37:25
合計ジャッジ時間 7,348 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 546 ms
4,820 KB
testcase_03 AC 441 ms
14,324 KB
testcase_04 AC 548 ms
4,820 KB
testcase_05 AC 351 ms
4,556 KB
testcase_06 AC 418 ms
4,556 KB
testcase_07 AC 296 ms
4,368 KB
testcase_08 AC 107 ms
6,932 KB
testcase_09 AC 383 ms
13,004 KB
testcase_10 AC 312 ms
11,684 KB
testcase_11 AC 7 ms
4,368 KB
testcase_12 AC 151 ms
4,820 KB
testcase_13 AC 1 ms
4,368 KB
testcase_14 AC 2 ms
4,368 KB
testcase_15 AC 24 ms
4,368 KB
testcase_16 AC 2 ms
4,368 KB
testcase_17 AC 135 ms
7,196 KB
testcase_18 AC 348 ms
11,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

vector<int> divisor(int n) {
    vector<int> v;
    for(int i = 1; i * i <= n ; i ++) {
        if(n % i == 0) {
            if(n != i * i ) v.pb(n / i);
            v.pb(i);
        }
    }
    return v;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false); 
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1, 0);
    for(int i = 1; i <= n ; i++) {
        all(e, divisor(i)) a[e] ^= 1; 
    }
    set<int> s;
    int b;
    rep(i, m) {
        cin >> b;
        s.insert(b);
    }
    vector<int> c(n + 1, 0);
    for(int i = 1;i <= n ; i++) {
        c[i] = a[i] ^ s.count(i);
        // cout << i << " " << a[i] << " " << s.count(i) << " " << c[i] << endl; 
        // if(c[i]) cout << i << endl;
    }
    int cnt = 0;
    for(int i = n ; i >= 1; i --) {
        if(c[i]) {
            cnt++;
            all(e, divisor(i)) {
                c[e] ^= 1;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}
0