結果

問題 No.1028 闇討ち
ユーザー RhoRho
提出日時 2020-04-18 00:33:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 795 ms / 2,000 ms
コード長 717 bytes
コンパイル時間 2,436 ms
コンパイル使用メモリ 181,160 KB
実行使用メモリ 11,472 KB
最終ジャッジ日時 2024-04-14 16:25:41
合計ジャッジ時間 10,415 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 12 ms
6,940 KB
testcase_10 AC 18 ms
8,576 KB
testcase_11 AC 101 ms
10,340 KB
testcase_12 AC 727 ms
11,232 KB
testcase_13 AC 718 ms
11,236 KB
testcase_14 AC 305 ms
10,348 KB
testcase_15 AC 67 ms
10,084 KB
testcase_16 AC 790 ms
11,252 KB
testcase_17 AC 793 ms
11,436 KB
testcase_18 AC 791 ms
11,472 KB
testcase_19 AC 795 ms
11,244 KB
testcase_20 AC 792 ms
11,456 KB
testcase_21 AC 795 ms
11,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include "bits/stdc++.h"
using namespace std;
int a[1005][1005];
int v[1005][1005];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
			a[i][j]--;
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				if (k > i + j) {
					v[a[i][j]][k] += k - i - j;
				}
				else if (k < i - j) {
					v[a[i][j]][k] += i - j - k;
				}
			}
		}
	}
	int ans = n * n * (n - 1) / 2;
	for (int i = 0; i < n; i++) {
		ans += *min_element(v[i], v[i]+n);
	}
	cout << ans << endl;
}
0