답안 #579183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579183 2022-06-18T12:47:40 Z tengiz05 Cubeword (CEOI19_cubeword) C++17
50 / 100
226 ms 4016 KB
#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

const string ex = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

constexpr int P = 998244353;
using i64 = long long;
// assume -P <= x < 2P
int norm(int x) {
    if (x < 0) {
        x += P;
    }
    if (x >= P) {
        x -= P;
    }
    return x;
}
template<class T>
T power(T a, int b) {
    T res = 1;
    for (; b; b /= 2, a *= a) {
        if (b % 2) {
            res *= a;
        }
    }
    return res;
}
struct Z {
    int x;
    Z(int x = 0) : x(norm(x)) {}
    int val() const {
        return x;
    }
    Z operator-() const {
        return Z(norm(P - x));
    }
    Z inv() const {
        assert(x != 0);
        return power(*this, P - 2);
    }
    Z &operator*=(const Z &rhs) {
        x = i64(x) * rhs.x % P;
        return *this;
    }
    Z &operator+=(const Z &rhs) {
        x = norm(x + rhs.x);
        return *this;
    }
    Z &operator-=(const Z &rhs) {
        x = norm(x - rhs.x);
        return *this;
    }
    Z &operator/=(const Z &rhs) {
        return *this *= rhs.inv();
    }
    friend Z operator*(const Z &lhs, const Z &rhs) {
        Z res = lhs;
        res *= rhs;
        return res;
    }
    friend Z operator+(const Z &lhs, const Z &rhs) {
        Z res = lhs;
        res += rhs;
        return res;
    }
    friend Z operator-(const Z &lhs, const Z &rhs) {
        Z res = lhs;
        res -= rhs;
        return res;
    }
    friend Z operator/(const Z &lhs, const Z &rhs) {
        Z res = lhs;
        res /= rhs;
        return res;
    }
};

