Submission #121879

# Submission time Handle Problem Language Result Execution time Memory
121879 2019-06-27T07:07:36 Z TuGSGeReL Ideal city (IOI12_city) C++14
23 / 100
64 ms 63704 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back()
#define ss second
#define ff first
#define mt make_tuple
#define pof pop_front()
#define fbo find_by_order
#define ook order_of_key
#define lb lower_bound
#define ub upper_bound
#define inbuf_len 1 << 16
#define outbuf_len 1 << 16

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
using pll = pair <ll, ll>;
using pii = pair <int, int>;

ll cx[100001], cy[100001], mod = 1e9, dist[2001][2001], grd[2002][2002], h[4] = {0, 0, -1, 1}, v[4] = {-1, 1, 0, 0}, ans;

int DistanceSum(int n, int *x, int *y) {
	int mnx = INT_MAX, mny = INT_MAX;
	
	for (int i = 0; i < n; i++)
	{
		mnx = min(mnx, x[i]);
		mny = min(mny, y[i]);
	}
	
	for (int i = 0; i < n; i++)
	{
		x[i] -= mnx;
		y[i] -= mny;
	}
	
	if ( n <= 2000 )
	{
		
		for (int i = 0; i < n; i++)
			grd[x[i]][y[i]] = i + 1;
		
		memset(dist, -1, sizeof dist);
		for (int i = 0; i < n; i++)
		{
			queue<pair <pii, pii> > q;
			q.push(mp(mp(x[i], y[i]), mp(-1, -1)));
			dist[i + 1][i + 1] = 0;
			
			while (!q.empty())
			{
				int u = q.front().ff.ff, ve = q.front().ff.ss, pru = q.front().ss.ff, prv = q.front().ss.ss;
				q.pop();
				
				for (int j = 0; j < 4; j++)
				{
					if ( u + v[i] >= 0 && ve + h[i] >= 0 && grd[u + v[i]][ve + h[i]] && (u + v[i] != pru || ve + h[i] != prv) )
					{
						dist[i + 1][grd[u + v[i]][ve + v[i]]] = dist[u][ve] + 1;
						q.push(mp(mp(u + v[i], ve + h[i]), mp(u, ve)));
					}
				}
			}
			
			for (int j = i + 1; j < n; j++)
			{
				ans = (ans + dist[i + 1][j + 1]) % mod;
			}
		}
	} else {
		for (int i = 0; i < n; i++)
		{
			cx[x[i]]++;
			cy[y[i]]++;
		}
		
		ll sx = 0, sy = 0, ssx = 0, ssy = 0;
		
		for (int i = n; i >= 0; i--)
		{
			ans = (ans + ((ssx * cx[i]) % mod + (cy[i] * ssy) % mod) % mod) % mod;
			sy = (sy + cy[i]) % mod;
			sx = (sx + cx[i]) % mod;
			ssx = (ssx + sx) % mod;
			ssy = (ssy + sy) % mod;
		}
		
	}
		return ans;
}
//
//int main() {
//  int tmp;
//
//  int N, i;
//  scanf("%d", &N);
//
//  int sq_x[100001], sq_y[100001];
//  for (i = 0; i < N; i++) {
//    tmp = scanf("%d %d", &sq_x[i], &sq_y[i]);
//  }
//
//  int ds = DistanceSum(N, sq_x, sq_y);
//  printf("%d\n", ds);
//
//  return 0;
//
//}
# Verdict Execution time Memory Grader output
1 Runtime error 62 ms 63224 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 64 ms 63704 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 Correct 7 ms 640 KB Output is correct
2 Correct 7 ms 640 KB Output is correct
3 Correct 15 ms 1152 KB Output is correct
4 Correct 14 ms 1152 KB Output is correct
5 Correct 30 ms 2040 KB Output is correct
6 Correct 29 ms 1920 KB Output is correct
7 Correct 36 ms 2040 KB Output is correct
8 Correct 28 ms 1912 KB Output is correct
9 Correct 28 ms 1920 KB Output is correct
10 Correct 28 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -