結果
問題 | No.2871 Universal Serial Bus |
ユーザー |
|
提出日時 | 2024-09-06 22:15:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,030 bytes |
コンパイル時間 | 1,965 ms |
コンパイル使用メモリ | 199,332 KB |
最終ジャッジ日時 | 2025-02-24 04:28:34 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;#define rep(i, n) for (int i = 0; i < (int)(n); i++)const long double EPS = 1e-8, LD1 = 1;void solve() {ll h, w;cin >> h >> w;vector<string> s(h), t(h);rep(i, h) cin >> s[i];rep(i, h) cin >> t[i];vector<ll> ok(2, 1);rep(k, 2) rep(si, h) rep(sj, w) {ll ti = si, tj = sj;if (k)ti = h - si - 1, tj = w - sj - 1;ok[k] &= s[si][sj] != t[ti][tj];}if (!ok[0] && !ok[1]) {cout << "-1\n";return;}long double ans = 0, p = 1, pow2 = 1;rep(i, 100) {if (ok[i % 2]) {long double cp = LD1 - LD1 / pow2;long double now = (long double)(i + 1) * p * cp;if (i > 10 && now < EPS) {cout << fixed << setprecision(16) << ans << '\n';return;}ans += now;p *= LD1 - cp;}pow2 *= 2;}}int main() {std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);int T = 1;for (int t = 0; t < T; t++) {solve();}return 0;}