結果

問題 No.1028 闇討ち
ユーザー RhoRho
提出日時 2020-03-28 19:00:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 847 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 171,228 KB
実行使用メモリ 28,848 KB
最終ジャッジ日時 2023-09-15 23:11:16
合計ジャッジ時間 4,923 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 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"
#pragma warning(disable:4996)
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
int a[1005][1005];
vector<P>pos[1005];

signed main() {
	int n; cin >> n;

	rep(i, n) {
		rep(j, n) {
			cin >> a[i][j];
			a[i][j]--;
			pos[a[i][j]].push_back(P(i, j));
		}
	}

	int ans = 0;

	rep(i, n) {
		vector<int>imos(n + 1);
		assert(pos[i].size() == n);
		rep(j, n) {
			int x = pos[i][j].first, y = pos[i][j].second;
			imos[0]--;
			imos[max(x - y,0ll)]++;
			imos[min(x + y + 1,n)]++;
			imos[n]--;
		}
		rep(j, n)imos[j + 1] += imos[j];
		int pos2 = 0;
		rep(j, n-1) {
			if (imos[j] < 0 && imos[j + 1] >= 0) {
				pos2 = j + 1; break;
			}
		}
		rep(j, n) {
			int x = pos[i][j].first, y = pos[i][j].second;
			ans += max(abs(x - pos2), y);
		}
	}
	cout << ans << endl;
}
0