QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203085 | #2476. Pizzo Collectors | PhantomThreshold# | WA | 1ms | 3900kb | C++14 | 2.4kb | 2023-10-06 15:20:10 | 2023-10-06 15:20:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100000;
const ll INF=1e2;
ll n;
ll p,k;
ll a[maxn+50];
ll w[30];
ll dp[20][maxn+50][27];
void dfs(ll dep,ll u,ll len){
// cerr << "dep,u,len : " << dep << " " << u << " " << len << endl;
if (dep==0){
if (a[u]==0){
dp[dep][u][0]=-INF;
for (int i=1;i<=26;i++) dp[dep][u][i]=w[i];
}
else{
for (int i=0;i<=26;i++) dp[dep][u][i]=-INF;
dp[dep][u][a[u]]=w[a[u]];
}
/*
cerr << "----------------" << endl;
cerr << "check---- dep,u,len : " << dep << " " << u << " " << len << endl;
for (int i=0;i<=3;i++){
cerr << dp[dep][u][i] << " ";
}
cerr << endl;
cerr << "----------------" << endl;
*/
return;
}
// for (int i=0;i<=26;i++) dp[dep][u][i]=-INF;
for (ll sel=0;sel<p;sel++){
ll v=u+n/len*sel;
dfs(dep-1,v,len/p);
ll mx=-INF;
for (int i=0;i<=26;i++){
mx=max(mx,dp[dep][u][0]+dp[dep-1][v][i]);
}
for (int i=0;i<=26;i++){
mx=max(mx,dp[dep][u][i]+dp[dep-1][v][0]);
}
vector<ll> lst(26+1+1);
lst[0]=lst[27]=-INF;
for (int i=1;i<=26;i++) lst[i]=dp[dep-1][v][i];
vector<ll> pre(26+1+1);
pre[0]=-INF;
for (int i=1;i<=26;i++) pre[i]=max(pre[i-1],lst[i]);
vector<ll> suf(26+1+1);
pre[27]=-INF;
for (int i=26;i>=1;i--) suf[i]=max(suf[i+1],lst[i]);
for (int i=1;i<=26;i++){
mx=max(mx,dp[dep][u][i]+max(pre[i-1],suf[i+1]));
}
dp[dep][u][0]=mx;
for (int i=1;i<=26;i++){
dp[dep][u][i]+=dp[dep-1][v][i];
// dp[dep][u][i]=max(dp[dep][u][i],-INF);
}
}
for (int i=1;i<=26;i++) dp[dep][u][i]+=len*w[i];
/*
cerr << "----------------" << endl;
cerr << "check---- dep,u,len : " << dep << " " << u << " " << len << endl;
for (int i=0;i<=3;i++){
cerr << dp[dep][u][i] << " ";
}
cerr << endl;
cerr << "----------------" << endl;
*/
}
int main(){
ios_base::sync_with_stdio(false);
cin >> n;
string str;
cin >> str;
for (int i=0;i<n;i++){
if (str[i]=='?') a[i]=0;
else a[i]=str[i]-'A'+1;
}
{
int Q;
cin >> Q;
for (;Q--;){
char ch;
ll v;
cin >> ch >> v;
w[ch-'A'+1]=v;
}
}
for (p=2;p<=n;p++){
k=0;
ll now=1;
while (now<n){
now=now*p;
k++;
}
if (now==n) break;
}
dfs(k,0,n);
ll ans=-INF;
for (int i=0;i<=26;i++) ans=max(ans,dp[k][0][i]);
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3900kb
input:
8 ?A?B?A?C 3 A 1 B 1000 C 100000
output:
2899700
result:
wrong answer 1st lines differ - expected: '1301004', found: '2899700'