# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
713673 | tamyte | Cards (LMIO19_korteles) | C++14 | 1063 ms | 16664 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
void setIO(string name = "")
{
cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
if (sz(name))
{
freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
freopen((name + ".out").c_str(), "w", stdout);
}
}
/*----------------------------------*/
vector<int> match[4][26][26]; // 0 - up, 1 - down, 2 - left, 3 - right
struct cards
{
char a, b, c, d;
};
int main()
{
setIO("");
int n;
cin >> n;
// cout << 'Z' - 65;
// return 0;
vector<cards> arr(n);
for (int i = 0; i < n; ++i) {
cin >> arr[i].a >> arr[i].b >> arr[i].c >> arr[i].d;
match[0][arr[i].a - 'A'][arr[i].b - 'A'].push_back(i);
match[1][arr[i].c - 'A'][arr[i].d - 'A'].push_back(i);
match[2][arr[i].a - 'A'][arr[i].c - 'A'].push_back(i);
match[3][arr[i].b - 'A'][arr[i].d - 'A'].push_back(i);
}
reverse(arr.begin(), arr.end());
int ans = 0;
for (int i = 0; i < n; ++i) {
set<int> st;
st.insert(n - i - 1);
match[0][arr[i].a - 'A'][arr[i].b - 'A'].pop_back();
match[1][arr[i].c - 'A'][arr[i].d - 'A'].pop_back();
match[2][arr[i].a - 'A'][arr[i].c - 'A'].pop_back();
match[3][arr[i].b - 'A'][arr[i].d - 'A'].pop_back();
for (auto u : match[1][arr[i].a - 'A'][arr[i].b - 'A']) {
// cout << u << " ";
st.insert(u);
}
for (auto u : match[0][arr[i].c - 'A'][arr[i].d - 'A']) {
// cout << u << " ";
st.insert(u);
}
for (auto u : match[3][arr[i].a - 'A'][arr[i].c - 'A']) {
// cout << u << " ";
st.insert(u);
}
for (auto u : match[2][arr[i].b - 'A'][arr[i].d - 'A']) {
// cout << u << " ";
st.insert(u);
}
ans += st.size() - 1;
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |