Submission #200057

# Submission time Handle Problem Language Result Execution time Memory
200057 2020-02-05T07:27:23 Z SamAnd Cards (LMIO19_korteles) C++17
100 / 100
249 ms 11512 KB
#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

korteles.cpp: In function 'int main()':
korteles.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
korteles.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %s", a[0]);
         ~~~~~^~~~~~~~~~~~~
korteles.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %s", a[1]);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 56 ms 504 KB Output is correct
2 Correct 56 ms 508 KB Output is correct
3 Correct 57 ms 1528 KB Output is correct
4 Correct 56 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 632 KB Output is correct
2 Correct 62 ms 6776 KB Output is correct
3 Correct 57 ms 1912 KB Output is correct
4 Correct 61 ms 8696 KB Output is correct
5 Correct 60 ms 6264 KB Output is correct
6 Correct 61 ms 7800 KB Output is correct
7 Correct 56 ms 508 KB Output is correct
8 Correct 56 ms 504 KB Output is correct
9 Correct 56 ms 508 KB Output is correct
10 Correct 57 ms 1528 KB Output is correct
11 Correct 56 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 241 ms 11512 KB Output is correct
2 Correct 242 ms 11468 KB Output is correct
3 Correct 244 ms 11512 KB Output is correct
4 Correct 249 ms 11512 KB Output is correct
5 Correct 243 ms 11512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 508 KB Output is correct
2 Correct 103 ms 9080 KB Output is correct
3 Correct 212 ms 10488 KB Output is correct
4 Correct 191 ms 9732 KB Output is correct
5 Correct 198 ms 9720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 632 KB Output is correct
2 Correct 62 ms 6776 KB Output is correct
3 Correct 57 ms 1912 KB Output is correct
4 Correct 61 ms 8696 KB Output is correct
5 Correct 60 ms 6264 KB Output is correct
6 Correct 61 ms 7800 KB Output is correct
7 Correct 56 ms 508 KB Output is correct
8 Correct 56 ms 504 KB Output is correct
9 Correct 56 ms 508 KB Output is correct
10 Correct 57 ms 1528 KB Output is correct
11 Correct 56 ms 1912 KB Output is correct
12 Correct 241 ms 11512 KB Output is correct
13 Correct 242 ms 11468 KB Output is correct
14 Correct 244 ms 11512 KB Output is correct
15 Correct 249 ms 11512 KB Output is correct
16 Correct 243 ms 11512 KB Output is correct
17 Correct 103 ms 9080 KB Output is correct
18 Correct 212 ms 10488 KB Output is correct
19 Correct 191 ms 9732 KB Output is correct
20 Correct 198 ms 9720 KB Output is correct
21 Correct 141 ms 9464 KB Output is correct
22 Correct 241 ms 10996 KB Output is correct
23 Correct 222 ms 10232 KB Output is correct
24 Correct 222 ms 10104 KB Output is correct