Submission #1095989

# Submission time Handle Problem Language Result Execution time Memory
1095989 2024-10-03T14:15:43 Z mohammad86 Bitaro’s Party (JOI18_bitaro) C++17
100 / 100
975 ms 327508 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];
bool mark3[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 (int(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});
    }*/

    for (int i = 1; i <= n; i++) {
        fv[i].push_back(pii(0, i));
        for (auto &j : readj[i]) {
            vector<pii> nxt = fv[j];
            vector<pii> prv = fv[i];
            fv[i].clear();
            int ptr = 0;
            for (auto &k : nxt) {
                k.first++;
                while (ptr < prv.size() && prv[ptr].first >= k.first) {
                    if (mark3[prv[ptr].second]) {
                        ptr++;
                        continue;
                    }
                    mark3[prv[ptr].second] = 1;
                    fv[i].push_back(prv[ptr++]);
                }
                if (mark3[k.second]) {
                    continue;
                }
                mark3[k.second] = 1;
                fv[i].push_back(k);
            }
            while (ptr < prv.size()) {
                if (mark3[prv[ptr].second]) {
                    ptr++;
                    continue;
                }
                mark3[prv[ptr].second] = 1;
                fv[i].push_back(prv[ptr++]);
            }
            for (auto &i : nxt) {
                mark3[i.second] = 0;
            }
            for (auto &i : prv) {
                mark3[i.second] = 0;
            }
            while (fv[i].size() > sqrtn) {
                fv[i].pop_back();
            }

        }
    }

    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 : tmp) {
            mark[i] = false;
        }
    }
}

Compilation message

bitaro.cpp: In function 'int main()':
bitaro.cpp:72:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |                 while (ptr < prv.size() && prv[ptr].first >= k.first) {
      |                        ~~~~^~~~~~~~~~~~
bitaro.cpp:86:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |             while (ptr < prv.size()) {
      |                    ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7256 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Correct 5 ms 8028 KB Output is correct
6 Correct 4 ms 8028 KB Output is correct
7 Correct 4 ms 7852 KB Output is correct
8 Correct 8 ms 9560 KB Output is correct
9 Correct 8 ms 9560 KB Output is correct
10 Correct 8 ms 9560 KB Output is correct
11 Correct 8 ms 9308 KB Output is correct
12 Correct 7 ms 8796 KB Output is correct
13 Correct 8 ms 9304 KB Output is correct
14 Correct 7 ms 8796 KB Output is correct
15 Correct 7 ms 8284 KB Output is correct
16 Correct 6 ms 8920 KB Output is correct
17 Correct 8 ms 8796 KB Output is correct
18 Correct 6 ms 8464 KB Output is correct
19 Correct 7 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7256 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Correct 5 ms 8028 KB Output is correct
6 Correct 4 ms 8028 KB Output is correct
7 Correct 4 ms 7852 KB Output is correct
8 Correct 8 ms 9560 KB Output is correct
9 Correct 8 ms 9560 KB Output is correct
10 Correct 8 ms 9560 KB Output is correct
11 Correct 8 ms 9308 KB Output is correct
12 Correct 7 ms 8796 KB Output is correct
13 Correct 8 ms 9304 KB Output is correct
14 Correct 7 ms 8796 KB Output is correct
15 Correct 7 ms 8284 KB Output is correct
16 Correct 6 ms 8920 KB Output is correct
17 Correct 8 ms 8796 KB Output is correct
18 Correct 6 ms 8464 KB Output is correct
19 Correct 7 ms 9052 KB Output is correct
20 Correct 292 ms 13136 KB Output is correct
21 Correct 281 ms 13140 KB Output is correct
22 Correct 287 ms 13240 KB Output is correct
23 Correct 334 ms 13496 KB Output is correct
24 Correct 502 ms 229324 KB Output is correct
25 Correct 503 ms 237456 KB Output is correct
26 Correct 521 ms 237016 KB Output is correct
27 Correct 571 ms 219604 KB Output is correct
28 Correct 520 ms 219340 KB Output is correct
29 Correct 494 ms 219236 KB Output is correct
30 Correct 534 ms 219304 KB Output is correct
31 Correct 618 ms 311760 KB Output is correct
32 Correct 549 ms 219048 KB Output is correct
33 Correct 426 ms 158924 KB Output is correct
34 Correct 458 ms 183184 KB Output is correct
35 Correct 427 ms 158932 KB Output is correct
36 Correct 492 ms 184100 KB Output is correct
37 Correct 525 ms 252628 KB Output is correct
38 Correct 459 ms 183756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7256 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Correct 5 ms 8028 KB Output is correct
6 Correct 4 ms 8028 KB Output is correct
7 Correct 4 ms 7852 KB Output is correct
8 Correct 8 ms 9560 KB Output is correct
9 Correct 8 ms 9560 KB Output is correct
10 Correct 8 ms 9560 KB Output is correct
11 Correct 8 ms 9308 KB Output is correct
12 Correct 7 ms 8796 KB Output is correct
13 Correct 8 ms 9304 KB Output is correct
14 Correct 7 ms 8796 KB Output is correct
15 Correct 7 ms 8284 KB Output is correct
16 Correct 6 ms 8920 KB Output is correct
17 Correct 8 ms 8796 KB Output is correct
18 Correct 6 ms 8464 KB Output is correct
19 Correct 7 ms 9052 KB Output is correct
20 Correct 292 ms 13136 KB Output is correct
21 Correct 281 ms 13140 KB Output is correct
22 Correct 287 ms 13240 KB Output is correct
23 Correct 334 ms 13496 KB Output is correct
24 Correct 502 ms 229324 KB Output is correct
25 Correct 503 ms 237456 KB Output is correct
26 Correct 521 ms 237016 KB Output is correct
27 Correct 571 ms 219604 KB Output is correct
28 Correct 520 ms 219340 KB Output is correct
29 Correct 494 ms 219236 KB Output is correct
30 Correct 534 ms 219304 KB Output is correct
31 Correct 618 ms 311760 KB Output is correct
32 Correct 549 ms 219048 KB Output is correct
33 Correct 426 ms 158924 KB Output is correct
34 Correct 458 ms 183184 KB Output is correct
35 Correct 427 ms 158932 KB Output is correct
36 Correct 492 ms 184100 KB Output is correct
37 Correct 525 ms 252628 KB Output is correct
38 Correct 459 ms 183756 KB Output is correct
39 Correct 630 ms 232204 KB Output is correct
40 Correct 497 ms 233040 KB Output is correct
41 Correct 496 ms 234836 KB Output is correct
42 Correct 582 ms 234144 KB Output is correct
43 Correct 517 ms 233296 KB Output is correct
44 Correct 431 ms 14428 KB Output is correct
45 Correct 305 ms 13796 KB Output is correct
46 Correct 291 ms 13532 KB Output is correct
47 Correct 296 ms 13300 KB Output is correct
48 Correct 292 ms 13092 KB Output is correct
49 Correct 760 ms 219984 KB Output is correct
50 Correct 621 ms 218704 KB Output is correct
51 Correct 401 ms 14280 KB Output is correct
52 Correct 282 ms 13392 KB Output is correct
53 Correct 594 ms 185152 KB Output is correct
54 Correct 654 ms 252860 KB Output is correct
55 Correct 489 ms 182024 KB Output is correct
56 Correct 558 ms 251728 KB Output is correct
57 Correct 412 ms 14416 KB Output is correct
58 Correct 398 ms 14372 KB Output is correct
59 Correct 281 ms 13392 KB Output is correct
60 Correct 284 ms 13396 KB Output is correct
61 Correct 686 ms 219072 KB Output is correct
62 Correct 504 ms 185976 KB Output is correct
63 Correct 555 ms 250960 KB Output is correct
64 Correct 830 ms 219152 KB Output is correct
65 Correct 685 ms 183888 KB Output is correct
66 Correct 734 ms 253628 KB Output is correct
67 Correct 755 ms 218748 KB Output is correct
68 Correct 478 ms 183200 KB Output is correct
69 Correct 520 ms 248988 KB Output is correct
70 Correct 653 ms 219216 KB Output is correct
71 Correct 504 ms 183124 KB Output is correct
72 Correct 550 ms 253216 KB Output is correct
73 Correct 767 ms 219136 KB Output is correct
74 Correct 518 ms 183596 KB Output is correct
75 Correct 599 ms 245332 KB Output is correct
76 Correct 890 ms 220272 KB Output is correct
77 Correct 693 ms 219068 KB Output is correct
78 Correct 555 ms 219492 KB Output is correct
79 Correct 402 ms 14584 KB Output is correct
80 Correct 294 ms 13604 KB Output is correct
81 Correct 295 ms 13236 KB Output is correct
82 Correct 855 ms 219984 KB Output is correct
83 Correct 975 ms 327040 KB Output is correct
84 Correct 759 ms 219220 KB Output is correct
85 Correct 851 ms 327508 KB Output is correct
86 Correct 606 ms 219476 KB Output is correct
87 Correct 855 ms 327376 KB Output is correct
88 Correct 457 ms 14452 KB Output is correct
89 Correct 424 ms 14448 KB Output is correct
90 Correct 297 ms 13552 KB Output is correct
91 Correct 292 ms 13472 KB Output is correct
92 Correct 312 ms 13276 KB Output is correct
93 Correct 293 ms 13140 KB Output is correct
94 Correct 552 ms 160392 KB Output is correct
95 Correct 594 ms 183460 KB Output is correct
96 Correct 410 ms 158292 KB Output is correct
97 Correct 438 ms 185256 KB Output is correct
98 Correct 413 ms 159836 KB Output is correct
99 Correct 423 ms 184180 KB Output is correct
100 Correct 468 ms 14544 KB Output is correct
101 Correct 454 ms 14676 KB Output is correct
102 Correct 348 ms 13724 KB Output is correct
103 Correct 340 ms 13652 KB Output is correct
104 Correct 340 ms 13352 KB Output is correct
105 Correct 325 ms 13344 KB Output is correct
106 Correct 580 ms 185684 KB Output is correct
107 Correct 640 ms 252788 KB Output is correct
108 Correct 459 ms 183744 KB Output is correct
109 Correct 501 ms 245584 KB Output is correct
110 Correct 455 ms 184144 KB Output is correct
111 Correct 514 ms 253860 KB Output is correct
112 Correct 428 ms 14544 KB Output is correct
113 Correct 397 ms 14800 KB Output is correct
114 Correct 300 ms 13904 KB Output is correct
115 Correct 311 ms 13652 KB Output is correct
116 Correct 292 ms 13268 KB Output is correct
117 Correct 306 ms 13228 KB Output is correct
118 Correct 721 ms 218724 KB Output is correct
119 Correct 503 ms 183220 KB Output is correct
120 Correct 552 ms 250704 KB Output is correct
121 Correct 668 ms 218704 KB Output is correct
122 Correct 472 ms 183508 KB Output is correct
123 Correct 519 ms 246348 KB Output is correct
124 Correct 638 ms 218640 KB Output is correct
125 Correct 460 ms 183888 KB Output is correct
126 Correct 542 ms 249128 KB Output is correct