이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> t3;
const int N=2505;
const int mod=1e9+7;
int n;
ll a,b,c;
string s;
ll dp[N][N];
bool vis[N][N];
ll hsh[N];
ll sub(int l,int r){
return (hsh[r]-hsh[l-1]+mod)%mod;
}
priority_queue<t3,vector<t3>,greater<t3>> pq;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> s >> a >> b >> c;
s=" "+s;
for(int i=1;i<=n;i++)hsh[i]=(hsh[i-1]*29%mod+s[i]-'a')%mod;
for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)dp[i][j]=1e18;
dp[0][0]=0;
pq.emplace(0,0,0);
while(!pq.empty()){
auto [d,i,j]=pq.top();
pq.pop();
if(vis[i][j])continue;
vis[i][j]=true;
if(i==n){
cout << d;
return 0;
}
if(i+1<=n&&d+a<dp[i+1][j]){
dp[i+1][j]=d+a;
pq.emplace(dp[i+1][j],i+1,j);
}
if(d+b<dp[0][i]){
dp[0][i]=d+b;
pq.emplace(dp[0][i],0,i);
}
if(i+j<=n&&sub(1,j)==sub(i+1,i+j)){
if(d+c<dp[i+j][j]){
dp[i+j][j]=d+c;
pq.emplace(dp[i+j][j],i+j,j);
}
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
copypaste3.cpp: In function 'int main()':
copypaste3.cpp:33:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
33 | auto [d,i,j]=pq.top();
| ^
# | 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... |