Submission #1048580

# Submission time Handle Problem Language Result Execution time Memory
1048580 2024-08-08T08:29:33 Z andrey27_sm Cubeword (CEOI19_cubeword) C++17
84 / 100
1100 ms 8972 KB
//#pragma GCC optimze("O3,unroll-loops")
//#pragma GCC target("avx,avx2,bmi,bmi2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll mod = 998244353;
ll tmp[62][62][62];
inline ll solve(vector<string> words){
    map<pair<char,char>,set<string>> mp;
    set<char> st;
    for(auto& word : words){
        st.insert(word[0]);
        st.insert(word.back());
        mp[{word[0],word.back()}].insert(word);
        reverse(word.begin(),word.end());
        mp[{word[0],word.back()}].insert(word);
        reverse(word.begin(),word.end());
    }
    vector<int> links(128,-1);
    int n = st.size();
    vector<vector<ll>> indeg(n,vector<ll>(n,0));
    {
        int i = 0;
        for(auto& c : st){
            links[c] = i++;
        }
    }
    for(auto& [k,v] : mp){
        if(v.size() > 0){
            indeg[links[k.first]][links[k.second]]+=v.size();
        }
    }
    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                tmp[i][j][k] = 0;
                for(int l = 0; l < n; l++){
                    ll ans1 = (ll)indeg[k][l] * indeg[i][l];
                    ans1%=mod;
                    ans1*=indeg[j][l];
                    ans1%=mod;
                    tmp[i][j][k] = (tmp[i][j][k] + ans1) % mod;
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){ // top
        for(int j = 0; j < n; j++){ // top
            for(int k = 0; k < n; k++){ // bot
                for (int l = 0; l < n; ++l) { // bot
                    ll ans_tmp = tmp[i][j][k]*tmp[i][j][l];
                    ans_tmp%=mod;
                    ans_tmp*=tmp[i][k][l];
                    ans_tmp%=mod;
                    ans_tmp*=tmp[j][k][l];
                    ans_tmp%=mod;
                    ans = (ans + ans_tmp) % mod;
                }
            }
        }
    }
    return ans;
}
inline void solve(){
    int n;
    cin >> n;
    vector<vector<string>> words(11,vector<string>());
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        words[s.size()].push_back(s);
    }
    ll ans = 0;
    for(int i = 1; i <= 10; i++){
        if(words[i].empty()) continue;
        ans = (ans + solve(words[i])) % mod;
    }
    cout << ans << "\n";

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}
# Verdict Execution time Memory Grader output
1 Correct 42 ms 7160 KB Output is correct
2 Correct 42 ms 8024 KB Output is correct
3 Correct 45 ms 8416 KB Output is correct
4 Correct 45 ms 8128 KB Output is correct
5 Correct 42 ms 8024 KB Output is correct
6 Correct 42 ms 8112 KB Output is correct
7 Correct 56 ms 7980 KB Output is correct
8 Correct 45 ms 8092 KB Output is correct
9 Correct 50 ms 8028 KB Output is correct
10 Correct 43 ms 7956 KB Output is correct
11 Correct 42 ms 8132 KB Output is correct
12 Correct 42 ms 7988 KB Output is correct
13 Correct 45 ms 7944 KB Output is correct
14 Correct 41 ms 7988 KB Output is correct
15 Correct 42 ms 8128 KB Output is correct
16 Correct 47 ms 8180 KB Output is correct
17 Correct 42 ms 7976 KB Output is correct
18 Correct 42 ms 7916 KB Output is correct
19 Correct 43 ms 7912 KB Output is correct
20 Correct 43 ms 7888 KB Output is correct
21 Correct 42 ms 8024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 7160 KB Output is correct
2 Correct 42 ms 8024 KB Output is correct
3 Correct 45 ms 8416 KB Output is correct
4 Correct 45 ms 8128 KB Output is correct
5 Correct 42 ms 8024 KB Output is correct
6 Correct 42 ms 8112 KB Output is correct
7 Correct 56 ms 7980 KB Output is correct
8 Correct 45 ms 8092 KB Output is correct
9 Correct 50 ms 8028 KB Output is correct
10 Correct 43 ms 7956 KB Output is correct
11 Correct 42 ms 8132 KB Output is correct
12 Correct 42 ms 7988 KB Output is correct
13 Correct 45 ms 7944 KB Output is correct
14 Correct 41 ms 7988 KB Output is correct
15 Correct 42 ms 8128 KB Output is correct
16 Correct 47 ms 8180 KB Output is correct
17 Correct 42 ms 7976 KB Output is correct
18 Correct 42 ms 7916 KB Output is correct
19 Correct 43 ms 7912 KB Output is correct
20 Correct 43 ms 7888 KB Output is correct
21 Correct 42 ms 8024 KB Output is correct
22 Correct 43 ms 7168 KB Output is correct
23 Correct 51 ms 7204 KB Output is correct
24 Correct 44 ms 7136 KB Output is correct
25 Correct 44 ms 7136 KB Output is correct
26 Correct 45 ms 7168 KB Output is correct
27 Correct 44 ms 7216 KB Output is correct
28 Correct 44 ms 7192 KB Output is correct
29 Correct 53 ms 7252 KB Output is correct
30 Correct 45 ms 7256 KB Output is correct
31 Correct 51 ms 7180 KB Output is correct
32 Correct 43 ms 7060 KB Output is correct
33 Correct 46 ms 7256 KB Output is correct
34 Correct 45 ms 6996 KB Output is correct
35 Correct 43 ms 7192 KB Output is correct
36 Correct 44 ms 7012 KB Output is correct
37 Correct 44 ms 7196 KB Output is correct
38 Correct 47 ms 7112 KB Output is correct
39 Correct 44 ms 7208 KB Output is correct
40 Correct 47 ms 7472 KB Output is correct
41 Correct 43 ms 7140 KB Output is correct
42 Correct 43 ms 7208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 7160 KB Output is correct
2 Correct 42 ms 8024 KB Output is correct
3 Correct 45 ms 8416 KB Output is correct
4 Correct 45 ms 8128 KB Output is correct
5 Correct 42 ms 8024 KB Output is correct
6 Correct 42 ms 8112 KB Output is correct
7 Correct 56 ms 7980 KB Output is correct
8 Correct 45 ms 8092 KB Output is correct
9 Correct 50 ms 8028 KB Output is correct
10 Correct 43 ms 7956 KB Output is correct
11 Correct 42 ms 8132 KB Output is correct
12 Correct 42 ms 7988 KB Output is correct
13 Correct 45 ms 7944 KB Output is correct
14 Correct 41 ms 7988 KB Output is correct
15 Correct 42 ms 8128 KB Output is correct
16 Correct 47 ms 8180 KB Output is correct
17 Correct 42 ms 7976 KB Output is correct
18 Correct 42 ms 7916 KB Output is correct
19 Correct 43 ms 7912 KB Output is correct
20 Correct 43 ms 7888 KB Output is correct
21 Correct 42 ms 8024 KB Output is correct
22 Correct 43 ms 7168 KB Output is correct
23 Correct 51 ms 7204 KB Output is correct
24 Correct 44 ms 7136 KB Output is correct
25 Correct 44 ms 7136 KB Output is correct
26 Correct 45 ms 7168 KB Output is correct
27 Correct 44 ms 7216 KB Output is correct
28 Correct 44 ms 7192 KB Output is correct
29 Correct 53 ms 7252 KB Output is correct
30 Correct 45 ms 7256 KB Output is correct
31 Correct 51 ms 7180 KB Output is correct
32 Correct 43 ms 7060 KB Output is correct
33 Correct 46 ms 7256 KB Output is correct
34 Correct 45 ms 6996 KB Output is correct
35 Correct 43 ms 7192 KB Output is correct
36 Correct 44 ms 7012 KB Output is correct
37 Correct 44 ms 7196 KB Output is correct
38 Correct 47 ms 7112 KB Output is correct
39 Correct 44 ms 7208 KB Output is correct
40 Correct 47 ms 7472 KB Output is correct
41 Correct 43 ms 7140 KB Output is correct
42 Correct 43 ms 7208 KB Output is correct
43 Correct 119 ms 7592 KB Output is correct
44 Correct 114 ms 7688 KB Output is correct
45 Correct 114 ms 7508 KB Output is correct
46 Correct 113 ms 7396 KB Output is correct
47 Correct 115 ms 7404 KB Output is correct
48 Correct 121 ms 7408 KB Output is correct
49 Correct 114 ms 7404 KB Output is correct
50 Correct 113 ms 7496 KB Output is correct
51 Correct 113 ms 7376 KB Output is correct
52 Correct 113 ms 7512 KB Output is correct
53 Correct 113 ms 7536 KB Output is correct
54 Correct 113 ms 7800 KB Output is correct
55 Correct 113 ms 7488 KB Output is correct
56 Correct 115 ms 7636 KB Output is correct
57 Correct 112 ms 7492 KB Output is correct
58 Correct 112 ms 7472 KB Output is correct
59 Correct 132 ms 7396 KB Output is correct
60 Correct 119 ms 7444 KB Output is correct
61 Correct 117 ms 7472 KB Output is correct
62 Correct 112 ms 7296 KB Output is correct
63 Correct 121 ms 7328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 7160 KB Output is correct
2 Correct 42 ms 8024 KB Output is correct
3 Correct 45 ms 8416 KB Output is correct
4 Correct 45 ms 8128 KB Output is correct
5 Correct 42 ms 8024 KB Output is correct
6 Correct 42 ms 8112 KB Output is correct
7 Correct 56 ms 7980 KB Output is correct
8 Correct 45 ms 8092 KB Output is correct
9 Correct 50 ms 8028 KB Output is correct
10 Correct 43 ms 7956 KB Output is correct
11 Correct 42 ms 8132 KB Output is correct
12 Correct 42 ms 7988 KB Output is correct
13 Correct 45 ms 7944 KB Output is correct
14 Correct 41 ms 7988 KB Output is correct
15 Correct 42 ms 8128 KB Output is correct
16 Correct 47 ms 8180 KB Output is correct
17 Correct 42 ms 7976 KB Output is correct
18 Correct 42 ms 7916 KB Output is correct
19 Correct 43 ms 7912 KB Output is correct
20 Correct 43 ms 7888 KB Output is correct
21 Correct 42 ms 8024 KB Output is correct
22 Correct 43 ms 7168 KB Output is correct
23 Correct 51 ms 7204 KB Output is correct
24 Correct 44 ms 7136 KB Output is correct
25 Correct 44 ms 7136 KB Output is correct
26 Correct 45 ms 7168 KB Output is correct
27 Correct 44 ms 7216 KB Output is correct
28 Correct 44 ms 7192 KB Output is correct
29 Correct 53 ms 7252 KB Output is correct
30 Correct 45 ms 7256 KB Output is correct
31 Correct 51 ms 7180 KB Output is correct
32 Correct 43 ms 7060 KB Output is correct
33 Correct 46 ms 7256 KB Output is correct
34 Correct 45 ms 6996 KB Output is correct
35 Correct 43 ms 7192 KB Output is correct
36 Correct 44 ms 7012 KB Output is correct
37 Correct 44 ms 7196 KB Output is correct
38 Correct 47 ms 7112 KB Output is correct
39 Correct 44 ms 7208 KB Output is correct
40 Correct 47 ms 7472 KB Output is correct
41 Correct 43 ms 7140 KB Output is correct
42 Correct 43 ms 7208 KB Output is correct
43 Correct 119 ms 7592 KB Output is correct
44 Correct 114 ms 7688 KB Output is correct
45 Correct 114 ms 7508 KB Output is correct
46 Correct 113 ms 7396 KB Output is correct
47 Correct 115 ms 7404 KB Output is correct
48 Correct 121 ms 7408 KB Output is correct
49 Correct 114 ms 7404 KB Output is correct
50 Correct 113 ms 7496 KB Output is correct
51 Correct 113 ms 7376 KB Output is correct
52 Correct 113 ms 7512 KB Output is correct
53 Correct 113 ms 7536 KB Output is correct
54 Correct 113 ms 7800 KB Output is correct
55 Correct 113 ms 7488 KB Output is correct
56 Correct 115 ms 7636 KB Output is correct
57 Correct 112 ms 7492 KB Output is correct
58 Correct 112 ms 7472 KB Output is correct
59 Correct 132 ms 7396 KB Output is correct
60 Correct 119 ms 7444 KB Output is correct
61 Correct 117 ms 7472 KB Output is correct
62 Correct 112 ms 7296 KB Output is correct
63 Correct 121 ms 7328 KB Output is correct
64 Correct 1088 ms 8940 KB Output is correct
65 Correct 1080 ms 8964 KB Output is correct
66 Execution timed out 1101 ms 8972 KB Time limit exceeded
67 Halted 0 ms 0 KB -