| 16971 | 2025-05-19 18:17:42 | horka | Labirintus | cpp17 | Forditási hiba |
#include "labirintus.h"
#include <bits/stdc++.h>
using namespace std;
#include <cassert>
#include <cstdio>
#include <array>
#include <vector>
#include <queue>
vector<vector<int>> d;
int n,m;
const int mxn=1005,p=1e6+5;
bool vis[mxn][mxn];
vector<array<int, 2>> dir{{0,1},{1,0},{-1,0},{0,-1}};
int lep;
int fonok[p],mer[p];
int holvan(int x)
{
return (fonok[x]==x?x:fonok[x]=holvan(fonok[x]));
}
void unio(int a, int b, int c, int d)
{
int x=(a-1)*m+b-1;
int y=(c-1)*m+d-1;
x=holvan(x);
y=holvan(y);
if(mer[x]>mer[y]) swap(x,y);
mer[y]+=mer[x];
fonok[x]=y;
}
set<array<int, 2>> last;
void init_labyrinth(int r, int c, std::vector<std::vector<int>> L) {
n=r,m=c;
d.assign(n+2, vector<int> (m+2, 1));
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
{
d[i][j]=L[i-1][j-1];
int f=(i-1)*m+j-1;
mer[f]=1;
fonok[f]=f;
}
return;
}
bool can_escape(int N, std::vector<int> u, std::vector<int> v) {
lep++;
if(lep==1)
{
for(int i=0; i<N; i++)
{
d[u[i]+1][v[i]+1]=1;
last.insert({u[i],v[i]});
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
if(i>1 && d[i][j]==0 && d[i-1][j]==0) unio(i,j,i-1,j);
if(j>1 && d[i][j]==0 && d[i][j-1]==0) unio(i,j,i,j-1);
}
}
}
else
{
set<int> curr;
for(int i=0; i<N; i++)
curr.insert({u[i],v[i]});
vector<array<int, 2>> tor;
for(auto &x:last)
{
if(curr.count(x)) continue;
auto [a,b]=x;
tor.push_back(x);
a++,b++;
d[a][b]=0;
if(d[a+1][b]==0) unio(a+1,b,a,b);
if(d[a-1][b]==0) unio(a-1,b,a,b);
if(d[a][b+1]==0) unio(a,b+1,a,b);
if(d[a][b-1]==0) unio(a,b-1,a,b);
}
for(int &x:tor)
last.erase(x);
}
return (holvan(0)==holvan((n-1)*m+m-1));
}
/*int main() {
int R, C, Q;
assert(3 == scanf("%d %d %d", &R, &C, &Q));
std::vector<std::vector<int>> labyrinth(R, std::vector<int>(C));
for (int i = 0; i < R; ++i) {
for (int j = 0; j < C; ++j) {
char c;
assert(1 == scanf(" %c", &c));
labyrinth[i][j] = c - '0';
}
}
init_labyrinth(R, C, labyrinth);
std::vector<int> answers(Q);
for (int i = 0; i < Q; ++i) {
int N;
assert(1 == scanf("%d", &N));
std::vector<int> U(N), V(N);
for (int j = 0; j < N; ++j) {
assert(2 == scanf("%d %d", &U[j], &V[j]));
}
answers[i] = can_escape(N, U, V);
}
for (int i = 0; i < Q; ++i) {
printf("%d\n", answers[i]);
}
return 0;
}*/
open /var/local/lib/isolate/405/box/a.out: no such file or directory
main.cpp: In function 'bool can_escape(int, std::vector<int>, std::vector<int>)':
main.cpp:71:26: error: no matching function for call to 'std::set<int>::count(const std::array<int, 2>&)'
71 | if(curr.count(x)) continue;
| ~~~~~~~~~~^~~
In file included from /usr/include/c++/12/set:61,
from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:87,
from main.cpp:2:
/usr/include/c++/12/bits/stl_set.h:754:9: note: candidate: 'template<class _Kt> decltype (((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_count_tr(__x)) std::set<_Key, _Compare, _Alloc>::count(const _Kt&) const [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
754 | count(const _Kt& __x) const
| ^~~~~
/usr/include/c++/12/bits/stl_set.h:754:9: note: template argument deduction/substitution failed:
/usr/include/c++/12/bits/stl_set.h: In substitution of 'template<class _Kt> decltype (((const std::set<int>*)this)->std::set<int>::_M_t.std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::_M_count_tr<_Kt, _Req>(__x)) std::set<int>::count(const _Kt&) const [with _Kt = std::array<int, 2>]':
main.cpp:71:26: required from here
/usr/include/c++/12/bits/stl_set.h:755:37: error: no matching function for call to 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::_M_count_tr(const std::array<int, 2>&) const'
755 | -> decltype(_M_t._M_count_tr(__x))
| ~~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/12/map:60,
from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:81:
/usr/include/c++/12/bits/stl_tree.h:1314:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_count_tr(const _Kt&) cons...