답안 #593954

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
593954 2022-07-11T18:02:35 Z CaroLinda Event Hopping (BOI22_events) C++14
0 / 100
1500 ms 4180 KB
#include <bits/stdc++.h>

//bad complexity to test idea

#define ll long long

const int MAXN = 1010;

using namespace std;

int N, Q;
int S[MAXN], E[MAXN];
int nxt[MAXN];
int mat[MAXN][MAXN];

void findNxtArray(){
	for(int i = 1; i <= N; i++){
		nxt[i] = -1;
		mat[i][i] = 1;

		for(int j = 1; j <= N; j++){
			if(j == i) 
				continue;
			if(!(E[j] >= S[i] && E[j] <= E[i]))
				continue;

			mat[i][j] = 1;

			if(nxt[i] == -1 || S[nxt[i]] > S[j])
				nxt[i] = j;
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> N >> Q;
	for(int i = 1; i <= N; i++)
		cin >> S[i] >> E[i];

	findNxtArray();

	for(int i = 1, a, b; i <= Q; i++){
		cin >> a >> b;

		int ans = 0;

		while(!mat[b][a] && nxt[b] != -1){
			b = nxt[b];
			ans++;
		}

		ans += (a != b);

		if(nxt[b] == -1 || !mat[b][a]){
			cout << "impossible\n";
		}
		else cout << ans << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 1 ms 468 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 0 ms 340 KB Output is correct
3 Correct 5 ms 4176 KB Output is correct
4 Correct 5 ms 4168 KB Output is correct
5 Correct 4 ms 4180 KB Output is correct
6 Execution timed out 1581 ms 4180 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 5 ms 4176 KB Output is correct
4 Correct 5 ms 4168 KB Output is correct
5 Correct 4 ms 4180 KB Output is correct
6 Execution timed out 1581 ms 4180 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 5 ms 4176 KB Output is correct
4 Correct 5 ms 4168 KB Output is correct
5 Correct 4 ms 4180 KB Output is correct
6 Execution timed out 1581 ms 4180 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 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 1 ms 468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -