제출 #795217

#제출 시각아이디문제언어결과실행 시간메모리
795217vjudge1Copy and Paste 3 (JOI22_copypaste3)C++11
1 / 100
16 ms780 KiB
#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>, int> dist ;
void deikstra()
{
    for(int ln = 1 ; ln <= n ; ln++)
        for(int 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 ;
    }
    if(n <= 30)
    {
        deikstra() ;
        cout << ans - 1 ;
    }
    return 0 ;
}
//30
//qazwsxedcrfvtgbyhnujmikolpaaaa
//1
//1
//1

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

copypaste3.cpp: In function 'void deikstra()':
copypaste3.cpp:15:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         for(int j = 0 ; j <= s.size() - ln ; j++)
      |                         ~~^~~~~~~~~~~~~~~~
#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...