結果
| 問題 |
No.2871 Universal Serial Bus
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-09-07 14:19:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 1,209 bytes |
| コンパイル時間 | 488 ms |
| コンパイル使用メモリ | 57,576 KB |
| 最終ジャッジ日時 | 2025-02-24 05:08:39 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:51:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
51 | scanf("%d%d", &h, &w);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:52:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
52 | for (int i = 0; i < h; i++) scanf("%s", ss[i]);
| ~~~~~^~~~~~~~~~~~~
main.cpp:53:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
53 | for (int i = 0; i < h; i++) scanf("%s", ts[i]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
/* -*- 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