Submission #971039

# Submission time Handle Problem Language Result Execution time Memory
971039 2024-04-27T21:09:41 Z andro Robots (IOI13_robots) C++14
0 / 100
2 ms 4444 KB
#include <bits/stdc++.h>

#include "robots.h"

using namespace std;

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    sort(X, X + A);
    sort(Y, Y + B);
    for(int i = 0; i < T; i++) {
        if(W[i] >= X[A - 1] && S[i] >= Y[B - 1]) {
            return - 1;
        }
    }
    vector<pair<int,int>> omg;
    for(int i = 0; i < T; i++) {
        omg.push_back({W[i], S[i]});
    }
    sort(omg.begin(), omg.end());
    int l = 1, r = 1e6, ans = - 1;
    while(l <= r) {
        int mid = (l + r) / 2;
        int pok = A - 1;
        int R = 0;
        int pok1 = B - 1;
        int ok = 0;
        int R1 = 0;
        multiset<pair<int,int>> ms;
        for(int i = 0; i < B; i++) {
            ms.insert({Y[i], 0});
        }
        for(int i = omg.size() - 1; i >= 0; i--) {
            //cout << i << ":::\n";
            //cout << "\n";
            if(pok < 0 && !ms.size()) {
                ok = 1;
                //cout << "NEMOGU NIJEDAN\n";
                break;
            }
            if(pok < 0) {
                auto it = ms.upper_bound({omg[i].second, -1});
                if(it == ms.end()) {
                    ok = 1;
                    //cout << "MORAO SAM IZ MS A NISAM IMAO STA DA UZMEM\n";
                    break;
                }
                int e1 = (*it).first;
                int e2 = (*it).second;
                e2 += 1;
                ms.erase(it);
                if(e2 >= mid) {
                    //cout << "obrisao sam i nisam ubacio natrag " << e1 << " " << e2 << "\n";
                }
                else {
                    ms.insert({e1, e2});
                    //cout << "ubacio sam1:" << e1 << " " << e2 << "\n";
                }
                continue;
            }
            if(!ms.size()) {
                if(X[pok] <= omg[i].first) {
                    ok = 1;
                    //cout << "NISAM MOGAO IZ MS A TAKODJE NI IZ X\n";
                    break;
                }
                R += 1;
                if(R >= mid) {
                    R = 0;
                    pok -= 1;
                }
            }
            if(X[pok] <= omg[i].first) {
                //! moram optimalno iz ms da uzmem i da azuriram
                auto it = ms.upper_bound({omg[i].second, -1});
                if(it == ms.end()) {
                    ok = 1;
                    //cout << "NEMOGU IZ X A NEMOGU NI IZ MS69\n";
                    break;
                }
                int e1 = (*it).first;
                int e2 = (*it).second;
                e2 += 1;
                ms.erase(it);
                if(e2 >= mid) {
                    //cout << "obrisao sam i nisam ubacio natrag " << e1 << " " << e2 << "\n";
                }
                else {
                    ms.insert({e1, e2});
                    //cout << "ubacio sam2:" << e1 << " " << e2 << "\n";
                }
                continue;
            }
            auto IT = ms.upper_bound({omg[i].second, -1});
            int nemamkogaizms = 0;
            if(IT == ms.end()) {
                nemamkogaizms = 1;
            }
            if(nemamkogaizms) {
                if(X[pok] <= omg[i].first) {
                    ok = 1;
                    //cout << "NEMOGU NI IZ MS NI IZ X\n";
                    break;
                }
                R += 1;
                if(R >= mid) {
                    R = 0;
                    pok -= 1;
                }
                continue;
            }
            // mogu oba gledam manji R
            auto it = ms.upper_bound({omg[i].second, -1});
            int e1 = (*it).first;
            int e2 = (*it).second;
            ms.erase(it);
            if(e2 <= R) {
                e2 += 1;
                if(e2 >= mid) {
                    //cout << "obrisao sam i nisam ubacio natrag " << e1 << " " << e2 << "\n";
                }
                else {
                    ms.insert({e1, e2});
                    //cout << "ubacio sam3:" << e1 << " " << e2 << "\n";
                }
            }
            else {
                ms.insert({e1, e2});
                R += 1;
                if(R >= mid) {
                    R = 0;
                    pok -= 1;
                }
            }
        }
        ok ^= 1;
        if(ok) {
            r = mid - 1;
            ans = mid;
        }
        else {
            l = mid + 1;
        }
    }
    return ans;
}
/*
int main() {
    int A = 3;
    int B = 2;
    int T = 10;
    int X[3] = {6, 2, 9};
    int Y[2] = {4, 7};
    int W[10] = {4, 8, 2, 7, 1, 5, 3, 8, 7, 10};
    int S[10] = {6, 5, 3, 9, 8, 1, 3, 7, 6, 5};
    cout << putaway(A, B, T, X, Y, W, S);
    int A = 2;
    int B = 1;
    int T = 3;
    int X[2] = {2, 5};
    int Y[1] = {2};
    int W[3] = {3, 5, 2};
    int S[3] = {1, 3, 2};
    cout << putaway(A, B, T, X, Y, W, S);
}*/

Compilation message

robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:25:13: warning: unused variable 'pok1' [-Wunused-variable]
   25 |         int pok1 = B - 1;
      |             ^~~~
robots.cpp:27:13: warning: unused variable 'R1' [-Wunused-variable]
   27 |         int R1 = 0;
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 1 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 1 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 1 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -