QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203507#2476. Pizzo CollectorsBoulevardDust#WA 0ms3952kbC++202.2kb2023-10-06 17:54:302023-10-06 17:54:30

Judging History

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

  • [2023-10-06 17:54:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3952kb
  • [2023-10-06 17:54:30]
  • 提交

answer

#include <iostream>
#include <cstdio>
#define mn 100005
#define ll long long

using namespace std;

int n, m, p, k, a[mn], v[30];
char s[mn];

int c[mn], cnt[mn], ban[mn];
ll ans, res[mn];

int main() {
	scanf("%d", &n);
	scanf("%s", s + 1);
	for(int i = 1; i <= n; ++i) {
		if(s[i] == '?') a[i] = 0;
		else a[i] = s[i] - 'A' + 1;
	}
	scanf("%d\n", &m);
	for(int i = 1; i <= m; ++i) {
		char c; int x;
		scanf("%c %d\n", &c, &x);
		v[c - 'A' + 1] = x;
	}
	for(p = 2; p <= n; ++p) {
		if(!(n % p)) break;
	}
	int x = n;
	k = 0;
	while(!(x % p)) ++k, x /= p;

	int m = 1;
	for(int i = 2; i <= 26; ++i) {
		if(v[i] > v[m]) m = i;
	}
	for(int i = 1; i <= n; ++i) {
		if(!a[i]) {
			c[i] = m, res[i] = v[m], cnt[i] = 1;
		}
		else {
			c[i] = a[i], res[i] = v[a[i]], cnt[i] = 0;
		}
		// printf("%d %lld\n", i, res[i]);
	}

	// i < (k?)
	for(int i = 1, u = n / p, s = 1; i <= k; ++i, u /= p, s *= p) {
		int uu = u * p;
		// printf("%d %d %d\n", i, u, s);
		for(int j = 1; j <= u; ++j) if(!ban[j]) {
			int same = 1, ssame = 1, cto = 0, cntsum = 0;
			ll ressum = 0;
			for(int l = j; l <= uu && !cto; l += u) {
				if(cnt[l] < s) {
					cto = c[l]; break;
				}
			}
			for(int l = j; l <= uu; l += u) {
				if(cnt[l] < s && c[l] != cto) {
					same = 0;
				}
				if(c[l] != c[j]) {
					ssame = 0;
				}
				cntsum += cnt[l], ressum += res[l];
			}
			// printf("%d %lld\n", cntsum, ressum);
			if(same) {
				// printf("p%lld %lld\n", 1ll * v[cto] * s * p * (i + 1) , ressum);
				if(1ll * v[cto] * s * p * (i + 1) > ressum) {
					c[j] = cto;
					res[j] = 1ll * v[cto] * s * p * (i + 1);
					// printf("j%d %lld\n", j, res[j]);
					cnt[j] = cntsum;
				}
				else {
					if(ssame) {
						res[j] = 1ll * v[c[j]] * s * p * (i + 1);
						cnt[j] = cntsum;
					}
					else {
						for(int l = j; l <= uu; l += u) {
							ban[l] = 1;
							ans += 1ll * v[c[l]] * s * i;
						}
					}
					// res[j] = ressum;
				}
			}
			else {
				for(int l = j; l <= uu; l += u) {
					ban[l] = 1;
					ans += 1ll * v[c[l]] * s * i;
				}
				// ans += ressum;
			}
		}
	}
	if(!ban[1]) ans = 1ll * v[c[1]] * n * (k + 1);
	printf("%lld", ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3952kb

input:

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

output:

1305016

result:

wrong answer 1st lines differ - expected: '1301004', found: '1305016'