Submission #471810

# Submission time Handle Problem Language Result Execution time Memory
471810 2021-09-10T23:29:33 Z Ozy Cubeword (CEOI19_cubeword) C++17
84 / 100
397 ms 17020 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "

#define abc 35
#define mod 998244353

lli n,a,b,res,MAX;
lli dp[abc+2][abc+2][abc+2], palabras[12][abc+2][abc+2];
string st,rev;
map<string, lli> mapa;

lli convierte(char car) {
    lli x;

    x = car;
    if (x > 96) x -= 96;
    else {
        x -= 65;
        x += 17;
    }
    return x;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    rep (i,1,n) {
        cin >> st;
        rev = st;
        reverse(st.begin(),st.end());
        if (st.size() > MAX) MAX = st.size();

        if (mapa.find(st) != mapa.end() || mapa.find(rev) != mapa.end()) continue;
        mapa[st] = 1;
        mapa[rev] = 1;

        a = convierte(st[0]);
        b = convierte(st[st.size()-1]);

        if (a == b) {
            palabras[st.size()][a][a]++;
            if (st != rev) palabras[st.size()][a][a]++;
        }
        else {
            palabras[st.size()][a][b]++;
            palabras[st.size()][b][a]++;
        }
    }

    rep (tam,3,MAX) {

        rep(i,1,abc) {
            rep(j,1,abc) {
                rep(k,1,abc) {
                    dp[i][j][k] = 0;

                    rep (num,1,abc) {
                        a = palabras[tam][i][num] * palabras[tam][j][num] * palabras[tam][k][num];
                        a %= mod;

                        dp[i][j][k] += a;
                        dp[i][j][k] %= mod;
                    }

                }
            }
        }

        rep(i,1,abc) {
            rep(j,1,abc) {
                rep(k,1,abc) {
                    rep(l,1,abc) {
                        a = dp[i][j][k] * dp[i][j][l];
                        a %= mod;
                        a *= dp[i][k][l];
                        a %= mod;
                        a *= dp[j][k][l];
                        a %= mod;

                        if (a) {
                            res += a;
                            res %= mod;
                        }
                    }
                }
            }
        }

    }

    cout << res;
}

Compilation message

cubeword.cpp: In function 'int main()':
cubeword.cpp:40:23: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   40 |         if (st.size() > MAX) MAX = st.size();
      |             ~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 358 ms 15188 KB Output is correct
