結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<vector<ll>> S(N,vector<ll>(5));
    for(int i=0;i<N;i++){
        for(int j=0;j<5;j++) cin>>S[i][j];
    }
    
    vector<vector<ll>> Lma(N+2,vector<ll>(1<<5,-(1LL<<60))),Rma,T;
    
    for(int i=0;i<N;i++){
        for(int x=0;x<(1<<5);x++){
            ll sum=0;
            for(int k=0;k<5;k++){
                if(x&(1<<k)) sum+=S[i][k];
                else sum-=S[i][k];
            }
            Lma[i+1][x]=sum;
        }
    }
    
    Rma=Lma;
    T=Lma;
    
    for(int i=1;i<=N+1;i++){
        for(int x=0;x<(1<<5);x++) chmax(Lma[i][x],Lma[i-1][x]);
    }
    for(int i=N;i>=0;i--){
        for(int x=0;x<(1<<5);x++) chmax(Rma[i][x],Rma[i+1][x]);
    }
    
    for(int s=1;s<=N;s++){
        ll ans=-(1LL<<60);
        for(int x=0;x<(1<<5);x++){
            chmax(ans,T[s][x]+Lma[s-1][31-x]);
            chmax(ans,T[s][x]+Rma[s+1][31-x]);
        }
        cout<<ans<<"\n";
    }
}
0