Submission #740493

# Submission time Handle Problem Language Result Execution time Memory
740493 2023-05-12T15:12:05 Z abczz Crocodile's Underground City (IOI11_crocodile) C++14
100 / 100
522 ms 90784 KB
#include "crocodile.h"
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#define ll long long
 
using namespace std;
 
vector <array<ll, 2> > adj[100000];
priority_queue <array<ll, 2>, vector<array<ll, 2>>, greater<array<ll,2>>> pq;
ll dist[100000], in[100000], MN[2][100000];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
  for (int i=0; i<N; ++i) dist[i] = MN[0][i] = MN[1][i] = 1e18;
  for (int i=0; i<M; ++i) {
    adj[R[i][0]].push_back({R[i][1], L[i]});
    adj[R[i][1]].push_back({R[i][0], L[i]});
  }
  for (int i=0; i<K; ++i) {
    dist[P[i]] = 0;
    pq.push({0, P[i]});
  }
  while (!pq.empty()) {
    auto [w, u] = pq.top();
    pq.pop();
    if (dist[u] != w) continue;
    for (auto [v, x] : adj[u]) {
      if (dist[v] > dist[u]+x) {
        ++in[v];
        if (in[v] == 1) MN[0][v] = dist[u]+x;
        else if (in[v] == 2) {
          MN[1][v] = max(MN[0][v], dist[u]+x);
          MN[0][v] = min(MN[0][v], dist[u]+x);
          dist[v] = MN[1][v];
          pq.push({dist[v], v});
        }
        else {
          if (MN[0][v] > dist[u]+x) {
            MN[1][v] = MN[0][v];
            MN[0][v] = dist[u]+x;
            if (dist[v] != MN[1][v]) pq.push({MN[1][v], v});
            dist[v] = MN[1][v];
          }
          else if (MN[1][v] > dist[u]+x) {
            MN[1][v] = dist[u]+x;
            dist[v] = MN[1][v];
            pq.push({dist[v], v});
          }
        }
      }
    }
  }
  return dist[0];
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:25:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |     auto [w, u] = pq.top();
      |          ^
crocodile.cpp:28:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   28 |     for (auto [v, x] : adj[u]) {
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 3 ms 2780 KB Output is correct
3 Correct 2 ms 2664 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2804 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 2 ms 2804 KB Output is correct
8 Correct 2 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 3 ms 2780 KB Output is correct
3 Correct 2 ms 2664 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2804 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 2 ms 2804 KB Output is correct
8 Correct 2 ms 2796 KB Output is correct
9 Correct 3 ms 3028 KB Output is correct
10 Correct 2 ms 2664 KB Output is correct
11 Correct 3 ms 2772 KB Output is correct
12 Correct 6 ms 3344 KB Output is correct
13 Correct 4 ms 3412 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 3 ms 2804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 3 ms 2780 KB Output is correct
3 Correct 2 ms 2664 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2804 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 2 ms 2804 KB Output is correct
8 Correct 2 ms 2796 KB Output is correct
9 Correct 3 ms 3028 KB Output is correct
10 Correct 2 ms 2664 KB Output is correct
11 Correct 3 ms 2772 KB Output is correct
12 Correct 6 ms 3344 KB Output is correct
13 Correct 4 ms 3412 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 3 ms 2804 KB Output is correct
16 Correct 419 ms 83496 KB Output is correct
17 Correct 79 ms 19148 KB Output is correct
18 Correct 104 ms 21788 KB Output is correct
19 Correct 522 ms 90784 KB Output is correct
20 Correct 282 ms 68132 KB Output is correct
21 Correct 51 ms 10236 KB Output is correct
22 Correct 293 ms 64596 KB Output is correct