結果

問題 No.1703 Much Matching
ユーザー 👑 jupirojupiro
提出日時 2021-10-08 22:44:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 2,076 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 210,432 KB
実行使用メモリ 34,624 KB
最終ジャッジ日時 2023-09-30 11:46:41
合計ジャッジ時間 5,827 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 13 ms
9,404 KB
testcase_04 AC 10 ms
7,536 KB
testcase_05 AC 24 ms
16,112 KB
testcase_06 AC 60 ms
14,340 KB
testcase_07 AC 5 ms
4,400 KB
testcase_08 AC 83 ms
22,600 KB
testcase_09 AC 78 ms
18,348 KB
testcase_10 AC 15 ms
7,004 KB
testcase_11 AC 29 ms
12,500 KB
testcase_12 AC 6 ms
4,960 KB
testcase_13 AC 36 ms
10,756 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 34 ms
17,744 KB
testcase_16 AC 36 ms
9,396 KB
testcase_17 AC 43 ms
10,936 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 85 ms
17,584 KB
testcase_20 AC 11 ms
4,920 KB
testcase_21 AC 105 ms
21,056 KB
testcase_22 AC 62 ms
19,672 KB
testcase_23 AC 41 ms
12,400 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 11 ms
7,272 KB
testcase_26 AC 44 ms
18,672 KB
testcase_27 AC 48 ms
11,496 KB
testcase_28 AC 113 ms
26,300 KB
testcase_29 AC 32 ms
13,840 KB
testcase_30 AC 38 ms
13,348 KB
testcase_31 AC 10 ms
7,304 KB
testcase_32 AC 63 ms
17,300 KB
testcase_33 AC 56 ms
19,864 KB
testcase_34 AC 5 ms
4,448 KB
testcase_35 AC 15 ms
7,504 KB
testcase_36 AC 199 ms
34,624 KB
testcase_37 AC 41 ms
26,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll = long long;
using std::cin;
using std::cout;
using std::endl;
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

void solve([[maybe_unused]] int CASE)
{
  int n, m, q;
  cin >> n >> m >> q;
  std::vector<std::pair<int, int>> vp(q);
  std::vector<std::vector<int>> mat(n, std::vector<int>(m));
  for (int i = 0; i < q; ++i)
  {
    cin >> vp[i].first >> vp[i].second;
    vp[i].first -= 1, vp[i].second -= 1;
    mat[vp[i].first][vp[i].second] = 1;
  }
  std::vector dp(4, std::vector(n, std::vector<int>(m)));
  if (mat[0][0])
    dp[3][0][0] = 1;

  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < m; ++j)
    {
      if (i + 1 < n)
      {
        for (int S = 0; S < 4; ++S)
        {
          int nS = S;
          if (S >> 1 & 1)
            nS -= (1 << 1);
          chmax(dp[nS][i + 1][j], dp[S][i][j]);
          if (mat[i + 1][j] and nS == 0)
          {
            chmax(dp[3][i + 1][j], dp[S][i][j] + 1);
          }
        }
      }
      if (j + 1 < m)
      {
        for (int S = 0; S < 4; ++S)
        {
          int nS = S;
          if (S & 1)
            nS -= 1;
          chmax(dp[nS][i][j + 1], dp[S][i][j]);
          if (mat[i][j + 1] and nS == 0)
          {
            chmax(dp[3][i][j + 1], dp[S][i][j] + 1);
          }
        }
      }
    }
  }
  // for (int i = 0; i < n; ++i)
  // {
  //   for (int j = 0; j < m; ++j)
  //   {
  //     cout << dp[3][i][j] << " \n"[j + 1 == m];
  //   }
  // }
  int res = 0;
  for (int i = 0; i < 4; ++i)
    chmax(res, dp[i][n - 1][m - 1]);
  cout << res << endl;
}

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int kkt = 1;
  // cin >> kkt;
  for (int jupi = 1; jupi <= kkt; jupi++)
    solve(jupi);
  return 0;
}
0