Submission #926343

#TimeUsernameProblemLanguageResultExecution timeMemory
926343OAleksaPassport (JOI23_passport)C++14
0 / 100
2082 ms9520 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define int long long const int N = 2e5 + 69; int n, l[N], r[N], q; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { cin >> n; for (int i = 1;i <= n;i++) cin >> l[i] >> r[i]; cin >> q; for (int i = 1;i <= q;i++) { int x; cin >> x; vector<int> vis; vector<int> was(n + 1); int c = 1; was[x] = 1; int ans = 0; vis.push_back(x); while (c < n) { int bst = 0, m = -1; for (auto u : vis) { int s = 0; for (int j = l[u];j <= r[u];j++) s += !(was[j]); if (s > bst) { bst = s; m = u; } } if (m == -1) { ans = -1; break; } ++ans; for (int j = l[m];j <= r[m];j++) { if (!was[j]) { was[j] = 1; c++; vis.push_back(j); } } } cout << ans << '\n'; } } return 0; }
#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...