Submission #827123

#TimeUsernameProblemLanguageResultExecution timeMemory
827123Amylopectin드문 곤충 (IOI22_insects)C++17
99.95 / 100
50 ms432 KiB
#include "insects.h"
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
const int mxn = 5e3 + 10;
int io[mxn] = {},nop[mxn] = {};
vector<int> cro,fno;
int min_cardinality(int n) 
{
  int i,j,cn,cm,fn,fm,cou = 0,cl,cr,mid,ndif,of;
  move_inside(0);
  io[0] = 1;
  cou ++;
  for(i=1; i<n; i++)
  {
    move_inside(i);
    cou ++;
    io[i] = 1;
    cn = press_button();
    if(cn == 2)
    {
      move_outside(i);
      io[i] = 0;
      cou --;
    }
  }
  cl = 1;
  cr = n / cou;
  ndif = cou;
  of = 0;
  while(cl < cr)
  {
    mid = (cl+cr) / 2 + (cl+cr) % 2;
    cro.clear();
    fno.clear();
    for(i=0; i<n; i++)
    {
      if(io[i] == 0 && nop[i] == 0)
      {
        move_inside(i);
        cou ++;
        io[i] = 1;
        cn = press_button();
        if(cn > mid)
        {
          fno.push_back(i);
          move_outside(i);
          io[i] = 0;
          cou --;
        }
        else 
        {
          cro.push_back(i);
        }
        if(mid * ndif == cou)
        {
          break;
        }
      }
    }
    if(mid * ndif == cou)
    {
      cl = mid;
      of = 0;
    }
    else 
    {
      for(i=0; i<fno.size(); i++)
      {
        nop[fno[i]] = 1;
      }
      if(of == 1)
      {
        move_outside(cro[0]);
          io[cro[0]] = 0;
          cou --;
      }
      for(i=1; i<cro.size(); i++)
      {
        // if(io[i] == 1)
        // {
          move_outside(cro[i]);
          io[cro[i]] = 0;
          cou --;
        // }
      }
      of = 1;
      cr = mid-1;
    }
  }
  return cl;
}

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:69:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |       for(i=0; i<fno.size(); i++)
      |                ~^~~~~~~~~~~
insects.cpp:79:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |       for(i=1; i<cro.size(); i++)
      |                ~^~~~~~~~~~~
insects.cpp:11:9: warning: unused variable 'j' [-Wunused-variable]
   11 |   int i,j,cn,cm,fn,fm,cou = 0,cl,cr,mid,ndif,of;
      |         ^
insects.cpp:11:14: warning: unused variable 'cm' [-Wunused-variable]
   11 |   int i,j,cn,cm,fn,fm,cou = 0,cl,cr,mid,ndif,of;
      |              ^~
insects.cpp:11:17: warning: unused variable 'fn' [-Wunused-variable]
   11 |   int i,j,cn,cm,fn,fm,cou = 0,cl,cr,mid,ndif,of;
      |                 ^~
insects.cpp:11:20: warning: unused variable 'fm' [-Wunused-variable]
   11 |   int i,j,cn,cm,fn,fm,cou = 0,cl,cr,mid,ndif,of;
      |                    ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...