답안 #672889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672889 2022-12-18T20:54:21 Z MilosMilutinovic Restore Array (RMI19_restore) C++14
100 / 100
355 ms 1044 KB
/**
 *    author:  wxhtzdy
 *    created: 18.12.2022 21:11:23
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> q;
  for (int i = 0; i < m; i++) {
    int l, r, k, v;
    cin >> l >> r >> k >> v;
    r += 1;
    int len = r - l;
    if (v == 0) {
      q.emplace_back(l, r, len - k);
    }
    if (v == 1) {
      q.emplace_back(r, l, -(len - k + 1));
    }
  }
  for (int i = 0; i < n; i++) {
    q.emplace_back(i, i + 1, 1);
    q.emplace_back(i + 1, i, 0);
  }
  const long long inf = (long long) 1e18;
  vector<long long> d(n + 1, inf);
  d[0] = 0;
  for (int iter = 0; iter <= n + 2; iter++) {
    bool any = false;
    for (auto& p : q) {
      int i = get<0>(p);
      int j = get<1>(p);
      int w = get<2>(p);
      if (d[i] < inf && d[j] > d[i] + w) {
        d[j] = max(-inf, d[i] + w);          
        any = true;
      }
    }
    if (iter == n + 2 && any) {
      cout << -1;
      return 0;
    }
  }
  long long prv = 0;
  for (int i = 1; i <= n; i++) {
    cout << d[i] - prv << " ";
    prv = d[i];
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 788 KB Output is correct
2 Correct 111 ms 900 KB Output is correct
3 Correct 114 ms 1044 KB Output is correct
4 Correct 126 ms 904 KB Output is correct
5 Correct 319 ms 916 KB Output is correct
6 Correct 309 ms 916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 788 KB Output is correct
2 Correct 111 ms 900 KB Output is correct
3 Correct 114 ms 1044 KB Output is correct
4 Correct 126 ms 904 KB Output is correct
5 Correct 319 ms 916 KB Output is correct
6 Correct 309 ms 916 KB Output is correct
7 Correct 115 ms 916 KB Output is correct
8 Correct 113 ms 916 KB Output is correct
9 Correct 118 ms 912 KB Output is correct
10 Correct 108 ms 916 KB Output is correct
11 Correct 337 ms 952 KB Output is correct
12 Correct 355 ms 916 KB Output is correct
13 Correct 108 ms 960 KB Output is correct
14 Correct 110 ms 916 KB Output is correct
15 Correct 114 ms 916 KB Output is correct
16 Correct 145 ms 1044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 114 ms 788 KB Output is correct
12 Correct 111 ms 900 KB Output is correct
13 Correct 114 ms 1044 KB Output is correct
14 Correct 126 ms 904 KB Output is correct
15 Correct 319 ms 916 KB Output is correct
16 Correct 309 ms 916 KB Output is correct
17 Correct 115 ms 916 KB Output is correct
18 Correct 113 ms 916 KB Output is correct
19 Correct 118 ms 912 KB Output is correct
20 Correct 108 ms 916 KB Output is correct
21 Correct 337 ms 952 KB Output is correct
22 Correct 355 ms 916 KB Output is correct
23 Correct 108 ms 960 KB Output is correct
24 Correct 110 ms 916 KB Output is correct
25 Correct 114 ms 916 KB Output is correct
26 Correct 145 ms 1044 KB Output is correct
27 Correct 106 ms 916 KB Output is correct
28 Correct 108 ms 908 KB Output is correct
29 Correct 116 ms 968 KB Output is correct
30 Correct 119 ms 912 KB Output is correct
31 Correct 104 ms 904 KB Output is correct
32 Correct 120 ms 960 KB Output is correct
33 Correct 337 ms 968 KB Output is correct
34 Correct 329 ms 964 KB Output is correct
35 Correct 130 ms 916 KB Output is correct
36 Correct 113 ms 916 KB Output is correct