답안 #1111138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111138 2024-11-11T15:13:49 Z fryingduc Restore Array (RMI19_restore) C++17
100 / 100
150 ms 1296 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef duc_debug
#include "bits/debug.h"
#else
#define debug(...)
#endif

const int maxn = 5005;
int n, q;

int f[maxn];

struct info {
  int u, v, w;
};
vector<info> edges;
void solve() {
  cin >> n >> q;
  for(int i = 1; i <= n; ++i) {
    edges.push_back({i, i - 1, 1});
    edges.push_back({i - 1, i, 0});
  } 
  for(int i = 1; i <= q; ++i) {
    int l, r, k, v; cin >> l >> r >> k >> v;
    if(!v) {
      // at least k zeros
      edges.push_back({l, r + 1, -k});
    }
    else {
      // at most k - 1 zeros
      edges.push_back({r + 1, l, k - 1});
    }
  }
  memset(f, 0x3f, sizeof(f));
  f[0] = 0;
  // check neg cycle
  for(int ite = 1; ite <= n; ++ite) {
    for(auto i:edges) {
      int u = i.u, v = i.v;
      int w = i.w;
      f[u] = min(f[u], f[v] + w);
    }
  }
  for(auto i:edges) {
    if(f[i.u] > f[i.v] + i.w) {
      cout << -1;
      return;
    }
  }
  for(int i = 1; i <= n; ++i) {
    cout << (f[i] - f[i - 1] ? 0 : 1) << ' ';
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  solve();

  return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 508 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 568 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 948 KB Output is correct
2 Correct 130 ms 1040 KB Output is correct
3 Correct 139 ms 1040 KB Output is correct
4 Correct 143 ms 1212 KB Output is correct
5 Correct 133 ms 1040 KB Output is correct
6 Correct 131 ms 1040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 948 KB Output is correct
2 Correct 130 ms 1040 KB Output is correct
3 Correct 139 ms 1040 KB Output is correct
4 Correct 143 ms 1212 KB Output is correct
5 Correct 133 ms 1040 KB Output is correct
6 Correct 131 ms 1040 KB Output is correct
7 Correct 143 ms 1004 KB Output is correct
8 Correct 146 ms 1040 KB Output is correct
9 Correct 130 ms 1040 KB Output is correct
10 Correct 129 ms 1256 KB Output is correct
11 Correct 139 ms 1040 KB Output is correct
12 Correct 135 ms 1092 KB Output is correct
13 Correct 141 ms 1296 KB Output is correct
14 Correct 145 ms 1040 KB Output is correct
15 Correct 150 ms 1040 KB Output is correct
16 Correct 148 ms 1040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 508 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 568 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 140 ms 948 KB Output is correct
12 Correct 130 ms 1040 KB Output is correct
13 Correct 139 ms 1040 KB Output is correct
14 Correct 143 ms 1212 KB Output is correct
15 Correct 133 ms 1040 KB Output is correct
16 Correct 131 ms 1040 KB Output is correct
17 Correct 143 ms 1004 KB Output is correct
18 Correct 146 ms 1040 KB Output is correct
19 Correct 130 ms 1040 KB Output is correct
20 Correct 129 ms 1256 KB Output is correct
21 Correct 139 ms 1040 KB Output is correct
22 Correct 135 ms 1092 KB Output is correct
23 Correct 141 ms 1296 KB Output is correct
24 Correct 145 ms 1040 KB Output is correct
25 Correct 150 ms 1040 KB Output is correct
26 Correct 148 ms 1040 KB Output is correct
27 Correct 143 ms 1040 KB Output is correct
28 Correct 131 ms 1040 KB Output is correct
29 Correct 134 ms 1040 KB Output is correct
30 Correct 140 ms 1040 KB Output is correct
31 Correct 136 ms 1040 KB Output is correct
32 Correct 133 ms 1040 KB Output is correct
33 Correct 140 ms 1040 KB Output is correct
34 Correct 128 ms 1040 KB Output is correct
35 Correct 137 ms 1040 KB Output is correct
36 Correct 131 ms 1040 KB Output is correct