Submission #218011

# Submission time Handle Problem Language Result Execution time Memory
218011 2020-03-31T12:10:23 Z tincamatei Restore Array (RMI19_restore) C++14
100 / 100
444 ms 5120 KB
/**
* user:  tinca-6db
* fname: Matei
* lname: Tinca
* task:  restore
* score: 100.0
* date:  2019-10-10 08:18:43.220236
*/
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 5000;

struct Edge {
	int son, difa, difb;
};

struct Range {
	int l, r;
} range[1+MAX_N];

vector<Edge> graph[1+MAX_N];

void reportError() {
	printf("-1");
	exit(0);
}

bool ok;
void dfs(int nod) {
	for(auto it: graph[nod]) {
		int newL = range[nod].l + it.difa, newR = range[nod].r + it.difb;
		if(newL > range[it.son].l || newR < range[it.son].r) {
			range[it.son].l = max(range[it.son].l, newL);
			range[it.son].r = min(range[it.son].r, newR);
			if(range[it.son].l > range[it.son].r)
				reportError();
			ok = true;
			dfs(it.son);
		}
	}
}

void insertLessStrict(int a, int b, int k) {
	graph[a].push_back({b, -MAX_N, k - 1});
	graph[b].push_back({a, -(k - 1), MAX_N});
}

void insertGreaterEq(int a, int b, int k) {
	graph[a].push_back({b, k, MAX_N});
	graph[b].push_back({a, -MAX_N, -k});
}

int main() {
	int N, M;
	int l, r, k, val;
	scanf("%d%d", &N, &M);
	for(int i = 0; i < M; ++i) {
		scanf("%d%d%d%d", &l, &r, &k, &val);
		++l;
		++r;
		
		if(val == 0) {
			insertGreaterEq(l - 1, r, k);
		} else {
			insertLessStrict(l - 1, r, k);
		}
	}

	for(int i = 0; i < N; ++i) {
		insertGreaterEq(i, i + 1, 0);
		insertLessStrict(i, i + 1, 2);
	}

	for(int i = 0; i <= N; ++i)
		range[i] = {0, i};
	
	do {
		ok = false;
		for(int i = 0; i <= N; ++i)
			dfs(i);
	} while(ok);

	for(int i = 1; i <= N; ++i)
		printf("%d ", 1 ^ (range[i].l - range[i - 1].l));

	return 0;
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:58:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
restore.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &l, &r, &k, &val);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1408 KB Output is correct
2 Correct 20 ms 1536 KB Output is correct
3 Correct 25 ms 1656 KB Output is correct
4 Correct 20 ms 1536 KB Output is correct
5 Correct 11 ms 1664 KB Output is correct
6 Correct 10 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1408 KB Output is correct
2 Correct 20 ms 1536 KB Output is correct
3 Correct 25 ms 1656 KB Output is correct
4 Correct 20 ms 1536 KB Output is correct
5 Correct 11 ms 1664 KB Output is correct
6 Correct 10 ms 1664 KB Output is correct
7 Correct 24 ms 1536 KB Output is correct
8 Correct 23 ms 1536 KB Output is correct
9 Correct 37 ms 1528 KB Output is correct
10 Correct 36 ms 1528 KB Output is correct
11 Correct 10 ms 1408 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 24 ms 1408 KB Output is correct
14 Correct 307 ms 1536 KB Output is correct
15 Correct 431 ms 1528 KB Output is correct
16 Correct 444 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 19 ms 1408 KB Output is correct
12 Correct 20 ms 1536 KB Output is correct
13 Correct 25 ms 1656 KB Output is correct
14 Correct 20 ms 1536 KB Output is correct
15 Correct 11 ms 1664 KB Output is correct
16 Correct 10 ms 1664 KB Output is correct
17 Correct 24 ms 1536 KB Output is correct
18 Correct 23 ms 1536 KB Output is correct
19 Correct 37 ms 1528 KB Output is correct
20 Correct 36 ms 1528 KB Output is correct
21 Correct 10 ms 1408 KB Output is correct
22 Correct 10 ms 1408 KB Output is correct
23 Correct 24 ms 1408 KB Output is correct
24 Correct 307 ms 1536 KB Output is correct
25 Correct 431 ms 1528 KB Output is correct
26 Correct 444 ms 1528 KB Output is correct
27 Correct 51 ms 4856 KB Output is correct
28 Correct 34 ms 5120 KB Output is correct
29 Correct 58 ms 3184 KB Output is correct
30 Correct 46 ms 4224 KB Output is correct
31 Correct 55 ms 3192 KB Output is correct
32 Correct 45 ms 4344 KB Output is correct
33 Correct 11 ms 1408 KB Output is correct
34 Correct 10 ms 1408 KB Output is correct
35 Correct 45 ms 4480 KB Output is correct
36 Correct 61 ms 2944 KB Output is correct