This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define upmin(a,b) (a)=(min((a),(b)))
#define upmax(a,b) (a)=(max((a),(b)))
#define INF (0x3f3f3f3f)
using namespace std;
const int MAXN = 5'005;
int L[MAXN], B[MAXN], C[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--) if(A[i] < i) { B[A[i]+1]++; B[i+1]--; }
for(int i = 1; i <= N; i++) B[i+1] += B[i];
int mx = 0;
for(int i = N; 1 < i; i--) {
upmax(mx, C[i]);
upmax(C[L[i]], mx + B[i]);
}
cout << N-1 - (mx + B[2]) << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |