답안 #540723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
540723 2022-03-21T14:00:10 Z GioChkhaidze Bitaro’s Party (JOI18_bitaro) C++14
100 / 100
1395 ms 272900 KB
#include <bits/stdc++.h>

#define pb push_back
#define f first
#define s second

using namespace std;

const int N = 1e5 + 5;

bool f[N];
int n, m, q, d[N], ans[N];
vector < int > s[N], v[N], Q[N];
vector < pair < int , int > > rec[N];

main () {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	cin >> n >> m >> q;
	for (int i = 1; i <= m; ++i) {
		int a, b;
		cin >> a >> b;
		v[b].pb(a);
	}
	
	int sq = sqrt(n);
	for (int i = 1; i <= q; ++i) {
		int st, k;
		cin >> st >> k;
		for (int j = 1; j <= k; ++j) {
			int x;
			cin >> x;
			s[i].pb(x);
		}
		
		if (k >= sq) {
			for (int j = 0; j < s[i].size(); ++j) {
				f[s[i][j]] = true;
			}
			
			d[st] = 1;
			ans[i] = -1;
			for (int j = st; j >= 1; --j) {
				if (d[j]) {
					if (!f[j]) {
						ans[i] = max(ans[i], d[j] - 1);
					}
					for (int j2 = 0; j2 < v[j].size(); ++j2) {
						int to = v[j][j2];
						d[to] = max(d[j] + 1, d[to]);
					}
				}
			}

			for (int j = st; j >= 1; --j) d[j] = 0;
			for (int j = 0; j < s[i].size(); ++j) {
				f[s[i][j]] = false;
			}
		}
			else {
			Q[st].pb(i);	
		}
	}
	
	for (int i = 1; i <= n; ++i) {
		rec[i].pb({0, i});
		for (int j = 0; j < v[i].size(); ++j) {
			int to = v[i][j];
			vector < pair < int , int > > ret;
			int isz = rec[i].size(), tosz = rec[to].size();
			int iid = 0, toid = 0, sz = min(sq + 5, isz + tosz);
			while (ret.size() < sz && (toid < tosz || iid < isz)) {
				if (toid < tosz && (iid == isz || rec[i][iid].f <= rec[to][toid].f + 1)) {
					if (!f[rec[to][toid].s]) {
						ret.pb({rec[to][toid].f + 1, rec[to][toid].s});
						f[rec[to][toid].s] = true;
					}
					++toid;
				}
					else
				if (iid < isz && (toid == tosz || rec[to][toid].f + 1 <= rec[i][iid].f)) {
					if (!f[rec[i][iid].s]) {
						f[rec[i][iid].s] = true;
						ret.pb(rec[i][iid]);
					}
				 	++iid;
				}
			}
			
			for (int k = 0; k < ret.size(); ++k) {
				f[ret[k].s] = false;
			}
			rec[i] = ret;
			ret.clear();	
		}

		for (int j = 0; j < Q[i].size(); ++j) {
			int id = Q[i][j];
			for (int k = 0; k < s[id].size(); ++k) {
				int x = s[id][k];
				f[x] = true;
			}	
			
			ans[id] = -1;
			for (int k = 0; k < rec[i].size(); ++k) {
				int x = rec[i][k].f, idx = rec[i][k].s;
				if (!f[idx]) {
					ans[id] = max(ans[id], x);
				}
			}
		
			for (int k = 0; k < s[id].size(); ++k) {
				int x = s[id][k];
				f[x] = false;
			}
		}
	}
	
	for (int i = 1; i <= q; ++i) {
		cout << ans[i] << "\n";
	}
}

Compilation message

bitaro.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   16 | main () {
      | ^~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |    for (int j = 0; j < s[i].size(); ++j) {
      |                    ~~^~~~~~~~~~~~~
bitaro.cpp:48:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |      for (int j2 = 0; j2 < v[j].size(); ++j2) {
      |                       ~~~^~~~~~~~~~~~~
bitaro.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |    for (int j = 0; j < s[i].size(); ++j) {
      |                    ~~^~~~~~~~~~~~~
bitaro.cpp:67:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   for (int j = 0; j < v[i].size(); ++j) {
      |                   ~~^~~~~~~~~~~~~
bitaro.cpp:72:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   72 |    while (ret.size() < sz && (toid < tosz || iid < isz)) {
      |           ~~~~~~~~~~~^~~~
bitaro.cpp:90:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |    for (int k = 0; k < ret.size(); ++k) {
      |                    ~~^~~~~~~~~~~~
bitaro.cpp:97:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |   for (int j = 0; j < Q[i].size(); ++j) {
      |                   ~~^~~~~~~~~~~~~
bitaro.cpp:99:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |    for (int k = 0; k < s[id].size(); ++k) {
      |                    ~~^~~~~~~~~~~~~~
bitaro.cpp:105:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |    for (int k = 0; k < rec[i].size(); ++k) {
      |                    ~~^~~~~~~~~~~~~~~
bitaro.cpp:112:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |    for (int k = 0; k < s[id].size(); ++k) {
      |                    ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 8 ms 9940 KB Output is correct
6 Correct 6 ms 9856 KB Output is correct
7 Correct 6 ms 9940 KB Output is correct
8 Correct 7 ms 9940 KB Output is correct
9 Correct 7 ms 9940 KB Output is correct
10 Correct 8 ms 10068 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 7 ms 9940 KB Output is correct
13 Correct 7 ms 9940 KB Output is correct
14 Correct 7 ms 9940 KB Output is correct
15 Correct 6 ms 9812 KB Output is correct
16 Correct 7 ms 9940 KB Output is correct
17 Correct 6 ms 9940 KB Output is correct
18 Correct 7 ms 9940 KB Output is correct
19 Correct 6 ms 9940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 8 ms 9940 KB Output is correct
6 Correct 6 ms 9856 KB Output is correct
7 Correct 6 ms 9940 KB Output is correct
8 Correct 7 ms 9940 KB Output is correct
9 Correct 7 ms 9940 KB Output is correct
10 Correct 8 ms 10068 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 7 ms 9940 KB Output is correct
13 Correct 7 ms 9940 KB Output is correct
14 Correct 7 ms 9940 KB Output is correct
15 Correct 6 ms 9812 KB Output is correct
16 Correct 7 ms 9940 KB Output is correct
17 Correct 6 ms 9940 KB Output is correct
18 Correct 7 ms 9940 KB Output is correct
19 Correct 6 ms 9940 KB Output is correct
20 Correct 154 ms 11104 KB Output is correct
21 Correct 147 ms 11104 KB Output is correct
22 Correct 150 ms 11128 KB Output is correct
23 Correct 153 ms 11120 KB Output is correct
24 Correct 831 ms 168172 KB Output is correct
25 Correct 870 ms 175256 KB Output is correct
26 Correct 862 ms 175004 KB Output is correct
27 Correct 1012 ms 265180 KB Output is correct
28 Correct 1028 ms 265160 KB Output is correct
29 Correct 1008 ms 265072 KB Output is correct
30 Correct 1000 ms 264684 KB Output is correct
31 Correct 1008 ms 256152 KB Output is correct
32 Correct 1002 ms 264824 KB Output is correct
33 Correct 807 ms 166252 KB Output is correct
34 Correct 719 ms 138332 KB Output is correct
35 Correct 790 ms 165180 KB Output is correct
36 Correct 927 ms 215740 KB Output is correct
37 Correct 912 ms 196204 KB Output is correct
38 Correct 928 ms 216088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 8 ms 9940 KB Output is correct
6 Correct 6 ms 9856 KB Output is correct
7 Correct 6 ms 9940 KB Output is correct
8 Correct 7 ms 9940 KB Output is correct
9 Correct 7 ms 9940 KB Output is correct
10 Correct 8 ms 10068 KB Output is correct
11 Correct 7 ms 9940 KB Output is correct
12 Correct 7 ms 9940 KB Output is correct
13 Correct 7 ms 9940 KB Output is correct
14 Correct 7 ms 9940 KB Output is correct
15 Correct 6 ms 9812 KB Output is correct
16 Correct 7 ms 9940 KB Output is correct
17 Correct 6 ms 9940 KB Output is correct
18 Correct 7 ms 9940 KB Output is correct
19 Correct 6 ms 9940 KB Output is correct
20 Correct 154 ms 11104 KB Output is correct
21 Correct 147 ms 11104 KB Output is correct
22 Correct 150 ms 11128 KB Output is correct
23 Correct 153 ms 11120 KB Output is correct
24 Correct 831 ms 168172 KB Output is correct
25 Correct 870 ms 175256 KB Output is correct
26 Correct 862 ms 175004 KB Output is correct
27 Correct 1012 ms 265180 KB Output is correct
28 Correct 1028 ms 265160 KB Output is correct
29 Correct 1008 ms 265072 KB Output is correct
30 Correct 1000 ms 264684 KB Output is correct
31 Correct 1008 ms 256152 KB Output is correct
32 Correct 1002 ms 264824 KB Output is correct
33 Correct 807 ms 166252 KB Output is correct
34 Correct 719 ms 138332 KB Output is correct
35 Correct 790 ms 165180 KB Output is correct
36 Correct 927 ms 215740 KB Output is correct
37 Correct 912 ms 196204 KB Output is correct
38 Correct 928 ms 216088 KB Output is correct
39 Correct 984 ms 174336 KB Output is correct
40 Correct 870 ms 172448 KB Output is correct
41 Correct 879 ms 173396 KB Output is correct
42 Correct 880 ms 172836 KB Output is correct
43 Correct 875 ms 172232 KB Output is correct
44 Correct 207 ms 14284 KB Output is correct
45 Correct 163 ms 11936 KB Output is correct
46 Correct 434 ms 11576 KB Output is correct
47 Correct 182 ms 11324 KB Output is correct
48 Correct 152 ms 11080 KB Output is correct
49 Correct 1261 ms 269512 KB Output is correct
50 Correct 1081 ms 265164 KB Output is correct
51 Correct 195 ms 16652 KB Output is correct
52 Correct 406 ms 13344 KB Output is correct
53 Correct 1097 ms 222544 KB Output is correct
54 Correct 1018 ms 204100 KB Output is correct
55 Correct 932 ms 217852 KB Output is correct
56 Correct 892 ms 199900 KB Output is correct
57 Correct 202 ms 16640 KB Output is correct
58 Correct 201 ms 16664 KB Output is correct
59 Correct 439 ms 13432 KB Output is correct
60 Correct 432 ms 13388 KB Output is correct
61 Correct 1231 ms 268292 KB Output is correct
62 Correct 1028 ms 218928 KB Output is correct
63 Correct 937 ms 199148 KB Output is correct
64 Correct 1395 ms 268164 KB Output is correct
65 Correct 1130 ms 218284 KB Output is correct
66 Correct 981 ms 200432 KB Output is correct
67 Correct 1148 ms 267600 KB Output is correct
68 Correct 962 ms 218596 KB Output is correct
69 Correct 901 ms 197520 KB Output is correct
70 Correct 1142 ms 268220 KB Output is correct
71 Correct 971 ms 218976 KB Output is correct
72 Correct 913 ms 199844 KB Output is correct
73 Correct 1129 ms 268200 KB Output is correct
74 Correct 981 ms 219212 KB Output is correct
75 Correct 922 ms 200052 KB Output is correct
76 Correct 1244 ms 272900 KB Output is correct
77 Correct 1084 ms 268112 KB Output is correct
78 Correct 1093 ms 268404 KB Output is correct
79 Correct 209 ms 16544 KB Output is correct
80 Correct 372 ms 13648 KB Output is correct
81 Correct 153 ms 12644 KB Output is correct
82 Correct 1258 ms 272672 KB Output is correct
83 Correct 1237 ms 264108 KB Output is correct
84 Correct 1093 ms 267988 KB Output is correct
85 Correct 1071 ms 258892 KB Output is correct
86 Correct 1105 ms 267932 KB Output is correct
87 Correct 1098 ms 259804 KB Output is correct
88 Correct 203 ms 16652 KB Output is correct
89 Correct 210 ms 16656 KB Output is correct
90 Correct 391 ms 13500 KB Output is correct
91 Correct 400 ms 13460 KB Output is correct
92 Correct 152 ms 12660 KB Output is correct
93 Correct 153 ms 12620 KB Output is correct
94 Correct 922 ms 174472 KB Output is correct
95 Correct 838 ms 145252 KB Output is correct
96 Correct 815 ms 168692 KB Output is correct
97 Correct 741 ms 143232 KB Output is correct
98 Correct 814 ms 169548 KB Output is correct
99 Correct 736 ms 142836 KB Output is correct
100 Correct 196 ms 16716 KB Output is correct
101 Correct 207 ms 16708 KB Output is correct
102 Correct 321 ms 13568 KB Output is correct
103 Correct 322 ms 13624 KB Output is correct
104 Correct 154 ms 12816 KB Output is correct
105 Correct 153 ms 12748 KB Output is correct
106 Correct 1095 ms 222856 KB Output is correct
107 Correct 1035 ms 204448 KB Output is correct
108 Correct 942 ms 219656 KB Output is correct
109 Correct 911 ms 199564 KB Output is correct
110 Correct 941 ms 219720 KB Output is correct
111 Correct 898 ms 200320 KB Output is correct
112 Correct 221 ms 16608 KB Output is correct
113 Correct 198 ms 16604 KB Output is correct
114 Correct 395 ms 13576 KB Output is correct
115 Correct 396 ms 13504 KB Output is correct
116 Correct 157 ms 12784 KB Output is correct
117 Correct 154 ms 12676 KB Output is correct
118 Correct 1106 ms 267880 KB Output is correct
119 Correct 959 ms 219280 KB Output is correct
120 Correct 907 ms 199300 KB Output is correct
121 Correct 1115 ms 268196 KB Output is correct
122 Correct 954 ms 218592 KB Output is correct
123 Correct 899 ms 199648 KB Output is correct
124 Correct 1082 ms 267724 KB Output is correct
125 Correct 950 ms 219404 KB Output is correct
126 Correct 889 ms 198588 KB Output is correct