BZOJ 1293: [SCOI 2009] 생일 선물

1774 단어 bzoj
SB 문제...해명 하지 않다
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using  namespace std;
 
long long FULL,now;
long long line[1000001];
char c;
inline void read(long long &a)
{
    a=0;do c=getchar();while(c<'0'||c>'9');
    while(c<='9'&&c>='0')a=(a<<3)+(a<<1)+c-'0',c=getchar();
}
struct Node
{
    long long color,place;
    inline friend bool operator <(Node a,Node b)
    {return a.place<b.place;}
}me[1000001];
long long P_color[80];
int main()
{
  long long n,k,i,j,l;
  long long con=0;
  read(n),read(k);  
  for(i=1;i<=k;i++)
    {
        read(j);
        for(l=1;l<=j;l++)
          {
          read(me[++con].place);
          me[con].color=i-1; 
          if(me[con].place==1282)
              con++,con--;
         }
    }
  FULL=1ll<<k;
  FULL--;
  sort(me+1,me+1+n);
  long long now=0;
  long long r=0;
  l=0;
  bool pr[100001];
  long long ans=1ll<<60;
  for(i=1;i<=n;i++)  
    {
        line[++r]=i;
        now|=1ll<<me[i].color;
        P_color[me[i].color]=me[i].place;
        while((P_color[me[line[l]].color]!=me[line[l]].place))l++;
        if(now!=FULL)
         continue;
        if(ans>me[line[r]].place-me[line[l]].place)
        {
         ans=min(ans,me[line[r]].place-me[line[l]].place);
        /*puts("");puts("");puts("");puts("");
        for(j=r;j>=l;j--)
           if(!pr[me[line[j]].color])
            pr[me[line[j]].color]=true,printf("Pla:%I64d Clo:%I64d
",me[line[j]].place,me[line[j]].color); memset(pr,false,sizeof(pr)); */ } } printf("%lld
",ans); }

좋은 웹페이지 즐겨찾기