이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> L(N), R(N);
for (int i = 0; i < N; i++) {
cin >> L[i] >> R[i];
L[i]--;
}
int Q, X;
cin >> Q >> X;
X--;
if (N <= 300) {
vector<int> dp(N);
iota(dp.begin(), dp.end(), 0);
dp[X] = X + 1;
for (int ans = 1; ; ans++) {
auto pd = dp;
iota(dp.begin(), dp.end(), 0);
for (int i = 0; i < N; i++) {
for (int j = i; j < pd[i]; j++) {
dp[min(i, L[j])] = max({dp[min(i, L[j])], pd[i], R[j]});
}
}
if (dp[0] == N) {
cout << ans << "\n";
return 0;
}
if (dp == pd) {
break;
}
}
cout << -1 << "\n";
return 0;
}
int ans = 0;
for (int f = R[0]; X < N - 1;) {
if (X == f) {
ans = -1;
break;
}
ans++;
for (int i = f - X; i; i--) {
f = max(f, R[++X]);
}
}
cout << ans << "\n";
return 6/22;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |