結果

問題 No.766 金魚すくい
ユーザー ei1333333ei1333333
提出日時 2018-11-09 00:05:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,324 bytes
コンパイル時間 2,009 ms
コンパイル使用メモリ 199,408 KB
実行使用メモリ 453,168 KB
最終ジャッジ日時 2023-08-26 04:46:13
合計ジャッジ時間 10,089 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 WA -
testcase_36 WA -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:57:11: 警告: ‘res’ may be used uninitialized [-Wmaybe-uninitialized]
   57 |   cout << res << endl;
      |           ^~~
main.cpp:46:7: 備考: ‘res’ はここで定義されています
   46 |   int res;
      |       ^~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int vy[] = {1, 0, -1, 0};
const int vx[] = {0, 1, 0, -1};

int N;
string S[3000];
bool v[3000][3000];
int ord[3000][3000], low[3000][3000], k;
int sub[3000][3000];


int rec(int y, int x, int py = -1, int px = -1) {
  v[y][x] = true;
  ord[y][x] = k++;
  low[y][x] = ord[y][x];
  sub[y][x] = S[y][x] == '.';
  int ret = 0, add = 1;
  for(int i = 0; i < 4; i++) {
    int ny = y + vy[i], nx = x + vx[i];
    if(ny < 0 || nx < 0 || ny >= N || nx >= N) continue;
    if(S[ny][nx] == '#') continue;
    if(ny == py && nx == px) continue;
    if(v[ny][nx]) {
      low[y][x] = min(low[y][x], ord[ny][nx]);
    } else {
      ret = max(ret, rec(ny, nx, y, x));
      sub[y][x] += sub[ny][nx];
      low[y][x] = min(low[y][x], low[ny][nx]);
      if(ord[y][x] <= low[ny][nx]) add += sub[ny][nx];
    }
  }
  if(S[y][x] == '.') ret = max(ret, add);
  return ret;
}

int main() {
  cin >> N;
  int all = 0;
  for(int i = 0; i < N; i++) {
    cin >> S[i];
    all += count(begin(S[i]), end(S[i]), '.');
  }
  int res;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      if(S[i][j] == 'T') res = all - rec(i, j);
    }
  }
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      if(!v[i][j]) res -= S[i][j] == '.';
    }
  }
  cout << res << endl;
}
0