제출 #232458

#제출 시각아이디문제언어결과실행 시간메모리
232458balbitPalembang Bridges (APIO15_bridge)C++14
31 / 100
2083 ms11364 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; #ifdef BALBIT #define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<" - ", _do(__VA_ARGS__) template<typename T> void _do(T && x){cerr<<x<<endl;} template<typename T, typename ...S> void _do(T && x, S&&...y){cerr<<x<<", "; _do(y...);} #define IOS() #else #define bug(...) #define IOS() ios::sync_with_stdio(0), cin.tie(0) #define endl '\n' #endif // BALBIT #define pii pair<ll, ll> #define f first #define s second #define ALL(x) x.begin(), x.end() #define SZ(x) (int)(x.size()) #define pb push_back vector<pii> v; int n; ll C(ll l, ll r) { ll re = 0; for (pii & p : v) { if (p.s < l) re += l-p.s; else if (p.f > r) re += p.f-r; else if (p.f>l && p.s < r) re += min (p.f-l, r-p.s); } return re; } signed main(){ IOS(); int k; cin>>k>>n; ll re = 0; map<int, int> hv; for (int i = 0; i<n; ++i) { char x, x2; int l, r; cin>>x>>l>>x2>>r; re += abs(r-l); if (x == x2) { }else{ if (r < l) swap(l,r); v.pb({l,r}); hv[l]--; hv[r]--; } } n = SZ(v); if (k == 1) { ll now = C(0,0); bug(now); ll ans = now; ll x = 0; ll frt = n; for (pii ele : hv) { ll X = ele.f; now -= (X-x) * (frt); bug(X, now); ans = min(ans, now); frt += ele.s; x=X; } cout<<re + ans*2 + n<<endl; }else{ int m = SZ(hv); vector<int> p (m); int _it = 0; for (pii ele : hv) { p[_it++] = ele.f; } int j = 0; ll ans = C(0,0); for (int i = 0; i<m; ++i) { for (int j = 0; j<=i; ++j) ans = min (ans, C(p[j], p[i])); // bug(p[j], p[i]); } cout<<re + ans*2 + n<<endl; } } /* 2 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 */

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

bridge.cpp: In function 'int main()':
bridge.cpp:79:13: warning: unused variable 'j' [-Wunused-variable]
         int j = 0;
             ^
#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...