結果

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

ソースコード

diff #

#include <bits/stdc++.h>

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int H, W;
    std::cin >> H >> W;

    std::vector<std::string> S(H), T(H);
    for(int i=0;i<H;i++){
        std::cin >> S[i];
    }
    for(int i=0;i<H;i++){
        std::cin >> T[i];
    }

    bool ok1 = true, ok2 = true;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i][j] == T[i][j]){
                ok1 = false;
            }
            if(S[H-1-i][W-1-j] == T[i][j]){
                ok2 = false;
            }
        }
    }

    if(!ok1 && !ok2){
        std::cout << -1 << std::endl;
        return 0;
    }

    double res = 0;
    double p = 1, q = 1;
    for(int i=1;i<=100;i++){
        if(i % 2 == 1 && ok1 || i % 2 == 0 && ok2){
            res += q * (1.0 - p) * i;
            q *= p;
        }
        p *= 0.5;
    }

    std::cout << std::setprecision(12) << res << std::endl;
}
0