이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include<bits/stdc++.h>
#define int long long
#define quick ios::sync_with_stdio(0);cin.tie(0);
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define repd(x,a,b) for(int x=a;x>=b;x--)
#define lowbit(x) (x&-x)
#define sz(x) (int)(x.size())
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define mp make_pair
#define eb emplace_back
using namespace std;
typedef pair<int,int> pii;
void debug(){
cout<<"\n";
}
template <class T,class ... U >
void debug(T a, U ... b){
cout<<a<<" ",debug(b...);
}
const int N=25e2+7;
const int INF=1e18;
int p;
const int Mod=462'779'347'772'851;
int pref[N][N];
int dp[N][N];
string s;
void build(int n){
mt19937 rand(time(0));
p=rand()%26+29;
rep(i,1,n){
rep(j,i,n){
pref[i][j]=pref[i][j-1]*p%Mod+s[j-1]-'a'+2;
pref[i][j]%=Mod;
}
}
}
int q(int l,int r){
return pref[l][r];
}
int nxt[N][N];
signed main(){
quick
int n;
cin>>n;
cin>>s;
build(n);
int a,b,c;
cin>>a>>b>>c;
rep(i,1,n){
rep(j,i,n){
dp[i][j]=(j-i+1)*a;
}
}
rep(L,1,n){
map<int,int> m;
repd(i,n-L+1,1){
if(i+2*L-1<=n){
m[pref[i+L][i+2*L-1]]=i+L;
nxt[L][i]=m[pref[i][i+L-1]];
}
}
}
rep(L,1,n){
rep(l,1,n-L+1){
int r=l+L-1;
if(l<r) dp[l][r]=min({dp[l][r],dp[l][r-1]+a,dp[l+1][r]+a});
int px=nxt[L][l];
int pst=1;
while(px){
dp[l][px+L-1]=min(dp[l][px+L-1],(px-l-pst*L)*a+pst*c+b+c+dp[l][r]);
pst++;
px=nxt[L][px];
}
}
}
cout<<dp[1][n]<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |