Submission #362960

# Submission time Handle Problem Language Result Execution time Memory
362960 2021-02-05T01:09:30 Z 8e7 Ideal city (IOI12_city) C++14
32 / 100
130 ms 3436 KB
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <set>
#include <queue>
#define ll long long
#define maxn 100005
#define mod 1000000000
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
vector<int> adj[maxn];
vector<pii> a;

int dis[maxn];
bool found[maxn];

int DistanceSum(int N, int *X, int *Y) {
	ll ans = 0;
	for (int i = 0;i < N;i++) {
		a.push_back(make_pair(X[i], Y[i]));
	}
	sort(a.begin(), a.end());
	if (N <= 2000) {
		for (int i = 0;i < N;i++) {
			for (int k = 0;k < 4;k++) {
				pii ne = make_pair(a[i].ff + dir[k][0], a[i].ss + dir[k][1]);
				int id = lower_bound(a.begin(), a.end(), ne) - a.begin();
				if (id < N && a[id] == ne) {
					adj[i].push_back(id);
					adj[id].push_back(i);
				}
			}
		}

		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) found[j] = 0, dis[j] = 0;
			queue<int> que;
			que.push(i);
			found[i] = 1;
			while (que.size()) {
				int cur = que.front();
				que.pop();
				ans += dis[cur];
				for (int v:adj[cur]) {
					if (!found[v]) {
						dis[v] = dis[cur] + 1;
						que.push(v);
						found[v] = 1;
					}
				}
			}
		}
		return int((ans / 2) % mod);
	} else {
		return 7122;
	}
}
/*
int main() {
	io
	int n;
	cin >> n;
	int x[n], y[n];
	for (int i = 0;i < n;i++) cin >> x[i];
	for (int i = 0;i <n ;i++) cin >> y[i];
	cout << DistanceSum(n, x, y);
}
/*
11
2 2 3 3 4 4 4 4 5 5 5
5 6 3 6 3 4 5 6 3 4 6
 */

Compilation message

city.cpp:75:1: warning: "/*" within comment [-Wcomment]
   75 | /*
      |
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 3 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 3 ms 2668 KB Output is correct
7 Correct 3 ms 2668 KB Output is correct
8 Correct 3 ms 2668 KB Output is correct
9 Correct 3 ms 2668 KB Output is correct
10 Correct 3 ms 2796 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 2796 KB Output is correct
2 Correct 33 ms 2796 KB Output is correct
3 Correct 75 ms 2848 KB Output is correct
4 Correct 73 ms 2796 KB Output is correct
5 Correct 130 ms 2816 KB Output is correct
6 Correct 113 ms 2892 KB Output is correct
7 Correct 128 ms 2796 KB Output is correct
8 Correct 127 ms 2924 KB Output is correct
9 Correct 123 ms 2796 KB Output is correct
10 Correct 117 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 3436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 3436 KB Output isn't correct
2 Halted 0 ms 0 KB -