Submission #793918

#TimeUsernameProblemLanguageResultExecution timeMemory
793918vjudge1Passport (JOI23_passport)C++14
22 / 100
2066 ms34292 KiB
#include<bits/stdc++.h> #define fi first #define se second #define ll long long using namespace std ; const int N = 2e5 ; int n, q, l[N + 1], r[N + 1], x[N + 1] ; int main() { ios_base::sync_with_stdio( 0 ) ; cin.tie( 0 ) ; cout.tie( 0 ) ; cin >> n ; for(int i = 1 ; i <= n ; i++) cin >> l[i] >> r[i] ; cin >> q ; for(int i = 1 ; i <= q ; i++) cin >> x[i] ; if(q == 1 && x[1] == 1) { int ans = 0, mx = r[1], ind = 1 ; while(ind < n) { int mx1 = 0 ; for(int j = ind ; j <= mx ; j++) mx1 = max(mx1, r[j]) ; ans++ ; ind = mx ; if(mx1 == mx) break ; mx = max(mx1, mx) ; } if(ind < n) ans = -1 ; cout << ans ; return 0 ; } if(q == 1 && n <= 2500) { int ans[n + 1][n + 1] ; for(int i = 1 ; i <= n ; i++) for(int j = 1 ; j <= n ; j++) ans[i][j] = 1e9 ; set<pair<int, pair<int, int>>> s ; s.insert({1, {l[x[1]], r[x[1]]}}) ; ans[l[x[1]]][r[x[1]]] = 1 ; while(s.size()) { auto j = *s.begin() ; int cnt = j.fi, ln = j.se.fi, rn = j.se.se ; s.erase(j) ; if(cnt > ans[ln][rn]) continue ; for(int q = ln ; q <= rn ; q++) { int lch = min(ln, l[q]), rch = max(rn, r[q]), cntch = cnt + 1 ; if(cntch < ans[lch][rch]) { ans[lch][rch] = cntch ; s.insert({cntch, {lch, rch}}) ; } } } if(ans[1][n] == 1e9)ans[1][n] = -1 ; cout << ans[1][n] ; return 0 ; } 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...