結果

問題 No.1028 闇討ち
ユーザー mfbgjsczmfbgjscz
提出日時 2020-04-17 22:06:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,100 bytes
コンパイル時間 2,121 ms
コンパイル使用メモリ 180,516 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-14 14:17:29
合計ジャッジ時間 6,672 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 220 ms
6,944 KB
testcase_10 AC 385 ms
6,940 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
int dy[8] = {1, 0, -1, 1, -1, 1 ,0 ,-1};
lli repow(lli n,lli k,lli m){
  if(k==0)return 1;
  if(m==0)return 0;
  else if(k%2==1)return repow(n,k-1,m)*n%m;
  else{
    lli temp=repow(n,k/2,m);
    return temp*temp%m;
  }
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  cin >> N;
  DV(G,int,N,N,0);
  DV(dist,int,N,N,-1);
  Vec(ans,lli,N,INF);
  rep(i,0,N)rep(j,0,N)cin >> G[i][j];
  rep(i,0,N){
    rep(j,0,N)rep(k,0,N)dist[j][k]=-1;
    queue<pint>que;
    que.push(pint(i,0));
    dist[i][0]=0;
    while(!que.empty()){
      auto v=que.front();que.pop();
      rep(j,0,8){
        auto nx=v.first+dx[j];
        auto ny=v.second+dy[j];
        if(nx>N-1||nx<0||ny>N-1||ny<0)continue;
        if(dist[nx][ny]!=-1)continue;
        dist[nx][ny]=dist[v.first][v.second]+1;
        que.push(pint(nx,ny));
      }
    }
    Vec(as,lli,N,0);
    rep(j,0,N)rep(k,0,N)as[G[j][k]-1]+=dist[j][k];
    rep(j,0,N)chmin(ans[j],as[j]);
  }
  rep(i,0,N)sum+=(ans[i]);
  Out(sum);
}
0