結果

問題 No.2871 Universal Serial Bus
ユーザー eve__fuyuki
提出日時 2024-09-07 00:44:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 541 ms / 2,000 ms
コード長 977 bytes
コンパイル時間 2,369 ms
コンパイル使用メモリ 198,700 KB
最終ジャッジ日時 2025-02-24 05:05:09
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void fast_io() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main() {
	fast_io();
	int h, w;
	cin >> h >> w;
	vector<string> s(h), t(h);
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < h; i++) {
		cin >> t[i];
	}
	vector<string> s_rot(h, string(w, '.'));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			s_rot[h - 1 - i][w - 1 - j] = s[i][j];
		}
	}
	bool ok[2] = {true, true};
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == t[i][j]) {
				ok[0] = false;
			}
			if (s_rot[i][j] == t[i][j]) {
				ok[1] = false;
			}
		}
	}
	if (!ok[0] && !ok[1]) {
		cout << -1 << endl;
		return 0;
	}
	long double ans = 0;
	long double prob = 1.0;
	int M = 1e6;
	for (int i = 0; i < M; i++) {
		if (ok[i % 2]) {
			long double p = powl(2, -i);
			ans += (i + 1) * prob * (1.0 - p);
			prob *= p;
		}
	}
	cout << fixed << setprecision(16) << ans << endl;
}
0