Submission #1138885

#TimeUsernameProblemLanguageResultExecution timeMemory
1138885RaduMCards (LMIO19_korteles)C++20
55 / 100
1101 ms142480 KiB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

vector < unordered_map <int, int> > mp(16);
string s[2];
int h[4];

int main()
{
    int n,i;
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    ll rez = 0;
    for(i = 1; i <= n; i++){
        for(int e = 0; e < 2; e++){
            cin.get();
            cin >> s[e];
        }
        h[0] = (s[0][0] - 65) * 26 + (s[0][1] - 65);
        h[2] = (s[1][0] - 65) * 26 + (s[1][1] - 65);
        h[1] = (s[0][0] - 65) * 26 + (s[1][0] - 65);
        h[3] = (s[0][1] - 65) * 26 + (s[1][1] - 65);
        for(int e = 1; e < 16; e++){
            int temp = 0;
            for(int j = 0; j < 4; j++){
                if((1 << j) & e) temp = temp * 676 + h[j ^ 2];
            }
            auto it = mp[e].find(temp);
            if(it != mp[e].end()){
                if(__builtin_popcount(e) & 1) rez += it->second;
                else rez -= it->second;
            }
        }
        for(int e = 1; e < 16; e++){
            int temp = 0;
            for(int j = 0; j < 4; j++){
                if((1 << j) & e) temp = temp * 676 + h[j];
            }
            mp[e][temp]++;
        }
    }
    cout << rez;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...