제출 #56630

#제출 시각아이디문제언어결과실행 시간메모리
56630leejseoPalembang Bridges (APIO15_bridge)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; int K, N; void solve1(){ long long ans = 0; vector<int> L; int u, v; char x, y; for(int i=0; i<N; i++){ scanf("%c %d %c %d\n", &x, &u, &y, &v); if (x == y) ans += abs(u-v); else{ L.push_back(u); L.push_back(v); } } sort(L.begin(), L.end()); int M = L.size(); if (M == 0){ printf("%lld\n", ans); return; } long long mid = L[M/2]; for (int i=0; i<M; i++) ans += abs(L[i] - mid); ans += M/2; printf("%lld\n", ans); L.clear(); return; } long long f(vector<int>&X, vector<int>&Y, int s){ vector<int> lo, hi; int N = X.size(); for (int i=0; i<N; i++){ if (X[i] + Y[i] < s){ lo.push_back(X[i]); lo.push_back(Y[i]); } else{ hi.push_back(X[i]); hi.push_back(Y[i]); } } long long ans = 0LL; sort(lo.begin(), lo.end()); sort(hi.begin(), hi.end()); for (int i=0; i<N; i++){ if (X[i] + Y[i] < s) ans += abs(X[i]-lo[lo.size()/2])+abs(Y[i]-lo[lo.size()/2]); else ans += abs(X[i]-hi[hi.size()/2])+abs(Y[i]-hi[hi.size()/2]); } lo.clear(); hi.clear(); return ans; } void solve2(){ long long ans = 0; vector<int> S; vector<int> X; vector<int> Y; int u, v; char x, y; for(int i=0; i<N; i++){ scanf("%c %d %c %d\n", &x, &u, &y, &v); if (x == y) ans += abs(u-v); else{ S.push_back(u+v); X.push_back(u); Y.push_back(v); } } int M = X.size(); if (M == 0){ printf("%lld\n", ans); return; } sort(S.begin(), S.end()); unique(S.begin(), S.end()); int lo = 0, hi = S.size()-1; long long temp = 1LL << 61; if (hi <= 2000){ for (int i=lo; i<=hi; i++){ temp = min(temp, f(X, Y, S[i])); } } else{ while (lo + 40 < hi){ int llh = (lo + lo + hi)/3; int lhh = (lo + hi + hi + 1)/3; long long left = f(X, Y, S[llh]), right = f(X, Y, S[lhh]); if (left <= right) hi = lhh - 1; else lo = llh+1; } for (int i=max(0, lo-10); i<=min(S.size()-1, hi+10); i++){ temp = min(temp, f(X, Y, S[i])); } } ans += temp; ans += M; printf("%lld\n", ans); return; } int main(void){ scanf("%d%d\n", &K, &N); if (K == 1) solve1(); else solve2(); }

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

bridge.cpp: In function 'void solve2()':
bridge.cpp:96:53: error: no matching function for call to 'min(std::vector<int>::size_type, int)'
   for (int i=max(0, lo-10); i<=min(S.size()-1, hi+10); i++){
                                                     ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from bridge.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr 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:
bridge.cpp:96:53: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'int')
   for (int i=max(0, lo-10); i<=min(S.size()-1, hi+10); i++){
                                                     ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from bridge.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr 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:
bridge.cpp:96:53: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'int')
   for (int i=max(0, lo-10); i<=min(S.size()-1, hi+10); i++){
                                                     ^
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 bridge.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _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:
bridge.cpp:96:53: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   for (int i=max(0, lo-10); i<=min(S.size()-1, hi+10); i++){
                                                     ^
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 bridge.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _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:
bridge.cpp:96:53: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   for (int i=max(0, lo-10); i<=min(S.size()-1, hi+10); i++){
                                                     ^
bridge.cpp: In function 'void solve1()':
bridge.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%c %d %c %d\n", &x, &u, &y, &v);  
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp: In function 'void solve2()':
bridge.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%c %d %c %d\n", &x, &u, &y, &v);  
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp: In function 'int main()':
bridge.cpp:106:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d\n", &K, &N);
  ~~~~~^~~~~~~~~~~~~~~~~~