QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#203470#2476. Pizzo Collectorssalvator_noster#RE 2ms22252kbC++201.6kb2023-10-06 17:40:572023-10-06 17:40:57

Judging History

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

  • [2023-10-06 17:40:57]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:22252kb
  • [2023-10-06 17:40:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll= long long ;
const ll M=5e5+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;
}


详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 22252kb

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

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: 0ms
memory: 22040kb

input:

2
AB
2
A 1
B 2

output:

3

result:

ok single line: '3'

Test #4:

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

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: