結果
| 問題 |
No.309 シャイな人たち (1)
|
| ユーザー |
piyoko_212
|
| 提出日時 | 2015-12-25 21:01:01 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,037 bytes |
| コンパイル時間 | 623 ms |
| コンパイル使用メモリ | 50,508 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-19 00:01:57 |
| 合計ジャッジ時間 | 21,527 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | WA * 13 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | int a,b;scanf("%d%d",&a,&b);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:14:54: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | for(int i=0;i<a;i++)for(int j=0;j<b;j++)scanf("%d",&p[i][j]);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:15:54: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | for(int i=0;i<a;i++)for(int j=0;j<b;j++)scanf("%d",&q[i][j]);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int p[20][20];
int q[20][20];
double dp[13][1<<11];
int st[20];
double pr[1<<11];
int v[20];
double EPS=1e-9;
int main(){
int a,b;scanf("%d%d",&a,&b);
for(int i=0;i<a;i++)for(int j=0;j<b;j++)scanf("%d",&p[i][j]);
for(int i=0;i<a;i++)for(int j=0;j<b;j++)scanf("%d",&q[i][j]);
for(int i=0;i<(1<<b);i++){
double th=1;
for(int j=0;j<b;j++){
if(i&(1<<j)){
th=th*p[0][j]/50;
}else{
th=th*(50-p[0][j])/50;
}
}
for(int j=0;j<b;j++)st[j]=v[j]=0;
for(int j=0;j<b;j++){
if(i&(1<<j))st[j]+=4-q[0][j];
}
queue<int>Q;
for(int j=0;j<b;j++){
if(st[j]>=4){
Q.push(j);v[j]=1;
}
}
while(Q.size()){
int at=Q.front();Q.pop();
if(at){
st[at-1]++;
if(st[at-1]==4){Q.push(at-1);v[at-1]=1;}
}
if(at<b-1){
st[at+1]++;
if(st[at+1]==4){Q.push(at+1);v[at+1]=1;}
}
}
int to=0;
for(int j=0;j<b;j++)if(v[j])to+=(1<<j);
dp[1][to]+=th;
}
for(int i=1;i<a;i++){
for(int j=0;j<(1<<b);j++){
double th=1;
for(int k=0;k<b;k++){
if(j&(1<<k)){
th=th*p[i][k]/50;
}else{
th=th*(50-p[i][k])/50;
}
}
pr[j]=th;
}
for(int k=0;k<(1<<b);k++){
if(dp[i][k]<EPS)continue;
for(int l=0;l<(1<<b);l++){
if(pr[l]<EPS)continue;
for(int j=0;j<b;j++)st[j]=v[j]=0;
for(int j=0;j<b;j++){
if(l&(1<<j))st[j]+=4-q[i][j];
if(k&(1<<j))st[j]++;
}
queue<int>Q;
for(int j=0;j<b;j++){
if(st[j]>=4){
Q.push(j);v[j]=1;
}
}
while(Q.size()){
int at=Q.front();Q.pop();
if(at){
st[at-1]++;
if(st[at-1]==4){Q.push(at-1);v[at-1]=1;}
}
if(at<b-1){
st[at+1]++;
if(st[at+1]==4){Q.push(at+1);v[at+1]=1;}
}
}
int to=0;
for(int j=0;j<b;j++)if(v[j])to+=(1<<j);
dp[i+1][to]+=pr[l]*dp[i][k];
}
}
}
double ret=0;
for(int i=1;i<=a;i++){
for(int j=0;j<(1<<b);j++){
// printf("%d %d: %f\n",i,j,dp[i][j]);
ret+=dp[i][j]*(__builtin_popcount(j));
}
}
printf("%.12f\n",ret);
}
piyoko_212