Submission #448808

# Submission time Handle Problem Language Result Execution time Memory
448808 2021-08-01T19:00:07 Z Ozy Viruses (BOI20_viruses) C++17
14 / 100
1 ms 332 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "

struct x {
    lli prin;
    vector<lli> des;
};

lli g,n,m,a,b,c,MAX,sum,INF;
lli res[102],dp[102];
vector<lli> gen[102],borr[102],anti[52];
vector<x> arr;

void DFS(lli act) {

    res[act] = -1;
    bool YES = false;
    lli sum = 0;

    for (auto h : gen[act]) {

        if (h == 0 || h == 1) {
            sum++;
            borr[act].push_back(h);
            continue;
        }

        if (res[h] == 0) DFS(h);

        if (res[h] < 0) {YES = true; break;}
        else {
            sum += res[h];
            for (auto k : borr[h]) borr[act].push_back(k);
        }
    }

    if (YES) {
        res[act] = -2;
        return;
    }
    //debug(act);
    //for (auto r : borr[act]) cout << r;
    //cout << endl;

    rep(i,1,m) {
        if (anti[i].size() > borr[act].size()) continue;

        rep(j,0,borr[act].size() - anti[i].size()) {
            bool igual = true;
            rep(k,j,j+anti[i].size()-1) {
                if (borr[act][k] != anti[i][k-j]) {igual = false;break;}
            }
            if (igual) {
                res[act] = -2;
                return;
            }
        }
    }

    res[act] = sum;
    if (borr[act].size() > MAX*2) {
        vector<lli> nuevo;
        rep(i,0,MAX-1) nuevo.push_back(borr[act][i]);
        nuevo.push_back(3);
        rep(i,borr[act].size()-MAX,borr[act].size()-1) nuevo.push_back(borr[act][i]);
        swap(nuevo, borr[act]);
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    INF = 1;
    rep(i,1,62) INF *= 2;
    cin >> g >> n >> m;

    if (m == 0) {

        x qw;
        rep(i,1,n) {
            cin >> a >> b;
            qw.prin = a;
            qw.des.clear();
            rep(j,1,b) {
                cin >> a;
                qw.des.push_back(a);
            }

            arr.push_back(qw);
        }

        dp[0] = dp[1] = 1;
        rep(i,2,g-1) dp[i] = INF;

        rep(j,1,n) {
            for (auto act : arr) {
                sum = 0;
                for (auto p : act.des) {
                    sum += dp[p];
                    if (sum > INF) sum=INF;
                }
                dp[act.prin] = min(dp[act.prin], sum);
            }

        }

        rep(i,2,g-1) {
            if (dp[i] < INF) cout << "NO " << dp[i] << "\n";
            else cout << "YES\n";
        }


    }
    else {
        rep(j,1,n) {
            cin >> a >> b;
            rep(i,1,b) {
                cin >> c;
                gen[a].push_back(c);
            }
        }

        MAX = 0;
        rep(i,1,m) {
            cin >> a;
            if (a > MAX) MAX = a;
            rep(j,1,a) {
                cin >> b;
                anti[i].push_back(b);
            }
        }

        rep(i,2,g-1) if(res[i] == 0) DFS(i);

        rep(i,2,g-1) {
            if (res[i] < 0) cout << "YES\n";
            else cout << "NO " << res[i] << "\n";
        }
    }
}

Compilation message

Viruses.cpp: In function 'void DFS(long long int)':
Viruses.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(i,a,b) for(int i = (a); i <= (b); i++)
      |                                       ^
Viruses.cpp:54:9: note: in expansion of macro 'rep'
   54 |         rep(j,0,borr[act].size() - anti[i].size()) {
      |         ^~~
Viruses.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(i,a,b) for(int i = (a); i <= (b); i++)
      |                                       ^
Viruses.cpp:56:13: note: in expansion of macro 'rep'
   56 |             rep(k,j,j+anti[i].size()-1) {
      |             ^~~
Viruses.cpp:67:26: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   67 |     if (borr[act].size() > MAX*2) {
      |         ~~~~~~~~~~~~~~~~~^~~~~~~
Viruses.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(i,a,b) for(int i = (a); i <= (b); i++)
      |                                       ^
Viruses.cpp:71:9: note: in expansion of macro 'rep'
   71 |         rep(i,borr[act].size()-MAX,borr[act].size()-1) nuevo.push_back(borr[act][i]);
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Incorrect 1 ms 204 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -