QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#792676#5051. Namomo SubsequenceLJY_ljyWA 2836ms775784kbC++112.9kb2024-11-29 12:53:552024-11-29 12:53:56

Judging History

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

  • [2024-11-29 12:53:56]
  • 评测
  • 测评结果:WA
  • 用时:2836ms
  • 内存:775784kb
  • [2024-11-29 12:53:55]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

const long long MOD = 998244353;
const long long MAXN = 1e6 + 10;
const long long MAXM = 70; // 'a' - 'z', 'A' - 'Z', '0' - '9' 

char str[MAXN];
int cnt[MAXN][MAXM], Sum[MAXN];
vector<int> Index[MAXM], sum[MAXM][MAXM];
vector<int> cnt2[MAXM], cnt3[MAXM][MAXM];

long long Tran(char c) {
	if ('a' <= c && c <= 'z') return c - 'a' + 1;
	if ('A' <= c && c <= 'Z') return c - 'A' + 27;
	return c - '0' + 53;
}

int main() {
	cin >> str + 1;
	long long n = strlen(str + 1);
	for (long long i = 1; i <= n; i++) {
		for (long long j = 1; j <= 62; j++) 
			cnt[i][j] = cnt[i - 1][j];
		cnt[i][Tran(str[i])] = cnt[i - 1][Tran(str[i])] + 1;
		Index[Tran(str[i])].push_back(i);
		Sum[i] = ( Sum[i - 1] + (cnt[i][Tran(str[i])] * (cnt[i][Tran(str[i])] - 1) / 2) % MOD - ((cnt[i][Tran(str[i])] - 1) * (cnt[i][Tran(str[i])] - 2) / 2) % MOD + MOD) % MOD;
 	}
	for (long long i = 1; i <= 62; i++) {
		long long A = 0;
		for (long long j = 0; j < Index[i].size(); j++) {
			A = (A + Index[i][j]) % MOD;
			cnt2[i].push_back(A);
		}
	}
	for (long long u = 1; u <= 62; u++) {
		for (long long i = 1; i <= 62; i++) {
			long long A = 0;
			for (long long j = 0; j < Index[i].size(); j++) {
				A = (A + cnt[Index[i][j]][u]) % MOD;
				cnt3[i][u].push_back(A);
			}
		}
	}
	for (long long i = 1; i <= 62; i++) {
		for (long long u = 1; u <= 62; u++) {
			long long ans = 0;
			if (!Index[u].empty()) {
				for (long long x = Index[u].size() - 1; x >= 0; x--) {
					ans = (ans + cnt[Index[u][x]][i]) % MOD;
					sum[u][i].push_back( ( ans - ( (Index[u].size() - x) * cnt[Index[u][x]][i]) % MOD + MOD) % MOD ); 
				}
			}
		}
	}
	long long Cnt = 0;
	for (long long i = 1; i <= 62; i++) {
		for (long long j = 0; j < Index[i].size(); j++) {
			long long I = Index[i][j];
			long long ans1 = ( ( (I - 1) * (I - 2) / 2) % MOD - Sum[I - 1] + MOD) % MOD; // ABC
			long long ans2 = 0, ans3 = 0;
			if (j > 0) {
				ans2 = (cnt2[i][j - 1] - cnt3[i][i][j - 1] + MOD) % MOD; //XCC;
				ans3 = (j * I - cnt2[i][j - 1] + 2 * MOD - (j * j) % MOD + ((j - 1) * j / 2) % MOD + MOD) % MOD; //CXC
			}
			long long ans4 = ( (j + 1) * j * (j - 1) / 6) % MOD; // CCC;
			long long A = (ans1 - ans2 - ans3 + ans4 + 2 * MOD) % MOD; // ABC
			for (long long u = 1; u <= 62; u++) {
				if (u != i) {
					long long ans5 = 0, ans6 = 0;
					if (cnt[I][u] >= 1) {
						ans5 = (cnt2[u][cnt[I][u] - 1] - cnt3[u][i][cnt[I][u] - 1] - cnt3[u][u][cnt[I][u] - 1] + 2 * MOD) % MOD; // XDC
				 		ans6 = ( (cnt[I][u] * I) % MOD - cnt2[u][cnt[I][u] - 1] - cnt[I][u] + 2 * MOD) % MOD; // DXC
				 	}
					long long B = (A - ans5 - ans6 + 2 * MOD) % MOD;
					if (cnt[n][u] != cnt[I][u]) {
						Cnt = ( Cnt + (B * sum[u][i][cnt[n][u] - cnt[I][u] - 1]) % MOD ) % MOD;
					}
				}
			} 
		}
	}
	printf("%lld\n", Cnt);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 6060kb

input:

wohaha

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5896kb

input:

momomo

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 1ms
memory: 7936kb

input:

gshfd1jkhaRaadfglkjerVcvuy0gf

output:

73

result:

ok 1 number(s): "73"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5932kb

input:

retiredMiFaFa0v0

output:

33

result:

ok 1 number(s): "33"

Test #5:

score: -100
Wrong Answer
time: 2836ms
memory: 775784kb

input:

bcdccccacccabdbdaddcabddbaccaaaaaabaccbbbcbbddabcbccabacdacbcbabccbcbddcdcbcaaadddddccdbabaabcbbcaaadadacdaadbdccbddddabcbaaddbcadadcbcbaaccacabdababaabdccadaddacdcacdaabbadadaddbbcccbcddaccaadbbcaaccccdcacbdbdddbaccaacbcaccaaabccdadddbaabdbcaaccacdcdcbcdddacbcacdbbbdccdddccccabdbacddacbaacbbcaccdcd...

output:

454219085

result:

wrong answer 1st numbers differ - expected: '587599316', found: '454219085'