이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = 2; i <= N; i++) {
int r = INF;
for(int j = L[i+1]; --j;) {
int t = D[j];
for(int v = i; j < v; v--)
if(j < A[v]) t++;
upmin(r, t);
}
D[i] = r;
}
cout << D[N] << '\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... |