結果
| 問題 |
No.2261 Coffee
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2023-04-07 22:05:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 217 ms / 2,000 ms |
| コード長 | 1,251 bytes |
| コンパイル時間 | 2,110 ms |
| コンパイル使用メモリ | 199,120 KB |
| 最終ジャッジ日時 | 2025-02-12 01:26:02 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 |
ソースコード
#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;
}
umezo