結果

問題 No.309 シャイな人たち (1)
ユーザー LayCurseLayCurse
提出日時 2015-11-30 17:42:49
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,497 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 162,068 KB
実行使用メモリ 9,888 KB
最終ジャッジ日時 2024-09-14 05:24:18
合計ジャッジ時間 11,977 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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[10][10], S[10][10];

int bc[1111];

double solve(void){
  int i, j, k, a, mask;
  int st[10], st_size, rest[10];
  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) 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;
    }
    rep(i,1<<Y) if(prob[i]) rep(j,1<<Y) if(pp[j]){
      rep(a,Y){
        rest[a] = 4;
        if(j&1<<a) rest[a] = S[k][a];
        if(i&1<<a) rest[a]--;
      }
      mask = 0;
      st_size = 0;
      rep(a,Y) if(rest[a] <= 0) st[st_size++] = a;
      while(st_size){
        a = st[--st_size];
        mask |= (1<<a);
        if(a     && --rest[a-1]==0) st[st_size++] = a-1;
        if(a+1<Y && --rest[a+1]==0) st[st_size++] = a+1;
      }
      nx[mask] += prob[i] * pp[j];
      res += bc[mask] * prob[i] * pp[j];
    }
    swap(prob, nx);
  }
  return res;
}


double solve_slow(void){
  int i, j, k, mask, cnt;
  double res=0, prob;
  int know[10][10], up[10][10], rest[10][10];

  rep(mask,1<<(X*Y)){
    rep(i,X) rep(j,Y) know[i][j] = up[i][j] = 0;
    prob = 1;
    rep(i,X) rep(j,Y){
      if(mask&1<<(i*Y+j)){
        know[i][j] = 1;
        prob *= P[i][j]/100.0;
      } else {
        prob *= (100-P[i][j])/100.0;
      }
    }

    rep(i,X) rep(j,Y){
      rest[i][j] = 4;
      if(know[i][j]) rest[i][j] = S[i][j];
    }

    cnt = 0;
    for(;;){
      int fg = 0;
      rep(i,X) rep(j,Y) if(!up[i][j] && rest[i][j]<=0){
        cnt++;
        fg = 1;
        up[i][j] = 1;
        if(i+1 < X) rest[i+1][j]--;
        if(j+1 < Y) rest[i][j+1]--;
        if(j-1 >=0) rest[i][j-1]--;
      }
      if(!fg) break;
    }

    res += cnt * prob;
  }

  return res;
}

int main(){
  int i, j, k;
  double res, res2;

  while(0){
    X = rand()%3+1;
    Y = rand()%6+1;
    rep(i,X) rep(j,Y) P[i][j]=rand()%101;
    rep(i,X) rep(j,Y) S[i][j]=rand()%4;

    writerLn(X,Y);
    res2 = solve_slow();
    writerLn(res2);
    res = solve();
    writerLn(res);
    assert(fabs(res-res2) < 1e-11);
  }

  reader(&X,&Y);
  rep(i,X) rep(j,Y) reader(P[i]+j);
  rep(i,X) rep(j,Y) reader(S[i]+j);

//  res2 = solve_slow();
//  writerLn(res2);
  res = solve();
  writerLn(res);

  return 0;
}
0