답안 #656526

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
656526 2022-11-07T18:58:55 Z Lobo Event Hopping (BOI22_events) C++17
0 / 100
4 ms 2644 KB
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

const int maxn = 1e5+10;

int n, q, lf[maxn], rg[maxn], sq[maxn], eq[maxn], ansq[maxn], atv[maxn];
vector<int> qrys[maxn];
void solve() {
    cin >> n >> q;
    vector<pair<pair<int,int>,int>> ord; // first smaller rg and smaller lf
    for(int i = 1; i <= n; i++) {
        cin >> lf[i] >> rg[i];
        ord.pb(mp(mp(rg[i],lf[i]),i));
    }
    sort(all(ord));

    for(int i = 1; i <= q; i++) {
        cin >> sq[i] >> eq[i];
        qrys[eq[i]].pb(i);
    }

    for(auto X : ord) {
        int i = X.sc;
        // cout << i << endl;
        atv[i] = 1;

        for(auto id : qrys[i]) {
            // cout << " " << id << endl;
            int j = sq[id];
            if(i == j) {
                ansq[id] = 0;
                continue;
            }
            if(rg[i] == rg[j]) {
                ansq[id] = 1;
                continue;
            }
            if(atv[j] == 0) {
                ansq[id] = -1;
                continue;
            }
            ansq[id] = 0;
            while(j != i) {
                int nx = -1;
                for(int k = 1; k <= n; k++) {
                    if(atv[k] == 0 || lf[k] > rg[j]) continue;
                    if(k == i) {
                        nx = k;
                        break;
                    }
                    if(nx == -1 || rg[nx] < rg[k]) nx = k;
                }
                if(nx == j) {
                    ansq[id] = -1;
                    break;
                }
                j = nx;
                ansq[id]++;
                if(j == i) {
                    break;
                }
                if(rg[j] == rg[i]) {
                    ansq[id]++;
                    break;
                }
            }
        }
    }

    for(int i = 1; i <= q; i++) {
        if(ansq[i] == -1) cout << "impossible" << endl;
        else cout << ansq[i] << endl;
    }
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }

}

Compilation message

events.cpp: In function 'int32_t main()':
events.cpp:89:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |     freopen("in.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -