답안 #827100

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827100 2023-08-16T08:44:59 Z Hanksburger Passport (JOI23_passport) C++17
48 / 100
2000 ms 25024 KB
#include <bits/stdc++.h>
using namespace std;
int dist[2505][2505], l[200005], r[200005], ans[200005];
queue<int> q;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n;
    for (int i=1; i<=n; i++)
        cin >> l[i] >> r[i];
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
            dist[i][j]=1e8;
        dist[i][i]=0;
        q.push(i);
        int L=i, R=i;
        while (!q.empty())
        {
            int u=q.front();
            q.pop();
            for (int v=l[u]; v<L; v++)
            {
                dist[i][v]=dist[i][u]+1;
                q.push(v);
            }
            for (int v=R+1; v<=r[u]; v++)
            {
                dist[i][v]=dist[i][u]+1;
                q.push(v);
            }
            L=min(L, l[u]);
            R=max(R, r[u]);
        }
    }
    for (int i=1; i<=n; i++)
    {
        ans[i]=min(dist[i][1]+dist[1][n], dist[i][n]+dist[n][1]);
        for (int j=2; j<n; j++)
            ans[i]=min(ans[i], dist[i][j]+dist[j][1]+dist[j][n]-1);
    }
    cin >> m;
    for (int i=1; i<=m; i++)
    {
        int x;
        cin >> x;
        if (ans[x]<5e7)
            cout << ans[x] << '\n';
        else
            cout << -1 << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Execution timed out 2085 ms 21948 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 328 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 1748 KB Output is correct
12 Correct 3 ms 1748 KB Output is correct
13 Correct 2 ms 1860 KB Output is correct
14 Correct 2 ms 1748 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 328 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 1748 KB Output is correct
12 Correct 3 ms 1748 KB Output is correct
13 Correct 2 ms 1860 KB Output is correct
14 Correct 2 ms 1748 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
16 Correct 79 ms 23300 KB Output is correct
17 Correct 91 ms 24732 KB Output is correct
18 Correct 85 ms 24788 KB Output is correct
19 Correct 87 ms 24240 KB Output is correct
20 Correct 71 ms 24880 KB Output is correct
21 Correct 64 ms 24824 KB Output is correct
22 Correct 66 ms 24856 KB Output is correct
23 Correct 82 ms 24896 KB Output is correct
24 Correct 66 ms 24788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 328 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 1748 KB Output is correct
12 Correct 3 ms 1748 KB Output is correct
13 Correct 2 ms 1860 KB Output is correct
14 Correct 2 ms 1748 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
16 Correct 79 ms 23300 KB Output is correct
17 Correct 91 ms 24732 KB Output is correct
18 Correct 85 ms 24788 KB Output is correct
19 Correct 87 ms 24240 KB Output is correct
20 Correct 71 ms 24880 KB Output is correct
21 Correct 64 ms 24824 KB Output is correct
22 Correct 66 ms 24856 KB Output is correct
23 Correct 82 ms 24896 KB Output is correct
24 Correct 66 ms 24788 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 79 ms 24116 KB Output is correct
28 Correct 88 ms 24800 KB Output is correct
29 Correct 77 ms 24888 KB Output is correct
30 Correct 75 ms 25024 KB Output is correct
31 Correct 82 ms 24152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Execution timed out 2085 ms 21948 KB Time limit exceeded
5 Halted 0 ms 0 KB -