답안 #714329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
714329 2023-03-24T08:55:49 Z vjudge1 Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 384820 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define OPT ios_base::sync_with_stdio(0); \
            cin.tie(0); \
            cout.tie(0)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define bpc __builtin_popcount
#define print(v) for(int i = 0; i < v.size(); i++) \
                    cout << v[i] << " "; \
                    cout<<endl;
vector<int> adj[100001];
int n;

int bfs(int s, int f)
{
    vector<int> dist(100001, -1);
    queue<int> q;
    q.push(s);
    dist[s] = 0;

    while (!q.empty())
    {
        int x = q.front();
        q.pop();

        for (int i = 0; i < adj[x].size(); i++)
        {
            if (dist[adj[x][i]] == -1)
            {
                dist[adj[x][i]] = dist[x] + 1;
                q.push(adj[x][i]);
            }
        }
    }

    return dist[f];
}
int main()
{
    int q;
    cin >> n >> q;
    set<int> ts;
    vector<pii> v;
    vector<pair<int, pii>> sorted;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        ts.insert(a);
        ts.insert(b);

        v.pb(mpr(a, b));
        sorted.pb(mpr(a, mpr(b, i)));
    }

    cout << endl;
    sort(all(sorted));
    unordered_set<int> on;

    int ind = 0;

    for (int i : ts)
    {
        while (ind < n && sorted[ind].fi <= i)
        {
            if (sorted[ind].fi >= i)
            {
                on.insert(sorted[ind].se.se);
            }
            ind++;
        }


        unordered_set<int> of;
        for (int x : on)
        {

            if (v[x].se == i)
            {
                for (auto j : on)
                {
                    if (x == j) continue;

                    adj[x+1].pb(j+1);
                }
                of.insert(x);
            }
        }

        for (int x : of)
        {
            on.erase(x);
        }
        of.clear();
    }

    while (q--)
    {
        int a, b;
        cin >> a >> b;
        int d = bfs(a, b);
        if (d == -1)
        {
            cout << "impossible\n";
        }
        else
        {
            cout << d << endl;
        }
    }

}

Compilation message

events.cpp: In function 'int bfs(int, int)':
events.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (int i = 0; i < adj[x].size(); i++)
      |                         ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Execution timed out 1574 ms 12740 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 5 ms 3156 KB Output is correct
4 Correct 4 ms 3148 KB Output is correct
5 Correct 5 ms 3064 KB Output is correct
6 Correct 10 ms 3924 KB Output is correct
7 Correct 25 ms 4704 KB Output is correct
8 Correct 29 ms 5836 KB Output is correct
9 Correct 120 ms 7124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 5 ms 3156 KB Output is correct
4 Correct 4 ms 3148 KB Output is correct
5 Correct 5 ms 3064 KB Output is correct
6 Correct 10 ms 3924 KB Output is correct
7 Correct 25 ms 4704 KB Output is correct
8 Correct 29 ms 5836 KB Output is correct
9 Correct 120 ms 7124 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 3 ms 3028 KB Output is correct
12 Correct 5 ms 3156 KB Output is correct
13 Correct 5 ms 3156 KB Output is correct
14 Correct 5 ms 3156 KB Output is correct
15 Correct 12 ms 3924 KB Output is correct
16 Correct 26 ms 4792 KB Output is correct
17 Correct 29 ms 5760 KB Output is correct
18 Correct 121 ms 7164 KB Output is correct
19 Execution timed out 1585 ms 33036 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 5 ms 3156 KB Output is correct
4 Correct 4 ms 3148 KB Output is correct
5 Correct 5 ms 3064 KB Output is correct
6 Correct 10 ms 3924 KB Output is correct
7 Correct 25 ms 4704 KB Output is correct
8 Correct 29 ms 5836 KB Output is correct
9 Correct 120 ms 7124 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 2 ms 3028 KB Output is correct
12 Correct 6 ms 3156 KB Output is correct
13 Correct 4 ms 3148 KB Output is correct
14 Correct 4 ms 3156 KB Output is correct
15 Correct 11 ms 3924 KB Output is correct
16 Correct 25 ms 4708 KB Output is correct
17 Correct 29 ms 5716 KB Output is correct
18 Correct 123 ms 7124 KB Output is correct
19 Correct 490 ms 12744 KB Output is correct
20 Correct 355 ms 14400 KB Output is correct
21 Execution timed out 1561 ms 384820 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1568 ms 12816 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Execution timed out 1574 ms 12740 KB Time limit exceeded
3 Halted 0 ms 0 KB -