Submission #81838

# Submission time Handle Problem Language Result Execution time Memory
81838 2018-10-27T06:53:20 Z tmwilliamlin168 Lightning Conductor (POI11_pio) C++14
72 / 100
1000 ms 9708 KB
#include <bits/stdc++.h>
using namespace std;

inline int in() {
	int r=0;
	char ch=getchar_unlocked();
	while(1) {
		if(ch>='0'&&ch<='9')
			break;
		ch=getchar_unlocked();
	}
	r=ch-'0';
	while(1) {
		ch=getchar_unlocked();
		if (ch<'0'||ch>'9')
			break;
		r=r*10+ch-'0';
	}
	return r;
}
inline void out(int x) {
	if(!x) {
		putchar_unlocked('0');
		return;
	}
	int r=x, c=0;
	while(!(r%10)) {
		++c;
		r/=10;
	}
	r=0;
	while(x) {
		r=r*10+x%10;
		x/=10;
	}
	while(r) {
		putchar_unlocked(r%10+'0');
		r/=10;
	}
	while(c--)
		putchar_unlocked('0');
}

const int mxN=5e5;
int n, h[mxN], a[mxN], a1[mxN+1], a2[mxN+1];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	n=in();
	for(int i=0; i<n; ++i) {
		a1[i+1]=max(a[i]=h[i]=in(), a1[i]);
		for(int j=0; i-j*j-1>=0; ++j)
			a1[i+1]=max(++a[i-j*j-1], a1[i+1]);
	}
	for(int i=n-1; i>=0; --i) {
		a2[i]=max(a[i]=h[i], a2[i+1]);
		for(int j=0; i+j*j+1<=n-1; ++j)
			a2[i]=max(++a[i+j*j+1], a2[i]);
	}
	for(int i=0; i<n; ++i) {
		out(max(a1[i+1], a2[i])-h[i]);
		putchar_unlocked('\n');
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 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 2 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 1824 KB Output is correct
2 Correct 53 ms 1972 KB Output is correct
3 Correct 48 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 2568 KB Output is correct
2 Correct 95 ms 2568 KB Output is correct
3 Correct 116 ms 3172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 353 ms 5444 KB Output is correct
2 Correct 392 ms 5444 KB Output is correct
3 Correct 348 ms 5804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 725 ms 9708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 9708 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 9708 KB Time limit exceeded
2 Halted 0 ms 0 KB -