답안 #904799

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
904799 2024-01-12T08:31:40 Z andrei_iorgulescu Cubeword (CEOI19_cubeword) C++14
84 / 100
1100 ms 20200 KB
#include <bits/stdc++.h>

using namespace std;

const int S = 62;
const int modulo = 998244353;
vector<string>cuv[15];
int cst[S][S];
int cost[S][S][S];

int toint(char c)
{
    if (c >= 'a' and c <= 'z')
        return c - 'a';
    else if (c >= 'A' and c <= 'Z')
        return 26 + c - 'A';
    else
        return 52 + c - '0';
}

bool palint(string s)
{
    for (int i = 1; i < s.size() - 1; i++)
        if (s[i] != s[s.size() - 1 - i])
            return false;
    return true;
}

string inv(string s)
{
    reverse(s.begin(),s.end());
    return s;
}

map<string,bool>mp;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        string s;
        cin >> s;
        cuv[s.size()].push_back(s);
    }
    int ans = 0;
    for (int l = 3; l <= 10; l++)
    {
        for (int i = 0; i < S; i++)
            for (int j = 0; j < S; j++)
                cst[i][j] = 0;
        for (int i = 0; i < S; i++)
            for (int j = 0; j < S; j++)
                for (int k = 0; k < S; k++)
                    cost[i][j][k] = 0;
        for (auto it : cuv[l])
        {
            if (mp[inv(it)] == true)
                continue;
            mp[it] = true;
            cst[toint(it[0])][toint(it[l - 1])]++;
            if (it[0] != it[l - 1])
                cst[toint(it[l - 1])][toint(it[0])]++;
            else if (palint(it) == false)
                cst[toint(it[0])][toint(it[l - 1])]++;
        }
        for (int i = 0; i < S; i++)
        {
            for (int j = 0; j < S; j++)
            {
                for (int k = 0; k < S; k++)
                {
                    for (int q = 0; q < S; q++)
                        cost[i][j][k] = (0ll + cost[i][j][k] + 1ll * cst[i][q] * cst[j][q] * cst[k][q]) % modulo;
                }
            }
        }
        for (int A = 0; A < S; A++)
        {
            for (int B = 0; B < S; B++)
            {
                for (int C = 0; C < S; C++)
                {
                    for (int D = 0; D < S; D++)
                    {
                        if (cost[A][B][C] != 0 and cost[A][B][D] != 0 and cost[A][C][D] != 0 and cost[B][C][D] != 0)
                        {
                            int adg = 1ll * cost[A][B][C] * cost[A][B][D] % modulo * cost[A][C][D] % modulo * cost[B][C][D] % modulo;
                            ans = (ans + adg) % modulo;
                        }
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Compilation message

cubeword.cpp: In function 'bool palint(std::string)':
cubeword.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int i = 1; i < s.size() - 1; i++)
      |                     ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 661 ms 18980 KB Output is correct
2 Correct 652 ms 19060 KB Output is correct
3 Correct 648 ms 19352 KB Output is correct
4 Correct 639 ms 19092 KB Output is correct
5 Correct 697 ms 18980 KB Output is correct
6 Correct 659 ms 19240 KB Output is correct
7 Correct 681 ms 18972 KB Output is correct
8 Correct 624 ms 19040 KB Output is correct
9 Correct 665 ms 19024 KB Output is correct
10 Correct 658 ms 18936 KB Output is correct
11 Correct 639 ms 18936 KB Output is correct
12 Correct 665 ms 18960 KB Output is correct
13 Correct 651 ms 19016 KB Output is correct
14 Correct 637 ms 18900 KB Output is correct
15 Correct 647 ms 19144 KB Output is correct
16 Correct 696 ms 19080 KB Output is correct
17 Correct 695 ms 19188 KB Output is correct
18 Correct 652 ms 19032 KB Output is correct
19 Correct 660 ms 18872 KB Output is correct
20 Correct 681 ms 18872 KB Output is correct
21 Correct 688 ms 19088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 661 ms 18980 KB Output is correct
2 Correct 652 ms 19060 KB Output is correct
3 Correct 648 ms 19352 KB Output is correct
4 Correct 639 ms 19092 KB Output is correct
5 Correct 697 ms 18980 KB Output is correct
6 Correct 659 ms 19240 KB Output is correct
7 Correct 681 ms 18972 KB Output is correct
8 Correct 624 ms 19040 KB Output is correct
9 Correct 665 ms 19024 KB Output is correct
10 Correct 658 ms 18936 KB Output is correct
11 Correct 639 ms 18936 KB Output is correct
12 Correct 665 ms 18960 KB Output is correct
13 Correct 651 ms 19016 KB Output is correct
14 Correct 637 ms 18900 KB Output is correct
15 Correct 647 ms 19144 KB Output is correct
16 Correct 696 ms 19080 KB Output is correct
17 Correct 695 ms 19188 KB Output is correct
18 Correct 652 ms 19032 KB Output is correct
19 Correct 660 ms 18872 KB Output is correct
20 Correct 681 ms 18872 KB Output is correct
21 Correct 688 ms 19088 KB Output is correct
22 Correct 719 ms 19724 KB Output is correct
23 Correct 764 ms 19448 KB Output is correct
24 Correct 717 ms 19864 KB Output is correct
25 Correct 741 ms 19696 KB Output is correct
26 Correct 686 ms 19456 KB Output is correct
27 Correct 755 ms 19556 KB Output is correct
28 Correct 687 ms 19712 KB Output is correct
29 Correct 666 ms 19836 KB Output is correct
30 Correct 672 ms 19644 KB Output is correct
31 Correct 685 ms 19704 KB Output is correct
32 Correct 672 ms 19680 KB Output is correct
33 Correct 700 ms 19660 KB Output is correct
34 Correct 695 ms 19848 KB Output is correct
35 Correct 715 ms 19544 KB Output is correct
36 Correct 723 ms 19792 KB Output is correct
37 Correct 706 ms 19552 KB Output is correct
38 Correct 642 ms 19484 KB Output is correct
39 Correct 672 ms 19696 KB Output is correct
40 Correct 722 ms 19964 KB Output is correct
41 Correct 685 ms 19452 KB Output is correct
42 Correct 702 ms 19888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 661 ms 18980 KB Output is correct
2 Correct 652 ms 19060 KB Output is correct
3 Correct 648 ms 19352 KB Output is correct
4 Correct 639 ms 19092 KB Output is correct
5 Correct 697 ms 18980 KB Output is correct
6 Correct 659 ms 19240 KB Output is correct
7 Correct 681 ms 18972 KB Output is correct
8 Correct 624 ms 19040 KB Output is correct
9 Correct 665 ms 19024 KB Output is correct
10 Correct 658 ms 18936 KB Output is correct
11 Correct 639 ms 18936 KB Output is correct
12 Correct 665 ms 18960 KB Output is correct
13 Correct 651 ms 19016 KB Output is correct
14 Correct 637 ms 18900 KB Output is correct
15 Correct 647 ms 19144 KB Output is correct
16 Correct 696 ms 19080 KB Output is correct
17 Correct 695 ms 19188 KB Output is correct
18 Correct 652 ms 19032 KB Output is correct
19 Correct 660 ms 18872 KB Output is correct
20 Correct 681 ms 18872 KB Output is correct
21 Correct 688 ms 19088 KB Output is correct
22 Correct 719 ms 19724 KB Output is correct
23 Correct 764 ms 19448 KB Output is correct
24 Correct 717 ms 19864 KB Output is correct
25 Correct 741 ms 19696 KB Output is correct
26 Correct 686 ms 19456 KB Output is correct
27 Correct 755 ms 19556 KB Output is correct
28 Correct 687 ms 19712 KB Output is correct
29 Correct 666 ms 19836 KB Output is correct
30 Correct 672 ms 19644 KB Output is correct
31 Correct 685 ms 19704 KB Output is correct
32 Correct 672 ms 19680 KB Output is correct
33 Correct 700 ms 19660 KB Output is correct
34 Correct 695 ms 19848 KB Output is correct
35 Correct 715 ms 19544 KB Output is correct
36 Correct 723 ms 19792 KB Output is correct
37 Correct 706 ms 19552 KB Output is correct
38 Correct 642 ms 19484 KB Output is correct
39 Correct 672 ms 19696 KB Output is correct
40 Correct 722 ms 19964 KB Output is correct
41 Correct 685 ms 19452 KB Output is correct
42 Correct 702 ms 19888 KB Output is correct
43 Correct 741 ms 19868 KB Output is correct
44 Correct 747 ms 19900 KB Output is correct
45 Correct 723 ms 19756 KB Output is correct
46 Correct 754 ms 20200 KB Output is correct
47 Correct 707 ms 19768 KB Output is correct
48 Correct 722 ms 19916 KB Output is correct
49 Correct 689 ms 19688 KB Output is correct
50 Correct 703 ms 19936 KB Output is correct
51 Correct 708 ms 19840 KB Output is correct
52 Correct 731 ms 19984 KB Output is correct
53 Correct 737 ms 20040 KB Output is correct
54 Correct 720 ms 19876 KB Output is correct
55 Correct 738 ms 19748 KB Output is correct
56 Correct 752 ms 20096 KB Output is correct
57 Correct 735 ms 19680 KB Output is correct
58 Correct 710 ms 19912 KB Output is correct
59 Correct 741 ms 20128 KB Output is correct
60 Correct 706 ms 19804 KB Output is correct
61 Correct 736 ms 19764 KB Output is correct
62 Correct 733 ms 19912 KB Output is correct
63 Correct 717 ms 19756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 661 ms 18980 KB Output is correct
2 Correct 652 ms 19060 KB Output is correct
3 Correct 648 ms 19352 KB Output is correct
4 Correct 639 ms 19092 KB Output is correct
5 Correct 697 ms 18980 KB Output is correct
6 Correct 659 ms 19240 KB Output is correct
7 Correct 681 ms 18972 KB Output is correct
8 Correct 624 ms 19040 KB Output is correct
9 Correct 665 ms 19024 KB Output is correct
10 Correct 658 ms 18936 KB Output is correct
11 Correct 639 ms 18936 KB Output is correct
12 Correct 665 ms 18960 KB Output is correct
13 Correct 651 ms 19016 KB Output is correct
14 Correct 637 ms 18900 KB Output is correct
15 Correct 647 ms 19144 KB Output is correct
16 Correct 696 ms 19080 KB Output is correct
17 Correct 695 ms 19188 KB Output is correct
18 Correct 652 ms 19032 KB Output is correct
19 Correct 660 ms 18872 KB Output is correct
20 Correct 681 ms 18872 KB Output is correct
21 Correct 688 ms 19088 KB Output is correct
22 Correct 719 ms 19724 KB Output is correct
23 Correct 764 ms 19448 KB Output is correct
24 Correct 717 ms 19864 KB Output is correct
25 Correct 741 ms 19696 KB Output is correct
26 Correct 686 ms 19456 KB Output is correct
27 Correct 755 ms 19556 KB Output is correct
28 Correct 687 ms 19712 KB Output is correct
29 Correct 666 ms 19836 KB Output is correct
30 Correct 672 ms 19644 KB Output is correct
31 Correct 685 ms 19704 KB Output is correct
32 Correct 672 ms 19680 KB Output is correct
33 Correct 700 ms 19660 KB Output is correct
34 Correct 695 ms 19848 KB Output is correct
35 Correct 715 ms 19544 KB Output is correct
36 Correct 723 ms 19792 KB Output is correct
37 Correct 706 ms 19552 KB Output is correct
38 Correct 642 ms 19484 KB Output is correct
39 Correct 672 ms 19696 KB Output is correct
40 Correct 722 ms 19964 KB Output is correct
41 Correct 685 ms 19452 KB Output is correct
42 Correct 702 ms 19888 KB Output is correct
43 Correct 741 ms 19868 KB Output is correct
44 Correct 747 ms 19900 KB Output is correct
45 Correct 723 ms 19756 KB Output is correct
46 Correct 754 ms 20200 KB Output is correct
47 Correct 707 ms 19768 KB Output is correct
48 Correct 722 ms 19916 KB Output is correct
49 Correct 689 ms 19688 KB Output is correct
50 Correct 703 ms 19936 KB Output is correct
51 Correct 708 ms 19840 KB Output is correct
52 Correct 731 ms 19984 KB Output is correct
53 Correct 737 ms 20040 KB Output is correct
54 Correct 720 ms 19876 KB Output is correct
55 Correct 738 ms 19748 KB Output is correct
56 Correct 752 ms 20096 KB Output is correct
57 Correct 735 ms 19680 KB Output is correct
58 Correct 710 ms 19912 KB Output is correct
59 Correct 741 ms 20128 KB Output is correct
60 Correct 706 ms 19804 KB Output is correct
61 Correct 736 ms 19764 KB Output is correct
62 Correct 733 ms 19912 KB Output is correct
63 Correct 717 ms 19756 KB Output is correct
64 Execution timed out 1136 ms 19992 KB Time limit exceeded
65 Halted 0 ms 0 KB -