結果
問題 | No.382 シャイな人たち (2) |
ユーザー | LayCurse |
提出日時 | 2015-12-06 00:49:54 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 1,499 ms / 8,000 ms |
コード長 | 6,134 bytes |
コンパイル時間 | 1,790 ms |
コンパイル使用メモリ | 173,088 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-14 14:56:42 |
合計ジャッジ時間 | 29,130 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,499 ms
5,248 KB |
testcase_01 | AC | 1,392 ms
5,376 KB |
testcase_02 | AC | 1,242 ms
5,376 KB |
testcase_03 | AC | 1,286 ms
5,376 KB |
testcase_04 | AC | 1,269 ms
5,376 KB |
testcase_05 | AC | 1,280 ms
5,376 KB |
testcase_06 | AC | 1,254 ms
5,376 KB |
testcase_07 | AC | 1,253 ms
5,376 KB |
testcase_08 | AC | 1,251 ms
5,376 KB |
testcase_09 | AC | 1,254 ms
5,376 KB |
testcase_10 | AC | 1,238 ms
5,376 KB |
testcase_11 | AC | 1,200 ms
5,376 KB |
testcase_12 | AC | 1,188 ms
5,376 KB |
testcase_13 | AC | 1,187 ms
5,376 KB |
testcase_14 | AC | 1,204 ms
5,376 KB |
testcase_15 | AC | 1,203 ms
5,376 KB |
testcase_16 | AC | 1,158 ms
5,376 KB |
testcase_17 | AC | 878 ms
5,376 KB |
testcase_18 | AC | 1,185 ms
5,376 KB |
testcase_19 | AC | 1,162 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
コンパイルメッセージ
main.cpp: In function ‘void reader(double*)’: main.cpp:15:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | void reader(double *x){scanf("%lf",x);} | ~~~~~^~~~~~~~~
ソースコード
#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; }