Submission #632224

# Submission time Handle Problem Language Result Execution time Memory
632224 2022-08-19T16:38:31 Z gs14004 Bread First Search (CCO21_day2problem2) C++17
11 / 25
2000 ms 5584 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
const int MAXN = 1005;
const int mod = 1e9 + 7;

int main(){	
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> L(n, 1e9), R(n, -1e9), dp(n + 1), nxt(n, 1e9);
	for(int i = 0; i < m; i++){
		int u, v; cin >> u >> v;
		u--; v--;
		if(u > v) swap(u, v);
		R[u] = max(R[u], v);
		L[v] = min(L[v], u);
	}
	for(int i = 0; i < n; i++){
		nxt[i] = R[i];
		if(i) nxt[i] = max(nxt[i], nxt[i - 1]);
	}
	vector<pi> swp;
	for(int i = 0; i < n; i++) swp.emplace_back(min(i, L[i]), i);
	sort(all(swp)); 
	for(int i = n - 1; i >= 1; i--){
		while(sz(swp) && swp.back().first >= i){
			for(int k = swp.back().second + 1; k <= n; k++) dp[k]++;
			swp.pop_back();
		}
		dp[i] = 1e9;
		int cnt = 0;
		for(int j = max(i, nxt[i - 1]) + 1; j <= n; j++){
			dp[i] = min(dp[i], dp[j]);
		}
	}
	cout << dp[1] << "\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:37:7: warning: unused variable 'cnt' [-Wunused-variable]
   37 |   int cnt = 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 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 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 24 ms 480 KB Output is correct
24 Correct 22 ms 500 KB Output is correct
25 Correct 20 ms 508 KB Output is correct
26 Correct 20 ms 500 KB Output is correct
27 Correct 21 ms 500 KB Output is correct
28 Correct 23 ms 468 KB Output is correct
29 Correct 11 ms 504 KB Output is correct
30 Correct 16 ms 504 KB Output is correct
31 Correct 17 ms 504 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 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 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 24 ms 480 KB Output is correct
24 Correct 22 ms 500 KB Output is correct
25 Correct 20 ms 508 KB Output is correct
26 Correct 20 ms 500 KB Output is correct
27 Correct 21 ms 500 KB Output is correct
28 Correct 23 ms 468 KB Output is correct
29 Correct 11 ms 504 KB Output is correct
30 Correct 16 ms 504 KB Output is correct
31 Correct 17 ms 504 KB Output is correct
32 Execution timed out 2086 ms 5584 KB Time limit exceeded
33 Halted 0 ms 0 KB -