Submission #167429

# Submission time Handle Problem Language Result Execution time Memory
167429 2019-12-08T14:36:53 Z Thuleanx Lightning Conductor (POI11_pio) C++14
81 / 100
1000 ms 20272 KB
#include <bits/stdc++.h>
using namespace std;

int n;

vector<int> solve(vector<int> &h) {
	vector<int> ans(n), mi(n, 0);
	int hi = 0;
	for (int i = 0; i < n; i++) {
		hi = max(hi, mi[i]);
		ans[i] = max(0, hi - h[i]);
		for (int j = 0; i + j*j + 1 < n; j++)
			mi[i+j*j+1] = max(mi[i + j*j + 1], h[i] + j + 1);
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;

	vector<int> h(n);
	for (int i = 0; i < n; i++)
		cin >> h[i];
	vector<int> ans = solve(h);
	reverse(h.begin(), h.end());
	vector<int> ans2 = solve(h);
	reverse(ans2.begin(), ans2.end());
	stringstream ss;
	for (int i = 0; i < n; i++)
		ss << max(ans[i], ans2[i]) << endl;
	cout << ss.str();

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 2032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 3076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 2708 KB Output is correct
2 Correct 58 ms 2056 KB Output is correct
3 Correct 63 ms 3316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 3868 KB Output is correct
2 Correct 114 ms 3800 KB Output is correct
3 Correct 114 ms 5456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 400 ms 8588 KB Output is correct
2 Correct 398 ms 8020 KB Output is correct
3 Correct 391 ms 10100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 773 ms 20272 KB Output is correct
2 Correct 779 ms 12776 KB Output is correct
3 Correct 772 ms 19148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1068 ms 12968 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1048 ms 13144 KB Time limit exceeded
2 Halted 0 ms 0 KB -