結果

問題 No.2731 Two Colors
ユーザー soldraysoldray
提出日時 2024-04-20 01:09:09
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,431 bytes
コンパイル時間 2,347 ms
コンパイル使用メモリ 167,168 KB
実行使用メモリ 832,088 KB
最終ジャッジ日時 2024-04-20 01:09:27
合計ジャッジ時間 11,548 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
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 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

#define yn(pope) (pope ? "Yes" : "No")

#define rep(i, n, m) for (int i = (n); i < (m); i++)
#define rrep(i, n, m) for (int i = (n); i > m; i--)

#define IINF (1 << 30)
#define INF (1ll << 60)

#define all(v) v.begin(), v.end()

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

  vector A(W, vector(H, 0ll));

  rep(i, 0, H) {
    rep(j, 0, W) { cin >> A[j][i]; }
  }

  vector used(W, vector(H, -1));

  auto valid = [&](int x, int y) -> bool {
    return 0 <= x && x < W && 0 <= y && y < H;
  };

  int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

  int ans = 0;

  using tt = tuple<i64, int, int>;

  vector<priority_queue<tt, vector<tt>, greater<tt>>> V(2);

  V[0].push({A[0][0], 0, 0});
  V[1].push({A[W - 1][H - 1], W - 1, H - 1});

  auto play = [&](int t) -> bool {
    if (V[t].size() > 0) {
      auto [u, x, y] = V[t].top(); V[t].pop();

      used[x][y] = t;

      rep(i, 0, 4) {
        int _x = x + dx[i], _y = y + dy[i];

        if (valid(_x, _y)) {
          if (used[_x][_y] == -1) {
            V[t].push({A[_x][_y], _x, _y});
          }

          if (used[_x][_y] == (t ^ 1)) {
            return false;
          }
        }
      }
    }

    return true;
  };

  int t = 0;

  while(play(t)) {
    t = t ^ 1;
  }

  rep(i, 0, H) {
    rep(j, 0, W) {
      ans += (used[j][i] != -1);
    }
  }

  cout << ans - 2 << endl;

  return 0;
}
0