Submission #548152

# Submission time Handle Problem Language Result Execution time Memory
548152 2022-04-12T14:29:10 Z elazarkoren Restore Array (RMI19_restore) C++17
100 / 100
459 ms 972 KB
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

const int infinity = 1e9;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
//    vector<vii> graph(n + 2);
    vector<pair<pii, int>> edges;
    for (int i = 0; i < m; i++) {
        int l, r, k, val;
        cin >> l >> r >> k >> val;
        r++;
        int sz = r - l;
        if (val) {
            edges.push_back({{r, l}, k - sz - 1});
//            graph[r].push_back({l, k - n});
        } else {
            edges.push_back({{l, r}, sz - k});
//            graph[l].push_back({r, n - k});
        }
    }
    for (int i = 0; i <= n; i++) {
        edges.push_back({{n + 1, i}, 0});
//        graph[n + 1].push_back({i, 0});
    }
    for (int i = 0; i < n; i++) {
        edges.push_back({{i, i + 1}, 1});
        edges.push_back({{i + 1, i}, 0});
    }
    vi distances(n + 2, infinity);
    distances[n + 1] = 0;
    for (int t = 0; t <= n + 2; t++) {
        for (auto [p, w] : edges) {
            auto [a, b] = p;
            chkmin(distances[b], distances[a] + w);
        }
    }
    for (auto [p, w] : edges) {
        auto [a, b] = p;
        if (distances[b] > distances[a] + w) {
            cout << -1 << '\n';
            return 0;
        }
    }
    int x = distances[0];
//    vi v(n + 1);
//    for (int i = 1; i <= n; i++) {
//        v[i] = v[i - 1] + distances[i] - x;
//    }
    for (int i = 1; i <= n; i++) {
        cout << distances[i] - distances[i - 1] << ' ';
    }
    return 0;
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:2:11: warning: unused variable 'first' [-Wunused-variable]
    2 | #define x first
      |           ^~~~~
restore.cpp:59:9: note: in expansion of macro 'x'
   59 |     int x = distances[0];
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 430 ms 916 KB Output is correct
2 Correct 430 ms 916 KB Output is correct
3 Correct 442 ms 916 KB Output is correct
4 Correct 405 ms 908 KB Output is correct
5 Correct 391 ms 908 KB Output is correct
6 Correct 439 ms 916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 430 ms 916 KB Output is correct
2 Correct 430 ms 916 KB Output is correct
3 Correct 442 ms 916 KB Output is correct
4 Correct 405 ms 908 KB Output is correct
5 Correct 391 ms 908 KB Output is correct
6 Correct 439 ms 916 KB Output is correct
7 Correct 425 ms 908 KB Output is correct
8 Correct 430 ms 972 KB Output is correct
9 Correct 458 ms 916 KB Output is correct
10 Correct 424 ms 904 KB Output is correct
11 Correct 415 ms 904 KB Output is correct
12 Correct 414 ms 916 KB Output is correct
13 Correct 420 ms 908 KB Output is correct
14 Correct 427 ms 916 KB Output is correct
15 Correct 433 ms 972 KB Output is correct
16 Correct 430 ms 904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 430 ms 916 KB Output is correct
12 Correct 430 ms 916 KB Output is correct
13 Correct 442 ms 916 KB Output is correct
14 Correct 405 ms 908 KB Output is correct
15 Correct 391 ms 908 KB Output is correct
16 Correct 439 ms 916 KB Output is correct
17 Correct 425 ms 908 KB Output is correct
18 Correct 430 ms 972 KB Output is correct
19 Correct 458 ms 916 KB Output is correct
20 Correct 424 ms 904 KB Output is correct
21 Correct 415 ms 904 KB Output is correct
22 Correct 414 ms 916 KB Output is correct
23 Correct 420 ms 908 KB Output is correct
24 Correct 427 ms 916 KB Output is correct
25 Correct 433 ms 972 KB Output is correct
26 Correct 430 ms 904 KB Output is correct
27 Correct 427 ms 964 KB Output is correct
28 Correct 428 ms 916 KB Output is correct
29 Correct 459 ms 900 KB Output is correct
30 Correct 424 ms 968 KB Output is correct
31 Correct 412 ms 968 KB Output is correct
32 Correct 423 ms 916 KB Output is correct
33 Correct 436 ms 916 KB Output is correct
34 Correct 425 ms 916 KB Output is correct
35 Correct 428 ms 916 KB Output is correct
36 Correct 430 ms 916 KB Output is correct