1 条题解

  • 1
    @ 2022-9-23 22:50:45
    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=1000005;
    int n,k,t,len=0x3f3f3f3f;
    int id[maxn],b;
    struct node{
    	int pos;
    	int val;
    }f[maxn];
    bool cmp(n0de a,node b)
    {
    	return a.pos<b.pos;
    }
    int main()
    {
    	memset(id,-1,sizeof(id));
    	scanf("%d%d",&n,&k);
    	for(int i=1;i<=k;i++)
    	{
    		scanf("%d",&t);
    		for(int j=1;j<=t;j++)
    		{
    			scanf("%d",&f[++b].pos);
    			f[b].val=i;
    		}
    	}
    	sort(f+1,f+n+1,cmp);
    	int hd=1,cnt=0;
    	for(int i=1;i<=n;i++)
    	{
    		if(id[f[i].val]==-1) cnt++;
    		id[f[i].val]=f[i].pos;
    		while(hd<=i&&f[hd].pos!=id[f[hd].val]) hd++;
    		if(cnt==k&&f[i].pos-f[hd].pos<len) len=f[i].pos-f[hd].pos;
    	}
    	printf("%d",len);
    	return o;
    }
    
    • 1

    信息

    ID
    1512
    时间
    1000ms
    内存
    125MiB
    难度
    5
    标签
    递交数
    2
    已通过
    1
    上传者