Submission #925206

# Submission time Handle Problem Language Result Execution time Memory
925206 2024-02-11T03:07:10 Z awu Passport (JOI23_passport) C++14
100 / 100
847 ms 587972 KB
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;

// #define int long long
#define ll long long
// #define double long double
#define all(x) x.begin(), x.end()
#define debug(x) do{auto _x = x; cerr << #x << " = " << _x << endl;} while(0)
#define f first
#define s second
// #define endl '\n'

using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int inf = 1 << 29;
// const ll inf = 1ll << 50;

const int MOD = 1e9 + 7;

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n; cin >> n;
  int s = 1;
  while(s < n) s *= 2;
  vector<vector<int>> adj(s * 2); // reversed edges
  vector<int> s1, sn;
  for(int i = 0; i < n; i++) {
    int l, r; cin >> l >> r; l--;
    if(l == 0) s1.push_back(i);
    if(r == n) sn.push_back(i);
    auto add = [&](int a, int b) {
      adj[a].push_back(b);
    };
    for(l += s, r += s; l < r; l /= 2, r /= 2) {
      if(l & 1) add(l++, s + i);
      if(r & 1) add(--r, s + i);
    }
  }
  vector<deque<int>> q(n * 4);
  auto dijk = [&](vector<int>& d) {
    int cd = 0;
    while(true) {
      while(cd < q.size() && q[cd].empty()) cd++;
      if(cd == q.size()) break;
      auto cur = q[cd].front(); q[cd].pop_front();
      if(d[cur] <= cd) continue;
      d[cur] = cd;
      for(auto i : adj[cur]) {
        q[cd + 1].push_back(i);
      }
      if(cur > 1) q[cd].push_back(cur / 2);
    }
  };
  for(auto i : s1) {
    q[0].push_back(s + i);
  }
  vector<int> d1(s * 2, inf);
  dijk(d1);
  for(auto i : sn) {
    q[0].push_back(s + i);
  }
  vector<int> dn(s * 2, inf);
  dijk(dn);
  vector<int> d(s * 2, inf);
  for(int i = 0; i < n; i++) {
    int dist = d1[s + i] + dn[s + i];
    if(dist >= inf) continue;
    q[dist].push_back(s + i);
  }
  dijk(d);
  int Q; cin >> Q;
  while(Q--) {
    int x; cin >> x; x--;
    cout << (d[s + x] == inf ? -1 : d[s + x] + 1) << endl;
  }
}

Compilation message

passport.cpp: In lambda function:
passport.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::deque<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |       while(cd < q.size() && q[cd].empty()) cd++;
      |             ~~~^~~~~~~~~~
passport.cpp:47:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::deque<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |       if(cd == q.size()) break;
      |          ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 615 ms 576392 KB Output is correct
5 Correct 385 ms 563284 KB Output is correct
6 Correct 356 ms 568740 KB Output is correct
7 Correct 349 ms 562740 KB Output is correct
8 Correct 267 ms 454096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 508 KB Output is correct
11 Correct 1 ms 1112 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 508 KB Output is correct
11 Correct 1 ms 1112 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 5 ms 7260 KB Output is correct
17 Correct 5 ms 7512 KB Output is correct
18 Correct 5 ms 7516 KB Output is correct
19 Correct 5 ms 7516 KB Output is correct
20 Correct 4 ms 7512 KB Output is correct
21 Correct 4 ms 7516 KB Output is correct
22 Correct 4 ms 7516 KB Output is correct
23 Correct 4 ms 7516 KB Output is correct
24 Correct 5 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 508 KB Output is correct
11 Correct 1 ms 1112 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 5 ms 7260 KB Output is correct
17 Correct 5 ms 7512 KB Output is correct
18 Correct 5 ms 7516 KB Output is correct
19 Correct 5 ms 7516 KB Output is correct
20 Correct 4 ms 7512 KB Output is correct
21 Correct 4 ms 7516 KB Output is correct
22 Correct 4 ms 7516 KB Output is correct
23 Correct 4 ms 7516 KB Output is correct
24 Correct 5 ms 7516 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 8 ms 7260 KB Output is correct
28 Correct 8 ms 7516 KB Output is correct
29 Correct 7 ms 7516 KB Output is correct
30 Correct 7 ms 7416 KB Output is correct
31 Correct 7 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 615 ms 576392 KB Output is correct
5 Correct 385 ms 563284 KB Output is correct
6 Correct 356 ms 568740 KB Output is correct
7 Correct 349 ms 562740 KB Output is correct
8 Correct 267 ms 454096 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 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 1 ms 508 KB Output is correct
19 Correct 1 ms 1112 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1112 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 5 ms 7260 KB Output is correct
25 Correct 5 ms 7512 KB Output is correct
26 Correct 5 ms 7516 KB Output is correct
27 Correct 5 ms 7516 KB Output is correct
28 Correct 4 ms 7512 KB Output is correct
29 Correct 4 ms 7516 KB Output is correct
30 Correct 4 ms 7516 KB Output is correct
31 Correct 4 ms 7516 KB Output is correct
32 Correct 5 ms 7516 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 8 ms 7260 KB Output is correct
36 Correct 8 ms 7516 KB Output is correct
37 Correct 7 ms 7516 KB Output is correct
38 Correct 7 ms 7416 KB Output is correct
39 Correct 7 ms 7260 KB Output is correct
40 Correct 847 ms 579560 KB Output is correct
41 Correct 615 ms 573096 KB Output is correct
42 Correct 738 ms 583616 KB Output is correct
43 Correct 688 ms 587972 KB Output is correct
44 Correct 590 ms 574076 KB Output is correct
45 Correct 629 ms 574288 KB Output is correct
46 Correct 242 ms 217740 KB Output is correct
47 Correct 631 ms 577292 KB Output is correct
48 Correct 607 ms 574220 KB Output is correct