結果

問題 No.309 シャイな人たち (1)
ユーザー chocoruskchocorusk
提出日時 2019-12-28 10:37:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,942 ms / 4,000 ms
コード長 2,190 bytes
コンパイル時間 1,701 ms
コンパイル使用メモリ 110,980 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 20:48:46
合計ジャッジ時間 29,140 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,792 ms
5,248 KB
testcase_01 AC 3,942 ms
6,944 KB
testcase_02 AC 37 ms
5,376 KB
testcase_03 AC 2,814 ms
5,376 KB
testcase_04 AC 39 ms
5,376 KB
testcase_05 AC 518 ms
5,376 KB
testcase_06 AC 31 ms
5,376 KB
testcase_07 AC 114 ms
5,376 KB
testcase_08 AC 2,971 ms
5,376 KB
testcase_09 AC 3,803 ms
5,376 KB
testcase_10 AC 3,937 ms
6,944 KB
testcase_11 AC 3,394 ms
5,376 KB
testcase_12 AC 2,339 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int r, c; cin>>r>>c;
  double p[11][11]; int s[11][11]={};
  for(int i=0; i<r; i++) for(int j=0; j<c; j++) cin>>p[i][j];
  for(int i=0; i<r; i++) for(int j=0; j<c; j++) cin>>s[i][j];
  double dp[12][1<<11]={};
  dp[0][0]=1;
  double ans=0;
  double q[11][1<<11];
  for(int i=0; i<r; i++){
    for(int k=0; k<(1<<c); k++){
        q[i][k]=1;
        for(int l=0; l<c; l++){
          if(k&(1<<l)){
            q[i][k]*=p[i][l]/100;
          }else{
            q[i][k]*=(100-p[i][l])/100;
          }
        }
    }
  }
  for(int i=0; i<r; i++){
    for(int j=0; j<(1<<c); j++){
      if(dp[i][j]==0) continue;
      for(int k=0; k<(1<<c); k++){
        int cnt[11]={};
        bool used[11]={};
        int que[30];
        int t=0, u=0, m=0;
        for(int l=0; l<c; l++){
          if(k&(1<<l)) cnt[l]=4-s[i][l];
          else continue;
          if(j&(1<<l)) cnt[l]++;
          if(cnt[l]>=4){
            que[u]=l; u++;
            used[l]=1;
            m^=(1<<l);
          }
        }
        while(t<u){
          int x=que[t]; t++;
          if(x>0 && !used[x-1] && cnt[x-1]>=2){
            cnt[x-1]++;
            if(cnt[x-1]>=4 && !used[x-1]){
              que[u]=x-1; u++;
              used[x-1]=1;
              m^=(1<<(x-1));
            }
          }
          if(x<c-1 && !used[x+1] && cnt[x+1]>=2){
            cnt[x+1]++;
            if(cnt[x+1]>=4){
              que[u]=x+1; u++;
              used[x+1]=1;
              m^=(1<<(x+1));
            }
          }
        }
        dp[i+1][m]+=q[i][k]*dp[i][j];
        ans+=q[i][k]*dp[i][j]*popcount(m);
      }
    }
  }
  printf("%.9lf\n", ans);
	return 0;
}
0