QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#296932 | #7994. 勿蹖宠物 | Heltion# | WA | 10ms | 16144kb | C++20 | 3.5kb | 2024-01-03 19:57:00 | 2024-01-03 19:57:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(...) 417
#endif
using i64 = int64_t;
constexpr i64 mod = 1000000007;
void add(i64& x, i64 y) {
if ((x += y) >= mod) { x -= mod; }
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cout << fixed << setprecision(20);
int n, l;
cin >> n >> l;
vector<string> s(n);
string ss;
vector<int> begin(n);
for (int i = 0; i < n; i += 1) {
cin >> s[i];
begin[i] = ss.size();
ss += s[i];
}
debug(s);
int m = ss.size();
vector<int> id(m, -1);
for (int i = 0; i < n; i += 1) { id[begin[i]] = i; }
for (int j = 0; j < m; j += 1) {
if (id[j] == -1) { id[j] = id[j - 1]; }
}
vector<vector<int>> p((m + 1) * (m + 1));
for (int i = 0; i <= m; i += 1) {
for (int j = 0; j <= m; j += 1) {
if (i == m and j == m) {
for (int si = 0; si < n; si += 1) {
for (int sj = 0; sj < n; sj += 1) {
if (s[si][0] == s[sj].back()) {
int x = s[si].size() == 1 ? m : begin[si];
int y = s[sj].size() == 1 ? m : begin[sj] + ssize(s[sj]) - 1;
p[i * (m + 1) + j].push_back(x * (m + 1) + y);
}
}
}
continue;
}
if (i == m) {
int sj = id[j];
for (int si = 0; si < n; si += 1) {
if (s[si][0] == s[sj][j - begin[sj] - 1]) {
int x = s[si].size() == 1 ? m : begin[si];
int y = j - begin[j] - 1 == 0 ? m : j - 1;
p[i * (m + 1) + j].push_back(x * (m + 1) + y);
}
}
continue;
}
if (j == m) {
int si = id[i];
for (int sj = 0; sj < n; sj += 1) {
if (s[si][i - begin[si] + 1] == s[sj].back()) {
int x = i - begin[si] + 1 == ssize(s[si]) - 1 ? m : i + 1;
int y = s[sj].size() == 1 ? m : begin[sj] + ssize(s[sj]) - 1;
p[i * (m + 1) + j].push_back(x * (m + 1) + y);
}
}
continue;
}
int si = id[i];
int sj = id[j];
if (s[si][i - begin[si] + 1] == s[sj][j - begin[sj] - 1]) {
int x = i - begin[si] + 1 == ssize(s[si]) - 1 ? m : i + 1;
int y = j - begin[sj] - 1 == 0 ? m : j - 1;
p[i * (m + 1) + j].push_back(x * (m + 1) + y);
}
}
}
vector<i64> f((m + 1) * (m + 1));
if (l % 2) {
for (int i = 0; i < n; i += 1) {
for (int j = 0; j < ssize(s[i]); j += 1) {
int x = j == ssize(s[i]) - 1 ? m : begin[i] + j;
int y = j == 0 ? m : begin[i] + j;
f[x * (m + 1) + y] += 1;
}
}
} else {
for (int i = 0; i < n; i += 1) {
for (int j = 0; j < n; j += 1) {
if (s[i][0] == s[j].back()) {
int x = s[i].size() == 1 ? m : begin[i];
int y = s[j].size() == 1 ? m : begin[j] + ssize(s[j]) - 1;
f[x * (m + 1) + y] += 1;
}
}
}
for (int i = 0; i < n; i += 1) {
for (int j = 0; j + 1 < ssize(s[i]); j += 1) {
if (s[i][j] == s[i][j + 1]) {
int x = j + 1 == ssize(s[i]) - 1 ? m : begin[i] + j + 1;
int y = j == 0 ? m : begin[i];
f[x * (m + 1) + y] += 1;
}
}
}
}
debug(begin);
debug(f);
debug(p);
for (int i = 0; i < (l - 1) / 2; i += 1) {
vector<i64> g((m + 1) * (m + 1));
for (int i = 0; i < (m + 1) * (m + 1); i += 1) {
if (f[i]) {
for (int j : p[i]) { add(g[j], f[i]); }
}
}
f.swap(g);
}
cout << f.back();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3752kb
input:
7 9 cats eel eve evil lee olive stack
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
2 2 a aa
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
6 12 aa aab no on pets step
output:
43
result:
ok single line: '43'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
26 1000 a b c d e f g h i j k l m n o p q r s t u v w x y z
output:
710955506
result:
ok single line: '710955506'
Test #5:
score: -100
Wrong Answer
time: 10ms
memory: 16144kb
input:
33 18 zrkodfkhhkfdokrzo ytcbwrgyygrwbcty makgiybggbyigkamc aptmvovgccgvovmtpa yydxdzhhhhzdxdyy iadqfexoxacojythvk iagcfiwlaalwifcgai rtfzhddzzddhzftrm vkreigbdyxfiuvyqid mbcgnvrvvrvngcbmc lywbtspuyyupstbwyl bmjxalsyyslaxjmb jrbminaooanimbrj wwrajerkkrejarww grocaiqccqiacorg efvibgurrugbivfec ilyzrft...
output:
0
result:
wrong answer 1st lines differ - expected: '9', found: '0'