結果
問題 |
No.1874 Minimum of Sum of Rectangles
|
ユーザー |
|
提出日時 | 2022-03-13 18:21:47 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,169 bytes |
コンパイル時間 | 2,791 ms |
コンパイル使用メモリ | 130,668 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-19 01:59:20 |
合計ジャッジ時間 | 5,575 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 WA * 1 |
ソースコード
#include <algorithm> #include <iostream> #include <numeric> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> X(N), Y(N); for (int i = 0; i < N; i++) cin >> X[i] >> Y[i]; vector<int> xord(N), yord(N); iota(xord.begin(), xord.end(), 0); sort(xord.begin(), xord.end(), [&](int a, int b) { return X[a] < X[b]; }); iota(yord.begin(), yord.end(), 0); sort(yord.begin(), yord.end(), [&](int a, int b) { return Y[a] < Y[b]; }); if (X[xord.front()] == X[xord.back()] || Y[yord.front()] == Y[yord.back()]) { cout << 0 << endl; return 0; } int xpt = X[0], ypt = Y[0]; auto calc = [&]() { long long ans = 0; for (int i = 0; i < N; i++) { ans += 1LL * abs(X[i] - xpt) * abs(Y[i] - ypt); } return ans; }; while (true) { { long long sd = 0; for (int i = 0; i < N; i++) sd += abs(Y[i] - ypt); long long cs = 0; for (int i : xord) { cs += abs(Y[i] - ypt); if (cs * 2 >= sd) { if (xpt == X[i]) { cout << calc() << endl; return 0; } else { xpt = X[i]; break; } } } } { long long sd = 0; for (int i = 0; i < N; i++) sd += abs(X[i] - xpt); long long cs = 0; for (int i : yord) { cs += abs(X[i] - xpt); if (cs * 2 >= sd) { if (ypt == Y[i]) { cout << calc() << endl; return 0; } else { ypt = Y[i]; break; } } } } } }