結果
| 問題 |
No.309 シャイな人たち (1)
|
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-12-02 23:56:46 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,641 bytes |
| コンパイル時間 | 954 ms |
| コンパイル使用メモリ | 91,904 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-14 08:12:37 |
| 合計ジャッジ時間 | 1,563 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | WA * 13 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:117:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
117 | scanf("%d", &p[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:124:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
124 | scanf("%d", &s[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
template<class T>
ostream& operator << (ostream& os, vector<T> vec){
for(int i=0; i<vec.size(); i++){
os << vec[i] << " ";
}
return os;
}
#include <bitset>
int main_(){
int r,c;
cin >> r >> c;
vector<vector<int>> p(r, vector<int>(c));
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
cin >> p[i][j];
}
}
vector<vector<int>> s(r, vector<int>(c));
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
cin >> s[i][j];
}
}
vector<double> Prob(1<<c, 0);
Prob[0] = 1.0;
vector<double> dp(1<<c, 0);
for(int i=0; i<r; i++){
vector<double> dp_(1<<c, 0);
vector<double> next_Prob(1<<c, 0);
double hoge = 0;
for(int w=0; w<(1<<c); w++){
double tmp_p = 1.0;
vector<int> y(c, 0);
for(int j=0; j<c; j++){
tmp_p *= (((w>>j)&1)?p[i][j]:100-p[i][j])/100.0;
if((w>>j)&1){
y[j] = 4-s[i][j];
}
}
if(tmp_p < 1e-12) continue;
for(int v=0; v<(1<<c); v++){
if(Prob[v] < 1e-12) continue;
auto z=y;
int used = 0;
for(int j=0; j<c; j++){
z[j] += (v>>j)&1;
}
for(int j=0; j<c; j++){
if(z[j]>=4 && ((used>>j)&1)!=1){
used |= 1<<j;
if(j-1>=0) z[j-1]++;
if(j+1< c) z[j+1]++;
}
}
for(int j=c-1; j>=0; j--){
if(z[j]>=4 && ((used>>j)&1)!=1){
used |= 1<<j;
if(j-1>=0) z[j-1]++;
if(j+1< c) z[j+1]++;
}
}
int next = 0;
int cnt = 0;
for(int j=0; j<c; j++){
next |= (z[j]>=4)<<j;
cnt += (z[j]>=4);
}
dp_[next] += (dp[v] + cnt * Prob[v]) * tmp_p;
next_Prob[next] += Prob[v] * tmp_p;
}
}
swap(dp, dp_);
swap(Prob, next_Prob);
}
double ans = 0;
for(int i=0; i<(1<<c); i++){
ans += dp[i];
}
printf("%.18f\n", ans);
return 0;
}
#include <cassert>
int main(){
int r,c;
cin >> r >> c;
vector<vector<int>> p(r, vector<int>(c));
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
scanf("%d", &p[i][j]);
//cin >> p[i][j];
}
}
vector<vector<int>> s(r, vector<int>(c));
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
scanf("%d", &s[i][j]);
//cin >> s[i][j];
}
}
vector<double> Prob(1<<c, 0);
vector<double> Prob_(1<<c, 0);
Prob[0] = 1.0;
vector<double> dp(1<<c, 0);
vector<double> dp_(1<<c, 0);
for(int i=0; i<r; i++){
for(int v=0; v<(1<<c); ++v){
if(Prob[v] < 1e-12){
dp[v] = 0;
Prob[v] = 0;
continue;
}
vector<int> y(c, 0);
for(int j=0; j<c; ++j){
y[j] += (v>>j)&1;
}
for(int w=0; w<(1<<c); ++w){
double tmp_p = 1.0;
auto z=y;
for(int j=0; j<c; ++j){
tmp_p *= (((w>>j)&1)?p[i][j]:100-p[i][j]) * 0.01;
if((w>>j)&1){
z[j] += 4-s[i][j];
}
}
if(tmp_p < 1e-12) continue;
if(dp[v] * tmp_p < 1e-12) continue;
//propagate
int used = 0;
for(int j=0; j<c; ++j){
if(z[j]>=4 && ((used>>j)&1)!=1){
used |= 1<<j;
if(j-1>=0) z[j-1]++;
if(j+1< c) z[j+1]++;
}
}
for(int j=c-1; j>=0; --j){
if(z[j]>=4 && ((used>>j)&1)!=1){
used |= 1<<j;
if(j-1>=0) z[j-1]++;
if(j+1< c) z[j+1]++;
}
}
int next = 0;
int cnt = 0;
for(int j=0; j<c; ++j){
next |= (z[j]>=4)<<j;
cnt += (z[j]>=4);
}
dp_[next] += (dp[v] + cnt * Prob[v]) * tmp_p;
Prob_[next] += Prob[v] * tmp_p;
}
dp[v] = 0;
Prob[v] = 0;
}
swap(dp, dp_);
swap(Prob, Prob_);
}
double ans = 0;
for(int i=0; i<(1<<c); i++){
ans += dp[i];
}
printf("%.18f\n", ans);
return 0;
}
koyumeishi