Submission #535835

#TimeUsernameProblemLanguageResultExecution timeMemory
535835idasCards (LMIO19_korteles)C++11
100 / 100
641 ms27700 KiB
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define all(x) (x).begin(), (x).end()
#define le(vec) vec[vec.size()-1]
#define sz(x) ((int)((x).size()))
#define pb push_back
#define s second
#define f first

using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;

const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e13;

void setIO()
{
    FAST_IO;
}

void setIO(string s)
{
    FAST_IO;
    freopen((s+".in").c_str(), "r", stdin);
    freopen((s+".out").c_str(), "w", stdout);
}

const int N=5e5+10;
int n;
ll ans;
char g[N][2][2];
unordered_map<int, int> Up, Left, Right, Down, LU, UR, RD, DL, all;

int con(char a, char b)
{
    int x=a-'A', y=b-'A';
    return 26*x+y;
}

int con(char a, char b, char c)
{
    int x=a-'A', y=b-'A', z=c-'A';
    return 26*26*x+26*y+z;
}

int con(char a, char b, char c, char d)
{
    int x=a-'A', y=b-'A', z=c-'A', w=d-'A';
    return 26*26*26*x+26*26*y+26*z+w;
}

int main()
{
    setIO();
    cin >> n;
    FOR(i, 0, n)
    {
        FOR(j, 0, 2)
        {
            FOR(k, 0, 2)
            {
                cin >> g[i][j][k];
            }
        }
    }

    FOR(i, 0, n)
    {
        char a=g[i][0][0], b=g[i][0][1], c=g[i][1][0], d=g[i][1][1];
        ans+=Up[con(c,d)];
        ans+=Right[con(a,c)];
        ans+=Down[con(a,b)];
        ans+=Left[con(b,d)];

        ans-=all[con(c,d,a,b)];
        ans-=all[con(b,a,d,c)];

        if(a==d){
            ans-=UR[con(c,a,c)];
            ans-=DL[con(b,a,b)];
        }
        if(b==c){
            ans-=LU[con(d,b,d)];
            ans-=RD[con(a,b,a)];
        }
        if(a==d && b==c){
            ans+=3*all[con(b,a,a,b)];
        }

        Up[con(a,b)]++;
        Right[con(b,d)]++;
        Down[con(c,d)]++;
        Left[con(a,c)]++;
        LU[con(c,a,b)]++;
        UR[con(a,b,d)]++;
        RD[con(b,d,c)]++;
        DL[con(d,c,a)]++;
        all[con(a,b,c,d)]++;
    }

    cout << ans;
}

Compilation message (stderr)

korteles.cpp: In function 'void setIO(std::string)':
korteles.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
korteles.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...