# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
411282 | LouayFarah | Dancing Elephants (IOI11_elephants) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
#include "elephants.h"
using namespace std;
int n, l;
int *x;
vector<int> pos;
vector<int> ele;
int n, l;
int *x;
vector<int> pos;
vector<int> ele;
void init(int N, int L, int X[])
{
n = N;
l = L;
x = X;
pos.resize(n);
ele.resize(n);
for(int i = 0; i<n; i++)
{
pos[i] = i;
ele[i] = x[i];
}
}
int solve()
{
int len = x[0];
len+=l;
int res = 1;
int j = 1;
while(j<n)
{
while(j<n&&x[j]<=len)
j++;
res++;
len = x[j]+l;
}
return res-1;
}
int get_max()
{
int maxi = 0;
for(int j = 0; j<n; j++)
maxi = max(maxi, x[j]);
return maxi;
}
void count_sort(int e)
{
vector<int> book(10, 0);
for(int j = 0; j<n; j++)
book[(x[j]/e)%10]++;
/*for(int j = 0; j<10; j++)
cout << book[j] << ' ';
cout << endl;*/
int output[n];
for(int j = 1; j<10; j++)
book[j]+=book[j-1];
for(int j = n-1; j>=0; j--)
{
output[book[(x[j]/e)%10]-1] = x[j];
book[(x[j]/e)%10]--;
}
for(int j = 0; j<n; j++)
x[j] = output[j];
}
void radix_sort()
{
int m = get_max();
for(int e = 1; m/e>0; e*=10)
count_sort(e);
}
int update(int i, int y)
{
int ind = lower_bound(x, x+n, ele[i]) - x;
x[ind] = y;
ele[i] = y;
radix_sort();
/*for(int j = 0; j<n; j++)
cout << x[j] << ' ';
cout << endl;*/
int res = solve();
return res;
}