제출 #106899

#제출 시각아이디문제언어결과실행 시간메모리
106899wilwxk포탈들 (BOI14_portals)C++11
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN=1e6+5; const int MAXNN=1e3+5; map<int, short> g[MAXN]; set< pair<int, int> > s; short ori[MAXNN][MAXNN]; short parede[5][MAXNN][MAXNN]; int dist[MAXN]; int n, nn, mm, star, chegada; int quem(int i, int j) { return (i-1)*mm+j; } void liga(int a, int b, int c, int k) { if(a==b||a<=0||b<=0) return; if(g[a][b]==0) g[a][b]=c; g[a][b]=min(g[a][b], c); if(k) { if(g[b][a]==0) g[b][a]=c; g[b][a]=min(g[b][a], c); } } void dijkstra(int star) { for(int i=1; i<=n; i++) { dist[i]=1e9+9; if(i==star) dist[i]=0; s.insert({dist[i], i}); } while(!s.empty()) { int cur=s.begin()->second; if(cur==chegada) return; s.erase(s.begin()); for(auto aresta : g[cur]) { int viz=aresta.first; int peso=aresta.second; if(dist[viz]>dist[cur]+peso) { s.erase({dist[viz], viz}); dist[viz]=dist[cur]+peso; s.insert({dist[viz], viz}); } } } } int main() { scanf("%d %d", &nn, &mm); for(int i=1; i<=nn; i++) { char cc[MAXNN]; scanf(" %s", &cc[1]); for(int j=1; j<=mm; j++) { char c=cc[j]; if(c=='#') ori[i][j]=1; else ori[i][j]=0; if(c=='S') star=quem(i, j); if(c=='C') chegada=quem(i, j); } } for(int i=1; i<=nn; i++) { int ult=1; for(int j=1; j<=mm; j++) { if(ori[i][j]!=0) { ult=j+1; continue; } parede[1][i][j]=ult; if(i-1>=1&&ori[i-1][j]==0) liga(quem(i-1, j), quem(i, j), 1, 1); if(i+1<=nn&&ori[i+1][j]==0) liga(quem(i+1, j), quem(i, j), 1, 1); if(j-1>=1&&ori[i][j-1]==0) liga(quem(i, j-1), quem(i, j), 1, 1); if(j+1<=mm&&ori[i][j+1]==0) liga(quem(i, j+1), quem(i, j), 1, 1); } ult=mm; for(int j=mm; j>=1; j--) { if(ori[i][j]!=0) { ult=j-1; continue; } parede[2][i][j]=ult; } } for(int j=1; j<=mm; j++) { int ult=nn; for(int i=nn; i>=1; i--) { if(ori[i][j]!=0) { ult=i-1; continue; } parede[4][i][j]=ult; } ult=1; for(int i=1; i<=nn; i++) { if(ori[i][j]!=0) { ult=i+1; continue; } parede[3][i][j]=ult; int aa=abs(parede[1][i][j]-j); int bb=abs(parede[2][i][j]-j); int cc=abs(parede[3][i][j]-i); int dd=abs(parede[4][i][j]-i); int melhor=min(min(aa, bb), min(cc, dd))+1; int cur=quem(i, j); liga(cur, quem(i, parede[1][i][j]), min(melhor, aa), 0); liga(cur, quem(i, parede[2][i][j]), min(melhor, bb), 0); liga(cur, quem(parede[3][i][j], j), min(melhor, cc), 0); liga(cur, quem(parede[4][i][j], j), min(melhor, dd), 0); } } // for(int i=1; i<=nn; i++) { for(int j=1; j<=mm; j++) printf("%d ", parede[3][i][j]); printf("\n"); } n=nn*mm; dijkstra(star); // for(int i=1; i<=n; i++) printf("%d > %d\n", i, dist[i]); printf("%d\n", dist[chegada]); }

컴파일 시 표준 에러 (stderr) 메시지

portals.cpp: In function 'void liga(int, int, int, int)':
portals.cpp:19:24: error: no matching function for call to 'min(std::map<int, short int>::mapped_type&, int&)'
  g[a][b]=min(g[a][b], c);
                        ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from portals.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
portals.cpp:19:24: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
  g[a][b]=min(g[a][b], c);
                        ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from portals.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
portals.cpp:19:24: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
  g[a][b]=min(g[a][b], c);
                        ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from portals.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
portals.cpp:19:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
  g[a][b]=min(g[a][b], c);
                        ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from portals.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
portals.cpp:19:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
  g[a][b]=min(g[a][b], c);
                        ^
portals.cpp:22:25: error: no matching function for call to 'min(std::map<int, short int>::mapped_type&, int&)'
   g[b][a]=min(g[b][a], c);
                         ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from portals.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
portals.cpp:22:25: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   g[b][a]=min(g[b][a], c);
                         ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from portals.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
portals.cpp:22:25: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   g[b][a]=min(g[b][a], c);
                         ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from portals.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
portals.cpp:22:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   g[b][a]=min(g[b][a], c);
                         ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from portals.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
portals.cpp:22:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   g[b][a]=min(g[b][a], c);
                         ^
portals.cpp: In function 'int main()':
portals.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &nn, &mm);
  ~~~~~^~~~~~~~~~~~~~~~~~~
portals.cpp:49:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   char cc[MAXNN]; scanf(" %s", &cc[1]);
                   ~~~~~^~~~~~~~~~~~~~~