結果

問題 No.77 レンガのピラミッド
ユーザー ngtkanangtkana
提出日時 2020-03-26 09:59:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 852 bytes
コンパイル時間 3,256 ms
コンパイル使用メモリ 204,112 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-30 12:10:34
合計ジャッジ時間 3,599 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using lint=long long;
void cmn(lint&x,lint y){if(x>y)x=y;}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<lint>a(n);
    for(lint&x:a)std::cin>>x;
    lint sum=std::accumulate(a.begin(),a.end(),0ll);
    lint h=std::sqrt(2*sum);
    if(sum<h*(h+1)/2)h--;
    cmn(h,(n+1)/2);
    lint w=h*2-1;
    std::vector<lint>b(n);
    for(lint i=0;i<w;i++){
        b.at(i)=std::max(0ll,h-std::abs(i-h+1));
    }
    lint ans=std::numeric_limits<lint>::max();
    for(lint i=w;i<=n;i++){
        lint now=0;
        for(lint j=0;j<n;j++){
            now+=std::min(a.at(j),b.at(j));
        }
        cmn(ans,now);
        std::rotate(b.begin(),b.end()-1,b.end());
    }
    std::cout<<sum-ans<<'\n';
}
0