跳到正文

题解

题解 CF962E 【Byteland, Berland and Disputed Cities】

大菜鸡fks约 1 分钟
原文
文章信息与版本

文章信息

发布
2018年8月20日
收录
2026年9月7日
更新
2026年11月11日
篇幅
约 1 分钟
获赞
4
题目
CF962E

版本

  1. v1当前

画画图可以发现 无非两种决策:

  1. PB依次连边(PR同理) 2.相邻两个P之间先连边(作为B和R 与P连通图的公用边)

然后相邻P之间的B和R单独连边(注意中间一条最大边可以去掉)

C++
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll ans,n,i,R,d,c,f,v,g,B,P;
int main(){
	scanf("%I64d",&n);
	for (int i=1;i<=n;i++){
		ll m; char s;
		scanf("%I64d %c",&m,&s);
		if (s=='P'||s=='R'){
			if (R) ans+=m-d,c=max(c,m-d);
			R=1; d=m;
		}
		if (s=='P'||s=='B'){
			if (B) ans+=m-f,v=max(v,m-f);
			B=1; f=m;
		}
		if (s=='P'){
			if (P) ans+=min(0ll,m-g-v-c);
			P=1; c=v=0; g=m; 
		}
	}
	printf("%I64d\n",ans);
	return 0;
}
原文
存档评论2 条抓取于