Submission #764338

# Submission time Handle Problem Language Result Execution time Memory
764338 2023-06-23T10:48:17 Z boris_mihov Dancing Elephants (IOI11_elephants) C++17
26 / 100
9000 ms 2132 KB
#include "elephants.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <random>
#include <vector>
#include <set>

typedef long long llong;
const int MAXN = 150000 + 10;
const int INF  = 2e9;

int n, len;
int a[MAXN];
int x[MAXN];
void init(int N, int L, int X[])
{
    n = N;
    len = L;
    for (int i = 0 ; i < n ; ++i)
    {
        a[i + 1] = x[i + 1] = X[i];
    }
}

int update(int idx, int y)
{
    idx++;
    int pos;
    for (int i = 1 ; i <= n ; ++i)
    {
        if (a[i] == x[idx])
        {
            a[i] = y;
            pos = i;
            break;
        }
    }

    x[idx] = y;
    idx = pos;
    
    while (idx > 1 && a[idx - 1] > a[idx])
    {
        std::swap(a[idx - 1], a[idx]);
        idx--;
    }

    while (idx < n && a[idx + 1] < a[idx])
    {
        std::swap(a[idx], a[idx + 1]);
        idx++;
    }

    std::sort(a + 1, a + 1 + n);
    int coveredTo = -1, ans = 0;
    for (int i = 1 ; i <= n ; ++i)
    {
        if (coveredTo < a[i])
        {
            ans++;
            coveredTo = a[i] + len;
        }
    }

    return ans;
}

Compilation message

elephants.cpp: In function 'int update(int, int)':
elephants.cpp:30:9: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |     int pos;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 7100 ms 1956 KB Output is correct
8 Execution timed out 9097 ms 2132 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 7100 ms 1956 KB Output is correct
8 Execution timed out 9097 ms 2132 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 7100 ms 1956 KB Output is correct
8 Execution timed out 9097 ms 2132 KB Time limit exceeded
9 Halted 0 ms 0 KB -