結果
| 問題 |
No.1028 闇討ち
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-17 22:48:10 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,169 ms / 2,000 ms |
| コード長 | 866 bytes |
| コンパイル時間 | 914 ms |
| コンパイル使用メモリ | 128,768 KB |
| 実行使用メモリ | 12,288 KB |
| 最終ジャッジ日時 | 2024-11-30 17:35:26 |
| 合計ジャッジ時間 | 12,246 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include <iostream>
#include <vector>
#include <queue>
#include <numeric>
#include <tuple>
#include <climits>
using namespace std;
using P = pair<int,int>;
using TP = tuple<int,int,int>;
const vector dx = {+0,+1,+1,+0,+1};
const vector dy = {+1,+1,+0,-1,-1};
queue<TP> q;
int main() {
int n;
cin >> n;
vector<vector<P>> a(n);
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
int ai;
cin >> ai;
a[ai-1].emplace_back(i,j);
}
}
vector<int> ans(n, INT_MAX);
for (int i=0; i<n; i++) {
vector<int> tmp(n, 0);
for (int j=0; j<n; j++) {
for (auto [y,x] : a[j]) {
tmp[j] += max(x, abs(y-i));
}
}
for (int j=0; j<n; j++) ans[j] = min(ans[j], tmp[j]);
}
cout << accumulate(ans.begin(), ans.end(), 0) << endl;
}