結果

問題 No.2692 How Many Times Reached?
ユーザー tnakao0123
提出日時 2024-04-26 18:11:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 41,600 KB
最終ジャッジ日時 2025-02-21 09:08:13
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:37:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:38:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |   for (int i = 0; i < n; i++) scanf("%s", ss[i]);
      |                               ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2692.cc:  No.2692 How Many Times Reached? - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

char ss[MAX_N][MAX_N + 4];

/* subroutines */

bool check(int n, int y, int x, int dy, int dx) {
  int a = 0, d = 0;
  for (int i = 0; i < n; i++) {
    if (ss[y][x] == 'A') a++;
    else if (ss[y][x] == '.') d++;
    y += dy, x += dx;
  }
  return (a == n - 1 && d == 1);
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%s", ss[i]);
  
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (check(n, i, 0, 0, 1)) cnt++;
    if (check(n, 0, i, 1, 0)) cnt++;
  }

  if (check(n, 0, 0, 1, 1)) cnt++;
  if (check(n, 0, n - 1, 1, -1)) cnt++;

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

  return 0;
}
0