Submission #446288

# Submission time Handle Problem Language Result Execution time Memory
446288 2021-07-21T13:24:38 Z qwerasdfzxcl Cubeword (CEOI19_cubeword) C++14
0 / 100
985 ms 7684 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
const int MOD = 998244353;
int cnt[101][10][10];
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};

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 1;
    }
    return 0;
}

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    unordered_set<string> st;
    for (int i=0;i<n;i++){
        string s;
        cin >> s;
        cnt[(int)s.size()][s[0]-'a'][s.back()-'a']++;
        cnt[(int)s.size()][s.back()-'a'][s[0]-'a']++;
        if (st.find(s)!=st.end()){
            cnt[(int)s.size()][s[0]-'a'][s.back()-'a']--;
            cnt[(int)s.size()][s.back()-'a'][s[0]-'a']--;
            continue;
        }
        reverse(s.begin(), s.end());
        if (st.find(s)!=st.end()){
            cnt[(int)s.size()][s[0]-'a'][s.back()-'a']--;
            cnt[(int)s.size()][s.back()-'a'][s[0]-'a']--;
            continue;
        }
        if (s[0]==s.back() && chk(s)) cnt[(int)s.size()][s.back()-'a'][s[0]-'a']--;
        st.insert(s);
    }
    ll ans = 0;
    for (int len=3;len<=10;len++){
        for (int i=0;i<8;i++) a[i] = 0;
        while(true){
            ans = (ans+calc(len))%MOD;
            if (!nxt(6)) break;
        }
    }
    printf("%lld\n", ans);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 985 ms 7684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 985 ms 7684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 985 ms 7684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 985 ms 7684 KB Output isn't correct
2 Halted 0 ms 0 KB -