이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std ;
const ll N = 3e5 ;
ll n, a, b, c, ans = 1e18 ;
string s ;
set<char> st ;
map<string, bool> mp ;
map<pair<string, string>, ll> dist ;
void deikstra()
{
for(ll ln = 1 ; ln <= n ; ln++)
for(ll j = 0 ; j <= s.size() - ln ; j++)
mp[s.substr(j, ln)] = 1 ;
set<pair<ll, pair<string, string>>> dxy ;
dxy.insert({1, {"", ""}}) ;
dist[{"", ""}] = 1 ;
while(dxy.size())
{
auto abu = *dxy.begin() ;
ll ds = abu.fi ;
string x = abu.se.fi, y = abu.se.se ;
dxy.erase(abu) ;
if(x == s)
ans = min(ans, ds) ;
if(ds > dist[{x, y}])
continue ;
for(char i = 'a' ; i <= 'z' ; i++)
if(mp[x + i] && (!dist[{x + i, y}] || dist[{x + i, y}] > ds + a))
{
dist[{x + i, y}] = ds + a ;
dxy.insert({ds + a, {x + i, y}}) ;
}
if(mp[x + y] && (!dist[{x + y, y}] || dist[{x + y, y}] > ds + c))
{
dist[{x + y, y}] = ds + c ;
dxy.insert({ds + c, {x + y, y}}) ;
}
if(mp[x] && (!dist[{"", x}] || dist[{"", x}] > ds + b))
{
dist[{"", x}] = ds + b ;
dxy.insert({ds + b, {"", x}}) ;
}
}
}
signed main()
{
ios_base::sync_with_stdio( 0 ) ;
cin.tie( 0 ) ;
cout.tie( 0 ) ;
cin >> n >> s >> a >> b >> c ;
if(n == 3)
{
for(char i : s)
st.insert(i) ;
cout << min(a * 3ll, (ll)st.size() * a + b + (3 - (ll)st.size() + 1) * c) ;
return 0 ;
}
deikstra() ;
cout << ans - 1 ;
return 0 ;
}
//30
//qazwsxedcrfvtgbyhnujmikolpaaaa
//1
//1
//1
컴파일 시 표준 에러 (stderr) 메시지
copypaste3.cpp: In function 'void deikstra()':
copypaste3.cpp:15:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
15 | for(ll j = 0 ; j <= s.size() - ln ; j++)
| ~~^~~~~~~~~~~~~~~~
# | 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... |