답안 #849230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849230 2023-09-14T09:41:01 Z vjudge1 Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 1880 KB
#include <bits/stdc++.h>
#define all(v) ((v).begin(),(v).end())
#define ll long long
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll mxN = 1e5 + 2;
using namespace std;
pair<int,int>a[mxN];
pair<int,int>og[mxN];
signed main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0  );
  int n,q;
  cin >>n>>q;
  for(int i = 0;i < n;i++){
    cin >>a[i].F>>a[i].S;
    og[i] = a[i];
  }
  sort(a,a + n);
  while(q--){
    int s,e;
    cin >>s>>e;
    auto x = og[s - 1],y = og[e - 1];
    int ans = 0;
    int i = lower_bound(a,a + n,x) - a;
    while(x != y){
      int nxt = -1;
      i++;
      while(i < n){
        if(a[i].F <= x.S && a[i].S >= x.S && a[i].S <= y.S){
          if(nxt == -1 || a[i].S >= a[nxt].S){
            nxt = i;
          }
        }
        if(a[i] == y) break;
        i++;
      }
      if(nxt == -1){
        cout<<"impossible\n";
        ans = -1;
        break;
      }
      x = a[nxt];
      i = nxt;
      ans++;
    }
    if(ans != -1) cout<<ans<<'\n';
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 1556 ms 1848 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 48 ms 348 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Incorrect 1 ms 344 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 48 ms 348 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Incorrect 1 ms 344 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 48 ms 348 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Incorrect 1 ms 344 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1541 ms 1880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 1556 ms 1848 KB Time limit exceeded
3 Halted 0 ms 0 KB -