結果

問題 No.1028 闇討ち
ユーザー kappybarkappybar
提出日時 2020-04-17 22:32:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 1,237 bytes
コンパイル時間 2,462 ms
コンパイル使用メモリ 168,588 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2024-04-14 14:49:43
合計ジャッジ時間 5,084 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 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,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 11 ms
6,940 KB
testcase_10 AC 14 ms
6,944 KB
testcase_11 AC 53 ms
6,940 KB
testcase_12 AC 220 ms
14,592 KB
testcase_13 AC 220 ms
14,592 KB
testcase_14 AC 117 ms
9,600 KB
testcase_15 AC 39 ms
6,940 KB
testcase_16 AC 235 ms
15,488 KB
testcase_17 AC 232 ms
15,232 KB
testcase_18 AC 233 ms
15,360 KB
testcase_19 AC 236 ms
15,360 KB
testcase_20 AC 238 ms
15,616 KB
testcase_21 AC 234 ms
15,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
const int INF = 1e9;
const int MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<vector<int>> maze(n,vector<int>(n,0));
    rep(i,n)rep(j,n) cin >> maze[i][j];
    
    vector<int> cnt(n,0);
    vector<vector<int>> down(n,vector<int>(n,0));
    vector<vector<int>> up(n,vector<int>(n,0));
    rep(i,n)rep(j,n){
        maze[i][j]--;
        int now = maze[i][j];
        cnt[now] += max(i,j);
        down[now][max(i-j,0)] ++;
        up[now][min(i+j,n-1)] ++;
    }
    /*
    rep(i,n)rep(j,n) cout << down[i][j] << " ";
    rep(i,n)rep(j,n) cout << up[i][j] << " ";
    rep(i,n) cout << cnt[i] <<" " ;
    */
    ll ans = 0;
    rep(i,n){
        ll res = cnt[i];
        ll now = cnt[i];
        int cnt_down = n,cnt_up = 0,cnt_pararell = 0;
        rep(j,n-1){
            cnt_down -= down[i][j];
            cnt_pararell += down[i][j];
            cnt_pararell -= up[i][j];
            cnt_up += up[i][j];
            now += cnt_up - cnt_down;
            res = min(res,now);
        }
        //cout <<res << endl;
        ans += res;
    }
    cout << ans << endl;
    return 0;
}
0