# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
659832 | 2022-11-19T11:45:02 Z | 600Mihnea | Event Hopping (BOI22_events) | C++17 | 1500 ms | 1360 KB |
bool home = 0; #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = (int) 1e5 + 7; int n; int q; struct T { int l; int r; }; T v[N]; int dp[N]; int nxt[N]; int main() { if (!home) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } else { freopen("input.txt", "r", stdin); } cin >> n >> q; for (int i = 1; i <= n; i++) { cin >> v[i].l >> v[i].r; } for (int i = 1; i <= n; i++) { nxt[i] = -1; for (int j = 1; j <= n; j++) { if (v[j].l <= v[i].r) { if (nxt[i] == -1) { nxt[i] = j; } else { if (v[j].r > v[nxt[i]].r) { nxt[i] = j; } } } } if (nxt[i] != -1 && v[i].r >= v[nxt[i]].r) { nxt[i] = -1; } } for (int iq = 1; iq <= q; iq++) { int ff, ss; cin >> ff >> ss; for (int i = 1; i <= n; i++) { dp[i] = -1; } int co = 0; while (nxt[ff] != -1 && v[nxt[ff]].r <= v[ss].l) { ff = nxt[ff]; co++; } queue<int> q; q.push(ff); dp[ff] = 0; while (!q.empty()) { int a = q.front(); q.pop(); for (int b = 1; b <= n; b++) { if (v[b].l <= v[a].r && v[a].r <= v[b].r && dp[b] == -1) { dp[b] = 1 + dp[a]; q.push(b); } } } if (dp[ss] == -1) { cout << "impossible\n"; continue; } assert(dp[ss] <= 3); cout << co + dp[ss] << "\n"; } return 0; } /** **/
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Execution timed out | 1584 ms | 1356 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 6 ms | 340 KB | Output is correct |
4 | Correct | 57 ms | 340 KB | Output is correct |
5 | Runtime error | 13 ms | 480 KB | Execution killed with signal 6 |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 6 ms | 340 KB | Output is correct |
4 | Correct | 57 ms | 340 KB | Output is correct |
5 | Runtime error | 13 ms | 480 KB | Execution killed with signal 6 |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 6 ms | 340 KB | Output is correct |
4 | Correct | 57 ms | 340 KB | Output is correct |
5 | Runtime error | 13 ms | 480 KB | Execution killed with signal 6 |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1566 ms | 1360 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Execution timed out | 1584 ms | 1356 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |