Submission #1075431

# Submission time Handle Problem Language Result Execution time Memory
1075431 2024-08-26T06:00:05 Z Muhammad_Aneeq Radio Towers (IOI22_towers) C++17
0 / 100
4000 ms 8536 KB
#include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int const MAXN=1e5+10,LG=18;
int sp[MAXN][LG]={};
int n;
int dp[MAXN]={};
int a[MAXN]={};
bool uni=1;
int k=0;
void init(int N,vector<int> H)
{
	for (int i=0;i<N;i++)
		sp[i][0]=H[i],a[i]=H[i];
	for (int i=1;(1<<i)<=N;i++)
		for (int j=0;j+(1<<i)-1<N;j++)
			sp[j][i]=max(sp[j][i-1],sp[j+(1<<(i-1))][i-1]);
	n=N;
	for (int i=0;i+1<n;i++)
	{
		if (a[i]<a[i+1])
			continue;
		else
		{
			k=i;
			break;
		}
	}
	for (int i=k;i+1<n;i++)
	{
		if (a[i]>a[i+1])
			continue;
		else
		{
			uni=0;
			break;
		}
	}
	cout<<k<<endl;
}
int get(int l,int r)
{
	if (l>r)
		return -1;
	int lg=log2(r-l+1);
	return max(sp[l][lg],sp[r-(1<<lg)+1][lg]);
}
int max_towers(int L, int R, int D)
{
	if (uni)
	{
		if (k>L&&k<R)
		{
			if (max(a[L],a[R])+D<=a[k])
				return 2;
		}
		return 1;
	}
	int i=L,j=R;
	if (R-L+1<3)
	{
		return R-L+1;
	}
	int ans=0;
	for (int i=L;i<=R;i++)
	{
		dp[i]=1;
		for (int j=i-2;j>=L;j--)
		{
			int z=get(j+1,i-1);
			if (z>=max(a[i],a[j])+D)
				dp[i]=max(dp[i],dp[j]+1);
		}
		ans=max(ans,dp[i]);
	}
	return ans;
}

Compilation message

towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:61:6: warning: unused variable 'i' [-Wunused-variable]
   61 |  int i=L,j=R;
      |      ^
towers.cpp:61:10: warning: unused variable 'j' [-Wunused-variable]
   61 |  int i=L,j=R;
      |          ^
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 5208 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4048 ms 8536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4014 ms 2428 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 5208 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -