답안 #501022

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
501022 2022-01-02T08:12:00 Z InternetPerson10 Cubeword (CEOI19_cubeword) C++17
100 / 100
1010 ms 9328 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll MOD = 998244353;

ll ct[200][200];
int ch[4];

string s1 = "abcdef";
string s2 = "abcdefghijklmnop";
string s3 = "abcdefghijklmnopABCDEFGHIJKLMNOP";
string s4 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

unordered_map<int, ll> m;

ll conv(ll b, ll c, ll d) {
    return 40000LL * b + 200LL * c + d;
}

ll rec(int i) {
    if(i == 4) {
        ll ans = 1;
        ans *= m[conv(ch[0], ch[1], ch[2])];
        if(ans > MOD) ans %= MOD;
        ans *= m[conv(ch[0], ch[1], ch[3])];
        if(ans > MOD) ans %= MOD;
        ans *= m[conv(ch[0], ch[2], ch[3])];
        if(ans > MOD) ans %= MOD;
        ans *= m[conv(ch[1], ch[2], ch[3])];
        if(ans > MOD) ans %= MOD;
        if(ans) cout << ch[0] << ' ' << ch[1] << ' ' << ch[2] << ' ' << ch[3] << ' ' << ans << '\n';
        return ans;
    }
    ll ans = 0;
    int k = 0;
    if(i) {
        for(int j = 0; j < s4.size(); j++) {
            if(s4.at(j) == ch[i-1]) k = j;
        }
    }
    for(int j = k; j < s4.size(); j++) {
        ch[i] = (int)s4.at(j);
        ans += rec(i+1);
        if(ans > MOD) ans %= MOD;
    }
    return ans;
}

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

int main() {
    int n;
    cin >> n;
    vector<string> words(n), v;
    set<string> s;
    for(int i = 0; i < n; i++) {
        cin >> words[i];
    }
    ll ans = 0;
    for(int x = 3; x <= 10; x++) {
        for(int i = 0; i < n; i++) {
            if(words[i].size() == x) v.push_back(words[i]);
        }
        for(int i = 0; i < v.size(); i++) {
            if(s.count(v[i])) continue;
            s.insert(v[i]);
            ct[v[i][0]][v[i][v[i].size()-1]]++;
            // Other side
            reverse(v[i].begin(), v[i].end());
            if(s.count(v[i])) continue;
            s.insert(v[i]);
            ct[v[i][0]][v[i][v[i].size()-1]]++;
        }
        for(int i = 0; i < s4.size(); i++) {
            for(int j = i; j < s4.size(); j++) {
                for(int k = j; k < s4.size(); k++) {
                    for(int l = 0; l < s4.size(); l++) {
                        int w = s4[i], x = s4[j], y = s4[k], z = s4[l];
                        ll g = (ct[w][z] * ct[x][z] * ct[y][z]) % MOD;
                        if(g == 0) continue;
                        m[conv(w, x, y)] += g; 
                        m[conv(w, x, y)] %= MOD;
                    }
                }
            }
        }
        for(int i = 0; i < s4.size(); i++) {
            for(int j = i; j < s4.size(); j++) {
                for(int k = j; k < s4.size(); k++) {
                    for(int l = k; l < s4.size(); l++) {
                        ll tot = 1;
                        tot *= m[conv(s4[i], s4[j], s4[k])];
                        tot *= m[conv(s4[i], s4[j], s4[l])];
                        tot %= MOD;
                        tot *= m[conv(s4[i], s4[k], s4[l])];
                        tot %= MOD;
                        tot *= m[conv(s4[j], s4[k], s4[l])];
                        tot %= MOD;
                        tot *= perms(i, j, k, l);
                        ans += tot;
                        ans %= MOD;
                    }
                }
            }
        }
        for(int i = 0; i < v.size(); i++) {
            ct[v[i][0]][v[i][v[i].size()-1]] = 0;
            reverse(v[i].begin(), v[i].end());
            ct[v[i][0]][v[i][v[i].size()-1]] = 0;
        }
        vector<string>().swap(v);
        set<string>().swap(s);
        unordered_map<int, ll>().swap(m);
    }
    cout << ans << '\n';
}

Compilation message

