結果

問題 No.2261 Coffee
ユーザー nu50218
提出日時 2023-04-07 21:47:40
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 412 ms / 2,000 ms
コード長 1,549 bytes
コンパイル時間 11,746 ms
コンパイル使用メモリ 278,676 KB
最終ジャッジ日時 2025-02-12 01:03:54
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef LOCAL
#include <local.hpp>
#else
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2")
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define postprocess(...) ((void)0)
#endif

using namespace std;
using ll = long long;
using ld = long double;

void solve([[maybe_unused]] int test) {
    int N;
    cin >> N;

    vector<vector<ll>> v(N, vector<ll>(5, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 5; j++) {
            cin >> v[i][j];
        }
    }

    vector<ll> ans(N, 0);

    for (int bits = 0; bits < (1 << 5); bits++) {
        bool positive[5];

        for (int i = 0; i < 5; i++) {
            positive[i] = bits & (1 << i);
        }

        auto opt = *max_element(v.begin(), v.end(), [&](vector<ll> a, vector<ll> b) {
            ll val_a = 0, val_b = 0;

            for (int i = 0; i < 5; i++) {
                ll k = positive[i] ? 1 : -1;

                val_a += k * a[i];
                val_b += k * b[i];
            }

            return val_a < val_b;
        });

        for (int i = 0; i < N; i++) {
            ll dist = 0;

            for (int j = 0; j < 5; j++) {
                dist += abs(v[i][j] - opt[j]);
            }

            ans[i] = max(ans[i], dist);
        }
    }

    for (int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) {
        solve(i);
    }

    postprocess();
}
0