답안 #720755

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
720755 2023-04-09T09:39:30 Z mseebacher Palembang Bridges (APIO15_bridge) C++17
0 / 100
1 ms 444 KB
#include <bits/stdc++.h> 
 
using namespace std;
 
// Idee 1 -> Set mit Wert|Index pair
// Idee 2 -> SegTree damit
 
struct Platz{
	char type;
	int c;
};

bool cmp(const Platz& p1,const Platz& p2){
	return p1.c < p2.c;
}
 
void solve(){
	int k; cin >> k;
	int n; cin >> n;
	
	vector<Platz> p;
	
	long long sum = 0;
	for(int i = 0;i<n;i++){
		char t1,t2;
		int c1,c2;
		cin >> t1 >> c1 >> t2 >> c2;
		if(t1 == t2){
			sum += abs(c2-c1);
		}else{
			Platz p1; p1.type = t1; p1.c = c1;
			p.push_back(p1);
			p1.type = t2; p1.c = c2;
			p.push_back(p1);
		}
	}
	sort(p.begin(),p.end(),cmp);
	sum += (p.size())/2;
	int mid = (p[p.size()/2].c+p[(p.size()-1)/2].c) >> 1;
	for(int i = 0;i<(int)p.size();i++){
		sum += abs(p[i].c-mid);
	}
	
	cout << sum << " ";
	
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout << fixed << setprecision(8);
 
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 444 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -