QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#401622#944. Cubewordnhuang685#0 0ms0kbC++202.3kb2024-04-29 03:00:512024-04-29 03:00:52

Judging History

你现在查看的是最新测评结果

  • [2024-04-29 03:00:52]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-04-29 03:00:51]
  • 提交

answer

#include <bits/stdc++.h>

const int MOD = 998244353;
struct Mint {
  int val = 0;
  Mint(int v = 0) : val(v) {
    if (val <= -MOD || MOD <= val) {
      val %= MOD;
    }
    if (val < 0) {
      val += MOD;
    }
  }
  Mint &operator+=(Mint b) {
    val += b.val;
    if (val >= MOD) {
      val -= MOD;
    }
    return *this;
  }
  Mint &operator*=(Mint b) {
    val = (int)((int64_t)val * b.val % MOD);
    return *this;
  }
};
Mint operator+(Mint a, Mint b) { return a += b; }
Mint operator*(Mint a, Mint b) { return a *= b; }

const int MX = 16;
const int LEN = 10;

int main() {
  std::cin.tie(nullptr)->sync_with_stdio(false);

  int n;
  std::cin >> n;

  std::set<std::string> ss;
  std::vector freq(LEN + 1, std::vector(MX, std::vector<int>(MX)));
  for (int i = 0; i < n; ++i) {
    std::string s;
    std::cin >> s;
    int len = (int)s.size();
    int st = s[0] - 'a', en = s.back() - 'a';
    if (!ss.contains(s)) {
      freq[len][st][en]++;
    }
    ss.insert(s);
    std::string t = s;
    std::reverse(t.begin(), t.end());
    if (!ss.contains(t)) {
      freq[len][en][st]++;
    }
    ss.insert(t);
  }

  Mint ans = 0;
  for (int len = 3; len <= 10; ++len) {
    std::vector cur(MX,
                    std::vector(MX, std::vector(MX, std::vector<Mint>(MX))));
    std::vector pre = cur;
    for (int i = 0; i < MX; ++i) {
      for (int j = 0; j < MX; ++j) {
        pre[i][j][i][j] = freq[len][i][j];
      }
    }
    for (int i = 0; i < 4; ++i) {
      for (int a = 0; a < MX; ++a) {
        for (int b = 0; b < MX; ++b) {
          for (int c = 0; c < MX; ++c) {
            for (int d = 0; d < MX; ++d) {
              for (int e = 0; e < MX; ++e) {
                for (int f = 0; f < MX; ++f) {
                  cur[a][b][c][d] +=
                      freq[len][e][c] * freq[len][f][d] * pre[a][b][e][f];
                }
              }
              if (i < 3) {
                cur[a][b][c][d] *= freq[len][c][d];
              }
            }
          }
        }
      }
      std::swap(cur, pre);
      cur.assign(MX, std::vector(MX, std::vector(MX, std::vector<Mint>(MX))));
    }
    for (int i = 0; i < MX; ++i) {
      for (int j = 0; j < MX; ++j) {
        ans += pre[i][j][i][j];
      }
    }
  }
  std::cout << ans.val << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

100000
aaa
aaaa
aaaaa
aaaaaacb
aaaaabfdab
aaaaacaeba
aaaaacbec
aaaaacc
aaaaacdde
aaaaad
aaaaaef
aaaaafe
aaaab
aaaaba
aaaabac
aaaabcab
aaaabdcab
aaaabddec
aaaabeabd
aaaabeeacc
aaaac
aaaacaafee
aaaacabec
aaaacad
aaaacb
aaaacbcbba
aaaacbddbe
aaaacc
aaaacdda
aaaacdf
aaaacecdca
aaaacfceed
aaaacfdef
aaaad...

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%