結果
| 問題 |
No.2884 Pieces on Squares
|
| コンテスト | |
| ユーザー |
Iroha_3856
|
| 提出日時 | 2024-09-06 21:47:30 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,159 bytes |
| コンパイル時間 | 3,825 ms |
| コンパイル使用メモリ | 168,140 KB |
| 実行使用メモリ | 13,724 KB |
| 最終ジャッジ日時 | 2024-09-06 21:47:47 |
| 合計ジャッジ時間 | 11,387 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 12 TLE * 2 -- * 31 |
ソースコード
#pragma GCC target("avx512vl")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/dsu>
using namespace atcoder;
bitset<5064> dp[5000+1];
#pragma clang attribute push(__attribute__((target ("avx,avx2"))),apply_to=function)
int main() {
int H, W, N; cin >> H >> W >> N;
atcoder::dsu d(H+W);
for (int i = 0; i < N; i++) {
int a, b; cin >> a >> b;
a--; b--;
d.merge(a, b+H);
}
vector<vector<int>> G = d.groups();
int K = (int)G.size();
dp[0][0] = 1;
int rcsum = 0;
for (int i = 0; i < K; i++) {
vector<int> g = G[i];
int rcnt = 0, ccnt = 0;
for (int v : g) {
if (v < H) rcnt++;
else ccnt++;
}
for (int j = rcsum; j >= 0; j--) {
dp[j+rcnt]|=(dp[j]<<ccnt);
}
rcsum += rcnt;
}
int ans = 0;
for (int i = 0; i <= H; i++) {
for (int j = 0; j <= W; j++) {
if (dp[i][j]) {
ans = max(ans, i*(W-j)+(H-i)*j);
}
}
}
cout << ans << endl;
}
#pragma clang attribute pop
Iroha_3856