Submission #1095974

# Submission time Handle Problem Language Result Execution time Memory
1095974 2024-10-03T13:57:48 Z mohammad86 Bitaro’s Party (JOI18_bitaro) C++17
14 / 100
663 ms 217116 KB
// https://oj.uz/problem/view/JOI18_bitaro

#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5 + 100;
const int sqrtn = 250;
const int inf = 1e9;
int n, m, q;
vector<int> adj[maxn];
vector<int> readj[maxn];
vector<pii> fv[maxn];
int pointer[maxn];
int dis[maxn];
bool mark[maxn];
bool mark2[maxn];

int main () {
    ios_base::sync_with_stdio(false);

    cin >> n >> m >> q;

    for (int i = 1; i <= m; i++) {
        int s, e;
        cin >> s >> e;
        adj[s].push_back(e);
        readj[e].push_back(s);
    }

    vector<int> tmp1;

    for (int i = 1; i <= n; i++) {
        tmp1.clear();
        for (int w = 0; w <= sqrtn; w++) {
            int maximum = -1;
            int v = -1;
            int nv = -1;
            for (int j : readj[i]) {
                if (fv[j].size() > pointer[j] && !mark2[fv[j][pointer[j]].second]) {
                    if (fv[j][pointer[j]].first +1 > maximum) {
                        maximum = fv[j][pointer[j]].first +1;
                        v = fv[j][pointer[j]].second;
                        nv = j;
                    }
                }
            }
            if (v == -1)
                break;
            mark2[v] = true;
            tmp1.push_back(v);
            fv[i].push_back({maximum, v});
            pointer[nv]++;
        }
        for (int j : readj[i])
            pointer[j] = 0;
        for (int j : tmp1) {
            mark2[j] = false;
        }
        fv[i].push_back({0, i});
    }

    vector<int> tmp;

    for (int _ = 1; _ <= q; _++) {
        int t, y;
        cin >> t >> y;
        tmp.clear();
        for (int i = 0; i < y; i++) {
            int c;
            cin >> c;
            tmp.push_back(c);
            mark[c] = true;
        }
        if (y < sqrtn) {
            bool is_find = false;
            for (pii i : fv[t]) {
                if (!mark[i.second]) {
                    cout << i.first << endl;
                    is_find = true;
                    break;
                }
            }
            if (!is_find) {
                cout << -1 << endl;
            }
        } else {
            fill(dis, dis+n+2, -1 * inf);

            dis[t] = 0;

            for (int i = t; i >= 1; i--) {
                for (int j : readj[i]) {
                    dis[j] = max(dis[j], dis[i]+1);
                }
            }

            int ans = -1;
            for (int i= 1; i <= t; i++) {
                if (!mark[i]) {
                    ans = max(ans, dis[i]);
                }
            }
            cout << ans << endl;
        }
        for (int i = 0; i < y; i++) {
            mark[tmp[i]] = false;
        }
    }
}

Compilation message

bitaro.cpp: In function 'int main()':
bitaro.cpp:40:34: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |                 if (fv[j].size() > pointer[j] && !mark2[fv[j][pointer[j]].second]) {
      |                     ~~~~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7256 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 4 ms 7516 KB Output is correct
5 Correct 4 ms 7772 KB Output is correct
6 Correct 4 ms 7516 KB Output is correct
7 Correct 4 ms 7516 KB Output is correct
8 Correct 8 ms 9304 KB Output is correct
9 Correct 8 ms 9304 KB Output is correct
10 Correct 9 ms 9308 KB Output is correct
11 Correct 7 ms 8540 KB Output is correct
12 Correct 4 ms 7772 KB Output is correct
13 Correct 6 ms 8540 KB Output is correct
14 Correct 6 ms 8612 KB Output is correct
15 Correct 4 ms 7772 KB Output is correct
16 Correct 6 ms 8540 KB Output is correct
17 Correct 5 ms 8284 KB Output is correct
18 Correct 5 ms 7696 KB Output is correct
19 Correct 5 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7256 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 4 ms 7516 KB Output is correct
5 Correct 4 ms 7772 KB Output is correct
6 Correct 4 ms 7516 KB Output is correct
7 Correct 4 ms 7516 KB Output is correct
8 Correct 8 ms 9304 KB Output is correct
9 Correct 8 ms 9304 KB Output is correct
10 Correct 9 ms 9308 KB Output is correct
11 Correct 7 ms 8540 KB Output is correct
12 Correct 4 ms 7772 KB Output is correct
13 Correct 6 ms 8540 KB Output is correct
14 Correct 6 ms 8612 KB Output is correct
15 Correct 4 ms 7772 KB Output is correct
16 Correct 6 ms 8540 KB Output is correct
17 Correct 5 ms 8284 KB Output is correct
18 Correct 5 ms 7696 KB Output is correct
19 Correct 5 ms 8284 KB Output is correct
20 Correct 121 ms 11604 KB Output is correct
21 Correct 117 ms 11600 KB Output is correct
22 Correct 118 ms 11600 KB Output is correct
23 Correct 110 ms 11344 KB Output is correct
24 Correct 138 ms 51924 KB Output is correct
25 Correct 143 ms 50384 KB Output is correct
26 Correct 143 ms 47584 KB Output is correct
27 Correct 438 ms 217040 KB Output is correct
28 Correct 441 ms 217116 KB Output is correct
29 Correct 446 ms 217040 KB Output is correct
30 Correct 437 ms 215512 KB Output is correct
31 Correct 313 ms 151244 KB Output is correct
32 Correct 438 ms 215764 KB Output is correct
33 Correct 346 ms 138700 KB Output is correct
34 Correct 295 ms 119544 KB Output is correct
35 Correct 312 ms 137856 KB Output is correct
36 Correct 392 ms 176156 KB Output is correct
37 Correct 292 ms 121044 KB Output is correct
38 Correct 377 ms 176148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7256 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 4 ms 7516 KB Output is correct
5 Correct 4 ms 7772 KB Output is correct
6 Correct 4 ms 7516 KB Output is correct
7 Correct 4 ms 7516 KB Output is correct
8 Correct 8 ms 9304 KB Output is correct
9 Correct 8 ms 9304 KB Output is correct
10 Correct 9 ms 9308 KB Output is correct
11 Correct 7 ms 8540 KB Output is correct
12 Correct 4 ms 7772 KB Output is correct
13 Correct 6 ms 8540 KB Output is correct
14 Correct 6 ms 8612 KB Output is correct
15 Correct 4 ms 7772 KB Output is correct
16 Correct 6 ms 8540 KB Output is correct
17 Correct 5 ms 8284 KB Output is correct
18 Correct 5 ms 7696 KB Output is correct
19 Correct 5 ms 8284 KB Output is correct
20 Correct 121 ms 11604 KB Output is correct
21 Correct 117 ms 11600 KB Output is correct
22 Correct 118 ms 11600 KB Output is correct
23 Correct 110 ms 11344 KB Output is correct
24 Correct 138 ms 51924 KB Output is correct
25 Correct 143 ms 50384 KB Output is correct
26 Correct 143 ms 47584 KB Output is correct
27 Correct 438 ms 217040 KB Output is correct
28 Correct 441 ms 217116 KB Output is correct
29 Correct 446 ms 217040 KB Output is correct
30 Correct 437 ms 215512 KB Output is correct
31 Correct 313 ms 151244 KB Output is correct
32 Correct 438 ms 215764 KB Output is correct
33 Correct 346 ms 138700 KB Output is correct
34 Correct 295 ms 119544 KB Output is correct
35 Correct 312 ms 137856 KB Output is correct
36 Correct 392 ms 176156 KB Output is correct
37 Correct 292 ms 121044 KB Output is correct
38 Correct 377 ms 176148 KB Output is correct
39 Correct 255 ms 48140 KB Output is correct
40 Correct 130 ms 43404 KB Output is correct
41 Correct 138 ms 54240 KB Output is correct
42 Correct 178 ms 51364 KB Output is correct
43 Correct 139 ms 51028 KB Output is correct
44 Correct 223 ms 12112 KB Output is correct
45 Correct 123 ms 11860 KB Output is correct
46 Correct 113 ms 11596 KB Output is correct
47 Correct 121 ms 11604 KB Output is correct
48 Correct 113 ms 11600 KB Output is correct
49 Correct 663 ms 216780 KB Output is correct
50 Correct 592 ms 216148 KB Output is correct
51 Correct 236 ms 12116 KB Output is correct
52 Correct 122 ms 11600 KB Output is correct
53 Incorrect 525 ms 175184 KB Output isn't correct
54 Halted 0 ms 0 KB -