Submission #769415

#TimeUsernameProblemLanguageResultExecution timeMemory
769415boris_mihovRobots (IOI13_robots)C++17
76 / 100
3075 ms28928 KiB
#include "robots.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <bitset>
#include <set>

typedef long long llong;
const int MAXN = 1000000 + 10;
const int MAXAB = 50000 + 10;

int n;
int a, b;
int w[MAXN];
int s[MAXN];
int permX[MAXN];
int permY[MAXN];
std::multiset <int> vals;

int check(int times, int X[], int Y[])
{
    vals.clear();
    int ptr = 0;
    int cntDestroyed = 0;
    for (int curr = 1 ; curr <= a ; ++curr)
    {
        while (ptr + 1 <= n && w[permX[ptr + 1]] <= X[curr - 1])
        {
            vals.insert(s[permX[ptr + 1]]);
            ptr++;
        }

        for (int t = 1 ; t <= times && vals.size() ; ++t)
        {
            vals.erase(vals.find(*vals.rbegin()));
        }
    }

    while (ptr + 1 <= n)
    {
        vals.insert(s[permX[ptr + 1]]);
        ptr++;
    }

    for (int curr = 1 ; curr <= b && vals.size() ; ++curr)
    {
        for (int t = 1 ; t <= times && vals.size() ; ++t)
        {
            auto it = vals.upper_bound(Y[curr - 1]);
            if (it == vals.begin())
            {
                break;
            } else
            {
                it = std::prev(it);
                vals.erase(it);
            }
        }
    }

    return vals.empty();
}

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) 
{
    a = A;
    b = B;
    n = T;

    for (int i = 1 ; i <= n ; ++i)
    {
        w[i] = W[i - 1] + 1;
        s[i] = S[i - 1] + 1;
    }

    std::iota(permX + 1, permX + 1 + n, 1);
    std::sort(permX + 1, permX + 1 + n, [&](const int &a, const int &b)
    {
        return w[a] < w[b];
    });

    std::iota(permY + 1, permY + 1 + n, 1);
    std::sort(permY + 1, permY + 1 + n, [&](const int &a, const int &b)
    {
        return s[a] < s[b];
    });

    std::sort(X, X + a);
    std::sort(Y, Y + b);

    // std::cout << "byW\n";
    // for (int i = 1 ; i <= n ; ++i)
    // {
    //     std::cout << w[sortedX.perm[i]] << ' ' << s[sortedX.perm[i]] << '\n';
    // }

    // std::cout << "byS\n";
    // for (int i = 1 ; i <= n ; ++i)
    // {
    //     std::cout << w[sortedY.perm[i]] << ' ' << s[sortedY.perm[i]] << '\n';
    // }

    int l = 0, r = n + 1, mid;
    while (l < r - 1)
    {
        mid = (l + r) / 2;
        if (!check(mid, X, Y)) l = mid;
        else r = mid;
    }

    check(2, X, Y);
    if (r == n + 1) return -1;
    return r;
}

Compilation message (stderr)

robots.cpp: In function 'int check(int, int*, int*)':
robots.cpp:26:9: warning: unused variable 'cntDestroyed' [-Wunused-variable]
   26 |     int cntDestroyed = 0;
      |         ^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...