이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Bismillahir-Rahmanir-Rahim
#include <bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long
#define ld long double
#define dbg(x) cerr << #x << " = " << x << "\n";
#define ff first
#define ss second
#define y1 lol
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma comment (linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
const long long INF = 1e9 + 7;
const long long MOD = 1e9 + 7;
const int maxn = 1e5 + 10;
const int lg = 30;
int n, Q, dp[maxn];
vector <int> g[maxn];
vector <pair <int, pair <int, int> > > v;
queue <int> q;
void press_F_() {
cin >> n >> Q;
for (int i = 1; i <= n; i++) {
int l, r;
cin >> l >> r;
v.pb({r, {l, i}});
}
sort(v.begin(), v.end());
while(Q--) {
int s, e;
cin >> s >> e;
for (int i = 1; i <= n; i++) {
dp[i] = INF;
}
dp[s] = 0;
for (int i = 0; i <= v.size(); i++) {
for (int j = i + 1; j < v.size(); j++) {
if (v[j].ss.ff <= v[i].ff) {
dp[v[j].ss.ss] = min(dp[v[j].ss.ss], dp[v[i].ss.ss] + 1);
}
}
}
if (dp[e] == INF) {
cout << "impossible" << '\n';
} else {
cout << dp[e] << '\n';
}
}
}
int main() {
flash;
int T = 1;
// cin >> T;
for (int _ = 1; _ <= T; ++_) {
// cout << "Case " << i << ": ";
press_F_();
}
//Respa gold 2025 InshAllah
// return 0;
}
/*
Maybe not today and tomorrow, but InshAllah one day I will reach cm
*/
// g++ -std=c++17 main.cpp
// ./a.out
컴파일 시 표준 에러 (stderr) 메시지
events.cpp: In function 'void press_F_()':
events.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 0; i <= v.size(); i++) {
| ~~^~~~~~~~~~~
events.cpp:49:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int j = i + 1; j < v.size(); j++) {
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |