답안 #446296

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446296 2021-07-21T13:55:17 Z qwerasdfzxcl Cubeword (CEOI19_cubeword) C++14
0 / 100
1100 ms 21124 KB
#include <bits/stdc++.h>
#define MX 62

typedef long long ll;
using namespace std;
const int MOD = 998244353;
int cnt[101][101][101];
int a[8], b[12] = {0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7}, c[12] = {1, 2, 3, 0, 4, 5, 6, 7, 5, 6, 7, 4};
int mp[505], val[11][101][101][101];

bool chk(string &s){
    int n = s.size();
    for (int i=0;i<n;i++){
        int j = n-1-i;
        if (i>j) break;
        if (s[i]!=s[j]) return 0;
    }
    return 1;
}

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    unordered_set<string> st[11];

    for (int i='a';i<='z';i++){
        mp[i] = i-'a';
    }
    for (int i='A';i<='Z';i++){
        mp[i] = i-'A'+26;
    }
    for (int i='0';i<='9';i++){
        mp[i] = i-'0'+52;
    }
    for (int i=0;i<n;i++){
        string s;
        cin >> s;
        int idx1 = mp[s[0]], idx2 = mp[s.back()], len = s.size();
        cnt[(int)s.size()][idx1][idx2]++;
        cnt[(int)s.size()][idx2][idx1]++;
        if (st[len].find(s)!=st[len].end()){
            cnt[(int)s.size()][idx1][idx2]--;
            cnt[(int)s.size()][idx2][idx1]--;
            continue;
        }
        reverse(s.begin(), s.end());
        if (st[len].find(s)!=st[len].end()){
            cnt[(int)s.size()][idx1][idx2]--;
            cnt[(int)s.size()][idx2][idx1]--;
            continue;
        }
        if (chk(s)) cnt[(int)s.size()][idx2][idx1]--;
        st[len].insert(s);
    }

    for (int len=3;len<=10;len++){
        for (int i=0;i<MX;i++){
            for (int j=0;j<MX;j++){
                for (int k=0;k<MX;k++){
                    for (int l=0;l<MX;l++){
                        ll tmp = (ll)cnt[len][i][l] * cnt[len][j][l] %MOD;
                        tmp = (tmp*cnt[len][k][l])%MOD;
                        val[len][i][j][k] += tmp;
                        if (val[len][i][j][k]>=MOD) val[len][i][j][k] -= MOD;
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int len=3;len<=10;len++){
        for (int i=0;i<MX;i++){
            for (int j=0;j<MX;j++){
                for (int k=0;k<MX;k++){
                    for (int l=0;l<MX;l++){
                        ll tmp = val[len][i][j][k];
                        tmp = (tmp*val[len][i][j][l])%MOD;
                        tmp = (tmp*val[len][i][k][l])%MOD;
                        tmp = (tmp*val[len][j][k][l])%MOD;
                        ans += tmp;
                        if (ans>=MOD) ans -= MOD;
                    }
                }
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

cubeword.cpp: In function 'int main()':
cubeword.cpp:40:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   40 |         int idx1 = mp[s[0]], idx2 = mp[s.back()], len = s.size();
      |                           ^
cubeword.cpp:40:46: warning: array subscript has type 'char' [-Wchar-subscripts]
   40 |         int idx1 = mp[s[0]], idx2 = mp[s.back()], len = s.size();
      |                                        ~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1195 ms 21124 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1195 ms 21124 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1195 ms 21124 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1195 ms 21124 KB Time limit exceeded
2 Halted 0 ms 0 KB -