結果
| 問題 |
No.2871 Universal Serial Bus
|
| コンテスト | |
| ユーザー |
n0ma_ru
|
| 提出日時 | 2024-09-06 21:53:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,777 bytes |
| コンパイル時間 | 2,149 ms |
| コンパイル使用メモリ | 206,056 KB |
| 最終ジャッジ日時 | 2025-02-24 04:16:14 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 WA * 9 |
ソースコード
#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';
}
n0ma_ru