Submission #200265

# Submission time Handle Problem Language Result Execution time Memory
200265 2020-02-05T20:25:24 Z wilwxk Safety (NOI18_safety) C++14
66 / 100
2000 ms 1744 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct point {
	ll x, y;
};

const int MAXN = 2e5+5;
vector<point> s;
int v[MAXN];
int n, x;

void expand() {
	ll mn = 1e18;
	for(auto pp : s) mn = min(mn, pp.y);

	int l = -1, r = -1;
	for(int i = 0; i < s.size(); i++) {
		if(s[i].y == mn) {
			if(l == -1) l = i;
			r = i;
		}
	}

	vector<point> aux;
	for(int i = 0; i < s.size(); i++) {
		if(i <= l) aux.push_back({s[i].x-x, s[i].y});
		if(i >= r) aux.push_back({s[i].x+x, s[i].y});
	}
	swap(aux, s);
}

void update(ll cur) {
	if(s.empty()) {
		s.push_back({v[cur], 0});
		return;
	}
	expand();
	// printf("bleh %lld\n", cur);
	// for(auto pp : s) printf("(%lld %lld) ", pp.x, pp.y); cout << endl;
	vector<point> aux;
	for(int i = 0; i < s.size(); i++) {
		if(s[i].x >= v[cur]) {
			if(i == 0) aux.push_back({ v[cur], s[i].y+(s[i].x-v[cur])*(cur-1) });
			else aux.push_back({ v[cur], ((v[cur]-s[i-1].x)*(s[i].y-s[i-1].y))/(s[i].x-s[i-1].x)+s[i-1].y });
			break;
		}
		aux.push_back(s[i]);
	}
	for(auto pp : s) if(pp.x >= v[cur]) aux.push_back(pp);
	if(aux.size() == s.size()) aux.push_back({ v[cur], (v[cur]-s.back().x)*(cur-1)+s.back().y });

	for(int i = 0; i < aux.size(); i++) aux[i].y += abs(aux[i].x-v[cur]);

	swap(aux, s);
	// for(auto pp : s) printf("(%lld %lld) ", pp.x, pp.y); cout << endl;
}

int main() {
	scanf("%d %d", &n, &x);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &v[i]);
		update(i);
	}

	ll ans = 1e18;
	for(auto cur : s) ans = min(ans, cur.y);
	printf("%lld\n", ans);
}

Compilation message

safety.cpp: In function 'void expand()':
safety.cpp:19:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < s.size(); i++) {
                 ~~^~~~~~~~~~
safety.cpp:27:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < s.size(); i++) {
                 ~~^~~~~~~~~~
safety.cpp: In function 'void update(ll)':
safety.cpp:43:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < s.size(); i++) {
                 ~~^~~~~~~~~~
safety.cpp:54:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < aux.size(); i++) aux[i].y += abs(aux[i].x-v[cur]);
                 ~~^~~~~~~~~~~~
safety.cpp: In function 'int main()':
safety.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &x);
  ~~~~~^~~~~~~~~~~~~~~~~
safety.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &v[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 1744 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 8 ms 376 KB Output is correct
14 Correct 8 ms 376 KB Output is correct
15 Correct 10 ms 376 KB Output is correct
16 Correct 8 ms 376 KB Output is correct
17 Correct 9 ms 376 KB Output is correct
18 Correct 8 ms 376 KB Output is correct
19 Correct 8 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 8 ms 376 KB Output is correct
14 Correct 8 ms 376 KB Output is correct
15 Correct 10 ms 376 KB Output is correct
16 Correct 8 ms 376 KB Output is correct
17 Correct 9 ms 376 KB Output is correct
18 Correct 8 ms 376 KB Output is correct
19 Correct 8 ms 376 KB Output is correct
20 Correct 10 ms 376 KB Output is correct
21 Correct 9 ms 376 KB Output is correct
22 Correct 7 ms 376 KB Output is correct
23 Correct 8 ms 376 KB Output is correct
24 Correct 8 ms 376 KB Output is correct
25 Correct 8 ms 376 KB Output is correct
26 Correct 8 ms 376 KB Output is correct
27 Correct 8 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 8 ms 376 KB Output is correct
14 Correct 8 ms 376 KB Output is correct
15 Correct 10 ms 376 KB Output is correct
16 Correct 8 ms 376 KB Output is correct
17 Correct 9 ms 376 KB Output is correct
18 Correct 8 ms 376 KB Output is correct
19 Correct 8 ms 376 KB Output is correct
20 Correct 10 ms 376 KB Output is correct
21 Correct 9 ms 376 KB Output is correct
22 Correct 7 ms 376 KB Output is correct
23 Correct 8 ms 376 KB Output is correct
24 Correct 8 ms 376 KB Output is correct
25 Correct 8 ms 376 KB Output is correct
26 Correct 8 ms 376 KB Output is correct
27 Correct 8 ms 376 KB Output is correct
28 Correct 256 ms 800 KB Output is correct
29 Correct 175 ms 692 KB Output is correct
30 Correct 284 ms 672 KB Output is correct
31 Correct 314 ms 828 KB Output is correct
32 Correct 318 ms 928 KB Output is correct
33 Correct 254 ms 808 KB Output is correct
34 Correct 487 ms 928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 256 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 8 ms 376 KB Output is correct
20 Correct 8 ms 376 KB Output is correct
21 Correct 10 ms 376 KB Output is correct
22 Correct 8 ms 376 KB Output is correct
23 Correct 9 ms 376 KB Output is correct
24 Correct 8 ms 376 KB Output is correct
25 Correct 8 ms 376 KB Output is correct
26 Correct 10 ms 376 KB Output is correct
27 Correct 9 ms 376 KB Output is correct
28 Correct 7 ms 376 KB Output is correct
29 Correct 8 ms 376 KB Output is correct
30 Correct 8 ms 376 KB Output is correct
31 Correct 8 ms 376 KB Output is correct
32 Correct 8 ms 376 KB Output is correct
33 Correct 8 ms 376 KB Output is correct
34 Correct 256 ms 800 KB Output is correct
35 Correct 175 ms 692 KB Output is correct
36 Correct 284 ms 672 KB Output is correct
37 Correct 314 ms 828 KB Output is correct
38 Correct 318 ms 928 KB Output is correct
39 Correct 254 ms 808 KB Output is correct
40 Correct 487 ms 928 KB Output is correct
41 Correct 248 ms 692 KB Output is correct
42 Correct 147 ms 504 KB Output is correct
43 Correct 403 ms 928 KB Output is correct
44 Correct 293 ms 692 KB Output is correct
45 Correct 393 ms 1072 KB Output is correct
46 Correct 331 ms 924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 256 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Execution timed out 2076 ms 1744 KB Time limit exceeded
20 Halted 0 ms 0 KB -