Submission #991179

# Submission time Handle Problem Language Result Execution time Memory
991179 2024-06-01T13:56:35 Z JuliaTatad Restore Array (RMI19_restore) C++17
100 / 100
485 ms 1052 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
const int INF = 1e9; int n; int m;
//vector<vector<int>> gr; vector<bool> used;

struct Edge {
	int from; int to; int w;
	Edge(int from, int to, int w) : from(from), to(to), w(w) {}
};

int main() {
	cin >> n >> m; 
	// we will have n+1 vertices
	vector<Edge> edges;
	
	for (int i = 0; i < m; i++) {
		int l; int r; int k; int v; cin >> l >> r >> k >> v; r++; l++;
		if (v == 0) {
			edges.push_back(Edge(l - 1, r, r + 1 - l - k)); 
		}
		else {
			edges.push_back(Edge(r, l - 1, l + k - r - 2)); 
		}
	}

	for (int i = 1; i <= n; i++){
		edges.push_back(Edge(i-1, i, 1)); edges.push_back(Edge(i, i-1, 0));
	}
	//edges.push_back(Edge(0, 1, 0));

	vector<int> d(n + 1, INF); d[0] = 0;

	for (int i = 0; i < n; i++) {
		for (auto& e : edges) {
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.w) {
				d[e.to] = d[e.from] + e.w;
			}
		}
	}

	vector<int> old = d;

	for (int i = 0; i < n; i++) {
		for (auto& e : edges) {
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.w) {
				d[e.to] = d[e.from] + e.w;
				//cout << "updated " << e.to << "\n";
			}
		}
	}

	for (int i = 0; i < n + 1; i++) {
		if (d[i] != old[i]) {
			cout << "-1" << "\n"; return 0;
		}
	}
	// ok so no negative cycles
	vector<int> ans(n);
	for (int i = 1; i <= n; i++) {
		ans[i - 1] = d[i] - d[i - 1]; //std::cout << "i ans = " << i << " " << ans[i-1] << "\n";
		if (ans[i - 1] > 1 or ans[i - 1] < 0) {
			cout << "-1" << "\n"; return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << ans[i] << " "; 
	}
	cout << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 348 KB Output is correct
5 Correct 0 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 344 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 198 ms 796 KB Output is correct
2 Correct 193 ms 792 KB Output is correct
3 Correct 196 ms 796 KB Output is correct
4 Correct 193 ms 792 KB Output is correct
5 Correct 259 ms 792 KB Output is correct
6 Correct 281 ms 1052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 198 ms 796 KB Output is correct
2 Correct 193 ms 792 KB Output is correct
3 Correct 196 ms 796 KB Output is correct
4 Correct 193 ms 792 KB Output is correct
5 Correct 259 ms 792 KB Output is correct
6 Correct 281 ms 1052 KB Output is correct
7 Correct 197 ms 1048 KB Output is correct
8 Correct 205 ms 1052 KB Output is correct
9 Correct 219 ms 1052 KB Output is correct
10 Correct 196 ms 1052 KB Output is correct
11 Correct 485 ms 1048 KB Output is correct
12 Correct 377 ms 1052 KB Output is correct
13 Correct 210 ms 1048 KB Output is correct
14 Correct 277 ms 1052 KB Output is correct
15 Correct 230 ms 1052 KB Output is correct
16 Correct 213 ms 1052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 348 KB Output is correct
5 Correct 0 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 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 198 ms 796 KB Output is correct
12 Correct 193 ms 792 KB Output is correct
13 Correct 196 ms 796 KB Output is correct
14 Correct 193 ms 792 KB Output is correct
15 Correct 259 ms 792 KB Output is correct
16 Correct 281 ms 1052 KB Output is correct
17 Correct 197 ms 1048 KB Output is correct
18 Correct 205 ms 1052 KB Output is correct
19 Correct 219 ms 1052 KB Output is correct
20 Correct 196 ms 1052 KB Output is correct
21 Correct 485 ms 1048 KB Output is correct
22 Correct 377 ms 1052 KB Output is correct
23 Correct 210 ms 1048 KB Output is correct
24 Correct 277 ms 1052 KB Output is correct
25 Correct 230 ms 1052 KB Output is correct
26 Correct 213 ms 1052 KB Output is correct
27 Correct 194 ms 1052 KB Output is correct
28 Correct 218 ms 1052 KB Output is correct
29 Correct 201 ms 1048 KB Output is correct
30 Correct 198 ms 1052 KB Output is correct
31 Correct 199 ms 1052 KB Output is correct
32 Correct 201 ms 1052 KB Output is correct
33 Correct 359 ms 1052 KB Output is correct
34 Correct 355 ms 1048 KB Output is correct
35 Correct 196 ms 1048 KB Output is correct
36 Correct 202 ms 1044 KB Output is correct