Submission #888761

#TimeUsernameProblemLanguageResultExecution timeMemory
888761vjudge1Passport (JOI23_passport)C++17
22 / 100
2076 ms205140 KiB
/* author : abushbandit contest : --- */ #include "bits/stdc++.h" using namespace std; #define int long long void solve(int tc){ int n; cin >> n; vector<pair<int,int>> a(n + 1); for(int i = 1;i <= n;i++){ int l,r; cin >> l >> r; a[i] = {l,r}; } int q; cin >> q; for(int i = 0;i < q;i++){ int x; cin >> x; if(x == 1){ int i = 1,lst = a[1].second,cnt = 0; bool check = 0; while(true){ cnt++; int mx = 0; while(i <= n && i <= lst){ mx = max(mx,a[i].second); i++; } if(i > n){ break; } else if(lst < mx){ lst = mx; } else{ check = 1; break; } } if(check){ cout << -1 << "\n"; } else{ cout << cnt << "\n"; } break; } else{ vector<vector<int>> dis(n + 1, vector<int> (n + 1,1e18)); vector<vector<int>> vis(n + 1, vector<int> (n + 1,0)); set<vector<int>> st; dis[a[x].first][a[x].second] = 1; st.insert({1,a[x].first,a[x].second}); while(!st.empty()){ int l = (*st.begin())[1], r = (*st.begin())[2]; st.erase(st.begin()); if(vis[l][r])continue; vis[l][r] = 1; for(int i = l;i <= r;i++){ for(int j = r;j <= max(r,a[i].second);j++){ for(int k = l;k >= min(l,a[i].first);k--){ if(dis[l][r] + 1 < dis[k][j]){ st.insert({dis[l][r] + 1,k,j}); dis[k][j] = dis[l][r] + 1; } } } } } if(dis[1][n] == 1e18){ cout << "-1\n"; } else{ cout << dis[1][n] << "\n"; } } } } signed main(){ // start_file(""); ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); int test_cases = 1; // cin >> test_cases ; for(int tc = 1;tc <= test_cases;++ tc){ solve(tc); } } /* */
#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...