結果

問題 No.1028 闇討ち
ユーザー 👑 rin204rin204
提出日時 2022-07-14 13:48:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,614 ms / 2,000 ms
コード長 920 bytes
コンパイル時間 3,178 ms
コンパイル使用メモリ 220,220 KB
実行使用メモリ 7,008 KB
最終ジャッジ日時 2023-09-08 03:51:33
合計ジャッジ時間 19,051 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 17 ms
4,376 KB
testcase_10 AC 28 ms
4,380 KB
testcase_11 AC 186 ms
4,384 KB
testcase_12 AC 1,425 ms
6,644 KB
testcase_13 AC 1,388 ms
6,684 KB
testcase_14 AC 584 ms
5,100 KB
testcase_15 AC 116 ms
4,380 KB
testcase_16 AC 1,564 ms
7,008 KB
testcase_17 AC 1,608 ms
6,948 KB
testcase_18 AC 1,614 ms
6,960 KB
testcase_19 AC 1,600 ms
7,004 KB
testcase_20 AC 1,597 ms
6,952 KB
testcase_21 AC 1,602 ms
7,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
//#include<atcoder/lazysegtree>
using namespace std;
//using namespace atcoder;

void solve(){
    int n;
    cin >> n;
    vector<vector<int>> dp(n, vector<int>(n, 0));
    int a;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> a;
            a--;
            for(int k = 0; k < n; k++){
                int ii = abs(k - i);
                if(ii <= j) dp[a][k] += j;
                else dp[a][k] += ii;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        int mi = n * n;
        for(int j = 0; j < n; j++){
            if(dp[i][j] < mi) mi = dp[i][j];
        }
        ans += mi;
    }
    cout << ans << "\n";

}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int t;
    t = 1;
    //cin >> t;
    while(t--) solve();
}
0