Submission #1048582

# Submission time Handle Problem Language Result Execution time Memory
1048582 2024-08-08T08:30:45 Z andrey27_sm Cubeword (CEOI19_cubeword) C++17
84 / 100
1100 ms 8240 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<int>> indeg(n,vector<int>(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();
}

Compilation message

cubeword.cpp:1: warning: ignoring '#pragma GCC optimze' [-Wunknown-pragmas]
    1 | #pragma GCC optimze("O3,unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 42 ms 7072 KB Output is correct
2 Correct 68 ms 7072 KB Output is correct
3 Correct 56 ms 7216 KB Output is correct
4 Correct 47 ms 7316 KB Output is correct
5 Correct 43 ms 7264 KB Output is correct
6 Correct 44 ms 7012 KB Output is correct
7 Correct 47 ms 7172 KB Output is correct
8 Correct 44 ms 7268 KB Output is correct
9 Correct 44 ms 7256 KB Output is correct
10 Correct 49 ms 7096 KB Output is correct
11 Correct 46 ms 7148 KB Output is correct
12 Correct 63 ms 7252 KB Output is correct
13 Correct 43 ms 7164 KB Output is correct
14 Correct 43 ms 7208 KB Output is correct
15 Correct 66 ms 7208 KB Output is correct
16 Correct 42 ms 7096 KB Output is correct
17 Correct 46 ms 7272 KB Output is correct
18 Correct 47 ms 7268 KB Output is correct
19 Correct 44 ms 7136 KB Output is correct
20 Correct 42 ms 7256 KB Output is correct
21 Correct 45 ms 7264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 7072 KB Output is correct
2 Correct 68 ms 7072 KB Output is correct
3 Correct 56 ms 7216 KB Output is correct
4 Correct 47 ms 7316 KB Output is correct
5 Correct 43 ms 7264 KB Output is correct
6 Correct 44 ms 7012 KB Output is correct
7 Correct 47 ms 7172 KB Output is correct
8 Correct 44 ms 7268 KB Output is correct
9 Correct 44 ms 7256 KB Output is correct
10 Correct 49 ms 7096 KB Output is correct
11 Correct 46 ms 7148 KB Output is correct
12 Correct 63 ms 7252 KB Output is correct
13 Correct 43 ms 7164 KB Output is correct
14 Correct 43 ms 7208 KB Output is correct
15 Correct 66 ms 7208 KB Output is correct
16 Correct 42 ms 7096 KB Output is correct
17 Correct 46 ms 7272 KB Output is correct
18 Correct 47 ms 7268 KB Output is correct
19 Correct 44 ms 7136 KB Output is correct
20 Correct 42 ms 7256 KB Output is correct
21 Correct 45 ms 7264 KB Output is correct
22 Correct 54 ms 6476 KB Output is correct
23 Correct 47 ms 6408 KB Output is correct
24 Correct 46 ms 6464 KB Output is correct
25 Correct 54 ms 6428 KB Output is correct
26 Correct 44 ms 6432 KB Output is correct
27 Correct 46 ms 6444 KB Output is correct
28 Correct 46 ms 6460 KB Output is correct
29 Correct 45 ms 6452 KB Output is correct
30 Correct 45 ms 6456 KB Output is correct
31 Correct 51 ms 6424 KB Output is correct
32 Correct 46 ms 6292 KB Output is correct
33 Correct 44 ms 6460 KB Output is correct
34 Correct 56 ms 6404 KB Output is correct
35 Correct 85 ms 6372 KB Output is correct
36 Correct 49 ms 6428 KB Output is correct
37 Correct 57 ms 6400 KB Output is correct
38 Correct 45 ms 6368 KB Output is correct
39 Correct 45 ms 6440 KB Output is correct
40 Correct 43 ms 6404 KB Output is correct
41 Correct 49 ms 6384 KB Output is correct
42 Correct 45 ms 6440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 7072 KB Output is correct
2 Correct 68 ms 7072 KB Output is correct
3 Correct 56 ms 7216 KB Output is correct
4 Correct 47 ms 7316 KB Output is correct
5 Correct 43 ms 7264 KB Output is correct
6 Correct 44 ms 7012 KB Output is correct
7 Correct 47 ms 7172 KB Output is correct
8 Correct 44 ms 7268 KB Output is correct
9 Correct 44 ms 7256 KB Output is correct
10 Correct 49 ms 7096 KB Output is correct
11 Correct 46 ms 7148 KB Output is correct
12 Correct 63 ms 7252 KB Output is correct
13 Correct 43 ms 7164 KB Output is correct
14 Correct 43 ms 7208 KB Output is correct
15 Correct 66 ms 7208 KB Output is correct
16 Correct 42 ms 7096 KB Output is correct
17 Correct 46 ms 7272 KB Output is correct
18 Correct 47 ms 7268 KB Output is correct
19 Correct 44 ms 7136 KB Output is correct
20 Correct 42 ms 7256 KB Output is correct
21 Correct 45 ms 7264 KB Output is correct
22 Correct 54 ms 6476 KB Output is correct
23 Correct 47 ms 6408 KB Output is correct
24 Correct 46 ms 6464 KB Output is correct
25 Correct 54 ms 6428 KB Output is correct
26 Correct 44 ms 6432 KB Output is correct
27 Correct 46 ms 6444 KB Output is correct
28 Correct 46 ms 6460 KB Output is correct
29 Correct 45 ms 6452 KB Output is correct
30 Correct 45 ms 6456 KB Output is correct
31 Correct 51 ms 6424 KB Output is correct
32 Correct 46 ms 6292 KB Output is correct
33 Correct 44 ms 6460 KB Output is correct
34 Correct 56 ms 6404 KB Output is correct
35 Correct 85 ms 6372 KB Output is correct
36 Correct 49 ms 6428 KB Output is correct
37 Correct 57 ms 6400 KB Output is correct
38 Correct 45 ms 6368 KB Output is correct
39 Correct 45 ms 6440 KB Output is correct
40 Correct 43 ms 6404 KB Output is correct
41 Correct 49 ms 6384 KB Output is correct
42 Correct 45 ms 6440 KB Output is correct
43 Correct 145 ms 6616 KB Output is correct
44 Correct 120 ms 6868 KB Output is correct
45 Correct 115 ms 6572 KB Output is correct
46 Correct 121 ms 6628 KB Output is correct
47 Correct 123 ms 6716 KB Output is correct
48 Correct 117 ms 6740 KB Output is correct
49 Correct 127 ms 6680 KB Output is correct
50 Correct 122 ms 6692 KB Output is correct
51 Correct 115 ms 6744 KB Output is correct
52 Correct 116 ms 6880 KB Output is correct
53 Correct 122 ms 6852 KB Output is correct
54 Correct 118 ms 6848 KB Output is correct
55 Correct 117 ms 6744 KB Output is correct
56 Correct 122 ms 6908 KB Output is correct
57 Correct 130 ms 6744 KB Output is correct
58 Correct 130 ms 6560 KB Output is correct
59 Correct 116 ms 6744 KB Output is correct
60 Correct 126 ms 6536 KB Output is correct
61 Correct 118 ms 6756 KB Output is correct
62 Correct 117 ms 6640 KB Output is correct
63 Correct 123 ms 6552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 7072 KB Output is correct
2 Correct 68 ms 7072 KB Output is correct
3 Correct 56 ms 7216 KB Output is correct
4 Correct 47 ms 7316 KB Output is correct
5 Correct 43 ms 7264 KB Output is correct
6 Correct 44 ms 7012 KB Output is correct
7 Correct 47 ms 7172 KB Output is correct
8 Correct 44 ms 7268 KB Output is correct
9 Correct 44 ms 7256 KB Output is correct
10 Correct 49 ms 7096 KB Output is correct
11 Correct 46 ms 7148 KB Output is correct
12 Correct 63 ms 7252 KB Output is correct
13 Correct 43 ms 7164 KB Output is correct
14 Correct 43 ms 7208 KB Output is correct
15 Correct 66 ms 7208 KB Output is correct
16 Correct 42 ms 7096 KB Output is correct
17 Correct 46 ms 7272 KB Output is correct
18 Correct 47 ms 7268 KB Output is correct
19 Correct 44 ms 7136 KB Output is correct
20 Correct 42 ms 7256 KB Output is correct
21 Correct 45 ms 7264 KB Output is correct
22 Correct 54 ms 6476 KB Output is correct
23 Correct 47 ms 6408 KB Output is correct
24 Correct 46 ms 6464 KB Output is correct
25 Correct 54 ms 6428 KB Output is correct
26 Correct 44 ms 6432 KB Output is correct
27 Correct 46 ms 6444 KB Output is correct
28 Correct 46 ms 6460 KB Output is correct
29 Correct 45 ms 6452 KB Output is correct
30 Correct 45 ms 6456 KB Output is correct
31 Correct 51 ms 6424 KB Output is correct
32 Correct 46 ms 6292 KB Output is correct
33 Correct 44 ms 6460 KB Output is correct
34 Correct 56 ms 6404 KB Output is correct
35 Correct 85 ms 6372 KB Output is correct
36 Correct 49 ms 6428 KB Output is correct
37 Correct 57 ms 6400 KB Output is correct
38 Correct 45 ms 6368 KB Output is correct
39 Correct 45 ms 6440 KB Output is correct
40 Correct 43 ms 6404 KB Output is correct
41 Correct 49 ms 6384 KB Output is correct
42 Correct 45 ms 6440 KB Output is correct
43 Correct 145 ms 6616 KB Output is correct
44 Correct 120 ms 6868 KB Output is correct
45 Correct 115 ms 6572 KB Output is correct
46 Correct 121 ms 6628 KB Output is correct
47 Correct 123 ms 6716 KB Output is correct
48 Correct 117 ms 6740 KB Output is correct
49 Correct 127 ms 6680 KB Output is correct
50 Correct 122 ms 6692 KB Output is correct
51 Correct 115 ms 6744 KB Output is correct
52 Correct 116 ms 6880 KB Output is correct
53 Correct 122 ms 6852 KB Output is correct
54 Correct 118 ms 6848 KB Output is correct
55 Correct 117 ms 6744 KB Output is correct
56 Correct 122 ms 6908 KB Output is correct
57 Correct 130 ms 6744 KB Output is correct
58 Correct 130 ms 6560 KB Output is correct
59 Correct 116 ms 6744 KB Output is correct
60 Correct 126 ms 6536 KB Output is correct
61 Correct 118 ms 6756 KB Output is correct
62 Correct 117 ms 6640 KB Output is correct
63 Correct 123 ms 6552 KB Output is correct
64 Execution timed out 1118 ms 8240 KB Time limit exceeded
65 Halted 0 ms 0 KB -