Submission #423436

#TimeUsernameProblemLanguageResultExecution timeMemory
423436Theo830Ideal city (IOI12_city)C++17
11 / 100
1089 ms1996 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<long long,long long>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
ll dx[4] = {0,0,1,-1};
ll dy[4] = {1,-1,0,0};
int DistanceSum(int N, int *X, int *Y){
    map<ii,ll>mp;
    ll n = N;
    f(i,0,n){
        mp[ii(X[i],Y[i])] = i;
    }
    ll ans = 0;
    f(i,0,n){
        queue<ii>q;
        bool v[n] = {0};
        v[i] = 1;
        ll dist[n] = {0};
        q.push(ii(X[i],Y[i]));
        while(!q.empty()){
            ii f = q.front();
            q.pop();
            f(j,0,4){
                ll x = f.F + dx[j],y = f.S + dy[j];
                if(mp.count(ii(x,y))){
                    ll pos = mp[ii(x,y)];
                    if(!v[pos]){
                        v[pos] = 1;
                        q.push(ii(x,y));
                        dist[pos] = dist[mp[f]] + 1;
                        if(pos > i){
                            ans += dist[pos];
                            ans %= INF;
                        }
                    }
                }
            }
        }
    }
    return ans;
}
/*
#define inbuf_len 1 << 16
#define outbuf_len 1 << 16

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

int main() {
  int tmp;
  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;

}
*/
/*
11
2 5
2 6
3 3
3 6
4 3
4 4
4 5
4 6
5 3
5 4
5 6
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...