結果

問題 No.866 レベルKの正方形
ユーザー nakaken88nakaken88
提出日時 2019-08-17 09:34:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,093 bytes
コンパイル時間 2,174 ms
コンパイル使用メモリ 182,352 KB
実行使用メモリ 251,212 KB
最終ジャッジ日時 2023-10-24 23:56:30
合計ジャッジ時間 10,512 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 25 ms
35,036 KB
testcase_07 AC 25 ms
35,036 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int c(std::vector<long long int>)':
main.cpp:20:10: warning: 'temp' may be used uninitialized [-Wmaybe-uninitialized]
   20 |   return temp;
      |          ^~~~
main.cpp:16:7: note: 'temp' was declared here
   16 |   int temp;
      |       ^~~~
main.cpp: In function 'void check(int, int, int, int, std::vector<long long int>)':
main.cpp:25:8: warning: 'temp' may be used uninitialized [-Wmaybe-uninitialized]
   25 |   if (c(A) < K) return;
      |       ~^~~
main.cpp:16:7: note: 'temp' was declared here
   16 |   int temp;
      |       ^~~~
main.cpp:26:8: warning: 'temp' may be used uninitialized [-Wmaybe-uninitialized]
   26 |   if (c(A) == K) ans++;
      |       ~^~~
main.cpp:16:7: note: 'temp' was declared here
   16 |   int temp;
      |       ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

ll H, W, K;
ll ans;
vector<vector<ll>> board(2000, vector<ll>(2000));
set <pair<pair<int, int>,int>> visited;

int c(vector<ll> x) {
  int temp;
  for (int i = 0; i < x.size(); i++) {
    if (x[i] > 0) temp++;
  }
  return temp;
}

void check(int sx, int sy, int ex, int ey, vector<ll> A) {
  visited.insert(make_pair(make_pair(sx, sy), ex - sx));
  if (c(A) < K) return;
  if (c(A) == K) ans++;
  if (sx == ex) return;

  vector<ll> A1 = A;
  for (int i = sx; i <= ex; i++) {
    A1[board[i][sy]]--;
  }
  vector<ll> A11 = A1;
  for (int i = sy + 1; i <= ey; i++) {
    A11[board[sx][i]]--;
  }
  if (visited.find(make_pair(make_pair(sx + 1, sy + 1), ex - sx - 1)) ==
      visited.end()) {
    check(sx + 1, sy + 1, ex, ey, A11);
  }

  vector<ll> A12 = A1;
  for (int i = sy + 1; i <= ey; i++) {
    A12[board[ex][i]]--;
  }
  if (visited.find(make_pair(make_pair(sx, sy + 1), ex - sx - 1)) ==
      visited.end()) {
    check(sx, sy + 1, ex - 1, ey, A12);
  }

  vector<ll> A2 = A;
  for (int i = sx; i <= ex; i++) {
    A2[board[i][ey]]--;
  }
  vector<ll> A21 = A2;
  for (int i = sy; i <= ey - 1; i++) {
    A21[board[sx][i]]--;
  }
  if (visited.find(make_pair(make_pair(sx + 1, sy), ex - sx - 1)) ==
      visited.end()) {
    check(sx + 1, sy, ex, ey - 1, A21);
  }

  vector<ll> A22 = A2;
  for (int i = sy; i <= ey - 1; i++) {
    A22[board[ex][i]]--;
  }
  if (visited.find(make_pair(make_pair(sx, sy), ex - sx - 1)) ==
      visited.end()) {
    check(sx, sy, ex - 1, ey - 1, A22);
  }
}

int main() {
  cin >> H >> W >> K;

  vector<ll> a(26, 0);

  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.size(); j++) {
      int alpha = s[j] - 'a';
      board[i][j] = alpha;
      a[alpha]++;
    }
  }
  ans = 0;
  check(0, 0, H - 1, W - 1, a);
  cout << ans << BR;

  return 0;
}
0