QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#715184 | #6197. 太阳神的宴会 | NineSuns | 0 | 19ms | 100372kb | C++14 | 1.6kb | 2024-11-06 10:43:18 | 2024-11-06 10:43:19 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back
#define ull unsigned long long
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e6+5, mod = 998244353;
int n, tot, k, f[N], id[N];
map <int, int> ch[N];
vector <int> las[N];
ll lv[26];
int pre[26];
struct trie {
int rt;
ll sm, sn;
void ins (string s, int l) {
int p = rt;
memset(pre, -1, sizeof pre);
for (int i = l;i < s.size();i++) {
int x;
if (~pre[s[i]-'a']) {
x = i-pre[s[i]-'a'];
}
else x = 0;
pre[s[i]-'a'] = i;
if (ch[p].count(x)) p = ch[p][x];
else {
ch[p][x] = ++tot; p = tot;
}
}
}
void dfs (int p, int x) {
(sm += lv[x]) %= mod; (sn += lv[x]*(k-ch[p].size()))%mod;
// cout << p << " " << x << " " << endl;
for (auto i : ch[p]) dfs(i.se, x+(i.fi == 0));
}
}tr[N];
string str;
void solve () {
cin >> n >> k;
lv[0] = 1; for (int i = 1;i < k;i++) lv[i] = lv[i-1]*(k-i)%mod;
for (int i = 1;i <= n;i++) {
int las = tot;
tr[i].rt = ++tot;
cin >> str;
for (int j = 0;j < str.size();j++) tr[i].ins(str, j);
tr[i].dfs(tr[i].rt+1, 0);
cout << tot << endl;
}
// cout << "CASE\n";
ll s = k, ans = 0;
for (int i = 1;i <= n;i++) {
(ans += s*tr[i].sm) %= mod;
// cout << s << " " << tr[i].sm << endl;
s = s*tr[i].sn%mod;
}
cout << (ans+1)%mod;
}
signed main () {
// ios::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
int T = 1;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 19ms
memory: 100372kb
input:
1 2 bbbaabbbbbaabaabbababbabbaaabbaaabaaabbabbabbbaaabaababbbaabbbabaaaaabbbbbabbabbbbbabbaababaabbbababbbbabababbaabbbbabbbababbbaabaabbabbbbababaabbbbbabaaaaaabbbbbbbaaaaabbabbbbaaabaaabaababbbababaaaabbababaaabbababaabbbbaabababbbabbabaababbbabaababaaabaaabaaababaaaaabbaaaaabbabaababbababbbbbaaba...
output:
490614 981227
result:
wrong answer 1st numbers differ - expected: '981227', found: '490614'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #4:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%