제출 #714431

#제출 시각아이디문제언어결과실행 시간메모리
714431089487Copy and Paste 3 (JOI22_copypaste3)C++14
62 / 100
3082 ms335264 KiB
#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;
	map<pair<int,int>,vector<int> > mx;
	rep(i,1,n){
		rep(j,i,n){
			dp[i][j]=(j-i+1)*a;
			mx[mp(q(i,j),j-i+1)].eb(i);
		}
	}
	for(auto [_x,v]:mx){
		int L=_x.S;
		int n2=sz(v);
		int r=0;
		rep(i,0,n2-1){
			while(r<n2&&v[r]<=v[i]+L-1) r++;
			nxt[L][v[i]]=(r>=n2 ? 0 : v[r]);
		}
	}
	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;
}

컴파일 시 표준 에러 (stderr) 메시지

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:61:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |  for(auto [_x,v]:mx){
      |           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...