# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
502133 |
2022-01-05T10:49:11 Z |
Marduk |
Cards (LMIO19_korteles) |
C++14 |
|
342 ms |
29380 KB |
#include <string>
#include <vector>
#include <iostream>
#include <unordered_set>
using namespace std;
inline int hashing(string s) {
return int(s[0] - 'A') * 26 * 26 * 26 + int(s[1] - 'A') * 26 * 26 + int(s[2] - 'A') * 26 + int(s[3] - 'A');
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
vector<vector<int> > gl(676), gr(676), gu(676), gd(676);
vector<string> s(N);
vector<bool> st(676 * 676);
for (int i = 0; i < N; ++i) {
string sa, sb;
cin >> sa >> sb;
s[i] = sa + sb;
int cu = int(s[i][0] - 'A') * 26 + int(s[i][1] - 'A');
int cd = int(s[i][2] - 'A') * 26 + int(s[i][3] - 'A');
int cl = int(s[i][0] - 'A') * 26 + int(s[i][2] - 'A');
int cr = int(s[i][1] - 'A') * 26 + int(s[i][3] - 'A');
gu[cu].push_back(cd);
gd[cd].push_back(cu);
gl[cl].push_back(cr);
gr[cr].push_back(cl);
st[hashing(s[i])] = true;
}
int ans = 0;
for (int i = 0; i < 676; ++i) {
vector<int> va = gl[i], vb = gr[i];
ans += va.size() * vb.size();
vector<bool> fa(676), fb(676);
for (int j : va) fa[j] = true;
for (int j : vb) fb[j] = true;
if (fa[i] && fb[i]) --ans;
}
for (int i = 0; i < 676; ++i) {
vector<int> va = gu[i], vb = gd[i];
ans += va.size() * vb.size();
vector<bool> fa(676), fb(676);
for (int j : va) fa[j] = true;
for (int j : vb) fb[j] = true;
if (fa[i] && fb[i]) --ans;
}
int twos = 0, fours = 0;
for (int i = 0; i < N; ++i) {
string opp1 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, s[i][0]) + string(1, s[i][1]);
string opp2 = string(1, s[i][1]) + string(1, s[i][0]) + string(1, s[i][3]) + string(1, s[i][2]);
if (s[i] != opp1 && st[hashing(opp1)]) ++twos;
if (s[i] != opp2 && st[hashing(opp2)]) ++twos;
if (s[i][1] == s[i][2]) {
for (char c = 'A'; c <= 'Z'; ++c) {
string opp3 = string(1, c) + string(1, s[i][0]) + string(1, s[i][0]) + string(1, s[i][1]);
string opp4 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, s[i][3]) + string(1, c);
if (s[i] != opp3 && st[hashing(opp3)]) ++twos;
if (s[i] != opp4 && st[hashing(opp4)]) ++twos;
}
}
if (s[i][0] == s[i][3]) {
for (char c = 'A'; c <= 'Z'; ++c) {
string opp3 = string(1, s[i][1]) + string(1, c) + string(1, s[i][0]) + string(1, s[i][1]);
string opp4 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, c) + string(1, s[i][2]);
if (s[i] != opp3 && st[hashing(opp3)]) ++twos;
if (s[i] != opp4 && st[hashing(opp4)]) ++twos;
}
}
if (s[i][0] == s[i][3] && s[i][1] == s[i][2]) {
string opp5 = string(1, s[i][1]) + string(1, s[i][0]) + string(1, s[i][0]) + string(1, s[i][1]);
if (s[i] != opp5 && st[hashing(opp5)]) ++fours;
}
}
twos /= 2;
fours /= 2;
cout << ans - twos + fours * 3 << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
420 KB |
Output is correct |
2 |
Correct |
1 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
420 KB |
Output is correct |
2 |
Correct |
1 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
4 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
588 KB |
Output is correct |
9 |
Correct |
5 ms |
588 KB |
Output is correct |
10 |
Correct |
4 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
310 ms |
28336 KB |
Output is correct |
2 |
Correct |
342 ms |
29288 KB |
Output is correct |
3 |
Correct |
322 ms |
29272 KB |
Output is correct |
4 |
Correct |
324 ms |
29380 KB |
Output is correct |
5 |
Correct |
318 ms |
29276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
23 ms |
3524 KB |
Output is correct |
3 |
Correct |
124 ms |
16432 KB |
Output is correct |
4 |
Correct |
85 ms |
12412 KB |
Output is correct |
5 |
Correct |
78 ms |
12356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
4 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
588 KB |
Output is correct |
5 |
Correct |
5 ms |
588 KB |
Output is correct |
6 |
Correct |
4 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
420 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
310 ms |
28336 KB |
Output is correct |
13 |
Correct |
342 ms |
29288 KB |
Output is correct |
14 |
Correct |
322 ms |
29272 KB |
Output is correct |
15 |
Correct |
324 ms |
29380 KB |
Output is correct |
16 |
Correct |
318 ms |
29276 KB |
Output is correct |
17 |
Correct |
23 ms |
3524 KB |
Output is correct |
18 |
Correct |
124 ms |
16432 KB |
Output is correct |
19 |
Correct |
85 ms |
12412 KB |
Output is correct |
20 |
Correct |
78 ms |
12356 KB |
Output is correct |
21 |
Correct |
74 ms |
7140 KB |
Output is correct |
22 |
Correct |
309 ms |
23932 KB |
Output is correct |
23 |
Correct |
168 ms |
14748 KB |
Output is correct |
24 |
Correct |
175 ms |
15008 KB |
Output is correct |