Submission #133619

# Submission time Handle Problem Language Result Execution time Memory
133619 2019-07-21T06:43:46 Z tinjyu Dancing Elephants (IOI11_elephants) C++14
26 / 100
9000 ms 3512 KB
#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

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 time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2542 ms 2168 KB Output is correct
8 Correct 3786 ms 2424 KB Output is correct
9 Correct 3338 ms 3512 KB Output is correct
10 Correct 8386 ms 3296 KB Output is correct
11 Correct 8115 ms 3236 KB Output is correct
12 Execution timed out 9065 ms 3320 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2542 ms 2168 KB Output is correct
8 Correct 3786 ms 2424 KB Output is correct
9 Correct 3338 ms 3512 KB Output is correct
10 Correct 8386 ms 3296 KB Output is correct
11 Correct 8115 ms 3236 KB Output is correct
12 Execution timed out 9065 ms 3320 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2542 ms 2168 KB Output is correct
8 Correct 3786 ms 2424 KB Output is correct
9 Correct 3338 ms 3512 KB Output is correct
10 Correct 8386 ms 3296 KB Output is correct
11 Correct 8115 ms 3236 KB Output is correct
12 Execution timed out 9065 ms 3320 KB Time limit exceeded
13 Halted 0 ms 0 KB -