結果

問題 No.2837 Flip Triomino
ユーザー tnakao0123
提出日時 2024-08-12 00:40:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,058 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 41,468 KB
最終ジャッジ日時 2025-02-23 22:36:02
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:42:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   42 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:45:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |     scanf("%s", s);
      |     ~~~~~^~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2837.cc:  No.2837 Flip Triomino - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 500;
const int MAX_M = 500;
const int MOD = 998244353;

/* typedef */

using ll = long long;

/* global variables */

char s[MAX_M + 4];
int bs[3], qs[3];

/* subroutines */

int powmod(int a, int b) {
  int p = 1;
  while (b > 0) {
    if (b & 1) p = (ll)p * a % MOD;
    a = (ll)a * a % MOD;
    b >>= 1;
  }
  return p;
}

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    for (int j = 0; j < m; j++) {
      if (s[j] == 'B') bs[(i + j) % 3]++;
      else if (s[j] == '?') qs[(i + j) % 3]++;
    }
  }

  int sum = 0;
  for (int p = 0; p < 2; p++) {
    int x = 1;
    for (int i = 0; i < 3; i++) {
      int c = 0;
      if (qs[i] == 0) c = ((bs[i] & 1) == p) ? 1 : 0;
      else c = powmod(2, qs[i] - 1);
      x = (ll)x * c % MOD;
    }
    sum = (sum + x) % MOD;
  }

  printf("%d\n", sum);

  return 0;
}
0