Submission #1025519

# Submission time Handle Problem Language Result Execution time Memory
1025519 2024-07-17T05:58:35 Z 변재우(#10944) Cubeword (CEOI19_cubeword) C++17
100 / 100
1071 ms 10216 KB
#include <bits/stdc++.h>
#pragma gcc optimize("O3")
#define int long long
using namespace std;

const int Nmax=100010, M=62, Mod=998244353;
int N, ans, cnt[M][M], val[M][M][M];
string S[Nmax];

int f(char x) {
    if('a'<=x && x<='z') return x-'a';
    else if('A'<=x && x<='Z') return x-'A'+26;
    else return x-'0'+52;
}

void solve(vector<string> V) {
    map<string, bool> chk;
    for(int i=0; i<V.size(); i++) {
        string tmp=V[i];
        reverse(tmp.begin(), tmp.end());
        if(chk[tmp]) {
            swap(V[i], V.back()); V.pop_back();
            i--; continue;
        }
        chk[V[i]]=true;
    }
    for(int i=0; i<M; i++) for(int j=0; j<M; j++) cnt[i][j]=0;
    for(int i=0; i<V.size(); i++) {
        int l=f(V[i][0]), r=f(V[i].back());
        cnt[l][r]++;
        string t=V[i]; reverse(t.begin(), t.end());
        if(l!=r || V[i]!=t) cnt[r][l]++;
    }
    for(int i=0; i<M; i++) for(int j=0; j<M; j++) for(int k=0; k<M; k++) {
        val[i][j][k]=0;
        for(int l=0; l<M; l++) val[i][j][k]=(val[i][j][k]+(cnt[i][l]*cnt[j][l]*cnt[k][l]))%Mod;
    }
    for(int a=0; a<M; a++) for(int b=0; b<M; b++) for(int c=0; c<M; c++) for(int d=0; d<M; d++)
        ans=(ans+((val[a][b][c]*val[a][b][d])%Mod)*((val[a][c][d]*val[b][c][d])%Mod))%Mod;
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N;
    for(int i=1; i<=N; i++) cin>>S[i];
    for(int i=3; i<=10; i++) {
        vector<string> v;
        for(int j=1; j<=N; j++) if(S[j].size()==i) v.push_back(S[j]);
        solve(v);
    }
    cout<<ans;
    return 0;
}

Compilation message

cubeword.cpp:2: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
    2 | #pragma gcc optimize("O3")
      | 
cubeword.cpp: In function 'void solve(std::vector<std::__cxx11::basic_string<char> >)':
cubeword.cpp:18:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0; i<V.size(); i++) {
      |                  ~^~~~~~~~~
cubeword.cpp:28:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i=0; i<V.size(); i++) {
      |                  ~^~~~~~~~~
cubeword.cpp: In function 'int main()':
cubeword.cpp:48:47: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   48 |         for(int j=1; j<=N; j++) if(S[j].size()==i) v.push_back(S[j]);
      |                                    ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 962 ms 9680 KB Output is correct
2 Correct 991 ms 9896 KB Output is correct
3 Correct 994 ms 10072 KB Output is correct
4 Correct 1018 ms 10048 KB Output is correct
5 Correct 980 ms 10072 KB Output is correct
6 Correct 1018 ms 9984 KB Output is correct
7 Correct 1004 ms 9684 KB Output is correct
8 Correct 1002 ms 10060 KB Output is correct
9 Correct 1014 ms 10036 KB Output is correct
10 Correct 989 ms 10216 KB Output is correct
11 Correct 1012 ms 9996 KB Output is correct
12 Correct 996 ms 9952 KB Output is correct
13 Correct 1002 ms 10144 KB Output is correct
14 Correct 1014 ms 10000 KB Output is correct
15 Correct 986 ms 9976 KB Output is correct
16 Correct 1008 ms 9884 KB Output is correct
17 Correct 1025 ms 9668 KB Output is correct
18 Correct 1033 ms 9980 KB Output is correct
19 Correct 1071 ms 10012 KB Output is correct
20 Correct 1052 ms 9888 KB Output is correct
21 Correct 998 ms 10156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 962 ms 9680 KB Output is correct
2 Correct 991 ms 9896 KB Output is correct
3 Correct 994 ms 10072 KB Output is correct
4 Correct 1018 ms 10048 KB Output is correct
5 Correct 980 ms 10072 KB Output is correct
6 Correct 1018 ms 9984 KB Output is correct
7 Correct 1004 ms 9684 KB Output is correct
8 Correct 1002 ms 10060 KB Output is correct
9 Correct 1014 ms 10036 KB Output is correct
10 Correct 989 ms 10216 KB Output is correct
11 Correct 1012 ms 9996 KB Output is correct
12 Correct 996 ms 9952 KB Output is correct
13 Correct 1002 ms 10144 KB Output is correct
14 Correct 1014 ms 10000 KB Output is correct
15 Correct 986 ms 9976 KB Output is correct
16 Correct 1008 ms 9884 KB Output is correct
17 Correct 1025 ms 9668 KB Output is correct
18 Correct 1033 ms 9980 KB Output is correct
19 Correct 1071 ms 10012 KB Output is correct
20 Correct 1052 ms 9888 KB Output is correct
21 Correct 998 ms 10156 KB Output is correct
22 Correct 992 ms 8572 KB Output is correct
23 Correct 926 ms 8600 KB Output is correct
24 Correct 993 ms 8600 KB Output is correct
25 Correct 980 ms 8604 KB Output is correct
26 Correct 987 ms 8568 KB Output is correct
27 Correct 953 ms 8600 KB Output is correct
28 Correct 909 ms 8604 KB Output is correct
29 Correct 920 ms 8476 KB Output is correct
30 Correct 959 ms 8624 KB Output is correct
31 Correct 925 ms 8608 KB Output is correct
32 Correct 980 ms 8480 KB Output is correct
33 Correct 975 ms 8608 KB Output is correct
34 Correct 1004 ms 8860 KB Output is correct
35 Correct 968 ms 8600 KB Output is correct
36 Correct 968 ms 8372 KB Output is correct
37 Correct 990 ms 8728 KB Output is correct
38 Correct 979 ms 8584 KB Output is correct
39 Correct 915 ms 8600 KB Output is correct
40 Correct 991 ms 8452 KB Output is correct
41 Correct 989 ms 8544 KB Output is correct
42 Correct 998 ms 8608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 962 ms 9680 KB Output is correct
2 Correct 991 ms 9896 KB Output is correct
3 Correct 994 ms 10072 KB Output is correct
4 Correct 1018 ms 10048 KB Output is correct
5 Correct 980 ms 10072 KB Output is correct
6 Correct 1018 ms 9984 KB Output is correct
7 Correct 1004 ms 9684 KB Output is correct
8 Correct 1002 ms 10060 KB Output is correct
9 Correct 1014 ms 10036 KB Output is correct
10 Correct 989 ms 10216 KB Output is correct
11 Correct 1012 ms 9996 KB Output is correct
12 Correct 996 ms 9952 KB Output is correct
13 Correct 1002 ms 10144 KB Output is correct
14 Correct 1014 ms 10000 KB Output is correct
15 Correct 986 ms 9976 KB Output is correct
16 Correct 1008 ms 9884 KB Output is correct
17 Correct 1025 ms 9668 KB Output is correct
18 Correct 1033 ms 9980 KB Output is correct
19 Correct 1071 ms 10012 KB Output is correct
20 Correct 1052 ms 9888 KB Output is correct
21 Correct 998 ms 10156 KB Output is correct
22 Correct 992 ms 8572 KB Output is correct
23 Correct 926 ms 8600 KB Output is correct
24 Correct 993 ms 8600 KB Output is correct
25 Correct 980 ms 8604 KB Output is correct
26 Correct 987 ms 8568 KB Output is correct
27 Correct 953 ms 8600 KB Output is correct
28 Correct 909 ms 8604 KB Output is correct
29 Correct 920 ms 8476 KB Output is correct
30 Correct 959 ms 8624 KB Output is correct
31 Correct 925 ms 8608 KB Output is correct
32 Correct 980 ms 8480 KB Output is correct
33 Correct 975 ms 8608 KB Output is correct
34 Correct 1004 ms 8860 KB Output is correct
35 Correct 968 ms 8600 KB Output is correct
36 Correct 968 ms 8372 KB Output is correct
37 Correct 990 ms 8728 KB Output is correct
38 Correct 979 ms 8584 KB Output is correct
39 Correct 915 ms 8600 KB Output is correct
40 Correct 991 ms 8452 KB Output is correct
41 Correct 989 ms 8544 KB Output is correct
42 Correct 998 ms 8608 KB Output is correct
43 Correct 988 ms 8252 KB Output is correct
44 Correct 982 ms 8372 KB Output is correct
45 Correct 991 ms 8248 KB Output is correct
46 Correct 969 ms 8376 KB Output is correct
47 Correct 973 ms 8364 KB Output is correct
48 Correct 993 ms 8328 KB Output is correct
49 Correct 953 ms 8496 KB Output is correct
50 Correct 972 ms 8248 KB Output is correct
51 Correct 961 ms 8188 KB Output is correct
52 Correct 912 ms 8244 KB Output is correct
53 Correct 913 ms 8396 KB Output is correct
54 Correct 974 ms 8240 KB Output is correct
55 Correct 979 ms 8396 KB Output is correct
56 Correct 975 ms 8288 KB Output is correct
57 Correct 1004 ms 8244 KB Output is correct
58 Correct 985 ms 8328 KB Output is correct
59 Correct 1008 ms 8396 KB Output is correct
60 Correct 1008 ms 8404 KB Output is correct
61 Correct 992 ms 8244 KB Output is correct
62 Correct 955 ms 8416 KB Output is correct
63 Correct 988 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 962 ms 9680 KB Output is correct
2 Correct 991 ms 9896 KB Output is correct
3 Correct 994 ms 10072 KB Output is correct
4 Correct 1018 ms 10048 KB Output is correct
5 Correct 980 ms 10072 KB Output is correct
6 Correct 1018 ms 9984 KB Output is correct
7 Correct 1004 ms 9684 KB Output is correct
8 Correct 1002 ms 10060 KB Output is correct
9 Correct 1014 ms 10036 KB Output is correct
10 Correct 989 ms 10216 KB Output is correct
11 Correct 1012 ms 9996 KB Output is correct
12 Correct 996 ms 9952 KB Output is correct
13 Correct 1002 ms 10144 KB Output is correct
14 Correct 1014 ms 10000 KB Output is correct
15 Correct 986 ms 9976 KB Output is correct
16 Correct 1008 ms 9884 KB Output is correct
17 Correct 1025 ms 9668 KB Output is correct
18 Correct 1033 ms 9980 KB Output is correct
19 Correct 1071 ms 10012 KB Output is correct
20 Correct 1052 ms 9888 KB Output is correct
21 Correct 998 ms 10156 KB Output is correct
22 Correct 992 ms 8572 KB Output is correct
23 Correct 926 ms 8600 KB Output is correct
24 Correct 993 ms 8600 KB Output is correct
25 Correct 980 ms 8604 KB Output is correct
26 Correct 987 ms 8568 KB Output is correct
27 Correct 953 ms 8600 KB Output is correct
28 Correct 909 ms 8604 KB Output is correct
29 Correct 920 ms 8476 KB Output is correct
30 Correct 959 ms 8624 KB Output is correct
31 Correct 925 ms 8608 KB Output is correct
32 Correct 980 ms 8480 KB Output is correct
33 Correct 975 ms 8608 KB Output is correct
34 Correct 1004 ms 8860 KB Output is correct
35 Correct 968 ms 8600 KB Output is correct
36 Correct 968 ms 8372 KB Output is correct
37 Correct 990 ms 8728 KB Output is correct
38 Correct 979 ms 8584 KB Output is correct
39 Correct 915 ms 8600 KB Output is correct
40 Correct 991 ms 8452 KB Output is correct
41 Correct 989 ms 8544 KB Output is correct
42 Correct 998 ms 8608 KB Output is correct
43 Correct 988 ms 8252 KB Output is correct
44 Correct 982 ms 8372 KB Output is correct
45 Correct 991 ms 8248 KB Output is correct
46 Correct 969 ms 8376 KB Output is correct
47 Correct 973 ms 8364 KB Output is correct
48 Correct 993 ms 8328 KB Output is correct
49 Correct 953 ms 8496 KB Output is correct
50 Correct 972 ms 8248 KB Output is correct
51 Correct 961 ms 8188 KB Output is correct
52 Correct 912 ms 8244 KB Output is correct
53 Correct 913 ms 8396 KB Output is correct
54 Correct 974 ms 8240 KB Output is correct
55 Correct 979 ms 8396 KB Output is correct
56 Correct 975 ms 8288 KB Output is correct
57 Correct 1004 ms 8244 KB Output is correct
58 Correct 985 ms 8328 KB Output is correct
59 Correct 1008 ms 8396 KB Output is correct
60 Correct 1008 ms 8404 KB Output is correct
61 Correct 992 ms 8244 KB Output is correct
62 Correct 955 ms 8416 KB Output is correct
63 Correct 988 ms 8192 KB Output is correct
64 Correct 1014 ms 8184 KB Output is correct
65 Correct 972 ms 8624 KB Output is correct
66 Correct 988 ms 8144 KB Output is correct
67 Correct 985 ms 8144 KB Output is correct
68 Correct 1006 ms 8148 KB Output is correct
69 Correct 973 ms 8368 KB Output is correct
70 Correct 1020 ms 8324 KB Output is correct
71 Correct 993 ms 8460 KB Output is correct
72 Correct 991 ms 8144 KB Output is correct
73 Correct 991 ms 8156 KB Output is correct
74 Correct 977 ms 8384 KB Output is correct
75 Correct 983 ms 8344 KB Output is correct
76 Correct 1018 ms 8136 KB Output is correct
77 Correct 1004 ms 8352 KB Output is correct
78 Correct 1034 ms 8344 KB Output is correct
79 Correct 1029 ms 8368 KB Output is correct
80 Correct 1038 ms 8344 KB Output is correct
81 Correct 996 ms 8160 KB Output is correct
82 Correct 964 ms 8144 KB Output is correct
83 Correct 981 ms 8152 KB Output is correct
84 Correct 966 ms 8148 KB Output is correct