Submission #593954

#TimeUsernameProblemLanguageResultExecution timeMemory
593954CaroLindaEvent Hopping (BOI22_events)C++14
0 / 100
1581 ms4180 KiB
#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"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...