結果

問題 No.1028 闇討ち
ユーザー hipopohipopo
提出日時 2020-04-21 14:33:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,986 ms / 2,000 ms
コード長 1,863 bytes
コンパイル時間 1,692 ms
コンパイル使用メモリ 140,592 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-16 23:57:24
合計ジャッジ時間 20,061 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 23 ms
5,376 KB
testcase_10 AC 38 ms
5,376 KB
testcase_11 AC 238 ms
5,376 KB
testcase_12 AC 1,812 ms
10,880 KB
testcase_13 AC 1,800 ms
10,880 KB
testcase_14 AC 765 ms
7,680 KB
testcase_15 AC 158 ms
5,376 KB
testcase_16 AC 1,966 ms
11,264 KB
testcase_17 AC 1,963 ms
11,392 KB
testcase_18 AC 1,982 ms
11,648 KB
testcase_19 AC 1,980 ms
11,520 KB
testcase_20 AC 1,986 ms
11,520 KB
testcase_21 AC 1,976 ms
11,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int main() {
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    cin >> a;
    
    vector<vector<int>> sum_dist(n, vector<int>(n));
    rep(i, n) rep(j, n) rep(k, n) sum_dist[a[i][j] - 1][k] += max(abs(i - k), j);
    
    int ans = 0;
    rep(id, n) {
        int min_sum = 1000000000;
        rep(i, n) chmin(min_sum, sum_dist[id][i]);
        ans += min_sum;
    }
    cout << ans << endl;
}
0