QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203464 | #2476. Pizzo Collectors | salvator_noster# | WA | 4ms | 24464kb | C++20 | 1.7kb | 2023-10-06 17:36:59 | 2023-10-06 17:37:00 |
Judging History
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][27],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[x][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;
}
ll t=n;
for(ll i=2;i<=n;++i)
if(n%i==0){
p=i,k=0;
while(n!=1)
n/=p,k++;
break;
}
n=t;
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",dp[tot][0]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 24464kb
input:
8 ?A?B?A?C 3 A 1 B 1000 C 100000
output:
2000000
result:
wrong answer 1st lines differ - expected: '1301004', found: '2000000'