답안 #670344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670344 2022-12-08T17:18:52 Z efedmrlr Uplifting Excursion (BOI22_vault) C++17
0 / 100
50 ms 99236 KB
#include <bits/stdc++.h>
#define li long long int
#define MP make_pair
#define pb push_back

using namespace std;

const int N = 5e3+5;
const int Q = 1e5+5;
const int MOD = 1e9+7;

int n,m,q;
vector<pair<int,int> > events;
vector<int> adj[N];
vector<pair<int,int> > queries(Q);
int dists[N][N];
bool vis[N];
void bfs(int x) {
    queue<int> nodes;
    nodes.push(x);
    nodes.push(-1);
    for (int i = 1; i <= n; i++)
    {
        vis[i] = false;
    }
    int dist = 0;
    int cur;
    while (nodes.size() > 1) {
        cur = nodes.front();
        nodes.pop();
        if(cur==-1) {
            dist++;
            nodes.push(-1);
            continue;
        }
        dists[x][cur] = dist;
        if(vis[cur]) continue;
        vis[cur] = true;
        for (int i = 0; i < adj[cur].size(); i++)
        {
            if(vis[adj[cur][i]]) continue;
            nodes.push(adj[cur][i]);
        }
        
    }
}

void solve() {
    cin>>n>>q;
    events.pb(MP(-1,-1));
    for (int i = 1; i <= n; i++)
    {
        int tmp1,tmp2;
        cin>>tmp1>>tmp2;
        events.pb(MP(tmp1,tmp2));

    }
    for (int i = 0; i < q; i++)
    {
        cin>>queries[i].first>>queries[i].second;
    }
    
    for (int i = 1; i <= n; i++)
    {
        for (int j = i+1; j <= n; j++)
        {

            if(events[i].second > events[j].second &&
                 events[j].second >= events[i].first) {
                adj[j].pb(i);
                //cout<<j<<" >> "<<i<<"\n";
            }
            else if(events[j].second > events[i].second &&
                     events[i].second >= events[j].first) {
                adj[i].pb(j);
                //cout<<i<<" >> "<<j<<"\n";
            }
            else if(events[j].second == events[i].second) {
                adj[i].pb(j); adj[j].pb(i);
            }
        }
        
    }
    int res;
    memset(dists, -1, sizeof(dists));
    for (int i = 1; i <= n; i++)
    {
        bfs(i);
    }
    
    for (int i = 0; i < q; i++)
    {
        res = dists[queries[i].first][queries[i].second];
        
        if(res == -1) cout<<"impossible\n";
        else cout<<res<<"\n";  
    }
    


    


    
}

signed main() {
    solve();
}

Compilation message

vault.cpp: In function 'void bfs(int)':
vault.cpp:39:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for (int i = 0; i < adj[cur].size(); i++)
      |                         ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 50 ms 99236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 50 ms 99236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 99160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 99160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 99160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 50 ms 99236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 99160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 50 ms 99236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 99160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 50 ms 99236 KB Output isn't correct
2 Halted 0 ms 0 KB -