Submission #1099418

# Submission time Handle Problem Language Result Execution time Memory
1099418 2024-10-11T09:29:19 Z andreiqwer Circle Passing (EGOI24_circlepassing) C++17
20 / 100
2000 ms 844488 KB
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

int n, m, q, px=-1, x, y;
vector<vector<int>> ad;
vector<int> dist;

void bfs(int k)
{
    if(px!=x || px==-1)
    {
        dist = vector<int>(2*n);
        dist[k]=1;
        queue<int> q;
        q.push(k);
        while(!q.empty())
        {
            int node=q.front();
            q.pop();

            for(auto& x : ad[node])
            {
                if(!dist[x])
                {
                    dist[x]=dist[node]+1;
                    q.push(x);
                }
            }
        }
    }
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin>>n>>m>>q;

    ad = vector<vector<int>>(2*n);

    for(int i=0; i<2*n-1; i++)
    {
        ad[i].push_back(i+1);
        ad[i+1].push_back(i);
    }
    ad[2*n-1].push_back(0);
    ad[0].push_back(2*n-1);

    for(int i=0; i<m; i++)
    {
        int k;
        cin>>k;
        ad[k].push_back(k+n);
        ad[k+n].push_back(k);
    }

    for(int i=1; i<=q; i++)
    {
        cin>>x>>y;
        bfs(x);
        cout<<dist[y]-1<<'\n';
        px=x;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 16 ms 12380 KB Output is correct
6 Runtime error 2 ms 600 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 496 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 9 ms 344 KB Output is correct
9 Correct 11 ms 592 KB Output is correct
10 Correct 10 ms 348 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 10 ms 348 KB Output is correct
13 Correct 10 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 496 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 9 ms 344 KB Output is correct
9 Correct 11 ms 592 KB Output is correct
10 Correct 10 ms 348 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 10 ms 348 KB Output is correct
13 Correct 10 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 3 ms 496 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 4 ms 496 KB Output is correct
28 Correct 9 ms 348 KB Output is correct
29 Correct 10 ms 348 KB Output is correct
30 Correct 9 ms 584 KB Output is correct
31 Correct 9 ms 584 KB Output is correct
32 Correct 10 ms 580 KB Output is correct
33 Correct 11 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Execution timed out 2085 ms 844488 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 16 ms 12380 KB Output is correct
6 Runtime error 2 ms 600 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -