Submission #577135

# Submission time Handle Problem Language Result Execution time Memory
577135 2022-06-14T07:25:47 Z Justin1 Ideal city (IOI12_city) C++14
11 / 100
1000 ms 5428 KB
#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define pii pair<int,int>
using namespace std;

vector<pii> dir = {{0,1},{1,0},{-1,0},{0,-1}};
map<pii,bool> ar,v;

ll bfs(int sx, int sy) {
	v.clear();
	ll ans = 0;
	queue<pair<pii,int>> nxt;
	nxt.push({{sx,sy},0});
	while (!nxt.empty()) {
		auto tmp = nxt.front();
		nxt.pop();
		if (v[tmp.f]) continue;
		v[tmp.f] = 1;
		ans += tmp.s;
		for (auto i : dir) {
			if (!v[{tmp.f.f+i.f, tmp.f.s+i.s}] && ar[{tmp.f.f+i.f, tmp.f.s+i.s}]) {
				nxt.push({{tmp.f.f+i.f, tmp.f.s+i.s}, tmp.s+1});
			}
		}
	}  
	return ans;
}

int DistanceSum(int N, int *X, int *Y) {
	ll ans = 0;
	for (int i = 0; i < N; i++) ar[{X[i],Y[i]}] = 1;
	for (int i = 0; i < N; i++) {
		ans += bfs(X[i],Y[i]);
	}
	return (ans/2) % 1'000'000'000;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 6 ms 212 KB Output is correct
5 Correct 6 ms 328 KB Output is correct
6 Correct 28 ms 340 KB Output is correct
7 Correct 24 ms 212 KB Output is correct
8 Correct 27 ms 304 KB Output is correct
9 Correct 23 ms 344 KB Output is correct
10 Correct 23 ms 212 KB Output is correct
11 Correct 23 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 843 ms 536 KB Output is correct
2 Correct 723 ms 492 KB Output is correct
3 Execution timed out 1084 ms 596 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 3384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 5428 KB Time limit exceeded
2 Halted 0 ms 0 KB -