답안 #1095920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095920 2024-10-03T11:58:04 Z yoav_s Cubeword (CEOI19_cubeword) C++17
84 / 100
677 ms 16624 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<vv> vvv;
typedef pair<ll, ll> p;
typedef vector<p> vp;
typedef vector<vp> vvp;
typedef vector<vvp> vvvp;
typedef pair<ll, p> tri;
typedef vector<tri> vtri;
typedef vector<vtri> vvtri;
typedef vector<vvtri> vvvtri;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;

#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()

const ll INF = 1e18;
const ll mod = 998244353;

bool isPalindrome(string &str)
{
    for (ll i = 0; i < str.size() / 2; i++) if (str[i] != str[str.size() - i - 1]) return false;
    return true;
}

ll combinations(ll a, ll b, ll c, ll d)
{
    if (a == d) return 1;
    if (a == c || b == d) return 4;
    if (a == b && c == d) return 6;
    if (a == b || c == d) return 12;
    return 24;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin >> n;
    vector<string> words(n);
    for (ll i = 0; i < n; i++) cin >> words[i];
    vector<char> characters;
    for (ll i=  'a'; i <= 'z'; i++) characters.pb(i);
    for (ll i = 'A'; i <= 'Z'; i++) characters.pb(i);
    //for (ll i = '0'; i <= '9'; i++) characters.pb(i);
    map<char, char> charShrink;
    for (ll i = 0; i < characters.size(); i++) charShrink[characters[i]] = i;
    for (ll i = 0; i < n; i++) for (ll j = 0; j < words[i].size(); j++) words[i][j] = charShrink[words[i][j]];
    vector<vector<string>> byLength(11);
    set<string> exists;
    for (ll i = 0; i < n; i++)
    {
        reverse(all(words[i]));
        if (exists.count(words[i]) > 0) continue;
        reverse(all(words[i]));
        byLength[words[i].size()].pb(words[i]);
        exists.insert(words[i]);
    }
    ll c = characters.size();
    ll res = 0;
    for (ll i = 3; i <= 10; i++)
    {
        vv amt(c, v(c, 0));
        for (ll j = 0; j < byLength[i].size(); j++)
        {
            amt[byLength[i][j][0]][byLength[i][j].back()]++;
            if (!isPalindrome(byLength[i][j])) amt[byLength[i][j].back()][byLength[i][j][0]]++;
        }
        vvv possibilities(c, vv(c, v(c)));
        for (ll i = 0; i < c; i++)
        {
            for (ll j = 0; j < c; j++)
            {
                for (ll k = 0; k < c; k++)
                {
                    for (ll l = 0; l < c; l++)
                    {
                        possibilities[i][j][k] += ((amt[i][l] * amt[j][l]) % mod) * amt[k][l];
                        possibilities[i][j][k] %= mod;
                    }
                }
            }
        }
        for (ll corner1 = 0; corner1 < c; corner1++)
        {
            for (ll corner2 = 0; corner2 < c; corner2++)
            {
                for (ll corner3 = 0; corner3 < c; corner3++)
                {
                    for (ll corner4 = 0; corner4 < c; corner4++)
                    {
                        ll cur = possibilities[corner1][corner2][corner3];
                        cur = (cur * possibilities[corner1][corner2][corner4]) % mod;
                        cur = (cur * possibilities[corner1][corner3][corner4]) % mod;
                        cur = (cur * possibilities[corner2][corner3][corner4]) % mod;
                        res = (res + cur) % mod;
                    }
                }
            }
        }
    }
    cout << res << "\n";
    return 0;
}

Compilation message

cubeword.cpp: In function 'bool isPalindrome(std::string&)':
cubeword.cpp:32:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (ll i = 0; i < str.size() / 2; i++) if (str[i] != str[str.size() - i - 1]) return false;
      |                    ~~^~~~~~~~~~~~~~~~
cubeword.cpp: In function 'int main()':
cubeword.cpp:57:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for (ll i = 0; i < characters.size(); i++) charShrink[characters[i]] = i;
      |                    ~~^~~~~~~~~~~~~~~~~~~
cubeword.cpp:58:49: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for (ll i = 0; i < n; i++) for (ll j = 0; j < words[i].size(); j++) words[i][j] = charShrink[words[i][j]];
      |                                               ~~^~~~~~~~~~~~~~~~~
cubeword.cpp:74:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         for (ll j = 0; j < byLength[i].size(); j++)
      |                        ~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 661 ms 14996 KB Output is correct
2 Correct 655 ms 15020 KB Output is correct
3 Correct 664 ms 15032 KB Output is correct
4 Correct 660 ms 15020 KB Output is correct
5 Correct 663 ms 15036 KB Output is correct
6 Correct 661 ms 15004 KB Output is correct
7 Correct 655 ms 15048 KB Output is correct
8 Correct 665 ms 15036 KB Output is correct
9 Correct 660 ms 15004 KB Output is correct
10 Correct 657 ms 15024 KB Output is correct
11 Correct 666 ms 15204 KB Output is correct
12 Correct 665 ms 15004 KB Output is correct
13 Correct 658 ms 15028 KB Output is correct
14 Correct 663 ms 15032 KB Output is correct
15 Correct 654 ms 15004 KB Output is correct
16 Correct 658 ms 15020 KB Output is correct
17 Correct 654 ms 15024 KB Output is correct
18 Correct 655 ms 15036 KB Output is correct
19 Correct 662 ms 15008 KB Output is correct
20 Correct 663 ms 15000 KB Output is correct
21 Correct 664 ms 15000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 661 ms 14996 KB Output is correct
2 Correct 655 ms 15020 KB Output is correct
3 Correct 664 ms 15032 KB Output is correct
4 Correct 660 ms 15020 KB Output is correct
5 Correct 663 ms 15036 KB Output is correct
6 Correct 661 ms 15004 KB Output is correct
7 Correct 655 ms 15048 KB Output is correct
8 Correct 665 ms 15036 KB Output is correct
9 Correct 660 ms 15004 KB Output is correct
10 Correct 657 ms 15024 KB Output is correct
11 Correct 666 ms 15204 KB Output is correct
12 Correct 665 ms 15004 KB Output is correct
13 Correct 658 ms 15028 KB Output is correct
14 Correct 663 ms 15032 KB Output is correct
15 Correct 654 ms 15004 KB Output is correct
16 Correct 658 ms 15020 KB Output is correct
17 Correct 654 ms 15024 KB Output is correct
18 Correct 655 ms 15036 KB Output is correct
19 Correct 662 ms 15008 KB Output is correct
20 Correct 663 ms 15000 KB Output is correct
21 Correct 664 ms 15000 KB Output is correct
22 Correct 658 ms 15500 KB Output is correct
23 Correct 657 ms 15480 KB Output is correct
24 Correct 655 ms 15496 KB Output is correct
25 Correct 668 ms 15480 KB Output is correct
26 Correct 660 ms 15480 KB Output is correct
27 Correct 675 ms 15424 KB Output is correct
28 Correct 663 ms 15492 KB Output is correct
29 Correct 673 ms 15484 KB Output is correct
30 Correct 660 ms 15724 KB Output is correct
31 Correct 659 ms 15484 KB Output is correct
32 Correct 658 ms 15476 KB Output is correct
33 Correct 667 ms 15484 KB Output is correct
34 Correct 660 ms 15488 KB Output is correct
35 Correct 675 ms 15496 KB Output is correct
36 Correct 666 ms 15480 KB Output is correct
37 Correct 665 ms 15484 KB Output is correct
38 Correct 656 ms 15480 KB Output is correct
39 Correct 666 ms 15440 KB Output is correct
40 Correct 666 ms 15484 KB Output is correct
41 Correct 672 ms 15492 KB Output is correct
42 Correct 667 ms 15484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 661 ms 14996 KB Output is correct
2 Correct 655 ms 15020 KB Output is correct
3 Correct 664 ms 15032 KB Output is correct
4 Correct 660 ms 15020 KB Output is correct
5 Correct 663 ms 15036 KB Output is correct
6 Correct 661 ms 15004 KB Output is correct
7 Correct 655 ms 15048 KB Output is correct
8 Correct 665 ms 15036 KB Output is correct
9 Correct 660 ms 15004 KB Output is correct
10 Correct 657 ms 15024 KB Output is correct
11 Correct 666 ms 15204 KB Output is correct
12 Correct 665 ms 15004 KB Output is correct
13 Correct 658 ms 15028 KB Output is correct
14 Correct 663 ms 15032 KB Output is correct
15 Correct 654 ms 15004 KB Output is correct
16 Correct 658 ms 15020 KB Output is correct
17 Correct 654 ms 15024 KB Output is correct
18 Correct 655 ms 15036 KB Output is correct
19 Correct 662 ms 15008 KB Output is correct
20 Correct 663 ms 15000 KB Output is correct
21 Correct 664 ms 15000 KB Output is correct
22 Correct 658 ms 15500 KB Output is correct
23 Correct 657 ms 15480 KB Output is correct
24 Correct 655 ms 15496 KB Output is correct
25 Correct 668 ms 15480 KB Output is correct
26 Correct 660 ms 15480 KB Output is correct
27 Correct 675 ms 15424 KB Output is correct
28 Correct 663 ms 15492 KB Output is correct
29 Correct 673 ms 15484 KB Output is correct
30 Correct 660 ms 15724 KB Output is correct
31 Correct 659 ms 15484 KB Output is correct
32 Correct 658 ms 15476 KB Output is correct
33 Correct 667 ms 15484 KB Output is correct
34 Correct 660 ms 15488 KB Output is correct
35 Correct 675 ms 15496 KB Output is correct
36 Correct 666 ms 15480 KB Output is correct
37 Correct 665 ms 15484 KB Output is correct
38 Correct 656 ms 15480 KB Output is correct
39 Correct 666 ms 15440 KB Output is correct
40 Correct 666 ms 15484 KB Output is correct
41 Correct 672 ms 15492 KB Output is correct
42 Correct 667 ms 15484 KB Output is correct
43 Correct 673 ms 15632 KB Output is correct
44 Correct 671 ms 16400 KB Output is correct
45 Correct 667 ms 16388 KB Output is correct
46 Correct 667 ms 16376 KB Output is correct
47 Correct 676 ms 16336 KB Output is correct
48 Correct 671 ms 16616 KB Output is correct
49 Correct 667 ms 16624 KB Output is correct
50 Correct 666 ms 16408 KB Output is correct
51 Correct 663 ms 16352 KB Output is correct
52 Correct 669 ms 16324 KB Output is correct
53 Correct 659 ms 16388 KB Output is correct
54 Correct 659 ms 16404 KB Output is correct
55 Correct 671 ms 16372 KB Output is correct
56 Correct 672 ms 16356 KB Output is correct
57 Correct 670 ms 16372 KB Output is correct
58 Correct 668 ms 16368 KB Output is correct
59 Correct 670 ms 16364 KB Output is correct
60 Correct 674 ms 16528 KB Output is correct
61 Correct 677 ms 16328 KB Output is correct
62 Correct 661 ms 16356 KB Output is correct
63 Correct 660 ms 16384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 661 ms 14996 KB Output is correct
2 Correct 655 ms 15020 KB Output is correct
3 Correct 664 ms 15032 KB Output is correct
4 Correct 660 ms 15020 KB Output is correct
5 Correct 663 ms 15036 KB Output is correct
6 Correct 661 ms 15004 KB Output is correct
7 Correct 655 ms 15048 KB Output is correct
8 Correct 665 ms 15036 KB Output is correct
9 Correct 660 ms 15004 KB Output is correct
10 Correct 657 ms 15024 KB Output is correct
11 Correct 666 ms 15204 KB Output is correct
12 Correct 665 ms 15004 KB Output is correct
13 Correct 658 ms 15028 KB Output is correct
14 Correct 663 ms 15032 KB Output is correct
15 Correct 654 ms 15004 KB Output is correct
16 Correct 658 ms 15020 KB Output is correct
17 Correct 654 ms 15024 KB Output is correct
18 Correct 655 ms 15036 KB Output is correct
19 Correct 662 ms 15008 KB Output is correct
20 Correct 663 ms 15000 KB Output is correct
21 Correct 664 ms 15000 KB Output is correct
22 Correct 658 ms 15500 KB Output is correct
23 Correct 657 ms 15480 KB Output is correct
24 Correct 655 ms 15496 KB Output is correct
25 Correct 668 ms 15480 KB Output is correct
26 Correct 660 ms 15480 KB Output is correct
27 Correct 675 ms 15424 KB Output is correct
28 Correct 663 ms 15492 KB Output is correct
29 Correct 673 ms 15484 KB Output is correct
30 Correct 660 ms 15724 KB Output is correct
31 Correct 659 ms 15484 KB Output is correct
32 Correct 658 ms 15476 KB Output is correct
33 Correct 667 ms 15484 KB Output is correct
34 Correct 660 ms 15488 KB Output is correct
35 Correct 675 ms 15496 KB Output is correct
36 Correct 666 ms 15480 KB Output is correct
37 Correct 665 ms 15484 KB Output is correct
38 Correct 656 ms 15480 KB Output is correct
39 Correct 666 ms 15440 KB Output is correct
40 Correct 666 ms 15484 KB Output is correct
41 Correct 672 ms 15492 KB Output is correct
42 Correct 667 ms 15484 KB Output is correct
43 Correct 673 ms 15632 KB Output is correct
44 Correct 671 ms 16400 KB Output is correct
45 Correct 667 ms 16388 KB Output is correct
46 Correct 667 ms 16376 KB Output is correct
47 Correct 676 ms 16336 KB Output is correct
48 Correct 671 ms 16616 KB Output is correct
49 Correct 667 ms 16624 KB Output is correct
50 Correct 666 ms 16408 KB Output is correct
51 Correct 663 ms 16352 KB Output is correct
52 Correct 669 ms 16324 KB Output is correct
53 Correct 659 ms 16388 KB Output is correct
54 Correct 659 ms 16404 KB Output is correct
55 Correct 671 ms 16372 KB Output is correct
56 Correct 672 ms 16356 KB Output is correct
57 Correct 670 ms 16372 KB Output is correct
58 Correct 668 ms 16368 KB Output is correct
59 Correct 670 ms 16364 KB Output is correct
60 Correct 674 ms 16528 KB Output is correct
61 Correct 677 ms 16328 KB Output is correct
62 Correct 661 ms 16356 KB Output is correct
63 Correct 660 ms 16384 KB Output is correct
64 Incorrect 662 ms 16224 KB Output isn't correct
65 Halted 0 ms 0 KB -