Submission #234815

# Submission time Handle Problem Language Result Execution time Memory
234815 2020-05-25T17:54:38 Z crossing0ver Ideal city (IOI12_city) C++17
32 / 100
132 ms 6264 KB
#include<bits/stdc++.h>
using namespace std;
int vis[100001],x,y,t,help,d[1000001];
map<pair<int,int>,int> mp;
vector<int> adj[100000];
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
pair<int,int> A[100000];
int DistanceSum(int N, int *X, int *Y) {
  int sum = 0;
  for (int i = 0; i < N; i++) 
  	mp[{X[i],Y[i]}] = i + 1, A[i] = {X[i],Y[i]};
  for (int i = 0; i < N;i ++) {
  	for (int j = 0; j < 4; j++) {
  		x = X[i] + dx[j];
  		y = Y[i] + dy[j];
  		t = mp[{x,y}];
		if (t) adj[i].push_back(t-1);
	  } 
  }	 if ( N <= 5000) {
  for (int i = 0; i < N; i++) {
  	help++;
  	queue<int> q;
  	q.push(i);
  	d[i] = 0;
  	vis[i] = help;
  	while (!q.empty()) {
  		x = q.front();
  		q.pop();
  		sum += d[x];
  		for (int j:adj[x]) {
  			if (vis[j]  != help ) {
  				vis[j] = help;
  				d[j] = d[x] + 1;
  				q.push(j);
			  }
		  }
		  if (sum >= 1e9) sum -= 1e9;
	  }     }  	return sum/2;}
	  sort (A, A + N);
	  int s = 0;
	  for (int i = 0; i < N; i ++) {
	  	s += A[i].first;
	  	if (s >= 1e9) s-= 1e9;
	  	sum = (1ll*(i + 1)*A[i].first - s)%(1000000000);
	  	if (sum < 0) sum += 1e9;
	  	swap(A[i].first,A[i].second);
	  }
	  sort (A , A+ N);
	  s = 0;
	  for (int i = 0; i < N; i ++) {
	  	s += A[i].first;
	  	if (s >= 1e9) s-= 1e9;
	  	sum = (1ll*(i + 1)*A[i].first - s)%(1000000000);
	  	if (sum < 0) sum += 1e9;
	  	swap(A[i].first,A[i].second);
	  }
	
	  
	  
	  
	    return sum/2;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 7 ms 2688 KB Output is correct
7 Correct 7 ms 2688 KB Output is correct
8 Correct 7 ms 2688 KB Output is correct
9 Correct 7 ms 2688 KB Output is correct
10 Correct 7 ms 2688 KB Output is correct
11 Correct 7 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2816 KB Output is correct
2 Correct 32 ms 2816 KB Output is correct
3 Correct 67 ms 3004 KB Output is correct
4 Correct 67 ms 2944 KB Output is correct
5 Correct 121 ms 3104 KB Output is correct
6 Correct 118 ms 3064 KB Output is correct
7 Correct 132 ms 3072 KB Output is correct
8 Correct 113 ms 3240 KB Output is correct
9 Correct 109 ms 2944 KB Output is correct
10 Correct 103 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 5112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 6264 KB Output isn't correct
2 Halted 0 ms 0 KB -