結果

問題 No.2871 Universal Serial Bus
ユーザー n0ma_run0ma_ru
提出日時 2024-09-06 21:53:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,777 bytes
コンパイル時間 2,435 ms
コンパイル使用メモリ 215,096 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-06 21:53:54
合計ジャッジ時間 3,081 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 WA -
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 WA -
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(v) v.begin(),v.end()
#define dbg(x) cerr << #x << ": " << (x) << endl;
template<class F, class S>
ostream& operator<<(ostream& os, pair<F,S>& p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<class Iter>
void print(Iter beg, Iter end) {
    for (Iter itr = beg; itr != end; ++itr) {
        cerr << *itr << ' ';
    }
    cerr << '\n';
}
// 転置
// pos 対象の座標
// h 転置前のy座標範囲[0, h)
// w 転置前のx座標範囲[0, w)
vector<pair<int,int>> transpose(const vector<pair<int,int>>& pos, int h, int w) {
    vector<pair<int,int>> res;
    for (const auto& [x,y] : pos) {
        int nx = y;
        int ny = x;
        res.emplace_back(nx, ny);
    }
    return res;
}
// y座標の反転
// h 反転前のy座標範囲[0, h)
// w 反転前のx座標範囲[0, w)
vector<pair<int,int>> flip_y(const vector<pair<int,int>>& pos, int h, int w) {
    vector<pair<int,int>> res;
    for (const auto& [x,y] : pos) {
        res.emplace_back(x, h-y-1);
    }
    return res;
}
// x座標の反転
// h 反転前のy座標範囲[0, h)
// w 反転前のx座標範囲[0, w)
vector<pair<int,int>> flip_x(const vector<pair<int,int>>& pos, int h, int w) {
    vector<pair<int,int>> res;
    for (const auto& [x,y] : pos) {
        res.emplace_back(w-x-1, y);
    }
    return res;
}
// 回転
// h 回転前のy座標範囲[0, h)
// w 回転前のx座標範囲[0, w)
// 必要:transpose, flip_xかflip_y
vector<pair<int,int>> rotate(const vector<pair<int,int>>& pos, int h, int w) {
    auto res = transpose(pos, h, w);
    res = flip_x(res, w, h); // 右回転
    // res = flip_y(res, w, h); // 左回転
    return res;
}
int h,w;
vector<string> s,t;
int main() {
    cin >> h >> w;
    s.resize(h); t.resize(h);
    for (int i = 0; i < h; ++i) cin >> s[i];
    for (int i = 0; i < h; ++i) cin >> t[i];

    vector<pair<int,int>> ps, pt;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '#') {
                ps.emplace_back(j, i);
            }
            if (t[i][j] == '.') {
                pt.emplace_back(j, i);
            }
        }
    }
    sort(ALL(ps));
    sort(ALL(pt));
    double ans = 0;
    if (ps == pt) {
        ans = 3.5317401904617327;
    } else {
        pt = rotate(pt, h, w);
        pt = rotate(pt, h, w);
        sort(ALL(pt));
        if (ps == pt) {
            double base = 1;
            for (int t = 4; t < 60; t+=2) {
                double p = 1.0 / (1LL << (t-1));
                ans += t * base * (1 - p);
                base *= p;
            }
        } else {
            ans = -1;
        }
    }
    cout << fixed << setprecision(20) << ans << '\n';
}
0