Submission #261560

# Submission time Handle Problem Language Result Execution time Memory
261560 2020-08-11T21:16:48 Z JoMee Cubeword (CEOI19_cubeword) C++17
0 / 100
1070 ms 8568 KB
#include <bits/stdc++.h>
#define int long long 
using namespace std;
#define rep(i,a,n) for(int i = a; i<n; i++)
#define per(i,a,n) for(int i = n-1; i>=a; i--)

int max(int a,int b){return (a>b)?a:b;}
int min(int a,int b){return (a<b)?a:b;}


int n;

int mp(char c){
    int ret = 0;
    if(c >= 'a' && c<='z')ret = (c-'a');
    if(c >= 'A' && c<='Z')ret = 26+(c-'A');
    if(c >= '0' && c<='9')ret = 2*26+(c-'0');
    return ret;
} 


bool isPal(string &s1){
    rep(i,0,s1.size()){
        if(s1[i] != s1[s1.size()-1-i])return false;
    }
    return true;
}

int am[65][65];
int curr[8];
vector<int> adj[8];




int brute(int idx){
    int res = 0;
    rep(i,0,65){
        int cr = 1;
        curr[idx] = i;
        int dir = -1;
        for(auto j:adj[idx]){
            if(curr[j] != -1){
             cr = cr*am[i][curr[j]];
            }else{
                dir = j;
            }
            
        }
        if(cr == 0)continue;
        else{
            if(dir != -1){
                cr*=brute(dir);
            }
            res += cr;
        }
    }
    curr[idx] = -1;
    return res;
}


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    adj[0].push_back(1);adj[0].push_back(3);adj[0].push_back(5);
    adj[1].push_back(0);adj[1].push_back(6);adj[1].push_back(2);
    adj[2].push_back(1);adj[2].push_back(7);adj[2].push_back(3);
    adj[3].push_back(0);adj[3].push_back(4);adj[3].push_back(2);
    adj[4].push_back(7);adj[4].push_back(5);adj[4].push_back(3);
    adj[5].push_back(0);adj[5].push_back(6);adj[5].push_back(4);
    adj[6].push_back(5);adj[6].push_back(7);adj[6].push_back(1);
    adj[7].push_back(2);adj[7].push_back(6);adj[7].push_back(4);
    cin>>n;
    vector<set<string> > cubes(11);
    rep(i,0,n){
        string s;
        cin>>s;
        string k = s;
        reverse(k.begin(),k.end());
        if(s>k)swap(s,k);
        cubes[s.size()].insert(s);
    }

    int res = 0;
    rep(i,0,11){
        memset(am,0,sizeof(am));
        memset(curr,-1,sizeof(curr));
        for(auto j:cubes[i]){
            int v1,v2;
            v1 = mp(j[0]);
            v2 = mp(j[j.size()-1]);

            if(!isPal(j)){
                am[v1][v2]++;
                am[v2][v1]++;
            }else{
                am[v1][v2]++;
            }
        }
        res+=brute(0);
    }
    cout<<res<<"\n";

    

}

Compilation message

cubeword.cpp: In function 'bool isPal(std::__cxx11::string&)':
cubeword.cpp:4:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,a,n) for(int i = a; i<n; i++)
cubeword.cpp:23:9:
     rep(i,0,s1.size()){
         ~~~~~~~~~~~~~               
cubeword.cpp:23:5: note: in expansion of macro 'rep'
     rep(i,0,s1.size()){
     ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1070 ms 8568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1070 ms 8568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1070 ms 8568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1070 ms 8568 KB Output isn't correct
2 Halted 0 ms 0 KB -