結果

問題 No.309 シャイな人たち (1)
ユーザー LayCurseLayCurse
提出日時 2015-11-30 23:17:36
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 3,753 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 162,420 KB
実行使用メモリ 21,236 KB
最終ジャッジ日時 2024-09-14 05:27:12
合計ジャッジ時間 7,121 ms
ジャッジサーバーID
(参考情報)
judge4 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 5 ms
6,944 KB
testcase_05 AC 61 ms
10,352 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 53 ms
9,816 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[2111111], red[2111], cnv[2111];

double solve(void){
  int i, j, k, a, mask, t;
  int st[11], st_size, 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(mask,1<<(2*Y)){
    k = mask;
    rep(i,Y) rest[i] = k%4, k/=4;
    st_size = 0;
    rep(i,Y) if(rest[i]==0) st[st_size++] = i;
    while(st_size){
      i = st[--st_size];
      k |= 1<<i;
      if(i+1 < Y && --rest[i+1]==0) st[st_size++] = i+1;
      if(i   > 0 && --rest[i-1]==0) st[st_size++] = i-1;
    }
    memo[mask] = k;
  }

  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];
        res += bc[mask] * prob[i] * pp[j];
      }
    }
    swap(prob, nx);
  }
  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