Submission #803189

# Submission time Handle Problem Language Result Execution time Memory
803189 2023-08-03T00:16:28 Z pavement Ideal city (IOI12_city) C++17
11 / 100
1000 ms 2016 KB
#include <bits/stdc++.h>
using namespace std;

#define mp make_pair

using ii = pair<int, int>;

int dist[100005], dx[] = {-1, 0, 0, 1}, dy[] = {0, -1, 1, 0};
bool vis[100005];
map<ii, int> mpp;
queue<ii> Q;

const int MOD = (int)1e9;

int DistanceSum(int N, int X[], int Y[]) {
	int ans = 0;
	for (int i = 0; i < N; i++) {
		mpp[mp(X[i], Y[i])] = i;
	}
	for (int i = 0; i < N; i++) {
		Q.emplace(X[i], Y[i]);
		for (int j = 0; j < N; j++) vis[j] = 0;
		vis[i] = 1;
		dist[i] = 0;
		while (!Q.empty()) {
			auto [x, y] = Q.front();
			Q.pop();
			for (int k = 0; k < 4; k++) {
				int nx = x + dx[k], ny = y + dy[k];
				if (mpp.find(mp(nx, ny)) != mpp.end()) {
					int idx = mpp[mp(nx, ny)];
					if (!vis[idx]) {
						vis[idx] = 1;
						dist[idx] = dist[mpp[mp(x, y)]] + 1;
						ans = (ans + dist[idx]) % MOD;
						Q.emplace(X[idx], Y[idx]);
					}
				}
			}
		}
	}
	return ans / 2;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 8 ms 212 KB Output is correct
7 Correct 9 ms 212 KB Output is correct
8 Correct 7 ms 212 KB Output is correct
9 Correct 10 ms 212 KB Output is correct
10 Correct 10 ms 340 KB Output is correct
11 Correct 10 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 408 ms 380 KB Output is correct
2 Correct 385 ms 384 KB Output is correct
3 Correct 920 ms 428 KB Output is correct
4 Correct 888 ms 432 KB Output is correct
5 Execution timed out 1080 ms 444 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1038 ms 1972 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 2016 KB Time limit exceeded
2 Halted 0 ms 0 KB -