제출 #119498

#제출 시각아이디문제언어결과실행 시간메모리
119498Charis02Palembang Bridges (APIO15_bridge)C++14
22 / 100
209 ms13552 KiB
#include<iostream> #include<stdio.h> #include<vector> #include<cmath> #include<queue> #include<utility> #include<string.h> #include<map> #include<set> #include<algorithm> #define ll long long #define pi pair < ll,ll > #define mp(a,b) make_pair(a,b) #define rep(i,a,b) for(int i = a;i < b;i++) #define N 100004 #define INF 1e18 using namespace std; ll n,k; pi ar[N]; ll b,d; char a,c; ll ans,cnt; vector <ll>possible; set < ll > p; ll checkbridge(ll x,ll y) { ll bridge = x; ll res = ans; rep(j,0,cnt) { if((ar[j].first <= bridge && bridge <= ar[j].second) || (ar[j].first <= y && y <= ar[j].second)) continue; else { res += 2*min((abs(ar[j].first-bridge),abs(ar[j].first-y)),min(abs(ar[j].second-bridge),abs(ar[j].second-y))); } } return res; } ll findans(ll x) { ll fin = checkbridge(possible[x],possible[x]); rep(i,x+1,possible.size()) { fin = min(fin,checkbridge(possible[x],possible[i])); } return fin; } void solve2() { if(possible.empty()) { cout << ans << endl; return; } if(possible.size() == 1) { cout << checkbridge(possible[0],possible[0]); return; } ll fin = INF; rep(i,0,possible.size()) { rep(j,0,possible.size()) { fin = min(fin,checkbridge(possible[i],possible[j])); } } cout << fin; return; } int main() { ios_base::sync_with_stdio(false); cin >> k >> n; rep(i,0,n) { cin >> a >> b >> c >> d; if(d < b) swap(b,d); ans += d-b; if(a != c) { ar[cnt].first = b; ar[cnt].second = d; ans++; cnt++; } } if(cnt == 0) { cout << ans; return 0; } rep(i,0,cnt) { p.insert(ar[i].first); p.insert(ar[i].second); } for(set < ll >::iterator it = p.begin();it != p.end();it++) { possible.push_back(*it); } if(k == 2) { solve2(); return 0; } ll low = 0; ll high = possible.size()-1; ll res = 0; while(low <= high) { ll mid = (low+high)/2; if(checkbridge(possible[mid-1],possible[mid-1]) >= checkbridge(possible[mid],possible[mid])) { low = mid+1; res = mid; } else { high = mid-1; } } cout << checkbridge(possible[res],possible[res]); return 0; } /* 2 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 2 3 A 1 B 1 A 4 B 7 A 10 B 12 */

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

bridge.cpp: In function 'long long int findans(long long int)':
bridge.cpp:14:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,a,b) for(int i = a;i < b;i++)
bridge.cpp:50:9:
     rep(i,x+1,possible.size())
         ~~~~~~~~~~~~~~~~~~~~~       
bridge.cpp:50:5: note: in expansion of macro 'rep'
     rep(i,x+1,possible.size())
     ^~~
bridge.cpp: In function 'void solve2()':
bridge.cpp:14:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,a,b) for(int i = a;i < b;i++)
bridge.cpp:72:9:
     rep(i,0,possible.size())
         ~~~~~~~~~~~~~~~~~~~         
bridge.cpp:72:5: note: in expansion of macro 'rep'
     rep(i,0,possible.size())
     ^~~
bridge.cpp:14:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,a,b) for(int i = a;i < b;i++)
bridge.cpp:74:13:
         rep(j,0,possible.size())
             ~~~~~~~~~~~~~~~~~~~     
bridge.cpp:74:9: note: in expansion of macro 'rep'
         rep(j,0,possible.size())
         ^~~
#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...