ARC C TLE * 4 求调悬一关
查看原帖
ARC C TLE * 4 求调悬一关
512724
wl2009_pretty_girl楼主2025/6/22 22:08
#include <bits/stdc++.h>
using namespace std;

const int N = 5e5 + 5;
const int mod = 998244353;

int n, pw[N];

unordered_map<string, int> sz, cnt, f;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	pw[0] = 1;
	for (int i = 1; i < N; i++)
		pw[i] = pw[i - 1] * 2LL % mod;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		string s;
		cin >> s;
		cnt[s]++;
		for (int j = s.length() - 1; ~j; j--) {
			sz[s]++;
			string t1 = s, t2 = s;
			t1 += 'A', t2 += 'B';
			f[s] = (1LL * cnt[s] * pw[(sz[s] - cnt[s])] % mod + 1LL * f[t1] * f[t2] % mod) % mod;
			s.pop_back();
		}
		string t1 = "A", t2 = "B";
		f[s] = (1LL * cnt[s] * pw[(sz[s] - cnt[s])] % mod + 1LL * f[t1] * f[t2] % mod) % mod;
		cout << f[s] << '\n';
	}
	return 0;
}
2025/6/22 22:08
加载中...