Submission #547773

# Submission time Handle Problem Language Result Execution time Memory
547773 2022-04-11T17:24:30 Z Soumya1 Toll (BOI17_toll) C++17
0 / 100
211 ms 317132 KB
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
const int mxN = 5e4 + 5;
const int mxK = 5;
const int lg = 16;
long long dist[mxN][lg][mxK][mxK];
int k, n, m, q;
void testCase() {
  for (int i = 0; i < mxN; i++) {
    for (int j = 0; j < lg; j++) {
      for (int x = 0; x < mxK; x++) {
        for (int l = 0; l < mxK; l++) {
          dist[i][j][x][l] = 1e18;
        }
      }
    }
  }
  cin >> k >> n >> m >> q;
  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    dist[a / k][0][a % k][b % k] = min(dist[a / k][0][a % k][b % k], 1LL * c);
  }
  for (int j = 1; j < lg; j++) {
    for (int i = 0; i < n; i++) {
      for (int a = 0; a < k; a++) {
        for (int b = 0; b < k; b++) {
          for (int c = 0; c < k; c++) {
            if (dist[i][j - 1][a][c] == 1e18) continue;
            if (dist[i + (1 << j) - 1][j - 1][c][b] == 1e18) continue;
            dist[i][j][a][b] = min(dist[i][j][a][b], dist[i][j - 1][a][c] + dist[i + (1 << j) - 1][j - 1][c][b]);
          }
        }
      }
    }
  }
  while (q--) {
    int a, b;
    cin >> a >> b;
    int aa = a / k;
    int bb = b / k;
    long long ans[k];
    for (int i = 0; i < k; i++) ans[i] = 1e18;
    ans[a % k] = 0;
    for (int j = lg - 1; j >= 0; j--) {
      if (aa + (1 << j) <= bb) {
        long long new_ans[k];
        for (int i = 0; i < k; i++) new_ans[i] = 1e18;
        for (int from = 0; from < k; from++) {
          for (int to = 0; to < k; to++) {
            if (ans[from] == 1e18) continue;
            if (dist[aa][j][from][to] == 1e18) continue;
            new_ans[to] = min(new_ans[to], ans[from] + dist[aa][j][from][to]);
          }
        }
        for (int i = 0; i < k; i++) ans[i] = new_ans[i];
        aa += (1 << j);
      }
    }
    long long out = ans[b % k];
    if (aa > bb || out == 1e18) out = -1;
    cout << out << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 211 ms 317132 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 178 ms 158548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 67 ms 156816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 67 ms 156816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 211 ms 317132 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -