求教一下qwq
  • 板块P1878 舞蹈课
  • 楼主STL_Lover
  • 当前回复1
  • 已保存回复1
  • 发布时间2020/8/1 16:54
  • 上次更新2023/11/6 21:34:50
查看原帖
求教一下qwq
320815
STL_Lover楼主2020/8/1 16:54

WA 了,只有 50 分。

数组开 2000000 也只有 50。

#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=(100000<<1)+5;
int n;char str[maxn];
bool t[maxn];
struct node{
  int l,r,abs;
};
int tmp[maxn],ans1[maxn],ans2[maxn],tot;
bool operator< (node A,node B)
{
  if(A.abs!=B.abs) return A.abs<B.abs;
  return A.l<B.l;
}
bool operator> (node A,node B)
{
  return !(A<B);
}
priority_queue<node>Q;
int main(){
  scanf("%d",&n);
  scanf("%s",str+1);
  for(register int i=1;i<=n;i++)
  {
    scanf("%d",&tmp[i]);
  }
  for(register int i=1;i<n;i++)
  {
    if(str[i]!=str[i+1])
    Q.push((node){i,i+1,-abs(tmp[i]-tmp[i+1])});
  }
  while(!Q.empty())
  {
    node temp=Q.top();
	Q.pop();
	if(t[temp.l]||t[temp.r]) continue;
	tot++;
	ans1[tot]=temp.l;
	ans2[tot]=temp.r;
	t[temp.l]=t[temp.r]=true;
	while(temp.l>1&&t[temp.l]) temp.l--;
	while(temp.r<n&&t[temp.r]) temp.r++;
	if(temp.l>=1&&temp.r<=n&&str[temp.l]!=str[temp.r])
	Q.push((node){temp.l,temp.r,-abs(tmp[temp.l]-tmp[temp.r])});
  }
  printf("%d\n",tot);
  for(register int i=1;i<=tot;i++) printf("%d %d\n",ans1[i],ans2[i]);
  return 0;
}
2020/8/1 16:54
加载中...