Submission #869908

# Submission time Handle Problem Language Result Execution time Memory
869908 2023-11-06T08:53:44 Z borisAngelov Passport (JOI23_passport) C++17
40 / 100
2000 ms 17128 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 2505;

int n, q;

int l[maxn];
int r[maxn];

int dp[maxn][maxn];

int f(int from, int to)
{
    if (from == 1 && to == n)
    {
        return 0;
    }

    if (dp[from][to] != 0)
    {
        return dp[from][to];
    }

    int result = maxn;

    for (int pos = from; pos <= to; ++pos)
    {
        if (l[pos] < from || r[pos] > to)
        {
            result = min(result, 1 + f(min(from, l[pos]), max(to, r[pos])));
        }
    }

    return dp[from][to] = result;
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> n;

    for (int i = 1; i <= n; ++i)
    {
        cin >> l[i] >> r[i];
    }

    cin >> q;

    for (int i = 1; i <= q; ++i)
    {
        int start;
        cin >> start;

        int ans = f(start, start);

        if (ans > n)
        {
            cout << -1 << "\n";
        }
        else
        {
            cout << ans << "\n";
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Runtime error 2 ms 604 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 2 ms 1116 KB Output is correct
16 Correct 1172 ms 6640 KB Output is correct
17 Correct 495 ms 7692 KB Output is correct
18 Correct 11 ms 5208 KB Output is correct
19 Correct 19 ms 4700 KB Output is correct
20 Correct 1601 ms 12876 KB Output is correct
21 Correct 694 ms 7512 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1166 ms 7572 KB Output is correct
24 Correct 600 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 2 ms 1116 KB Output is correct
16 Correct 1172 ms 6640 KB Output is correct
17 Correct 495 ms 7692 KB Output is correct
18 Correct 11 ms 5208 KB Output is correct
19 Correct 19 ms 4700 KB Output is correct
20 Correct 1601 ms 12876 KB Output is correct
21 Correct 694 ms 7512 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1166 ms 7572 KB Output is correct
24 Correct 600 ms 3796 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1669 ms 15816 KB Output is correct
28 Correct 1096 ms 17128 KB Output is correct
29 Execution timed out 2060 ms 11468 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Runtime error 2 ms 604 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -