結果

問題 No.382 シャイな人たち (2)
ユーザー LayCurse
提出日時 2015-12-06 00:49:54
言語 C++11
(gcc 4.8.5)
結果
AC  
実行時間 1,533 ms
コード長 6,134 Byte
コンパイル時間 1,303 ms
使用メモリ 2,128 KB
最終ジャッジ日時 2019-10-26 18:16:17

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
input-00 AC 1,533 ms
2,060 KB
input-01 AC 1,412 ms
2,052 KB
input-02 AC 1,268 ms
2,064 KB
input-03 AC 1,312 ms
2,044 KB
input-04 AC 1,296 ms
2,048 KB
input-05 AC 1,304 ms
2,036 KB
input-06 AC 1,277 ms
2,088 KB
input-07 AC 1,280 ms
2,052 KB
input-08 AC 1,283 ms
2,076 KB
input-09 AC 1,272 ms
2,008 KB
input-10 AC 1,263 ms
2,080 KB
input-11 AC 1,226 ms
2,128 KB
input-12 AC 1,215 ms
2,020 KB
input-13 AC 1,214 ms
2,036 KB
input-14 AC 1,231 ms
2,004 KB
input-15 AC 1,230 ms
2,004 KB
input-16 AC 1,187 ms
2,052 KB
input-17 AC 904 ms
2,004 KB
input-18 AC 1,209 ms
2,056 KB
input-19 AC 1,191 ms
2,080 KB
input-a0 AC 2 ms
1,464 KB
テストケース一括ダウンロード

ソースコード

diff #
#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(double *x){scanf("%lf",x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(double x, char c){printf("%.15f",x);mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}

char memarr[57000000]; void *mem = memarr;
#define MD 1000000007

int maxIndependenceSet(int n, int *es, int **edge, int *res, void *mem, int lim=-1){int i,j,k,f=1,x,y,z=0,U,s,T,*r,*d,*c,*e,*u,*W,**G;pair<int,int>*p;void*E;if(n==0||n<=lim)return 0;if(n==1){res[0]=0;return 1;}r=(int*)mem;d=r+n;c=d+n;e=c+n;u=e+n;p=(pair<int,int>*)(u+n);mem=p+n;rep(i,n)if(es[i]<=1)break;if(i<n){rep(i,n)r[i]=es[i];rep(i,n)e[i]=1;for(;f;){f=0;rep(i,n)if(e[i]&&r[i]<=1){f=1;res[z++]=i;e[i]=0;rep(j,es[i]){k=edge[i][j];if(e[k]){e[k]=0;rep(x,es[k])r[edge[k][x]]--;}}}}U=0;rep(i,n)if(e[i])u[U++]=i;rep(i,n)c[i]=-1;rep(i,U)c[u[i]]=i;W=(int*)mem;G=(int**)(W+U);G[0]=(int*)(G+U);REP(i,1,U)G[i]=G[i-1]+es[u[i-1]];E=G[U-1]+es[u[U-1]];rep(i,U)W[i]=0;rep(i,U)rep(j,es[u[i]]){x=c[edge[u[i]][j]];if(x>=0)G[i][W[i]++]=x;}s=maxIndependenceSet(U,W,G,d,E,max(-1,lim-z));rep(i,s)res[z++]=u[d[i]];return z;}if(lim>=1){rep(i,n)e[i]=es[i];sort(e,e+n);s=0;rep(k,n)s+=es[k];j=0;rep(i,n){j+=e[i];if(2*j>s)break;}if(i<=lim)return z;rep(i,n)if(e[i]>n-i-1)break;if(i<=lim)return z;}rep(i,n)r[i]=-1;x=0;rep(i,n)if(r[i]==-1){s=1;e[0]=i;r[i]=i;x++;while(s){k=e[--s];rep(j,es[k])if(r[edge[k][j]]==-1)r[edge[k][j]]=i,e[s++]=edge[k][j];}}if(x>1){rep(i,n)e[i]=0;k=0;rep(i,n){j=r[i];if(e[j]==0)k++;e[j]++;}rep(i,n)p[i].first=e[i],p[i].second=i;sort(p,p+n);T=n;rep(y,n)if(p[y].first){k=p[y].second;U=0;rep(i,n)if(r[i]==k)u[U++]=i;rep(i,n)c[i]=-1;rep(i,U)c[u[i]]=i;W=(int*)mem;G=(int**)(W+U);G[0]=(int*)(G+U);REP(i,1,U)G[i]=G[i-1]+es[u[i-1]];E=G[U-1]+es[u[U-1]];rep(i,U)W[i]=0;rep(i,U)rep(j,es[u[i]]){x=c[edge[u[i]][j]];if(x>=0)G[i][W[i]++]=x;}T-=U;s=maxIndependenceSet(U,W,G,d,E,max(-1,lim-T-z));rep(i,s)res[z++]=u[d[i]];}return z;}k=0;REP(i,1,n)if(es[k]<es[i])k=i;if(es[k]==2){rep(i,n)e[i]=0;j=k=0;for(;;){e[k]=1;if(e[edge[k][0]]&&e[edge[k][1]])break;if(e[edge[k][0]])k=edge[k][1];else k=edge[k][0];if(j==0)res[z++]=k;j^=1;}return z;}rep(i,n)if(es[i]==2){x=edge[i][0];y=edge[i][1];rep(j,es[x])if(edge[x][j]==y)break;if(j!=es[x]){k=i;rep(i,n)e[i]=1;e[k]=0;rep(i,es[k])e[edge[k][i]]=0;U=0;rep(i,n)if(e[i])u[U++]=i;rep(i,n)c[i]=-1;rep(i,U)c[u[i]]=i;W=(int*)mem;G=(int**)(W+U);G[0]=(int*)(G+U);REP(i,1,U)G[i]=G[i-1]+es[u[i-1]];E=G[U-1]+es[u[U-1]];rep(i,U)W[i]=0;rep(i,U)rep(j,es[u[i]]){x=c[edge[u[i]][j]];if(x>=0)G[i][W[i]++]=x;}s=maxIndependenceSet(U,W,G,d,E,max(lim-1,z-1));if(z<s){z=0;res[z++]=k;rep(i,s)res[z++]=u[d[i]];}return z;}}rep(i,n)e[i]=1;e[k]=0;rep(i,es[k])e[edge[k][i]]=0;U=0;rep(i,n)if(e[i])u[U++]=i;rep(i,n)c[i]=-1;rep(i,U)c[u[i]]=i;W=(int*)mem;G=(int**)(W+U);G[0]=(int*)(G+U);REP(i,1,U)G[i]=G[i-1]+es[u[i-1]];E=G[U-1]+es[u[U-1]];rep(i,U)W[i]=0;rep(i,U)rep(j,es[u[i]]){x=c[edge[u[i]][j]];if(x>=0)G[i][W[i]++]=x;}s=maxIndependenceSet(U,W,G,d,E,max(lim-1,z-1));if(z<s){z=0;res[z++]=k;rep(i,s)res[z++]=u[d[i]];}U=0;rep(i,n)if(i!=k)u[U++]=i;rep(i,n)c[i]=-1;rep(i,U)c[u[i]]=i;W=(int*)mem;G=(int**)(W+U);G[0]=(int*)(G+U);REP(i,1,U)G[i]=G[i-1]+es[u[i-1]];E=G[U-1]+es[u[U-1]];rep(i,U)W[i]=0;rep(i,U)rep(j,es[u[i]]){x=c[edge[u[i]][j]];if(x>=0)G[i][W[i]++]=x;}s=maxIndependenceSet(U,W,G,d,E,max(lim,z));if(z<s){z=0;rep(i,s)res[z++]=u[d[i]];}return z;}
template<class T> void *malloc1d(T **arr, int x, void *mem){(*arr)=(T*)mem;return((*arr)+x);}
template<class T> void *malloc2d(T ***arr, int x, int y, void *mem){int i;(*arr)=(T**)mem;(*arr)[0]=(T*)((*arr)+x);REP(i,1,x)(*arr)[i]=(*arr)[i-1]+y;return((*arr)[x-1]+y);}

ll S;
int get_next(void){
  S = S * 12345 % 1000003;
  return S;
}

int main(){
  int i, j, k;
  int res, arr[200];
  int N, P;
  int *es, **edge, **mat;

  mem = malloc1d(&es, 130, mem);
  mem = malloc2d(&edge, 130, 130, mem);
  mem = malloc2d(&mat, 130, 130, mem);

  reader(&S);
  N = get_next() % 120 + 2;
  P = get_next();


  rep(i,N) rep(j,N) mat[i][j] = 0;
  rep(i,N) REP(j,i+1,N){
    k = get_next();
    if(k >= P) mat[i][j] = mat[j][i] = 1;
  }

  rep(i,N) es[i] = 0;
  rep(i,N) rep(j,N) if(mat[i][j]) edge[i][es[i]++] = j;

  res = maxIndependenceSet(N, es, edge, arr, mem);
  if(res==N){
    writerLn(-1);
  } else {
    writerLn(res+1);
    rep(i,res) arr[i]++;
    writerArr(arr,res);
  }

  return 0;
}
0