답안 #299529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
299529 2020-09-15T06:20:07 Z E869120 Joker (BOI20_joker) C++14
39 / 100
2000 ms 22520 KB
#include <bits/stdc++.h>
using namespace std;

// Input
int N;
int M, A[1 << 18], B[1 << 18];
int Q, L[1 << 18], R[1 << 18];

// Graph
vector<int> X[1 << 18];
int col[1 << 18];
int lim[1 << 18];
bool flag;

void dfs(int pos, int dep) {
	col[pos] = dep;
	for (int i : X[pos]) {
		if (col[i] != -1) {
			if (col[i] == dep) flag = true;
			continue;
		}
		dfs(i, dep ^ 1);
	}
}

bool solve(int l, int r) {
	flag = false;
	for (int i = 1; i <= N; i++) X[i].clear();
	for (int i = 1; i <= M; i++) {
		if (l <= i && i <= r) continue;
		X[A[i]].push_back(B[i]);
		X[B[i]].push_back(A[i]);
	}
	for (int i = 1; i <= N; i++) col[i] = -1;
	for (int i = 1; i <= N; i++) {
		if (col[i] >= 0) continue;
		dfs(i, 0);
	}
	return flag;
}

void solve_subtask1() {
	for (int i = 1; i <= Q; i++) {
		bool ans = solve(L[i], R[i]);
		if (ans == false) printf("NO\n");
		else printf("YES\n");
	}
}

void solve_subtask3() {
	int maxL = 0;
	for (int i = 1; i <= Q; i++) maxL = max(maxL, L[i]);
	for (int i = 1; i <= maxL; i++) {
		int cl = i, cr = M + 1, cm;
		for (int j = 0; j < 20; j++) {
			cm = (cl + cr) / 2;
			bool I = solve(i, cm);
			if (I == true) { lim[i] = max(lim[i], cm); cl = cm; }
			else { cr = cm; }
		}
	}
	
	for (int i = 1; i <= Q; i++) {
		if (R[i] <= lim[L[i]]) printf("YES\n");
		else printf("NO\n");
	}
}

int main() {
	scanf("%d%d%d", &N, &M, &Q);
	for (int i = 1; i <= M; i++) scanf("%d%d", &A[i], &B[i]);
	for (int i = 1; i <= Q; i++) scanf("%d%d", &L[i], &R[i]);
	
	if (N <= 2000 && M <= 2000 && Q <= 2000) solve_subtask1();
	else solve_subtask3();
	return 0;
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:70:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   70 |  scanf("%d%d%d", &N, &M, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:71:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   71 |  for (int i = 1; i <= M; i++) scanf("%d%d", &A[i], &B[i]);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:72:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   72 |  for (int i = 1; i <= Q; i++) scanf("%d%d", &L[i], &R[i]);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 6528 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Correct 5 ms 6656 KB Output is correct
4 Correct 5 ms 6528 KB Output is correct
5 Correct 5 ms 6528 KB Output is correct
6 Correct 6 ms 6528 KB Output is correct
7 Correct 5 ms 6656 KB Output is correct
8 Correct 6 ms 6528 KB Output is correct
9 Correct 6 ms 6528 KB Output is correct
10 Correct 6 ms 6528 KB Output is correct
11 Correct 6 ms 6528 KB Output is correct
12 Correct 6 ms 6528 KB Output is correct
13 Correct 6 ms 6528 KB Output is correct
14 Correct 7 ms 6656 KB Output is correct
15 Correct 6 ms 6528 KB Output is correct
16 Correct 6 ms 6528 KB Output is correct
17 Correct 6 ms 6528 KB Output is correct
18 Correct 6 ms 6528 KB Output is correct
19 Correct 6 ms 6528 KB Output is correct
20 Correct 6 ms 6528 KB Output is correct
21 Correct 6 ms 6528 KB Output is correct
22 Correct 6 ms 6528 KB Output is correct
23 Correct 6 ms 6528 KB Output is correct
24 Correct 6 ms 6528 KB Output is correct
25 Correct 6 ms 6528 KB Output is correct
26 Correct 6 ms 6528 KB Output is correct
27 Correct 6 ms 6528 KB Output is correct
28 Correct 6 ms 6528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 6528 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Correct 5 ms 6656 KB Output is correct
4 Correct 5 ms 6528 KB Output is correct
5 Correct 5 ms 6528 KB Output is correct
6 Correct 6 ms 6528 KB Output is correct
7 Correct 5 ms 6656 KB Output is correct
8 Correct 6 ms 6528 KB Output is correct
9 Correct 6 ms 6528 KB Output is correct
10 Correct 6 ms 6528 KB Output is correct
11 Correct 6 ms 6528 KB Output is correct
12 Correct 6 ms 6528 KB Output is correct
13 Correct 6 ms 6528 KB Output is correct
14 Correct 7 ms 6656 KB Output is correct
15 Correct 6 ms 6528 KB Output is correct
16 Correct 6 ms 6528 KB Output is correct
17 Correct 6 ms 6528 KB Output is correct
18 Correct 6 ms 6528 KB Output is correct
19 Correct 6 ms 6528 KB Output is correct
20 Correct 6 ms 6528 KB Output is correct
21 Correct 6 ms 6528 KB Output is correct
22 Correct 6 ms 6528 KB Output is correct
23 Correct 6 ms 6528 KB Output is correct
24 Correct 6 ms 6528 KB Output is correct
25 Correct 6 ms 6528 KB Output is correct
26 Correct 6 ms 6528 KB Output is correct
27 Correct 6 ms 6528 KB Output is correct
28 Correct 6 ms 6528 KB Output is correct
29 Correct 112 ms 6776 KB Output is correct
30 Correct 156 ms 6656 KB Output is correct
31 Correct 153 ms 6832 KB Output is correct
32 Correct 117 ms 6784 KB Output is correct
33 Correct 103 ms 6648 KB Output is correct
34 Correct 158 ms 6656 KB Output is correct
35 Correct 167 ms 6932 KB Output is correct
36 Correct 70 ms 6656 KB Output is correct
37 Correct 132 ms 6656 KB Output is correct
38 Correct 140 ms 6656 KB Output is correct
39 Correct 122 ms 6784 KB Output is correct
40 Correct 108 ms 6656 KB Output is correct
41 Correct 108 ms 6776 KB Output is correct
42 Correct 107 ms 6656 KB Output is correct
43 Correct 124 ms 6776 KB Output is correct
44 Correct 147 ms 6656 KB Output is correct
45 Correct 173 ms 6780 KB Output is correct
46 Correct 189 ms 6656 KB Output is correct
47 Correct 104 ms 6776 KB Output is correct
48 Correct 113 ms 6656 KB Output is correct
49 Correct 132 ms 6664 KB Output is correct
50 Correct 153 ms 6784 KB Output is correct
51 Correct 107 ms 6780 KB Output is correct
52 Correct 122 ms 6656 KB Output is correct
53 Correct 144 ms 6776 KB Output is correct
54 Correct 174 ms 6656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 6528 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Correct 298 ms 17016 KB Output is correct
4 Correct 680 ms 22520 KB Output is correct
5 Correct 294 ms 19320 KB Output is correct
6 Correct 368 ms 20472 KB Output is correct
7 Correct 405 ms 20344 KB Output is correct
8 Correct 354 ms 18812 KB Output is correct
9 Correct 534 ms 20088 KB Output is correct
10 Correct 791 ms 20984 KB Output is correct
11 Correct 414 ms 19960 KB Output is correct
12 Correct 584 ms 20484 KB Output is correct
13 Correct 263 ms 17660 KB Output is correct
14 Correct 351 ms 19320 KB Output is correct
15 Correct 649 ms 21240 KB Output is correct
16 Correct 788 ms 21368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 6528 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Correct 5 ms 6656 KB Output is correct
4 Correct 5 ms 6528 KB Output is correct
5 Correct 5 ms 6528 KB Output is correct
6 Correct 6 ms 6528 KB Output is correct
7 Correct 5 ms 6656 KB Output is correct
8 Correct 6 ms 6528 KB Output is correct
9 Correct 6 ms 6528 KB Output is correct
10 Correct 6 ms 6528 KB Output is correct
11 Correct 6 ms 6528 KB Output is correct
12 Correct 6 ms 6528 KB Output is correct
13 Correct 6 ms 6528 KB Output is correct
14 Correct 7 ms 6656 KB Output is correct
15 Correct 6 ms 6528 KB Output is correct
16 Correct 6 ms 6528 KB Output is correct
17 Correct 6 ms 6528 KB Output is correct
18 Correct 6 ms 6528 KB Output is correct
19 Correct 6 ms 6528 KB Output is correct
20 Correct 6 ms 6528 KB Output is correct
21 Correct 6 ms 6528 KB Output is correct
22 Correct 6 ms 6528 KB Output is correct
23 Correct 6 ms 6528 KB Output is correct
24 Correct 6 ms 6528 KB Output is correct
25 Correct 6 ms 6528 KB Output is correct
26 Correct 6 ms 6528 KB Output is correct
27 Correct 6 ms 6528 KB Output is correct
28 Correct 6 ms 6528 KB Output is correct
29 Correct 298 ms 17016 KB Output is correct
30 Correct 680 ms 22520 KB Output is correct
31 Correct 294 ms 19320 KB Output is correct
32 Correct 368 ms 20472 KB Output is correct
33 Correct 405 ms 20344 KB Output is correct
34 Correct 354 ms 18812 KB Output is correct
35 Correct 534 ms 20088 KB Output is correct
36 Correct 791 ms 20984 KB Output is correct
37 Correct 414 ms 19960 KB Output is correct
38 Correct 584 ms 20484 KB Output is correct
39 Correct 263 ms 17660 KB Output is correct
40 Correct 351 ms 19320 KB Output is correct
41 Correct 649 ms 21240 KB Output is correct
42 Correct 788 ms 21368 KB Output is correct
43 Execution timed out 2041 ms 22168 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 6528 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Correct 5 ms 6656 KB Output is correct
4 Correct 5 ms 6528 KB Output is correct
5 Correct 5 ms 6528 KB Output is correct
6 Correct 6 ms 6528 KB Output is correct
7 Correct 5 ms 6656 KB Output is correct
8 Correct 6 ms 6528 KB Output is correct
9 Correct 6 ms 6528 KB Output is correct
10 Correct 6 ms 6528 KB Output is correct
11 Correct 6 ms 6528 KB Output is correct
12 Correct 6 ms 6528 KB Output is correct
13 Correct 6 ms 6528 KB Output is correct
14 Correct 7 ms 6656 KB Output is correct
15 Correct 6 ms 6528 KB Output is correct
16 Correct 6 ms 6528 KB Output is correct
17 Correct 6 ms 6528 KB Output is correct
18 Correct 6 ms 6528 KB Output is correct
19 Correct 6 ms 6528 KB Output is correct
20 Correct 6 ms 6528 KB Output is correct
21 Correct 6 ms 6528 KB Output is correct
22 Correct 6 ms 6528 KB Output is correct
23 Correct 6 ms 6528 KB Output is correct
24 Correct 6 ms 6528 KB Output is correct
25 Correct 6 ms 6528 KB Output is correct
26 Correct 6 ms 6528 KB Output is correct
27 Correct 6 ms 6528 KB Output is correct
28 Correct 6 ms 6528 KB Output is correct
29 Correct 112 ms 6776 KB Output is correct
30 Correct 156 ms 6656 KB Output is correct
31 Correct 153 ms 6832 KB Output is correct
32 Correct 117 ms 6784 KB Output is correct
33 Correct 103 ms 6648 KB Output is correct
34 Correct 158 ms 6656 KB Output is correct
35 Correct 167 ms 6932 KB Output is correct
36 Correct 70 ms 6656 KB Output is correct
37 Correct 132 ms 6656 KB Output is correct
38 Correct 140 ms 6656 KB Output is correct
39 Correct 122 ms 6784 KB Output is correct
40 Correct 108 ms 6656 KB Output is correct
41 Correct 108 ms 6776 KB Output is correct
42 Correct 107 ms 6656 KB Output is correct
43 Correct 124 ms 6776 KB Output is correct
44 Correct 147 ms 6656 KB Output is correct
45 Correct 173 ms 6780 KB Output is correct
46 Correct 189 ms 6656 KB Output is correct
47 Correct 104 ms 6776 KB Output is correct
48 Correct 113 ms 6656 KB Output is correct
49 Correct 132 ms 6664 KB Output is correct
50 Correct 153 ms 6784 KB Output is correct
51 Correct 107 ms 6780 KB Output is correct
52 Correct 122 ms 6656 KB Output is correct
53 Correct 144 ms 6776 KB Output is correct
54 Correct 174 ms 6656 KB Output is correct
55 Execution timed out 2041 ms 16504 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 6528 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Correct 5 ms 6656 KB Output is correct
4 Correct 5 ms 6528 KB Output is correct
5 Correct 5 ms 6528 KB Output is correct
6 Correct 6 ms 6528 KB Output is correct
7 Correct 5 ms 6656 KB Output is correct
8 Correct 6 ms 6528 KB Output is correct
9 Correct 6 ms 6528 KB Output is correct
10 Correct 6 ms 6528 KB Output is correct
11 Correct 6 ms 6528 KB Output is correct
12 Correct 6 ms 6528 KB Output is correct
13 Correct 6 ms 6528 KB Output is correct
14 Correct 7 ms 6656 KB Output is correct
15 Correct 6 ms 6528 KB Output is correct
16 Correct 6 ms 6528 KB Output is correct
17 Correct 6 ms 6528 KB Output is correct
18 Correct 6 ms 6528 KB Output is correct
19 Correct 6 ms 6528 KB Output is correct
20 Correct 6 ms 6528 KB Output is correct
21 Correct 6 ms 6528 KB Output is correct
22 Correct 6 ms 6528 KB Output is correct
23 Correct 6 ms 6528 KB Output is correct
24 Correct 6 ms 6528 KB Output is correct
25 Correct 6 ms 6528 KB Output is correct
26 Correct 6 ms 6528 KB Output is correct
27 Correct 6 ms 6528 KB Output is correct
28 Correct 6 ms 6528 KB Output is correct
29 Correct 112 ms 6776 KB Output is correct
30 Correct 156 ms 6656 KB Output is correct
31 Correct 153 ms 6832 KB Output is correct
32 Correct 117 ms 6784 KB Output is correct
33 Correct 103 ms 6648 KB Output is correct
34 Correct 158 ms 6656 KB Output is correct
35 Correct 167 ms 6932 KB Output is correct
36 Correct 70 ms 6656 KB Output is correct
37 Correct 132 ms 6656 KB Output is correct
38 Correct 140 ms 6656 KB Output is correct
39 Correct 122 ms 6784 KB Output is correct
40 Correct 108 ms 6656 KB Output is correct
41 Correct 108 ms 6776 KB Output is correct
42 Correct 107 ms 6656 KB Output is correct
43 Correct 124 ms 6776 KB Output is correct
44 Correct 147 ms 6656 KB Output is correct
45 Correct 173 ms 6780 KB Output is correct
46 Correct 189 ms 6656 KB Output is correct
47 Correct 104 ms 6776 KB Output is correct
48 Correct 113 ms 6656 KB Output is correct
49 Correct 132 ms 6664 KB Output is correct
50 Correct 153 ms 6784 KB Output is correct
51 Correct 107 ms 6780 KB Output is correct
52 Correct 122 ms 6656 KB Output is correct
53 Correct 144 ms 6776 KB Output is correct
54 Correct 174 ms 6656 KB Output is correct
55 Correct 298 ms 17016 KB Output is correct
56 Correct 680 ms 22520 KB Output is correct
57 Correct 294 ms 19320 KB Output is correct
58 Correct 368 ms 20472 KB Output is correct
59 Correct 405 ms 20344 KB Output is correct
60 Correct 354 ms 18812 KB Output is correct
61 Correct 534 ms 20088 KB Output is correct
62 Correct 791 ms 20984 KB Output is correct
63 Correct 414 ms 19960 KB Output is correct
64 Correct 584 ms 20484 KB Output is correct
65 Correct 263 ms 17660 KB Output is correct
66 Correct 351 ms 19320 KB Output is correct
67 Correct 649 ms 21240 KB Output is correct
68 Correct 788 ms 21368 KB Output is correct
69 Execution timed out 2041 ms 22168 KB Time limit exceeded
70 Halted 0 ms 0 KB -