Submission #736540

#TimeUsernameProblemLanguageResultExecution timeMemory
736540AdamGSRarest Insects (IOI22_insects)C++17
53.16 / 100
192 ms428 KiB
#include "insects.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
int min_cardinality(int n) {
  vector<int>A, B;
  rep(i, n) {
    move_inside(i);
    if(press_button()==1) A.pb(i);
    else {
      B.pb(i);
      move_outside(i);
    }
  }
  for(auto i : A) move_outside(i);
  int po=0, ko=n/(int)A.size()-1;
  stack<pair<int,int>>S;
  S.push({-1, -1});
  mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
  rep(i, A.size()) swap(A[i], A[rng()%(i+1)]);
  int ile=0, akt=0;
  while(po<ko) {
    ++akt;
    int sr=(po+ko+1)/2;
    vector<int>tmp;
    rep(i, B.size()) swap(B[i], B[rng()%(i+1)]);
    for(auto i : B) {
      move_inside(i);
      ++ile;
      int x=press_button();
      if(x>sr) {
        move_outside(i);
        --ile;
        tmp.pb(i);
        continue;
      }
      S.push({akt, i});
    }
    B=tmp;
    if(ile==(int)A.size()*sr) po=sr; else {
      while(S.top().st==akt) {
        --ile;
        move_outside(S.top().nd);
        B.pb(S.top().nd);
        S.pop();
      }
      ko=sr-1;
    }
  }
  return po+1;
}

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
insects.cpp:24:3: note: in expansion of macro 'rep'
   24 |   rep(i, A.size()) swap(A[i], A[rng()%(i+1)]);
      |   ^~~
insects.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
insects.cpp:30:5: note: in expansion of macro 'rep'
   30 |     rep(i, B.size()) swap(B[i], B[rng()%(i+1)]);
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...