답안 #658494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
658494 2022-11-13T10:43:48 Z mychecksedad Cubeword (CEOI19_cubeword) C++17
21 / 100
105 ms 7472 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD1 (1000000000+7)
#define MOD (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;

int n, S = 6;
ll dp[100][100];
vector<string> s[15];
bool is_palindrome(string &a){
    bool ok = 1;
    int x = a.length();
    for(int i = 0; i < x / 2; ++i) ok &= (a[i] == a[x - i - 1]);

    return ok;
}
void solve(){
    cin >> n;
    for(int i = 0; i < n; ++i){
        string a; cin >> a;
        // for(char &c: a) if(!(c >= 'a' && c <= 'p')) c = 'p' + (c - 'A') + 1;
        s[a.length()].pb(a);
    }
    ll ans = 0;
    for(int i = 1; i < 15; ++i){
        if(s[i].empty()) continue;
        for(int j = 0; j <= S; ++j) for(int k = 0; k <= S; ++k) dp[j][k] = 0;
        map<string, bool> used;
        for(auto a: s[i]){
            if(used[a]) continue;
            if(is_palindrome(a)){
                dp[a[0] - 'a'][a[0] - 'a']++;
            }else{
                dp[a[0] - 'a'][a.back() - 'a']++;
                dp[a.back() - 'a'][a[0] - 'a']++;
            }
            reverse(all(a));
            used[a] = 1;
        }
        for(int left = 0; left < S*S; ++left){
            int x = left / S, y = left % S;
            for(int right = 0; right < S*S; ++right){
                int z = right / S, w = right % S;

                ll p = (dp[x][y] * dp[z][w]) % MOD;

                ll P = 0;

                for(int middle = 0; middle < S*S; ++middle){
                    int k = middle / S, l = middle % S;

                    ll pp = (dp[k][l] * dp[x][k]) % MOD;
                    (pp *= dp[y][l]) %= MOD;
                    ll ppp = (dp[z][k] * dp[w][l]) % MOD;
                    (ppp *= pp) %= MOD;
                    (P += ppp) %= MOD;
                }
                (P *= P) %= MOD;
                (ans += P * p) %= MOD;
            }
        }
    }
    cout << ans;
}





int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
    }
    return 0;
 
}

Compilation message

cubeword.cpp: In function 'int main()':
cubeword.cpp:82:16: warning: unused variable 'aa' [-Wunused-variable]
   82 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 6388 KB Output is correct
2 Correct 87 ms 7288 KB Output is correct
3 Correct 79 ms 7428 KB Output is correct
4 Correct 103 ms 7304 KB Output is correct
5 Correct 84 ms 7268 KB Output is correct
6 Correct 79 ms 7308 KB Output is correct
7 Correct 80 ms 7312 KB Output is correct
8 Correct 105 ms 7376 KB Output is correct
9 Correct 81 ms 7364 KB Output is correct
10 Correct 78 ms 7376 KB Output is correct
11 Correct 80 ms 7336 KB Output is correct
12 Correct 82 ms 7348 KB Output is correct
13 Correct 90 ms 7272 KB Output is correct
14 Correct 105 ms 7356 KB Output is correct
15 Correct 79 ms 7388 KB Output is correct
16 Correct 78 ms 7356 KB Output is correct
17 Correct 79 ms 7388 KB Output is correct
18 Correct 97 ms 7472 KB Output is correct
19 Correct 79 ms 7244 KB Output is correct
20 Correct 80 ms 7240 KB Output is correct
21 Correct 82 ms 7248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 6388 KB Output is correct
2 Correct 87 ms 7288 KB Output is correct
3 Correct 79 ms 7428 KB Output is correct
4 Correct 103 ms 7304 KB Output is correct
5 Correct 84 ms 7268 KB Output is correct
6 Correct 79 ms 7308 KB Output is correct
7 Correct 80 ms 7312 KB Output is correct
8 Correct 105 ms 7376 KB Output is correct
9 Correct 81 ms 7364 KB Output is correct
10 Correct 78 ms 7376 KB Output is correct
11 Correct 80 ms 7336 KB Output is correct
12 Correct 82 ms 7348 KB Output is correct
13 Correct 90 ms 7272 KB Output is correct
14 Correct 105 ms 7356 KB Output is correct
15 Correct 79 ms 7388 KB Output is correct
16 Correct 78 ms 7356 KB Output is correct
17 Correct 79 ms 7388 KB Output is correct
18 Correct 97 ms 7472 KB Output is correct
19 Correct 79 ms 7244 KB Output is correct
20 Correct 80 ms 7240 KB Output is correct
21 Correct 82 ms 7248 KB Output is correct
22 Incorrect 87 ms 6428 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 6388 KB Output is correct
2 Correct 87 ms 7288 KB Output is correct
3 Correct 79 ms 7428 KB Output is correct
4 Correct 103 ms 7304 KB Output is correct
5 Correct 84 ms 7268 KB Output is correct
6 Correct 79 ms 7308 KB Output is correct
7 Correct 80 ms 7312 KB Output is correct
8 Correct 105 ms 7376 KB Output is correct
9 Correct 81 ms 7364 KB Output is correct
10 Correct 78 ms 7376 KB Output is correct
11 Correct 80 ms 7336 KB Output is correct
12 Correct 82 ms 7348 KB Output is correct
13 Correct 90 ms 7272 KB Output is correct
14 Correct 105 ms 7356 KB Output is correct
15 Correct 79 ms 7388 KB Output is correct
16 Correct 78 ms 7356 KB Output is correct
17 Correct 79 ms 7388 KB Output is correct
18 Correct 97 ms 7472 KB Output is correct
19 Correct 79 ms 7244 KB Output is correct
20 Correct 80 ms 7240 KB Output is correct
21 Correct 82 ms 7248 KB Output is correct
22 Incorrect 87 ms 6428 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 6388 KB Output is correct
2 Correct 87 ms 7288 KB Output is correct
3 Correct 79 ms 7428 KB Output is correct
4 Correct 103 ms 7304 KB Output is correct
5 Correct 84 ms 7268 KB Output is correct
6 Correct 79 ms 7308 KB Output is correct
7 Correct 80 ms 7312 KB Output is correct
8 Correct 105 ms 7376 KB Output is correct
9 Correct 81 ms 7364 KB Output is correct
10 Correct 78 ms 7376 KB Output is correct
11 Correct 80 ms 7336 KB Output is correct
12 Correct 82 ms 7348 KB Output is correct
13 Correct 90 ms 7272 KB Output is correct
14 Correct 105 ms 7356 KB Output is correct
15 Correct 79 ms 7388 KB Output is correct
16 Correct 78 ms 7356 KB Output is correct
17 Correct 79 ms 7388 KB Output is correct
18 Correct 97 ms 7472 KB Output is correct
19 Correct 79 ms 7244 KB Output is correct
20 Correct 80 ms 7240 KB Output is correct
21 Correct 82 ms 7248 KB Output is correct
22 Incorrect 87 ms 6428 KB Output isn't correct
23 Halted 0 ms 0 KB -