답안 #1120146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1120146 2024-11-28T05:38:28 Z vjudge1 Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 9664 KB
//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, dst[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());
	for (int i = 0; i < v.size(); i++) {
		for (int j = i - 1; j >= 0; j--) {
			if (v[i].ss.ff > v[j].ff) {
				break;
			}
			g[v[j].ss.ss].pb(v[i].ss.ss);
		}
	}
	while(Q--) {
		for (int i = 1; i <= n; i++) {
			dst[i] = INF;
		}
		int s, e;
		cin >> s >> e;
		dst[s] = 0;
		q.push(s);
		while(!q.empty() > 0) {
			int v = q.front();
			q.pop();
			for (auto to: g[v]) {
				if (dst[to] > dst[v] + 1) {
					dst[to] = dst[v] + 1;
					q.push(to);
				}
			}
		}
		if (dst[e] == INF) {
			cout << "impossible" << '\n';
		} else {
			cout << dst[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

Compilation message

events.cpp: In function 'void press_F_()':
events.cpp:41:20: 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]
   41 |  for (int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2640 KB Output is correct
2 Execution timed out 1581 ms 9664 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2640 KB Output is correct
2 Correct 3 ms 2640 KB Output is correct
3 Correct 4 ms 2644 KB Output is correct
4 Correct 4 ms 2644 KB Output is correct
5 Correct 4 ms 2644 KB Output is correct
6 Correct 8 ms 3668 KB Output is correct
7 Correct 16 ms 4436 KB Output is correct
8 Correct 22 ms 5512 KB Output is correct
9 Incorrect 11 ms 5392 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2640 KB Output is correct
2 Correct 3 ms 2640 KB Output is correct
3 Correct 4 ms 2644 KB Output is correct
4 Correct 4 ms 2644 KB Output is correct
5 Correct 4 ms 2644 KB Output is correct
6 Correct 8 ms 3668 KB Output is correct
7 Correct 16 ms 4436 KB Output is correct
8 Correct 22 ms 5512 KB Output is correct
9 Incorrect 11 ms 5392 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2640 KB Output is correct
2 Correct 3 ms 2640 KB Output is correct
3 Correct 4 ms 2644 KB Output is correct
4 Correct 4 ms 2644 KB Output is correct
5 Correct 4 ms 2644 KB Output is correct
6 Correct 8 ms 3668 KB Output is correct
7 Correct 16 ms 4436 KB Output is correct
8 Correct 22 ms 5512 KB Output is correct
9 Incorrect 11 ms 5392 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1555 ms 7504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2640 KB Output is correct
2 Execution timed out 1581 ms 9664 KB Time limit exceeded
3 Halted 0 ms 0 KB -