답안 #962967

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962967 2024-04-14T10:18:21 Z serkanrashid 로봇 (IOI13_robots) C++14
14 / 100
2923 ms 18932 KB
#include "robots.h"
#include <bits/stdc++.h>

using namespace std;

struct toy
{
    int w,s;
    toy(){};
    toy(int wi, int si)
    {
        w = wi;
        s = si;
    }
};

const int maxt = 1e6;
const int maxr = 5e4;

int t;
toy k[maxt];

int a,b,x[maxr],y[maxr];


bool cmp1(toy p1, toy p2)
{
    if(p1.w==p2.w) return p1.s>p2.s;
    return p1.w<p2.w;
}

bool cmp2(toy p1, toy p2)
{
    if(p1.s==p2.s) return p1.w>p2.w;
    return p1.s<p2.s;
}

bool check1(int z)
{
    sort(k,k+t,cmp1);
    int p = 0;
    for(int i = 0; i < a; i++)
    {
        int br = 0;
        while(br<z&&p<t&&k[p].w<=x[i])
        {
            br++;
            p++;
        }
    }
    vector<toy>pom;
    for(int i = p; i < t; i++) pom.push_back(k[i]);
    sort(pom.begin(),pom.end(),cmp2);
    p = 0;
    for(int i = 0; i < b; i++)
    {
        int br = 0;
        while(br<z&&p<pom.size()&&k[p].s<=y[i])
        {
            br++;
            p++;
        }
    }
    return p>=pom.size();
}

bool check2(int z)
{
    sort(k,k+t,cmp2);
    int p = 0;
    for(int i = 0; i < b; i++)
    {
        int br = 0;
        while(br<z&&p<t&&k[p].s<=y[i])
        {
            br++;
            p++;
        }
    }
    vector<toy>pom;
    for(int i = p; i < t; i++) pom.push_back(k[i]);
    sort(pom.begin(),pom.end(),cmp1);
    p = 0;
    for(int i = 0; i < a; i++)
    {
        int br = 0;
        while(br<z&&p<pom.size()&&k[p].w<=x[i])
        {
            br++;
            p++;
        }
    }
    return p>=pom.size();
}

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[])
{
    a = A;
    b = B;
    for(int i = 0; i < A; i++) x[i] = X[i]-1;
    for(int i = 0; i < B; i++) y[i] = Y[i]-1;
    t = T;
    for(int i = 0; i < T; i++)
    {
        k[i].w = W[i];
        k[i].s = S[i];
    }
    if(a) sort(x,x+a);
    if(b) sort(y,y+b);
    //for(int i = 0; i < T; i++) if((!a||W[i]>x[a-1])&&(!b||S[i]>y[b-1])) return -1;
    int l = 1, r = t;
    int mid;
    while(l<=r)
    {
        mid = (l+r)/2;
        if(check1(mid)||check2(mid)) r = mid-1;
        else l = mid+1;
    }
    if(l>t) l = -1;
    return l;
}

Compilation message

robots.cpp: In function 'bool check1(int)':
robots.cpp:58:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<toy>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         while(br<z&&p<pom.size()&&k[p].s<=y[i])
      |                     ~^~~~~~~~~~~
robots.cpp:64:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<toy>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     return p>=pom.size();
      |            ~^~~~~~~~~~~~
robots.cpp: In function 'bool check2(int)':
robots.cpp:87:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<toy>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         while(br<z&&p<pom.size()&&k[p].w<=x[i])
      |                     ~^~~~~~~~~~~
robots.cpp:93:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<toy>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |     return p>=pom.size();
      |            ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 908 ms 18788 KB Output is correct
5 Correct 2923 ms 18932 KB Output is correct
6 Correct 69 ms 7376 KB Output is correct
7 Correct 945 ms 18872 KB Output is correct
8 Correct 1051 ms 18828 KB Output is correct
9 Correct 837 ms 18724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -