結果

問題 No.1028 闇討ち
ユーザー 👑 jupirojupiro
提出日時 2020-04-17 21:49:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,287 ms / 2,000 ms
コード長 1,590 bytes
コンパイル時間 1,124 ms
コンパイル使用メモリ 119,148 KB
実行使用メモリ 16,512 KB
最終ジャッジ日時 2024-04-14 13:28:41
合計ジャッジ時間 13,278 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 16 ms
6,940 KB
testcase_10 AC 25 ms
6,940 KB
testcase_11 AC 157 ms
6,944 KB
testcase_12 AC 1,177 ms
15,616 KB
testcase_13 AC 1,162 ms
15,872 KB
testcase_14 AC 493 ms
11,648 KB
testcase_15 AC 102 ms
6,940 KB
testcase_16 AC 1,285 ms
16,384 KB
testcase_17 AC 1,284 ms
16,256 KB
testcase_18 AC 1,287 ms
16,384 KB
testcase_19 AC 1,285 ms
16,256 KB
testcase_20 AC 1,287 ms
16,128 KB
testcase_21 AC 1,286 ms
16,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	int N; scanf("%d", &N);
	vector<vector<int>> a(N, vector<int>(N)); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) scanf("%d", &a[i][j]), a[i][j]--;

	vector<vector<int>> H(N);
	vector<vector<int>> W(N);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			H[a[i][j]].push_back(i);
			W[a[i][j]].push_back(j);
		}
	}

	ll res = 0;

	for (int i = 0; i < N; i++) {
		ll tmp = INF;
		for (int j = 0; j < N; j++) {
			ll tmp2 = 0;
			for (int k = 0; k < N; k++) {
				tmp2 += max(abs(H[i][k] - j), W[i][k]);
			}
			chmin(tmp, tmp2);
		}
		res += tmp;
	}
	cout << res << endl;
    return 0;
} 
0