Submission #483058

#TimeUsernameProblemLanguageResultExecution timeMemory
483058MohamedAliSaidaneRobots (IOI13_robots)C++14
0 / 100
3075 ms36652 KiB
#include <bits/stdc++.h>
#include "robots.h"
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> ti;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ld,ld> pld;
#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front
#define ff first
#define ss second
#define MOD (ll)(1000000007)
#define INF (ll) (1e18)
#define all(v) (v).begin(),(v).end()
const int nx[8] = {0, 0, 1, -1,1,1,-1,-1}, ny[8] = {1, -1, 0, 0,1,-1,1,-1}; //East, West, South, North+
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;}
ll lcm(ll a, ll b){return (a / gcd(a, b)) * b;}
////////////******SOLUTION******\\\\\\\\\\\

const int MAX_T = 1e6 + 4;
const int MAX_N = 5e4 + 4;

int A, B, T;
int X[MAX_N],Y[MAX_N], W[MAX_T], S[MAX_T];

pii toys[MAX_T];
pii byW[MAX_T];
pii byS[MAX_T];

bool comp(pii a, pii b)
{
    if(a.ff == b.ff)
        return a.ss >= b.ss;
    else
        return a.ff < b.ff;
}

bool how(pii a, pii b)
{
    if(a.ss == b.ss)
        return a.ff >= b.ff;
    else
        return a.ss < b.ss;
}

bool test(int x)
{
    //cout << x << " : \n";
    multiset<int> s;
    int time = 0;
    int i = 0;
    int j = 0;
    while(i < A)
    {
        int time = 0;
        for(; byW[j].ff < X[i] && j <T; j ++)
        s.insert(-byW[j].ss);
        //cout << "avant size ?" << s.size() << '\n';
        while(time < x && !s.empty())
        {
            //cout << "quoi " << i << ' ' << time << " value" << *(s.begin()) <<'\n';
            s.erase(s.begin());
            time ++;
        }
        //cout << '\t' <<  i << ' ' << j << '\n';
        //cout << "apres size ? " << s.size() << '\n';
        i ++;
    }
    multiset<int> rem;
    for(auto e: s)
        rem.insert(-e);
    for(;j<T;j ++)
        rem.insert(byW[j].ss);
    if(s.size() > B*x)
        return 0;
   // cout << "this far\n";
    i = 0;
    time = 0;
    while(!rem.empty())
    {
        if(i == B)
            return 0;
        int sz = *(rem.begin());
        //cout << "BS: "<< i << ' ' << sz << '\n';
        while(time < x && sz < Y[i])
        {
            time ++;
            rem.erase(rem.begin());
            if(rem.empty())
                return 1;
            sz = *(rem.begin());
            //cout << "not " << s.size() << ' ' << sz << '\n';
        }
        i ++;
    }
    return 1;
}

int putaway(int a, int b, int t, int x[], int y[], int w[], int s[])
{
    A = a, B = b, T = t;
    sort(x,x+A); sort(y,y+b);
    for(int i = 0; i < A; i ++)
        X[i] = x[i];
    for(int i = 0; i < B; i ++)
        Y[i] = y[i];
    for(int i = 0; i < T; i ++)
    {
        W[i] = w[i];
        S[i] = s[i];
        byW[i] = byS[i] = toys[i] = {W[i],S[i]};
    }
    int wmax = 0;
    int smax = 0;
    for(int i = 0; i < A; i ++)
        wmax = max(wmax,X[i]);
    for(int i = 0; i < B; i ++)
        smax = max(smax,Y[i]);
    for(int i = 0; i < T; i ++)
        if(W[i] >= wmax && S[i] >= smax)
            return -1;
    sort(byW,byW+T,comp);
    //for(int i = 0; i < T; i ++)
        //cout << byW[i].ff << ' ' << byW[i].ss << '\n';
    //cout << '\n';
    //sort(byS,byS+T,how);
    int debut = 1;
    int fin = T;
    int ans = T;
    while(debut <= fin)
    {
        int mid = (debut+fin)/2;
        if(test(mid))
        {
            ans = mid;
            fin = mid - 1;
        }
        else
            debut = mid + 1;
    }
    return ans;

}
/*
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int A, B, T;
    cin >> A >> B >> T;
    int X[A], Y[B], W[T], S[T];
    for(int i = 0; i < A; i ++)
    {
        int x; cin >> x;
        X[i]=x;
    }
    for(int i = 0; i< B; i ++)
    {
        int y; cin >> y;
        Y[i]=y;
    }
    for(int i = 0;  i < T; i ++)
    {
        int w, s;
        cin >> w >> s;
        W[i] = w;
        S[i] = s;
    }
    cout << putaway(A,B,T,X,Y,W,S) << '\n';
}
/*
5 0 6
2 3 4 5 6
1 80
2 80
3 80
4 80
1 80
5 80
*/
/*
3 2 10
6 2 9
4 7
4 6
8 5
2 3
7 9
1 8
5 1
3 3
8 7
7 6
10 5
*/

Compilation message (stderr)

robots.cpp:25:1: warning: multi-line comment [-Wcomment]
   25 | ////////////******SOLUTION******\\\\\\\\\\\
      | ^
robots.cpp:178:1: warning: "/*" within comment [-Wcomment]
  178 | /*
      |  
robots.cpp: In function 'bool test(int)':
robots.cpp:81:17: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   81 |     if(s.size() > B*x)
      |        ~~~~~~~~~^~~~~
#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...