Submission #308840

# Submission time Handle Problem Language Result Execution time Memory
308840 2020-10-02T04:51:34 Z shivensinha4 Lightning Conductor (POI11_pio) C++17
72 / 100
1000 ms 6272 KB
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'


int main() {
	#ifdef shiven
	freopen("test.in", "r", stdin);
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin >> n;
	vi h(n), pt, pref(n), suf(n);
	for_(i, 0, n) {
		cin >> h[i];
		pref[i] = suf[i] = h[i];
	}
	for_(i, 0, n) {
		if (i*i+1 < n) pt.push_back(i*i+1);
		else break;
	}
	
	for_(i, 0, n) {
		for_(k, 0, pt.size()) {
			if (i+pt[k] < n) pref[i+pt[k]] = max(pref[i+pt[k]], h[i]+k+1);
			else break;
		}
		for_(k, 0, pt.size()) {
			if (i-pt[k] >= 0) suf[i-pt[k]] = max(suf[i-pt[k]], h[i]+k+1);
			else break;
		}
	}
	
	for_(i, 1, n) pref[i] = max(pref[i], pref[i-1]);
	for (int i = n-2; i >= 0; i--) suf[i] = max(suf[i], suf[i+1]);
	
	for_(i, 0, n) cout << max(pref[i], suf[i]) - h[i] << endl;
	

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 1504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 1528 KB Output is correct
2 Correct 111 ms 1532 KB Output is correct
3 Correct 115 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 1912 KB Output is correct
2 Correct 209 ms 2040 KB Output is correct
3 Correct 205 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 703 ms 4116 KB Output is correct
2 Correct 711 ms 4088 KB Output is correct
3 Correct 697 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 4480 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1097 ms 6272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 6272 KB Time limit exceeded
2 Halted 0 ms 0 KB -