답안 #445680

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445680 2021-07-19T09:02:50 Z Haruto810198 Cubeword (CEOI19_cubeword) C++17
50 / 100
929 ms 16452 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define double long double

#define FOR(i,l,r,d) for(int i=(l);i<=(r);i+=(d))
#define szof(x) ((int)(x).size())

#define vi vector<int>
#define pii pair<int,int>

#define F first
#define S second

#define pb push_back
#define eb emplace_back
#define mkp make_pair

const int INF = 2147483647;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int mod = 998244353;
const double eps = 1e-12;

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

const int MAX = 65;
int SZ = 16; /// Subtask 2

int n;
map<char, int> char_id;

vector<string> strings[11];

set<string> edges[MAX][MAX];

int edge_cnt[MAX][MAX];
//int half_cnt[MAX][MAX][MAX];
int half_cnt[4097];

int res;

signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    /// a~p -> 0~15
    for(char i='a'; i<='p'; i++){
        char_id[i] = i - 'a';
    }

    /// A~P -> 16~31
    for(char i='A'; i<='P'; i++){
        char_id[i] = i - 'A' + 16;
    }

    /// q~z -> 32~41
    for(char i='q'; i<='z'; i++){
        char_id[i] = i - 'a' + 16;
    }

    /// Q~Z -> 42~51
    for(char i='Q'; i<='Z'; i++){
        char_id[i] = i - 'A' + 26;
    }

    /// 0~9 -> 52~61
    for(char i='0'; i<='9'; i++){
        char_id[i] = i - '0' + 52;
    }

    cin>>n;

    FOR(i, 1, n, 1){
        string str;
        cin>>str;
        strings[szof(str)].pb(str);
    }

    /// L = len. of strings
    FOR(L, 3, 10, 1){

        FOR(i, 0, SZ-1, 1){
            FOR(j, 0, SZ-1, 1){
                edges[i][j].clear();
            }
        }

        for(string S : strings[L]){
            int u = char_id[ S[0] ];
            int v = char_id[ S[L-1] ];
            edges[u][v].insert(S);
            reverse(S.begin(), S.end());
            edges[v][u].insert(S);
        }

        FOR(i, 0, SZ-1, 1){
            FOR(j, 0, SZ-1, 1){
                edge_cnt[i][j] = szof(edges[i][j]);
            }
        }

        /// one half

        FOR(i, 0, 4095, 1){
            half_cnt[i] = 0;
        }

        FOR(i, 0, 4095, 1){

            int B = (i>>8) & 15;
            int D = (i>>4) & 15;
            int E = i & 15;

            FOR(A, 0, 15, 1){
                half_cnt[i] += edge_cnt[A][B] * edge_cnt[A][D] * edge_cnt[A][E];
                half_cnt[i] %= mod;
            }

        }

        /// another half

        FOR(i, 0, 4095, 1){
            FOR(j, 0, i, 1){

                int B = ((i>>8) & 15);
                int D = ((i>>4) & 15);
                int E = (i & 15);

                int H = ((j>>8) & 15);
                int F = ((j>>4) & 15);
                int C = (j & 15);

                //int BFC = (edge_cnt[B][F] * edge_cnt[B][C]) % mod;
                //int DHC = (edge_cnt[D][H] * edge_cnt[D][C]) % mod;
                //int EHF = (edge_cnt[E][H] * edge_cnt[E][F]) % mod;

                int AAA = (edge_cnt[B][F] * edge_cnt[D][H] * edge_cnt[E][H]) % mod;
                int BBB = (edge_cnt[B][C] * edge_cnt[D][C] * edge_cnt[E][F]) % mod;

                int BDEHFC = (AAA * BBB) % mod;

                int owo = (i==j) ? 1 : 2;
                res += (((half_cnt[i] * half_cnt[j]) % mod) * BDEHFC * owo) % mod;

            }

            res %= mod;

        }

    }

    cout<<res<<'\n';

    return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 897 ms 6860 KB Output is correct
2 Correct 898 ms 6904 KB Output is correct
3 Correct 905 ms 6732 KB Output is correct
4 Correct 907 ms 6832 KB Output is correct
5 Correct 914 ms 6736 KB Output is correct
6 Correct 901 ms 6748 KB Output is correct
7 Correct 906 ms 6784 KB Output is correct
8 Correct 913 ms 6856 KB Output is correct
9 Correct 900 ms 6860 KB Output is correct
10 Correct 916 ms 6760 KB Output is correct
11 Correct 904 ms 6904 KB Output is correct
12 Correct 898 ms 6780 KB Output is correct
13 Correct 900 ms 6880 KB Output is correct
14 Correct 915 ms 6812 KB Output is correct
15 Correct 900 ms 6644 KB Output is correct
16 Correct 904 ms 6852 KB Output is correct
17 Correct 903 ms 6904 KB Output is correct
18 Correct 915 ms 6712 KB Output is correct
19 Correct 903 ms 6800 KB Output is correct
20 Correct 912 ms 6736 KB Output is correct
21 Correct 903 ms 6740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 897 ms 6860 KB Output is correct
2 Correct 898 ms 6904 KB Output is correct
3 Correct 905 ms 6732 KB Output is correct
4 Correct 907 ms 6832 KB Output is correct
5 Correct 914 ms 6736 KB Output is correct
6 Correct 901 ms 6748 KB Output is correct
7 Correct 906 ms 6784 KB Output is correct
8 Correct 913 ms 6856 KB Output is correct
9 Correct 900 ms 6860 KB Output is correct
10 Correct 916 ms 6760 KB Output is correct
11 Correct 904 ms 6904 KB Output is correct
12 Correct 898 ms 6780 KB Output is correct
13 Correct 900 ms 6880 KB Output is correct
14 Correct 915 ms 6812 KB Output is correct
15 Correct 900 ms 6644 KB Output is correct
16 Correct 904 ms 6852 KB Output is correct
17 Correct 903 ms 6904 KB Output is correct
18 Correct 915 ms 6712 KB Output is correct
19 Correct 903 ms 6800 KB Output is correct
20 Correct 912 ms 6736 KB Output is correct
21 Correct 903 ms 6740 KB Output is correct
22 Correct 893 ms 6012 KB Output is correct
23 Correct 891 ms 6748 KB Output is correct
24 Correct 889 ms 6780 KB Output is correct
25 Correct 886 ms 6804 KB Output is correct
26 Correct 897 ms 6808 KB Output is correct
27 Correct 893 ms 6752 KB Output is correct
28 Correct 895 ms 6744 KB Output is correct
29 Correct 891 ms 6868 KB Output is correct
30 Correct 890 ms 6688 KB Output is correct
31 Correct 895 ms 6744 KB Output is correct
32 Correct 897 ms 6680 KB Output is correct
33 Correct 895 ms 6792 KB Output is correct
34 Correct 902 ms 6788 KB Output is correct
35 Correct 892 ms 6828 KB Output is correct
36 Correct 892 ms 6808 KB Output is correct
37 Correct 897 ms 6720 KB Output is correct
38 Correct 897 ms 6780 KB Output is correct
39 Correct 895 ms 6676 KB Output is correct
40 Correct 902 ms 6744 KB Output is correct
41 Correct 892 ms 6692 KB Output is correct
42 Correct 891 ms 6840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 897 ms 6860 KB Output is correct
2 Correct 898 ms 6904 KB Output is correct
3 Correct 905 ms 6732 KB Output is correct
4 Correct 907 ms 6832 KB Output is correct
5 Correct 914 ms 6736 KB Output is correct
6 Correct 901 ms 6748 KB Output is correct
7 Correct 906 ms 6784 KB Output is correct
8 Correct 913 ms 6856 KB Output is correct
9 Correct 900 ms 6860 KB Output is correct
10 Correct 916 ms 6760 KB Output is correct
11 Correct 904 ms 6904 KB Output is correct
12 Correct 898 ms 6780 KB Output is correct
13 Correct 900 ms 6880 KB Output is correct
14 Correct 915 ms 6812 KB Output is correct
15 Correct 900 ms 6644 KB Output is correct
16 Correct 904 ms 6852 KB Output is correct
17 Correct 903 ms 6904 KB Output is correct
18 Correct 915 ms 6712 KB Output is correct
19 Correct 903 ms 6800 KB Output is correct
20 Correct 912 ms 6736 KB Output is correct
21 Correct 903 ms 6740 KB Output is correct
22 Correct 893 ms 6012 KB Output is correct
23 Correct 891 ms 6748 KB Output is correct
24 Correct 889 ms 6780 KB Output is correct
25 Correct 886 ms 6804 KB Output is correct
26 Correct 897 ms 6808 KB Output is correct
27 Correct 893 ms 6752 KB Output is correct
28 Correct 895 ms 6744 KB Output is correct
29 Correct 891 ms 6868 KB Output is correct
30 Correct 890 ms 6688 KB Output is correct
31 Correct 895 ms 6744 KB Output is correct
32 Correct 897 ms 6680 KB Output is correct
33 Correct 895 ms 6792 KB Output is correct
34 Correct 902 ms 6788 KB Output is correct
35 Correct 892 ms 6828 KB Output is correct
36 Correct 892 ms 6808 KB Output is correct
37 Correct 897 ms 6720 KB Output is correct
38 Correct 897 ms 6780 KB Output is correct
39 Correct 895 ms 6676 KB Output is correct
40 Correct 902 ms 6744 KB Output is correct
41 Correct 892 ms 6692 KB Output is correct
42 Correct 891 ms 6840 KB Output is correct
43 Incorrect 929 ms 16452 KB Output isn't correct
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 897 ms 6860 KB Output is correct
2 Correct 898 ms 6904 KB Output is correct
3 Correct 905 ms 6732 KB Output is correct
4 Correct 907 ms 6832 KB Output is correct
5 Correct 914 ms 6736 KB Output is correct
6 Correct 901 ms 6748 KB Output is correct
7 Correct 906 ms 6784 KB Output is correct
8 Correct 913 ms 6856 KB Output is correct
9 Correct 900 ms 6860 KB Output is correct
10 Correct 916 ms 6760 KB Output is correct
11 Correct 904 ms 6904 KB Output is correct
12 Correct 898 ms 6780 KB Output is correct
13 Correct 900 ms 6880 KB Output is correct
14 Correct 915 ms 6812 KB Output is correct
15 Correct 900 ms 6644 KB Output is correct
16 Correct 904 ms 6852 KB Output is correct
17 Correct 903 ms 6904 KB Output is correct
18 Correct 915 ms 6712 KB Output is correct
19 Correct 903 ms 6800 KB Output is correct
20 Correct 912 ms 6736 KB Output is correct
21 Correct 903 ms 6740 KB Output is correct
22 Correct 893 ms 6012 KB Output is correct
23 Correct 891 ms 6748 KB Output is correct
24 Correct 889 ms 6780 KB Output is correct
25 Correct 886 ms 6804 KB Output is correct
26 Correct 897 ms 6808 KB Output is correct
27 Correct 893 ms 6752 KB Output is correct
28 Correct 895 ms 6744 KB Output is correct
29 Correct 891 ms 6868 KB Output is correct
30 Correct 890 ms 6688 KB Output is correct
31 Correct 895 ms 6744 KB Output is correct
32 Correct 897 ms 6680 KB Output is correct
33 Correct 895 ms 6792 KB Output is correct
34 Correct 902 ms 6788 KB Output is correct
35 Correct 892 ms 6828 KB Output is correct
36 Correct 892 ms 6808 KB Output is correct
37 Correct 897 ms 6720 KB Output is correct
38 Correct 897 ms 6780 KB Output is correct
39 Correct 895 ms 6676 KB Output is correct
40 Correct 902 ms 6744 KB Output is correct
41 Correct 892 ms 6692 KB Output is correct
42 Correct 891 ms 6840 KB Output is correct
43 Incorrect 929 ms 16452 KB Output isn't correct
44 Halted 0 ms 0 KB -