結果

問題 No.1028 闇討ち
ユーザー QCFiumQCFium
提出日時 2020-04-17 21:38:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 862 bytes
コンパイル時間 1,714 ms
コンパイル使用メモリ 169,032 KB
実行使用メモリ 16,256 KB
最終ジャッジ日時 2024-04-14 13:18:38
合計ジャッジ時間 4,160 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,944 KB
testcase_04 AC 2 ms
6,944 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 #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a[n][n];
	for (auto &i : a) for (auto &j : i) j = ri() - 1;
	std::vector<std::pair<int, int> > cover[n];
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cover[a[i][j]].push_back({i, j});
	int64_t res = 0;
	for (int i = 0; i < n; i++) {
		int imos[n + 1];
		memset(imos, 0, sizeof(imos));
		for (auto j : cover[i]) {
			imos[0]++;
			imos[std::max(0, j.first - j.second)]--;
			imos[std::min(n, j.first + j.second + 1)]--;
			imos[n]++;
		}
		for (int j = 0; j < n; j++) imos[j + 1] += imos[j];
		int index = -1;
		for (int j = 0; j < n; j++) {
			if (j + 1 == n || imos[j] <= 0) {
				index = j;
				break;
			}
		}
		for (auto j : cover[i]) res += std::max(std::abs(j.first - index), j.second);
	}
	printf("%" PRId64 "\n", res);
	return 0;
}
0