Submission #1106850

# Submission time Handle Problem Language Result Execution time Memory
1106850 2024-10-31T07:57:35 Z VectorLi Restore Array (RMI19_restore) C++17
100 / 100
238 ms 1272 KB
#include <bits/stdc++.h>
#define long long long

using namespace std;

const int N = 5000;

int n, m;
vector<pair<int, int>> e[N + 1];

int d[N + 1];

void BF(int x) {
	fill(d, d + n + 1, numeric_limits<int>::max());
	d[x] = 0;
	for (int i = 0; i < n; i++) {
		for (int u = 0; u < n + 1; u++) {
			for (auto [v, w] : e[u]) {
				if (d[u] < numeric_limits<int>::max()) {
					d[v] = min(d[v], d[u] + w);
				}
			}
		}
	}
	for (int u = 0; u < n + 1; u++) {
		for (auto [v, w] : e[u]) {
			if (d[v] > d[u] + w) {
				cout << 0 - 1 << "\n";
				exit(0);
			}
		}
	}
}

void solve() {
	cin >> n >> m;
	for (int i = 0; i <= n - 1; i++) {
		e[i + 1].push_back({i, 0});
		e[i].push_back({i + 1, 1});
	}
	for (int i = 0; i < m; i++) {
		int l, r;
		int k, x;
		cin >> l >> r >> k >> x;
		l = l + 1;
		r = r + 1;
		if (x == 0) {
			e[r].push_back({l - 1, 0 - k});
		} else {
			e[l - 1].push_back({r, k - 1});
		}
	}
	BF(0);
	for (int i = 1; i <= n; i++) {
		if (d[i] - d[i - 1] == 0) {
			cout << 1 << " ";
		} else {
			cout << 0 << " ";
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	int t;
	t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 500 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
# Verdict Execution time Memory Grader output
1 Correct 194 ms 1272 KB Output is correct
2 Correct 197 ms 848 KB Output is correct
3 Correct 184 ms 848 KB Output is correct
4 Correct 188 ms 1072 KB Output is correct
5 Correct 197 ms 848 KB Output is correct
6 Correct 200 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 194 ms 1272 KB Output is correct
2 Correct 197 ms 848 KB Output is correct
3 Correct 184 ms 848 KB Output is correct
4 Correct 188 ms 1072 KB Output is correct
5 Correct 197 ms 848 KB Output is correct
6 Correct 200 ms 848 KB Output is correct
7 Correct 195 ms 1096 KB Output is correct
8 Correct 218 ms 1092 KB Output is correct
9 Correct 211 ms 1092 KB Output is correct
10 Correct 198 ms 848 KB Output is correct
11 Correct 201 ms 848 KB Output is correct
12 Correct 188 ms 848 KB Output is correct
13 Correct 199 ms 1084 KB Output is correct
14 Correct 199 ms 1104 KB Output is correct
15 Correct 205 ms 1092 KB Output is correct
16 Correct 238 ms 1096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 500 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 194 ms 1272 KB Output is correct
12 Correct 197 ms 848 KB Output is correct
13 Correct 184 ms 848 KB Output is correct
14 Correct 188 ms 1072 KB Output is correct
15 Correct 197 ms 848 KB Output is correct
16 Correct 200 ms 848 KB Output is correct
17 Correct 195 ms 1096 KB Output is correct
18 Correct 218 ms 1092 KB Output is correct
19 Correct 211 ms 1092 KB Output is correct
20 Correct 198 ms 848 KB Output is correct
21 Correct 201 ms 848 KB Output is correct
22 Correct 188 ms 848 KB Output is correct
23 Correct 199 ms 1084 KB Output is correct
24 Correct 199 ms 1104 KB Output is correct
25 Correct 205 ms 1092 KB Output is correct
26 Correct 238 ms 1096 KB Output is correct
27 Correct 205 ms 1096 KB Output is correct
28 Correct 206 ms 1092 KB Output is correct
29 Correct 196 ms 1096 KB Output is correct
30 Correct 232 ms 1092 KB Output is correct
31 Correct 213 ms 848 KB Output is correct
32 Correct 190 ms 1096 KB Output is correct
33 Correct 217 ms 1104 KB Output is correct
34 Correct 205 ms 1088 KB Output is correct
35 Correct 208 ms 1104 KB Output is correct
36 Correct 211 ms 1096 KB Output is correct