結果
問題 | No.2884 Pieces on Squares |
ユーザー | shobonvip |
提出日時 | 2024-09-20 03:18:02 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 240 ms / 2,000 ms |
コード長 | 1,825 bytes |
コンパイル時間 | 2,153 ms |
コンパイル使用メモリ | 211,348 KB |
実行使用メモリ | 11,520 KB |
最終ジャッジ日時 | 2024-09-20 03:18:09 |
合計ジャッジ時間 | 5,864 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
6,784 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 21 ms
6,400 KB |
testcase_04 | AC | 6 ms
5,376 KB |
testcase_05 | AC | 16 ms
5,632 KB |
testcase_06 | AC | 44 ms
9,472 KB |
testcase_07 | AC | 44 ms
9,472 KB |
testcase_08 | AC | 38 ms
8,576 KB |
testcase_09 | AC | 26 ms
7,296 KB |
testcase_10 | AC | 24 ms
6,656 KB |
testcase_11 | AC | 58 ms
11,520 KB |
testcase_12 | AC | 4 ms
5,376 KB |
testcase_13 | AC | 4 ms
5,376 KB |
testcase_14 | AC | 168 ms
5,376 KB |
testcase_15 | AC | 201 ms
5,376 KB |
testcase_16 | AC | 23 ms
5,376 KB |
testcase_17 | AC | 13 ms
5,376 KB |
testcase_18 | AC | 13 ms
5,504 KB |
testcase_19 | AC | 4 ms
5,376 KB |
testcase_20 | AC | 24 ms
6,656 KB |
testcase_21 | AC | 39 ms
5,376 KB |
testcase_22 | AC | 50 ms
10,624 KB |
testcase_23 | AC | 32 ms
8,192 KB |
testcase_24 | AC | 47 ms
9,856 KB |
testcase_25 | AC | 240 ms
5,376 KB |
testcase_26 | AC | 210 ms
5,376 KB |
testcase_27 | AC | 232 ms
5,376 KB |
testcase_28 | AC | 19 ms
6,528 KB |
testcase_29 | AC | 19 ms
6,400 KB |
testcase_30 | AC | 22 ms
6,912 KB |
testcase_31 | AC | 240 ms
5,376 KB |
testcase_32 | AC | 31 ms
8,192 KB |
testcase_33 | AC | 32 ms
7,936 KB |
testcase_34 | AC | 3 ms
5,376 KB |
testcase_35 | AC | 4 ms
5,376 KB |
testcase_36 | AC | 4 ms
5,376 KB |
testcase_37 | AC | 2 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 2 ms
5,376 KB |
testcase_40 | AC | 2 ms
5,376 KB |
testcase_41 | AC | 2 ms
5,376 KB |
testcase_42 | AC | 2 ms
5,376 KB |
testcase_43 | AC | 2 ms
5,376 KB |
testcase_44 | AC | 2 ms
5,376 KB |
testcase_45 | AC | 16 ms
5,504 KB |
testcase_46 | AC | 4 ms
5,376 KB |
testcase_47 | AC | 2 ms
5,376 KB |
testcase_48 | AC | 2 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; } | ^~~~
ソースコード
#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'; }