답안 #471807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
471807 2021-09-10T22:43:15 Z Ozy Cubeword (CEOI19_cubeword) C++17
0 / 100
14 ms 1356 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];
lli cas[abc][abc];
string st,rev;

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();

        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,i,abc) {
                rep(k,j,abc) {

                    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;
                    }

                    //duda de repetidos
                    cas[i][j] += dp[i][j][k];
                    cas[i][j] %= mod;

                    if (i == j && i == k) continue;
                    if (j == k) {cas[j][k] += dp[i][j][k]; cas[j][k] %= mod;}
                    else if (i == j || i == k) {cas[i][k] += dp[i][j][k]; cas[i][k] %= mod;}
                    else {
                        cas[j][k] += dp[i][j][k]; cas[j][k] %= mod;
                        cas[i][k] += dp[i][j][k]; cas[i][k] %= mod;
                    }

                }
            }
        }

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

                    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:62:49: warning: iteration 34 invokes undefined behavior [-Waggressive-loop-optimizations]
   62 |                         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:61:21: note: in expansion of macro 'rep'
   61 |                     rep (num,1,abc) {
      |                     ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 1356 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 1356 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 1356 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 1356 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -