結果

問題 No.1028 闇討ち
ユーザー StrorkisStrorkis
提出日時 2020-04-18 00:23:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 499 ms / 2,000 ms
コード長 851 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 73,172 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-04-14 16:19:18
合計ジャッジ時間 6,173 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 12 ms
6,940 KB
testcase_10 AC 18 ms
6,940 KB
testcase_11 AC 79 ms
6,940 KB
testcase_12 AC 460 ms
7,296 KB
testcase_13 AC 457 ms
7,168 KB
testcase_14 AC 212 ms
6,944 KB
testcase_15 AC 56 ms
6,944 KB
testcase_16 AC 493 ms
7,296 KB
testcase_17 AC 493 ms
7,424 KB
testcase_18 AC 498 ms
7,552 KB
testcase_19 AC 499 ms
7,424 KB
testcase_20 AC 496 ms
7,424 KB
testcase_21 AC 498 ms
7,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

int main() {
    int N;
    std::cin >> N;

    std::vector<std::vector<int>> A(N, std::vector<int>(N));
    std::vector<int> b(N), c(N);

    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++) {
            std::cin >> A[i][j];
            A[i][j]--;
            b[A[i][j]] += std::max(i, j);
            c[A[i][j]] += std::max(i, j);
        }

    for (int k = 1; k < N; k++) {
        for (int i = 0; i < k; i++)
            for (int j = 0; j < k - i; j++)
                b[A[i][j]]++;

        for (int i = k; i < N; i++)
            for (int j = 0; j <= i - k; j++)
                b[A[i][j]]--;

        for (int i = 0; i < N; i++)
            c[i] = std::min(c[i], b[i]);
    }
          
    int ans = 0;
    for (int i = 0; i < N; i++)
        ans += c[i];
    std::cout << ans << "\n";
}
0