結果

問題 No.1028 闇討ち
ユーザー konchanksukonchanksu
提出日時 2020-04-20 20:46:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 930 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 72,164 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-16 00:53:26
合計ジャッジ時間 3,800 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 14 ms
5,376 KB
testcase_11 AC 51 ms
5,376 KB
testcase_12 AC 209 ms
10,880 KB
testcase_13 AC 207 ms
10,880 KB
testcase_14 AC 115 ms
7,424 KB
testcase_15 AC 38 ms
5,376 KB
testcase_16 AC 224 ms
11,392 KB
testcase_17 AC 225 ms
11,264 KB
testcase_18 AC 228 ms
11,520 KB
testcase_19 AC 229 ms
11,264 KB
testcase_20 AC 230 ms
11,392 KB
testcase_21 AC 232 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int n, i, j;

int main(){
    cin >> n;
    long long a[n][n];
    long long tmp[n], ans[n], g[n];
    long long answer = 0;
    
    for(i = 0; i < n; i++){for(j = 0; j < n; j++){cin >> a[i][j];} g[i] = 0; tmp[i] = 0;}
    for(i = 0;i < n; i++){
        for(j = 0; j < n; j++){
            g[a[i][j] - 1] += max(i, j);
            if(i >= j) tmp[a[i][j] - 1] -= 1;
        }
    }
    
    for(i = 0; i < n; i++) {ans[i] = g[i];}
    
    for(i = 1; i < n; i++){
        for(j = 0; j < n; j++){
            if(j - i + 1 == 0) tmp[a[i - 1][0] - 1] += 2;
            else tmp[a[j][abs(j - i + 1)] - 1] += 1;
        }
        
        for(j = 0; j < n; j++){
            g[j] += tmp[j];
            if(g[j] < ans[j]) ans[j] = g[j];
        }
    }
    
    for(i = 0; i < n; i++) answer += ans[i];
    cout << answer << endl;
        
    return 0;
}
0