답안 #965523

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965523 2024-04-18T19:06:27 Z ThegeekKnight16 로봇 (IOI13_robots) C++17
0 / 100
3000 ms 15000 KB
#include <bits/stdc++.h>
#include "robots.h"
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("avx2")

bool Test(int x, int A, int B, int T, int *X, int *Y, const vector<pair<int, int>> &Toy)
{
    if ((long long)x*(A+B) < T) return 0;
    vector<int> sweep; //id
    sweep.reserve(max(A, B)+T);
    int idT = 0, idA = 0;
    while (idT < T && idA < A)
    {
        if (X[idA] <= Toy[idT].first) sweep.push_back(-1), idA++;
        else sweep.push_back(idT++);
    }
    while (idT < T) sweep.push_back(idT++);
    while (idA < A) sweep.push_back(-1), idA++;

    vector<int> remain;
    for (auto id : sweep)
    {
        if (id == -1)
        {
            int remov = x;
            if (remov >= remain.size()) remain.clear(), remov = 0;
            else
            {
                nth_element(remain.begin(), remain.end()-x, remain.end());
                while (remov > 0) remain.pop_back(), remov--;
            }
        }
        else remain.push_back(Toy[id].second);
    }

    sweep.clear(); //now type
    int idR = 0; int idB = 0;
    int cnt = 0;
    while (idR < remain.size() && idB < B)
    {
        if (Y[idB] <= remain[idR]) cnt = max(0, cnt-x), idB++;
        else cnt, idR++;
    }
    if (idR < remain.size()) return 0;
    while (idB < B) cnt = max(0, cnt-x), idB++;

    return (cnt == 0);
}

int putaway(int A, int B, int T, int X[], int Y[], int _W[], int _S[])
{
    vector<pair<int, int>> Toy(T);
    for (int i = 0; i < T; i++) Toy[i] = make_pair(_W[i], _S[i]);
    sort(X, X+A); sort(Y, Y+B);
    for (int i = 0; i < T; i++) if (Toy[i].first >= X[A-1] && Toy[i].second >= Y[B-1]) return -1;
    sort(Toy.begin(), Toy.end());

    int ini = 1, fim = T;
    while (ini < fim)
    {
        int m = (ini + fim) >> 1;
        if (Test(m, A, B, T, X, Y, Toy)) fim = m;
        else ini = m+1;
    }
    return fim;
}

Compilation message

robots.cpp: In function 'bool Test(int, int, int, int, int*, int*, const std::vector<std::pair<int, int> >&)':
robots.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             if (remov >= remain.size()) remain.clear(), remov = 0;
      |                 ~~~~~~^~~~~~~~~~~~~~~~
robots.cpp:40:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     while (idR < remain.size() && idB < B)
      |            ~~~~^~~~~~~~~~~~~~~
robots.cpp:43:14: warning: left operand of comma operator has no effect [-Wunused-value]
   43 |         else cnt, idR++;
      |              ^~~
robots.cpp:45:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     if (idR < remain.size()) return 0;
      |         ~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Execution timed out 3049 ms 15000 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -