比赛 20241127 评测结果 AWAAAAAAAAAAAAAAAAAAAAAAAWWWWAWAWWWWWWWWWAWAWWWWWWWWWAWAWWW
题目名称 魔法传送阵 最终得分 51
用户昵称 ┭┮﹏┭┮ 运行时间 1.388 s
代码语言 C++ 内存使用 4.04 MiB
提交时间 2024-11-27 11:42:05
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,ll>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 2e5+10;

ll read(){
	ll x = 0,f = 1;char c = getchar();
	for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
	for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
	return x * f;
}

int k,n;
char c1,c2;
ll ans = 0,c[N<<1],cnt;

int main(){
	freopen("bridge.in","r",stdin);
	freopen("bridge.out","w",stdout);
	k = read(),n = read();
	for(int i = 1;i <= n;i++){
		cin>>c1;int x = read();
		cin>>c2;int y = read();
		if(c1 == c2)ans += abs(x - y);
		else ans++,c[++cnt] = x,c[++cnt] = y;
	}
	sort(c + 1,c + 1 + cnt);
	for(int i = 1;i <= cnt;i++)ans += abs(c[i] - c[cnt / 2]);
	printf("%lld\n",ans);

	return 0;

}