Submission #1039427

# Submission time Handle Problem Language Result Execution time Memory
1039427 2024-07-30T20:59:03 Z vjudge1 Cubeword (CEOI19_cubeword) C++17
100 / 100
347 ms 36432 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(i,X){
            fore(j,i,X){
                fore(k,j,X){
                    fore(l,k,X){
                        if(min({cnt[t][i][j][k],cnt[t][l][i][j],cnt[t][l][k][j],cnt[t][i][l][k]})==0)continue;
                        int a[4]={1,1,1,1}, p;
                        if(i==j) a[1]+=a[0];
                        if(j==k) a[2]+=a[1];
                        if(k==l) a[3]+=a[2];
                        p=24/(a[0]*a[1]*a[2]*a[3]);
                        ans+=cnt[t][i][j][k]*cnt[t][i][j][l]%mod*cnt[t][i][k][l]%mod*cnt[t][j][k][l]%mod*p%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 110 ms 19568 KB Output is correct
2 Correct 114 ms 19536 KB Output is correct
3 Correct 112 ms 19544 KB Output is correct
4 Correct 110 ms 19540 KB Output is correct
5 Correct 105 ms 19536 KB Output is correct
6 Correct 134 ms 19536 KB Output is correct
7 Correct 118 ms 19580 KB Output is correct
8 Correct 111 ms 19448 KB Output is correct
9 Correct 116 ms 19536 KB Output is correct
10 Correct 112 ms 19540 KB Output is correct
11 Correct 101 ms 19540 KB Output is correct
12 Correct 117 ms 19468 KB Output is correct
13 Correct 121 ms 19536 KB Output is correct
14 Correct 111 ms 19604 KB Output is correct
15 Correct 111 ms 19448 KB Output is correct
16 Correct 117 ms 19540 KB Output is correct
17 Correct 122 ms 19540 KB Output is correct
18 Correct 114 ms 19372 KB Output is correct
19 Correct 127 ms 19480 KB Output is correct
20 Correct 120 ms 19540 KB Output is correct
21 Correct 120 ms 19536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 19568 KB Output is correct
2 Correct 114 ms 19536 KB Output is correct
3 Correct 112 ms 19544 KB Output is correct
4 Correct 110 ms 19540 KB Output is correct
5 Correct 105 ms 19536 KB Output is correct
6 Correct 134 ms 19536 KB Output is correct
7 Correct 118 ms 19580 KB Output is correct
8 Correct 111 ms 19448 KB Output is correct
9 Correct 116 ms 19536 KB Output is correct
10 Correct 112 ms 19540 KB Output is correct
11 Correct 101 ms 19540 KB Output is correct
12 Correct 117 ms 19468 KB Output is correct
13 Correct 121 ms 19536 KB Output is correct
14 Correct 111 ms 19604 KB Output is correct
15 Correct 111 ms 19448 KB Output is correct
16 Correct 117 ms 19540 KB Output is correct
17 Correct 122 ms 19540 KB Output is correct
18 Correct 114 ms 19372 KB Output is correct
19 Correct 127 ms 19480 KB Output is correct
20 Correct 120 ms 19540 KB Output is correct
21 Correct 120 ms 19536 KB Output is correct
22 Correct 128 ms 21332 KB Output is correct
23 Correct 125 ms 21328 KB Output is correct
24 Correct 132 ms 21328 KB Output is correct
25 Correct 125 ms 21332 KB Output is correct
26 Correct 128 ms 21328 KB Output is correct
27 Correct 124 ms 21216 KB Output is correct
28 Correct 125 ms 21332 KB Output is correct
29 Correct 125 ms 21216 KB Output is correct
30 Correct 122 ms 21328 KB Output is correct
31 Correct 151 ms 21328 KB Output is correct
32 Correct 117 ms 21328 KB Output is correct
33 Correct 123 ms 21304 KB Output is correct
34 Correct 120 ms 21332 KB Output is correct
35 Correct 133 ms 21328 KB Output is correct
36 Correct 124 ms 21188 KB Output is correct
37 Correct 122 ms 21332 KB Output is correct
38 Correct 127 ms 21328 KB Output is correct
39 Correct 129 ms 21336 KB Output is correct
40 Correct 126 ms 21236 KB Output is correct
41 Correct 141 ms 21332 KB Output is correct
42 Correct 125 ms 21328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 19568 KB Output is correct
2 Correct 114 ms 19536 KB Output is correct
3 Correct 112 ms 19544 KB Output is correct
4 Correct 110 ms 19540 KB Output is correct
5 Correct 105 ms 19536 KB Output is correct
6 Correct 134 ms 19536 KB Output is correct
7 Correct 118 ms 19580 KB Output is correct
8 Correct 111 ms 19448 KB Output is correct
9 Correct 116 ms 19536 KB Output is correct
10 Correct 112 ms 19540 KB Output is correct
11 Correct 101 ms 19540 KB Output is correct
12 Correct 117 ms 19468 KB Output is correct
13 Correct 121 ms 19536 KB Output is correct
14 Correct 111 ms 19604 KB Output is correct
15 Correct 111 ms 19448 KB Output is correct
16 Correct 117 ms 19540 KB Output is correct
17 Correct 122 ms 19540 KB Output is correct
18 Correct 114 ms 19372 KB Output is correct
19 Correct 127 ms 19480 KB Output is correct
20 Correct 120 ms 19540 KB Output is correct
21 Correct 120 ms 19536 KB Output is correct
22 Correct 128 ms 21332 KB Output is correct
23 Correct 125 ms 21328 KB Output is correct
24 Correct 132 ms 21328 KB Output is correct
25 Correct 125 ms 21332 KB Output is correct
26 Correct 128 ms 21328 KB Output is correct
27 Correct 124 ms 21216 KB Output is correct
28 Correct 125 ms 21332 KB Output is correct
29 Correct 125 ms 21216 KB Output is correct
30 Correct 122 ms 21328 KB Output is correct
31 Correct 151 ms 21328 KB Output is correct
32 Correct 117 ms 21328 KB Output is correct
33 Correct 123 ms 21304 KB Output is correct
34 Correct 120 ms 21332 KB Output is correct
35 Correct 133 ms 21328 KB Output is correct
36 Correct 124 ms 21188 KB Output is correct
37 Correct 122 ms 21332 KB Output is correct
38 Correct 127 ms 21328 KB Output is correct
39 Correct 129 ms 21336 KB Output is correct
40 Correct 126 ms 21236 KB Output is correct
41 Correct 141 ms 21332 KB Output is correct
42 Correct 125 ms 21328 KB Output is correct
43 Correct 153 ms 26164 KB Output is correct
44 Correct 142 ms 26196 KB Output is correct
45 Correct 142 ms 26192 KB Output is correct
46 Correct 144 ms 26040 KB Output is correct
47 Correct 138 ms 26192 KB Output is correct
48 Correct 138 ms 26024 KB Output is correct
49 Correct 161 ms 26192 KB Output is correct
50 Correct 146 ms 26192 KB Output is correct
51 Correct 172 ms 26192 KB Output is correct
52 Correct 141 ms 26196 KB Output is correct
53 Correct 158 ms 26044 KB Output is correct
54 Correct 149 ms 26232 KB Output is correct
55 Correct 144 ms 26196 KB Output is correct
56 Correct 142 ms 26192 KB Output is correct
57 Correct 149 ms 26192 KB Output is correct
58 Correct 137 ms 26196 KB Output is correct
59 Correct 152 ms 26096 KB Output is correct
60 Correct 184 ms 26092 KB Output is correct
61 Correct 139 ms 26192 KB Output is correct
62 Correct 147 ms 26196 KB Output is correct
63 Correct 134 ms 26192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 19568 KB Output is correct
2 Correct 114 ms 19536 KB Output is correct
3 Correct 112 ms 19544 KB Output is correct
4 Correct 110 ms 19540 KB Output is correct
5 Correct 105 ms 19536 KB Output is correct
6 Correct 134 ms 19536 KB Output is correct
7 Correct 118 ms 19580 KB Output is correct
8 Correct 111 ms 19448 KB Output is correct
9 Correct 116 ms 19536 KB Output is correct
10 Correct 112 ms 19540 KB Output is correct
11 Correct 101 ms 19540 KB Output is correct
12 Correct 117 ms 19468 KB Output is correct
13 Correct 121 ms 19536 KB Output is correct
14 Correct 111 ms 19604 KB Output is correct
15 Correct 111 ms 19448 KB Output is correct
16 Correct 117 ms 19540 KB Output is correct
17 Correct 122 ms 19540 KB Output is correct
18 Correct 114 ms 19372 KB Output is correct
19 Correct 127 ms 19480 KB Output is correct
20 Correct 120 ms 19540 KB Output is correct
21 Correct 120 ms 19536 KB Output is correct
22 Correct 128 ms 21332 KB Output is correct
23 Correct 125 ms 21328 KB Output is correct
24 Correct 132 ms 21328 KB Output is correct
25 Correct 125 ms 21332 KB Output is correct
26 Correct 128 ms 21328 KB Output is correct
27 Correct 124 ms 21216 KB Output is correct
28 Correct 125 ms 21332 KB Output is correct
29 Correct 125 ms 21216 KB Output is correct
30 Correct 122 ms 21328 KB Output is correct
31 Correct 151 ms 21328 KB Output is correct
32 Correct 117 ms 21328 KB Output is correct
33 Correct 123 ms 21304 KB Output is correct
34 Correct 120 ms 21332 KB Output is correct
35 Correct 133 ms 21328 KB Output is correct
36 Correct 124 ms 21188 KB Output is correct
37 Correct 122 ms 21332 KB Output is correct
38 Correct 127 ms 21328 KB Output is correct
39 Correct 129 ms 21336 KB Output is correct
40 Correct 126 ms 21236 KB Output is correct
41 Correct 141 ms 21332 KB Output is correct
42 Correct 125 ms 21328 KB Output is correct
43 Correct 153 ms 26164 KB Output is correct
44 Correct 142 ms 26196 KB Output is correct
45 Correct 142 ms 26192 KB Output is correct
46 Correct 144 ms 26040 KB Output is correct
47 Correct 138 ms 26192 KB Output is correct
48 Correct 138 ms 26024 KB Output is correct
49 Correct 161 ms 26192 KB Output is correct
50 Correct 146 ms 26192 KB Output is correct
51 Correct 172 ms 26192 KB Output is correct
52 Correct 141 ms 26196 KB Output is correct
53 Correct 158 ms 26044 KB Output is correct
54 Correct 149 ms 26232 KB Output is correct
55 Correct 144 ms 26196 KB Output is correct
56 Correct 142 ms 26192 KB Output is correct
57 Correct 149 ms 26192 KB Output is correct
58 Correct 137 ms 26196 KB Output is correct
59 Correct 152 ms 26096 KB Output is correct
60 Correct 184 ms 26092 KB Output is correct
61 Correct 139 ms 26192 KB Output is correct
62 Correct 147 ms 26196 KB Output is correct
63 Correct 134 ms 26192 KB Output is correct
64 Correct 310 ms 36136 KB Output is correct
65 Correct 312 ms 36244 KB Output is correct
66 Correct 333 ms 36176 KB Output is correct
67 Correct 316 ms 36180 KB Output is correct
68 Correct 306 ms 36180 KB Output is correct
69 Correct 275 ms 36176 KB Output is correct
70 Correct 347 ms 36392 KB Output is correct
71 Correct 312 ms 36000 KB Output is correct
72 Correct 288 ms 36176 KB Output is correct
73 Correct 307 ms 36176 KB Output is correct
74 Correct 293 ms 36088 KB Output is correct
75 Correct 308 ms 36016 KB Output is correct
76 Correct 291 ms 36180 KB Output is correct
77 Correct 275 ms 36172 KB Output is correct
78 Correct 297 ms 36124 KB Output is correct
79 Correct 283 ms 36152 KB Output is correct
80 Correct 308 ms 36432 KB Output is correct
81 Correct 268 ms 36176 KB Output is correct
82 Correct 289 ms 36180 KB Output is correct
83 Correct 279 ms 36176 KB Output is correct
84 Correct 307 ms 36000 KB Output is correct