Submission #578858

# Submission time Handle Problem Language Result Execution time Memory
578858 2022-06-18T06:14:08 Z talant117408 Cubeword (CEOI19_cubeword) C++17
0 / 100
197 ms 18480 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define long                unsigned long 
#define pb                  push_back
#define mp                  make_pair
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define lb                  lower_bound
#define ub                  upper_bound
#define sz(v)               int((v).size())
#define do_not_disturb      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl                '\n'

const int mod = 998244353;

ll add(ll a, ll b) {
    return ((a + b) % mod + mod) % mod;
}

ll mult(ll a, ll b) {
    return ((a * b) % mod + mod) % mod;
}

int index(char ch) {
    if ('a' <= ch && ch <= 'z') return int(ch-'a');
    else if ('A' <= ch && ch <= 'Z') return int(ch-'A')+26;
    else return int(ch-'0')+52;
}

ll ways[62][62], dp[9][62][62];

void solve() {
    int n;
    cin >> n;
    vector <string> v;
    set <string> st;
    
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        auto s2 = s;
        reverse(all(s2));
        int last = sz(st);
        st.insert(s2);
        if (last == sz(st)) {
            
        }
        else {
            st.insert(s);
            v.pb(s);
        }
    }
    
    for (auto to : v) {
        if (to[0] == to.back()) {
            auto to2 = to;
            reverse(all(to2));
            ways[index(to.back())][index(to.back())] += 1 + (to != to2);
        }
        else {
            ways[index(to[0])][index(to.back())]++;
            ways[index(to.back())][index(to[0])]++;
        }
    }
    
    
    
    ll ans = 0;
    
    for (int _1 = 0; _1 < 6; _1++) 
    for (int _2 = 0; _2 < 6; _2++)
    for (int _3 = 0; _3 < 6; _3++)
    for (int _4 = 0; _4 < 6; _4++)
    for (int _5 = 0; _5 < 6; _5++)
    for (int _6 = 0; _6 < 6; _6++)
    for (int _7 = 0; _7 < 6; _7++)
    for (int _8 = 0; _8 < 6; _8++) {
        auto res = mult(ways[_1][_2], ways[_1][_3]);
        res = mult(res, ways[_4][_2]);
        res = mult(res, ways[_4][_3]);
        res = mult(res, ways[_5][_6]);
        res = mult(res, ways[_5][_7]);
        res = mult(res, ways[_8][_6]);
        res = mult(res, ways[_8][_7]);
        res = mult(res, ways[_1][_5]);
        res = mult(res, ways[_3][_7]);
        res = mult(res, ways[_2][_6]);
        res = mult(res, ways[_8][_4]);
        ans = add(res, ans);
    }
    
    cout << ans << endl;
}

int main() {
    do_not_disturb
    
    int t = 1;
    //~ cin >> t;
    while (t--) {
        solve();
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 197 ms 18480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 197 ms 18480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 197 ms 18480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 197 ms 18480 KB Output isn't correct
2 Halted 0 ms 0 KB -