結果

問題 No.309 シャイな人たち (1)
ユーザー LayCurseLayCurse
提出日時 2015-12-01 15:12:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 299 ms / 4,000 ms
コード長 3,938 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 164,100 KB
実行使用メモリ 21,024 KB
最終ジャッジ日時 2024-09-14 05:22:53
合計ジャッジ時間 5,203 ms
ジャッジサーバーID
(参考情報)
judge2 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 246 ms
20,648 KB
testcase_01 AC 238 ms
21,024 KB
testcase_02 AC 239 ms
20,776 KB
testcase_03 AC 239 ms
20,404 KB
testcase_04 AC 6 ms
6,944 KB
testcase_05 AC 59 ms
11,120 KB
testcase_06 AC 207 ms
20,816 KB
testcase_07 AC 241 ms
20,548 KB
testcase_08 AC 239 ms
20,432 KB
testcase_09 AC 242 ms
20,660 KB
testcase_10 AC 299 ms
20,640 KB
testcase_11 AC 287 ms
21,000 KB
testcase_12 AC 271 ms
20,880 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 49 ms
11,228 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];

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)) memo[mask] = -1;
  rep(mask,1<<(2*Y)) if(memo[mask]==-1){
    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,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;
}
0