답안 #412704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412704 2021-05-27T11:16:33 Z 송준혁(#7518) Bread First Search (CCO21_day2problem2) C++17
0 / 25
1 ms 204 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]] = 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-1], D[i]);
		D[r] = max(D[r], D[i-1] + 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 204 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 Incorrect 1 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 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 Incorrect 1 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 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 Incorrect 1 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -