Submission #805039

# Submission time Handle Problem Language Result Execution time Memory
805039 2023-08-03T12:35:13 Z aymanrs Ideal city (IOI12_city) C++14
32 / 100
1000 ms 2912 KB
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9;
int DistanceSum(int N, int *X, int *Y){
	vector<int> g[N];
	map<pair<int, int>, int> s;
	for(int i = 0;i < N;i++){
		auto p = s.find({X[i]-1, Y[i]});
		if(p != s.end()) {
			g[i].push_back(p->second);
			g[p->second].push_back(i);
		}
		p = s.find({X[i]+1, Y[i]});
		if(p != s.end()) {
			g[i].push_back(p->second);
			g[p->second].push_back(i);
		}
		p = s.find({X[i], Y[i]-1});
		if(p != s.end()) {
			g[i].push_back(p->second);
			g[p->second].push_back(i);
		}
		p = s.find({X[i], Y[i]+1});
		if(p != s.end()) {
			g[i].push_back(p->second);
			g[p->second].push_back(i);
		}
		s[{X[i], Y[i]}] = i;
	}
	long long ans = 0;
	int D[N];
	for(int i = 0;i < N;i++){
    memset(D, 0, sizeof(D));
		queue<int> q;
		q.push(i);
		while(!q.empty()){
			int t = q.front();
			q.pop();
			for(int j : g[t]){
				if(j != i && !D[j]){
					D[j] = D[t]+1;
					if(j > i) ans = (ans+D[j])%MOD;
					q.push(j);
				}
			}
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 432 KB Output is correct
2 Correct 20 ms 340 KB Output is correct
3 Correct 47 ms 484 KB Output is correct
4 Correct 56 ms 500 KB Output is correct
5 Correct 74 ms 468 KB Output is correct
6 Correct 84 ms 576 KB Output is correct
7 Correct 84 ms 568 KB Output is correct
8 Correct 88 ms 568 KB Output is correct
9 Correct 84 ms 468 KB Output is correct
10 Correct 80 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 2900 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 2912 KB Time limit exceeded
2 Halted 0 ms 0 KB -