Submission #1058341

# Submission time Handle Problem Language Result Execution time Memory
1058341 2024-08-14T09:26:37 Z Dan4Life Rarest Insects (IOI22_insects) C++17
Compilation error
0 ms 0 KB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a), end(a)
using vi = vector<int>;
int D, inside[3000];
 
int min_cardinality(int n) {
    for(int i = 0; i < n; i++){
        move_inside(i);
        if(press_button()>1) move_outside(i);
        else inside[i]=1, D++;
    }
    if(D==1) return n;
    if(D==n) return 1;
    int l = 1, r = n/D, p=1, tot=D,ans=1;
    while(l<=r){
        int mid = (l+r)/2;
        for(int i = 0; i < n; i++)
            if(inside[i] >= mid and mid<=p)
                move_outside(i), inside[i]=0, tot--;
        vector<int> v(n,0); iota(all(v));
        random_shuffle(all(v));
        for(auto i : v){
            if(!!inside[i] or tot==D*mid) continue; move_inside(i);
            if(press_button()>mid) move_outside(i);
            else inside[i]=mid, tot++;
        }
        if(tot==D*mid) ans=mid,l = mid+1;
        else{
            for(int i = 0; i < n; i++) 
                if(!inside[i]) inside[i]=-1;
            r=mid-1;
        }
        p=mid;
    }
    return ans;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:24:40: error: no matching function for call to 'iota(std::vector<int>::iterator, std::vector<int>::iterator)'
   24 |         vector<int> v(n,0); iota(all(v));
      |                                        ^
In file included from /usr/include/c++/10/numeric:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:84,
                 from insects.cpp:2:
/usr/include/c++/10/bits/stl_numeric.h:88:5: note: candidate: 'template<class _ForwardIterator, class _Tp> void std::iota(_ForwardIterator, _ForwardIterator, _Tp)'
   88 |     iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
      |     ^~~~
/usr/include/c++/10/bits/stl_numeric.h:88:5: note:   template argument deduction/substitution failed:
insects.cpp:24:40: note:   candidate expects 3 arguments, 2 provided
   24 |         vector<int> v(n,0); iota(all(v));
      |                                        ^
insects.cpp:27:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   27 |             if(!!inside[i] or tot==D*mid) continue; move_inside(i);
      |             ^~
insects.cpp:27:53: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   27 |             if(!!inside[i] or tot==D*mid) continue; move_inside(i);
      |                                                     ^~~~~~~~~~~