結果

問題 No.1028 闇討ち
ユーザー ngtkanangtkana
提出日時 2020-04-17 21:52:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 986 bytes
コンパイル時間 3,944 ms
コンパイル使用メモリ 201,544 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-14 13:31:42
合計ジャッジ時間 4,632 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
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<std::vector<lint>>a(n,std::vector<lint>(n));
    for(lint i=0;i<n;i++)for(lint j=0;j<n;j++){
        lint x;std::cin>>x;x--;
        a.at(x).at(i)=j;
    }
    lint ans=0;
    for(auto&&v:a){
        std::vector<lint>b(2*n);
        for(lint i=0;i<n;i++){
            lint j=v.at(i);
            for(lint k:{n+i-j+1,n+i+j+1})if(k<2*n)b.at(k)++;
        }
        b.at(0)=-n;
        std::partial_sum(ALL(b),b.begin());
        b.at(0)=0;
        for(lint i=0;i<n;i++){
            b.at(0)+=n+i;
        }
        std::partial_sum(ALL(b),b.begin());
        ans+=*std::min_element(b.begin()+n,b.begin()+2*n);
    }
    std::cout<<ans<<'\n';
}
0