Submission #423437

#TimeUsernameProblemLanguageResultExecution timeMemory
423437Theo830이상적인 도시 (IOI12_city)C++17
32 / 100
1083 ms1624 KiB
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
const ll INF = 1e9;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<int,int>
#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
vector<vector<ll> >adj;
int DistanceSum(int N, int *X, int *Y){
    ll n = N;
    adj.assign(n,vll());
    f(i,0,n){
        f(j,i+1,n){
            if(abs(X[i] - X[j]) + abs(Y[i] - Y[j]) == 1){
                adj[i].pb(j);
                adj[j].pb(i);
            }
        }
    }
    long long ans = 0;
    f(i,0,n){
        queue<ll>q;
        bool v[n] = {0};
        v[i] = 1;
        ll dist[n] = {0};
        q.push(i);
        while(!q.empty()){
            ll f = q.front();
            q.pop();
            for(auto x:adj[f]){
                if(!v[x]){
                    dist[x] = dist[f] + 1;
                    if(x > i){
                        ans += dist[x];
                        ans %= INF;
                    }
                    v[x] = 1;
                    q.push(x);
                }
            }
        }
    }
    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...