QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203474#2476. Pizzo Collectorssalvator_noster#RE 14ms59296kbC++201.6kb2023-10-06 17:44:112023-10-06 17:44:12

Judging History

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

  • [2023-10-06 17:44:12]
  • 评测
  • 测评结果:RE
  • 用时:14ms
  • 内存:59296kb
  • [2023-10-06 17:44:11]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll= long long ;
const ll M=2e6+10;
vector<ll>idx[22];
ll fa[M],n;
vector<ll>G[M];
ll p,k,dp[M][30],A[M],val[30];
ll tot,sz[M];
void build_tree(ll layer, ll nodeCnt) {
	if(nodeCnt==0)return ;
    idx[layer].resize(nodeCnt + 1);
    for (ll i = 1; i <= nodeCnt; i ++) idx[layer][i] = ++tot;
    if (layer) {
        for (ll i = 1; i <= nodeCnt; i ++) {
            for (ll j = i; j <= nodeCnt * p; j += nodeCnt) {
                fa[idx[layer - 1][j]] = idx[layer][i];
				G[idx[layer][i]].push_back(idx[layer-1][j]);
				//printf("%d -> %d\n",idx[layer][i],idx[layer-1][j]);
            }
        }
    }
    build_tree(layer + 1, nodeCnt / p);
}

void dfs(ll x){
	if(x<=n){
		if(A[x]){
			dp[x][A[x]]=val[A[x]];
			dp[x][0]=val[A[x]];
		}else{
			for(ll i=1;i<=26;++i){
				dp[x][i]=val[i];
				dp[x][0]=max(dp[x][0],val[i]);
			}
		}
		sz[x]=1;
	}else{
		for(ll y:G[x])dfs(y),sz[x]+=sz[y];
		for(ll i=0;i<=26;++i){
			bool fl=1;
			for(ll y:G[x]){
				dp[x][i]+=dp[y][i];
				if(dp[y][i]==0)fl=0;
			}
			if(fl)dp[x][i]+=sz[x]*val[i];
			else if(i)dp[x][i]=0;
		}
		for(ll i=0;i<=26;++i)
			dp[x][0]=max(dp[x][0],dp[x][i]);
	}
}
char s[M];
int  main(){
	scanf("%lld",&n);
	scanf("%s",s+1);
	for(ll i=1;i<=n;++i){
		if(s[i]>='A'&&s[i]<='Z')
			A[i]=s[i]-'A'+1;
	}
	for(ll i=2;i<=n;++i)
		if(n%i==0){
			p=i;
			break;
		}
	build_tree(0,n);	
	scanf("%lld",&k);
	for(ll i=1;i<=k;++i){
		ll v;
		char op[10];
		scanf("%s %lld",op,&v);
		val[(*op)-'A'+1]=v;
	}
	dfs(tot);
	printf("%lld\n",dp[tot][0]);
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 14ms
memory: 59276kb

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: 59296kb

input:

4
ABCD
4
A 4
B 3
C 2
D 1

output:

10

result:

ok single line: '10'

Test #3:

score: 0
Accepted
time: 3ms
memory: 59216kb

input:

2
AB
2
A 1
B 2

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 7ms
memory: 57172kb

input:

7
???????
3
A 1
B 3
C 2

output:

42

result:

ok single line: '42'

Test #5:

score: -100
Runtime Error

input:

1
?
26
A 1
B 2
C 3
D 4
E 5
F 6
G 7
H 8
I 9
J 10
K 11
L 12
M 13
N 14
O 15
P 16
Q 17
R 18
S 19
T 20
U 21
V 22
W 23
X 24
Y 25
Z 26

output:


result: