Submission #501828

# Submission time Handle Problem Language Result Execution time Memory
501828 2022-01-04T16:12:03 Z fabijan_cikac Cards (LMIO19_korteles) C++17
100 / 100
835 ms 36296 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

const int N = 1e6;
const int M = 30;

int n;
map<string, ll> m;
ll sol = 0;
vector<string> v;
int g[N][M] = { 0 };
int kounter = 2;
int vel[N] = { 0 };

ll dio(string a, string b){
    for (int i = 0; i < a.size(); ++i){
        if (a[i] != '*' && a[i] != b[i])
            return 0;
    }
    return 1;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n; v.resize(n);
    for (int i = 0; i < n; ++i){
        string b; cin >> v[i] >> b;
        v[i].push_back(b[1]); v[i].push_back(b[0]);
        for (int j = 0; j < 16; ++j){
            string s;
            for (int k = 0; k < 4; ++k){
                if (j & (1 << k))
                    s.push_back(v[i][k]);
                else s.push_back('*');
            }
            int x = 1;
            for (int k = 0; k < 4; ++k){
                if (s[k] == '*' && g[x][M - 1] == 0){
                    g[x][M - 1] = kounter; ++kounter;
                    x = g[x][M - 1];
                }
                else if (s[k] != '*' && g[x][int(s[k]) - 65] == 0){
                    g[x][int(s[k]) - 65] = kounter;
                    x = kounter; ++kounter;
                }
                else{
                    if (s[k] == '*')
                        x = g[x][M - 1];
                    else x = g[x][int(s[k]) - 65];
                }
            }
            ++vel[x];
        }
    }
    for (int j = 0; j < n; ++j){
        string a = v[j]; string s = "****";
        for (int i = 1; i < 16; ++i){
            s = "****"; int cnt = 0;
            if (i & 1){
                if ((s[3] != '*' && s[3] != a[0]) || (s[2] != '*' && s[2] != a[1]))
                    continue;
                s[3] = a[0]; s[2] = a[1]; ++cnt;
            }
            if (i & 2){
                if ((s[0] != '*' && s[0] != a[1]) || (s[3] != '*' && s[3] != a[2]))
                    continue;
                s[0] = a[1]; s[3] = a[2]; ++cnt;
            }
            if (i & 4){
                if ((s[0] != '*' && s[0] != a[3]) || (s[1] != '*' && s[1] != a[2]))
                    continue;
                s[0] = a[3]; s[1] = a[2]; ++cnt;
            }
            if (i & 8){
                if ((s[1] != '*' && s[1] != a[0]) || (s[2] != '*' && s[2] != a[3]))
                    continue;
                s[1] = a[0]; s[2] = a[3]; ++cnt;
            }
            int x = 1;
            for (int k = 0; k < 4; ++k){
                if (s[k] == '*')
                    x = g[x][M - 1];
                else x = g[x][int(s[k]) - 65];
            }
            if (x == 0)
                continue;
            if (cnt & 1)
                sol += (vel[x] - dio(s, a));
            else sol -= (vel[x] - dio(s, a));
        }
    }
    cout << sol / 2;

    return 0;
}

Compilation message

korteles.cpp: In function 'll dio(std::string, std::string)':
korteles.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0; i < a.size(); ++i){
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 2 ms 1228 KB Output is correct
7 Correct 3 ms 844 KB Output is correct
8 Correct 5 ms 2948 KB Output is correct
9 Correct 5 ms 1868 KB Output is correct
10 Correct 4 ms 1996 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 786 ms 35900 KB Output is correct
2 Correct 784 ms 36208 KB Output is correct
3 Correct 763 ms 36292 KB Output is correct
4 Correct 835 ms 36296 KB Output is correct
5 Correct 756 ms 36156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 84 ms 17524 KB Output is correct
3 Correct 472 ms 27800 KB Output is correct
4 Correct 357 ms 23500 KB Output is correct
5 Correct 309 ms 23572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 2 ms 1228 KB Output is correct
3 Correct 3 ms 844 KB Output is correct
4 Correct 5 ms 2948 KB Output is correct
5 Correct 5 ms 1868 KB Output is correct
6 Correct 4 ms 1996 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 786 ms 35900 KB Output is correct
13 Correct 784 ms 36208 KB Output is correct
14 Correct 763 ms 36292 KB Output is correct
15 Correct 835 ms 36296 KB Output is correct
16 Correct 756 ms 36156 KB Output is correct
17 Correct 84 ms 17524 KB Output is correct
18 Correct 472 ms 27800 KB Output is correct
19 Correct 357 ms 23500 KB Output is correct
20 Correct 309 ms 23572 KB Output is correct
21 Correct 191 ms 23448 KB Output is correct
22 Correct 560 ms 32480 KB Output is correct
23 Correct 348 ms 28344 KB Output is correct
24 Correct 435 ms 28308 KB Output is correct