Submission #873094

# Submission time Handle Problem Language Result Execution time Memory
873094 2023-11-14T12:40:12 Z nskybytskyi Restore Array (RMI19_restore) C++17
100 / 100
392 ms 1108 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0)->sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> graph(n + 1);
  for (int v = 0; v < n; ++v) {
    graph[v + 1].emplace_back(v, 0);
    graph[v].emplace_back(v + 1, 1);
  }
  while (m--) {
    int l, r, k, v;
    cin >> l >> r >> k >> v;
    if (v) {
      graph[r + 1].emplace_back(l, k - r + l - 2);
    } else {
      graph[l].emplace_back(r + 1, r - l + 1 - k);
    }
  }

  const auto inf = numeric_limits<int>::max() >> 1;
  vector<int> distance(n + 1, inf);
  distance[0] = 0;
  bool exists = true;
  for (int phase = 0; phase <= n; ++phase) {
    exists = true;
    for (int u = 0; u < n; ++u) {
      if (distance[u] < inf) {
        for (const auto& [v, w] : graph[u]) {
          if (distance[v] > distance[u] + w) {
            exists = false;
            distance[v] = distance[u] + w;
          }
        }
      }
    }
  }

  if (!exists) {
    cout << -1 << '\n';
  } else {
    for (int v = 0; v < n; ++v) {
      cout << distance[v + 1] - distance[v] << ' ';
    }
    cout << '\n';
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 219 ms 860 KB Output is correct
2 Correct 221 ms 1108 KB Output is correct
3 Correct 217 ms 1040 KB Output is correct
4 Correct 225 ms 1036 KB Output is correct
5 Correct 243 ms 1040 KB Output is correct
6 Correct 236 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 219 ms 860 KB Output is correct
2 Correct 221 ms 1108 KB Output is correct
3 Correct 217 ms 1040 KB Output is correct
4 Correct 225 ms 1036 KB Output is correct
5 Correct 243 ms 1040 KB Output is correct
6 Correct 236 ms 860 KB Output is correct
7 Correct 244 ms 1068 KB Output is correct
8 Correct 261 ms 1108 KB Output is correct
9 Correct 246 ms 1072 KB Output is correct
10 Correct 246 ms 1040 KB Output is correct
11 Correct 392 ms 1048 KB Output is correct
12 Correct 388 ms 1108 KB Output is correct
13 Correct 243 ms 860 KB Output is correct
14 Correct 264 ms 1076 KB Output is correct
15 Correct 244 ms 1068 KB Output is correct
16 Correct 251 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 219 ms 860 KB Output is correct
12 Correct 221 ms 1108 KB Output is correct
13 Correct 217 ms 1040 KB Output is correct
14 Correct 225 ms 1036 KB Output is correct
15 Correct 243 ms 1040 KB Output is correct
16 Correct 236 ms 860 KB Output is correct
17 Correct 244 ms 1068 KB Output is correct
18 Correct 261 ms 1108 KB Output is correct
19 Correct 246 ms 1072 KB Output is correct
20 Correct 246 ms 1040 KB Output is correct
21 Correct 392 ms 1048 KB Output is correct
22 Correct 388 ms 1108 KB Output is correct
23 Correct 243 ms 860 KB Output is correct
24 Correct 264 ms 1076 KB Output is correct
25 Correct 244 ms 1068 KB Output is correct
26 Correct 251 ms 856 KB Output is correct
27 Correct 240 ms 1048 KB Output is correct
28 Correct 244 ms 860 KB Output is correct
29 Correct 252 ms 860 KB Output is correct
30 Correct 249 ms 1068 KB Output is correct
31 Correct 228 ms 856 KB Output is correct
32 Correct 244 ms 1072 KB Output is correct
33 Correct 340 ms 1080 KB Output is correct
34 Correct 355 ms 856 KB Output is correct
35 Correct 239 ms 1064 KB Output is correct
36 Correct 252 ms 1068 KB Output is correct