# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
38116 |
2018-01-01T10:33:40 Z |
funcsr |
Ideal city (IOI12_city) |
C++14 |
|
226 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;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
33564 KB |
Output is correct |
2 |
Correct |
0 ms |
33564 KB |
Output is correct |
3 |
Correct |
0 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 |
9 ms |
33564 KB |
Output is correct |
7 |
Correct |
9 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 |
6 ms |
33564 KB |
Output is correct |
11 |
Correct |
0 ms |
33564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
33564 KB |
Output is correct |
2 |
Correct |
39 ms |
33564 KB |
Output is correct |
3 |
Correct |
123 ms |
33564 KB |
Output is correct |
4 |
Correct |
106 ms |
33564 KB |
Output is correct |
5 |
Correct |
216 ms |
33564 KB |
Output is correct |
6 |
Correct |
153 ms |
33564 KB |
Output is correct |
7 |
Correct |
226 ms |
33564 KB |
Output is correct |
8 |
Correct |
146 ms |
33564 KB |
Output is correct |
9 |
Correct |
153 ms |
33564 KB |
Output is correct |
10 |
Correct |
136 ms |
33564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
34624 KB |
Output is correct |
2 |
Correct |
6 ms |
34624 KB |
Output is correct |
3 |
Correct |
33 ms |
35920 KB |
Output is correct |
4 |
Correct |
33 ms |
35920 KB |
Output is correct |
5 |
Correct |
49 ms |
38120 KB |
Output is correct |
6 |
Correct |
49 ms |
38120 KB |
Output is correct |
7 |
Correct |
46 ms |
38120 KB |
Output is correct |
8 |
Correct |
36 ms |
38120 KB |
Output is correct |
9 |
Correct |
43 ms |
38120 KB |
Output is correct |
10 |
Correct |
53 ms |
38120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
34624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |