結果

問題 No.1703 Much Matching
ユーザー jupiro
提出日時 2021-10-08 22:44:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 2,076 bytes
コンパイル時間 3,440 ms
コンパイル使用メモリ 203,776 KB
最終ジャッジ日時 2025-01-24 22:58:29
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0