답안 #869907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869907 2023-11-06T08:52:57 Z borisAngelov Passport (JOI23_passport) C++17
40 / 100
2000 ms 17012 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 == 0 || ans > n)
        {
            cout << -1 << "\n";
        }
        else
        {
            cout << ans << "\n";
        }
    }

    return 0;
}
# 결과 실행 시간 메모리 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 1 ms 604 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 468 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 468 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 1 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 1181 ms 6484 KB Output is correct
17 Correct 493 ms 7508 KB Output is correct
18 Correct 11 ms 5212 KB Output is correct
19 Correct 19 ms 4956 KB Output is correct
20 Correct 1585 ms 12956 KB Output is correct
21 Correct 687 ms 7140 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1143 ms 7244 KB Output is correct
24 Correct 595 ms 3312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 468 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 1 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 1181 ms 6484 KB Output is correct
17 Correct 493 ms 7508 KB Output is correct
18 Correct 11 ms 5212 KB Output is correct
19 Correct 19 ms 4956 KB Output is correct
20 Correct 1585 ms 12956 KB Output is correct
21 Correct 687 ms 7140 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1143 ms 7244 KB Output is correct
24 Correct 595 ms 3312 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 464 KB Output is correct
27 Correct 1659 ms 15784 KB Output is correct
28 Correct 1107 ms 17012 KB Output is correct
29 Execution timed out 2065 ms 11736 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 604 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -