답안 #1042399

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1042399 2024-08-03T03:46:37 Z Math4Life2020 Palembang Bridges (APIO15_bridge) C++17
22 / 100
30 ms 5076 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<ll,ll>;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll K,N; cin >> K >> N;
	vector<pii> v;
	ll ans = 0;
	for (ll i=0;i<N;i++) {
		string p,q; ll s,t;
		cin >> p >> s >> q >> t;
		if (p==q) {
			ans += abs(s-t);
		} else {
			ans++;
			v.push_back({min(s,t),max(s,t)});
		}
	}
	vector<ll> v2;
	for (pii p0: v) {
		v2.push_back(p0.first);
		v2.push_back(p0.second);
	}
	if (K==1) {
		sort(v2.begin(),v2.end());
		for (ll x: v2) {
			ans += abs(x-v2[v2.size()/2]);
		}
		cout << ans; exit(0);
	}
	ll emin = 1e18;
	for (ll a: v2) {
		ll ec = 0;
		priority_queue<pii> PQ; //-pos,sign(+1/-1)
		for (pii p0: v) {
			ll x = p0.first; ll y = p0.second;
			ec += abs(a-x)+abs(a-y);
			if (a<x || a>y) {
				PQ.push({-a,-1});
				PQ.push({-x,1});
				PQ.push({-y,1});
				PQ.push({-x-y+a,-1});
			}
		}
		ll xmin = 1e18;
		ll sp=0; ll sn=0;
		while (!PQ.empty()) {
			pii p0 = PQ.top(); PQ.pop();
			ll p = -p0.first; ll n = p0.second;
			xmin = min(xmin,(p*sn-sp));
			sp += p*n; sn += n;
		}
		emin = min(emin,2*xmin+ec);
	}
	cout << (emin+ans);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 472 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 17 ms 4896 KB Output is correct
13 Correct 30 ms 5076 KB Output is correct
14 Correct 23 ms 4820 KB Output is correct
15 Correct 17 ms 2848 KB Output is correct
16 Correct 20 ms 4992 KB Output is correct
17 Correct 26 ms 5064 KB Output is correct
18 Correct 24 ms 5072 KB Output is correct
19 Correct 30 ms 5076 KB Output is correct
20 Correct 22 ms 4852 KB Output is correct
21 Correct 28 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -