Submission #880555

# Submission time Handle Problem Language Result Execution time Memory
880555 2023-11-29T16:15:24 Z edogawa_something Ideal city (IOI12_city) C++17
32 / 100
1000 ms 4956 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/=2;
  ans%=mod;
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 2 ms 2648 KB Output is correct
10 Correct 2 ms 2612 KB Output is correct
11 Correct 2 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 2912 KB Output is correct
2 Correct 23 ms 2908 KB Output is correct
3 Correct 50 ms 2952 KB Output is correct
4 Correct 53 ms 2964 KB Output is correct
5 Correct 88 ms 2908 KB Output is correct
6 Correct 108 ms 2908 KB Output is correct
7 Correct 88 ms 3036 KB Output is correct
8 Correct 91 ms 2904 KB Output is correct
9 Correct 91 ms 2908 KB Output is correct
10 Correct 88 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1046 ms 4948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1054 ms 4956 KB Time limit exceeded
2 Halted 0 ms 0 KB -