結果
| 問題 | No.2871 Universal Serial Bus |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-09-07 14:19:28 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 2,000 ms |
| コード長 | 1,209 bytes |
| 記録 | |
| コンパイル時間 | 242 ms |
| コンパイル使用メモリ | 70,928 KB |
| 実行使用メモリ | 16,640 KB |
| 最終ジャッジ日時 | 2026-07-05 14:55:57 |
| 合計ジャッジ時間 | 1,592 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 2871.cc: No.2871 Universal Serial Bus - yukicoder
*/
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_H = 20;
const int MAX_W = 20;
const int CNT = 100;
/* typedef */
/* global variables */
char ss[MAX_H][MAX_W + 4], ts[MAX_H][MAX_W + 4];
/* subroutines */
bool check(int h, int w, bool rev) {
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++) {
int ti = rev ? h - 1 - i : i;
int tj = rev ? w - 1 - j : j;
if (ss[i][j] == ts[ti][tj]) return false;
}
return true;
}
double calc(double p1, double p2) {
double sum = 0.0, r = 1.0;
for (int i = 1; i <= CNT; i++) {
double pi = (i & 1) ? p1 : p2;
double dr = r * (1.0 - pow(pi, -(i - 1)));
sum += i * dr;
r -= dr;
}
return sum;
}
/* main */
int main() {
int h, w;
scanf("%d%d", &h, &w);
for (int i = 0; i < h; i++) scanf("%s", ss[i]);
for (int i = 0; i < h; i++) scanf("%s", ts[i]);
bool f0 = check(h, w, false), f1 = check(h, w, true);
//printf("%d %d\n", f0, f1);
double sum = calc(f0 ? 2 : 1, f1 ? 2 : 1);
if (sum <= 0.0) puts("-1");
else printf("%.12lf\n", sum);
return 0;
}
tnakao0123