Submission #241636

# Submission time Handle Problem Language Result Execution time Memory
241636 2020-06-24T22:05:41 Z ChrisT Lightning Conductor (POI11_pio) C++17
45 / 100
1000 ms 16744 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pib = pair<int,bool>;
using ll = long long;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#ifdef fread_unlocked
#define fread fread_unlocked
#define fwrite fwrite_unlocked
#endif
#define lc ind<<1
#define rc ind<<1|1
const int MN = 501265, MOD = 1e9+7, BASE = 31;
int h[MN]; ld mx[MN];
ld get (int x, int y) {
	return h[y] + sqrtl(abs(x-y));
}
int intersect (int a, int b) { //when does a pass b?
	int low = 1, high = min(a,b) - 1, mid, ans = 0;
	while (low <= high) {
		mid = (low + high) / 2;
		if (get(mid,a) > get(mid,b)) low = (ans = mid) + 1;
		else high = mid - 1;
	}
	return ans;
}
// -1 -1 -1 -1 0 0 0 0 1 1 1 1
int main () {
	int n;
	scanf ("%d",&n);
	for (int i = 1; i <= n; i++) scanf ("%d",h+i);
	deque<int> dq;
	for (int i = n; i >= 1; i--) {
		while ((int)dq.size()>1 && get(i,dq.front()) < get(i,dq[1])) dq.pop_front();
		if (i<n) {
			mx[i] = max(mx[i],get(i,dq.front()));
			for (int j : dq) mx[i] = max(mx[i],get(i,j));
		}
		while ((int)dq.size() > 1 && intersect(i,dq.back()) > intersect(dq.back(),dq[(int)dq.size()-2])) dq.pop_back();
		dq.push_back(i);
	}
	dq.clear();
	reverse(h+1,h+1+n);
	for (int i = n; i >= 1; i--) {
		while ((int)dq.size()>1 && get(i,dq.front()) < get(i,dq[1])) dq.pop_front();
		if (i<n) {
			mx[n-i+1] = max(mx[n-i+1],get(i,dq.front()));
			for (int j : dq) mx[n-i+1] = max(mx[n-i+1],get(i,j));
		}
		while ((int)dq.size() > 1 && intersect(i,dq.back()) > intersect(dq.back(),dq[(int)dq.size()-2])) dq.pop_back();
		dq.push_back(i);
	}
	for (int i = 1; i <= n; i++) printf ("%d\n",(int)ceill(max((ld)0,mx[i] - h[n-i+1])));
	return 0;
}

Compilation message

pio.cpp: In function 'int main()':
pio.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d",&n);
  ~~~~~~^~~~~~~~~
pio.cpp:32:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf ("%d",h+i);
                               ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 242 ms 2636 KB Output is correct
2 Execution timed out 1064 ms 1052 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 422 ms 3704 KB Output is correct
2 Execution timed out 1045 ms 2240 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 6560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 678 ms 12380 KB Output is correct
2 Execution timed out 1089 ms 4088 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 955 ms 16744 KB Output is correct
2 Execution timed out 1092 ms 4472 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 8532 KB Time limit exceeded
2 Halted 0 ms 0 KB -