結果
| 問題 |
No.2871 Universal Serial Bus
|
| コンテスト | |
| ユーザー |
a01sa01to
|
| 提出日時 | 2024-12-28 00:40:19 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,876 bytes |
| コンパイル時間 | 3,549 ms |
| コンパイル使用メモリ | 254,236 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-28 00:40:24 |
| 合計ジャッジ時間 | 4,674 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "settings/debug.cpp"
#else
#define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;
int main() {
int h, w;
cin >> h >> w;
vector Grid1(h, vector<char>(w)), Grid2(h, vector<char>(w));
rep(i, h) rep(j, w) cin >> Grid1[i][j];
rep(i, h) rep(j, w) cin >> Grid2[i][j];
rep(i, h) rep(j, w) Grid2[i][j] = Grid2[i][j] ^ '.' ^ '#';
bool rotateOk = true;
rep(i, h) rep(j, w) if (Grid1[i][j] != Grid2[h - i - 1][w - j - 1]) rotateOk = false;
// f(x) = x 回目に成功する確率
function<double(int)> f;
if (rotateOk) {
if (Grid1 == Grid2) {
f = [&](int x) -> double {
double res = 1;
rep(i, x - 1) res *= pow(2, -i);
res *= 1 - pow(2, -(x - 1));
return res;
};
}
else {
f = [&](int x) -> double {
double res = 1;
// 奇数回目はミス
rep(i, x - 1) {
if (i % 2 == 0)
res *= 1;
else
res *= pow(2, -i);
}
if (x % 2 == 0)
res *= 1 - pow(2, -(x - 1));
else
res *= 0;
return res;
};
}
}
else {
if (Grid1 == Grid2) {
f = [&](int x) -> double {
double res = 1;
// 偶数回目はミス
rep(i, x - 1) {
if (i % 2 == 1)
res *= 1;
else
res *= pow(2, -i);
}
if (x % 2 == 1)
res *= 1 - pow(2, -(x - 1));
else
res *= 0;
return res;
};
}
else {
// 全ミス
cout << -1 << endl;
return 0;
}
}
double ans = 0;
for (int x = 1; x <= 100; ++x) {
Debug(x, f(x));
ans += x * f(x);
}
cout << fixed << setprecision(15) << ans << endl;
return 0;
}
a01sa01to