Submission #1249139

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

#define MAXD 4040
char mat[MAXD][MAXD];
short breadth[MAXD][MAXD];
vector<pair<short, short>> perb[MAXD*MAXD];

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

int main() {
    memset(mat, '.', sizeof(mat));
    memset(breadth, 0, sizeof(breadth));
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) cin >> mat[i][j];
    breadth[1][1]=1;
    perb[1].push_back({1, 1});
    for(int cur=1;!perb[cur].empty();cur++) {
        for(int i=0;i<perb[cur].size();i++) {
            auto pr=perb[cur][i];
            int y=pr.first, x=pr.second;
            for(int k=0;k<4;k++) {
                int newy=y+dy[k];
                int newx=x+dx[k];
                if(!breadth[newy][newx]&&mat[newy][newx]==mat[y][x]) {
                    breadth[newy][newx]=breadth[y][x];
                    perb[cur].push_back({newy, newx});
                }
            }
        }
        for(auto pr : perb[cur]) {
            int y=pr.first, x=pr.second;
            for(int k=0;k<4;k++) {
                int newy=y+dy[k];
                int newx=x+dx[k];
                if(!breadth[newy][newx]&&mat[newy][newx]!='.') {
                    breadth[newy][newx]=breadth[y][x]+1;
                    perb[cur+1].push_back({newy, newx});
                }
            }
        }
    }
    int ans=0;
    for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) ans=max(ans, breadth[i][j]);
    cout << ans << endl;
}

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:48:56: error: no matching function for call to 'max(int&, short int&)'
   48 |     for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) ans=max(ans, breadth[i][j]);
      |                                                     ~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from tracks.cpp:1:
/usr/include/c++/11/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++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
tracks.cpp:48:56: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'short int')
   48 |     for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) ans=max(ans, breadth[i][j]);
      |                                                     ~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from tracks.cpp:1:
/usr/include/c++/11/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++/11/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
tracks.cpp:48:56: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'short int')
   48 |     for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) ans=max(ans, breadth[i][j]);
      |                                                     ~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from tracks.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3461 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3461:5: note:   template argument deduction/substitution failed:
tracks.cpp:48:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   48 |     for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) ans=max(ans, breadth[i][j]);
      |                                                     ~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from tracks.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
tracks.cpp:48:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   48 |     for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) ans=max(ans, breadth[i][j]);
      |                                                     ~~~^~~~~~~~~~~~~~~~~~~~