Submission #446292

# Submission time Handle Problem Language Result Execution time Memory
446292 2021-07-21T13:51:12 Z qwerasdfzxcl Cubeword (CEOI19_cubeword) C++14
0 / 100
1100 ms 21608 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
const int MOD = 998244353;
int cnt[101][101][101];
int a[8], b[12] = {0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7}, c[12] = {1, 2, 3, 0, 4, 5, 6, 7, 5, 6, 7, 4};
int mp[505], val[11][101][101][101];

ll calc(int len){
    ll ret = 1;
    for (int i=0;i<12;i++){
        ret *= cnt[len][a[b[i]]][a[c[i]]];
        ret %= MOD;
    }
    return ret;
}

bool nxt(int mx){
    bool flag = 1;
    for (int i=0;i<8;i++) if (a[i]!=mx-1) flag = 0;
    if (flag) return 0;
    a[7]++;
    for (int i=7;i>0;i--){
        if (a[i]!=mx) break;
        a[i] = 0;
        a[i-1]++;
    }
    return 1;
}

bool chk(string &s){
    int n = s.size();
    for (int i=0;i<n;i++){
        int j = n-1-i;
        if (i>j) break;
        if (s[i]!=s[j]) return 0;
    }
    return 1;
}

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    unordered_set<string> st;

    for (int i='a';i<='z';i++){
        mp[i] = i-'a';
    }
    for (int i='A';i<='Z';i++){
        mp[i] = i-'A'+26;
    }
    for (int i='0';i<='9';i++){
        mp[i] = i-'0'+52;
    }
    for (int i=0;i<n;i++){
        string s;
        cin >> s;
        int idx1 = mp[s[0]], idx2 = mp[s.back()];
        cnt[(int)s.size()][idx1][idx2]++;
        cnt[(int)s.size()][idx2][idx1]++;
        if (st.find(s)!=st.end()){
            cnt[(int)s.size()][idx1][idx2]--;
            cnt[(int)s.size()][idx2][idx1]--;
            continue;
        }
        reverse(s.begin(), s.end());
        if (st.find(s)!=st.end()){
            cnt[(int)s.size()][idx1][idx2]--;
            cnt[(int)s.size()][idx2][idx1]--;
            continue;
        }
        if (chk(s)) cnt[(int)s.size()][idx2][idx1]--;
        st.insert(s);
    }

    for (int len=3;len<=10;len++){
        for (int i=0;i<62;i++){
            for (int j=0;j<62;j++){
                for (int k=0;k<62;k++){
                    for (int l=0;l<62;l++){
                        ll tmp = (ll)cnt[len][i][l] * cnt[len][j][l] %MOD;
                        tmp = (tmp*cnt[len][k][l])%MOD;
                        val[len][i][j][k] += tmp;
                        if (val[len][i][j][k]>=MOD) val[len][i][j][k] -= MOD;
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int len=3;len<=10;len++){
        for (int i=0;i<62;i++){
            for (int j=0;j<62;j++){
                for (int k=0;k<62;k++){
                    for (int l=0;l<62;l++){
                        ll tmp = val[len][i][j][k];
                        tmp = (tmp*val[len][i][j][l])%MOD;
                        tmp = (tmp*val[len][i][k][l])%MOD;
                        tmp = (tmp*val[len][j][k][l])%MOD;
                        ans += tmp;
                        if (ans>=MOD) ans -= MOD;
                    }
                }
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

cubeword.cpp: In function 'int main()':
cubeword.cpp:61:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   61 |         int idx1 = mp[s[0]], idx2 = mp[s.back()];
      |                           ^
cubeword.cpp:61:46: warning: array subscript has type 'char' [-Wchar-subscripts]
   61 |         int idx1 = mp[s[0]], idx2 = mp[s.back()];
      |                                        ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Execution timed out 1191 ms 21608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1191 ms 21608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1191 ms 21608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1191 ms 21608 KB Time limit exceeded
2 Halted 0 ms 0 KB -