cubeword.cpp: In function 'll rec(int)':
cubeword.cpp:39:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for(int j = 0; j < s4.size(); j++) {
      |                        ~~^~~~~~~~~~~
cubeword.cpp:43:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int j = k; j < s4.size(); j++) {
      |                    ~~^~~~~~~~~~~
cubeword.cpp: In function 'int main()':
cubeword.cpp:71:32: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   71 |             if(words[i].size() == x) v.push_back(words[i]);
      |                ~~~~~~~~~~~~~~~~^~~~
cubeword.cpp:73:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for(int i = 0; i < v.size(); i++) {
      |                        ~~^~~~~~~~~~
cubeword.cpp:76:23: warning: array subscript has type 'char' [-Wchar-subscripts]
   76 |             ct[v[i][0]][v[i][v[i].size()-1]]++;
      |                       ^
cubeword.cpp:76:44: warning: array subscript has type 'char' [-Wchar-subscripts]
   76 |             ct[v[i][0]][v[i][v[i].size()-1]]++;
      |                                            ^
cubeword.cpp:81:23: warning: array subscript has type 'char' [-Wchar-subscripts]
   81 |             ct[v[i][0]][v[i][v[i].size()-1]]++;
      |                       ^
cubeword.cpp:81:44: warning: array subscript has type 'char' [-Wchar-subscripts]
   81 |             ct[v[i][0]][v[i][v[i].size()-1]]++;
      |                                            ^
cubeword.cpp:83:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |         for(int i = 0; i < s4.size(); i++) {
      |                        ~~^~~~~~~~~~~
cubeword.cpp:84:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |             for(int j = i; j < s4.size(); j++) {
      |                            ~~^~~~~~~~~~~
cubeword.cpp:85:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |                 for(int k = j; k < s4.size(); k++) {
      |                                ~~^~~~~~~~~~~
cubeword.cpp:86:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |                     for(int l = 0; l < s4.size(); l++) {
      |                                    ~~^~~~~~~~~~~
cubeword.cpp:96:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |         for(int i = 0; i < s4.size(); i++) {
      |                        ~~^~~~~~~~~~~
cubeword.cpp:97:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |             for(int j = i; j < s4.size(); j++) {
      |                            ~~^~~~~~~~~~~
cubeword.cpp:98:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |                 for(int k = j; k < s4.size(); k++) {
      |                                ~~^~~~~~~~~~~
cubeword.cpp:99:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |                     for(int l = k; l < s4.size(); l++) {
      |                                    ~~^~~~~~~~~~~
cubeword.cpp:115:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |         for(int i = 0; i < v.size(); i++) {
      |                        ~~^~~~~~~~~~
cubeword.cpp:116:23: warning: array subscript has type 'char' [-Wchar-subscripts]
  116 |             ct[v[i][0]][v[i][v[i].size()-1]] = 0;
      |                       ^
cubeword.cpp:116:44: warning: array subscript has type 'char' [-Wchar-subscripts]
  116 |             ct[v[i][0]][v[i][v[i].size()-1]] = 0;
      |                                            ^
cubeword.cpp:118:23: warning: array subscript has type 'char' [-Wchar-subscripts]
  118 |             ct[v[i][0]][v[i][v[i].size()-1]] = 0;
      |                       ^
cubeword.cpp:118:44: warning: array subscript has type 'char' [-Wchar-subscripts]
  118 |             ct[v[i][0]][v[i][v[i].size()-1]] = 0;
      |                                            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 507 ms 9084 KB Output is correct
2 Correct 525 ms 9100 KB Output is correct
3 Correct 499 ms 9156 KB Output is correct
4 Correct 524 ms 9160 KB Output is correct
5 Correct 516 ms 9160 KB Output is correct
6 Correct 486 ms 9132 KB Output is correct
7 Correct 502 ms 9096 KB Output is correct
8 Correct 499 ms 9184 KB Output is correct
9 Correct 520 ms 9148 KB Output is correct
10 Correct 496 ms 9156 KB Output is correct
11 Correct 496 ms 9152 KB Output is correct
12 Correct 505 ms 9128 KB Output is correct
13 Correct 496 ms 9244 KB Output is correct
14 Correct 486 ms 9120 KB Output is correct
15 Correct 508 ms 9152 KB Output is correct
16 Correct 499 ms 9088 KB Output is correct
17 Correct 501 ms 9152 KB Output is correct
18 Correct 498 ms 9144 KB Output is correct
19 Correct 517 ms 9240 KB Output is correct
20 Correct 517 ms 9060 KB Output is correct
21 Correct 504 ms 9328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 507 ms 9084 KB Output is correct
2 Correct 525 ms 9100 KB Output is correct
3 Correct 499 ms 9156 KB Output is correct
4 Correct 524 ms 9160 KB Output is correct
5 Correct 516 ms 9160 KB Output is correct
6 Correct 486 ms 9132 KB Output is correct
7 Correct 502 ms 9096 KB Output is correct
8 Correct 499 ms 9184 KB Output is correct
9 Correct 520 ms 9148 KB Output is correct
10 Correct 496 ms 9156 KB Output is correct
11 Correct 496 ms 9152 KB Output is correct
12 Correct 505 ms 9128 KB Output is correct
13 Correct 496 ms 9244 KB Output is correct
14 Correct 486 ms 9120 KB Output is correct
15 Correct 508 ms 9152 KB Output is correct
16 Correct 499 ms 9088 KB Output is correct
17 Correct 501 ms 9152 KB Output is correct
18 Correct 498 ms 9144 KB Output is correct
19 Correct 517 ms 9240 KB Output is correct
20 Correct 517 ms 9060 KB Output is correct
21 Correct 504 ms 9328 KB Output is correct
22 Correct 532 ms 7836 KB Output is correct
23 Correct 519 ms 7880 KB Output is correct
24 Correct 517 ms 8172 KB Output is correct
25 Correct 529 ms 7736 KB Output is correct
26 Correct 560 ms 7764 KB Output is correct
27 Correct 503 ms 7820 KB Output is correct
28 Correct 507 ms 7856 KB Output is correct
29 Correct 484 ms 7980 KB Output is correct
30 Correct 520 ms 7856 KB Output is correct
31 Correct 503 ms 7856 KB Output is correct
32 Correct 514 ms 7816 KB Output is correct
33 Correct 500 ms 7820 KB Output is correct
34 Correct 510 ms 7864 KB Output is correct
35 Correct 559 ms 7860 KB Output is correct
36 Correct 526 ms 7736 KB Output is correct
37 Correct 488 ms 7764 KB Output is correct
38 Correct 535 ms 7860 KB Output is correct
39 Correct 490 ms 7864 KB Output is correct
40 Correct 506 ms 7836 KB Output is correct
41 Correct 523 ms 7868 KB Output is correct
42 Correct 519 ms 7852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 507 ms 9084 KB Output is correct
2 Correct 525 ms 9100 KB Output is correct
3 Correct 499 ms 9156 KB Output is correct
4 Correct 524 ms 9160 KB Output is correct
5 Correct 516 ms 9160 KB Output is correct
6 Correct 486 ms 9132 KB Output is correct
7 Correct 502 ms 9096 KB Output is correct
8 Correct 499 ms 9184 KB Output is correct
9 Correct 520 ms 9148 KB Output is correct
10 Correct 496 ms 9156 KB Output is correct
11 Correct 496 ms 9152 KB Output is correct
12 Correct 505 ms 9128 KB Output is correct
13 Correct 496 ms 9244 KB Output is correct
14 Correct 486 ms 9120 KB Output is correct
15 Correct 508 ms 9152 KB Output is correct
16 Correct 499 ms 9088 KB Output is correct
17 Correct 501 ms 9152 KB Output is correct
18 Correct 498 ms 9144 KB Output is correct
19 Correct 517 ms 9240 KB Output is correct
20 Correct 517 ms 9060 KB Output is correct
21 Correct 504 ms 9328 KB Output is correct
22 Correct 532 ms 7836 KB Output is correct
23 Correct 519 ms 7880 KB Output is correct
24 Correct 517 ms 8172 KB Output is correct
25 Correct 529 ms 7736 KB Output is correct
26 Correct 560 ms 7764 KB Output is correct
27 Correct 503 ms 7820 KB Output is correct
28 Correct 507 ms 7856 KB Output is correct
29 Correct 484 ms 7980 KB Output is correct
30 Correct 520 ms 7856 KB Output is correct
31 Correct 503 ms 7856 KB Output is correct
32 Correct 514 ms 7816 KB Output is correct
33 Correct 500 ms 7820 KB Output is correct
34 Correct 510 ms 7864 KB Output is correct
35 Correct 559 ms 7860 KB Output is correct
36 Correct 526 ms 7736 KB Output is correct
37 Correct 488 ms 7764 KB Output is correct
38 Correct 535 ms 7860 KB Output is correct
39 Correct 490 ms 7864 KB Output is correct
40 Correct 506 ms 7836 KB Output is correct
41 Correct 523 ms 7868 KB Output is correct
42 Correct 519 ms 7852 KB Output is correct
43 Correct 534 ms 7704 KB Output is correct
44 Correct 529 ms 7696 KB Output is correct
45 Correct 532 ms 7700 KB Output is correct
46 Correct 530 ms 7628 KB Output is correct
47 Correct 518 ms 7716 KB Output is correct
48 Correct 523 ms 7716 KB Output is correct
49 Correct 542 ms 7596 KB Output is correct
50 Correct 556 ms 7716 KB Output is correct
51 Correct 515 ms 7780 KB Output is correct
52 Correct 524 ms 7724 KB Output is correct
53 Correct 511 ms 7700 KB Output is correct
54 Correct 533 ms 7692 KB Output is correct
55 Correct 543 ms 7648 KB Output is correct
56 Correct 529 ms 7692 KB Output is correct
57 Correct 533 ms 7680 KB Output is correct
58 Correct 537 ms 7712 KB Output is correct
59 Correct 526 ms 7696 KB Output is correct
60 Correct 523 ms 7724 KB Output is correct
61 Correct 522 ms 7636 KB Output is correct
62 Correct 544 ms 7768 KB Output is correct
63 Correct 535 ms 7688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 507 ms 9084 KB Output is correct
2 Correct 525 ms 9100 KB Output is correct
3 Correct 499 ms 9156 KB Output is correct
4 Correct 524 ms 9160 KB Output is correct
5 Correct 516 ms 9160 KB Output is correct
6 Correct 486 ms 9132 KB Output is correct
7 Correct 502 ms 9096 KB Output is correct
8 Correct 499 ms 9184 KB Output is correct
9 Correct 520 ms 9148 KB Output is correct
10 Correct 496 ms 9156 KB Output is correct
11 Correct 496 ms 9152 KB Output is correct
12 Correct 505 ms 9128 KB Output is correct
13 Correct 496 ms 9244 KB Output is correct
14 Correct 486 ms 9120 KB Output is correct
15 Correct 508 ms 9152 KB Output is correct
16 Correct 499 ms 9088 KB Output is correct
17 Correct 501 ms 9152 KB Output is correct
18 Correct 498 ms 9144 KB Output is correct
19 Correct 517 ms 9240 KB Output is correct
20 Correct 517 ms 9060 KB Output is correct
21 Correct 504 ms 9328 KB Output is correct
22 Correct 532 ms 7836 KB Output is correct
23 Correct 519 ms 7880 KB Output is correct
24 Correct 517 ms 8172 KB Output is correct
25 Correct 529 ms 7736 KB Output is correct
26 Correct 560 ms 7764 KB Output is correct
27 Correct 503 ms 7820 KB Output is correct
28 Correct 507 ms 7856 KB Output is correct
29 Correct 484 ms 7980 KB Output is correct
30 Correct 520 ms 7856 KB Output is correct
31 Correct 503 ms 7856 KB Output is correct
32 Correct 514 ms 7816 KB Output is correct
33 Correct 500 ms 7820 KB Output is correct
34 Correct 510 ms 7864 KB Output is correct
35 Correct 559 ms 7860 KB Output is correct
36 Correct 526 ms 7736 KB Output is correct
37 Correct 488 ms 7764 KB Output is correct
38 Correct 535 ms 7860 KB Output is correct
39 Correct 490 ms 7864 KB Output is correct
40 Correct 506 ms 7836 KB Output is correct
41 Correct 523 ms 7868 KB Output is correct
42 Correct 519 ms 7852 KB Output is correct
43 Correct 534 ms 7704 KB Output is correct
44 Correct 529 ms 7696 KB Output is correct
45 Correct 532 ms 7700 KB Output is correct
46 Correct 530 ms 7628 KB Output is correct
47 Correct 518 ms 7716 KB Output is correct
48 Correct 523 ms 7716 KB Output is correct
49 Correct 542 ms 7596 KB Output is correct
50 Correct 556 ms 7716 KB Output is correct
51 Correct 515 ms 7780 KB Output is correct
52 Correct 524 ms 7724 KB Output is correct
53 Correct 511 ms 7700 KB Output is correct
54 Correct 533 ms 7692 KB Output is correct
55 Correct 543 ms 7648 KB Output is correct
56 Correct 529 ms 7692 KB Output is correct
57 Correct 533 ms 7680 KB Output is correct
58 Correct 537 ms 7712 KB Output is correct
59 Correct 526 ms 7696 KB Output is correct
60 Correct 523 ms 7724 KB Output is correct
61 Correct 522 ms 7636 KB Output is correct
62 Correct 544 ms 7768 KB Output is correct
63 Correct 535 ms 7688 KB Output is correct
64 Correct 998 ms 7712 KB Output is correct
65 Correct 983 ms 8448 KB Output is correct
66 Correct 982 ms 8312 KB Output is correct
67 Correct 977 ms 8312 KB Output is correct
68 Correct 975 ms 8308 KB Output is correct
69 Correct 976 ms 8412 KB Output is correct
70 Correct 980 ms 8444 KB Output is correct
71 Correct 1000 ms 8444 KB Output is correct
72 Correct 982 ms 8392 KB Output is correct
73 Correct 973 ms 8392 KB Output is correct
74 Correct 990 ms 8380 KB Output is correct
75 Correct 991 ms 8424 KB Output is correct
76 Correct 1010 ms 8392 KB Output is correct
77 Correct 976 ms 8384 KB Output is correct
78 Correct 994 ms 8312 KB Output is correct
79 Correct 980 ms 8300 KB Output is correct
80 Correct 981 ms 8384 KB Output is correct
81 Correct 981 ms 8392 KB Output is correct
82 Correct 980 ms 8580 KB Output is correct
83 Correct 977 ms 8508 KB Output is correct
84 Correct 986 ms 8316 KB Output is correct