제출 #488857

#제출 시각아이디문제언어결과실행 시간메모리
488857s_samchenkoPalembang Bridges (APIO15_bridge)C++17
22 / 100
39 ms7204 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
#define ll long long
#define ff first
#define ss second
#define int ll
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define pii pair <int, int>
#define pdd pair <double, double>
using namespace std;
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const int inf = 1e15;
const int mod = 1e9+7;
const int N = 1e6+1010;

void solve(){
	int k, n, ans = 0;
	cin >> k >> n;
	
	vector <pii> a;
	for (int i = 0; i < n; ++i){
		char c1, c2;
		int x, y;
		cin >> c1 >> x >> c2 >> y;
		if (c1 == c2){
			ans += abs(x-y);
			continue;
		}
		if (x > y) swap(x, y);
		a.pb({x, y});
	}
	n = a.size();
	ans += n;
	
	if (k == 1){
		vector <int> b;
		for (auto i : a){
			b.pb(i.ff);
			b.pb(i.ss);
		}
		sort(all(b));
		for (int i = 0; i < n; ++i) ans -= b[i];
		for (int i = n; i < 2*n; ++i) ans += b[i];
		
		cout << ans;
		return;
	}
}

signed main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int tt = 1;
	//cin >> tt;
	while (tt--){
		solve();
		cout << '\n';
	}
}
#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...