Submission #337161

# Submission time Handle Problem Language Result Execution time Memory
337161 2020-12-18T16:48:50 Z VROOM_VARUN Olympic Bus (JOI20_ho_t4) C++14
5 / 100
1000 ms 3692 KB
/*
ID: varunra2
LANG: C++
TASK: olympic
*/

#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
  cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif

#define int long long

#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e15
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second

const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions

int n, m;
vector<vector<pair<int, PII>>> adj;
int mn = INF;
VVI dists;

void init() {
  adj.resize(n);
  dists.resize(n);
}

VI dijk(int src, VI ign = {-1, -1, -1, -1}) {
  VI dist(n, INF);
  vector<bool> vis(n, false);
  priority_queue<PII, VII, greater<PII>> pq;

  dist[src] = 0;
  pq.push(MP(0, src));

  while (!pq.empty()) {
    auto xx = pq.top();
    pq.pop();
    int u = xx.y;
    if (vis[u]) continue;
    vis[u] = true;
    for (auto& x : adj[u]) {
      if (vis[x.x]) continue;
      if (u == ign[0] and x.x == ign[1] and x.y.x == ign[2] and x.y.y == ign[3])
        continue;
      if (dist[x.x] > dist[u] + x.y.x) {
        dist[x.x] = dist[u] + x.y.x;
        pq.push(MP(dist[x.x], x.x));
      }
    }
  }
  return dist;
}

void ckmin(int& a, int b) { a = min(a, b); }

int32_t main() {
  // #ifndef ONLINE_JUDGE
  // freopen("olympic.in", "r", stdin);
  // freopen("olympic.out", "w", stdout);
  // #endif
  cin.sync_with_stdio(0);
  cin.tie(0);

  cin >> n >> m;

  init();

  for (int i = 0; i < m; i++) {
    int u, v, c, d;
    cin >> u >> v >> c >> d;
    u--, v--;
    adj[u].PB(MP(v, MP(c, d)));
    // if (u == 1 and v == 3 and c == 2 and d == 5) debug("here reeeee");
  }

  for (int i = 0; i < n; i++) {
    dists[i] = dijk(i);
  }

  int ret = INF;

  ckmin(ret, dists[0][n - 1] + dists[n - 1][0]);

  VVI goodedgs;

  rep(u, 0, n) for (int j = 0; j < sz(adj[u]); j++) {
    auto x = adj[u][j];
    int v = x.x;
    int cost = x.y.x;
    int swip = x.y.y;
    bool ok = false;
    if (dists[0][v] + dists[u][n - 1] + cost < dists[0][n - 1]) ok = true;
    if (dists[n - 1][v] + dists[u][0] + cost < dists[n - 1][0]) ok = true;
    if (ok) {
      VI cur = {u, v, cost, swip};
      // debug(cur);
      // goodedgs.PB(cur);
      adj[v].PB(MP(u, MP(cost, swip)));
      int d1 = dijk(0, cur)[n - 1];
      int d2 = dijk(n - 1, cur)[0];
      int nw = d1 + d2 + swip;
      // debug(nw, d1, d2);
      // debug(dijk(0, cur));
      // trav(x, adj) debug(x);
      ckmin(ret, nw);
      adj[v].pop_back();
    }
  }

  if (ret >= INF) ret = -1;

  cout << ret << '\n';

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 748 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 9 ms 748 KB Output is correct
4 Correct 10 ms 748 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 5 ms 364 KB Output is correct
10 Correct 14 ms 748 KB Output is correct
11 Correct 23 ms 748 KB Output is correct
12 Correct 21 ms 748 KB Output is correct
13 Correct 17 ms 748 KB Output is correct
14 Correct 6 ms 748 KB Output is correct
15 Correct 6 ms 748 KB Output is correct
16 Correct 7 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 3308 KB Output is correct
2 Correct 84 ms 3180 KB Output is correct
3 Correct 88 ms 3692 KB Output is correct
4 Correct 9 ms 748 KB Output is correct
5 Correct 6 ms 748 KB Output is correct
6 Correct 2 ms 748 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Execution timed out 1095 ms 3692 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 748 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 56 ms 2796 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 68 ms 3180 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Execution timed out 1095 ms 3436 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 748 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 9 ms 748 KB Output is correct
4 Correct 10 ms 748 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 5 ms 364 KB Output is correct
10 Correct 14 ms 748 KB Output is correct
11 Correct 23 ms 748 KB Output is correct
12 Correct 21 ms 748 KB Output is correct
13 Correct 17 ms 748 KB Output is correct
14 Correct 6 ms 748 KB Output is correct
15 Correct 6 ms 748 KB Output is correct
16 Correct 7 ms 748 KB Output is correct
17 Correct 79 ms 3308 KB Output is correct
18 Correct 84 ms 3180 KB Output is correct
19 Correct 88 ms 3692 KB Output is correct
20 Correct 9 ms 748 KB Output is correct
21 Correct 6 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 1 ms 640 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Execution timed out 1095 ms 3692 KB Time limit exceeded
26 Halted 0 ms 0 KB -