結果

問題 No.1028 闇討ち
ユーザー trineutrontrineutron
提出日時 2020-04-18 01:21:17
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 824 ms / 2,000 ms
コード長 734 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 35,236 KB
実行使用メモリ 9,684 KB
最終ジャッジ日時 2024-04-14 18:52:18
合計ジャッジ時間 8,489 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 13 ms
6,944 KB
testcase_10 AC 18 ms
6,940 KB
testcase_11 AC 109 ms
9,196 KB
testcase_12 AC 752 ms
9,544 KB
testcase_13 AC 740 ms
9,480 KB
testcase_14 AC 318 ms
8,596 KB
testcase_15 AC 70 ms
6,940 KB
testcase_16 AC 818 ms
9,648 KB
testcase_17 AC 810 ms
9,592 KB
testcase_18 AC 818 ms
9,684 KB
testcase_19 AC 821 ms
9,600 KB
testcase_20 AC 822 ms
9,652 KB
testcase_21 AC 824 ms
9,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <stdio.h>

int a[1000][1000];
int v[1000][1000];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%d", &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++) {
	    int d = v[i][0];
	    for (int j = 1; j < n; j++) {
	        if (v[i][j] < d) d = v[i][j];
	    }
		ans += d;
	}
	printf("%d\n", ans);
}
0