#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;
^
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |