Submission #1108294

# Submission time Handle Problem Language Result Execution time Memory
1108294 2024-11-03T16:58:24 Z VMaksimoski008 Passport (JOI23_passport) C++17
0 / 100
1257 ms 1048576 KB
#include <bits/stdc++.h>
#define ar array
//#define int long long

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 2e5 + 5;

signed main() {
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

    int n; cin >> n;
    vector<int> G[n+1], L(n+1), R(n+1);

    for(int i=1; i<=n; i++) {
        cin >> L[i] >> R[i];
        for(int j=L[i]; j<=R[i]; j++) G[i].push_back(j);
    }

    int q; cin >> q;
    while(q--) {
        int s; cin >> s;
        int dist[n+1][n+1][n+1], vis[n+1][n+1][n+1];
        memset(dist, 0, sizeof(dist));
        memset(vis, 0, sizeof(vis));

        vis[s][L[s]][R[s]] = 1;
        queue<ar<int, 3> > q;
        q.push({ s, L[s], R[s] });

        while(!q.empty()) {
            auto [u, l, r] = q.front(); q.pop();

            for(int v : G[u]) {
                if(vis[v][min(l, L[v])][max(r, R[v])]) continue;
                vis[v][min(l, L[v])][max(r, R[v])] = 1;
                dist[v][min(l, L[v])][max(r, R[v])] = dist[u][l][r] + 1;
                q.push({ v, min(l, L[v]), max(r, R[v]) });
            }
        }

        int ans = 1e9;
        for(int i=1; i<=n; i++)
            if(vis[i][1][n]) ans = min(ans, dist[i][1][n]);
        cout << (ans == 1e9 ? -1 : ans + 1) << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Runtime error 1257 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 208 ms 185160 KB Output is correct
12 Incorrect 215 ms 205640 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 208 ms 185160 KB Output is correct
12 Incorrect 215 ms 205640 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 208 ms 185160 KB Output is correct
12 Incorrect 215 ms 205640 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Runtime error 1257 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -