제출 #766340

#제출 시각아이디문제언어결과실행 시간메모리
766340vitoPalembang Bridges (APIO15_bridge)C++98
17 / 100
16 ms5716 KiB
#include <bits/stdc++.h> using namespace std; using ll=long long; const ll INF=1e18+5; #define F first #define S second int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int k, n; cin >> k >> n; char c, cc; vector<vector<ll>> a(n, vector<ll>(3)); for(int i=0; i<n; i++) { cin >> c; cin >> a[i][0]; cin >> cc; cin >> a[i][1]; a[i][2]=(c==cc); if(a[i][0]>a[i][1]) { swap(a[i][0], a[i][1]); } } if(k==1 && n<=1000) { vector<ll> pos; for(int i=0; i<n; i++) { pos.push_back(a[i][0]); pos.push_back(a[i][1]); } ll rj=INF, cur; for(int i=0; i<2*n; i++) { cur=0; for(int j=0; j<n; j++) { cur+=a[j][1]-a[j][0]; if(a[j][2]==0) { cur++; if(pos[i]<a[j][0]) { cur+=2*(a[j][0]-pos[i]); } else if(pos[i]>a[j][1]) { cur+=2*(pos[i]-a[j][1]); } } } rj=min(rj, cur); } cout << rj << '\n'; return 0; } if(k==2 && n<=100) { vector<ll> pos; for(int i=0; i<n; i++) { pos.push_back(a[i][0]); pos.push_back(a[i][1]); } ll rj=INF, cur; for(int i=0; i<2*n-1; i++) { for(int j=i+1; j<2*n; j++) { cur=0; for(int l=0; l<n; l++) { cur+=a[l][1]-a[l][0]; if(a[l][2]==0) { cur++; pair<ll, ll> cos; if(pos[i]<a[l][0]) { cos.F=2*(a[l][0]-pos[i]); } else if(pos[i]>a[l][1]) { cos.F=2*(pos[i]-a[l][1]); } if(pos[j]<a[l][0]) { cos.S+=2*(a[l][0]-pos[j]); } else if(pos[j]>a[l][1]) { cos.S+=2*(pos[j]-a[l][1]); } cur+=min(cos.F, cos.S); } } rj=min(rj, cur); } } cout << rj << '\n'; return 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...