Submission #598629

# Submission time Handle Problem Language Result Execution time Memory
598629 2022-07-18T15:33:03 Z definitelynotmee Fountain Parks (IOI21_parks) C++17
Compilation error
0 ms 0 KB
#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename t>
using matrix = vector<vector<t>>;


int construct_roads(std::vector<int> x, std::vector<int> y) {
    if (x.size() == 1) {
	build({}, {}, {}, {});
        return 1;
    }
    int n = x.size();
    std::vector<int> u, v, a, b;

    int dx[]{1,0,-1,0};
    int dy[]{0,1,0,-1};

    vector<int> pai(n);
    int comp = n;
    iota(all(pai),0);

    auto find =[&](int id, auto f){
        if(pai[id] == id)
            return id;
        return pai[id] = f(pai[id],f);
    };
    auto onion =[&](int a, int b){
        int pa = find(a,find);
        int pb = find(b,find);
        if(pa != pb){
            comp--;
            u.push_back(a);
            v.push_back(b);
        }
        pai[pa] = pb;
    };
    map<pii,int> fount;



    for(int i = 0; i < n; i++)
        fount[{x[i],y[i]}] = i;


    for(int i = 0; i < n; i++){
        for(int j = 0; j < 4; j++){
            int xi = x[i] + dx[j]*2, yi = y[i]+dy[j]*2;
            if(fount.count({xi,yi}))
                onion(i,fount[{xi,yi}]);
        }
    }
    if(comp > 1)
        return 0;

    set<pii> bench;

    mt19937 rng(time(nullptr));
    vector<int>o(n-1);
    iota(all(o));
    shuffle(all(o),rng);

    for(int i : o){
        int cx = (x[u[i]]+x[v[i]])>>1, cy = (y[u[i]]+y[v[i]])>>1;
        bool ok = 0;
        for(int j = 0; j < 4; j++){
            int xi = cx + dx[j], yi = cy+dy[j];
            if(!((xi&1)&&(yi&1)))
                continue;
            if(!bench.count({xi,yi})){
                a.push_back(xi);
                b.push_back(yi);
                bench.insert({xi,yi});
                ok = 1;
                break;
            }
        }
        if(!ok)
            return 0;
    }
    build(u,v,a,b);

    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:66:16: error: no matching function for call to 'iota(std::vector<int>::iterator, std::vector<int>::iterator)'
   66 |     iota(all(o));
      |                ^
In file included from /usr/include/c++/10/numeric:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:84,
                 from parks.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:
parks.cpp:66:16: note:   candidate expects 3 arguments, 2 provided
   66 |     iota(all(o));
      |                ^