結果

問題 No.1028 闇討ち
ユーザー yutasyutas
提出日時 2020-04-17 22:38:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,673 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 99,408 KB
実行使用メモリ 16,304 KB
最終ジャッジ日時 2024-04-14 14:56:34
合計ジャッジ時間 3,320 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

int N, A[1005][1005], start[1005];
vector <Pii> P[1005];

int Dist(int i1, int j1, int i2, int j2){
  int now = abs(i2 - i1);
  if (j1 - now <= j2 && j2 <= j1 + now){
    return now;
  }
  
  if (j2 < j1 - now){
    return now + (j1 - now - j2);
  }else{
    return now + (j2 - j1 - now);
  }
}

int main(){
  scanf("%d", &N);
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      scanf("%d", &A[i][j]);
      P[A[i][j]].push_back(make_pair(i, j));
    }
  }

  int ans = 0;
  for (int i = 1; i <= N; i++){
    fill(start, start + N + 1, 0);
    for (int j = 0; j < N; j++){
      int I = P[i][j].first, J = P[i][j].second;
      int s = max(I - J, 0), t = min(I + J, N) + 1;
      start[s]++; start[t]--;
    }
    
    for (int j = 1; j < N; j++){
      start[j] += start[j - 1];
    }
    
    int now = 0, sum = 0;
    for (int j = 0; j < N; j++){
      if (sum < start[j]){
        now = j; sum = start[j];
      }
    }
    
    for (int j = 0; j < N; j++){
      ans += Dist(now, 0, P[i][j].first, P[i][j].second);
    }
  }
  cout << ans << endl;

  return 0;
}
0