답안 #712071

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
712071 2023-03-18T04:33:08 Z wenqi Love Polygon (BOI18_polygon) C++17
100 / 100
109 ms 12816 KB
// trans rights
#include <bits/extc++.h>
using namespace std;
using ll = long long;

int N;
unordered_map<string, int> mp;

int to[100069];
int cnt[100069];
bool taken[100069];

int main(int argc, const char *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    if (N & 1)
    {
        cout << -1;
        return 0;
    }
    int n = 1;
    for (int i = 0; i < N; i++)
    {
        string a, b;
        cin >> a >> b;
        int &ia = mp[a], &ib = mp[b];
        if (not ia)
            ia = n++;
        if (not ib)
            ib = n++;
        to[ia] = ib;
        cnt[ib]++;
    }
    priority_queue<pair<int, int>> pq;
    int ans = 0;
    for (int i = 1; i <= N; i++)
    {
        if (i == to[i])
        {
        }
        else if (i == to[to[i]])
        {
            taken[i] = true;
            taken[to[i]] = true;
        }
    }
    for (int i = 1; i <= N; i++)
    {
        if (not taken[i])
            pq.push({-cnt[i], i});
    }
    while (pq.size())
    {
        auto [k, i] = pq.top();
        pq.pop();
        if (-k != cnt[i] or taken[i])
            continue;
        ans++;
        if (taken[to[i]])
        {
            continue;
        }
        cnt[to[to[i]]]--;
        pq.push({-cnt[to[to[i]]], to[to[i]]});
        taken[i] = taken[to[i]] = true;
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 75 ms 12816 KB Output is correct
5 Correct 74 ms 12628 KB Output is correct
6 Correct 75 ms 12728 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 10568 KB Output is correct
2 Correct 97 ms 12736 KB Output is correct
3 Correct 77 ms 12736 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 84 ms 12760 KB Output is correct
6 Correct 105 ms 12764 KB Output is correct
7 Correct 94 ms 12732 KB Output is correct
8 Correct 76 ms 12740 KB Output is correct
9 Correct 75 ms 12736 KB Output is correct
10 Correct 57 ms 12212 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 75 ms 12816 KB Output is correct
20 Correct 74 ms 12628 KB Output is correct
21 Correct 75 ms 12728 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 73 ms 10568 KB Output is correct
24 Correct 97 ms 12736 KB Output is correct
25 Correct 77 ms 12736 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 84 ms 12760 KB Output is correct
28 Correct 105 ms 12764 KB Output is correct
29 Correct 94 ms 12732 KB Output is correct
30 Correct 76 ms 12740 KB Output is correct
31 Correct 75 ms 12736 KB Output is correct
32 Correct 57 ms 12212 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 80 ms 12728 KB Output is correct
38 Correct 101 ms 12780 KB Output is correct
39 Correct 98 ms 12724 KB Output is correct
40 Correct 92 ms 12772 KB Output is correct
41 Correct 74 ms 12676 KB Output is correct
42 Correct 77 ms 12696 KB Output is correct
43 Correct 95 ms 12756 KB Output is correct
44 Correct 109 ms 12744 KB Output is correct
45 Correct 79 ms 12692 KB Output is correct
46 Correct 78 ms 12772 KB Output is correct
47 Correct 69 ms 12676 KB Output is correct
48 Correct 92 ms 12768 KB Output is correct
49 Correct 103 ms 12776 KB Output is correct
50 Correct 69 ms 12748 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 78 ms 12688 KB Output is correct
53 Correct 80 ms 12788 KB Output is correct
54 Correct 98 ms 12664 KB Output is correct
55 Correct 75 ms 12692 KB Output is correct
56 Correct 73 ms 12736 KB Output is correct
57 Correct 58 ms 12224 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 0 ms 212 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 84 ms 12668 KB Output is correct
66 Correct 73 ms 12664 KB Output is correct
67 Correct 78 ms 12748 KB Output is correct
68 Correct 0 ms 340 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 336 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 1 ms 212 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 0 ms 340 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 0 ms 212 KB Output is correct
81 Correct 1 ms 212 KB Output is correct
82 Correct 1 ms 328 KB Output is correct
83 Correct 1 ms 332 KB Output is correct