Submission #1195836

#TimeUsernameProblemLanguageResultExecution timeMemory
1195836niepamietamhaslaSoccer (JOI17_soccer)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll n, m, A, B, C;
int k;
short x, y;

struct d{
    short a;
    short b;
    ll koszt;
};

const int MAXN = 505;

queue<d> q;
ll odl[MAXN][MAXN][2];

struct e{
    short a;
    short b;
    short kt;
    ll koszt;
};

short odl2[MAXN][MAXN];

void bfs(){
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= m; ++j){
            odl2[i][j] = -1;
        }
    }
    while(!q.empty()){
        auto e = q.front();
        q.pop();
        if(odl2[e.a][e.b] != -1) continue;
        odl2[e.a][e.b] = e.koszt;
        if(e.a > 0 and odl2[e.a-1][e.b] == -1){
            q.push({e.a - 1, e.b, e.koszt + 1});
        }
        if(e.a < n and odl2[e.a+1][e.b] == -1){
            q.push({e.a + 1, e.b, e.koszt + 1});

        }
        if(e.b > 0 and odl2[e.a][e.b-1] == -1){
            q.push({e.a, e.b - 1, e.koszt + 1});
        }
        if(e.b < m and odl2[e.a][e.b+1] == -1){
            q.push({e.a, e.b + 1, e.koszt + 1});
        }
    }
    return;
}

struct comp{
    bool operator()(const e &e1, const e &e2) const {
        if(e1.koszt != e2.koszt) return e1.koszt > e2.koszt;
        return false;
    }
};

priority_queue<e, vector<e>, comp> pq;

void dijkstra(pair<int,int> st){
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= m; ++j){
            odl[i][j][0] = -1;
            odl[i][j][1] = -1;
        }
    }
    pq.push({st.first, st.second, 0, 0});
    pq.push({st.first, st.second, 1, 0});
    while(!pq.empty()){
        auto u = pq.top();
        pq.pop();
        if(odl[u.a][u.b][u.kt] != -1) continue;
        odl[u.a][u.b][u.kt] = u.koszt;
        //cout << u.a << " " << u.b << " " << u.kt << " " << u.koszt << " u\n";
        for(int l = max(0, u.a-1); l <= min(n, u.a+1); ++l){
            if(l == u.a) continue;
            if(u.kt == 0){
            	if(odl[l][u.b][0] == -1) pq.push({l, u.b, 0, C * abs(l - u.a) + u.koszt});
            	if(odl[l][u.b][1] == -1) pq.push({l, u.b, 1, B + A * abs(l - u.a) + u.koszt});	
            }
            else{
            	if(odl[l][u.b][0] == -1) pq.push({l, u.b, 0, C * abs(l - u.a) + C * odl2[u.a][u.b] + u.koszt});
            	if(odl[l][u.b][1] == -1) pq.push({l, u.b, 1, C * odl2[u.a][u.b] + B + A * abs(l - u.a) + u.koszt});	
            }
        }
        for(int l = max(0, u.b-1); l <= min(u.b+1,m); ++l){
            if(l == u.b) continue;
            if(u.kt == 0){
            	if(odl[u.a][l][0] == -1) pq.push({u.a, l, 0, C * abs(l - u.b) + u.koszt});
            	if(odl[u.a][l][1] == -1) pq.push({u.a, l, 1, B + A * abs(l - u.b) + u.koszt});	
            }
            else{
            	if(odl[u.a][l][0] == -1) pq.push({u.a, l, 0, C * abs(l - u.b) + C * odl2[u.a][u.b] + u.koszt});
            	if(odl[u.a][l][1] == -1) pq.push({u.a, l, 1, C * odl2[u.a][u.b] + B + A * abs(l - u.b) + u.koszt});	
            }
        }
    }
    return;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    cin >> A >> B >> C;
    cin >> k;
    pair<short,short> start;
    pair<short,short> koniec;
    for(int i = 0; i < k; ++i){
        cin >> x >> y;
        if(i == 0) start = {x,y};
        if(i == k-1) koniec = {x,y};
        q.push({x, y, 0});
    }
    bfs();
    dijkstra(start);
    cout << min(odl[koniec.first][koniec.second][0], odl[koniec.first][koniec.second][1]) << "\n";
    return 0;
}

Compilation message (stderr)

soccer.cpp: In function 'void bfs()':
soccer.cpp:41:25: warning: narrowing conversion of '(((int)e.d::a) - 1)' from 'int' to 'short int' [-Wnarrowing]
   41 |             q.push({e.a - 1, e.b, e.koszt + 1});
      |                     ~~~~^~~
soccer.cpp:44:25: warning: narrowing conversion of '(((int)e.d::a) + 1)' from 'int' to 'short int' [-Wnarrowing]
   44 |             q.push({e.a + 1, e.b, e.koszt + 1});
      |                     ~~~~^~~
soccer.cpp:48:30: warning: narrowing conversion of '(((int)e.d::b) - 1)' from 'int' to 'short int' [-Wnarrowing]
   48 |             q.push({e.a, e.b - 1, e.koszt + 1});
      |                          ~~~~^~~
soccer.cpp:51:30: warning: narrowing conversion of '(((int)e.d::b) + 1)' from 'int' to 'short int' [-Wnarrowing]
   51 |             q.push({e.a, e.b + 1, e.koszt + 1});
      |                          ~~~~^~~
soccer.cpp: In function 'void dijkstra(std::pair<int, int>)':
soccer.cpp:73:17: warning: narrowing conversion of 'st.std::pair<int, int>::first' from 'int' to 'short int' [-Wnarrowing]
   73 |     pq.push({st.first, st.second, 0, 0});
      |              ~~~^~~~~
soccer.cpp:73:27: warning: narrowing conversion of 'st.std::pair<int, int>::second' from 'int' to 'short int' [-Wnarrowing]
   73 |     pq.push({st.first, st.second, 0, 0});
      |                        ~~~^~~~~~
soccer.cpp:74:17: warning: narrowing conversion of 'st.std::pair<int, int>::first' from 'int' to 'short int' [-Wnarrowing]
   74 |     pq.push({st.first, st.second, 1, 0});
      |              ~~~^~~~~
soccer.cpp:74:27: warning: narrowing conversion of 'st.std::pair<int, int>::second' from 'int' to 'short int' [-Wnarrowing]
   74 |     pq.push({st.first, st.second, 1, 0});
      |                        ~~~^~~~~~
soccer.cpp:81:44: error: no matching function for call to 'min(ll&, int)'
   81 |         for(int l = max(0, u.a-1); l <= min(n, u.a+1); ++l){
      |                                         ~~~^~~~~~~~~~
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 soccer.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
soccer.cpp:81:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   81 |         for(int l = max(0, u.a-1); l <= min(n, u.a+1); ++l){
      |                                         ~~~^~~~~~~~~~
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 soccer.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
soccer.cpp:81:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   81 |         for(int l = max(0, u.a-1); l <= min(n, u.a+1); ++l){
      |                                         ~~~^~~~~~~~~~
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 soccer.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3449:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3449 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3449:5: note:   template argument deduction/substitution failed:
soccer.cpp:81:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   81 |         for(int l = max(0, u.a-1); l <= min(n, u.a+1); ++l){
      |                                         ~~~^~~~~~~~~~
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 soccer.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3455:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3455 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3455:5: note:   template argument deduction/substitution failed:
soccer.cpp:81:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   81 |         for(int l = max(0, u.a-1); l <= min(n, u.a+1); ++l){
      |                                         ~~~^~~~~~~~~~
soccer.cpp:84:51: warning: narrowing conversion of 'l' from 'int' to 'short int' [-Wnarrowing]
   84 |                 if(odl[l][u.b][0] == -1) pq.push({l, u.b, 0, C * abs(l - u.a) + u.koszt});
      |                                                   ^
soccer.cpp:85:51: warning: narrowing conversion of 'l' from 'int' to 'short int' [-Wnarrowing]
   85 |                 if(odl[l][u.b][1] == -1) pq.push({l, u.b, 1, B + A * abs(l - u.a) + u.koszt});
      |                                                   ^
soccer.cpp:88:51: warning: narrowing conversion of 'l' from 'int' to 'short int' [-Wnarrowing]
   88 |                 if(odl[l][u.b][0] == -1) pq.push({l, u.b, 0, C * abs(l - u.a) + C * odl2[u.a][u.b] + u.koszt});
      |                                                   ^
soccer.cpp:89:51: warning: narrowing conversion of 'l' from 'int' to 'short int' [-Wnarrowing]
   89 |                 if(odl[l][u.b][1] == -1) pq.push({l, u.b, 1, C * odl2[u.a][u.b] + B + A * abs(l - u.a) + u.koszt});
      |                                                   ^
soccer.cpp:92:44: error: no matching function for call to 'min(int, ll&)'
   92 |         for(int l = max(0, u.b-1); l <= min(u.b+1,m); ++l){
      |                                         ~~~^~~~~~~~~
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 soccer.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
soccer.cpp:92:44: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   92 |         for(int l = max(0, u.b-1); l <= min(u.b+1,m); ++l){
      |                                         ~~~^~~~~~~~~
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 soccer.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
soccer.cpp:92:44: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   92 |         for(int l = max(0, u.b-1); l <= min(u.b+1,m); ++l){
      |                                         ~~~^~~~~~~~~
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 soccer.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3449:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3449 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3449:5: note:   template argument deduction/substitution failed:
soccer.cpp:92:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   92 |         for(int l = max(0, u.b-1); l <= min(u.b+1,m); ++l){
      |                                         ~~~^~~~~~~~~
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 soccer.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3455:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3455 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3455:5: note:   template argument deduction/substitution failed:
soccer.cpp:92:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   92 |         for(int l = max(0, u.b-1); l <= min(u.b+1,m); ++l){
      |                                         ~~~^~~~~~~~~
soccer.cpp:95:56: warning: narrowing conversion of 'l' from 'int' to 'short int' [-Wnarrowing]
   95 |                 if(odl[u.a][l][0] == -1) pq.push({u.a, l, 0, C * abs(l - u.b) + u.koszt});
      |                                                        ^
soccer.cpp:96:56: warning: narrowing conversion of 'l' from 'int' to 'short int' [-Wnarrowing]
   96 |                 if(odl[u.a][l][1] == -1) pq.push({u.a, l, 1, B + A * abs(l - u.b) + u.koszt});
      |                                                        ^
soccer.cpp:99:56: warning: narrowing conversion of 'l' from 'int' to 'short int' [-Wnarrowing]
   99 |                 if(odl[u.a][l][0] == -1) pq.push({u.a, l, 0, C * abs(l - u.b) + C * odl2[u.a][u.b] + u.koszt});
      |                                                        ^
soccer.cpp:100:56: warning: narrowing conversion of 'l' from 'int' to 'short int' [-Wnarrowing]
  100 |                 if(odl[u.a][l][1] == -1) pq.push({u.a, l, 1, C * odl2[u.a][u.b] + B + A * abs(l - u.b) + u.koszt});
      |                                                        ^