제출 #391215

#제출 시각아이디문제언어결과실행 시간메모리
391215Andyvanh1Unscrambling a Messy Bug (IOI16_messy)C++14
컴파일 에러
0 ms0 KiB
using namespace std; // 17.4.1.2 Headers // C #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> #endif #define vt vector #define pb push_back typedef long long ll; typedef vt<int> vi; vt<pair<int,int>> edges; vt<ll> weights; const int mxN=5e5+1, M=1e9+7; int n, m, p[mxN]; int find(int x) { return x^p[x]?p[x]=find(p[x]):x; } bool join(int x, int y) { if((x=find(x))==(y=find(y))) return 0; p[find(x)]=find(y); return 1; } ll prim(){ for(int i = 0; i < 200001; i++){ p[i] = i; } priority_queue<pair<ll,pair<int,int>>,vt<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>> pq; for(int i = 0; i < edges.size(); i++){ pq.push({weights[i],{edges[i].first,edges[i].second}}); } ll ans = 0; while(!pq.empty()){ auto e = pq.top(); pq.pop(); if(find(e.second.first)!=find(e.second.second)){ join(e.second.first,e.second.second); ans+=e.first; } } return ans; } ll min_total_length(vi r, vi b){ int n = r.size(); int m = b.size(); ll ans = 0; if(b[0]>r[n-1]) { ans += (ll) max(n, m) * (b[0] - r[n - 1]); for (int i = 0; i < n; i++) { ans += r[n - 1] - r[i]; } for (int i = 0; i < m; i++) { ans += b[i] - b[0]; } return ans; }else{ ll dp[n][m]; dp[0][0] = abs(r[0]-b[0]); for(int i = 0; i < n; i++){ for(int j = (i?0:1); j < m; j++){ if(i==0){ dp[i][j] = dp[i][j-1]+abs(b[j]-r[i]); }else if(j==0){ dp[i][j] = dp[i-1][j]+abs(b[j]-r[i]); }else{ dp[i][j] = min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1]))+abs(b[j]-r[i]); } } } return dp[n-1][m-1]; } } vi restore_permutation(int n , int w, int r){ string s = ""; string s1 = ""; for(int i = 0; i < n; i++){ s+="0"; s1+="1"; } for(int i = 0; i < n; i++){ add_element(s1.substr(0,i+1)+s.substr(i+1)); } compile_set(); vi p; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ bool nh = false; for(auto& e: p){ if(e==j){nh = true; break; } } if(nh)continue; bool bol = check_element(s.substr(0,j)+"1"+s.substr(j+1)); if(bol){ p.pb(j); s = s.substr(0,j)+"1"+s.substr(j+1); break; } } } return p; }

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

messy.cpp: In function 'll prim()':
messy.cpp:125:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |     for(int i = 0; i < edges.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
messy.cpp: In function 'vi restore_permutation(int, int, int)':
messy.cpp:188:9: error: 'add_element' was not declared in this scope
  188 |         add_element(s1.substr(0,i+1)+s.substr(i+1));
      |         ^~~~~~~~~~~
messy.cpp:190:5: error: 'compile_set' was not declared in this scope
  190 |     compile_set();
      |     ^~~~~~~~~~~
messy.cpp:202:22: error: 'check_element' was not declared in this scope
  202 |           bool bol = check_element(s.substr(0,j)+"1"+s.substr(j+1));
      |                      ^~~~~~~~~~~~~