Submission #133619

#TimeUsernameProblemLanguageResultExecution timeMemory
133619tinjyuDancing Elephants (IOI11_elephants)C++14
26 / 100
9065 ms3512 KiB
#include "elephants.h"
#include <iostream>
using namespace std;
long long int n,l,x[100005][2];
void init(int N, int L, int X[])
{
  n = N,l = L;
  for(int i=0;i<n;i++)
  {
  	x[i][0]=X[i];
  	x[i][1]=i;
  }
}

int update(int i, int y)
{
	int t;
	for(int j=0;j<n;j++)
	{
		if(x[j][1]==i)
		{
			t=j;
			break;
		}
	}
	
	i=t;
	x[i][0]=y;
	if(x[i][0]<x[i-1][0])
	{
		for(int j=i-1;j>=0;j--)
		{
			if(x[j+1][0]<x[j][0])
			{
				swap(x[j+1][0],x[j][0]);
				swap(x[j+1][1],x[j][1]);
			}
			else break;
		}
	}
	else 
	{
		for(int j=i+1;j<n;j++)
		{
			//cout<<j<<endl;
			if(x[j-1][0]>x[j][0])
			{
				swap(x[j-1][0],x[j][0]);
				swap(x[j-1][1],x[j][1]);
			}
			else break;
		}
	}
	//for(int i=0;i<n;i++)
	//{
	//	cout<<x[i][0]<<" "<<x[i][1]<<"  ";
	//}
	//cout<<endl;
	long long int ans=1,now=x[0][0];
	for(int i=1;i<n;i++)
	{
		if(x[i][0]-now>l)
		{
			ans++;
			now=x[i][0];
		}
	}
 	return ans;
}

Compilation message (stderr)

elephants.cpp: In function 'int update(int, int)':
elephants.cpp:17:6: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int t;
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...