結果

問題 No.1028 闇討ち
ユーザー micheeeeell1001micheeeeell1001
提出日時 2020-04-17 22:34:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,575 bytes
コンパイル時間 2,980 ms
コンパイル使用メモリ 240,540 KB
実行使用メモリ 35,712 KB
最終ジャッジ日時 2024-04-14 14:52:30
合計ジャッジ時間 30,021 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 5 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 116 ms
6,944 KB
testcase_10 AC 169 ms
6,940 KB
testcase_11 AC 665 ms
10,880 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 AC 1,493 ms
23,168 KB
testcase_15 AC 491 ms
9,472 KB
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    vector graph(n, vector<ll>(n));
    rep(i,n)rep(j,n) cin >> graph[i][j];
    vector num(n, vector<Pll>());
    vector<ll> ave(n, 0LL);
    rep(i,n)rep(j,n){
        num[--graph[i][j]].emplace_back(Pll(i, j));
        ave[graph[i][j]] += i;
    }
    rep(i,n)ave[i] /= n;

    vector ans(n, vector<ll>(n, INF));
    ll ret = 0;
    rep(i,n){
        ll ans = INF;
        for(int j = -50; j <= 50; j++){
            ll temp = 0;
            if(j + ave[i] < 0 || j + ave[i] > n)continue;
            for(auto &p : num[i])temp += max(p.second, abs(p.first - j - ave[i]));
            chmin(ans, temp);
        }
        ret += ans;
    }

    cout << ret << endl;
}
0