Submission #316123

# Submission time Handle Problem Language Result Execution time Memory
316123 2020-10-25T10:32:38 Z amunduzbaev Ideal city (IOI12_city) C++14
11 / 100
7 ms 1024 KB
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=205, mod= 1e9;
int used[N][N], x[N], y[N], n, dist[N][N], pos[N][N], used1[N][N];
void Dijkstra(int xx,int yy){
	memset(used1, 0, sizeof(used1));
	queue<pair<int, pair<int,int>>> q;
	q.push({0,{xx,yy}});
	used1[xx][yy]=1;
	while(!q.empty()){
		auto point = q.front();
		q.pop();
		int d = point.first, 
		a = point.second.first, 
		b = point.second.second;
		for(int i=-1;i<=1;i+=2){
			int x1=a+i, y1=b;
			if(used[x1][y1] && !used1[x1][y1]) {
				used1[x1][y1] = 1;
				dist[pos[xx][yy]][pos[x1][y1]] = d+1;
				q.push({d+1,{x1,y1}});
			}
		}
		for(int i=-1;i<=1;i+=2){
			int x1=a, y1=b+i;
			if(used[x1][y1] && !used1[x1][y1]) {
				used1[x1][y1] = 1;
				dist[pos[xx][yy]][pos[x1][y1]] = d+1;
				q.push({d+1,{x1,y1}});
			}
		}
	}
}

int DistanceSum(int N, int *X, int *Y) {
	n=N;
	for(int i=0;i<n;i++){
		x[i]=X[i];
		y[i]=Y[i];
		used[x[i]][y[i]]=1;
		pos[x[i]][y[i]]=i;
	}
	for(int i=0;i<n;i++){
		Dijkstra(x[i], y[i]);
	}
	/*
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			cout<<i<<" "<<j<<" "<<dist[i][j]<<"\n";
		}
	}
	*/
	int ans=0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n;j++){
			ans += dist[i][j];
			ans %= mod;
		}
	}
 	return ans;
}

/*

11
2 5
2 6
3 3
3 6
4 3
4 4
4 5
4 6
5 3
5 4
5 6

*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 540 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 4 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 4 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -