QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#720226#6197. 太阳神的宴会NineSuns0 25ms144644kbC++142.8kb2024-11-07 11:17:222024-11-07 11:17:23

Judging History

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

  • [2024-11-07 11:17:23]
  • 评测
  • 测评结果:0
  • 用时:25ms
  • 内存:144644kb
  • [2024-11-07 11:17:22]
  • 提交

answer

#include <bits/stdc++.h>
#include<vector>
#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, k, id[N], cnt[N]; 
ll lv[26], f[N];   
struct node {
	unordered_map <int, int> ch; 
	int sz, len, fa; 
}v[N*2];
vector <int> pr; 
int las, tot, o[26]; 
inline int tr (int p, int k) { return k > v[p].sz ? 0 : k; }
void upd (int k) {
	int p = las, cur = ++tot; 
	v[cur].sz = v[p].sz+(tr(p, k) == 0); v[cur].len = v[p].len+1;
	las = cur;  
	while (!v[p].ch.count(tr(p, k))) {
		if (v[p].sz+(tr(p, k) == 0) < v[cur].sz) {
			int nc = ++tot; 
			v[nc].sz = v[p].sz+(tr(p, k) == 0); v[nc].len = v[p].len+1; 
			v[cur].fa = nc; cur = nc; 
		}
		v[p].ch[tr(p, k)] = cur; 
		p = v[p].fa; 
	}
	if (!p) return v[cur].fa = 1, void(); 
	int q = v[p].ch[tr(p, k)];
	if (v[q].len == v[p].len+1) return v[cur].fa = q, void(); 
	int cl = ++tot; v[cl] = v[q]; v[cl].len = v[p].len+1; v[q].fa = v[cur].fa = cl; 
	while (v[p].ch.count(tr(p, k)) && v[p].ch[tr(p, k)] == q) v[p].ch[tr(p, k)] = cl, p = v[p].fa; 
}

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; 
	ll s = k, ans = 0; 
	for (int i = 1;i <= n;i++) {
		while (tot) {
			v[tot].ch.clear(); 
			v[tot].sz = v[tot].len = v[tot].fa = 0; 
			tot--; 
		}
		las = tot = 1; 
		pr.clear(); memset(o, 0, sizeof o); 
		cin >> str;
		for (char j : str) {
			int x = j-'a'; 
			if (o[x]) {
				int id = 0; 
				for (int p = pr.size()-1;~p;p--) if (pr[p] == x) {
					id = p; break; 
				}
				upd(id+1); 
				pr.erase(pr.begin()+id); pr.push_back(x); 
			}
			else {
				upd(0); pr.push_back(x); o[x] = 1; 
			}
		}
		memset(f, 0, tot+1<<3); 
//		cout << s << " " << v[1].ch[0] << " " << tot << endl; 
		for (auto j : v[1].ch) f[j.se] = s; s = 0; 
		memset(cnt, 0, str.size()+1<<2); 
		for (int j = 2;j <= tot;j++) ++cnt[v[j].len]; 
		for (int j = 1;j <= str.size();j++) cnt[j] += cnt[j-1]; 
		for (int j = 2;j <= tot;j++) id[cnt[v[j].len]--] = j; 
		for (int J = 1;J < tot;J++) {
			int j = id[J]; (ans += lv[v[j].sz-1]*f[j]) %= mod; 
//			cout << "F:" << j << " " << f[j] << " " << v[j].sz << " :\n"; 
			for (auto p : v[j].ch) (f[p.se] += f[j]) %= mod; //, cout << p.se << " "; 
//			cout << endl; 
			if (v[j].ch.count(0)) (s += f[j]*lv[v[j].sz-1]%mod*(v[j].sz+1-v[j].ch.size())) %= mod; 
			else (s += f[j]*lv[v[j].sz-1]%mod*(k-v[j].ch.size())) %= mod;  
		}
//		cout << ans << endl; 
	}
	cout << (ans+mod+1)%mod; 
}

signed main () {
//	ios::sync_with_stdio(0);
//	cin.tie(0); cout.tie(0);
	int T = 1;
	while (T--) solve();
	return 0;
}


详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 25ms
memory: 144644kb

input:

1 2
bbbaabbbbbaabaabbababbabbaaabbaaabaaabbabbabbbaaabaababbbaabbbabaaaaabbbbbabbabbbbbabbaababaabbbababbbbabababbaabbbbabbbababbbaabaabbabbbbababaabbbbbabaaaaaabbbbbbbaaaaabbabbbbaaabaaabaababbbababaaaabbababaaabbababaabbbbaabababbbabbabaababbbabaababaaabaaabaaababaaaaabbaaaaabbabaababbababbbbbaaba...

output:

981239

result:

wrong answer 1st numbers differ - expected: '981227', found: '981239'

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%