답안 #38115

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
38115 2018-01-01T10:32:53 Z funcsr 이상적인 도시 (IOI12_city) C++14
34 / 100
119 ms 38120 KB
#include <iostream>
#include <vector>
#include <set>
#include <cassert>
#include <queue>
#include <map>
#include <algorithm>
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(xs) xs.begin(), xs.end()
#define pb push_back
#define _1 first
#define _2 second
#define INF 1145141919
#define MOD 1000000000
using namespace std;
int DX[4] = {-1, 0, 1, 0};
int DY[4] = {0, -1, 0, 1};

typedef pair<int, int> P;
int mp[2010][2010];
int D[2000][2000];

int count(vector<P> seq) {
  sort(all(seq));
  int all = 0, sum = 0, ret = 0, last = seq[0]._1;
  for (P p : seq) all += p._2;
  for (P p : seq) {
    if (last != p._1) {
      ret = (ret + 1LL*(p._1-last)*((1LL*sum*(all-sum)) % MOD)) % MOD;
      last = p._1;
    }
    sum += p._2;
  }
  return ret;
}

int DistanceSum(int N, int *X, int *Y) {
  if (N < 2000) {
    int mx = *min_element(X, X+N), my = *min_element(Y, Y+N);
    mx -= 5, my -= 5;
    rep(i, N) X[i] -= mx, Y[i] -= my;
    rep(i, 2010) rep(j, 2010) mp[i][j] = -1;
    rep(i, N) mp[X[i]][Y[i]] = i;
    rep(i, N) rep(j, N) D[i][j] = INF;
    rep(s, N) {
      queue<int> q;
      q.push(s);
      D[s][s] = 0;
      while (!q.empty()) {
        int x = q.front();
        q.pop();
        rep(k, 4) {
          int t = mp[X[x]+DX[k]][Y[x]+DY[k]];
          if (t != -1 && D[s][t] == INF) {
            D[s][t] = D[s][x]+1;
            q.push(t);
          }
        }
      }
    }
    int s = 0;
    rep(i, N) rep(j, i) s = (s + D[i][j]) % MOD;
    return s;
  }
  else {
    vector<P> xs, ys;
    rep(i, N) {
      xs.pb(P(X[i], 1));
      ys.pb(P(Y[i], 1));
    }
    int s = (count(xs) + count(ys)) % MOD;
    return s;
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 33564 KB Output is correct
2 Correct 0 ms 33564 KB Output is correct
3 Correct 6 ms 33564 KB Output is correct
4 Correct 0 ms 33564 KB Output is correct
5 Correct 6 ms 33564 KB Output is correct
6 Correct 6 ms 33564 KB Output is correct
7 Correct 6 ms 33564 KB Output is correct
8 Correct 3 ms 33564 KB Output is correct
9 Correct 3 ms 33564 KB Output is correct
10 Correct 3 ms 33564 KB Output is correct
11 Correct 0 ms 33564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 33564 KB Output is correct
2 Correct 36 ms 33564 KB Output is correct
3 Correct 119 ms 33564 KB Output is correct
4 Correct 96 ms 33564 KB Output is correct
5 Incorrect 0 ms 33696 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 34624 KB Output is correct
2 Correct 6 ms 34624 KB Output is correct
3 Correct 19 ms 35920 KB Output is correct
4 Correct 19 ms 35920 KB Output is correct
5 Correct 39 ms 38120 KB Output is correct
6 Correct 43 ms 38120 KB Output is correct
7 Correct 43 ms 38120 KB Output is correct
8 Correct 59 ms 38120 KB Output is correct
9 Correct 46 ms 38120 KB Output is correct
10 Correct 43 ms 38120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 34624 KB Output isn't correct
2 Halted 0 ms 0 KB -