結果

問題 No.1028 闇討ち
ユーザー knshnbknshnb
提出日時 2020-04-18 16:22:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,587 bytes
コンパイル時間 2,347 ms
コンパイル使用メモリ 201,380 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-14 20:59:22
合計ジャッジ時間 4,940 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 WA -
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 #

#define PROBLEM "https://yukicoder.me/problems/no/1028"

#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Apr 18 15:55:11 JST 2020
 **/

#define CALL_FROM_TEST
// #include "../../src/"
#undef CALL_FROM_TEST

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

signed main() {
    Int n;
    std::cin >> n;
    auto js = make_vec<Int>(n, n, -1);
    REP(i, n) REP(j, n) {
        Int x;
        std::cin >> x;
        js[x - 1][i] = j;
    }
    Int ans = 0;
    REP(idx, n) {
        auto f = [&](Int mid) {
            Int ret = 0;
            REP(i, n) { ret += std::max(std::abs(mid - i), js[idx][i]); }
            return ret;
        };
        Int l = 0, r = n;
        while (abs(l - r) > 2) {
            Int m1 = (2 * l + r) / 3;
            Int m2 = (l + 2 * r) / 3;
            if (f(m1) < f(m2))
                r = m2;
            else
                l = m1;
        }
        if (l + 1 < r && f(l + 1) < f(l)) l = l + 1;
        ans += f(l);
    }
    std::cout << ans << std::endl;
}
0