全WA求助
  • 板块P1878 舞蹈课
  • 楼主yyz1005
  • 当前回复2
  • 已保存回复2
  • 发布时间2022/2/11 10:26
  • 上次更新2023/10/28 08:55:57
查看原帖
全WA求助
220824
yyz1005楼主2022/2/11 10:26
#include<bits/stdc++.h>
using namespace std;
const int N = 200010;
int n,a[N];
char t[N];
bool vis[N];
queue<pair<int,int> > ans;
int myabs(int x){
	if(x<0) return -x;
	return x;
}
struct pai{
	int p1;
	int p2;
	bool operator <(const pai &b) const{
		if(myabs(a[p1]-a[p2])==myabs(a[b.p1]-a[b.p2])) return p1>b.p1;
		return myabs(a[p1]-a[p2])>myabs(a[b.p1]-a[b.p2]);
	}
};
priority_queue<pai> q; 
int main(){
	scanf("%d",&n);
	scanf("%s", t+1);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		if(i!=1&&t[i]!=t[i-1]) q.push((pai){i-1,i});
	}
	while(!q.empty()){
		pai head = q.top();
		q.pop();
		if(vis[head.p1]||vis[head.p2]) continue;
		vis[head.p1] = true;
		vis[head.p2] = true;
		if(t[head.p1-1]!=t[head.p2+1]&&head.p2+1<=n&&head.p1-1>=1){
			q.push((pai){head.p1-1,head.p2+1});
		}
		ans.push(make_pair(head.p1,head.p2));
	}
	printf("%d\n",ans.size());
	while(!ans.empty()){
		printf("%d %d\n",ans.front().first,ans.front().second);
		ans.pop();
	}
	return 0;
}
2022/2/11 10:26
加载中...