제출 #997497

#제출 시각아이디문제언어결과실행 시간메모리
997497AbitoPassport (JOI23_passport)C++17
16 / 100
12 ms3348 KiB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=305;
int dp[N][N],L[N],R[N],n,q;
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>L[i]>>R[i];
    for (int i=1;i<=n;i++) for (int j=i;j<=n;j++) dp[i][j]=INT_MAX;
    dp[1][n]=0;
    for (int len=n-2;len>=0;len--){
        for (int l=1;l+len<=n;l++){
            int r=l+len;
            for (int k=l;k<=r;k++){
                int l1=min(L[k],l),r1=max(R[k],r);
                dp[l][r]=min(dp[l][r],dp[l1][r1]+1);
            }
        }
    }
    cin>>q;
    while (q--){
        int x;cin>>x;
        if (dp[x][x]>=INT_MAX) cout<<-1<<endl;
        else cout<<dp[x][x]<<endl;
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...