답안 #1095947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095947 2024-10-03T12:39:30 Z mohammad86 Bitaro’s Party (JOI18_bitaro) C++17
14 / 100
630 ms 419236 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 = 320;
int n, m, q;
vector<int> adj[maxn];
vector<int> readj[maxn];
vector<pii> fv[maxn];
int pointer[maxn];
bool mark[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);
    }

    for (int i = 1; i <= n; i++) {
        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]) {
                    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;
            fv[i].push_back({maximum, v});
            pointer[nv]++;
        }
        for (int j : readj[i])
            pointer[j] = 0;
        fv[i].push_back({0, i});
    }

    for (int i = 1; i <= q; i++) {
        int t, y;
        cin >> t >> y;
        vector<int> tmp;
        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 {
            vector<int> dis(t+2, -1);

            int maximum = -1;

            dis[t] = 0;

            if (!mark[t]) {
                maximum = 0;
            }

            for (int i = t-1; i >= 1; i--) {
                dis[i] = -1;
                for (int j : adj[i]) {
                    if (j > t || dis[j] == -1) {
                        continue;
                    }

                    dis[i] = max(dis[i], dis[j] +1);
                }
                if (!mark[i])
                    maximum = max(maximum, dis[i]);
            }

            cout << maximum << endl;
        }
        for (int i = 0; i < y; i++) {
            mark[tmp[i]] = false;
        }
    }
}

Compilation message

bitaro.cpp: In function 'int main()':
bitaro.cpp:34: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]
   34 |                 if (fv[j].size() > pointer[j]) {
      |                     ~~~~~~~~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7772 KB Output is correct
2 Correct 2 ms 7772 KB Output is correct
3 Correct 2 ms 7772 KB Output is correct
4 Correct 2 ms 7772 KB Output is correct
5 Correct 6 ms 10076 KB Output is correct
6 Correct 5 ms 9820 KB Output is correct
7 Correct 5 ms 9820 KB Output is correct
8 Correct 7 ms 11868 KB Output is correct
9 Correct 10 ms 11816 KB Output is correct
10 Correct 11 ms 11868 KB Output is correct
11 Correct 10 ms 11524 KB Output is correct
12 Correct 7 ms 10584 KB Output is correct
13 Correct 10 ms 11608 KB Output is correct
14 Correct 5 ms 9816 KB Output is correct
15 Correct 4 ms 8796 KB Output is correct
16 Correct 5 ms 9820 KB Output is correct
17 Correct 7 ms 10844 KB Output is correct
18 Correct 5 ms 9564 KB Output is correct
19 Correct 7 ms 10904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7772 KB Output is correct
2 Correct 2 ms 7772 KB Output is correct
3 Correct 2 ms 7772 KB Output is correct
4 Correct 2 ms 7772 KB Output is correct
5 Correct 6 ms 10076 KB Output is correct
6 Correct 5 ms 9820 KB Output is correct
7 Correct 5 ms 9820 KB Output is correct
8 Correct 7 ms 11868 KB Output is correct
9 Correct 10 ms 11816 KB Output is correct
10 Correct 11 ms 11868 KB Output is correct
11 Correct 10 ms 11524 KB Output is correct
12 Correct 7 ms 10584 KB Output is correct
13 Correct 10 ms 11608 KB Output is correct
14 Correct 5 ms 9816 KB Output is correct
15 Correct 4 ms 8796 KB Output is correct
16 Correct 5 ms 9820 KB Output is correct
17 Correct 7 ms 10844 KB Output is correct
18 Correct 5 ms 9564 KB Output is correct
19 Correct 7 ms 10904 KB Output is correct
20 Correct 144 ms 15188 KB Output is correct
21 Correct 140 ms 15188 KB Output is correct
22 Correct 135 ms 15332 KB Output is correct
23 Correct 132 ms 15184 KB Output is correct
24 Correct 476 ms 329428 KB Output is correct
25 Correct 479 ms 328652 KB Output is correct
26 Correct 468 ms 328680 KB Output is correct
27 Correct 546 ms 418784 KB Output is correct
28 Correct 531 ms 419236 KB Output is correct
29 Correct 519 ms 418820 KB Output is correct
30 Correct 541 ms 417876 KB Output is correct
31 Correct 497 ms 407752 KB Output is correct
32 Correct 485 ms 417976 KB Output is correct
33 Correct 351 ms 259800 KB Output is correct
34 Correct 300 ms 213812 KB Output is correct
35 Correct 433 ms 258160 KB Output is correct
36 Correct 436 ms 341964 KB Output is correct
37 Correct 436 ms 314192 KB Output is correct
38 Correct 457 ms 342220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7772 KB Output is correct
2 Correct 2 ms 7772 KB Output is correct
3 Correct 2 ms 7772 KB Output is correct
4 Correct 2 ms 7772 KB Output is correct
5 Correct 6 ms 10076 KB Output is correct
6 Correct 5 ms 9820 KB Output is correct
7 Correct 5 ms 9820 KB Output is correct
8 Correct 7 ms 11868 KB Output is correct
9 Correct 10 ms 11816 KB Output is correct
10 Correct 11 ms 11868 KB Output is correct
11 Correct 10 ms 11524 KB Output is correct
12 Correct 7 ms 10584 KB Output is correct
13 Correct 10 ms 11608 KB Output is correct
14 Correct 5 ms 9816 KB Output is correct
15 Correct 4 ms 8796 KB Output is correct
16 Correct 5 ms 9820 KB Output is correct
17 Correct 7 ms 10844 KB Output is correct
18 Correct 5 ms 9564 KB Output is correct
19 Correct 7 ms 10904 KB Output is correct
20 Correct 144 ms 15188 KB Output is correct
21 Correct 140 ms 15188 KB Output is correct
22 Correct 135 ms 15332 KB Output is correct
23 Correct 132 ms 15184 KB Output is correct
24 Correct 476 ms 329428 KB Output is correct
25 Correct 479 ms 328652 KB Output is correct
26 Correct 468 ms 328680 KB Output is correct
27 Correct 546 ms 418784 KB Output is correct
28 Correct 531 ms 419236 KB Output is correct
29 Correct 519 ms 418820 KB Output is correct
30 Correct 541 ms 417876 KB Output is correct
31 Correct 497 ms 407752 KB Output is correct
32 Correct 485 ms 417976 KB Output is correct
33 Correct 351 ms 259800 KB Output is correct
34 Correct 300 ms 213812 KB Output is correct
35 Correct 433 ms 258160 KB Output is correct
36 Correct 436 ms 341964 KB Output is correct
37 Correct 436 ms 314192 KB Output is correct
38 Correct 457 ms 342220 KB Output is correct
39 Correct 630 ms 322900 KB Output is correct
40 Correct 490 ms 326568 KB Output is correct
41 Correct 493 ms 326328 KB Output is correct
42 Correct 605 ms 326696 KB Output is correct
43 Correct 464 ms 325976 KB Output is correct
44 Incorrect 252 ms 16188 KB Output isn't correct
45 Halted 0 ms 0 KB -