답안 #736093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
736093 2023-05-05T08:20:16 Z nguyentunglam Passport (JOI23_passport) C++17
48 / 100
34 ms 22920 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 1e5 + 10;
int f[N], g[N], h[N];
vector<int> adj[N];
void bfs(int start, int d[]) {
    queue<int> q;
    d[start] = 1;
    q.push(start);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for(int &v : adj[u]) if (!d[v]) d[v] = d[u] + 1, q.push(v);
    }
}
int main() {
    #define task ""
    cin.tie(0) -> sync_with_stdio(0);
    if (fopen ("task.inp", "r")) {
        freopen ("task.inp", "r", stdin);
        freopen ("task.out", "w", stdout);
    }
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }

    int n; cin >> n;
    for(int i = 1; i <= n; i++) {
        int l, r; cin >> l >> r;
        for(int j = l; j <= r; j++) adj[j].push_back(i);
    }
    bfs(1, f);
    bfs(n, g);
    priority_queue<ii, vector<ii>, greater<ii> > Q;

    for(int i = 1; i <= n; i++) {
        if (f[i] > 0 && g[i] > 0) {
            if (i == 1 || i == n) h[i] = f[i] + g[i] - 2;
            else h[i] = f[i] + g[i] - 3;
        }
        else h[i] = 1e9;
        Q.push({h[i], i});
    }
    while (!Q.empty()) {
        int cost, u; tie(cost, u) = Q.top(); Q.pop();
        if (cost != h[u]) continue;
        for(int &v : adj[u]) if (h[v] > h[u] + 1) {
            h[v] = h[u] + 1;
            Q.push({h[v], v});
        }
    }

    for(int i = 1; i <= n; i++) if (h[i] == 1e9) h[i] = -1;

    int q; cin >> q;
    while (q--) {
        int x; cin >> x;
        cout << h[x] << endl;
    }
}

Compilation message

passport.cpp: In function 'int main()':
passport.cpp:23:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
passport.cpp:24:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
passport.cpp:27:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
passport.cpp:28:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Runtime error 15 ms 17076 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2732 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2900 KB Output is correct
14 Correct 2 ms 2900 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2732 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2900 KB Output is correct
14 Correct 2 ms 2900 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 17 ms 11004 KB Output is correct
17 Correct 3 ms 2900 KB Output is correct
18 Correct 34 ms 19924 KB Output is correct
19 Correct 32 ms 18900 KB Output is correct
20 Correct 2 ms 2772 KB Output is correct
21 Correct 6 ms 5076 KB Output is correct
22 Correct 29 ms 22920 KB Output is correct
23 Correct 30 ms 16980 KB Output is correct
24 Correct 28 ms 17616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2732 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2900 KB Output is correct
14 Correct 2 ms 2900 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 17 ms 11004 KB Output is correct
17 Correct 3 ms 2900 KB Output is correct
18 Correct 34 ms 19924 KB Output is correct
19 Correct 32 ms 18900 KB Output is correct
20 Correct 2 ms 2772 KB Output is correct
21 Correct 6 ms 5076 KB Output is correct
22 Correct 29 ms 22920 KB Output is correct
23 Correct 30 ms 16980 KB Output is correct
24 Correct 28 ms 17616 KB Output is correct
25 Correct 1 ms 2656 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 18 ms 11604 KB Output is correct
28 Correct 3 ms 2900 KB Output is correct
29 Correct 3 ms 2852 KB Output is correct
30 Correct 10 ms 4936 KB Output is correct
31 Correct 23 ms 12692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Runtime error 15 ms 17076 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -