結果

問題 No.2261 Coffee
ユーザー umezoumezo
提出日時 2023-04-07 22:05:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 1,251 bytes
コンパイル時間 2,209 ms
コンパイル使用メモリ 201,172 KB
実行使用メモリ 86,232 KB
最終ジャッジ日時 2024-04-10 17:09:01
合計ジャッジ時間 9,121 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 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,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 8 ms
6,944 KB
testcase_18 AC 7 ms
6,944 KB
testcase_19 AC 6 ms
6,940 KB
testcase_20 AC 5 ms
6,944 KB
testcase_21 AC 7 ms
6,940 KB
testcase_22 AC 6 ms
6,940 KB
testcase_23 AC 8 ms
6,940 KB
testcase_24 AC 207 ms
80,100 KB
testcase_25 AC 171 ms
69,320 KB
testcase_26 AC 212 ms
85,412 KB
testcase_27 AC 197 ms
79,392 KB
testcase_28 AC 134 ms
72,532 KB
testcase_29 AC 126 ms
70,992 KB
testcase_30 AC 101 ms
56,304 KB
testcase_31 AC 167 ms
86,108 KB
testcase_32 AC 164 ms
86,108 KB
testcase_33 AC 170 ms
86,104 KB
testcase_34 AC 165 ms
86,108 KB
testcase_35 AC 163 ms
86,100 KB
testcase_36 AC 164 ms
86,104 KB
testcase_37 AC 165 ms
86,104 KB
testcase_38 AC 219 ms
86,104 KB
testcase_39 AC 210 ms
86,100 KB
testcase_40 AC 214 ms
86,232 KB
testcase_41 AC 217 ms
86,108 KB
testcase_42 AC 220 ms
85,980 KB
testcase_43 AC 223 ms
85,976 KB
testcase_44 AC 215 ms
86,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;
 
const ll INF=1e18+7;

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n;
  cin>>n;
  vector<vector<ll>> G(n,vector<ll>(5));
  rep(i,n){
    rep(j,5) cin>>G[i][j];
  }
  
  vector<vector<ll>> A(32,vector<ll>(n,-INF));
  rep(i,n){
    for(int bit=0;bit<(1<<5);bit++){
      ll tmp=0;
      for(int j=0;j<5;j++){
        if(bit&(1<<j)){
          tmp+=G[i][j];
        }
        else tmp-=G[i][j];
      }
      A[bit][i]=max(A[bit][i],tmp);
    }
  }
  
  vector<vector<ll>> L(32,vector<ll>(n,-INF)),R(32,vector<ll>(n,-INF));
  rep(i,32){
    L[i][0]=A[i][0];
    R[i][n-1]=A[i][n-1];
  }
  rep(i,32){
    for(int j=1;j<n;j++) L[i][j]=max(L[i][j-1],A[i][j]);
    for(int j=n-2;j>=0;j--) R[i][j]=max(R[i][j+1],A[i][j]);
  }
  
  rep(i,n){
    ll ma=-INF;
    if(i==0){
      rep(j,32){
        ma=max(ma,A[j][i]+R[31-j][i+1]);
      }
    }
    else if(i==n-1){
      rep(j,32){
        ma=max(ma,A[j][i]+L[31-j][i-1]);
      }
    }
    else{
      rep(j,32){
        ma=max(ma,A[j][i]+max(L[31-j][i-1],R[31-j][i+1]));
      }
    }
    cout<<ma<<'\n';
  }
    
  return 0;
}
0