結果

問題 No.1028 闇討ち
ユーザー trineutrontrineutron
提出日時 2020-04-18 01:17:20
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 728 bytes
コンパイル時間 1,211 ms
コンパイル使用メモリ 34,964 KB
実行使用メモリ 9,836 KB
最終ジャッジ日時 2024-04-14 18:46:51
合計ジャッジ時間 8,344 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

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