結果
問題 | No.309 シャイな人たち (1) |
ユーザー | mayoko_ |
提出日時 | 2015-12-04 20:32:27 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 3,485 ms / 4,000 ms |
コード長 | 2,777 bytes |
コンパイル時間 | 935 ms |
コンパイル使用メモリ | 91,008 KB |
実行使用メモリ | 20,480 KB |
最終ジャッジ日時 | 2024-09-14 13:20:15 |
合計ジャッジ時間 | 28,890 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,952 ms
20,352 KB |
testcase_01 | AC | 3,476 ms
20,480 KB |
testcase_02 | AC | 527 ms
20,352 KB |
testcase_03 | AC | 2,643 ms
20,432 KB |
testcase_04 | AC | 19 ms
6,940 KB |
testcase_05 | AC | 461 ms
7,936 KB |
testcase_06 | AC | 502 ms
20,224 KB |
testcase_07 | AC | 597 ms
20,096 KB |
testcase_08 | AC | 2,698 ms
20,352 KB |
testcase_09 | AC | 3,222 ms
20,480 KB |
testcase_10 | AC | 3,485 ms
20,428 KB |
testcase_11 | AC | 3,150 ms
20,436 KB |
testcase_12 | AC | 2,470 ms
20,352 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 119 ms
7,808 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:43:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 43 | scanf("%d %d", &R, &C); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:44:66: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 44 | for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) scanf("%d", &P[i][j]); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:45:66: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) scanf("%d", &S[i][j]); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> //#include<cctype> #include<climits> #include<iostream> #include<string> #include<vector> #include<map> //#include<list> #include<queue> #include<deque> #include<algorithm> //#include<numeric> #include<utility> #include<complex> //#include<memory> #include<functional> #include<cassert> #include<set> #include<stack> const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef double Real; const int MAX = 11; int P[MAX][MAX], S[MAX][MAX]; int memo[1<<(2*MAX)], rest[MAX]; Real pmemo[MAX][1<<MAX]; Real dp[MAX+1][1<<MAX]; int main() { int R, C; scanf("%d %d", &R, &C); for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) scanf("%d", &P[i][j]); for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) scanf("%d", &S[i][j]); for (int s = 0; s < 1<<(2*C); s++) { int tmp = s; queue<int> que; for (int i = 0; i < C; i++) { rest[i] = tmp%4; tmp /= 4; if (rest[i] == 0) que.push(i); } while (!que.empty()) { int now = que.front(); que.pop(); if (now-1 >= 0) { rest[now-1]--; if (rest[now-1] == 0) que.push(now-1); } if (now+1 < C) { rest[now+1]--; if (rest[now+1] == 0) que.push(now+1); } } int& result = memo[s]; for (int i = 0; i < C; i++) result |= (rest[i]<=0)<<i; } for (int r = 0; r < R; r++) for (int s = 0; s < (1<<C); s++) { double& prob = pmemo[r][s]; prob = 1; for (int c = 0; c < C; c++) { if ((s>>c)&1) prob *= P[r][c]/100.; else prob *= (100-P[r][c])/100.; } } dp[0][0] = 1; for (int r = 0; r < R; r++) { for (int s0 = 0; s0 < (1<<C); s0++) { if (r == 0 && s0 > 0) continue; for (int s1 = 0; s1 < (1<<C); s1++) { double prob = dp[r][s0]*pmemo[r][s1]; if (prob == 0) continue; int mask = 0; for (int c = 0; c < C; c++) { int score = 3; if ((s1>>c)&1) { score = min(3, S[r][c]-((s0>>c)&1)); score = max(0, score); } mask |= score<<(2*c); } dp[r+1][memo[mask]] += prob; } } } Real ans = 0; for (int i = 1; i <= R; i++) for (int s = 1; s < (1<<C); s++) { ans += dp[i][s] * __builtin_popcount(s); } printf("%.10lf\n", ans); return 0; }