用户工具

站点工具


2020-2021:teams:wangzai_milk:20200808比赛记录

这是本文档旧的修订版!


2020牛客暑期多校训练营(第九场)

比赛情况

题号 A B C D E F G H I J K L
状态 O - - - O O - - O - O -

O 在比赛中通过 Ø 赛后通过 ! 尝试了但是失败了 - 没有尝试

比赛时间

2020-08-08 12:00-17:00

题解

F - Groundhog Looking Dowdy

我们考虑把所有衣服放到一起,然后把衣服按照邋遢值排序,然后做一个类似滑动窗口的东西,每次滑动保证窗口内有m天及以上可以穿的衣服,然后用当前的最大值和最小值相减一下更新答案即可。

点击以显示 ⇲

点击以隐藏 ⇱

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
struct Node {
	int val,bel;
}clo[N<<1];
bool cmp(const Node &x,const Node &y) { return x.val < y.val; }
int buk[N],cnt,n,m;
int main()
{
	scanf("%d%d",&n,&m);
	int ki;
	for (int i = 1;i<= n;i++) {
		scanf("%d",&ki);
		for (int j = 1;j<= ki;j++) {
			cnt++;
			scanf("%d",&clo[cnt].val);
			clo[cnt].bel = i;
		}
	}
	sort(clo+1,clo+cnt+1,cmp);
	for (int i = 1;i<= n;i++)buk[i] = 0;
	int tail = 0;
	int ans = 1e9+5;
	int cntbel = 0;
	for (int i = 1;i<= cnt;i++) {
		while (tail+1<=cnt) {
			tail++;
			buk[clo[tail].bel]++;
			if (buk[clo[tail].bel] == 1)cntbel++;
			if (cntbel >= m) {ans = min(ans,clo[tail].val-clo[i].val);break;}
		}
		buk[clo[i].bel]--;
		if (buk[clo[i].bel]==0)cntbel--;
	}
	printf("%d\n",ans);
	return 0;
}


2020-2021/teams/wangzai_milk/20200808比赛记录.1597319465.txt.gz · 最后更改: 2020/08/13 19:51 由 infinity37