Submission #880550

# Submission time Handle Problem Language Result Execution time Memory
880550 2023-11-29T16:08:24 Z edogawa_something Ideal city (IOI12_city) C++17
0 / 100
1000 ms 5196 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
const ll M=1e5+6;
const ll mod=1e9;
ll n;
map<pii,ll>mp;
bool vis[M];
vii v[M];
ll bfs(ll x){
  for(int i=0;i<n;i++)
  vis[i]=0;
  queue<pii>q;
  q.push({0,x});
  ll res=0;
  while(!q.empty()){
    pii p=q.front();
    q.pop();
    if(vis[p.S])
    continue;
    res+=p.F;
    vis[p.S]=1;
    for(auto it:v[p.S]){
      if(!vis[it])
      q.push({p.F+1,it});
    }
  }
  return res;
}
int DistanceSum(int N, int *X, int *Y) {
  n=N;
  for(int i=0;i<n;i++){
    mp[{X[i],Y[i]}]=i+1;
  }
  for(auto &it:mp){
    for(ll i=0;i<4;i++){
      if(mp.find({it.F.F+dx[i],it.F.S+dy[i]})!=mp.end())
      v[it.S].pb(mp[{it.F.F+dx[i],it.F.S+dy[i]}]);
    }
  }
  ll ans=0;
  for(int i=1;i<=n;i++){
    ans+=bfs(i);
    ans%=mod;
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 2908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1065 ms 5196 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1053 ms 4956 KB Time limit exceeded
2 Halted 0 ms 0 KB -