제출 #967230

#제출 시각아이디문제언어결과실행 시간메모리
967230ByeWorldPalembang Bridges (APIO15_bridge)C++14
9 / 100
2092 ms600 KiB
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
const int MAXN = 2e5+10;
const int INF = 4e18+10;
typedef pair<int,int> pii;
typedef pair<int,pii> ipii;

int K, n;
int ans;
vector <int> vec;
vector <pii> seg;
int pr[MAXN];

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> K >> n;
	if(K==1){
		exit(0);

		vector <int> cc; cc.pb(-1);
		for(int i=1; i<=n; i++){
			char x, y; int a, b;
			cin >> x >> a >> y >> b; a++; b++;
			if(x==y) ans += abs(a-b);
			else {
				if(a > b) swap(a, b);
				seg.pb({a, b});
				cc.pb(a); cc.pb(b);
			}
		}
		sort(seg.begin(), seg.end()); 
		sort(cc.begin(), cc.end());
		// cc.resize(unique(cc.begin(), cc.end()) - cc.begin());

		// cout << ans << " ans\n";
		int MN = INF, all = cc.size()-1, las = 1;
		// for(int i=1; i<=all; i++){
				int te = 0, le = cc[(all+1)/2];

				for(auto ed : seg){
					int l = ed.fi, r = ed.se;
					te += abs(l-le)+abs(r-le);
				}
				MN = min(MN, te);
		// }

		ans += seg.size();
		cout << ans+MN << '\n';
	} else {
		vector <int> cc; cc.pb(-1);
		for(int i=1; i<=n; i++){
			char x, y; int a, b;
			cin >> x >> a >> y >> b; a++; b++;
			if(x==y) ans += abs(a-b);
			else {
				if(a > b) swap(a, b);
				seg.pb({a, b});
				cc.pb(a); cc.pb(b);
			}
		}
		sort(seg.begin(), seg.end()); 
		sort(cc.begin(), cc.end());
		cc.resize(unique(cc.begin(), cc.end()) - cc.begin());

		// cout << ans << " ans\n";
		int MN = INF, all = cc.size()-1, las = 1;
		if(all==0) MN = 0;

		for(int i=1; i<=all; i++){
			for(int j=las; j<=all; j++){
				int te = 0, le = cc[i], ri = cc[j];

				for(auto ed : seg){
					int l = ed.fi, r = ed.se;
					te += min(abs(l-le)+abs(r-le), abs(l-ri)+abs(r-ri));
				}
				if(MN > te){
					MN = te;
					las = j;
				}
			}
		}

		ans += seg.size();
		cout << ans+MN << '\n';
	}
}

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

bridge.cpp: In function 'int main()':
bridge.cpp:41:36: warning: unused variable 'las' [-Wunused-variable]
   41 |   int MN = INF, all = cc.size()-1, las = 1;
      |                                    ^~~
#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...