답안 #1105775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105775 2024-10-27T17:36:00 Z mrwang Viruses (BOI20_viruses) C++14
100 / 100
225 ms 7764 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 val[maxn];
ll  numNode, nTree, numQuery;
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];
    }
    val[pt]=1;
}

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];
            }
        }
    }
}
void preDfs(int u,int p) {
    for (int it = 0; it < int(adj[u].size()); ++it) {
        int v(adj[u][it]);
        val[v]+=val[u];
        preDfs(v,u);
    }
}
void buildTree(void) {
    nTree = Trie.size();
    for (int i = 1; i < nTree; ++i)
        adj[Trie[i].link].push_back(i);
    preDfs(0,0);
}
ll z,m,n;
vector<pli>vec[maxn];
vector<ll>cc[maxn];
ll dp[2][55][55];
vector<vector<ll>>query;
vector<ll>id;
ll nxt[55][55],dis[105][55][55];
void solve()
{
    Trie.emplace_back();
    cin >> z >> n >> m;
    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);
        }
        query.pb(bd);
        id.pb(x);
    }
    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();
    buildTree();
    for(int i=0;i<=z;i++)
    {
        for(int j=0;j<numNode;j++)
        {
            for(int k=0;k<numNode;k++)
            {
                dis[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;
            }
            nxt[luu][i]=Trie[u].nxt[i];
            if(val[Trie[u].nxt[i]]==0)
            {
                dis[i][luu][Trie[u].nxt[i]]=1;
            }
            u=luu;
        }
    }
    for(int turn=0;turn<=n;turn++)
    {
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<numNode;j++)
            {
                for(int q=0;q<numNode;q++)
                {
                    dp[0][j][q]=dp[1][j][q]=inf;
                }
            }
            int p=0;
            for(int j=0;j<numNode;j++) dp[p][j][j]=0;
            for(auto x:query[i])
            {
                for(int j=0;j<numNode;j++)
                {
                    for(int q=0;q<numNode;q++)
                    {
                        if(dp[p][j][q]==inf) continue;
                        if(x<=1)
                        {
                            dp[p^1][j][nxt[q][x]]=min(dp[p^1][j][nxt[q][x]],dp[p][j][q]+dis[x][q][nxt[q][x]]);
                        }
                        for(int k=0;k<numNode;k++)
                        {
                            dp[p^1][j][k]=min(dp[p^1][j][k],dp[p][j][q]+dis[x][q][k]);
                        }
                        dp[p][j][q]=inf;
                    }
                }
                p^=1;
            }
            for(int j=0;j<numNode;j++)
            {
                for(int q=0;q<numNode;q++)
                {
                    dis[id[i]][j][q]=min(dis[id[i]][j][q],dp[p][j][q]);
                }
            }
        }
    }
    for(int i=2;i<=z-1;i++)
    {
        ll ans=inf;
        for(int j=0;j<numNode;j++)
        {
            ans=min(ans,dis[i][0][j]);
        }
        if(ans!=inf) cout <<"NO "<< ans << '\n';
        else cout << "YES" << '\n';
    }
}
int main()
{
    fastio
    //freopen("c.INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7504 KB Output is correct
2 Correct 3 ms 7504 KB Output is correct
3 Correct 3 ms 7504 KB Output is correct
4 Correct 2 ms 5456 KB Output is correct
5 Correct 2 ms 7504 KB Output is correct
6 Correct 2 ms 7504 KB Output is correct
7 Correct 2 ms 7504 KB Output is correct
8 Correct 2 ms 5456 KB Output is correct
9 Correct 2 ms 7504 KB Output is correct
10 Correct 2 ms 7504 KB Output is correct
11 Correct 2 ms 7608 KB Output is correct
12 Correct 2 ms 7504 KB Output is correct
13 Correct 2 ms 7504 KB Output is correct
14 Correct 2 ms 5624 KB Output is correct
15 Correct 2 ms 7504 KB Output is correct
16 Correct 2 ms 7568 KB Output is correct
17 Correct 3 ms 7504 KB Output is correct
18 Correct 3 ms 7504 KB Output is correct
19 Correct 3 ms 7504 KB Output is correct
20 Correct 2 ms 7504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7504 KB Output is correct
2 Correct 3 ms 7504 KB Output is correct
3 Correct 33 ms 7504 KB Output is correct
4 Correct 95 ms 7756 KB Output is correct
5 Correct 34 ms 7752 KB Output is correct
6 Correct 32 ms 7764 KB Output is correct
7 Correct 18 ms 7504 KB Output is correct
8 Correct 10 ms 7748 KB Output is correct
9 Correct 8 ms 7504 KB Output is correct
10 Correct 2 ms 5468 KB Output is correct
11 Correct 4 ms 7504 KB Output is correct
12 Correct 3 ms 7504 KB Output is correct
13 Correct 6 ms 7504 KB Output is correct
14 Correct 4 ms 7504 KB Output is correct
15 Correct 5 ms 7504 KB Output is correct
16 Correct 2 ms 5456 KB Output is correct
17 Correct 6 ms 7760 KB Output is correct
18 Correct 4 ms 7504 KB Output is correct
19 Correct 4 ms 7504 KB Output is correct
20 Correct 4 ms 7504 KB Output is correct
21 Correct 5 ms 7504 KB Output is correct
22 Correct 2 ms 7504 KB Output is correct
23 Correct 2 ms 5456 KB Output is correct
24 Correct 2 ms 5456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 7504 KB Output is correct
2 Correct 95 ms 7756 KB Output is correct
3 Correct 34 ms 7752 KB Output is correct
4 Correct 32 ms 7764 KB Output is correct
5 Correct 18 ms 7504 KB Output is correct
6 Correct 10 ms 7748 KB Output is correct
7 Correct 8 ms 7504 KB Output is correct
8 Correct 2 ms 7504 KB Output is correct
9 Correct 2 ms 7504 KB Output is correct
10 Correct 2 ms 7504 KB Output is correct
11 Correct 2 ms 7504 KB Output is correct
12 Correct 2 ms 7504 KB Output is correct
13 Correct 2 ms 7672 KB Output is correct
14 Correct 2 ms 7504 KB Output is correct
15 Correct 2 ms 7504 KB Output is correct
16 Correct 2 ms 7504 KB Output is correct
17 Correct 2 ms 7504 KB Output is correct
18 Correct 2 ms 7504 KB Output is correct
19 Correct 2 ms 7504 KB Output is correct
20 Correct 2 ms 7504 KB Output is correct
21 Correct 2 ms 7504 KB Output is correct
22 Correct 2 ms 7504 KB Output is correct
23 Correct 2 ms 7504 KB Output is correct
24 Correct 3 ms 7428 KB Output is correct
25 Correct 12 ms 5640 KB Output is correct
26 Correct 89 ms 7504 KB Output is correct
27 Correct 225 ms 7736 KB Output is correct
28 Correct 19 ms 7504 KB Output is correct
29 Correct 120 ms 7504 KB Output is correct
30 Correct 150 ms 7740 KB Output is correct
31 Correct 21 ms 7504 KB Output is correct
32 Correct 19 ms 7504 KB Output is correct
33 Correct 45 ms 7756 KB Output is correct
34 Correct 69 ms 7756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7504 KB Output is correct
2 Correct 3 ms 7504 KB Output is correct
3 Correct 3 ms 7504 KB Output is correct
4 Correct 2 ms 5456 KB Output is correct
5 Correct 2 ms 7504 KB Output is correct
6 Correct 2 ms 7504 KB Output is correct
7 Correct 2 ms 7504 KB Output is correct
8 Correct 2 ms 5456 KB Output is correct
9 Correct 2 ms 7504 KB Output is correct
10 Correct 2 ms 7504 KB Output is correct
11 Correct 2 ms 7608 KB Output is correct
12 Correct 2 ms 7504 KB Output is correct
13 Correct 2 ms 7504 KB Output is correct
14 Correct 2 ms 5624 KB Output is correct
15 Correct 2 ms 7504 KB Output is correct
16 Correct 2 ms 7568 KB Output is correct
17 Correct 3 ms 7504 KB Output is correct
18 Correct 3 ms 7504 KB Output is correct
19 Correct 3 ms 7504 KB Output is correct
20 Correct 2 ms 7504 KB Output is correct
21 Correct 2 ms 5468 KB Output is correct
22 Correct 2 ms 7504 KB Output is correct
23 Correct 2 ms 7504 KB Output is correct
24 Correct 2 ms 7504 KB Output is correct
25 Correct 2 ms 7504 KB Output is correct
26 Correct 2 ms 7504 KB Output is correct
27 Correct 2 ms 7672 KB Output is correct
28 Correct 2 ms 7504 KB Output is correct
29 Correct 2 ms 7504 KB Output is correct
30 Correct 2 ms 7504 KB Output is correct
31 Correct 2 ms 7504 KB Output is correct
32 Correct 2 ms 7504 KB Output is correct
33 Correct 2 ms 7504 KB Output is correct
34 Correct 2 ms 7504 KB Output is correct
35 Correct 2 ms 7504 KB Output is correct
36 Correct 2 ms 7504 KB Output is correct
37 Correct 2 ms 7504 KB Output is correct
38 Correct 3 ms 7428 KB Output is correct
39 Correct 2 ms 5456 KB Output is correct
40 Correct 3 ms 7504 KB Output is correct
41 Correct 2 ms 5456 KB Output is correct
42 Correct 3 ms 7504 KB Output is correct
43 Correct 4 ms 7504 KB Output is correct
44 Correct 3 ms 7504 KB Output is correct
45 Correct 3 ms 7504 KB Output is correct
46 Correct 3 ms 7672 KB Output is correct
47 Correct 3 ms 7504 KB Output is correct
48 Correct 3 ms 7504 KB Output is correct
49 Correct 4 ms 7568 KB Output is correct
50 Correct 3 ms 7504 KB Output is correct
51 Correct 3 ms 7504 KB Output is correct
52 Correct 3 ms 7504 KB Output is correct
53 Correct 3 ms 7516 KB Output is correct
54 Correct 3 ms 7672 KB Output is correct
55 Correct 3 ms 7504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7504 KB Output is correct
2 Correct 3 ms 7504 KB Output is correct
3 Correct 3 ms 7504 KB Output is correct
4 Correct 2 ms 5456 KB Output is correct
5 Correct 2 ms 7504 KB Output is correct
6 Correct 2 ms 7504 KB Output is correct
7 Correct 2 ms 7504 KB Output is correct
8 Correct 2 ms 5456 KB Output is correct
9 Correct 2 ms 7504 KB Output is correct
10 Correct 2 ms 7504 KB Output is correct
11 Correct 2 ms 7608 KB Output is correct
12 Correct 2 ms 7504 KB Output is correct
13 Correct 2 ms 7504 KB Output is correct
14 Correct 2 ms 5624 KB Output is correct
15 Correct 2 ms 7504 KB Output is correct
16 Correct 2 ms 7568 KB Output is correct
17 Correct 3 ms 7504 KB Output is correct
18 Correct 3 ms 7504 KB Output is correct
19 Correct 3 ms 7504 KB Output is correct
20 Correct 2 ms 7504 KB Output is correct
21 Correct 33 ms 7504 KB Output is correct
22 Correct 95 ms 7756 KB Output is correct
23 Correct 34 ms 7752 KB Output is correct
24 Correct 32 ms 7764 KB Output is correct
25 Correct 18 ms 7504 KB Output is correct
26 Correct 10 ms 7748 KB Output is correct
27 Correct 8 ms 7504 KB Output is correct
28 Correct 2 ms 5468 KB Output is correct
29 Correct 4 ms 7504 KB Output is correct
30 Correct 3 ms 7504 KB Output is correct
31 Correct 6 ms 7504 KB Output is correct
32 Correct 4 ms 7504 KB Output is correct
33 Correct 5 ms 7504 KB Output is correct
34 Correct 2 ms 5456 KB Output is correct
35 Correct 6 ms 7760 KB Output is correct
36 Correct 4 ms 7504 KB Output is correct
37 Correct 4 ms 7504 KB Output is correct
38 Correct 4 ms 7504 KB Output is correct
39 Correct 5 ms 7504 KB Output is correct
40 Correct 2 ms 7504 KB Output is correct
41 Correct 2 ms 5456 KB Output is correct
42 Correct 2 ms 5456 KB Output is correct
43 Correct 2 ms 7504 KB Output is correct
44 Correct 2 ms 7504 KB Output is correct
45 Correct 2 ms 7504 KB Output is correct
46 Correct 2 ms 7504 KB Output is correct
47 Correct 2 ms 7504 KB Output is correct
48 Correct 2 ms 7672 KB Output is correct
49 Correct 2 ms 7504 KB Output is correct
50 Correct 2 ms 7504 KB Output is correct
51 Correct 2 ms 7504 KB Output is correct
52 Correct 2 ms 7504 KB Output is correct
53 Correct 2 ms 7504 KB Output is correct
54 Correct 2 ms 7504 KB Output is correct
55 Correct 2 ms 7504 KB Output is correct
56 Correct 2 ms 7504 KB Output is correct
57 Correct 2 ms 7504 KB Output is correct
58 Correct 2 ms 7504 KB Output is correct
59 Correct 3 ms 7428 KB Output is correct
60 Correct 12 ms 5640 KB Output is correct
61 Correct 89 ms 7504 KB Output is correct
62 Correct 225 ms 7736 KB Output is correct
63 Correct 19 ms 7504 KB Output is correct
64 Correct 120 ms 7504 KB Output is correct
65 Correct 150 ms 7740 KB Output is correct
66 Correct 21 ms 7504 KB Output is correct
67 Correct 19 ms 7504 KB Output is correct
68 Correct 45 ms 7756 KB Output is correct
69 Correct 69 ms 7756 KB Output is correct
70 Correct 2 ms 5456 KB Output is correct
71 Correct 3 ms 7504 KB Output is correct
72 Correct 2 ms 5456 KB Output is correct
73 Correct 3 ms 7504 KB Output is correct
74 Correct 4 ms 7504 KB Output is correct
75 Correct 3 ms 7504 KB Output is correct
76 Correct 3 ms 7504 KB Output is correct
77 Correct 3 ms 7672 KB Output is correct
78 Correct 3 ms 7504 KB Output is correct
79 Correct 3 ms 7504 KB Output is correct
80 Correct 4 ms 7568 KB Output is correct
81 Correct 3 ms 7504 KB Output is correct
82 Correct 3 ms 7504 KB Output is correct
83 Correct 3 ms 7504 KB Output is correct
84 Correct 3 ms 7516 KB Output is correct
85 Correct 3 ms 7672 KB Output is correct
86 Correct 3 ms 7504 KB Output is correct
87 Correct 20 ms 7504 KB Output is correct
88 Correct 3 ms 7672 KB Output is correct
89 Correct 2 ms 7504 KB Output is correct
90 Correct 8 ms 7756 KB Output is correct
91 Correct 8 ms 7512 KB Output is correct
92 Correct 48 ms 7700 KB Output is correct
93 Correct 27 ms 7708 KB Output is correct
94 Correct 8 ms 7672 KB Output is correct
95 Correct 6 ms 7504 KB Output is correct
96 Correct 8 ms 7504 KB Output is correct
97 Correct 12 ms 7504 KB Output is correct
98 Correct 9 ms 7504 KB Output is correct
99 Correct 27 ms 7504 KB Output is correct
100 Correct 9 ms 7504 KB Output is correct
101 Correct 10 ms 7504 KB Output is correct
102 Correct 67 ms 7732 KB Output is correct
103 Correct 14 ms 7504 KB Output is correct
104 Correct 33 ms 7504 KB Output is correct
105 Correct 7 ms 7504 KB Output is correct
106 Correct 83 ms 7736 KB Output is correct
107 Correct 80 ms 7504 KB Output is correct