Submission #275998

# Submission time Handle Problem Language Result Execution time Memory
275998 2020-08-20T09:09:19 Z egekabas Cubeword (CEOI19_cubeword) C++14
84 / 100
342 ms 8792 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 dp[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){
                dp[i][j][k] = 0;
                for(int mid = 0; mid < n; ++mid){
                    dp[i][j][k] += cnt[mid][i]*cnt[mid][j]*cnt[mid][k]%mod;
                    if(dp[i][j][k] >= mod)
                        dp[i][j][k] -= mod;
                }
            }
    for(int i = 0; i < n; ++i)
        for(int k = 0; k < n; ++k)
            for(int y = 0; y < n; ++y)
                for(int j = 0; j < n; ++j){
                    ans += dp[i][k][j]*dp[i][j][y]%mod*dp[y][j][k]%mod*dp[i][k][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)
        if(a[i].size())
            solve(i);
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 270 ms 8688 KB Output is correct
2 Correct 258 ms 8660 KB Output is correct
3 Correct 261 ms 8628 KB Output is correct
4 Correct 266 ms 8712 KB Output is correct
5 Correct 261 ms 8700 KB Output is correct
6 Correct 260 ms 8792 KB Output is correct
7 Correct 263 ms 8656 KB Output is correct
8 Correct 265 ms 8584 KB Output is correct
9 Correct 261 ms 8724 KB Output is correct
10 Correct 260 ms 8688 KB Output is correct
11 Correct 264 ms 8648 KB Output is correct
12 Correct 264 ms 8772 KB Output is correct
13 Correct 264 ms 8652 KB Output is correct
14 Correct 261 ms 8680 KB Output is correct
15 Correct 261 ms 8748 KB Output is correct
16 Correct 267 ms 8676 KB Output is correct
17 Correct 275 ms 8628 KB Output is correct
18 Correct 260 ms 8620 KB Output is correct
19 Correct 265 ms 8688 KB Output is correct
20 Correct 262 ms 8692 KB Output is correct
21 Correct 265 ms 8692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 270 ms 8688 KB Output is correct
2 Correct 258 ms 8660 KB Output is correct
3 Correct 261 ms 8628 KB Output is correct
4 Correct 266 ms 8712 KB Output is correct
5 Correct 261 ms 8700 KB Output is correct
6 Correct 260 ms 8792 KB Output is correct
7 Correct 263 ms 8656 KB Output is correct
8 Correct 265 ms 8584 KB Output is correct
9 Correct 261 ms 8724 KB Output is correct
10 Correct 260 ms 8688 KB Output is correct
11 Correct 264 ms 8648 KB Output is correct
12 Correct 264 ms 8772 KB Output is correct
13 Correct 264 ms 8652 KB Output is correct
14 Correct 261 ms 8680 KB Output is correct
15 Correct 261 ms 8748 KB Output is correct
16 Correct 267 ms 8676 KB Output is correct
17 Correct 275 ms 8628 KB Output is correct
18 Correct 260 ms 8620 KB Output is correct
19 Correct 265 ms 8688 KB Output is correct
20 Correct 262 ms 8692 KB Output is correct
21 Correct 265 ms 8692 KB Output is correct
22 Correct 270 ms 7940 KB Output is correct
23 Correct 268 ms 7740 KB Output is correct
24 Correct 264 ms 8000 KB Output is correct
25 Correct 262 ms 7756 KB Output is correct
26 Correct 267 ms 7644 KB Output is correct
27 Correct 263 ms 7864 KB Output is correct
28 Correct 262 ms 7652 KB Output is correct
29 Correct 266 ms 7720 KB Output is correct
30 Correct 272 ms 7808 KB Output is correct
31 Correct 263 ms 7604 KB Output is correct
32 Correct 262 ms 7756 KB Output is correct
33 Correct 262 ms 7888 KB Output is correct
34 Correct 274 ms 7740 KB Output is correct
35 Correct 272 ms 7704 KB Output is correct
36 Correct 266 ms 7672 KB Output is correct
37 Correct 263 ms 7644 KB Output is correct
38 Correct 261 ms 7624 KB Output is correct
39 Correct 267 ms 7732 KB Output is correct
40 Correct 261 ms 7852 KB Output is correct
41 Correct 263 ms 7736 KB Output is correct
42 Correct 260 ms 7656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 270 ms 8688 KB Output is correct
2 Correct 258 ms 8660 KB Output is correct
3 Correct 261 ms 8628 KB Output is correct
4 Correct 266 ms 8712 KB Output is correct
5 Correct 261 ms 8700 KB Output is correct
6 Correct 260 ms 8792 KB Output is correct
7 Correct 263 ms 8656 KB Output is correct
8 Correct 265 ms 8584 KB Output is correct
9 Correct 261 ms 8724 KB Output is correct
10 Correct 260 ms 8688 KB Output is correct
11 Correct 264 ms 8648 KB Output is correct
12 Correct 264 ms 8772 KB Output is correct
13 Correct 264 ms 8652 KB Output is correct
14 Correct 261 ms 8680 KB Output is correct
15 Correct 261 ms 8748 KB Output is correct
16 Correct 267 ms 8676 KB Output is correct
17 Correct 275 ms 8628 KB Output is correct
18 Correct 260 ms 8620 KB Output is correct
19 Correct 265 ms 8688 KB Output is correct
20 Correct 262 ms 8692 KB Output is correct
21 Correct 265 ms 8692 KB Output is correct
22 Correct 270 ms 7940 KB Output is correct
23 Correct 268 ms 7740 KB Output is correct
24 Correct 264 ms 8000 KB Output is correct
25 Correct 262 ms 7756 KB Output is correct
26 Correct 267 ms 7644 KB Output is correct
27 Correct 263 ms 7864 KB Output is correct
28 Correct 262 ms 7652 KB Output is correct
29 Correct 266 ms 7720 KB Output is correct
30 Correct 272 ms 7808 KB Output is correct
31 Correct 263 ms 7604 KB Output is correct
32 Correct 262 ms 7756 KB Output is correct
33 Correct 262 ms 7888 KB Output is correct
34 Correct 274 ms 7740 KB Output is correct
35 Correct 272 ms 7704 KB Output is correct
36 Correct 266 ms 7672 KB Output is correct
37 Correct 263 ms 7644 KB Output is correct
38 Correct 261 ms 7624 KB Output is correct
39 Correct 267 ms 7732 KB Output is correct
40 Correct 261 ms 7852 KB Output is correct
41 Correct 263 ms 7736 KB Output is correct
42 Correct 260 ms 7656 KB Output is correct
43 Correct 320 ms 7888 KB Output is correct
44 Correct 328 ms 8124 KB Output is correct
45 Correct 324 ms 7652 KB Output is correct
46 Correct 320 ms 7632 KB Output is correct
47 Correct 323 ms 7784 KB Output is correct
48 Correct 325 ms 7664 KB Output is correct
49 Correct 327 ms 7976 KB Output is correct
50 Correct 324 ms 7656 KB Output is correct
51 Correct 323 ms 7988 KB Output is correct
52 Correct 322 ms 8052 KB Output is correct
53 Correct 331 ms 8076 KB Output is correct
54 Correct 328 ms 7872 KB Output is correct
55 Correct 321 ms 8124 KB Output is correct
56 Correct 333 ms 8132 KB Output is correct
57 Correct 322 ms 7988 KB Output is correct
58 Correct 336 ms 7904 KB Output is correct
59 Correct 325 ms 7892 KB Output is correct
60 Correct 334 ms 8120 KB Output is correct
61 Correct 323 ms 7644 KB Output is correct
62 Correct 322 ms 7912 KB Output is correct
63 Correct 326 ms 7652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 270 ms 8688 KB Output is correct
2 Correct 258 ms 8660 KB Output is correct
3 Correct 261 ms 8628 KB Output is correct
4 Correct 266 ms 8712 KB Output is correct
5 Correct 261 ms 8700 KB Output is correct
6 Correct 260 ms 8792 KB Output is correct
7 Correct 263 ms 8656 KB Output is correct
8 Correct 265 ms 8584 KB Output is correct
9 Correct 261 ms 8724 KB Output is correct
10 Correct 260 ms 8688 KB Output is correct
11 Correct 264 ms 8648 KB Output is correct
12 Correct 264 ms 8772 KB Output is correct
13 Correct 264 ms 8652 KB Output is correct
14 Correct 261 ms 8680 KB Output is correct
15 Correct 261 ms 8748 KB Output is correct
16 Correct 267 ms 8676 KB Output is correct
17 Correct 275 ms 8628 KB Output is correct
18 Correct 260 ms 8620 KB Output is correct
19 Correct 265 ms 8688 KB Output is correct
20 Correct 262 ms 8692 KB Output is correct
21 Correct 265 ms 8692 KB Output is correct
22 Correct 270 ms 7940 KB Output is correct
23 Correct 268 ms 7740 KB Output is correct
24 Correct 264 ms 8000 KB Output is correct
25 Correct 262 ms 7756 KB Output is correct
26 Correct 267 ms 7644 KB Output is correct
27 Correct 263 ms 7864 KB Output is correct
28 Correct 262 ms 7652 KB Output is correct
29 Correct 266 ms 7720 KB Output is correct
30 Correct 272 ms 7808 KB Output is correct
31 Correct 263 ms 7604 KB Output is correct
32 Correct 262 ms 7756 KB Output is correct
33 Correct 262 ms 7888 KB Output is correct
34 Correct 274 ms 7740 KB Output is correct
35 Correct 272 ms 7704 KB Output is correct
36 Correct 266 ms 7672 KB Output is correct
37 Correct 263 ms 7644 KB Output is correct
38 Correct 261 ms 7624 KB Output is correct
39 Correct 267 ms 7732 KB Output is correct
40 Correct 261 ms 7852 KB Output is correct
41 Correct 263 ms 7736 KB Output is correct
42 Correct 260 ms 7656 KB Output is correct
43 Correct 320 ms 7888 KB Output is correct
44 Correct 328 ms 8124 KB Output is correct
45 Correct 324 ms 7652 KB Output is correct
46 Correct 320 ms 7632 KB Output is correct
47 Correct 323 ms 7784 KB Output is correct
48 Correct 325 ms 7664 KB Output is correct
49 Correct 327 ms 7976 KB Output is correct
50 Correct 324 ms 7656 KB Output is correct
51 Correct 323 ms 7988 KB Output is correct
52 Correct 322 ms 8052 KB Output is correct
53 Correct 331 ms 8076 KB Output is correct
54 Correct 328 ms 7872 KB Output is correct
55 Correct 321 ms 8124 KB Output is correct
56 Correct 333 ms 8132 KB Output is correct
57 Correct 322 ms 7988 KB Output is correct
58 Correct 336 ms 7904 KB Output is correct
59 Correct 325 ms 7892 KB Output is correct
60 Correct 334 ms 8120 KB Output is correct
61 Correct 323 ms 7644 KB Output is correct
62 Correct 322 ms 7912 KB Output is correct
63 Correct 326 ms 7652 KB Output is correct
64 Incorrect 342 ms 8004 KB Output isn't correct
65 Halted 0 ms 0 KB -