0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AtCoder Beginner Contest 350 B問題

Posted at

AtCoder Beginner Contest 350 B問題
こちらの問題です。

問題

image.png

入出力例

image.png

解法

bool型の配列を用いて歯の状態を管理します。
indexの数字に!=をして状態を判定させます。

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int N, Q;
    cin >> N >> Q; 

    vector<bool> teeth(N + 1, true);
    int index;

    for (int i = 0; i < Q; i++) {
        cin >> index;
        teeth[index] = !teeth[index];
    }

    int count = 0;
    for (int i = 1; i <= N; i++) {
        if (teeth[i]) count++;
    }

    cout << count << std::endl;

    return 0;
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?