# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200057 | SamAnd | Cards (LMIO19_korteles) | C++17 | 249 ms | 11512 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;
const int K = 26, Q = 4;
int n;
bool c[K][K][K][K];
int a[(1 << Q)][K][K][K][K];
int main()
{
scanf("%d", &n);
for (int i = 0; i < n; ++i)
{
char a[3][3];
scanf(" %s", a[0]);
scanf(" %s", a[1]);
c[a[0][0] - 'A'][a[0][1] - 'A'][a[1][0] - 'A'][a[1][1] - 'A'] = true;
}
for (int x = 0; x < (1 << Q); ++x)
{
int i[4];
for (i[0] = 0; i[0] < 26; ++i[0])
{
for (i[1] = 0; i[1] < 26; ++i[1])
{
for (i[2] = 0; i[2] < 26; ++i[2])
{
for (i[3] = 0; i[3] < 26; ++i[3])
{
if (!c[i[0]][i[1]][i[2]][i[3]])
continue;
int ii[4];
for (int j = 0; j < 4; ++j)
{
if ((x & (1 << j)))
ii[j] = i[j];
else
ii[j] = 0;
}
++a[x][ii[0]][ii[1]][ii[2]][ii[3]];
}
}
}
}
}
long long ans = 0;
for (int x = 1; x < (1 << Q); ++x)
{
int q = 0;
for (int i = 0; i < 4; ++i)
{
if ((x & (1 << i)))
++q;
}
int i[4];
for (i[0] = 0; i[0] < 26; ++i[0])
{
for (i[1] = 0; i[1] < 26; ++i[1])
{
for (i[2] = 0; i[2] < 26; ++i[2])
{
for (i[3] = 0; i[3] < 26; ++i[3])
{
if (!c[i[0]][i[1]][i[2]][i[3]])
continue;
int ii[4] = {-1, -1, -1, -1};
bool z = true;
for (int j = 0; j < 4; ++j)
{
if ((x & (1 << j)))
{
if (j == 0)
{
if (!(ii[0] == -1 || ii[0] == i[1]))
{
z = false;
break;
}
if (!(ii[2] == -1 || ii[2] == i[3]))
{
z = false;
break;
}
ii[0] = i[1];
ii[2] = i[3];
}
else if (j == 1)
{
if (!(ii[1] == -1 || ii[1] == i[0]))
{
z = false;
break;
}
if (!(ii[3] == -1 || ii[3] == i[2]))
{
z = false;
break;
}
ii[1] = i[0];
ii[3] = i[2];
}
else if (j == 2)
{
if (!(ii[0] == -1 || ii[0] == i[2]))
{
z = false;
break;
}
if (!(ii[1] == -1 || ii[1] == i[3]))
{
z = false;
break;
}
ii[0] = i[2];
ii[1] = i[3];
}
else if (j == 3)
{
if (!(ii[2] == -1 || ii[2] == i[0]))
{
z = false;
break;
}
if (!(ii[3] == -1 || ii[3] == i[1]))
{
z = false;
break;
}
ii[2] = i[0];
ii[3] = i[1];
}
}
}
if (!z)
continue;
int x = 0;
for (int j = 0; j < 4; ++j)
{
if (ii[j] != -1)
{
x |= (1 << j);
}
else
{
ii[j] = 0;
}
}
if (q % 2 == 1)
ans += a[x][ii[0]][ii[1]][ii[2]][ii[3]];
else
ans -= a[x][ii[0]][ii[1]][ii[2]][ii[3]];
for (int j = 0; j < 4; ++j)
{
if (!(x & (1 << j)))
continue;
if (ii[j] != i[j])
{
z = false;
break;
}
}
if (z)
{
if (q % 2 == 1)
--ans;
else
++ans;
}
}
}
}
}
}
ans /= 2;
printf("%lld\n", ans);
return 0;
}
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... |