2 Correct 321 ms 16040 KB Output is correct
3 Correct 323 ms 15940 KB Output is correct
4 Correct 328 ms 16044 KB Output is correct
5 Correct 373 ms 16084 KB Output is correct
6 Correct 330 ms 16076 KB Output is correct
7 Correct 322 ms 16068 KB Output is correct
8 Correct 326 ms 16204 KB Output is correct
9 Correct 342 ms 15944 KB Output is correct
10 Correct 332 ms 16076 KB Output is correct
11 Correct 343 ms 16060 KB Output is correct
12 Correct 341 ms 16052 KB Output is correct
13 Correct 337 ms 16072 KB Output is correct
14 Correct 397 ms 16008 KB Output is correct
15 Correct 323 ms 16068 KB Output is correct
16 Correct 323 ms 15960 KB Output is correct
17 Correct 327 ms 16068 KB Output is correct
18 Correct 352 ms 16008 KB Output is correct
19 Correct 326 ms 15940 KB Output is correct
20 Correct 332 ms 15940 KB Output is correct
21 Correct 363 ms 16104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 358 ms 15188 KB Output is correct
2 Correct 321 ms 16040 KB Output is correct
3 Correct 323 ms 15940 KB Output is correct
4 Correct 328 ms 16044 KB Output is correct
5 Correct 373 ms 16084 KB Output is correct
6 Correct 330 ms 16076 KB Output is correct
7 Correct 322 ms 16068 KB Output is correct
8 Correct 326 ms 16204 KB Output is correct
9 Correct 342 ms 15944 KB Output is correct
10 Correct 332 ms 16076 KB Output is correct
11 Correct 343 ms 16060 KB Output is correct
12 Correct 341 ms 16052 KB Output is correct
13 Correct 337 ms 16072 KB Output is correct
14 Correct 397 ms 16008 KB Output is correct
15 Correct 323 ms 16068 KB Output is correct
16 Correct 323 ms 15960 KB Output is correct
17 Correct 327 ms 16068 KB Output is correct
18 Correct 352 ms 16008 KB Output is correct
19 Correct 326 ms 15940 KB Output is correct
20 Correct 332 ms 15940 KB Output is correct
21 Correct 363 ms 16104 KB Output is correct
22 Correct 328 ms 16600 KB Output is correct
23 Correct 342 ms 16616 KB Output is correct
24 Correct 331 ms 16668 KB Output is correct
25 Correct 334 ms 16548 KB Output is correct
26 Correct 327 ms 16760 KB Output is correct
27 Correct 323 ms 16608 KB Output is correct
28 Correct 331 ms 16660 KB Output is correct
29 Correct 329 ms 16656 KB Output is correct
30 Correct 338 ms 16808 KB Output is correct
31 Correct 341 ms 16664 KB Output is correct
32 Correct 323 ms 16580 KB Output is correct
33 Correct 328 ms 16560 KB Output is correct
34 Correct 337 ms 16652 KB Output is correct
35 Correct 325 ms 16620 KB Output is correct
36 Correct 329 ms 16600 KB Output is correct
37 Correct 334 ms 16676 KB Output is correct
38 Correct 364 ms 16580 KB Output is correct
39 Correct 328 ms 16776 KB Output is correct
40 Correct 323 ms 16656 KB Output is correct
41 Correct 325 ms 16660 KB Output is correct
42 Correct 326 ms 16608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 358 ms 15188 KB Output is correct
2 Correct 321 ms 16040 KB Output is correct
3 Correct 323 ms 15940 KB Output is correct
4 Correct 328 ms 16044 KB Output is correct
5 Correct 373 ms 16084 KB Output is correct
6 Correct 330 ms 16076 KB Output is correct
7 Correct 322 ms 16068 KB Output is correct
8 Correct 326 ms 16204 KB Output is correct
9 Correct 342 ms 15944 KB Output is correct
10 Correct 332 ms 16076 KB Output is correct
11 Correct 343 ms 16060 KB Output is correct
12 Correct 341 ms 16052 KB Output is correct
13 Correct 337 ms 16072 KB Output is correct
14 Correct 397 ms 16008 KB Output is correct
15 Correct 323 ms 16068 KB Output is correct
16 Correct 323 ms 15960 KB Output is correct
17 Correct 327 ms 16068 KB Output is correct
18 Correct 352 ms 16008 KB Output is correct
19 Correct 326 ms 15940 KB Output is correct
20 Correct 332 ms 15940 KB Output is correct
21 Correct 363 ms 16104 KB Output is correct
22 Correct 328 ms 16600 KB Output is correct
23 Correct 342 ms 16616 KB Output is correct
24 Correct 331 ms 16668 KB Output is correct
25 Correct 334 ms 16548 KB Output is correct
26 Correct 327 ms 16760 KB Output is correct
27 Correct 323 ms 16608 KB Output is correct
28 Correct 331 ms 16660 KB Output is correct
29 Correct 329 ms 16656 KB Output is correct
30 Correct 338 ms 16808 KB Output is correct
31 Correct 341 ms 16664 KB Output is correct
32 Correct 323 ms 16580 KB Output is correct
33 Correct 328 ms 16560 KB Output is correct
34 Correct 337 ms 16652 KB Output is correct
35 Correct 325 ms 16620 KB Output is correct
36 Correct 329 ms 16600 KB Output is correct
37 Correct 334 ms 16676 KB Output is correct
38 Correct 364 ms 16580 KB Output is correct
39 Correct 328 ms 16776 KB Output is correct
40 Correct 323 ms 16656 KB Output is correct
41 Correct 325 ms 16660 KB Output is correct
42 Correct 326 ms 16608 KB Output is correct
43 Correct 341 ms 16852 KB Output is correct
44 Correct 347 ms 16836 KB Output is correct
45 Correct 357 ms 16780 KB Output is correct
46 Correct 356 ms 16868 KB Output is correct
47 Correct 364 ms 16808 KB Output is correct
48 Correct 365 ms 16940 KB Output is correct
49 Correct 349 ms 16796 KB Output is correct
50 Correct 357 ms 16964 KB Output is correct
51 Correct 352 ms 16856 KB Output is correct
52 Correct 349 ms 16964 KB Output is correct
53 Correct 361 ms 16840 KB Output is correct
54 Correct 356 ms 16924 KB Output is correct
55 Correct 372 ms 16864 KB Output is correct
56 Correct 354 ms 16868 KB Output is correct
57 Correct 355 ms 16800 KB Output is correct
58 Correct 356 ms 16836 KB Output is correct
59 Correct 351 ms 16900 KB Output is correct
60 Correct 355 ms 16836 KB Output is correct
61 Correct 353 ms 16876 KB Output is correct
62 Correct 353 ms 16836 KB Output is correct
63 Correct 361 ms 16836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 358 ms 15188 KB Output is correct
2 Correct 321 ms 16040 KB Output is correct
3 Correct 323 ms 15940 KB Output is correct
4 Correct 328 ms 16044 KB Output is correct
5 Correct 373 ms 16084 KB Output is correct
6 Correct 330 ms 16076 KB Output is correct
7 Correct 322 ms 16068 KB Output is correct
8 Correct 326 ms 16204 KB Output is correct
9 Correct 342 ms 15944 KB Output is correct
10 Correct 332 ms 16076 KB Output is correct
11 Correct 343 ms 16060 KB Output is correct
12 Correct 341 ms 16052 KB Output is correct
13 Correct 337 ms 16072 KB Output is correct
14 Correct 397 ms 16008 KB Output is correct
15 Correct 323 ms 16068 KB Output is correct
16 Correct 323 ms 15960 KB Output is correct
17 Correct 327 ms 16068 KB Output is correct
18 Correct 352 ms 16008 KB Output is correct
19 Correct 326 ms 15940 KB Output is correct
20 Correct 332 ms 15940 KB Output is correct
21 Correct 363 ms 16104 KB Output is correct
22 Correct 328 ms 16600 KB Output is correct
23 Correct 342 ms 16616 KB Output is correct
24 Correct 331 ms 16668 KB Output is correct
25 Correct 334 ms 16548 KB Output is correct
26 Correct 327 ms 16760 KB Output is correct
27 Correct 323 ms 16608 KB Output is correct
28 Correct 331 ms 16660 KB Output is correct
29 Correct 329 ms 16656 KB Output is correct
30 Correct 338 ms 16808 KB Output is correct
31 Correct 341 ms 16664 KB Output is correct
32 Correct 323 ms 16580 KB Output is correct
33 Correct 328 ms 16560 KB Output is correct
34 Correct 337 ms 16652 KB Output is correct
35 Correct 325 ms 16620 KB Output is correct
36 Correct 329 ms 16600 KB Output is correct
37 Correct 334 ms 16676 KB Output is correct
38 Correct 364 ms 16580 KB Output is correct
39 Correct 328 ms 16776 KB Output is correct
40 Correct 323 ms 16656 KB Output is correct
41 Correct 325 ms 16660 KB Output is correct
42 Correct 326 ms 16608 KB Output is correct
43 Correct 341 ms 16852 KB Output is correct
44 Correct 347 ms 16836 KB Output is correct
45 Correct 357 ms 16780 KB Output is correct
46 Correct 356 ms 16868 KB Output is correct
47 Correct 364 ms 16808 KB Output is correct
48 Correct 365 ms 16940 KB Output is correct
49 Correct 349 ms 16796 KB Output is correct
50 Correct 357 ms 16964 KB Output is correct
51 Correct 352 ms 16856 KB Output is correct
52 Correct 349 ms 16964 KB Output is correct
53 Correct 361 ms 16840 KB Output is correct
54 Correct 356 ms 16924 KB Output is correct
55 Correct 372 ms 16864 KB Output is correct
56 Correct 354 ms 16868 KB Output is correct
57 Correct 355 ms 16800 KB Output is correct
58 Correct 356 ms 16836 KB Output is correct
59 Correct 351 ms 16900 KB Output is correct
60 Correct 355 ms 16836 KB Output is correct
61 Correct 353 ms 16876 KB Output is correct
62 Correct 353 ms 16836 KB Output is correct
63 Correct 361 ms 16836 KB Output is correct
64 Incorrect 366 ms 17020 KB Output isn't correct
65 Halted 0 ms 0 KB -