Submission #502111

# Submission time Handle Problem Language Result Execution time Memory
502111 2022-01-05T10:05:02 Z Marduk Cards (LMIO19_korteles) C++14
0 / 100
1000 ms 64928 KB
#include <bits/stdc++.h>
using namespace std;

#define X first
#define Y second

int n,sol;

map<pair<string,int>,int> m; //prefix, up/down, id
map<pair<string,string>,int> ob;

map<pair<string,int>,int> mf; //prefix, up/down, id
map<pair<string,string>,int> obf;

map<pair<string,string>,int> isti;
map<pair<char,char>,int> gay1, gay2, gay3, gay4, hm;

pair<string,string> Flip(string x, string y){
    return {string()+y[0]+x[0], string()+y[1]+x[1]};
}

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

    cin >> n;

    for(int i = 0;i<n;i++){
        string a,b; cin >> a >> b;

        sol+=m[{a,1}]+m[{b,0}]-ob[{b,a}];
        m[{a,0}]++;
        m[{b,1}]++;
        ob[{a,b}]++;

        pair<string,string> f = Flip(a,b);
        a = f.X; b = f.Y;

        sol+=mf[{a,1}]+mf[{b,0}]-obf[{b,a}];
        mf[{a,0}]++;
        mf[{b,1}]++;
        obf[{a,b}]++;

        if(b[0]==a[1]){
            sol-=gay4[{b[1],b[0]}];
            sol-=gay1[{b[0],a[0]}];
            gay1[{b[1],b[0]}]++;
            gay4[{b[0],a[0]}]++;
            if(a[0]==b[1]){
                sol+=hm[{a[1],a[0]}];
                hm[{a[0],a[1]}]++;
            }
        }
        if(a[0]==b[1]){
            sol-=gay3[{a[1],a[0]}];
            sol-=gay2[{a[0],b[0]}];
            gay2[{a[1],a[0]}]++;
            gay3[{a[0],b[0]}]++;
            if(a[1]==b[0]){
                sol+=hm[{a[1],a[0]}];
//                hm[{a[0],a[1]}]++;
            }
        }

        if(a[0]==a[1] && a[1] == b[0] && b[0] == b[1]){
            sol+=isti[{a,b}];
            isti[{a,b}]++;
        }
    }

    cout << sol;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 64928 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 250 ms 21176 KB Output is correct
3 Execution timed out 1064 ms 60604 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -