답안 #412713

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412713 2021-05-27T11:26:27 Z 송준혁(#7518) Bread First Search (CCO21_day2problem2) C++17
25 / 25
66 ms 3408 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define MOD 1000000007
#define INF (1ll<<62)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, M;
int L[202020], R[202020];
int D[202020], A[202020];

int main(){
	scanf("%d %d", &N, &M);
	for (int i=1; i<=N; i++) L[i] = R[i] = i;
	while (M--){
		int u, v;
		scanf("%d %d", &u, &v);
		if (u > v) swap(u, v);
		R[u] = max(R[u], v);
		L[v] = min(L[v], u);
	}
	for (int i=2; i<=N; i++) A[L[i]]++, A[i]--;
	int s=0, r=0;
	if (R[1] > 1) D[R[1]] = A[1];
	for (int i=1; i<=N; i++){
		s += A[i], r = max(r, R[i]);
		if (i < R[1]) continue;
		D[i] = max(D[i], D[i-1]);
		D[r] = max(D[r], D[i] + s);
	}
	printf("%d\n", N-D[N]-1);
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  scanf("%d %d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 5 ms 332 KB Output is correct
26 Correct 6 ms 332 KB Output is correct
27 Correct 4 ms 332 KB Output is correct
28 Correct 4 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 9 ms 352 KB Output is correct
31 Correct 9 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 5 ms 332 KB Output is correct
26 Correct 6 ms 332 KB Output is correct
27 Correct 4 ms 332 KB Output is correct
28 Correct 4 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 9 ms 352 KB Output is correct
31 Correct 9 ms 356 KB Output is correct
32 Correct 6 ms 3404 KB Output is correct
33 Correct 6 ms 3408 KB Output is correct
34 Correct 55 ms 2628 KB Output is correct
35 Correct 64 ms 3400 KB Output is correct
36 Correct 64 ms 3400 KB Output is correct
37 Correct 61 ms 3388 KB Output is correct
38 Correct 5 ms 3404 KB Output is correct
39 Correct 7 ms 3404 KB Output is correct
40 Correct 29 ms 1580 KB Output is correct
41 Correct 54 ms 2504 KB Output is correct
42 Correct 61 ms 3264 KB Output is correct
43 Correct 66 ms 3256 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 204 KB Output is correct