Submission #253982

# Submission time Handle Problem Language Result Execution time Memory
253982 2020-07-29T08:17:13 Z nabilervatra Cards (LMIO19_korteles) C++14
100 / 100
551 ms 72792 KB
#include <bits/stdc++.h>

#define pb push_back
using namespace std;
int n,satu,dua,empat;
vector<vector<int> > pairu(676*676+5),paird(676*676+5),pairr(676*676+5),pairl(676*676+5);
bool tmp1[680],tmp2[680],tmp3[680],tmp4[680];
bool ada[676*676+5];
string s[676*676+5],abaw,tms1,tms2,kaki,tms;
int hsh(string a){
    return int(a[0]-'A')*676*26+int(a[1]-'A')*676+int(a[2]-'A')*26+int(a[3]-'A');
}
string ts( char a, char b, char c , char d){
    string ret = "";
    ret.pb(a);
    ret.pb(b);
    ret.pb(c);
    ret.pb(d);
    return ret;
}

int main(){
    cin>>n;
    for(int i =1;i<=n;i++){
        string a,b;
        cin>>a>>b;
        s[i] = a+b;
        int u = (s[i][0]-'A')*26+ (s[i][1]-'A');
        int d = (s[i][2]-'A')*26+ (s[i][3]-'A');
        int l = (s[i][0]-'A')*26+ (s[i][2]-'A');
        int r = (s[i][1]-'A')*26+ (s[i][3]-'A');
        pairu[u].pb(d);
        paird[d].pb(u);
        pairl[l].pb(r);
        pairr[r].pb(l);
        ada[hsh(s[i])]=1;
    }
    for(int i =0;i<26*26;i++){
        satu+= pairu[i].size()*paird[i].size();
        memset(tmp1,0,sizeof(tmp1));
        memset(tmp2,0,sizeof(tmp2));
        memset(tmp3,0,sizeof(tmp3));
        memset(tmp4,0,sizeof(tmp4));

        for(auto j :pairu[i])tmp1[j]=1;
        for(auto j :paird[i])tmp2[j]=1;
        if(tmp1[i]&&tmp2[i])satu--;
        satu+= pairl[i].size()*pairr[i].size();
        for(auto j :pairl[i])tmp3[j]=1;
        for(auto j :pairr[i])tmp4[j]=1;
        if(tmp3[i]&&tmp4[i])satu--;
    }
    // cout<<satu<<endl;
    for(int i =1;i<=n;i++){
         abaw= ts(s[i][2],s[i][3],s[i][0],s[i][1]);
        // cout<<abaw<<endl;
        kaki=ts(s[i][1],s[i][0],s[i][3],s[i][2]);
        if(s[i]!=abaw&&ada[hsh(abaw)])dua++;
        if(s[i]!=kaki&&ada[hsh(kaki)])dua++;
        if(s[i][0]==s[i][3]&&s[i][2]==s[i][1]){
            tms = ts(s[i][1],s[i][0],s[i][3],s[i][2]);
            if(s[i]!=tms&&ada[hsh(tms)])empat++;
        }
        if(s[i][1]==s[i][2]){
            for(char j = 'A' ;j<='Z';j++){
                 tms1=ts(j,s[i][0],s[i][0],s[i][1]);
                 tms2 = ts(s[i][1],s[i][3],s[i][3],j);
                if(s[i]!=tms1&&ada[hsh(tms1)])dua++;
                if(s[i]!=tms2&&ada[hsh(tms2)])dua++;
            }
        }
        if(s[i][0]==s[i][3]){
            for(char j = 'A' ;j<='Z';j++){
                 tms1 = ts(s[i][1],j,s[i][0],s[i][1]);
                tms2 = ts(s[i][2],s[i][0],j,s[i][2]);
                if(s[i]!=tms1&&ada[hsh(tms1)])dua++;
                if(s[i]!=tms2&&ada[hsh(tms2)])dua++;
            }
        }
    }
    // cout<<dua<<' '<<empat<<endl;
    cout<<satu- dua/2 + (empat/2)*3<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 57592 KB Output is correct
2 Correct 40 ms 57600 KB Output is correct
3 Correct 34 ms 57720 KB Output is correct
4 Correct 34 ms 57756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 57592 KB Output is correct
2 Correct 41 ms 58112 KB Output is correct
3 Correct 38 ms 57720 KB Output is correct
4 Correct 37 ms 58112 KB Output is correct
5 Correct 38 ms 58112 KB Output is correct
6 Correct 39 ms 58112 KB Output is correct
7 Correct 43 ms 57592 KB Output is correct
8 Correct 34 ms 57592 KB Output is correct
9 Correct 40 ms 57600 KB Output is correct
10 Correct 34 ms 57720 KB Output is correct
11 Correct 34 ms 57756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 520 ms 72792 KB Output is correct
2 Correct 542 ms 72568 KB Output is correct
3 Correct 551 ms 72540 KB Output is correct
4 Correct 523 ms 72708 KB Output is correct
5 Correct 537 ms 72568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 57592 KB Output is correct
2 Correct 86 ms 59896 KB Output is correct
3 Correct 295 ms 65556 KB Output is correct
4 Correct 184 ms 64504 KB Output is correct
5 Correct 185 ms 64632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 57592 KB Output is correct
2 Correct 41 ms 58112 KB Output is correct
3 Correct 38 ms 57720 KB Output is correct
4 Correct 37 ms 58112 KB Output is correct
5 Correct 38 ms 58112 KB Output is correct
6 Correct 39 ms 58112 KB Output is correct
7 Correct 43 ms 57592 KB Output is correct
8 Correct 34 ms 57592 KB Output is correct
9 Correct 40 ms 57600 KB Output is correct
10 Correct 34 ms 57720 KB Output is correct
11 Correct 34 ms 57756 KB Output is correct
12 Correct 520 ms 72792 KB Output is correct
13 Correct 542 ms 72568 KB Output is correct
14 Correct 551 ms 72540 KB Output is correct
15 Correct 523 ms 72708 KB Output is correct
16 Correct 537 ms 72568 KB Output is correct
17 Correct 86 ms 59896 KB Output is correct
18 Correct 295 ms 65556 KB Output is correct
19 Correct 184 ms 64504 KB Output is correct
20 Correct 185 ms 64632 KB Output is correct
21 Correct 144 ms 61648 KB Output is correct
22 Correct 429 ms 70520 KB Output is correct
23 Correct 290 ms 65476 KB Output is correct
24 Correct 288 ms 65276 KB Output is correct