Submission #1227745

#TimeUsernameProblemLanguageResultExecution timeMemory
1227745vyaductTracks in the Snow (BOI13_tracks)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

/* Somehiw
 *
 *
 *
*/

const int mxN = 4001;
int a[mxN][mxN];
bool visited[mxN][mxN];
int color[mxN][mxN];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, -1, 1};

bool valid(int x, int y, int n, int m){
  return x >= 0 && x < n && y >= 0 && y < m;
}

void floodfill(int r, int c, int idx, int n, int m){
  if (!valid(r, c, n, m)) return;
  if (visited[r][c] || a[r][c] == 0) return;
  color[r][c] = idx;
  visited[r][c] = true;
  if (valid(r+1, c, n, m)){
    if (a[r+1][c] == a[r][c]) {
      floodfill(r+1, c, idx, n, m);
    }
  }
  if (valid(r-1, c, n, m)){
    if (a[r-1][c] == a[r][c]) {
      floodfill(r-1, c, idx, n, m);
    }
  }
  if (valid(r, c+1, n, m)){
    if (a[r][c+1] == a[r][c]) {
      floodfill(r, c+1, idx, n, m);
    }
  }
  if (valid(r, c-1, n, m)){
    if (a[r][c-1] == a[r][c]) {
      floodfill(r, c-1, idx, n, m);
    }
  }
}

void solve(){
  int n,m; cin>>n>>m;
  for (int i=0;i<n;i++){
    for (int j=0;j<m;j++){
      char c; cin>>c;
      visited[i][j] = false;
      color[i][j]=0;
      if (c == '.') a[i][j] = 0;
      else if (c == 'F') a[i][j] = 1;
      else a[i][j] = 2;
    }
  }

  int g=1;
  for (int i=0;i<n;i++){
    for (int j=0;j<m;j++){
      if (!visited[i][j] && a[i][j]>0){
        floodfill(i, j, g, n, m);
        g++;
      }
    }
  }
    
  vector<vector<int>> adj(g);
  for (int i=0;i<n;i++){
    for (int j=0;j<m;j++){
      if (a[i][j] == 0) continue;
      for (int k=0;k<4;k++){
        int r = i+dx[k], c = j + dy[k];
        if (valid(r, c, n, m)){
          if (a[r][c]==0) continue;
          if (color[i][j] == color[r][c]) continue;
          adj[color[i][j]].insert(color[r][c]);
          adj[color[r][c]].insert(color[i][j]);
        }
      }
    }
  }

  int s = 1;
  queue<int> q;
  vector<bool> seen(g,false);
  vector<int> d(g);
  d[s] = 1;
  seen[s] = true;
  q.push(s);
  while(!q.empty()){
    int cur = q.front(); q.pop();
    for (int u: adj[cur]){
      if (!seen[u]){
        seen[u] = true;
        d[u] = d[cur]+1;
        q.push(u);
      }
    }
  }
  int mx = 0;
  for (auto dd: d) mx = max(mx, dd);
  cout << mx << endl;
}

int main(){
  solve();
  return 0;
}

Compilation message (stderr)

tracks.cpp: In function 'void solve()':
tracks.cpp:81:34: error: no matching function for call to 'std::vector<int>::insert(int&)'
   81 |           adj[color[i][j]].insert(color[r][c]);
      |           ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/vector:67,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from tracks.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:1379:9: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, _InputIterator, _InputIterator) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = int; _Alloc = std::allocator<int>]'
 1379 |         insert(const_iterator __position, _InputIterator __first,
      |         ^~~~~~
/usr/include/c++/11/bits/stl_vector.h:1379:9: note:   template argument deduction/substitution failed:
tracks.cpp:81:34: note:   candidate expects 3 arguments, 1 provided
   81 |           adj[color[i][j]].insert(color[r][c]);
      |           ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/vector:72,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from tracks.cpp:1:
/usr/include/c++/11/bits/vector.tcc:130:5: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = std::vector<int>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<int>::const_iterator; std::vector<_Tp, _Alloc>::value_type = int]'
  130 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/bits/vector.tcc:130:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/11/vector:67,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from tracks.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:1293:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = std::vector<int>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<int>::const_iterator; std::vector<_Tp, _Alloc>::value_type = int]'
 1293 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_vector.h:1293:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/11/bits/stl_vector.h:1310:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = std::vector<int>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<int>::const_iterator]'
 1310 |       insert(const_iterator __position, initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_vector.h:1310:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/11/bits/stl_vector.h:1335:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = std::vector<int>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<int>::const_iterator; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = int]'
 1335 |       insert(const_iterator __position, size_type __n, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_vector.h:1335:7: note:   candidate expects 3 arguments, 1 provided
tracks.cpp:82:34: error: no matching function for call to 'std::vector<int>::insert(int&)'
   82 |           adj[color[r][c]].insert(color[i][j]);
      |           ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/vector:67,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from tracks.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:1379:9: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, _InputIterator, _InputIterator) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = int; _Alloc = std::allocator<int>]'
 1379 |         insert(const_iterator __position, _InputIterator __first,
      |         ^~~~~~
/usr/include/c++/11/bits/stl_vector.h:1379:9: note:   template argument deduction/substitution failed:
tracks.cpp:82:34: note:   candidate expects 3 arguments, 1 provided
   82 |           adj[color[r][c]].insert(color[i][j]);
      |           ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/vector:72,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from tracks.cpp:1:
/usr/include/c++/11/bits/vector.tcc:130:5: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = std::vector<int>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<int>::const_iterator; std::vector<_Tp, _Alloc>::value_type = int]'
  130 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/bits/vector.tcc:130:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/11/vector:67,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from tracks.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:1293:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = std::vector<int>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<int>::const_iterator; std::vector<_Tp, _Alloc>::value_type = int]'
 1293 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_vector.h:1293:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/11/bits/stl_vector.h:1310:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = std::vector<int>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<int>::const_iterator]'
 1310 |       insert(const_iterator __position, initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_vector.h:1310:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/11/bits/stl_vector.h:1335:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = std::vector<int>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<int>::const_iterator; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = int]'
 1335 |       insert(const_iterator __position, size_type __n, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_vector.h:1335:7: note:   candidate expects 3 arguments, 1 provided