結果

問題 No.1028 闇討ち
ユーザー RhoRho
提出日時 2020-03-28 19:36:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 247 ms / 2,000 ms
コード長 1,087 bytes
コンパイル時間 1,638 ms
コンパイル使用メモリ 172,332 KB
実行使用メモリ 28,952 KB
最終ジャッジ日時 2023-09-15 23:13:21
合計ジャッジ時間 5,254 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 11 ms
5,460 KB
testcase_10 AC 16 ms
6,080 KB
testcase_11 AC 56 ms
11,352 KB
testcase_12 AC 231 ms
27,976 KB
testcase_13 AC 229 ms
27,580 KB
testcase_14 AC 128 ms
21,332 KB
testcase_15 AC 42 ms
10,836 KB
testcase_16 AC 243 ms
28,952 KB
testcase_17 AC 244 ms
28,788 KB
testcase_18 AC 244 ms
28,744 KB
testcase_19 AC 245 ms
28,576 KB
testcase_20 AC 244 ms
28,664 KB
testcase_21 AC 247 ms
28,724 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:51:39: 警告: ‘pos2’ may be used uninitialized [-Wmaybe-uninitialized]
   51 |                         ans += max(abs(x - pos2), y);
      |                                    ~~~^~~~~~~~~~
main.cpp:42:21: 備考: ‘pos2’ はここで定義されています
   42 |                 int pos2, mx = 1e17;
      |                     ^~~~

ソースコード

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;
	assert(1 <= n&&n <= 1000);
	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);
		vector<int>imos1(n + 1), imos2(n + 1);
		assert(pos[I].size() == n);
		rep(j, n) {
			int x = pos[I][j].first, y = pos[I][j].second;
			imos1[0]++;
			imos1[max(x - y,0ll)]--;
			imos2[min(x + y + 1,n)]++;
			imos2[n]--;
		}
		rep(i, n) {
			imos1[i + 1] += imos1[i];
			imos2[i + 1] += imos2[i];
		}
		for (int i = n; i > 0; i--)imos1[i - 1] += imos1[i];
		rep(i, n)imos2[i + 1] += imos2[i];
		rep(i, n)imos[i] = imos1[i] + imos2[i];
		
		int pos2, mx = 1e17;
		rep(i, n) {
			if (mx > imos[i]) {
				mx = imos[i]; pos2 = i;
			}
		}

		rep(j, n) {
			int x = pos[I][j].first, y = pos[I][j].second;
			ans += max(abs(x - pos2), y);
		}
	}
	cout << ans << endl;
}
0