Submission #275989

# Submission time Handle Problem Language Result Execution time Memory
275989 2020-08-20T08:54:59 Z egekabas Cubeword (CEOI19_cubeword) C++14
84 / 100
495 ms 31580 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
ll mod = 998244353;
ll ans = 0;
vector<string> a[11];
ll n = 62;
ll cnt[70][70];
map<char, ll> mpp;
ll dp1[70][70][70];
ll dp2[70][70][70][70];
ll dp3[70][70][70];

void solve(int cur){
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            cnt[i][j] = 0;
    int sz = a[cur].size();
    for(int i = 0;  i < sz; ++i){
        string u = a[cur][i];
        reverse(all(u));
        a[cur].pb(u);
    }
    sort(all(a[cur]));
    a[cur].resize(unique(all(a[cur]))-a[cur].begin());
    for(auto u : a[cur]){
        cnt[mpp[u[0]]][mpp[u.back()]]++;
    }
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            for(int k = 0; k < n; ++k){
                dp1[i][j][k] = 0;
                for(int mid = 0; mid < n; ++mid){
                    dp1[i][j][k] += cnt[mid][i]*cnt[mid][j]%mod*cnt[mid][k]%mod;
                    if(dp1[i][j][k] >= mod)
                        dp1[i][j][k] -= mod;
                }
            }
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            for(int k = 0; k < n; ++k)
                for(int y = 0; y < n; ++y)
                    dp2[i][j][k][y] = dp1[i][j][k]*dp1[j][k][y]%mod;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            for(int y = 0; y < n; ++y){
                dp3[i][j][y] = 0;
                for(int k = 0; k < n; ++k){
                    dp3[i][j][y] += dp2[i][j][k][y]*dp1[i][k][y]%mod;
                    if(dp3[i][j][y] >= mod)
                        dp3[i][j][y] -= mod;
                }
            }
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            for(int y = 0; y < n; ++y)
                for(int fin = 0; fin < n; ++fin){
                    ans += dp3[i][j][y]*cnt[fin][i]%mod*cnt[fin][j]%mod*cnt[fin][y]%mod;
                    if(ans >= mod)
                        ans -= mod;
                }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    ll t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        a[s.size()].pb(s);
    }
    ll cnt = 0;
    for(char i = 'a'; i <= 'p'; ++i)
        mpp[i] = cnt++;
    for(char i = 'A'; i <= 'P'; ++i)
        mpp[i] = cnt++;
    n = cnt;
    for(char i = '0'; i <= '9'; ++i)
        mpp[i] = cnt++;
    for(ll i = 3; i <= 10; ++i)
        solve(i);
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 426 ms 31268 KB Output is correct
2 Correct 427 ms 31384 KB Output is correct
3 Correct 435 ms 31260 KB Output is correct
4 Correct 425 ms 31228 KB Output is correct
5 Correct 435 ms 31240 KB Output is correct
6 Correct 426 ms 31320 KB Output is correct
7 Correct 426 ms 31280 KB Output is correct
8 Correct 431 ms 31128 KB Output is correct
9 Correct 428 ms 31132 KB Output is correct
10 Correct 450 ms 31256 KB Output is correct
11 Correct 429 ms 31172 KB Output is correct
12 Correct 430 ms 31216 KB Output is correct
13 Correct 428 ms 31180 KB Output is correct
14 Correct 434 ms 31208 KB Output is correct
15 Correct 430 ms 31328 KB Output is correct
16 Correct 423 ms 31220 KB Output is correct
17 Correct 424 ms 31184 KB Output is correct
18 Correct 423 ms 31272 KB Output is correct
19 Correct 440 ms 31204 KB Output is correct
20 Correct 424 ms 31216 KB Output is correct
21 Correct 426 ms 31216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 426 ms 31268 KB Output is correct
2 Correct 427 ms 31384 KB Output is correct
3 Correct 435 ms 31260 KB Output is correct
4 Correct 425 ms 31228 KB Output is correct
5 Correct 435 ms 31240 KB Output is correct
6 Correct 426 ms 31320 KB Output is correct
7 Correct 426 ms 31280 KB Output is correct
8 Correct 431 ms 31128 KB Output is correct
9 Correct 428 ms 31132 KB Output is correct
10 Correct 450 ms 31256 KB Output is correct
11 Correct 429 ms 31172 KB Output is correct
12 Correct 430 ms 31216 KB Output is correct
13 Correct 428 ms 31180 KB Output is correct
14 Correct 434 ms 31208 KB Output is correct
15 Correct 430 ms 31328 KB Output is correct
16 Correct 423 ms 31220 KB Output is correct
17 Correct 424 ms 31184 KB Output is correct
18 Correct 423 ms 31272 KB Output is correct
19 Correct 440 ms 31204 KB Output is correct
20 Correct 424 ms 31216 KB Output is correct
21 Correct 426 ms 31216 KB Output is correct
22 Correct 427 ms 30416 KB Output is correct
23 Correct 426 ms 30252 KB Output is correct
24 Correct 429 ms 30528 KB Output is correct
25 Correct 437 ms 30172 KB Output is correct
26 Correct 434 ms 30324 KB Output is correct
27 Correct 429 ms 30520 KB Output is correct
28 Correct 431 ms 30324 KB Output is correct
29 Correct 434 ms 30248 KB Output is correct
30 Correct 432 ms 30484 KB Output is correct
31 Correct 421 ms 30136 KB Output is correct
32 Correct 423 ms 30260 KB Output is correct
33 Correct 444 ms 30432 KB Output is correct
34 Correct 429 ms 30188 KB Output is correct
35 Correct 462 ms 30336 KB Output is correct
36 Correct 431 ms 30200 KB Output is correct
37 Correct 426 ms 30228 KB Output is correct
38 Correct 444 ms 30408 KB Output is correct
39 Correct 425 ms 30264 KB Output is correct
40 Correct 427 ms 30512 KB Output is correct
41 Correct 434 ms 30268 KB Output is correct
42 Correct 430 ms 30172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 426 ms 31268 KB Output is correct
2 Correct 427 ms 31384 KB Output is correct
3 Correct 435 ms 31260 KB Output is correct
4 Correct 425 ms 31228 KB Output is correct
5 Correct 435 ms 31240 KB Output is correct
6 Correct 426 ms 31320 KB Output is correct
7 Correct 426 ms 31280 KB Output is correct
8 Correct 431 ms 31128 KB Output is correct
9 Correct 428 ms 31132 KB Output is correct
10 Correct 450 ms 31256 KB Output is correct
11 Correct 429 ms 31172 KB Output is correct
12 Correct 430 ms 31216 KB Output is correct
13 Correct 428 ms 31180 KB Output is correct
14 Correct 434 ms 31208 KB Output is correct
15 Correct 430 ms 31328 KB Output is correct
16 Correct 423 ms 31220 KB Output is correct
17 Correct 424 ms 31184 KB Output is correct
18 Correct 423 ms 31272 KB Output is correct
19 Correct 440 ms 31204 KB Output is correct
20 Correct 424 ms 31216 KB Output is correct
21 Correct 426 ms 31216 KB Output is correct
22 Correct 427 ms 30416 KB Output is correct
23 Correct 426 ms 30252 KB Output is correct
24 Correct 429 ms 30528 KB Output is correct
25 Correct 437 ms 30172 KB Output is correct
26 Correct 434 ms 30324 KB Output is correct
27 Correct 429 ms 30520 KB Output is correct
28 Correct 431 ms 30324 KB Output is correct
29 Correct 434 ms 30248 KB Output is correct
30 Correct 432 ms 30484 KB Output is correct
31 Correct 421 ms 30136 KB Output is correct
32 Correct 423 ms 30260 KB Output is correct
33 Correct 444 ms 30432 KB Output is correct
34 Correct 429 ms 30188 KB Output is correct
35 Correct 462 ms 30336 KB Output is correct
36 Correct 431 ms 30200 KB Output is correct
37 Correct 426 ms 30228 KB Output is correct
38 Correct 444 ms 30408 KB Output is correct
39 Correct 425 ms 30264 KB Output is correct
40 Correct 427 ms 30512 KB Output is correct
41 Correct 434 ms 30268 KB Output is correct
42 Correct 430 ms 30172 KB Output is correct
43 Correct 478 ms 30604 KB Output is correct
44 Correct 467 ms 31540 KB Output is correct
45 Correct 495 ms 30948 KB Output is correct
46 Correct 481 ms 30924 KB Output is correct
47 Correct 469 ms 30936 KB Output is correct
48 Correct 475 ms 31024 KB Output is correct
49 Correct 470 ms 31316 KB Output is correct
50 Correct 471 ms 30948 KB Output is correct
51 Correct 466 ms 31580 KB Output is correct
52 Correct 464 ms 31348 KB Output is correct
53 Correct 466 ms 31444 KB Output is correct
54 Correct 463 ms 31424 KB Output is correct
55 Correct 473 ms 31416 KB Output is correct
56 Correct 470 ms 31440 KB Output is correct
57 Correct 467 ms 31284 KB Output is correct
58 Correct 478 ms 31240 KB Output is correct
59 Correct 473 ms 31024 KB Output is correct
60 Correct 475 ms 31348 KB Output is correct
61 Correct 475 ms 31076 KB Output is correct
62 Correct 460 ms 31212 KB Output is correct
63 Correct 464 ms 31084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 426 ms 31268 KB Output is correct
2 Correct 427 ms 31384 KB Output is correct
3 Correct 435 ms 31260 KB Output is correct
4 Correct 425 ms 31228 KB Output is correct
5 Correct 435 ms 31240 KB Output is correct
6 Correct 426 ms 31320 KB Output is correct
7 Correct 426 ms 31280 KB Output is correct
8 Correct 431 ms 31128 KB Output is correct
9 Correct 428 ms 31132 KB Output is correct
10 Correct 450 ms 31256 KB Output is correct
11 Correct 429 ms 31172 KB Output is correct
12 Correct 430 ms 31216 KB Output is correct
13 Correct 428 ms 31180 KB Output is correct
14 Correct 434 ms 31208 KB Output is correct
15 Correct 430 ms 31328 KB Output is correct
16 Correct 423 ms 31220 KB Output is correct
17 Correct 424 ms 31184 KB Output is correct
18 Correct 423 ms 31272 KB Output is correct
19 Correct 440 ms 31204 KB Output is correct
20 Correct 424 ms 31216 KB Output is correct
21 Correct 426 ms 31216 KB Output is correct
22 Correct 427 ms 30416 KB Output is correct
23 Correct 426 ms 30252 KB Output is correct
24 Correct 429 ms 30528 KB Output is correct
25 Correct 437 ms 30172 KB Output is correct
26 Correct 434 ms 30324 KB Output is correct
27 Correct 429 ms 30520 KB Output is correct
28 Correct 431 ms 30324 KB Output is correct
29 Correct 434 ms 30248 KB Output is correct
30 Correct 432 ms 30484 KB Output is correct
31 Correct 421 ms 30136 KB Output is correct
32 Correct 423 ms 30260 KB Output is correct
33 Correct 444 ms 30432 KB Output is correct
34 Correct 429 ms 30188 KB Output is correct
35 Correct 462 ms 30336 KB Output is correct
36 Correct 431 ms 30200 KB Output is correct
37 Correct 426 ms 30228 KB Output is correct
38 Correct 444 ms 30408 KB Output is correct
39 Correct 425 ms 30264 KB Output is correct
40 Correct 427 ms 30512 KB Output is correct
41 Correct 434 ms 30268 KB Output is correct
42 Correct 430 ms 30172 KB Output is correct
43 Correct 478 ms 30604 KB Output is correct
44 Correct 467 ms 31540 KB Output is correct
45 Correct 495 ms 30948 KB Output is correct
46 Correct 481 ms 30924 KB Output is correct
47 Correct 469 ms 30936 KB Output is correct
48 Correct 475 ms 31024 KB Output is correct
49 Correct 470 ms 31316 KB Output is correct
50 Correct 471 ms 30948 KB Output is correct
51 Correct 466 ms 31580 KB Output is correct
52 Correct 464 ms 31348 KB Output is correct
53 Correct 466 ms 31444 KB Output is correct
54 Correct 463 ms 31424 KB Output is correct
55 Correct 473 ms 31416 KB Output is correct
56 Correct 470 ms 31440 KB Output is correct
57 Correct 467 ms 31284 KB Output is correct
58 Correct 478 ms 31240 KB Output is correct
59 Correct 473 ms 31024 KB Output is correct
60 Correct 475 ms 31348 KB Output is correct
61 Correct 475 ms 31076 KB Output is correct
62 Correct 460 ms 31212 KB Output is correct
63 Correct 464 ms 31084 KB Output is correct
64 Incorrect 471 ms 31432 KB Output isn't correct
65 Halted 0 ms 0 KB -