Submission #1039425

# Submission time Handle Problem Language Result Execution time Memory
1039425 2024-07-30T20:47:57 Z vjudge1 Cubeword (CEOI19_cubeword) C++17
100 / 100
813 ms 36312 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target("popcnt")
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using lld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int,int>;
using pll = pair<ll, ll>;
using vii = vector<ii>;
using vpll = vector<pll>;
 
#define endl '\n'
#define all(x) x.begin(),x.end()
#define lsb(x) x&(-x)
#define gcd(a,b) __gcd(a,b)
#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fls cout.flush()
 
#define fore(i,l,r) for(auto i=l;i<r;i++)
#define fo(i,n) fore(i,0,n)
#define forex(i,r,l) for(auto i=r; i>=l;i--)
#define ffo(i,n) forex(i,n-1,0)
 
bool cmin(int &a, int b){if(b<a){a=b;return 1;}return 0;}
bool cmax(int &a, int b){if(b>a){a=b;return 1;}return 0;}
void valid(ll in){cout<<((in)?"YES\n":"NO\n");}
ll lcm(ll a, ll b){return (a/gcd(a,b))*b;}
ll gauss(ll n){return (n*(n+1))/2;}
const int N = 1e5 + 7, LOG=20,mod=998244353;
int n,X=0;
ll cnt[11][64][64][64], cnt2[11][64][64];
string s[N];
map<char, int> let;
void test_case(){
    cin>>n;
    set<string> st;
    fo(i,n){
        cin>>s[i];
        int t=sz(s[i]);
        st.insert(s[i]);
        reverse(all(s[i]));
        st.insert(s[i]);
    }
    for(auto e:st)cnt2[sz(e)][let[e[0]]][let[e.back()]]++;
    fore(t, 3, 11){
        fo(d,X){
            fo(a,X){
                if(cnt2[t][d][a]==0)continue;
                fo(b,X){
                    if(cnt2[t][b][d]==0)continue;
                    fo(c,X){
                        if(cnt2[t][d][c]==0)continue;
                        ll aa=cnt2[t][d][a];
                        aa=aa*cnt2[t][b][d];
                        aa=aa*cnt2[t][d][c];
                        cnt[t][a][b][c]=(cnt[t][a][b][c]+aa)%mod;
                    }
                }
            }
        }
    }
    ll ans=0;
    fore(t, 3, 11){
        fo(a,X){
            fo(b,X){
                fo(c,X){
                    fo(d,X){
                        if(min({cnt[t][a][b][c],cnt[t][d][a][b],cnt[t][d][c][b],cnt[t][a][d][c]})==0)continue;
                        ll aa=cnt[t][a][b][c];
                        aa=aa*cnt[t][d][a][b];
                        if(aa>=mod)aa%=mod;
                        ll aa2=cnt[t][d][c][b];
                        aa2=aa2*cnt[t][a][d][c];
                        if(aa2>=mod)aa2%=mod;
                        ans=ans+(aa*aa2)%mod;
                        if(ans>=mod)ans-=mod;
                    }
                }
            }
        }
    }
    ans%=mod;
    cout<<ans<<endl;
}
int main(){cin.tie(0)->sync_with_stdio(0);
    for(char a='a';a<='z';a++)let[a]=X++;
    for(char a='A';a<='Z';a++)let[a]=X++;
    for(char a='0';a<='9';a++)let[a]=X++;
    int t=1;
    // cin >> t;
    while(t--)test_case();
}

Compilation message

cubeword.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    4 | #pragma GCC optimization ("O3")
      | 
cubeword.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("unroll-loops")
      | 