constexpr int K = 30;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    vector<vector<string>> s(11);
    for (int i = 0; i < n; i++) {
        string g;
        cin >> g;
        string t(g.rbegin(), g.rend());
        if (t < g)
            g = t;
        s[g.size()].push_back(g);
    }
    
    auto work = [&](vector<string> &s) {
        sort(s.begin(), s.end());
        s.erase(unique(s.begin(), s.end()), s.end());
        
        int n = s.size();
        Z cnt[K][K] {}, cntp[K][K] {};
        for (int i = 0; i < n; i++) {
            int x = ex.find(s[i][0]);
            int y = ex.find(s[i].back());
            string t(s[i].rbegin(), s[i].rend());
            if (s[i] == t) {
                cntp[x][y] += 1;
            } else {
                cnt[x][y] += 1;
                cnt[y][x] += 1;
            }
        }
        
        Z dp[K][K][K] {};
        
        for (int a = 0; a < K; a++) {
            for (int b = 0; b < K; b++) {
                for (int c = 0; c < K; c++) {
                    for (int x = 0; x < K; x++) {
                        Z res = 1;
                        res *= ((a == x) * cntp[a][x]) + cnt[a][x];
                        res *= ((b == x) * cntp[b][x]) + cnt[b][x];
                        res *= ((c == x) * cntp[c][x]) + cnt[c][x];
                        dp[a][b][c] += res;
                    }
                }
            }
        }
        
        Z ans = 0;
        
        for (int a = 0; a < K; a++) {
            for (int b = 0; b < K; b++) {
                for (int c = 0; c < K; c++) {
                    for (int d = 0; d < K; d++) {
                        ans += dp[a][b][c] * dp[a][c][d] * dp[a][b][d] * dp[b][c][d];
                    }
                }
            }
        }
        
        return ans;
    };
    
    Z ans = 0;
    for (int k = 3; k <= 10; k++) {
        ans += work(s[k]);
    }
    
    cout << ans.val() << "\n";
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 3744 KB Output is correct
2 Correct 196 ms 3764 KB Output is correct
3 Correct 181 ms 3984 KB Output is correct
4 Correct 181 ms 4012 KB Output is correct
5 Correct 170 ms 3804 KB Output is correct
6 Correct 177 ms 3716 KB Output is correct
7 Correct 225 ms 4016 KB Output is correct
8 Correct 205 ms 3760 KB Output is correct
9 Correct 176 ms 3804 KB Output is correct
10 Correct 205 ms 3792 KB Output is correct
11 Correct 194 ms 3708 KB Output is correct
12 Correct 226 ms 3900 KB Output is correct
13 Correct 199 ms 3724 KB Output is correct
14 Correct 200 ms 4016 KB Output is correct
15 Correct 173 ms 4008 KB Output is correct
16 Correct 179 ms 3804 KB Output is correct
17 Correct 184 ms 3984 KB Output is correct
18 Correct 217 ms 3716 KB Output is correct
19 Correct 165 ms 3788 KB Output is correct
20 Correct 179 ms 3784 KB Output is correct
21 Correct 173 ms 3800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 3744 KB Output is correct
2 Correct 196 ms 3764 KB Output is correct
3 Correct 181 ms 3984 KB Output is correct
4 Correct 181 ms 4012 KB Output is correct
5 Correct 170 ms 3804 KB Output is correct
6 Correct 177 ms 3716 KB Output is correct
7 Correct 225 ms 4016 KB Output is correct
8 Correct 205 ms 3760 KB Output is correct
9 Correct 176 ms 3804 KB Output is correct
10 Correct 205 ms 3792 KB Output is correct
11 Correct 194 ms 3708 KB Output is correct
12 Correct 226 ms 3900 KB Output is correct
13 Correct 199 ms 3724 KB Output is correct
14 Correct 200 ms 4016 KB Output is correct
15 Correct 173 ms 4008 KB Output is correct
16 Correct 179 ms 3804 KB Output is correct
17 Correct 184 ms 3984 KB Output is correct
18 Correct 217 ms 3716 KB Output is correct
19 Correct 165 ms 3788 KB Output is correct
20 Correct 179 ms 3784 KB Output is correct
21 Correct 173 ms 3800 KB Output is correct
22 Correct 187 ms 3816 KB Output is correct
23 Correct 199 ms 3984 KB Output is correct
24 Correct 177 ms 3712 KB Output is correct
25 Correct 184 ms 3836 KB Output is correct
26 Correct 213 ms 3996 KB Output is correct
27 Correct 211 ms 3824 KB Output is correct
28 Correct 191 ms 3984 KB Output is correct
29 Correct 190 ms 3716 KB Output is correct
30 Correct 212 ms 3952 KB Output is correct
31 Correct 159 ms 3872 KB Output is correct
32 Correct 178 ms 3904 KB Output is correct
33 Correct 170 ms 3896 KB Output is correct
34 Correct 164 ms 3732 KB Output is correct
35 Correct 170 ms 4012 KB Output is correct
36 Correct 182 ms 3976 KB Output is correct
37 Correct 165 ms 3936 KB Output is correct
38 Correct 165 ms 3652 KB Output is correct
39 Correct 176 ms 3656 KB Output is correct
40 Correct 162 ms 3712 KB Output is correct
41 Correct 183 ms 3720 KB Output is correct
42 Correct 170 ms 3628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 3744 KB Output is correct
2 Correct 196 ms 3764 KB Output is correct
3 Correct 181 ms 3984 KB Output is correct
4 Correct 181 ms 4012 KB Output is correct
5 Correct 170 ms 3804 KB Output is correct
6 Correct 177 ms 3716 KB Output is correct
7 Correct 225 ms 4016 KB Output is correct
8 Correct 205 ms 3760 KB Output is correct
9 Correct 176 ms 3804 KB Output is correct
10 Correct 205 ms 3792 KB Output is correct
11 Correct 194 ms 3708 KB Output is correct
12 Correct 226 ms 3900 KB Output is correct
13 Correct 199 ms 3724 KB Output is correct
14 Correct 200 ms 4016 KB Output is correct
15 Correct 173 ms 4008 KB Output is correct
16 Correct 179 ms 3804 KB Output is correct
17 Correct 184 ms 3984 KB Output is correct
18 Correct 217 ms 3716 KB Output is correct
19 Correct 165 ms 3788 KB Output is correct
20 Correct 179 ms 3784 KB Output is correct
21 Correct 173 ms 3800 KB Output is correct
22 Correct 187 ms 3816 KB Output is correct
23 Correct 199 ms 3984 KB Output is correct
24 Correct 177 ms 3712 KB Output is correct
25 Correct 184 ms 3836 KB Output is correct
26 Correct 213 ms 3996 KB Output is correct
27 Correct 211 ms 3824 KB Output is correct
28 Correct 191 ms 3984 KB Output is correct
29 Correct 190 ms 3716 KB Output is correct
30 Correct 212 ms 3952 KB Output is correct
31 Correct 159 ms 3872 KB Output is correct
32 Correct 178 ms 3904 KB Output is correct
33 Correct 170 ms 3896 KB Output is correct
34 Correct 164 ms 3732 KB Output is correct
35 Correct 170 ms 4012 KB Output is correct
36 Correct 182 ms 3976 KB Output is correct
37 Correct 165 ms 3936 KB Output is correct
38 Correct 165 ms 3652 KB Output is correct
39 Correct 176 ms 3656 KB Output is correct
40 Correct 162 ms 3712 KB Output is correct
41 Correct 183 ms 3720 KB Output is correct
42 Correct 170 ms 3628 KB Output is correct
43 Incorrect 189 ms 3612 KB Output isn't correct
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 3744 KB Output is correct
2 Correct 196 ms 3764 KB Output is correct
3 Correct 181 ms 3984 KB Output is correct
4 Correct 181 ms 4012 KB Output is correct
5 Correct 170 ms 3804 KB Output is correct
6 Correct 177 ms 3716 KB Output is correct
7 Correct 225 ms 4016 KB Output is correct
8 Correct 205 ms 3760 KB Output is correct
9 Correct 176 ms 3804 KB Output is correct
10 Correct 205 ms 3792 KB Output is correct
11 Correct 194 ms 3708 KB Output is correct
12 Correct 226 ms 3900 KB Output is correct
13 Correct 199 ms 3724 KB Output is correct
14 Correct 200 ms 4016 KB Output is correct
15 Correct 173 ms 4008 KB Output is correct
16 Correct 179 ms 3804 KB Output is correct
17 Correct 184 ms 3984 KB Output is correct
18 Correct 217 ms 3716 KB Output is correct
19 Correct 165 ms 3788 KB Output is correct
20 Correct 179 ms 3784 KB Output is correct
21 Correct 173 ms 3800 KB Output is correct
22 Correct 187 ms 3816 KB Output is correct
23 Correct 199 ms 3984 KB Output is correct
24 Correct 177 ms 3712 KB Output is correct
25 Correct 184 ms 3836 KB Output is correct
26 Correct 213 ms 3996 KB Output is correct
27 Correct 211 ms 3824 KB Output is correct
28 Correct 191 ms 3984 KB Output is correct
29 Correct 190 ms 3716 KB Output is correct
30 Correct 212 ms 3952 KB Output is correct
31 Correct 159 ms 3872 KB Output is correct
32 Correct 178 ms 3904 KB Output is correct
33 Correct 170 ms 3896 KB Output is correct
34 Correct 164 ms 3732 KB Output is correct
35 Correct 170 ms 4012 KB Output is correct
36 Correct 182 ms 3976 KB Output is correct
37 Correct 165 ms 3936 KB Output is correct
38 Correct 165 ms 3652 KB Output is correct
39 Correct 176 ms 3656 KB Output is correct
40 Correct 162 ms 3712 KB Output is correct
41 Correct 183 ms 3720 KB Output is correct
42 Correct 170 ms 3628 KB Output is correct
43 Incorrect 189 ms 3612 KB Output isn't correct
44 Halted 0 ms 0 KB -