답안 #745117

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
745117 2023-05-19T12:13:48 Z onebit1024 Passport (JOI23_passport) C++17
0 / 100
215 ms 65600 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define all(c) c.begin(), c.end()
#define endl "\n"

const double PI=3.141592653589;


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " <<"[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif

const int N = 2501;
int dist[N][N];
bool visited[N][N];

void solve()
{
    int n;
    cin >> n;
    vector<pair<int,int>>range(n+1);
    for(int i = 1;i<=n;++i){
        int l,r;
        cin >> l >> r;
        range[i] = {l,r};
        for(int j = 1;j<=n;++j)dist[i][j] = 1e9,visited[i][j] = 0;
    }

    int Q;
    cin >> Q;
    while(Q--){
        int x;
        cin >> x;


        queue<pair<int,int>>q;
        dist[range[x].first][range[x].second] = 1;
        q.push({range[x].first,range[x].second});
        set<int>left;
        for(int i = 1;i<=n;++i)left.insert(i);
        while(!q.empty()){
            int l = q.front().first ,r = q.front().second;
            q.pop();
            if(visited[l][r])continue;
            visited[l][r] = 1;
            set<int>bac;
            for(int i : left){
                if(i < l || i > r){
                    bac.insert(i);
                    continue;
                }
                
                int k = min(l,range[i].first), j = max(r,range[i].second);
                int curr_dist = dist[k][j], new_dist = dist[l][r]+1;
                if(new_dist < curr_dist){
                    q.push({k,j});
                    dist[k][j] = new_dist;
                }
            }
            left = bac;
        }
        int res = dist[1][n];
        if(res>=1e9)res = -1;
        cout << res << endl;
    }
}   
/*
5
1 1
2 3
1 5
3 4
5 5
1
2
*/
int32_t main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    

    int T=1;
    for(int i = 1;i<=T;++i)
    {
        // cout << "Case #" << i << ": ";
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Runtime error 215 ms 65600 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Runtime error 215 ms 65600 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -