Submission #883551

#TimeUsernameProblemLanguageResultExecution timeMemory
883551vjudge1Passport (JOI23_passport)C++17
16 / 100
2050 ms1048576 KiB
#include <bits/stdc++.h> //#pragma GCC optimize("O3") //#pragma GCC target("avx,avx2,fma") #define sz(x) (x).size() #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using db = long double; // or double, if TL is tight using str = string; using ii = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; vector<ii> S; for(int i = 0; i < n; ++i) { int l, r; cin >> l >> r; --l; --r; S.push_back({l, r}); } int q; cin >> q; for(int nrq = 0; nrq < q; ++nrq) { vector<vi> DP(n, vi(n, -1)); int x0; cin >> x0; --x0; DP[x0][x0] = 0; for(int len = 1; len <= n; ++len) { for(int i = 0; i < n; ++i) { int j = i + len - 1; if(j >= n || DP[i][j] == -1) continue; for(int k = i; k <= j; ++k) { int ni = min(i, S[k].first), nj = max(j, S[k].second); if(DP[ni][nj] == -1 || DP[ni][nj] > 1 + DP[i][j]) { DP[ni][nj] = DP[i][j] + 1; } } } } cout << DP[0][n - 1] << "\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...