結果
問題 | No.309 シャイな人たち (1) |
ユーザー | LayCurse |
提出日時 | 2015-12-01 15:28:59 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 283 ms / 4,000 ms |
コード長 | 3,891 bytes |
コンパイル時間 | 1,420 ms |
コンパイル使用メモリ | 164,396 KB |
実行使用メモリ | 20,504 KB |
最終ジャッジ日時 | 2024-09-14 05:23:06 |
合計ジャッジ時間 | 4,955 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 224 ms
20,504 KB |
testcase_01 | AC | 217 ms
20,096 KB |
testcase_02 | AC | 218 ms
20,224 KB |
testcase_03 | AC | 217 ms
20,096 KB |
testcase_04 | AC | 5 ms
5,376 KB |
testcase_05 | AC | 55 ms
7,680 KB |
testcase_06 | AC | 185 ms
20,224 KB |
testcase_07 | AC | 218 ms
20,224 KB |
testcase_08 | AC | 219 ms
20,172 KB |
testcase_09 | AC | 220 ms
20,096 KB |
testcase_10 | AC | 283 ms
20,224 KB |
testcase_11 | AC | 266 ms
19,968 KB |
testcase_12 | AC | 251 ms
20,096 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 43 ms
7,552 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[17000000]; void *mem = memarr; #define MD 1000000007 int X, Y; int P[11][11], S[11][11]; int bc[2111]; int memo[4211111], red[2111], cnv[2111]; int nei[11]; double solve(void){ int i, j, k, a, mask, t; int rest[11]; double *prob, *nx, *pp, res = 0; prob = (double*)mem; nx = prob + (1<<Y); pp = nx + (1<<Y); bc[0] = 0; REP(i,1,1<<Y) bc[i] = bc[i&(i-1)] + 1; rep(i,1<<Y) rep(j,Y) if(i&1<<j) red[i] |= (1<<(2*j)); rep(i,1<<Y) rep(j,Y) if(!(i&1<<j)) cnv[i] |= (3<<(2*j)); rep(i,Y){ if(i+1 < Y) nei[i] |= 1<<(i+1); if(i > 0) nei[i] |= 1<<(i-1); } rep(mask,1<<(2*Y)) memo[mask] = -1; rep(mask,1<<(2*Y)) if(memo[mask]==-1){ k = mask; rep(i,Y) rest[i] = k%4, k/=4; rep(i,Y) if(bc[k&nei[i]] >= rest[i]) k |= 1<<i; for(i=Y-1;i>=0;i--) if(bc[k&nei[i]] >= rest[i]) k |= 1<<i; memo[mask] = k; rep(i,Y) if(!(k&1<<i)){ j = (mask >> (2*i)) & 3; t = mask; while(j<3) t += 1<<(2*i), memo[t] = k, j++; } } rep(i,1<<Y) prob[i] = 0; prob[0] = 1; rep(k,X){ rep(i,1<<Y) nx[i] = 0; rep(i,1<<Y){ pp[i] = 1; rep(j,Y) if(i&1<<j) pp[i] *= P[k][j]/100.0; else pp[i] *= (100-P[k][j])/100.0; } for(i=(1<<Y)-1;i;i--){ rep(j,Y) if((i&1<<j)&&(S[k][j]==0||S[k][j]==4)){ prob[i^(1<<j)] += prob[i]; prob[i] = 0; break; } } rep(j,1<<Y) if(pp[j]){ t = 0; rep(a,Y) t += (S[k][a]==4?3:S[k][a])<<(2*a); rep(i,1<<Y) if(prob[i]){ mask = memo[(t-red[i])|cnv[j]]; nx[mask] += prob[i] * pp[j]; } } swap(prob, nx); rep(i,1<<Y) res += prob[i] * bc[i]; } return res; } int main(){ int i, j, k; double res; reader(&X,&Y); rep(i,X) rep(j,Y) reader(P[i]+j); rep(i,X) rep(j,Y) reader(S[i]+j); res = solve(); writerLn(res); return 0; }