Submission #631278

#TimeUsernameProblemLanguageResultExecution timeMemory
631278czhang2718Tracks in the Snow (BOI13_tracks)C++17
Compilation error
0 ms0 KiB
#include "bits/stdc++.h" using namespace std; const int N=4000; int n, m; string grid[N]; int par[N*N]; short rnk[N*N]; short dx[]={0, 0, 1, -1}; short dy[]={1, -1, 0, 0}; vector<int> adj[N*N]; bool vis[N*N]; int find(int x){ return par[x]==x?x:par[x]=find(par[x]); } void join(int x, int y){ int a=find(x); int b=find(y); if(a==b) return; if(rnk[a]<rnk[b]) par[a]=b; else if(rnk[b]<rnk[a]) par[b]=a; else{ rnk[a]++; par[b]=a; } } int main(){ cin.tie(0)->sync_with_stdio(0); cin >> n >> m; for(int i=0; i<n; i++){ for(int j=0; j<m; j++) par[i*m+j]=i*m+j; cin >> grid[i]; } for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ if(grid[i][j]=='.') continue; for(int k=0; k<4; k++){ int x=i+dx[k]; int y=j+dy[k]; if(x<0 || x==n || y<0 || y==m || grid[x][y]!=grid[i][j]) continue; join(m*i+j, m*x+y); } } } for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ if(grid[i][j]=='.') continue; for(int k=0; k<4; k++){ int x=i+dx[k]; int y=j+dy[k]; if(x<0 || x==n || y<0 || y==m || grid[x][y]==grid[i][j] || grid[x][y]=='.') continue; int a=find(m*i+j), b=find(m*x+y); adj[a].push_back(b); adj[b].push_back(a); } } } // for(int i=0; i<n*m; i++){ // if(find(i)!=i) continue; // sort(adj[i].begin(), adj[i].end()); // adj[i].erase(unique(adj[i].begin(), adj[i].end()), adj[i].end()); // // for(int k:adj[i]) cout << i << " " << k << "\n"; // } queue<int> q; int r=find(0); q.push(r); for(; !q.empty(); q.pop()){ int x=q.front(); for(int k:adj[x]){ if(!vis[k] && k!=r){ vis[k]=vis[x]+1; // cout << "vis[" << k << "] = " << vis[k] << "\n"; q.push(k); } } } int mx=0; for(int i=0; i<n*m; i++) mx=max(mx, vis[i]); cout << mx+1; } // when its been a long time since goodbye

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:84:47: error: no matching function for call to 'max(int&, bool&)'
   84 |     for(int i=0; i<n*m; i++) mx=max(mx, vis[i]);
      |                                               ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from tracks.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
tracks.cpp:84:47: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'bool')
   84 |     for(int i=0; i<n*m; i++) mx=max(mx, vis[i]);
      |                                               ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from tracks.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
tracks.cpp:84:47: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'bool')
   84 |     for(int i=0; i<n*m; i++) mx=max(mx, vis[i]);
      |                                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from tracks.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
tracks.cpp:84:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   84 |     for(int i=0; i<n*m; i++) mx=max(mx, vis[i]);
      |                                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from tracks.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
tracks.cpp:84:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   84 |     for(int i=0; i<n*m; i++) mx=max(mx, vis[i]);
      |                                               ^