結果
| 問題 |
No.2884 Pieces on Squares
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2024-09-20 03:18:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 199 ms / 2,000 ms |
| コード長 | 1,825 bytes |
| コンパイル時間 | 2,184 ms |
| コンパイル使用メモリ | 205,860 KB |
| 最終ジャッジ日時 | 2025-02-24 09:41:55 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 45 |
コンパイルメッセージ
main.cpp:6:12: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
6 | bool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; }
| ^~~~
main.cpp:6:21: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
6 | bool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; }
| ^~~~
main.cpp:7:12: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
7 | bool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; }
| ^~~~
main.cpp:7:21: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
7 | bool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; }
| ^~~~
ソースコード
#include<bits/stdc++.h>
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define all(v) begin(v),end(v)
using namespace std;
using ll = long long;
bool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; }
int main(){
cin.tie(0)->sync_with_stdio(0);
int h, w, n; cin >> h >> w >> n;
vector<int> a(n), b(n);
vector ikeru(2*(h+w), vector<int>(0));
rep(i,0,n) {
cin >> a[i] >> b[i];
a[i] -= 1;
b[i] -= 1;
ikeru[a[i]].push_back(b[i]+h);
ikeru[b[i]+h].push_back(a[i]);
ikeru[a[i]+h+w].push_back(b[i]+h+h+w);
ikeru[b[i]+h+h+w].push_back(a[i]+h+w);
}
vector<ll> dp(h+1,-1e18);
vector<ll> dp2(h+1,1e18);
dp[0] = 0;
dp2[0] = 0;
vector<bool> seen(2*(h+w));
int px = 0, py = 0;
int ax = 0, ay = 0;
auto dfs = [&](auto self, int i) -> void {
if (0 <= i && i < h){
px++;
ax++;
}
if (h <= i && i < h + w){
py++;
ay++;
}
if (h + w <= i && i < h + w + h) {
ax++;
}
if (h + w + h <= i && i < h + w + h + w){
ay++;
}
seen[i] = true;
seen[(i + h + w) % (2 * (h + w))] = true;
for (int j: ikeru[i]){
if (seen[j]) continue;
self(self, j);
}
};
rep(i,0,h+w){
if (seen[i] || seen[i+h+w]) continue;
px = 0;
py = 0;
ax = 0;
ay = 0;
dfs(dfs, i);
vector<ll> ndp(h+1,-1e18);
vector<ll> ndp2(h+1,1e18);
rep(j,0,h+1){
if (j+px <= h) {
chmax(ndp[j+px], dp[j] + py);
chmin(ndp2[j+px], dp2[j] + py);
}
if (j+ax-px <= h) {
chmax(ndp[j+ax-px], dp[j] + ay-py);
chmin(ndp2[j+ax-px], dp2[j] + ay-py);
}
}
swap(dp, ndp);
swap(dp2, ndp2);
}
ll ans = 0;
rep(i,0,h+1){
if (dp[i] >= 0){
chmax(ans, (ll)i * w + (ll)dp[i] * h - 2 * (ll)i * dp[i]);
chmax(ans, (ll)i * w + (ll)dp2[i] * h - 2 * (ll)i * dp2[i]);
}
}
cout << ans << '\n';
}
shobonvip