Submission #501021

# Submission time Handle Problem Language Result Execution time Memory
501021 2022-01-02T08:11:46 Z InternetPerson10 Cubeword (CEOI19_cubeword) C++17
0 / 100
495 ms 9156 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++) {
        cout << x << '\n';
        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:72:32: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   72 |             if(words[i].size() == x) v.push_back(words[i]);
      |                ~~~~~~~~~~~~~~~~^~~~
cubeword.cpp:74: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]
   74 |         for(int i = 0; i < v.size(); i++) {
      |                        ~~^~~~~~~~~~
cubeword.cpp:77:23: warning: array subscript has type 'char' [-Wchar-subscripts]
   77 |             ct[v[i][0]][v[i][v[i].size()-1]]++;
      |                       ^
cubeword.cpp:77:44: warning: array subscript has type 'char' [-Wchar-subscripts]
   77 |             ct[v[i][0]][v[i][v[i].size()-1]]++;
      |                                            ^
cubeword.cpp:82:23: warning: array subscript has type 'char' [-Wchar-subscripts]
   82 |             ct[v[i][0]][v[i][v[i].size()-1]]++;
      |                       ^
cubeword.cpp:82:44: warning: array subscript has type 'char' [-Wchar-subscripts]
   82 |             ct[v[i][0]][v[i][v[i].size()-1]]++;
      |                                            ^
cubeword.cpp:84:26: 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 i = 0; i < s4.size(); i++) {
      |                        ~~^~~~~~~~~~~
cubeword.cpp:85:30: 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 j = i; j < s4.size(); j++) {
      |                            ~~^~~~~~~~~~~
cubeword.cpp:86:34: 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 k = j; k < s4.size(); k++) {
      |                                ~~^~~~~~~~~~~
cubeword.cpp:87:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |                     for(int l = 0; l < s4.size(); l++) {
      |                                    ~~^~~~~~~~~~~
cubeword.cpp:97:26: 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 i = 0; i < s4.size(); i++) {
      |                        ~~^~~~~~~~~~~
cubeword.cpp:98:30: 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 j = i; j < s4.size(); j++) {
      |                            ~~^~~~~~~~~~~
cubeword.cpp:99:34: 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 k = j; k < s4.size(); k++) {
      |                                ~~^~~~~~~~~~~
cubeword.cpp:100:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |                     for(int l = k; l < s4.size(); l++) {
      |                                    ~~^~~~~~~~~~~
cubeword.cpp:116: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]
  116 |         for(int i = 0; i < v.size(); i++) {
      |                        ~~^~~~~~~~~~
cubeword.cpp:117:23: warning: array subscript has type 'char' [-Wchar-subscripts]
  117 |             ct[v[i][0]][v[i][v[i].size()-1]] = 0;
      |                       ^
cubeword.cpp:117:44: warning: array subscript has type 'char' [-Wchar-subscripts]
  117 |             ct[v[i][0]][v[i][v[i].size()-1]] = 0;
      |                                            ^
cubeword.cpp:119:23: warning: array subscript has type 'char' [-Wchar-subscripts]
  119 |             ct[v[i][0]][v[i][v[i].size()-1]] = 0;
      |                       ^
cubeword.cpp:119:44: warning: array subscript has type 'char' [-Wchar-subscripts]
  119 |             ct[v[i][0]][v[i][v[i].size()-1]] = 0;
      |                                            ^
# Verdict Execution time Memory Grader output
1 Incorrect 495 ms 9156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 495 ms 9156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 495 ms 9156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 495 ms 9156 KB Output isn't correct
2 Halted 0 ms 0 KB -