제출 #566643

#제출 시각아이디문제언어결과실행 시간메모리
566643ac2huPalembang Bridges (APIO15_bridge)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> #ifdef DEBUG #include "../templates/debug.h" #else #define deb(x...) #endif using namespace std; #define int long long signed main() { iostream::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); int n,k;cin >> k >> n; vector<pair<int,int>> loc; int same_part = 0; vector<int> s; for(int i = 0;i<n;i++){ char c1, c2; int a,b; cin >> c1 >> a >> c2 >> b; if(c1 == c2){ same_part += abs(a - b); } else{ s.push_back(a); s.push_back(b); s.push_back(a - 1); s.push_back(b - 1); s.push_back(a + 1); s.push_back(b + 1); same_part++; if(a > b)swap(a, b); loc.emplace_back(a, b); } } s.push_back(0); sort(s.begin(), s.end()); s.erase(unique(s.begin(), s.end()), s.end()); int ans = 1e18; for(uint i = 0;i<s.size();i++){ for(uint ii = i + 1;ii<s.size();ii++){ int b1 = s[i], b2 = s[ii]; int temp = same_part; for(auto [l, r] : loc){ if(l <= b1 && b1 <= r){ temp += abs(l - r); } else if(l <= b2 && b2 <= r){ temp += abs(l - r); } else{ int db1 = abs(l + r - 2*b1); int db2 = abs(l + r - 2*b2); temp += min(db1, db2); } } ans = min(ans, temp); } } cout << ans << "\n"; }

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

bridge.cpp: In function 'int main()':
bridge.cpp:43:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |             for(auto [l, r] : loc){
      |                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...