Submission #701155

# Submission time Handle Problem Language Result Execution time Memory
701155 2023-02-20T09:01:48 Z Baytoro Lightning Conductor (POI11_pio) C++17
100 / 100
347 ms 13920 KB
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
//#define int long long
#define ll long long
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+7;
const int N=5e5+5,M=1e4;
int h[N],ans[N];
void rec(int l, int r, int optl, int optr){
	if(l>r) return;
	int md=(l+r)/2,opt=optl;
	for(int i=optl;i<=min(md,optr);i++){
		if(h[i]+sqrt(abs(md-i))>h[opt]+sqrt(abs(md-opt))) opt=i;
	}
	ans[md]=max(ans[md],h[opt]+(int)ceil(sqrt(abs(md-opt)))-h[md]);
	rec(l,md-1,optl,opt);
	rec(md+1,r,opt,optr);
}
void solve(){
	int n;cin>>n;
	for(int i=1;i<=n;i++) cin>>h[i];
	rec(1,n,1,n);
	reverse(h+1,h+n+1);
	reverse(ans+1,ans+n+1);
	rec(1,n,1,n);
	for(int i=n;i>=1;i--)
		cout<<ans[i]<<'\n';
}
main(){
	//ios;
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
}

Compilation message

pio.cpp:39:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   39 | main(){
      | ^~~~
pio.cpp: In function 'void fopn(std::string)':
pio.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pio.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 1676 KB Output is correct
2 Correct 29 ms 1296 KB Output is correct
3 Correct 35 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 2472 KB Output is correct
2 Correct 63 ms 2416 KB Output is correct
3 Correct 55 ms 2532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 5408 KB Output is correct
2 Correct 151 ms 4988 KB Output is correct
3 Correct 134 ms 4920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 236 ms 9832 KB Output is correct
2 Correct 244 ms 7884 KB Output is correct
3 Correct 192 ms 8520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 338 ms 13920 KB Output is correct
2 Correct 347 ms 11052 KB Output is correct
3 Correct 277 ms 12076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 340 ms 11496 KB Output is correct
2 Correct 334 ms 11096 KB Output is correct
3 Correct 287 ms 12104 KB Output is correct