結果

問題 No.1028 闇討ち
ユーザー ngtkanangtkana
提出日時 2020-04-17 21:56:15
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 953 bytes
コンパイル時間 2,391 ms
コンパイル使用メモリ 203,720 KB
実行使用メモリ 20,992 KB
最終ジャッジ日時 2024-04-14 14:07:02
合計ジャッジ時間 4,611 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 AC 26 ms
7,552 KB
testcase_12 AC 112 ms
20,352 KB
testcase_13 AC 112 ms
20,224 KB
testcase_14 AC 62 ms
15,744 KB
testcase_15 AC 20 ms
6,940 KB
testcase_16 AC 118 ms
20,736 KB
testcase_17 AC 118 ms
20,992 KB
testcase_18 AC 118 ms
20,992 KB
testcase_19 AC 121 ms
20,992 KB
testcase_20 AC 118 ms
20,608 KB
testcase_21 AC 123 ms
20,992 KB
権限があれば一括ダウンロードができます

ソースコード

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<std::pair<lint,lint>>>a(n);
    for(lint i=0;i<n;i++)for(lint j=0;j<n;j++){
        lint x;std::cin>>x;x--;
        a.at(x).emplace_back(i,j);
    }
    lint ans=0;
    for(auto&&v:a){
        std::vector<lint>b(2*n);
        for(auto[i,j]:v){
            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(auto[i,j]:v){
            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