QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#211799 | #5051. Namomo Subsequence | bigJ | TL | 0ms | 3644kb | C++20 | 2.2kb | 2023-10-12 21:21:15 | 2023-10-12 21:21:16 |
Judging History
answer
#include <bits/stdc++.h>
#define dug(x) cerr << "死了吧小丑" << x << endl
using namespace std;
using i64 = long long;
template <class T> bool chmax(T& a, T b)
{
a > b ? (a = a) : (a = b);
return a == b;
}
template <class T> bool chmin(T& a, T b)
{
a > b ? (a = b) : (a = a);
return a == b;
}
const int M = 998244353, N = 1e6 + 10;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(15) << fixed;
int yi[128]{};
vector<char> tm(62);
for (int i = 0; i < 26; i++)
{
yi[i + 'A'] = i;
tm[i] = i + 'A';
yi[i + 'a'] = i + 26;
tm[i + 26] = i + 'a';
}
for (int i = 0; i < 10; i++)
{
yi[i + '0'] = i + 52;
tm[i + 52] = i + '0';
}
string a;
cin >> a;
int n = a.size();
vector<array<int, 62>> s(n + 1);
fill(s[0].begin(), s[0].end(), 0);
vector<vector<int>> mp(62);
for (int i = 1; i <= n; i++)
{
s[i] = s[i - 1];
s[i][yi[a[i - 1]]]++;
mp[yi[a[i - 1]]].push_back(i);
}
vector<int> sa(n + 1, 0);
for (int i = 1; i <= n; i++)
{
sa[i] = sa[i - 1];
sa[i] += s[i - 1][yi[a[i - 1]]];
sa[i] %= M;
}
i64 ans = 0;
for (int i = 0; i < 62; i++)
{
if (mp[i].size() <= 1)
continue;
for (int j = 0; j < 62; j++)
{
if (i == j) continue;
i64 f1 = 0, f2 = 0, dp1 = 0, dp2 = 0, res{};
f2 = s[n][j] - s[mp[i].back()][j];
for (int z = (int)mp[i].size() - 2; z >= 0; z--)
{
dp1 = (dp2 + i64(s[mp[i][z + 1]][j] - s[mp[i][z]][j]) * f2) % M;
f1 = (i64(s[n][j] - s[mp[i][z]][j]) + f2) % M;
i64 id = mp[i][z] - 1;
if (id == 1) continue;
res = 1LL * id * (id - 1) / 2;
i64 s1 = s[id][j], s2 = s[id][i];
res = (res + M - sa[id] - s1 * s2 % M - (s1 + s2) * (id - s1 - s2) % M) % M;
ans = (ans + res * dp1) % M;
std::swap(f1, f2), std::swap(dp1, dp2);
}
}
}
std::cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
input:
wohaha
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
momomo
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
gshfd1jkhaRaadfglkjerVcvuy0gf
output:
73
result:
ok 1 number(s): "73"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
retiredMiFaFa0v0
output:
33
result:
ok 1 number(s): "33"
Test #5:
score: -100
Time Limit Exceeded
input:
bcdccccacccabdbdaddcabddbaccaaaaaabaccbbbcbbddabcbccabacdacbcbabccbcbddcdcbcaaadddddccdbabaabcbbcaaadadacdaadbdccbddddabcbaaddbcadadcbcbaaccacabdababaabdccadaddacdcacdaabbadadaddbbcccbcddaccaadbbcaaccccdcacbdbdddbaccaacbcaccaaabccdadddbaabdbcaaccacdcdcbcdddacbcacdbbbdccdddccccabdbacddacbaacbbcaccdcd...