답안 #577885

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
577885 2022-06-15T11:27:23 Z IvanJ Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 30360 KB
#include<bits/stdc++.h>

#define pb push_back

using namespace std;

const int maxn = 5e3 + 5;

int n, q, pot = 1;
vector<int> adj[maxn];
int L[maxn], R[maxn];

int main() {
	scanf("%d%d", &n, &q);
	for(int i = 0;i < n;i++) 
		scanf("%d%d", L + i, R + i);
	
	for(int i = 0;i < n;i++) 
		for(int j = 0;j < n;j++)
			if(i != j && L[j] <= R[i] && R[i] <= R[j])
				adj[i].pb(j);
	
	for(int i = 0;i < q;i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--, y--;
		vector<int> d(n, n);
		queue<int> q;
		q.push(x), d[x] = 0;
		while(q.size()) {
			x = q.front();q.pop();
			if(x == y) break;
			for(int xi : adj[x]) {
				if(d[xi] != n) continue;
				d[xi] = d[x] + 1;
				q.push(xi);	
			}	
		}
		
		if(d[y] == n) printf("impossible\n");
		else printf("%d\n", d[y]);
	}
	return 0;	
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
events.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   scanf("%d%d", L + i, R + i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
events.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   scanf("%d%d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 8 ms 724 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 7 ms 340 KB Output is correct
4 Correct 6 ms 460 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 12 ms 1172 KB Output is correct
7 Correct 24 ms 2060 KB Output is correct
8 Correct 18 ms 3116 KB Output is correct
9 Correct 48 ms 4428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 7 ms 340 KB Output is correct
4 Correct 6 ms 460 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 12 ms 1172 KB Output is correct
7 Correct 24 ms 2060 KB Output is correct
8 Correct 18 ms 3116 KB Output is correct
9 Correct 48 ms 4428 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 6 ms 468 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 6 ms 428 KB Output is correct
15 Correct 10 ms 1236 KB Output is correct
16 Correct 16 ms 2004 KB Output is correct
17 Correct 20 ms 3036 KB Output is correct
18 Correct 48 ms 4452 KB Output is correct
19 Execution timed out 1581 ms 30360 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 7 ms 340 KB Output is correct
4 Correct 6 ms 460 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 12 ms 1172 KB Output is correct
7 Correct 24 ms 2060 KB Output is correct
8 Correct 18 ms 3116 KB Output is correct
9 Correct 48 ms 4428 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 8 ms 468 KB Output is correct
13 Correct 7 ms 468 KB Output is correct
14 Correct 6 ms 340 KB Output is correct
15 Correct 11 ms 1236 KB Output is correct
16 Correct 18 ms 2060 KB Output is correct
17 Correct 18 ms 3028 KB Output is correct
18 Correct 49 ms 4436 KB Output is correct
19 Runtime error 9 ms 724 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 708 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 8 ms 724 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -