結果

問題 No.309 シャイな人たち (1)
ユーザー LayCurseLayCurse
提出日時 2015-12-01 15:52:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 262 ms / 4,000 ms
コード長 3,992 bytes
コンパイル時間 1,466 ms
コンパイル使用メモリ 164,344 KB
実行使用メモリ 22,092 KB
最終ジャッジ日時 2024-09-14 05:23:24
合計ジャッジ時間 4,615 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 195 ms
20,096 KB
testcase_01 AC 185 ms
19,968 KB
testcase_02 AC 187 ms
20,096 KB
testcase_03 AC 185 ms
20,096 KB
testcase_04 AC 5 ms
5,376 KB
testcase_05 AC 47 ms
7,808 KB
testcase_06 AC 163 ms
20,096 KB
testcase_07 AC 188 ms
20,096 KB
testcase_08 AC 187 ms
20,096 KB
testcase_09 AC 190 ms
22,092 KB
testcase_10 AC 262 ms
19,968 KB
testcase_11 AC 249 ms
20,224 KB
testcase_12 AC 233 ms
20,096 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 39 ms
7,936 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);}
      |                        ~~~~~^~~~~~~~~

ソースコード

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[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];

int pmemo[12][200000];
int pw[12];

double solve(void){
  int i, j, k, a, mask, t;
  int rest[12] = {};
  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 = 0;
      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++;
      }
    }
    rest[0]++;
    for(i=0;rest[i]>=4;i++) rest[i+1]++, rest[i]-=4;
  }

  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;
}
0