結果

問題 No.2261 Coffee
ユーザー mtrhmtrh
提出日時 2023-04-08 19:04:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 480 ms / 2,000 ms
コード長 1,416 bytes
コンパイル時間 2,523 ms
コンパイル使用メモリ 203,604 KB
実行使用メモリ 27,520 KB
最終ジャッジ日時 2024-04-14 15:43:48
合計ジャッジ時間 13,761 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 15 ms
6,940 KB
testcase_18 AC 14 ms
6,940 KB
testcase_19 AC 12 ms
6,940 KB
testcase_20 AC 11 ms
6,944 KB
testcase_21 AC 14 ms
6,944 KB
testcase_22 AC 12 ms
6,944 KB
testcase_23 AC 15 ms
6,944 KB
testcase_24 AC 442 ms
25,856 KB
testcase_25 AC 377 ms
22,528 KB
testcase_26 AC 467 ms
27,264 KB
testcase_27 AC 437 ms
25,600 KB
testcase_28 AC 219 ms
23,424 KB
testcase_29 AC 216 ms
23,040 KB
testcase_30 AC 169 ms
18,816 KB
testcase_31 AC 277 ms
27,504 KB
testcase_32 AC 276 ms
27,376 KB
testcase_33 AC 281 ms
27,520 KB
testcase_34 AC 278 ms
27,392 KB
testcase_35 AC 276 ms
27,392 KB
testcase_36 AC 278 ms
27,376 KB
testcase_37 AC 282 ms
27,392 KB
testcase_38 AC 479 ms
27,392 KB
testcase_39 AC 479 ms
27,392 KB
testcase_40 AC 474 ms
27,392 KB
testcase_41 AC 473 ms
27,520 KB
testcase_42 AC 473 ms
27,392 KB
testcase_43 AC 480 ms
27,392 KB
testcase_44 AC 475 ms
27,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

vector<ll> max_manhattan_distance(const vector<vector<ll>> &p) {
    int k = p[0].size(), N = p.size();
    int maxbit = 1 << (k - 1);
    vector<vector<ll>> fp(N, vector<ll>(maxbit));
    for (int i = 0; i < N; i++) {
        for (int bit = 0; bit < maxbit; bit++) {
            ll tmp = p[i][k - 1];
            for (int j = 0; j < k - 1; j++) {
                if (bit & (1 << j)) {
                    tmp += p[i][j];
                } else {
                    tmp -= p[i][j];
                }
            }
            fp[i][bit] = tmp;
        }
    }
    ll INF = 1LL << 60;
    vector<ll> m(maxbit, INF), M(maxbit, -INF);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < maxbit; j++) {
            m[j] = min(m[j], fp[i][j]);
            M[j] = max(M[j], fp[i][j]);
        }
    }
    vector<ll> res(N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < maxbit; j++) {
            res[i] = max({res[i], abs(fp[i][j] - m[j]), abs(fp[i][j] - M[j])});
        }
    }
    return res;
}

int main() {
    int N;
    cin >> N;
    vector<vector<ll>> param(N, vector<ll>(5));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 5; j++) {
            cin >> param[i][j];
        }
    }
    auto ans = max_manhattan_distance(param);
    for (auto a : ans) {
        cout << a << endl;
    }
    return 0;
}
0