Submission #696383

# Submission time Handle Problem Language Result Execution time Memory
696383 2023-02-06T11:10:07 Z youngyojun Bread First Search (CCO21_day2problem2) C++17
5 / 25
2000 ms 460 KB
#include <bits/stdc++.h>
#define upmin(a,b) (a)=(min((a),(b)))
#define INF (0x3f3f3f3f)
using namespace std;

const int MAXN = 5'005;

int D[MAXN], L[MAXN];

int A[MAXN];

int N;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

{
	int M;
	cin >> N >> M;
	fill_n(A, N+2, INF);
	while(M--) {
		int a, b; cin >> a >> b;
		if(a > b) swap(a, b);
		upmin(A[b], a);
	}
}

	L[N+1] = N;
	for(int i = N; i; i--) L[i] = min({L[i+1], A[i], i-1});

	for(int i = N; i; i--) {
		int r = 0;
		for(int j = N+1; i < j; j--) if(i <= L[j]) {
			if(1 == i && 2 != j) continue;
			int t = D[j];
			for(int v = N; j <= v; v--)
				if(A[v] < j) t++;
			if(r < t) r = t;
		}
		D[i] = r;
	}

	cout << N-1 - D[1] << '\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 2 ms 332 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 2 ms 332 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Execution timed out 2082 ms 460 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 2 ms 332 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Execution timed out 2082 ms 460 KB Time limit exceeded
24 Halted 0 ms 0 KB -