답안 #408728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
408728 2021-05-19T14:53:51 Z atoiz Restore Array (RMI19_restore) C++14
100 / 100
439 ms 912 KB
/*input
8 3
0 2 3 0
3 4 1 1
5 7 2 0
4 5
0 1 2 1
0 2 2 0
2 2 1 0
0 1 1 0
1 2 1 0
*/
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	struct edge_t {
		int u, v, c;
		edge_t(int _u, int _v, int _c): u(_u), v(_v), c(_c) {};
	};
	vector<edge_t> edges;
	while (m--) {
		int l, r, k, x;
		cin >> l >> r >> k >> x;
		++r;
		if (x == 0) edges.emplace_back(l, r, r - l - k);
		else edges.emplace_back(r, l, k - 1 - r + l);
	}
	for (int i = 0; i < n; ++i) edges.emplace_back(i, i + 1, 1);
	for (int i = 0; i < n; ++i) edges.emplace_back(i + 1, i, 0);

	vector<int> min_dist(n + 1, n + 2);
	min_dist[0] = 0;
	bool unfinished = true;
	for (int i = 0; i <= n + 2 && unfinished; ++i) {
		unfinished = false;
		for (auto &e : edges) {
			if (min_dist[e.u] + e.c < min_dist[e.v]) {
				min_dist[e.v] = min_dist[e.u] + e.c;
				unfinished = true;
			}
		}
	}

	if (unfinished) {
		cout << -1 << endl;
	} else {
		for (int i = 0; i < n; ++i) {
			cout << min_dist[i + 1] - min_dist[i] << ' ';
		}
		cout << endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 780 KB Output is correct
2 Correct 9 ms 780 KB Output is correct
3 Correct 9 ms 780 KB Output is correct
4 Correct 9 ms 780 KB Output is correct
5 Correct 396 ms 912 KB Output is correct
6 Correct 385 ms 904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 780 KB Output is correct
2 Correct 9 ms 780 KB Output is correct
3 Correct 9 ms 780 KB Output is correct
4 Correct 9 ms 780 KB Output is correct
5 Correct 396 ms 912 KB Output is correct
6 Correct 385 ms 904 KB Output is correct
7 Correct 11 ms 908 KB Output is correct
8 Correct 10 ms 904 KB Output is correct
9 Correct 9 ms 908 KB Output is correct
10 Correct 10 ms 900 KB Output is correct
11 Correct 425 ms 908 KB Output is correct
12 Correct 439 ms 908 KB Output is correct
13 Correct 8 ms 908 KB Output is correct
14 Correct 7 ms 908 KB Output is correct
15 Correct 11 ms 908 KB Output is correct
16 Correct 58 ms 908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 9 ms 780 KB Output is correct
12 Correct 9 ms 780 KB Output is correct
13 Correct 9 ms 780 KB Output is correct
14 Correct 9 ms 780 KB Output is correct
15 Correct 396 ms 912 KB Output is correct
16 Correct 385 ms 904 KB Output is correct
17 Correct 11 ms 908 KB Output is correct
18 Correct 10 ms 904 KB Output is correct
19 Correct 9 ms 908 KB Output is correct
20 Correct 10 ms 900 KB Output is correct
21 Correct 425 ms 908 KB Output is correct
22 Correct 439 ms 908 KB Output is correct
23 Correct 8 ms 908 KB Output is correct
24 Correct 7 ms 908 KB Output is correct
25 Correct 11 ms 908 KB Output is correct
26 Correct 58 ms 908 KB Output is correct
27 Correct 7 ms 908 KB Output is correct
28 Correct 8 ms 908 KB Output is correct
29 Correct 10 ms 908 KB Output is correct
30 Correct 10 ms 908 KB Output is correct
31 Correct 6 ms 908 KB Output is correct
32 Correct 7 ms 908 KB Output is correct
33 Correct 401 ms 900 KB Output is correct
34 Correct 405 ms 908 KB Output is correct
35 Correct 8 ms 908 KB Output is correct
36 Correct 8 ms 908 KB Output is correct