結果

問題 No.1028 闇討ち
ユーザー hiroahiroa
提出日時 2020-04-18 08:49:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 819 bytes
コンパイル時間 1,526 ms
コンパイル使用メモリ 164,720 KB
実行使用メモリ 7,616 KB
最終ジャッジ日時 2024-04-14 20:26:27
合計ジャッジ時間 4,733 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,948 KB
testcase_09 AC 10 ms
6,944 KB
testcase_10 AC 13 ms
6,944 KB
testcase_11 AC 47 ms
6,940 KB
testcase_12 AC 191 ms
7,308 KB
testcase_13 AC 187 ms
7,320 KB
testcase_14 AC 107 ms
6,940 KB
testcase_15 AC 35 ms
6,944 KB
testcase_16 AC 210 ms
7,412 KB
testcase_17 AC 202 ms
7,508 KB
testcase_18 AC 211 ms
7,552 KB
testcase_19 AC 202 ms
7,540 KB
testcase_20 AC 197 ms
7,616 KB
testcase_21 AC 206 ms
7,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int b[2000],c[2000];
int d[2000][2];


int main() {
    int n;
    cin>>n;
    int a[n][n];
    rep(i,n){
        rep(j,n){
            cin>>a[i][j];
            a[i][j]--;
            b[a[i][j]]+=i+j-min(i,j);
            if(j-i<0) d[a[i][j]][1]++;
        }
    }

    rep(i,n) c[i]=b[i];

    rep(i,n){
        for(int j=0;i-j>=0;j++){
            d[a[i-j][j]][0]++;
        }
        rep(j,n){
            b[j]+=d[j][0]-d[j][1];
            c[j]=min(c[j],b[j]);
        }
        for(int j=0;i+j+1<n;j++){
            d[a[i+j+1][j]][1]--;
        }
    }

    int ans=0;
    rep(i,n) ans+=c[i];
    cout<<ans<<endl;

}

0