답안 #629679

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
629679 2022-08-14T21:50:26 Z hy_1 열쇠 (IOI21_keys) C++17
20 / 100
3000 ms 12952 KB
#include <bits/stdc++.h>

#define MAXN 300000
#define MAXM 300000
#define MAXK 2000

using namespace std;

typedef pair<int,int> pi;


int n, m, p[MAXN + 5], l;
int vis[MAXN + 5];
int hasKey[MAXK + 5];

vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
	n = r.size();
	m = c.size();

	for (int i = 0; i < n; ++i){

		for (int j = 0; j < MAXK; ++j) hasKey[j] = 0;
		for (int j = 0; j < n; ++j) vis[j] = 0;

		vis[i] = 1;
		hasKey[r[i]] = 1;

		int round = 0;
		while (1){
            round++;
			int check = 0;
			for (int j = 0; j < m; ++j){
				if (hasKey[c[j]]){
					if (vis[u[j]] == 1 && vis[v[j]] == 0){
						vis[v[j]] = 1;
						hasKey[r[v[j]]] = 1;
						check++;
					}
					else if (vis[v[j]] == 1 && vis[u[j]] == 0){
						vis[u[j]] = 1;
						hasKey[r[u[j]]] = 1;
						check++;
					}
				}
			}
			if (!check) break;
		}
		//printf("i=%d round=%d\n", i, round);

		for (int j = 0; j < n; ++j) p[i] += vis[j];
	}

	int minval = n;
	vector<int> ans, vals;
	for (int i = 0; i < n; ++i){
		if (p[i] < minval){
			vals.clear();
			minval = p[i];
		}
		if (p[i] == minval){
			vals.push_back(i);
		}
	}

	ans.resize(n);
	for (int i = 0; i < vals.size(); ++i){
		ans[vals[i]] = 1;
	}

	return ans;
}


Compilation message

keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:66:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |  for (int i = 0; i < vals.size(); ++i){
      |                  ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 4 ms 212 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 5 ms 308 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 3 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 4 ms 212 KB Output is correct
24 Correct 8 ms 308 KB Output is correct
25 Correct 8 ms 304 KB Output is correct
26 Correct 11 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 4 ms 212 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 5 ms 308 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 3 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 4 ms 212 KB Output is correct
24 Correct 8 ms 308 KB Output is correct
25 Correct 8 ms 304 KB Output is correct
26 Correct 11 ms 212 KB Output is correct
27 Correct 2168 ms 412 KB Output is correct
28 Correct 2270 ms 416 KB Output is correct
29 Correct 2197 ms 408 KB Output is correct
30 Correct 90 ms 352 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 5 ms 340 KB Output is correct
34 Correct 14 ms 340 KB Output is correct
35 Correct 312 ms 344 KB Output is correct
36 Correct 2476 ms 400 KB Output is correct
37 Execution timed out 3090 ms 396 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Execution timed out 3055 ms 12952 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 4 ms 212 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 5 ms 308 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 3 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 4 ms 212 KB Output is correct
24 Correct 8 ms 308 KB Output is correct
25 Correct 8 ms 304 KB Output is correct
26 Correct 11 ms 212 KB Output is correct
27 Correct 2168 ms 412 KB Output is correct
28 Correct 2270 ms 416 KB Output is correct
29 Correct 2197 ms 408 KB Output is correct
30 Correct 90 ms 352 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 5 ms 340 KB Output is correct
34 Correct 14 ms 340 KB Output is correct
35 Correct 312 ms 344 KB Output is correct
36 Correct 2476 ms 400 KB Output is correct
37 Execution timed out 3090 ms 396 KB Time limit exceeded
38 Halted 0 ms 0 KB -