結果
問題 | No.1028 闇討ち |
ユーザー |
|
提出日時 | 2020-04-18 16:22:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,587 bytes |
コンパイル時間 | 2,321 ms |
コンパイル使用メモリ | 198,040 KB |
最終ジャッジ日時 | 2025-01-09 21:11:03 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 2 WA * 18 |
ソースコード
#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; }