답안 #794047

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794047 2023-07-26T08:58:00 Z vjudge1 Passport (JOI23_passport) C++17
0 / 100
1 ms 244 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 3010;
const int INF = 1e9;

int n;
int dp[N][N];
int L[N], R[N];

vector<vector<int>> ans;
int recur(int l, int r) {
    if(l == 1 && r == n) ans[l][r] = 0;
    if(ans[l][r] != -1) return ans[l][r];
    ans[l][r] = INF;
    for(int i = l; i <= r; i++) {
        if(l <= L[i] && R[i] <= r) continue;
        ans[l][r] = min(ans[l][r], recur(min(l, L[i]), max(r, R[i])) + 1);
    }
    return ans[l][r];
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> L[i] >> R[i];
    int mx[n + 1] = {};
    for(int i = 1; i <= n; i++) 
        mx[i] = max(mx[i - 1], R[i]);
    // if(n <= 300) {
    //     dp[1][n] = 0;
    //     for(int len = n - 1; len >= 1; len--) {
    //         for(int l = 1; l <= n - len + 1; l++) {
    //             int r = l + len - 1;
    //             dp[l][r] = INF;
    //             for(int i = l; i <= r; i++) {
    //                 dp[l][r] = min(dp[l][r], dp[min(l, L[i])][max(r, R[i])] + 1);
    //             } 
    //         }
    //     }   
    //     int q;
    //     cin >> q;
    //     while(q--) {
    //         int x;
    //         cin >> x;
    //         cout << (dp[x][x] == INF ? -1 : dp[x][x]) << '\n';
    //     }
    //     return 0;
    // }
    if(n <= 2500) {
        int q;
        cin >> q;
        int x;
        cin >> x;
        ans.resize(n + 10, vector<int>(n + 10, -1));
        cout << recur(x, x);
        return 0;
    }
    int q;
    cin >> q;
    int x, res = 0;
    cin >> x;
    while(x < n) {
        res++;
        if(mx[x] == x) {
            cout << -1;
            return 0;
        }
        x = max(x, mx[x]);
    }
    cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 244 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 244 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 244 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -