Submission #261568

# Submission time Handle Problem Language Result Execution time Memory
261568 2020-08-11T21:32:29 Z JoMee Cubeword (CEOI19_cubeword) C++17
0 / 100
1100 ms 7288 KB
#include <bits/stdc++.h>
#include <unordered_map>
#define int long long 
using namespace std;

#define rep(i,a,n) for(signed 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 mod = 998244353;

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(const string &s1){
    rep(i,0,s1.size()){
        if(s1[i] != s1[s1.size()-1-i])return false;
    }
    return true;
}

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

int brute(int idx){
    int res = 0;
    rep(i,0,26){
        int cr = 1;
        curr[idx] = i;
        int dir = -1;
        for(auto j:adj[idx]){
            if(curr[j] != -1){
             cr = (cr*am[i][curr[j]])%mod;
            }else{
                dir = j;
            }
            
        }
        if(cr == 0)continue;
        else{
            if(dir != -1){
                cr=(cr*brute(dir))%mod;
            }
            res = (res+cr)%mod;
        }
    }
    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<unordered_map<string,bool> > 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()][s] = true;
    }

    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.first[0]);
            v2 = mp(j.first[j.first.size()-1]);

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

Compilation message

cubeword.cpp: In function 'bool isPal(const string&)':
cubeword.cpp:6:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,a,n) for(signed int i = a; i<n; i++)
cubeword.cpp:26:9:
     rep(i,0,s1.size()){
         ~~~~~~~~~~~~~                      
cubeword.cpp:26:5: note: in expansion of macro 'rep'
     rep(i,0,s1.size()){
     ^~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1187 ms 7288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1187 ms 7288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1187 ms 7288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1187 ms 7288 KB Time limit exceeded
2 Halted 0 ms 0 KB -