QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#753270 | #5051. Namomo Subsequence | _xqy_ | WA | 401ms | 564984kb | C++20 | 2.4kb | 2024-11-16 12:05:36 | 2024-11-16 12:05:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int mod = 998244353;
void solve() {
string s;
cin >> s;
int n = s.size();
s = " " + s;
auto get = [&] (char c) {
if (c >= 'a' && c <= 'z') return c - 'a';
else if (c >= 'A' && c <= 'Z') return c - 'A' + 26;
else return c - '0' + 52;
};
vector<int> t(n + 1);
for (int i = 1 ; i <= n ; ++i) {
t[i] = get(s[i]);
}
constexpr int M = 62;
vector<int> cnt(M) , sum(n + 1);
vector<vector<int>> pos(M);
vector<vector<int>> Pre(n + 1 , vector<int>(M));
vector<vector<int>> lst(n + 1 , vector<int>(M));
for (int i = 1 ; i <= n ; ++i) {
for (int j = 0 ; j < M ; ++j) {
Pre[i][j] = Pre[i - 1][j];
lst[i][j] = lst[i - 1][j];
}
Pre[i][t[i]] += 1;
pos[t[i]].emplace_back(i);
int a1 = 1LL * cnt[t[i]] * (cnt[t[i]] - 1) / 2 % mod;
cnt[t[i]] += 1;
int a2 = 1LL * cnt[t[i]] * (cnt[t[i]] - 1) / 2 % mod;
sum[i] = (1LL * sum[i - 1] + 1LL * a2 - 1LL * a1) % mod;
lst[i][t[i]] = (1LL * lst[i][t[i]] + 1LL * a2 - 1LL * a1) % mod;
}
LL ans = 0;
for (int i = 0 ; i < M ; ++i) {
if (pos[i].empty()) continue;
int m1 = pos[i].size() , k1 = m1 - 1;
vector<int> dp(m1);
int cnt_1_0 = 0;
for (int j = 0 ; j < M ; ++j) {
if (i == j || pos[j].empty() || pos[j].back() < pos[i][0]) continue;
int cnt_0_0 = 0 , cnt_0_1 = 0;
int m2 = pos[j].size() , k2 = m2 - 1;
while (k1 >= 0 || k2 >= 0) {
if (k1 >= 0 && k2 >= 0) {
if (pos[i][k1] > pos[j][k2]) {
cnt_1_0 += cnt_0_0;
if (cnt_1_0 >= mod) cnt_1_0 -= mod;
dp[k1] = cnt_0_1;
k1 --;
} else {
cnt_0_0 += 1 , cnt_0_1 += cnt_1_0;
if (cnt_0_1 >= mod) cnt_0_1 -= mod;
k2 --;
}
} else if (k1 >= 0) {
cnt_1_0 += cnt_0_0;
if (cnt_1_0 >= mod) cnt_1_0 -= mod;
dp[k1] = cnt_0_1;
k1 --;
} else {
break;
}
}
for (int k = 0 ; k < m1 ; ++k) {
int p = pos[i][k];
int a = ((p - 1 - Pre[p - 1][i]) % mod - Pre[p - 1][j]) % mod;
LL a1 = 1LL * (1LL * a * (a - 1) / 2 - 1LL * sum[p - 1] + 1LL * lst[p - 1][i] + 1LL * lst[p - 1][j]) * dp[k] % mod;
ans += a1;
if (ans >= mod) ans -= mod;
dp[k] = 0;
}
cnt_1_0 = 0 , k1 = m1 - 1;
}
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
input:
wohaha
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
momomo
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
gshfd1jkhaRaadfglkjerVcvuy0gf
output:
73
result:
ok 1 number(s): "73"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
retiredMiFaFa0v0
output:
33
result:
ok 1 number(s): "33"
Test #5:
score: -100
Wrong Answer
time: 401ms
memory: 564984kb
input:
bcdccccacccabdbdaddcabddbaccaaaaaabaccbbbcbbddabcbccabacdacbcbabccbcbddcdcbcaaadddddccdbabaabcbbcaaadadacdaadbdccbddddabcbaaddbcadadcbcbaaccacabdababaabdccadaddacdcacdaabbadadaddbbcccbcddaccaadbbcaaccccdcacbdbdddbaccaacbcaccaaabccdadddbaabdbcaaccacdcdcbcdddacbcacdbbbdccdddccccabdbacddacbaacbbcaccdcd...
output:
411074423
result:
wrong answer 1st numbers differ - expected: '587599316', found: '411074423'