Submission #853907

# Submission time Handle Problem Language Result Execution time Memory
853907 2023-09-25T12:55:02 Z x0r Lightning Conductor (POI11_pio) C++17
100 / 100
737 ms 21816 KB
#include <bits/stdc++.h>

#define name ""
#define ll long long
#define ld long double
#define fi first 
#define se second
#define pll pair < ll, ll >
#define pii pair < int, int >
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZE(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define lnode node * 2, l, (l + r) / 2
#define rnode node * 2 + 1, (l + r) / 2 + 1, r

using namespace std;

const ld EPS = 1e-9;
const int INF = 1e9 + 7;
const ll LINF = 1E18;
const int NMAX = 5e5;
const ll MOD = 1e9 + 7;
const ll BASE = 2309;
const int LG = 19;

ll n, a[NMAX + 3], pre[NMAX + 3], suff[NMAX + 3];

int main() {
	fast;
	if(fopen(name".inp", "r")) {
		freopen(name".inp", "r", stdin);
		freopen(name".out", "w", stdout);
	}
	//int t; cin >> t; while (t --) sol();
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) {
		for (int j = 0; i + j * j + 1 <= n; j++) 
			pre[i + j * j + 1] = max(pre[i + j * j + 1], a[i] + j + 1);
		for (int j = 0; i - j * j - 1 >= 1; j++)
			suff[i - j * j - 1] = max(suff[i - j * j - 1], a[i] + j + 1);
	}
	for (int i = 1; i <= n; i++) pre[i] = max(pre[i], pre[i - 1]);
	for (int i = n; i >= 1; i--) suff[i] = max(suff[i], suff[i + 1]);
	for (int i = 1; i <= n; i++) cout << max(0ll, max(pre[i], suff[i]) - a[i]) << '\n';
}

Compilation message

pio.cpp: In function 'int main()':
pio.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   freopen(name".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pio.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   freopen(name".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 3192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 3708 KB Output is correct
2 Correct 38 ms 3768 KB Output is correct
3 Correct 37 ms 3916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 6404 KB Output is correct
2 Correct 68 ms 6484 KB Output is correct
3 Correct 79 ms 6876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 237 ms 9048 KB Output is correct
2 Correct 242 ms 11088 KB Output is correct
3 Correct 244 ms 11028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 437 ms 16808 KB Output is correct
2 Correct 489 ms 14476 KB Output is correct
3 Correct 427 ms 15244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 737 ms 21816 KB Output is correct
2 Correct 710 ms 18968 KB Output is correct
3 Correct 716 ms 19964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 706 ms 19796 KB Output is correct
2 Correct 711 ms 19040 KB Output is correct
3 Correct 713 ms 20060 KB Output is correct