PS

BOJ 27111 : 출입 기록

lickelon 2025. 1. 9. 17:02

코드

#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()

#define INF 0x7FFFFFFF

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    unordered_set<int> _s;
    int n;
    cin >> n;

    int ans = 0;
    for(int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        if(b) {
            if(_s.find(a) != _s.end()) ans++;
            else _s.insert(a);
        }
        else {
            if(_s.find(a) == _s.end()) ans++;
            else _s.erase(a);
        }
    }
    cout << ans + _s.size();

    return 0;
}

풀이

셋을 이용하여 출입 기록을 관리한다.

비정상적인 출입 기록이 있을 경우 누락된 것이다.

모든 입력을 처리한 뒤 셋에 남아있는 사람 또한 출입 기록이 누락된 것이다.

728x90