답안 #864135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
864135 2023-10-22T07:16:26 Z danikoynov Event Hopping (BOI22_events) C++14
10 / 100
1500 ms 35268 KB
#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 10;

struct interval
{
    int s, e;
}seg[maxn];

int n, q;   
pair < int, int > task[maxn];
void read()
{
    cin >> n >> q;
    for (int i = 1; i <= n; i ++)
    {
        cin >> seg[i].s >> seg[i].e;
    }
    for (int i = 1; i <= q; i ++)
    {
        cin >> task[i].first >> task[i].second;
    }
}


vector < int > adj[maxn];

int used[maxn];

void bfs(int start)
{
    for (int i = 1; i <= n; i ++)
        used[i] = -1;

    used[start] = 0;
    queue < int > q;
    q.push(start);
    while(!q.empty())
    {
        int v = q.front();
        q.pop();
        for (int u : adj[v])
        {
            if (used[u] == - 1)
            {
                used[u] = used[v] + 1;
                q.push(u);
            }
        }
    }
}

void build_graph()
{
    for (int i = 1; i <= n; i ++)
       for (int j = 1; j <= n; j ++)
        {
            if (seg[j].s <= seg[i].e && seg[i].e <= seg[j].e)
                adj[i].push_back(j);
        }
}

void answer_queries()
{
    for (int i = 1; i <= q; i ++)
    {
        bfs(task[i].first);
        if (used[task[i].second] == -1)
            cout << "impossible" << endl;
        else
            cout << used[task[i].second] << endl;

    }
}
void solve()
{
    read();
    build_graph();
    answer_queries();    
}

int main()
{
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Execution timed out 1558 ms 4804 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 7 ms 4444 KB Output is correct
4 Correct 6 ms 4552 KB Output is correct
5 Correct 7 ms 4444 KB Output is correct
6 Correct 11 ms 5212 KB Output is correct
7 Correct 17 ms 5980 KB Output is correct
8 Correct 19 ms 7256 KB Output is correct
9 Correct 83 ms 8400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 7 ms 4444 KB Output is correct
4 Correct 6 ms 4552 KB Output is correct
5 Correct 7 ms 4444 KB Output is correct
6 Correct 11 ms 5212 KB Output is correct
7 Correct 17 ms 5980 KB Output is correct
8 Correct 19 ms 7256 KB Output is correct
9 Correct 83 ms 8400 KB Output is correct
10 Correct 1 ms 4696 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 7 ms 4640 KB Output is correct
13 Correct 6 ms 4444 KB Output is correct
14 Correct 7 ms 4444 KB Output is correct
15 Correct 9 ms 5212 KB Output is correct
16 Correct 17 ms 5980 KB Output is correct
17 Correct 18 ms 7004 KB Output is correct
18 Correct 81 ms 8412 KB Output is correct
19 Execution timed out 1521 ms 35268 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 7 ms 4444 KB Output is correct
4 Correct 6 ms 4552 KB Output is correct
5 Correct 7 ms 4444 KB Output is correct
6 Correct 11 ms 5212 KB Output is correct
7 Correct 17 ms 5980 KB Output is correct
8 Correct 19 ms 7256 KB Output is correct
9 Correct 83 ms 8400 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 7 ms 4444 KB Output is correct
13 Correct 6 ms 4444 KB Output is correct
14 Correct 6 ms 4524 KB Output is correct
15 Correct 9 ms 5212 KB Output is correct
16 Correct 20 ms 6100 KB Output is correct
17 Correct 18 ms 7260 KB Output is correct
18 Correct 69 ms 8792 KB Output is correct
19 Execution timed out 1545 ms 6804 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1562 ms 4692 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Execution timed out 1558 ms 4804 KB Time limit exceeded
3 Halted 0 ms 0 KB -