結果

問題 No.2261 Coffee
ユーザー t98slider
提出日時 2023-04-07 22:04:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 702 ms / 2,000 ms
コード長 1,562 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 179,976 KB
実行使用メモリ 11,064 KB
最終ジャッジ日時 2024-10-02 19:33:50
合計ジャッジ時間 17,218 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<array<ll, 5>> a(N);
    vector<ll> ans(N, -(1ll << 60));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 5; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < 32; i++){
        vector<pair<ll,ll>> b(N);
        for(int j = 0; j < N; j++){
            ll x = 0, y = 0;
            for(int k = 0; k < 5; k++){
                if(i >> k & 1) x += a[j][k];
                else y += a[j][k];
            }
            b[j] = make_pair(x, y);
        }
        auto c = b;
        sort(c.begin(), c.end(), [&](pair<ll,ll> lhs, pair<ll,ll> rhs){
            return lhs.first + lhs.second < rhs.first + rhs.second;
        });
        ll mn = c[0].first + c[0].second, mx = c[N - 1].first + c[N - 1].second;
        for(int j = 0; j < N; j++){
            ll v = b[j].first + b[j].second;
            ans[j] = max(ans[j], abs(mn - v));
            ans[j] = max(ans[j], abs(mx - v));
        }
        sort(c.begin(), c.end(), [&](pair<ll,ll> lhs, pair<ll,ll> rhs){
            return lhs.first - lhs.second < rhs.first - rhs.second;
        });
        mn = c[0].first - c[0].second, mx = c[N - 1].first - c[N - 1].second;
        for(int j = 0; j < N; j++){
            ll v = b[j].first - b[j].second;
            ans[j] = max(ans[j], abs(mn - v));
            ans[j] = max(ans[j], abs(mx - v));
        }
    }
    for(int i = 0; i < N; i++) cout << ans[i] << '\n';
}
0