Submission #535835

# Submission time Handle Problem Language Result Execution time Memory
535835 2022-03-11T13:12:08 Z idas Cards (LMIO19_korteles) C++11
100 / 100
641 ms 27700 KB
#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

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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 641 ms 24920 KB Output is correct
2 Correct 587 ms 27592 KB Output is correct
3 Correct 587 ms 27700 KB Output is correct
4 Correct 594 ms 27672 KB Output is correct
5 Correct 615 ms 27672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 78 ms 8560 KB Output is correct
3 Correct 413 ms 23472 KB Output is correct
4 Correct 256 ms 17236 KB Output is correct
5 Correct 235 ms 17224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 4 ms 1236 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 3 ms 852 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 641 ms 24920 KB Output is correct
13 Correct 587 ms 27592 KB Output is correct
14 Correct 587 ms 27700 KB Output is correct
15 Correct 594 ms 27672 KB Output is correct
16 Correct 615 ms 27672 KB Output is correct
17 Correct 78 ms 8560 KB Output is correct
18 Correct 413 ms 23472 KB Output is correct
19 Correct 256 ms 17236 KB Output is correct
20 Correct 235 ms 17224 KB Output is correct
21 Correct 150 ms 14552 KB Output is correct
22 Correct 464 ms 26364 KB Output is correct
23 Correct 361 ms 24876 KB Output is correct
24 Correct 307 ms 24852 KB Output is correct