Submission #411282

# Submission time Handle Problem Language Result Execution time Memory
411282 2021-05-24T22:56:13 Z LouayFarah Dancing Elephants (IOI11_elephants) C++14
Compilation error
0 ms 0 KB
#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;
}

Compilation message

elephants.cpp:10:5: error: redefinition of 'int n'
   10 | int n, l;
      |     ^
elephants.cpp:5:5: note: 'int n' previously declared here
    5 | int n, l;
      |     ^
elephants.cpp:10:8: error: redefinition of 'int l'
   10 | int n, l;
      |        ^
elephants.cpp:5:8: note: 'int l' previously declared here
    5 | int n, l;
      |        ^
elephants.cpp:11:6: error: redefinition of 'int* x'
   11 | int *x;
      |      ^
elephants.cpp:6:6: note: 'int* x' previously declared here
    6 | int *x;
      |      ^
elephants.cpp:12:13: error: redefinition of 'std::vector<int> pos'
   12 | vector<int> pos;
      |             ^~~
elephants.cpp:7:13: note: 'std::vector<int> pos' previously declared here
    7 | vector<int> pos;
      |             ^~~
elephants.cpp:13:13: error: redefinition of 'std::vector<int> ele'
   13 | vector<int> ele;
      |             ^~~
elephants.cpp:8:13: note: 'std::vector<int> ele' previously declared here
    8 | vector<int> ele;
      |             ^~~