結果

問題 No.1028 闇討ち
ユーザー t98slidert98slider
提出日時 2023-04-02 01:11:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 929 bytes
コンパイル時間 2,808 ms
コンパイル使用メモリ 173,212 KB
実行使用メモリ 11,172 KB
最終ジャッジ日時 2023-10-24 20:14:34
合計ジャッジ時間 5,346 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 5 ms
4,348 KB
testcase_10 AC 6 ms
4,348 KB
testcase_11 AC 21 ms
5,284 KB
testcase_12 AC 101 ms
10,644 KB
testcase_13 AC 98 ms
10,644 KB
testcase_14 AC 45 ms
7,212 KB
testcase_15 AC 16 ms
4,572 KB
testcase_16 AC 112 ms
11,172 KB
testcase_17 AC 112 ms
11,172 KB
testcase_18 AC 112 ms
11,172 KB
testcase_19 AC 112 ms
11,172 KB
testcase_20 AC 112 ms
11,172 KB
testcase_21 AC 111 ms
11,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> A(n, vector<int>(n)), B(n, vector<int>(n));
    vector<int> s(n), r(n), add(n);
    for(int y = 0; y < n; y++){
        for(int x = 0; x < n; x++){
            cin >> A[y][x];
            s[--A[y][x]] += x;
            r[x] += add[x];
            B[x][y] = r[x];
        }
        for(int x = 0; x <= y; x++) add[A[y - x][x]]++;
    }
    fill(r.begin(), r.end(), 0);
    fill(add.begin(), add.end(), 0);
    reverse(A.begin(), A.end());
    for(int y = 0; y < n; y++){
        for(int x = 0; x < n; x++){
            r[x] += add[x];
            B[x][n - 1 - y] += r[x] + s[x];
        }
        for(int x = 0; x <= y; x++) add[A[y - x][x]]++;
    }
    int ans = 0;
    for(int i = 0; i < n; i++) ans += *min_element(B[i].begin(), B[i].end());
    cout << ans << '\n';
}
0