QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#168248#2476. Pizzo CollectorsLaStataleBlue#TL 0ms1760kbC++141.1kb2023-09-08 00:52:172023-09-08 00:52:17

Judging History

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

  • [2023-09-08 00:52:17]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:1760kb
  • [2023-09-08 00:52:17]
  • 提交

answer

#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
constexpr int MAXN = 100'005;

int n;
int prime;
char s[MAXN];
int pizzo[100];
int maxpizzo = 0;

ll util(const int x, const int d)
{
	if (d == n)
		return pizzo[s[x]];

	ll ans = 0;
	for (int i = 0; i < prime; i++)
		ans += util((x + i * d) % n, d * prime);

	const int elems = n / d;
	char cchar = 0;
	for (int i = 0; i < elems; i++)
	{
		const char c = s[(x + i * d) % n];
		if (c == '?')
			;
		else if (cchar == 0)
			cchar = c;
		else if (c != cchar)
			cchar = '!';
	}

	int val = 0;
	if (cchar == 0)
		val = maxpizzo;
	else if (cchar != '!')
		val = pizzo[cchar];

	int e = 0;
	for (int i = d; i <= n; i *= prime)
		e += elems;

	ll ans2 = (ll)val * e;
	return max(ans, ans2);
}

int main()
{
	int n, k;
	scanf("%d %s %d", &n, s, &k);
	::n = n;
	for (int i = 0; i < k; i++)
	{
		char c;
		int v;
		scanf(" %c %d ", &c, &v);
		pizzo[c] = v;
		maxpizzo = max(maxpizzo, v);
	}
	pizzo['?'] = maxpizzo;

	for (int i = 2; i < n; i++)
		if (n % i == 0)
		{
			prime = i;
			break;
		}

	printf("%lld\n", util(0, 1));
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 1748kb

input:

8
?A?B?A?C
3
A 1
B 1000
C 100000

output:

1301004

result:

ok single line: '1301004'

Test #2:

score: 0
Accepted
time: 0ms
memory: 1760kb

input:

4
ABCD
4
A 4
B 3
C 2
D 1

output:

10

result:

ok single line: '10'

Test #3:

score: -100
Time Limit Exceeded

input:

2
AB
2
A 1
B 2

output:


result: