Submission #535416

#TimeUsernameProblemLanguageResultExecution timeMemory
535416christinelynnRobots (IOI13_robots)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "robots.h"
using namespace std;

int putaway(int a, int b, int T, vector<int> x, vector<int> y, vector<int> W, vector<int> S){
  vector<pair<int,int>> w, s;
  for(int i=0;i<W.size();i++) w.push_back({W[i], i});
  for(int i=0;i<S.size();i++) s.push_back({S[i], i});
  sort(w.begin(),w.end(), [&](pair<int,int> _x, pair<int,int> _y){
    return S[_x.second] > S[_y.second];
  });
  sort(s.begin(),s.end(), [&](pair<int,int> _x, pair<int,int> _y){
    return W[_x.second] > W[_y.second];
  });
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  queue<pair<int,int>> q;
  vector<int> dist(T, -1);
  for(int i=0;i<a;i++)
  {
    for(int j=0;j<T;j++)
      if(w[j].first < x[i] && dist[w[j].second] == -1)
      {
        q.push({x[i], w[j].second});
        dist[w[j].second] = 1;
        break;
      }
  }
  for(int i=0;i<b;i++)
  {
    for(int j=0;j<T;j++)
    {
      if(s[j].first < y[i] && dist[s[j].second] == -1)
      {
        q.push({-y[i], s[j].second});
        dist[s[j].second] = 1;
        break;
      }
    }
  }
  while(!q.empty()){
    int c = q.front().first, id = q.front().second;// capacity & type, current vertex
    q.pop();
    if(c < 0) // size robot
    {
      c = -c;
      for(int i=0;i<T;i++)
      {  
        if(dist[s[i].second] == -1 && s[i].first < c)
        {
          dist[s[i].second] = dist[id] + 1;
          // cout << "S, C : " << c << ' ' << id << "-> " << s[i].second << "\n";
          q.push({-c, s[i].second});
          break;
        }
      }
    }
    else // weight robot
    {
      for(int i=0;i<T;i++)
      {
        if(dist[w[i].second] == -1 && w[i].first < c)
        {
          dist[w[i].second] = dist[id] + 1;
          // cout << "W , C : " << c << " " << id << "-> " << w[i].second << "\n";
          q.push({c, w[i].second});
          break;
        }
      }
    }
  }
  // for(int i=0;i<T;i++) cout << dist[i] << " "; cout << '\n';
  if(*min_element(dist.begin(), dist.end()) == -1) return -1;
  else return *max_element(dist.begin(), dist.end());
}

// int main(){
//   cin.tie(0) -> ios_base::sync_with_stdio(0);

//   int a, b, t;
//   cin >> a >> b >> t;
//   vector<int> x(a), y(b), w(t), s(t);
//   for(int i=0;i<a;i++) cin >> x[i];
//   for(int i=0;i<b;i++) cin >> y[i];
//   for(int i=0;i<t;i++)
//   {
//     cin >> w[i] >> s[i];
//   }
//   cout << putaway(a, b, t, x, y, w, s);

// }

Compilation message (stderr)

robots.cpp: In function 'int putaway(int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
robots.cpp:7:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |   for(int i=0;i<W.size();i++) w.push_back({W[i], i});
      |               ~^~~~~~~~~
robots.cpp:8:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |   for(int i=0;i<S.size();i++) s.push_back({S[i], i});
      |               ~^~~~~~~~~
/usr/bin/ld: /tmp/cc2TaQNJ.o: in function `main':
grader.c:(.text.startup+0x1b1): undefined reference to `putaway'
collect2: error: ld returned 1 exit status