Submission #593957

# Submission time Handle Problem Language Result Execution time Memory
593957 2022-07-11T18:07:26 Z CaroLinda Event Hopping (BOI22_events) C++14
10 / 100
8 ms 5588 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(S[j] >= S[i])
				continue;

			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(b != -1 && !mat[b][a]){
			b = nxt[b];
			ans++;
		}

		ans += (a != b);

		if(b == -1 || !mat[b][a]){
			cout << "impossible\n";
		}
		else cout << ans << "\n";
	}
}
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 5 ms 4180 KB Output is correct
4 Correct 6 ms 4180 KB Output is correct
5 Correct 5 ms 4180 KB Output is correct
6 Correct 7 ms 4172 KB Output is correct
7 Correct 7 ms 4180 KB Output is correct
8 Correct 5 ms 4180 KB Output is correct
9 Correct 3 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 5 ms 4180 KB Output is correct
4 Correct 6 ms 4180 KB Output is correct
5 Correct 5 ms 4180 KB Output is correct
6 Correct 7 ms 4172 KB Output is correct
7 Correct 7 ms 4180 KB Output is correct
8 Correct 5 ms 4180 KB Output is correct
9 Correct 3 ms 4180 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 5 ms 4180 KB Output is correct
13 Correct 6 ms 4180 KB Output is correct
14 Correct 5 ms 4180 KB Output is correct
15 Correct 6 ms 4180 KB Output is correct
16 Correct 8 ms 4180 KB Output is correct
17 Correct 5 ms 4180 KB Output is correct
18 Correct 3 ms 4180 KB Output is correct
19 Runtime error 6 ms 5588 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 5 ms 4180 KB Output is correct
4 Correct 6 ms 4180 KB Output is correct
5 Correct 5 ms 4180 KB Output is correct
6 Correct 7 ms 4172 KB Output is correct
7 Correct 7 ms 4180 KB Output is correct
8 Correct 5 ms 4180 KB Output is correct
9 Correct 3 ms 4180 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 5 ms 4180 KB Output is correct
13 Correct 6 ms 4240 KB Output is correct
14 Correct 5 ms 4180 KB Output is correct
15 Correct 6 ms 4228 KB Output is correct
16 Correct 7 ms 4180 KB Output is correct
17 Correct 5 ms 4180 KB Output is correct
18 Correct 3 ms 4180 KB Output is correct
19 Runtime error 1 ms 468 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 -