이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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";
}
컴파일 시 표준 에러 (stderr) 메시지
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |