Submission #833776

# Submission time Handle Problem Language Result Execution time Memory
833776 2023-08-22T08:35:29 Z kevinsogo Dancing Elephants (IOI11_elephants) C++17
26 / 100
9000 ms 3252 KB
#include <bits/stdc++.h>
using namespace std;
#include "elephants.h"
using ll = long long;

#ifdef LOCAL
bool debug = true;
#else
bool debug = false;
#endif

int n, L;
vector<pair<int,int>> x;
vector<int> best;

void init(int N, int L, int X[]) {
    n = N;
    ::L = L;
    x.resize(n);
    best.resize(n + 1);
    for (int i = 0; i < n; i++) {
        x[i] = {X[i], i};
    }
}

int update(int i, int y) {
    if (debug) { cerr << "DOING UPDATE " << i << " " << y << endl; }
    if (debug) { cerr << "INITIALLY:    "; }
    if (debug) { for (int t = 0; t < n; t++) cerr << x[t].first << " "; cerr << endl; }

    for (int t = 0; t < x.size(); t++) {
        auto& [v, j] = x[t];
        if (j == i) {
            v = y;
            i = t;
            break;
        }
    }
    assert(x[i].first == y);

    while (i + 1 < n and x[i].first > x[i + 1].first) {
        swap(x[i], x[i + 1]);
        i++;
    }
    while (i - 1 >= 0 and x[i - 1].first > x[i].first) {
        swap(x[i - 1], x[i]);
        i--;
    }
    if (debug) { cerr << "AFTER UPDATE: "; }
    if (debug) { for (int t = 0; t < n; t++) cerr << x[t].first << " "; cerr << endl; }

    int prev = -1;

    for (int i = 0; i < n; i++) {
        while (prev + 1 < i and x[prev + 1].first <= x[i].first - L - 1) {
            prev++;
        }
        best[i + 1] = best[prev + 1] + 1;
    }
    return best[n];
}

Compilation message

elephants.cpp: In function 'int update(int, int)':
elephants.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int t = 0; t < x.size(); t++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 212 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 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3483 ms 1996 KB Output is correct
8 Correct 4921 ms 2196 KB Output is correct
9 Correct 6487 ms 3252 KB Output is correct
10 Execution timed out 9082 ms 3004 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3483 ms 1996 KB Output is correct
8 Correct 4921 ms 2196 KB Output is correct
9 Correct 6487 ms 3252 KB Output is correct
10 Execution timed out 9082 ms 3004 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3483 ms 1996 KB Output is correct
8 Correct 4921 ms 2196 KB Output is correct
9 Correct 6487 ms 3252 KB Output is correct
10 Execution timed out 9082 ms 3004 KB Time limit exceeded
11 Halted 0 ms 0 KB -