結果

問題 No.309 シャイな人たち (1)
ユーザー LayCurseLayCurse
提出日時 2015-11-30 23:24:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 372 ms / 4,000 ms
コード長 3,880 bytes
コンパイル時間 1,501 ms
コンパイル使用メモリ 162,884 KB
実行使用メモリ 21,896 KB
最終ジャッジ日時 2024-09-14 05:27:24
合計ジャッジ時間 5,790 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 292 ms
21,672 KB
testcase_01 AC 287 ms
21,896 KB
testcase_02 AC 285 ms
20,500 KB
testcase_03 AC 284 ms
20,276 KB
testcase_04 AC 6 ms
6,940 KB
testcase_05 AC 67 ms
10,588 KB
testcase_06 AC 252 ms
21,216 KB
testcase_07 AC 288 ms
20,452 KB
testcase_08 AC 287 ms
20,448 KB
testcase_09 AC 287 ms
21,116 KB
testcase_10 AC 372 ms
21,544 KB
testcase_11 AC 358 ms
20,172 KB
testcase_12 AC 333 ms
20,396 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 56 ms
10,272 KB
権限があれば一括ダウンロードができます

ソースコード

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

ll read_int(ll mn, ll mx, char nx){int k,z=0,f=1;ll r=0;mygc(k);if(k=='-')f=-1,mygc(k);for(;;){if(k==nx)break;if(!('0'<=k&&k<='9'))assert(0&&"failed at read_int(): unexpected character");if(r==0&&k=='0')z++;if(r*10/10!=r)assert(0&&"failed at read_int(): overflow");r=r*10+(k-'0');mygc(k);}if(r==0&&z!=1)assert(0&&"failed at read_int(): number of leading zs (val=0)");if(r!=0&&z!=0)assert(0&&"failed at read_int(): number of leading zs (val!=0)");if(r==0&&f==-1)assert(0&&"failed at read_int(): -0 is not allowed");r*=f;if(r<mn)assert(0&&"failed at read_int(): the value is too small");if(r>mx)assert(0&&"failed at read_int(): the value is too large");return r;}
template<class T> void read_int_array(int N, T res[], ll mn, ll mx){int i; rep(i,N)res[i]=read_int(mn,mx,i==N-1?'\n':' ');}
void end_input(void){int k;mygc(k);if(k!=EOF)assert(0&&"failed at end_input(): there may be some unnecessary characters");}

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)){
    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;

  X = read_int(1, 11, ' ');
  Y = read_int(1, 11, '\n');
  mygc(k); assert(k=='\n');
  rep(i,X) read_int_array(Y, P[i], 0, 100);
  mygc(k); assert(k=='\n');
  rep(i,X) read_int_array(Y, S[i], 0, 4);
  end_input();
  
  res = solve();
  writerLn(res);

  return 0;
}
0