cubeword.cpp: In function 'void test_case()':
cubeword.cpp:50:13: warning: unused variable 't' [-Wunused-variable]
   50 |         int t=sz(s[i]);
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 728 ms 18516 KB Output is correct
2 Correct 796 ms 18532 KB Output is correct
3 Correct 751 ms 18512 KB Output is correct
4 Correct 688 ms 18512 KB Output is correct
5 Correct 718 ms 18512 KB Output is correct
6 Correct 729 ms 18540 KB Output is correct
7 Correct 707 ms 18504 KB Output is correct
8 Correct 703 ms 18352 KB Output is correct
9 Correct 727 ms 18532 KB Output is correct
10 Correct 775 ms 18556 KB Output is correct
11 Correct 773 ms 18540 KB Output is correct
12 Correct 760 ms 18532 KB Output is correct
13 Correct 765 ms 18772 KB Output is correct
14 Correct 768 ms 18512 KB Output is correct
15 Correct 708 ms 18512 KB Output is correct
16 Correct 703 ms 18408 KB Output is correct
17 Correct 731 ms 18512 KB Output is correct
18 Correct 787 ms 18516 KB Output is correct
19 Correct 731 ms 18536 KB Output is correct
20 Correct 748 ms 18552 KB Output is correct
21 Correct 730 ms 18772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 728 ms 18516 KB Output is correct
2 Correct 796 ms 18532 KB Output is correct
3 Correct 751 ms 18512 KB Output is correct
4 Correct 688 ms 18512 KB Output is correct
5 Correct 718 ms 18512 KB Output is correct
6 Correct 729 ms 18540 KB Output is correct
7 Correct 707 ms 18504 KB Output is correct
8 Correct 703 ms 18352 KB Output is correct
9 Correct 727 ms 18532 KB Output is correct
10 Correct 775 ms 18556 KB Output is correct
11 Correct 773 ms 18540 KB Output is correct
12 Correct 760 ms 18532 KB Output is correct
13 Correct 765 ms 18772 KB Output is correct
14 Correct 768 ms 18512 KB Output is correct
15 Correct 708 ms 18512 KB Output is correct
16 Correct 703 ms 18408 KB Output is correct
17 Correct 731 ms 18512 KB Output is correct
18 Correct 787 ms 18516 KB Output is correct
19 Correct 731 ms 18536 KB Output is correct
20 Correct 748 ms 18552 KB Output is correct
21 Correct 730 ms 18772 KB Output is correct
22 Correct 732 ms 20392 KB Output is correct
23 Correct 714 ms 20612 KB Output is correct
24 Correct 680 ms 20308 KB Output is correct
25 Correct 683 ms 20316 KB Output is correct
26 Correct 695 ms 20304 KB Output is correct
27 Correct 708 ms 20380 KB Output is correct
28 Correct 706 ms 20344 KB Output is correct
29 Correct 666 ms 20312 KB Output is correct
30 Correct 678 ms 20208 KB Output is correct
31 Correct 694 ms 20168 KB Output is correct
32 Correct 711 ms 20368 KB Output is correct
33 Correct 709 ms 20424 KB Output is correct
34 Correct 698 ms 20560 KB Output is correct
35 Correct 700 ms 20408 KB Output is correct
36 Correct 664 ms 20392 KB Output is correct
37 Correct 686 ms 20304 KB Output is correct
38 Correct 670 ms 20304 KB Output is correct
39 Correct 685 ms 20304 KB Output is correct
40 Correct 675 ms 20384 KB Output is correct
41 Correct 675 ms 20392 KB Output is correct
42 Correct 684 ms 20300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 728 ms 18516 KB Output is correct
2 Correct 796 ms 18532 KB Output is correct
3 Correct 751 ms 18512 KB Output is correct
4 Correct 688 ms 18512 KB Output is correct
5 Correct 718 ms 18512 KB Output is correct
6 Correct 729 ms 18540 KB Output is correct
7 Correct 707 ms 18504 KB Output is correct
8 Correct 703 ms 18352 KB Output is correct
9 Correct 727 ms 18532 KB Output is correct
10 Correct 775 ms 18556 KB Output is correct
11 Correct 773 ms 18540 KB Output is correct
12 Correct 760 ms 18532 KB Output is correct
13 Correct 765 ms 18772 KB Output is correct
14 Correct 768 ms 18512 KB Output is correct
15 Correct 708 ms 18512 KB Output is correct
16 Correct 703 ms 18408 KB Output is correct
17 Correct 731 ms 18512 KB Output is correct
18 Correct 787 ms 18516 KB Output is correct
19 Correct 731 ms 18536 KB Output is correct
20 Correct 748 ms 18552 KB Output is correct
21 Correct 730 ms 18772 KB Output is correct
22 Correct 732 ms 20392 KB Output is correct
23 Correct 714 ms 20612 KB Output is correct
24 Correct 680 ms 20308 KB Output is correct
25 Correct 683 ms 20316 KB Output is correct
26 Correct 695 ms 20304 KB Output is correct
27 Correct 708 ms 20380 KB Output is correct
28 Correct 706 ms 20344 KB Output is correct
29 Correct 666 ms 20312 KB Output is correct
30 Correct 678 ms 20208 KB Output is correct
31 Correct 694 ms 20168 KB Output is correct
32 Correct 711 ms 20368 KB Output is correct
33 Correct 709 ms 20424 KB Output is correct
34 Correct 698 ms 20560 KB Output is correct
35 Correct 700 ms 20408 KB Output is correct
36 Correct 664 ms 20392 KB Output is correct
37 Correct 686 ms 20304 KB Output is correct
38 Correct 670 ms 20304 KB Output is correct
39 Correct 685 ms 20304 KB Output is correct
40 Correct 675 ms 20384 KB Output is correct
41 Correct 675 ms 20392 KB Output is correct
42 Correct 684 ms 20300 KB Output is correct
43 Correct 696 ms 25172 KB Output is correct
44 Correct 692 ms 25400 KB Output is correct
45 Correct 714 ms 25296 KB Output is correct
46 Correct 688 ms 25104 KB Output is correct
47 Correct 711 ms 25192 KB Output is correct
48 Correct 671 ms 25292 KB Output is correct
49 Correct 687 ms 25168 KB Output is correct
50 Correct 682 ms 25172 KB Output is correct
51 Correct 685 ms 25300 KB Output is correct
52 Correct 683 ms 25296 KB Output is correct
53 Correct 681 ms 25424 KB Output is correct
54 Correct 679 ms 25172 KB Output is correct
55 Correct 676 ms 25168 KB Output is correct
56 Correct 726 ms 25312 KB Output is correct
57 Correct 712 ms 25284 KB Output is correct
58 Correct 714 ms 25172 KB Output is correct
59 Correct 692 ms 25424 KB Output is correct
60 Correct 686 ms 25292 KB Output is correct
61 Correct 708 ms 25172 KB Output is correct
62 Correct 697 ms 25168 KB Output is correct
63 Correct 704 ms 25168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 728 ms 18516 KB Output is correct
2 Correct 796 ms 18532 KB Output is correct
3 Correct 751 ms 18512 KB Output is correct
4 Correct 688 ms 18512 KB Output is correct
5 Correct 718 ms 18512 KB Output is correct
6 Correct 729 ms 18540 KB Output is correct
7 Correct 707 ms 18504 KB Output is correct
8 Correct 703 ms 18352 KB Output is correct
9 Correct 727 ms 18532 KB Output is correct
10 Correct 775 ms 18556 KB Output is correct
11 Correct 773 ms 18540 KB Output is correct
12 Correct 760 ms 18532 KB Output is correct
13 Correct 765 ms 18772 KB Output is correct
14 Correct 768 ms 18512 KB Output is correct
15 Correct 708 ms 18512 KB Output is correct
16 Correct 703 ms 18408 KB Output is correct
17 Correct 731 ms 18512 KB Output is correct
18 Correct 787 ms 18516 KB Output is correct
19 Correct 731 ms 18536 KB Output is correct
20 Correct 748 ms 18552 KB Output is correct
21 Correct 730 ms 18772 KB Output is correct
22 Correct 732 ms 20392 KB Output is correct
23 Correct 714 ms 20612 KB Output is correct
24 Correct 680 ms 20308 KB Output is correct
25 Correct 683 ms 20316 KB Output is correct
26 Correct 695 ms 20304 KB Output is correct
27 Correct 708 ms 20380 KB Output is correct
28 Correct 706 ms 20344 KB Output is correct
29 Correct 666 ms 20312 KB Output is correct
30 Correct 678 ms 20208 KB Output is correct
31 Correct 694 ms 20168 KB Output is correct
32 Correct 711 ms 20368 KB Output is correct
33 Correct 709 ms 20424 KB Output is correct
34 Correct 698 ms 20560 KB Output is correct
35 Correct 700 ms 20408 KB Output is correct
36 Correct 664 ms 20392 KB Output is correct
37 Correct 686 ms 20304 KB Output is correct
38 Correct 670 ms 20304 KB Output is correct
39 Correct 685 ms 20304 KB Output is correct
40 Correct 675 ms 20384 KB Output is correct
41 Correct 675 ms 20392 KB Output is correct
42 Correct 684 ms 20300 KB Output is correct
43 Correct 696 ms 25172 KB Output is correct
44 Correct 692 ms 25400 KB Output is correct
45 Correct 714 ms 25296 KB Output is correct
46 Correct 688 ms 25104 KB Output is correct
47 Correct 711 ms 25192 KB Output is correct
48 Correct 671 ms 25292 KB Output is correct
49 Correct 687 ms 25168 KB Output is correct
50 Correct 682 ms 25172 KB Output is correct
51 Correct 685 ms 25300 KB Output is correct
52 Correct 683 ms 25296 KB Output is correct
53 Correct 681 ms 25424 KB Output is correct
54 Correct 679 ms 25172 KB Output is correct
55 Correct 676 ms 25168 KB Output is correct
56 Correct 726 ms 25312 KB Output is correct
57 Correct 712 ms 25284 KB Output is correct
58 Correct 714 ms 25172 KB Output is correct
59 Correct 692 ms 25424 KB Output is correct
60 Correct 686 ms 25292 KB Output is correct
61 Correct 708 ms 25172 KB Output is correct
62 Correct 697 ms 25168 KB Output is correct
63 Correct 704 ms 25168 KB Output is correct
64 Correct 771 ms 35156 KB Output is correct
65 Correct 747 ms 35920 KB Output is correct
66 Correct 751 ms 36104 KB Output is correct
67 Correct 745 ms 35924 KB Output is correct
68 Correct 735 ms 35964 KB Output is correct
69 Correct 747 ms 35920 KB Output is correct
70 Correct 755 ms 35932 KB Output is correct
71 Correct 797 ms 36092 KB Output is correct
72 Correct 751 ms 36020 KB Output is correct
73 Correct 774 ms 36096 KB Output is correct
74 Correct 774 ms 36096 KB Output is correct
75 Correct 777 ms 35936 KB Output is correct
76 Correct 798 ms 35920 KB Output is correct
77 Correct 811 ms 36312 KB Output is correct
78 Correct 813 ms 36176 KB Output is correct
79 Correct 778 ms 35928 KB Output is correct
80 Correct 741 ms 35920 KB Output is correct
81 Correct 742 ms 35920 KB Output is correct
82 Correct 760 ms 35920 KB Output is correct
83 Correct 798 ms 36100 KB Output is correct
84 Correct 791 ms 35920 KB Output is correct