結果
| 問題 | 
                            No.1028 闇討ち
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-04-17 23:14:26 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 646 bytes | 
| コンパイル時間 | 758 ms | 
| コンパイル使用メモリ | 68,460 KB | 
| 最終ジャッジ日時 | 2025-01-09 20:42:30 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 12 TLE * 8 | 
ソースコード
#include <iostream>
using namespace std;
int n, i, j, k;
int main(){
    cin >> n;
    int a[n][n];
    for(i = 0; i < n; i++){for(j = 0; j < n; j++){cin >> a[i][j];}}
    
    int ans[n], tmp[n];
    for(i = 0; i < n; i++){ans[i] = 1000000000;}
    
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){tmp[j] = 0;}
        for(j = 0; j < n; j++){
            for(k = 0; k < n; k++){
                tmp[a[k][j] - 1] += max(j, abs(i - k));
            }
        }
        
        for(j = 0; j < n; j++){ans[j] = min(tmp[j], ans[j]);}
    }    
    k = 0;
    for(i = 0; i < n; i++) {k += ans[i];}
    cout << k << endl;
    return 0;
}