Submission #810566

# Submission time Handle Problem Language Result Execution time Memory
810566 2023-08-06T11:18:24 Z YassirSalama Ideal city (IOI12_city) C++17
32 / 100
1000 ms 6356 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define OVL(v,s) for(auto x:v) cout<<x<<s;cout<<endl;
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define pb push_back
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#define endl "\n"
#define mod 1000000007
const ll INF=1e18;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int DistanceSum(int N, int *X, int *Y) {
  vector<set<int>> v(N);
  map<pair<int,int>,int> mp;
  for(int i=0;i<N;i++) mp[{X[i],Y[i]}]=i;
  for(int i=0;i<N;i++){
    for(int x=0;x<4;x++){
      int ni=X[i]+dx[x];
      int nj=Y[i]+dy[x];
      if(mp.find({ni,nj})==mp.end()) continue;
      v[i].insert((*mp.find({ni,nj})).second);
      v[(*mp.find({ni,nj})).second].insert(i);
     }
  }
  int ans=0;
  for(int i=0;i<N;i++) {
    bool visited[N];
    memset(visited,false,sizeof(visited));
    queue<pair<int,int>> q;
    q.push({i,0});
    while(!q.empty()){
        pair<int,int> p=q.front();
        q.pop();
        if(visited[p.F]) continue;
        visited[p.F]=true;
        ans+=p.S;
        for(auto x:v[p.F]){
            if(!visited[x]) q.push({x,p.S+1});
        }
    }
  }
  return ans/2;

}

#ifdef IOI

#define inbuf_len 1 << 16
#define outbuf_len 1 << 16

int DistanceSum(int N, int *X, int *Y);

int main() {
  int tmp;

  /* Set input and output buffering */
  char *inbuf, *outbuf;
  inbuf = (char*) malloc(inbuf_len * sizeof(char));
  outbuf = (char*) malloc(outbuf_len * sizeof(char));
  tmp = setvbuf(stdin, inbuf, _IOFBF, inbuf_len);
  assert(tmp == 0);
  tmp = setvbuf(stdout, outbuf, _IOFBF, outbuf_len);
  assert(tmp == 0);

  int N, i;
  tmp = scanf("%d", &N);
  assert(tmp == 1);
  int *sq_x, *sq_y;
  sq_x = (int*) malloc(N * sizeof(int));
  sq_y = (int*) malloc(N * sizeof(int));
  for (i = 0; i < N; i++) {
    tmp = scanf("%d %d", &sq_x[i], &sq_y[i]);
    assert(tmp == 2);
  }
  int ds = DistanceSum(N, sq_x, sq_y);
  printf("%d\n", ds);

  return 0;

}

#endif
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 468 KB Output is correct
2 Correct 37 ms 564 KB Output is correct
3 Correct 79 ms 644 KB Output is correct
4 Correct 88 ms 688 KB Output is correct
5 Correct 122 ms 772 KB Output is correct
6 Correct 191 ms 864 KB Output is correct
7 Correct 126 ms 776 KB Output is correct
8 Correct 183 ms 860 KB Output is correct
9 Correct 201 ms 872 KB Output is correct
10 Correct 194 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 6356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1057 ms 4940 KB Time limit exceeded
2 Halted 0 ms 0 KB -