Submission #471809

# Submission time Handle Problem Language Result Execution time Memory
471809 2021-09-10T23:27:43 Z Ozy Cubeword (CEOI19_cubeword) C++17
0 / 100
347 ms 30660 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][abc][abc], palabras[12][abc][abc];
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();
      |             ~~~~~~~~~~^~~~~
cubeword.cpp:64:33: warning: iteration 34 invokes undefined behavior [-Waggressive-loop-optimizations]
   64 |                     dp[i][j][k] = 0;
      |                     ~~~~~~~~~~~~^~~
cubeword.cpp:5:39: note: within this loop
    5 | #define rep(i,a,b) for(int i = (a); i <= (b); i++)
      |                                       ^
cubeword.cpp:63:17: note: in expansion of macro 'rep'
   63 |                 rep(k,1,abc) {
      |                 ^~~
cubeword.cpp:67:49: warning: iteration 34 invokes undefined behavior [-Waggressive-loop-optimizations]
   67 |                         a = palabras[tam][i][num] * palabras[tam][j][num] * palabras[tam][k][num];
      |                             ~~~~~~~~~~~~~~~~~~~~^
cubeword.cpp:5:39: note: within this loop
    5 | #define rep(i,a,b) for(int i = (a); i <= (b); i++)
      |                                       ^
cubeword.cpp:66:21: note: in expansion of macro 'rep'
   66 |                     rep (num,1,abc) {
      |                     ^~~
cubeword.cpp:82:53: warning: iteration 34 invokes undefined behavior [-Waggressive-loop-optimizations]
   82 |                         a = dp[i][j][k] * dp[i][j][l];
      |                                           ~~~~~~~~~~^
cubeword.cpp:5:39: note: within this loop
    5 | #define rep(i,a,b) for(int i = (a); i <= (b); i++)
      |                                       ^
cubeword.cpp:81:21: note: in expansion of macro 'rep'
   81 |                     rep(l,1,abc) {
      |                     ^~~
# Verdict Execution time Memory Grader output
1 Runtime error 347 ms 30660 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 347 ms 30660 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 347 ms 30660 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 347 ms 30660 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -