結果

問題 No.1028 闇討ち
ユーザー 👑 rin204rin204
提出日時 2023-07-04 23:52:20
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,827 ms / 2,000 ms
コード長 920 bytes
コンパイル時間 4,075 ms
コンパイル使用メモリ 266,320 KB
実行使用メモリ 7,160 KB
最終ジャッジ日時 2023-09-25 23:08:44
合計ジャッジ時間 22,739 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 19 ms
4,376 KB
testcase_10 AC 31 ms
4,380 KB
testcase_11 AC 210 ms
4,380 KB
testcase_12 AC 1,686 ms
6,724 KB
testcase_13 AC 1,651 ms
6,644 KB
testcase_14 AC 688 ms
5,112 KB
testcase_15 AC 135 ms
4,376 KB
testcase_16 AC 1,812 ms
7,072 KB
testcase_17 AC 1,819 ms
7,048 KB
testcase_18 AC 1,820 ms
6,984 KB
testcase_19 AC 1,803 ms
7,160 KB
testcase_20 AC 1,827 ms
6,944 KB
testcase_21 AC 1,822 ms
7,036 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