답안 #963335

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963335 2024-04-14T21:00:13 Z TimAni Bitaro’s Party (JOI18_bitaro) C++17
100 / 100
1367 ms 145840 KB
//start-time: 2024-04-14 19:39:32
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
const int w = 100;
 
void solve(){
    int n, m, q;
    cin >> n >> m >> q;
 
    vector<vector<int>> gR(n);
 
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        gR[v - 1].push_back(u - 1);
    }
    
    vector<vector<pair<int, int>>> dp(n);
    vector<int> vis(n);

    for(int u = 0; u < n; u++){
        vector<int> val(n), cur;
        for(auto &v : gR[u]){
            for(auto &[value, ind] : dp[v]){
                if(vis[ind] == u) val[ind] = max(val[ind], value + 1);
                else vis[ind] = u, val[ind] = value + 1, cur.push_back(ind);
            }
        }
		for(auto v : cur) dp[u].push_back({val[v],v});
		dp[u].push_back({0,u}); 
        sort(dp[u].rbegin(), dp[u].rend());
		if(dp[u].size()>w) dp[u].erase(dp[u].begin() + w, dp[u].end());
    }
 
    while(q--){
        vector<bool> c(n);
        int u, y, ans = -1;
        cin >> u >> y;
        u--;
        for(int j = 0; j < y; j++){
            int a; cin >> a;
            c[--a] = 1;
        }
 
        if(y < w) {
            for(auto &[v, i] : dp[u]){
                if(!c[i]){
                    ans = max(ans, v);
                }
            }
        }
        else {
            vector<int> naive(n);
            for(int v = 0; v <= u; v++){
                naive[v] = c[v] ? -1 : 0;
                for(auto &el : gR[v]){
                    naive[v] = max(naive[v], naive[el] + (naive[el] != -1));
                }
            }
            ans = naive[u];
        }
 
        cout << ans << endl;
    }
}
 
int main() {
    cin.tie(0)->sync_with_stdio(0);
    ll T = 1;
    //cin >> T;
    while(T--) solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 3 ms 1372 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Correct 4 ms 1372 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 3 ms 1372 KB Output is correct
14 Correct 3 ms 1116 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 3 ms 1116 KB Output is correct
18 Correct 4 ms 1116 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 3 ms 1372 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Correct 4 ms 1372 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 3 ms 1372 KB Output is correct
14 Correct 3 ms 1116 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 3 ms 1116 KB Output is correct
18 Correct 4 ms 1116 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
20 Correct 56 ms 2388 KB Output is correct
21 Correct 51 ms 2384 KB Output is correct
22 Correct 50 ms 2384 KB Output is correct
23 Correct 54 ms 2644 KB Output is correct
24 Correct 980 ms 113288 KB Output is correct
25 Correct 1046 ms 109840 KB Output is correct
26 Correct 1069 ms 109424 KB Output is correct
27 Correct 808 ms 111252 KB Output is correct
28 Correct 812 ms 111112 KB Output is correct
29 Correct 801 ms 111144 KB Output is correct
30 Correct 828 ms 111068 KB Output is correct
31 Correct 960 ms 129040 KB Output is correct
32 Correct 825 ms 111000 KB Output is correct
33 Correct 801 ms 75204 KB Output is correct
34 Correct 928 ms 103644 KB Output is correct
35 Correct 834 ms 74820 KB Output is correct
36 Correct 848 ms 91688 KB Output is correct
37 Correct 1037 ms 113788 KB Output is correct
38 Correct 774 ms 91976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 3 ms 1372 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Correct 4 ms 1372 KB Output is correct
12 Correct 3 ms 1116 KB Output is correct
13 Correct 3 ms 1372 KB Output is correct
14 Correct 3 ms 1116 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 3 ms 1116 KB Output is correct
18 Correct 4 ms 1116 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
20 Correct 56 ms 2388 KB Output is correct
21 Correct 51 ms 2384 KB Output is correct
22 Correct 50 ms 2384 KB Output is correct
23 Correct 54 ms 2644 KB Output is correct
24 Correct 980 ms 113288 KB Output is correct
25 Correct 1046 ms 109840 KB Output is correct
26 Correct 1069 ms 109424 KB Output is correct
27 Correct 808 ms 111252 KB Output is correct
28 Correct 812 ms 111112 KB Output is correct
29 Correct 801 ms 111144 KB Output is correct
30 Correct 828 ms 111068 KB Output is correct
31 Correct 960 ms 129040 KB Output is correct
32 Correct 825 ms 111000 KB Output is correct
33 Correct 801 ms 75204 KB Output is correct
34 Correct 928 ms 103644 KB Output is correct
35 Correct 834 ms 74820 KB Output is correct
36 Correct 848 ms 91688 KB Output is correct
37 Correct 1037 ms 113788 KB Output is correct
38 Correct 774 ms 91976 KB Output is correct
39 Correct 1171 ms 114976 KB Output is correct
40 Correct 1059 ms 110696 KB Output is correct
41 Correct 1367 ms 112364 KB Output is correct
42 Correct 1111 ms 113428 KB Output is correct
43 Correct 1012 ms 115012 KB Output is correct
44 Correct 204 ms 4436 KB Output is correct
45 Correct 75 ms 3780 KB Output is correct
46 Correct 119 ms 3988 KB Output is correct
47 Correct 64 ms 3452 KB Output is correct
48 Correct 53 ms 3536 KB Output is correct
49 Correct 1039 ms 113224 KB Output is correct
50 Correct 1070 ms 112608 KB Output is correct
51 Correct 200 ms 4284 KB Output is correct
52 Correct 109 ms 3692 KB Output is correct
53 Correct 1014 ms 93608 KB Output is correct
54 Correct 1256 ms 114340 KB Output is correct
55 Correct 1053 ms 93380 KB Output is correct
56 Correct 1305 ms 117960 KB Output is correct
57 Correct 196 ms 4176 KB Output is correct
58 Correct 200 ms 4520 KB Output is correct
59 Correct 123 ms 3908 KB Output is correct
60 Correct 110 ms 3832 KB Output is correct
61 Correct 921 ms 112560 KB Output is correct
62 Correct 857 ms 93456 KB Output is correct
63 Correct 1045 ms 113600 KB Output is correct
64 Correct 993 ms 112792 KB Output is correct
65 Correct 987 ms 93452 KB Output is correct
66 Correct 1133 ms 115620 KB Output is correct
67 Correct 1095 ms 113020 KB Output is correct
68 Correct 1030 ms 93800 KB Output is correct
69 Correct 1262 ms 115584 KB Output is correct
70 Correct 861 ms 112884 KB Output is correct
71 Correct 778 ms 93668 KB Output is correct
72 Correct 951 ms 115304 KB Output is correct
73 Correct 829 ms 112560 KB Output is correct
74 Correct 828 ms 93472 KB Output is correct
75 Correct 1008 ms 117440 KB Output is correct
76 Correct 1122 ms 113268 KB Output is correct
77 Correct 1110 ms 112816 KB Output is correct
78 Correct 847 ms 113012 KB Output is correct
79 Correct 194 ms 4532 KB Output is correct
80 Correct 110 ms 3668 KB Output is correct
81 Correct 62 ms 3408 KB Output is correct
82 Correct 1016 ms 113292 KB Output is correct
83 Correct 1341 ms 134480 KB Output is correct
84 Correct 1049 ms 112808 KB Output is correct
85 Correct 1255 ms 145840 KB Output is correct
86 Correct 886 ms 113900 KB Output is correct
87 Correct 975 ms 134768 KB Output is correct
88 Correct 208 ms 5384 KB Output is correct
89 Correct 196 ms 5196 KB Output is correct
90 Correct 115 ms 4320 KB Output is correct
91 Correct 109 ms 4272 KB Output is correct
92 Correct 52 ms 4124 KB Output is correct
93 Correct 50 ms 3908 KB Output is correct
94 Correct 1020 ms 78332 KB Output is correct
95 Correct 1269 ms 113556 KB Output is correct
96 Correct 990 ms 77568 KB Output is correct
97 Correct 1258 ms 114224 KB Output is correct
98 Correct 855 ms 77836 KB Output is correct
99 Correct 949 ms 109780 KB Output is correct
100 Correct 201 ms 5232 KB Output is correct
101 Correct 206 ms 5180 KB Output is correct
102 Correct 103 ms 4260 KB Output is correct
103 Correct 93 ms 4320 KB Output is correct
104 Correct 52 ms 4180 KB Output is correct
105 Correct 52 ms 4000 KB Output is correct
106 Correct 1006 ms 94648 KB Output is correct
107 Correct 1278 ms 121040 KB Output is correct
108 Correct 1029 ms 94916 KB Output is correct
109 Correct 1263 ms 112092 KB Output is correct
110 Correct 871 ms 94712 KB Output is correct
111 Correct 987 ms 117636 KB Output is correct
112 Correct 202 ms 5132 KB Output is correct
113 Correct 198 ms 5304 KB Output is correct
114 Correct 112 ms 4588 KB Output is correct
115 Correct 110 ms 4172 KB Output is correct
116 Correct 50 ms 3932 KB Output is correct
117 Correct 51 ms 3920 KB Output is correct
118 Correct 890 ms 113096 KB Output is correct
119 Correct 859 ms 94084 KB Output is correct
120 Correct 1052 ms 121380 KB Output is correct
121 Correct 882 ms 112608 KB Output is correct
122 Correct 853 ms 92868 KB Output is correct
123 Correct 1024 ms 119888 KB Output is correct
124 Correct 830 ms 112576 KB Output is correct
125 Correct 803 ms 93648 KB Output is correct
126 Correct 980 ms 116472 KB Output is correct