제출 #1120219

#제출 시각아이디문제언어결과실행 시간메모리
1120219madiyarEvent Hopping (BOI22_events)C++17
10 / 100
1598 ms58508 KiB
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
vector<ll> g[200100];
ll d[200100];
bool ok(pair<ll, pair<ll, ll>> a, pair<ll, pair<ll, ll>> b) {
    return (b.s.f <= a.f && a.f <= b.f);
}
void solve() {
    ll n; cin>>n;
    ll Q; cin>>Q;
    vector<pair<ll, pair<ll, ll>>> v;
    for(ll i=1; i<=n; i++) {
        ll l,r; cin>>l>>r;
        v.push_back({r, {l, i}});
    }
    sort(v.begin(), v.end());
    for(ll i=0; i<v.size(); i++) {
        for(ll j=0; j<v.size(); j++) {
            if(ok(v[i], v[j])) {
                g[v[i].s.s].push_back(v[j].s.s);
            }
        }
    }
    while(Q--) {
        ll x,y; cin>>x>>y;
        queue<ll> q;
        for(ll i=1; i<=n; i++) d[i]=1e18;
        d[x]=0;
        q.push(x);
        while(!q.empty()) {
            ll v=q.front();
            q.pop();
            for(auto to: g[v]) {
                if(d[to] > d[v]+1) {
                    d[to]=d[v]+1;
                    q.push(to);
                }
            }
        }
        if(d[y] == 1e18) cout<<"impossible\n";
        else cout<<d[y]<<'\n';
    }
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--) {
        solve();
        cout<<'\n';
    }
}

컴파일 시 표준 에러 (stderr) 메시지

events.cpp: In function 'void solve()':
events.cpp:20:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(ll i=0; i<v.size(); i++) {
      |                 ~^~~~~~~~~
events.cpp:21:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for(ll j=0; j<v.size(); j++) {
      |                     ~^~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...