Submission #1092546

# Submission time Handle Problem Language Result Execution time Memory
1092546 2024-09-24T10:54:44 Z May27_th Restore Array (RMI19_restore) C++17
100 / 100
447 ms 1308 KB
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include<bits/stdc++.h>
 
using namespace std;
 
#define i64 long long
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()

const int MAXN = 2e5 + 10;
const i64 INF = 1e18;
void Solve(void) {  
  int N, M; cin >> N >> M;
  vector<array<int, 3>> edges;
  for (int i = 1; i <= N; i ++) {
    edges.pb({i, i - 1, 0});
    edges.pb({i - 1, i, 1});
  }
  for (int i = 0; i < M; i ++) {
    int l, r, k, v; cin >> l >> r >> k >> v;
    r ++;
    if (v == 0) edges.pb({r, l, -k});
    else edges.pb({l, r, k - 1});
  }
  // Add new vertex N + 1 to the graph -> cnt[i] = shortest path from N + 1 to i;
  vector<i64> d(N + 5, INF); d[0] = 0;
  int x = -1;
  for (int i = 0; i < N; i ++) {
    x = -1;
    for (auto [u, v, w] : edges) {
      // cout << u << " " << v << " " << w << "\n";
      if (d[u] < INF) {
        if (d[u] + w < d[v]) {
          x = v;
          d[v] = max(-INF, d[u] + w);
        }
      }
    }
  }

  if (x != -1) {
    cout << -1 << "\n";
    return;
  }
  for (int i = 1; i <= N; i ++) {
    // cout << d[i] << " ";
    cout << (d[i] > d[i - 1] ? 0 : 1) << " ";
  } 
}
signed main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(10);
  int Tests = 1; // cin >> Tests; 
  while (Tests --) {
    Solve();    
  }
}
# 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 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 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 96 ms 1052 KB Output is correct
2 Correct 97 ms 1052 KB Output is correct
3 Correct 97 ms 1048 KB Output is correct
4 Correct 99 ms 1048 KB Output is correct
5 Correct 447 ms 1052 KB Output is correct
6 Correct 384 ms 1052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 1052 KB Output is correct
2 Correct 97 ms 1052 KB Output is correct
3 Correct 97 ms 1048 KB Output is correct
4 Correct 99 ms 1048 KB Output is correct
5 Correct 447 ms 1052 KB Output is correct
6 Correct 384 ms 1052 KB Output is correct
7 Correct 101 ms 1052 KB Output is correct
8 Correct 101 ms 1052 KB Output is correct
9 Correct 99 ms 1052 KB Output is correct
10 Correct 98 ms 1308 KB Output is correct
11 Correct 202 ms 1052 KB Output is correct
12 Correct 138 ms 1052 KB Output is correct
13 Correct 99 ms 1052 KB Output is correct
14 Correct 103 ms 1048 KB Output is correct
15 Correct 109 ms 1048 KB Output is correct
16 Correct 103 ms 1052 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 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 96 ms 1052 KB Output is correct
12 Correct 97 ms 1052 KB Output is correct
13 Correct 97 ms 1048 KB Output is correct
14 Correct 99 ms 1048 KB Output is correct
15 Correct 447 ms 1052 KB Output is correct
16 Correct 384 ms 1052 KB Output is correct
17 Correct 101 ms 1052 KB Output is correct
18 Correct 101 ms 1052 KB Output is correct
19 Correct 99 ms 1052 KB Output is correct
20 Correct 98 ms 1308 KB Output is correct
21 Correct 202 ms 1052 KB Output is correct
22 Correct 138 ms 1052 KB Output is correct
23 Correct 99 ms 1052 KB Output is correct
24 Correct 103 ms 1048 KB Output is correct
25 Correct 109 ms 1048 KB Output is correct
26 Correct 103 ms 1052 KB Output is correct
27 Correct 97 ms 1052 KB Output is correct
28 Correct 110 ms 1052 KB Output is correct
29 Correct 98 ms 1048 KB Output is correct
30 Correct 100 ms 1052 KB Output is correct
31 Correct 95 ms 1052 KB Output is correct
32 Correct 98 ms 1096 KB Output is correct
33 Correct 237 ms 1052 KB Output is correct
34 Correct 323 ms 1048 KB Output is correct
35 Correct 99 ms 1052 KB Output is correct
36 Correct 98 ms 1052 KB Output is correct