Submission #446329

# Submission time Handle Problem Language Result Execution time Memory
446329 2021-07-21T14:43:43 Z qwerasdfzxcl Cubeword (CEOI19_cubeword) C++14
0 / 100
119 ms 15040 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#define MX 62

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];

inline 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[11];

    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()], len = s.size();
        cnt[len][idx1][idx2]++;
        cnt[len][idx2][idx1]++;
        if (st[len].find(s)!=st[len].end()){
            cnt[len][idx1][idx2]--;
            cnt[len][idx2][idx1]--;
            continue;
        }
        reverse(s.begin(), s.end());
        if (st[len].find(s)!=st[len].end()){
            cnt[len][idx1][idx2]--;
            cnt[len][idx2][idx1]--;
            continue;
        }
        if (chk(s)) cnt[(int)s.size()][idx2][idx1]--;
        st[len].insert(s);
    }

    for (register int len=3;len<=10;len++){
        for (register int i=0;i<MX;i++){
            for (register int j=i;j<MX;j++){
                for (register int k=j;k<MX;k++){
                    for (register int l=0;l<MX;l++){
                        ll tmp = (ll)cnt[len][i][l] * cnt[len][j][l];
                        if (tmp>=MOD) tmp %= MOD;
                        tmp *= cnt[len][k][l];
                        if (tmp>=MOD) tmp %= MOD;
                        val[len][i][j][k] += tmp;
                        if (val[len][i][j][k]>=MOD) val[len][i][j][k] -= MOD;
                    }
                }
            }
        }
    }
    int ans = 0;
    for (register int len=3;len<=10;len++){
        for (register int i=0;i<MX;i++){
            for (register int j=i;j<MX;j++){
                for (register int k=j;k<MX;k++) if (val[len][i][j][k]){
                    for (register int l=k;l<MX;l++) {
                        ll tmp = val[len][i][j][k];
                        tmp *= val[len][i][j][l];
                        if (tmp>=MOD) tmp %= MOD;
                        tmp *= val[len][i][k][l];
                        if (tmp>=MOD) tmp %= MOD;
                        tmp *= val[len][j][k][l];
                        if (tmp>=MOD) tmp %= MOD;

                        if (i==j && j==k && k==l);
                        else if ((i==j && j==k) || (i==k && k==l) || (j==k && k==l) || (i==j && j==l) || (i==j && k==l) || (i==k && j==l) || (i==l && j==k)) tmp *= 2;
                        else if ((i==j) || i==k || i==l || j==k || j==l || k==l) tmp *= 6;
                        else tmp *= 24;
                        tmp %= MOD;
                        ans += tmp;
                        if (ans>=MOD) ans -= MOD;
                    }
                }
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

cubeword.cpp: In function 'int main()':
cubeword.cpp:42:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   42 |         int idx1 = mp[s[0]], idx2 = mp[s.back()], len = s.size();
      |                           ^
cubeword.cpp:42:46: warning: array subscript has type 'char' [-Wchar-subscripts]
   42 |         int idx1 = mp[s[0]], idx2 = mp[s.back()], len = s.size();
      |                                        ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Incorrect 119 ms 15040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 119 ms 15040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 119 ms 15040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 119 ms 15040 KB Output isn't correct
2 Halted 0 ms 0 KB -