답안 #658588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
658588 2022-11-13T15:30:23 Z mychecksedad Cubeword (CEOI19_cubeword) C++17
100 / 100
272 ms 8168 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 = 65, mul[8] = { 24, 12, 12, 4, 12, 6, 4, 1 };
ll dp[100][100], d[70][70][70];
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;
}

int comb(int a, int b, int c, int d){
    int q = 0;
    if(a==b) q += 1;
    if(b==c) q += 2;
    if(c==d) q += 4;
    return mul[q];
}

void solve(){
    cin >> n;
    for(int i = 0; i < n; ++i){
        string a; cin >> a;
        for(char &c: a){
            if(c >= 'a' && c <= 'z'){
                c = '9' + 1 + (c - 'a');
            }
            else if(c >= 'A' && c <= 'Z'){
                c = '9' + 27 + (c - 'A');
            }
        }
        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] - '0'][a[0] - '0']++;
            }else{
                dp[a[0] - '0'][a.back() - '0']++;
                dp[a.back() - '0'][a[0] - '0']++;
            }
            reverse(all(a));
            used[a] = 1;
        }


        for(int a = 0; a < S; ++a){
            for(int b = a; b < S; ++b){
                for(int c = b; c < S; ++c){
                    d[a][b][c] = 0;
                    for(int l = 0; l < S; ++l){
                        (d[a][b][c] += (dp[a][l] * dp[b][l] % MOD) * dp[c][l]) %= MOD;
                    }   
                }
            }
        }

        for(int a = 0; a < S; ++a){
            for(int b = a; b < S; ++b){
                for(int c = b; c < S; ++c){
                    for(int e = c; e < S; ++e){
                        ll p = (d[a][b][c] * d[a][b][e] % MOD) * (d[a][c][e] * d[b][c][e] % MOD) % MOD;
                        (ans += p * comb(a, b, c, e)) %= 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:101:16: warning: unused variable 'aa' [-Wunused-variable]
  101 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 232 ms 7924 KB Output is correct
2 Correct 217 ms 7980 KB Output is correct
3 Correct 223 ms 8024 KB Output is correct
4 Correct 226 ms 7964 KB Output is correct
5 Correct 227 ms 7876 KB Output is correct
6 Correct 225 ms 8068 KB Output is correct
7 Correct 220 ms 7928 KB Output is correct
8 Correct 217 ms 8008 KB Output is correct
9 Correct 228 ms 7900 KB Output is correct
10 Correct 219 ms 7992 KB Output is correct
11 Correct 241 ms 7912 KB Output is correct
12 Correct 220 ms 8004 KB Output is correct
13 Correct 229 ms 7908 KB Output is correct
14 Correct 222 ms 7960 KB Output is correct
15 Correct 218 ms 7972 KB Output is correct
16 Correct 217 ms 7936 KB Output is correct
17 Correct 236 ms 7964 KB Output is correct
18 Correct 223 ms 8036 KB Output is correct
19 Correct 224 ms 7892 KB Output is correct
20 Correct 237 ms 7876 KB Output is correct
21 Correct 223 ms 8168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 232 ms 7924 KB Output is correct
2 Correct 217 ms 7980 KB Output is correct
3 Correct 223 ms 8024 KB Output is correct
4 Correct 226 ms 7964 KB Output is correct
5 Correct 227 ms 7876 KB Output is correct
6 Correct 225 ms 8068 KB Output is correct
7 Correct 220 ms 7928 KB Output is correct
8 Correct 217 ms 8008 KB Output is correct
9 Correct 228 ms 7900 KB Output is correct
10 Correct 219 ms 7992 KB Output is correct
11 Correct 241 ms 7912 KB Output is correct
12 Correct 220 ms 8004 KB Output is correct
13 Correct 229 ms 7908 KB Output is correct
14 Correct 222 ms 7960 KB Output is correct
15 Correct 218 ms 7972 KB Output is correct
16 Correct 217 ms 7936 KB Output is correct
17 Correct 236 ms 7964 KB Output is correct
18 Correct 223 ms 8036 KB Output is correct
19 Correct 224 ms 7892 KB Output is correct
20 Correct 237 ms 7876 KB Output is correct
21 Correct 223 ms 8168 KB Output is correct
22 Correct 226 ms 7168 KB Output is correct
23 Correct 219 ms 7172 KB Output is correct
24 Correct 241 ms 7248 KB Output is correct
25 Correct 218 ms 7068 KB Output is correct
26 Correct 216 ms 7096 KB Output is correct
27 Correct 223 ms 7244 KB Output is correct
28 Correct 225 ms 7164 KB Output is correct
29 Correct 219 ms 7164 KB Output is correct
30 Correct 242 ms 7280 KB Output is correct
31 Correct 223 ms 7260 KB Output is correct
32 Correct 226 ms 7112 KB Output is correct
33 Correct 227 ms 7248 KB Output is correct
34 Correct 221 ms 7168 KB Output is correct
35 Correct 225 ms 7244 KB Output is correct
36 Correct 226 ms 7284 KB Output is correct
37 Correct 216 ms 7164 KB Output is correct
38 Correct 239 ms 7184 KB Output is correct
39 Correct 222 ms 7144 KB Output is correct
40 Correct 216 ms 7232 KB Output is correct
41 Correct 226 ms 7100 KB Output is correct
42 Correct 240 ms 7272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 232 ms 7924 KB Output is correct
2 Correct 217 ms 7980 KB Output is correct
3 Correct 223 ms 8024 KB Output is correct
4 Correct 226 ms 7964 KB Output is correct
5 Correct 227 ms 7876 KB Output is correct
6 Correct 225 ms 8068 KB Output is correct
7 Correct 220 ms 7928 KB Output is correct
8 Correct 217 ms 8008 KB Output is correct
9 Correct 228 ms 7900 KB Output is correct
10 Correct 219 ms 7992 KB Output is correct
11 Correct 241 ms 7912 KB Output is correct
12 Correct 220 ms 8004 KB Output is correct
13 Correct 229 ms 7908 KB Output is correct
14 Correct 222 ms 7960 KB Output is correct
15 Correct 218 ms 7972 KB Output is correct
16 Correct 217 ms 7936 KB Output is correct
17 Correct 236 ms 7964 KB Output is correct
18 Correct 223 ms 8036 KB Output is correct
19 Correct 224 ms 7892 KB Output is correct
20 Correct 237 ms 7876 KB Output is correct
21 Correct 223 ms 8168 KB Output is correct
22 Correct 226 ms 7168 KB Output is correct
23 Correct 219 ms 7172 KB Output is correct
24 Correct 241 ms 7248 KB Output is correct
25 Correct 218 ms 7068 KB Output is correct
26 Correct 216 ms 7096 KB Output is correct
27 Correct 223 ms 7244 KB Output is correct
28 Correct 225 ms 7164 KB Output is correct
29 Correct 219 ms 7164 KB Output is correct
30 Correct 242 ms 7280 KB Output is correct
31 Correct 223 ms 7260 KB Output is correct
32 Correct 226 ms 7112 KB Output is correct
33 Correct 227 ms 7248 KB Output is correct
34 Correct 221 ms 7168 KB Output is correct
35 Correct 225 ms 7244 KB Output is correct
36 Correct 226 ms 7284 KB Output is correct
37 Correct 216 ms 7164 KB Output is correct
38 Correct 239 ms 7184 KB Output is correct
39 Correct 222 ms 7144 KB Output is correct
40 Correct 216 ms 7232 KB Output is correct
41 Correct 226 ms 7100 KB Output is correct
42 Correct 240 ms 7272 KB Output is correct
43 Correct 224 ms 7004 KB Output is correct
44 Correct 230 ms 7908 KB Output is correct
45 Correct 226 ms 7728 KB Output is correct
46 Correct 220 ms 7872 KB Output is correct
47 Correct 272 ms 7608 KB Output is correct
48 Correct 221 ms 7848 KB Output is correct
49 Correct 223 ms 7780 KB Output is correct
50 Correct 227 ms 7724 KB Output is correct
51 Correct 227 ms 7608 KB Output is correct
52 Correct 249 ms 7864 KB Output is correct
53 Correct 218 ms 7680 KB Output is correct
54 Correct 251 ms 7876 KB Output is correct
55 Correct 221 ms 7728 KB Output is correct
56 Correct 219 ms 7920 KB Output is correct
57 Correct 229 ms 7728 KB Output is correct
58 Correct 223 ms 7668 KB Output is correct
59 Correct 233 ms 7672 KB Output is correct
60 Correct 239 ms 7728 KB Output is correct
61 Correct 222 ms 7756 KB Output is correct
62 Correct 231 ms 7676 KB Output is correct
63 Correct 215 ms 7640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 232 ms 7924 KB Output is correct
2 Correct 217 ms 7980 KB Output is correct
3 Correct 223 ms 8024 KB Output is correct
4 Correct 226 ms 7964 KB Output is correct
5 Correct 227 ms 7876 KB Output is correct
6 Correct 225 ms 8068 KB Output is correct
7 Correct 220 ms 7928 KB Output is correct
8 Correct 217 ms 8008 KB Output is correct
9 Correct 228 ms 7900 KB Output is correct
10 Correct 219 ms 7992 KB Output is correct
11 Correct 241 ms 7912 KB Output is correct
12 Correct 220 ms 8004 KB Output is correct
13 Correct 229 ms 7908 KB Output is correct
14 Correct 222 ms 7960 KB Output is correct
15 Correct 218 ms 7972 KB Output is correct
16 Correct 217 ms 7936 KB Output is correct
17 Correct 236 ms 7964 KB Output is correct
18 Correct 223 ms 8036 KB Output is correct
19 Correct 224 ms 7892 KB Output is correct
20 Correct 237 ms 7876 KB Output is correct
21 Correct 223 ms 8168 KB Output is correct
22 Correct 226 ms 7168 KB Output is correct
23 Correct 219 ms 7172 KB Output is correct
24 Correct 241 ms 7248 KB Output is correct
25 Correct 218 ms 7068 KB Output is correct
26 Correct 216 ms 7096 KB Output is correct
27 Correct 223 ms 7244 KB Output is correct
28 Correct 225 ms 7164 KB Output is correct
29 Correct 219 ms 7164 KB Output is correct
30 Correct 242 ms 7280 KB Output is correct
31 Correct 223 ms 7260 KB Output is correct
32 Correct 226 ms 7112 KB Output is correct
33 Correct 227 ms 7248 KB Output is correct
34 Correct 221 ms 7168 KB Output is correct
35 Correct 225 ms 7244 KB Output is correct
36 Correct 226 ms 7284 KB Output is correct
37 Correct 216 ms 7164 KB Output is correct
38 Correct 239 ms 7184 KB Output is correct
39 Correct 222 ms 7144 KB Output is correct
40 Correct 216 ms 7232 KB Output is correct
41 Correct 226 ms 7100 KB Output is correct
42 Correct 240 ms 7272 KB Output is correct
43 Correct 224 ms 7004 KB Output is correct
44 Correct 230 ms 7908 KB Output is correct
45 Correct 226 ms 7728 KB Output is correct
46 Correct 220 ms 7872 KB Output is correct
47 Correct 272 ms 7608 KB Output is correct
48 Correct 221 ms 7848 KB Output is correct
49 Correct 223 ms 7780 KB Output is correct
50 Correct 227 ms 7724 KB Output is correct
51 Correct 227 ms 7608 KB Output is correct
52 Correct 249 ms 7864 KB Output is correct
53 Correct 218 ms 7680 KB Output is correct
54 Correct 251 ms 7876 KB Output is correct
55 Correct 221 ms 7728 KB Output is correct
56 Correct 219 ms 7920 KB Output is correct
57 Correct 229 ms 7728 KB Output is correct
58 Correct 223 ms 7668 KB Output is correct
59 Correct 233 ms 7672 KB Output is correct
60 Correct 239 ms 7728 KB Output is correct
61 Correct 222 ms 7756 KB Output is correct
62 Correct 231 ms 7676 KB Output is correct
63 Correct 215 ms 7640 KB Output is correct
64 Correct 230 ms 7792 KB Output is correct
65 Correct 225 ms 7800 KB Output is correct
66 Correct 216 ms 7616 KB Output is correct
67 Correct 233 ms 7812 KB Output is correct
68 Correct 258 ms 7916 KB Output is correct
69 Correct 223 ms 7712 KB Output is correct
70 Correct 231 ms 7576 KB Output is correct
71 Correct 224 ms 7796 KB Output is correct
72 Correct 223 ms 7680 KB Output is correct
73 Correct 241 ms 7704 KB Output is correct
74 Correct 220 ms 7692 KB Output is correct
75 Correct 221 ms 7704 KB Output is correct
76 Correct 243 ms 7564 KB Output is correct
77 Correct 223 ms 7792 KB Output is correct
78 Correct 223 ms 7780 KB Output is correct
79 Correct 240 ms 7700 KB Output is correct
80 Correct 223 ms 7672 KB Output is correct
81 Correct 225 ms 7804 KB Output is correct
82 Correct 230 ms 7676 KB Output is correct
83 Correct 223 ms 7648 KB Output is correct
84 Correct 221 ms 7700 KB Output is correct