結果

問題 No.2884 Pieces on Squares
ユーザー shobonvipshobonvip
提出日時 2024-09-20 03:03:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,840 bytes
コンパイル時間 2,590 ms
コンパイル使用メモリ 212,052 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-09-20 03:03:28
合計ジャッジ時間 6,067 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 186 ms
5,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 46 ms
9,856 KB
testcase_25 AC 237 ms
5,376 KB
testcase_26 AC 260 ms
5,376 KB
testcase_27 AC 237 ms
5,376 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 23 ms
6,784 KB
testcase_31 AC 240 ms
5,376 KB
testcase_32 AC 32 ms
8,064 KB
testcase_33 AC 29 ms
7,936 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 2 ms
5,376 KB
testcase_38 WA -
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 1 ms
5,376 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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; }
      |                     ^~~~

ソースコード

diff #

#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]+w);
		ikeru[b[i]+w].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(i,0,h+1){
			if (i+px <= h) {
				chmax(ndp[i+px], dp[i] + py);
				chmin(ndp2[i+px], dp2[i] + py);
			}
			if (i+ax-px <= h) {
				chmax(ndp[i+ax-px], dp[i] + ay-py);
				chmin(ndp2[i+ax-px], dp2[i] + ay-py);
			}
		}
		swap(dp, ndp);
		swap(dp2, ndp2);
	}

	ll ans = 1e18;
	rep(i,0,h+1){
		if (dp[i] >= 0){
			chmin(ans, (ll)(h - i) * (w - dp[i]) + (ll)i * dp[i]);
			chmin(ans, (ll)(h - i) * (w - dp2[i]) + (ll)i * dp2[i]);
		}
	}

	ans = h * w - ans;
	cout << ans << '\n';
}
0