# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1089927 |
2024-09-17T12:03:37 Z |
gyg |
Love Polygon (BOI18_polygon) |
C++17 |
|
143 ms |
23604 KB |
#include <bits/stdc++.h>
using namespace std;
#define arr array
#define vct vector
#define hmap unordered_map
#define str string
#define pii pair<int, int>
#define hset unordered_set
const int MX_N = 1e5 + 5;
int n;
arr<int, MX_N> ot;
arr<int, MX_N> in_cnt;
arr<bool, MX_N> dltd;
set<pii> ord; // {in_cnt[u], u}
void intls() {
for (int u = 1; u <= n; u++) in_cnt[ot[u]]++;
for (int u = 1; u <= n; u++) ord.insert({in_cnt[u], u});
}
void dlt(int u) {
dltd[u] = true;
ord.erase({in_cnt[u], u});
if (dltd[ot[u]]) return;
ord.erase({in_cnt[ot[u]], ot[u]});
in_cnt[ot[u]]--;
ord.insert({in_cnt[ot[u]], ot[u]});
}
int prcmp() {
int ans = 0;
for (int u = 1; u <= n; u++) {
if (dltd[u]) continue;
if (ot[u] == u) continue;
if (ot[ot[u]] != u) continue;
ans += 2;
dlt(u), dlt(ot[u]);
}
return ans;
}
int grdy() {
int ans = 0;
while (ord.size()) {
int u = ord.begin()->second;
if (ot[u] == u || dltd[ot[u]]) { dlt(u); continue; }
ans++;
dlt(u), dlt(ot[u]);
}
return ans;
}
int main() {
// freopen("lv.in", "r", stdin);
cin >> n;
hmap<int, str> ot_str;
hmap<str, int> ind;
for (int u = 1; u <= n; u++) {
str x, y; cin >> x >> y;
ind[x] = u, ot_str[u] = y;
}
for (int u = 1; u <= n; u++) ot[u] = ind[ot_str[u]];
if (n % 2 == 1) { cout << -1 << endl; exit(0); }
intls();
int ans = prcmp() + grdy();
cout << n - ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
444 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
444 KB |
Output is correct |
12 |
Correct |
0 ms |
444 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
129 ms |
23192 KB |
Output is correct |
5 |
Correct |
120 ms |
23180 KB |
Output is correct |
6 |
Correct |
115 ms |
23352 KB |
Output is correct |
7 |
Correct |
66 ms |
17976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
23384 KB |
Output is correct |
2 |
Correct |
132 ms |
23348 KB |
Output is correct |
3 |
Correct |
92 ms |
23356 KB |
Output is correct |
4 |
Correct |
67 ms |
18208 KB |
Output is correct |
5 |
Correct |
119 ms |
23356 KB |
Output is correct |
6 |
Correct |
142 ms |
23348 KB |
Output is correct |
7 |
Correct |
134 ms |
23348 KB |
Output is correct |
8 |
Correct |
111 ms |
23348 KB |
Output is correct |
9 |
Correct |
107 ms |
23308 KB |
Output is correct |
10 |
Correct |
83 ms |
22920 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
444 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
444 KB |
Output is correct |
12 |
Correct |
0 ms |
444 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
129 ms |
23192 KB |
Output is correct |
20 |
Correct |
120 ms |
23180 KB |
Output is correct |
21 |
Correct |
115 ms |
23352 KB |
Output is correct |
22 |
Correct |
66 ms |
17976 KB |
Output is correct |
23 |
Correct |
123 ms |
23384 KB |
Output is correct |
24 |
Correct |
132 ms |
23348 KB |
Output is correct |
25 |
Correct |
92 ms |
23356 KB |
Output is correct |
26 |
Correct |
67 ms |
18208 KB |
Output is correct |
27 |
Correct |
119 ms |
23356 KB |
Output is correct |
28 |
Correct |
142 ms |
23348 KB |
Output is correct |
29 |
Correct |
134 ms |
23348 KB |
Output is correct |
30 |
Correct |
111 ms |
23348 KB |
Output is correct |
31 |
Correct |
107 ms |
23308 KB |
Output is correct |
32 |
Correct |
83 ms |
22920 KB |
Output is correct |
33 |
Correct |
0 ms |
600 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
123 ms |
23260 KB |
Output is correct |
38 |
Correct |
131 ms |
23352 KB |
Output is correct |
39 |
Correct |
125 ms |
23352 KB |
Output is correct |
40 |
Correct |
121 ms |
23400 KB |
Output is correct |
41 |
Correct |
121 ms |
23352 KB |
Output is correct |
42 |
Correct |
142 ms |
23360 KB |
Output is correct |
43 |
Correct |
143 ms |
23604 KB |
Output is correct |
44 |
Correct |
117 ms |
23204 KB |
Output is correct |
45 |
Correct |
119 ms |
23228 KB |
Output is correct |
46 |
Correct |
137 ms |
23352 KB |
Output is correct |
47 |
Correct |
119 ms |
23352 KB |
Output is correct |
48 |
Correct |
124 ms |
23244 KB |
Output is correct |
49 |
Correct |
135 ms |
23352 KB |
Output is correct |
50 |
Correct |
89 ms |
23352 KB |
Output is correct |
51 |
Correct |
67 ms |
18108 KB |
Output is correct |
52 |
Correct |
117 ms |
23276 KB |
Output is correct |
53 |
Correct |
116 ms |
23340 KB |
Output is correct |
54 |
Correct |
117 ms |
23368 KB |
Output is correct |
55 |
Correct |
114 ms |
23356 KB |
Output is correct |
56 |
Correct |
96 ms |
23164 KB |
Output is correct |
57 |
Correct |
82 ms |
22844 KB |
Output is correct |
58 |
Correct |
0 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
0 ms |
348 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
115 ms |
23228 KB |
Output is correct |
66 |
Correct |
112 ms |
23348 KB |
Output is correct |
67 |
Correct |
128 ms |
23336 KB |
Output is correct |
68 |
Correct |
65 ms |
18064 KB |
Output is correct |
69 |
Correct |
0 ms |
348 KB |
Output is correct |
70 |
Correct |
0 ms |
348 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
600 KB |
Output is correct |
73 |
Correct |
0 ms |
344 KB |
Output is correct |
74 |
Correct |
0 ms |
348 KB |
Output is correct |
75 |
Correct |
1 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
0 ms |
348 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
0 ms |
348 KB |
Output is correct |
80 |
Correct |
0 ms |
440 KB |
Output is correct |
81 |
Correct |
0 ms |
348 KB |
Output is correct |
82 |
Correct |
0 ms |
344 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |