답안 #1105746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105746 2024-10-27T15:16:47 Z mrwang Viruses (BOI20_viruses) C++14
0 / 100
693 ms 10064 KB
#include<bits/stdc++.h>
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxn=500;
const ll inf=1e18;
const ll mod=1e9+7;
struct TrieNode {
    int nxt[2], link;
};
const ll maxN=2e5;
vector<TrieNode> Trie;
vector<ll> adj[maxN];
ll  numNode, nTree, numQuery;
bool ed[maxn];
ll a[maxn];
void insertString(ll len) {
    int pt(0);
    for (int i=1;i<=len;i++) {
        int c=a[i];
        if(!Trie[pt].nxt[c]) {
            Trie[pt].nxt[c] = Trie.size();
            Trie.emplace_back();
        }
        pt = Trie[pt].nxt[c];
    }
    ed[pt]=true;
}

void buildAutomaton(void) {
    queue<int> qu;
    qu.push(0);
    while(qu.size()) {
        int v(qu.front()), u(Trie[v].link);
        qu.pop();
        for (int c = 0; c < 2; ++c) {
            if(Trie[v].nxt[c]) {
                Trie[Trie[v].nxt[c]].link = (v) ? Trie[u].nxt[c] : 0;
                qu.push(Trie[v].nxt[c]);
            } else {
                Trie[v].nxt[c] = Trie[u].nxt[c];
            }
        }
    }
}
ll z,m,n;
vector<pli>vec[maxn];
vector<ll>cc[maxn];
ll dp[300][55][55];
void solve()
{
    Trie.emplace_back();
    cin >> z >> n >> m;
    ll ct=z;
    for(int i=1;i<=n;i++)
    {
        ll x;
        cin >> x;
        ll k;
        cin >> k;
        vector<ll>bd;
        while(k--)
        {
            ll z;
            cin >> z;
            bd.pb(z);
        }
        if(bd.size()>=2)
        {
            ll u=x;
            for(int j=0;j+2<bd.size();j++)
            {
                ct++;
                vec[u].pb({bd[j],ct});
                u=ct;
            }
            vec[u].pb({bd[bd.size()-2],bd.back()});
        }
        else
        {
            cc[x].pb(bd[0]);
        }
    }
    for(int i=0;i<=50;i++) ed[i]=false;
    for(int i=1;i<=m;i++)
    {
        ll k;
        cin >> k;
        for(int j=1;j<=k;j++)
        {
            cin >> a[j];
        }
        insertString(k);
    }
    buildAutomaton();
    numNode=Trie.size();
    //cout << Trie.size()<<'\n';
    for(int i=0;i<=ct;i++)
    {
        for(int j=0;j<numNode;j++)
        {
            for(int k=0;k<numNode;k++)
            {
                dp[i][j][k]=inf;
            }
        }
    }
    for(int i=0;i<2;i++)
    {
        for(int u=0;u<numNode;u++)
        {
            ll luu=u;
            while(u!=0&&Trie[u].nxt[i]==0)
            {
                u=Trie[u].link;
            }
            //cout << Trie[u].nxt[i]<<'\n';
            if(ed[Trie[u].nxt[i]]==0)
            {
                dp[i][luu][Trie[u].nxt[i]]=1;
                //cout << i<<' '<<luu << '\n';
            }
            u=luu;
        }
    }
    for(int turn=1;turn<=n;turn++)
    {
        for(int k=0;k<numNode;k++)
        {
            for(int i=0;i<=ct;i++)
            {
                for(int j=0;j<numNode;j++)
                {
                    for(int q=0;q<numNode;q++)
                    {
                        for(auto zz:vec[i])
                        {
                            dp[i][j][q]=min(dp[i][j][q],dp[zz.fi][j][k]+dp[zz.se][k][q]);
                        }
                        for(auto zz:cc[i])
                        {
                            dp[i][j][q]=min(dp[i][j][q],dp[zz][j][q]);
                        }
                    }
                }
            }
        }
    }
    for(int i=2;i<=z-1;i++)
    {
        ll ans=inf;
        for(int j=0;j<numNode;j++)
        {
            ans=min(ans,dp[i][0][j]);
        }
        if(ans!=inf) cout << ans << '\n';
        else cout << 0 << '\n';
    }
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

Compilation message

Viruses.cpp: In function 'void solve()':
Viruses.cpp:75:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |             for(int j=0;j+2<bd.size();j++)
      |                         ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 10064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 10064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 693 ms 8016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 10064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 10064 KB Output isn't correct
2 Halted 0 ms 0 KB -