Submission #61396

# Submission time Handle Problem Language Result Execution time Memory
61396 2018-07-25T17:28:10 Z zetapi Ideal city (IOI12_city) C++14
23 / 100
65 ms 9424 KB
#include <bits/stdc++.h>
using namespace std;

#define pb  push_back
#define mp  make_pair
#define ll  long long
#define itr ::iterator 

typedef pair<ll,ll>  pii;

const ll MAX=1e6;
const ll mod=1e9;

vector<pii> vec;

ll pre[MAX];

ll cal(vector<ll> arr)
{
	ll sum=0,res=0;
	for(int A=1;A<arr.size();A++)
		pre[A]=(pre[A-1]+arr[A])%mod;
	for(int A=1;A<arr.size();A++)
	{
		res+=(sum*arr[A])%mod;
		res%=mod;
		sum+=pre[A];
		sum%=mod;
	}
	return res;
}

int DistanceSum(int N, int *X, int *Y) 
{
	vector<ll> arr;
	ll res=0,cur,lol;
	for(int A=0;A<N;A++)
		vec.pb(mp(X[A],Y[A]));
	sort(vec.begin(),vec.end());
	cur=0;
	arr.pb(0);
	while(cur<vec.size())
	{
		lol=vec[cur].second;
		while(cur+1<vec.size() and vec[cur+1].first==vec[cur].first)
			++cur;
		arr.pb(vec[cur].second-lol+1);
		++cur;
	}
	//for(auto A:arr)
	//	cout<<A<<" ha ha\n";
	res=cal(arr);
	for(int A=0;A<N;A++)
		swap(vec[A].first,vec[A].second);
	sort(vec.begin(),vec.end());
	arr.clear();
	arr.pb(0);
	cur=0;
	while(cur<vec.size())
	{
		lol=vec[cur].second;
		while(cur+1<vec.size() and vec[cur+1].first==vec[cur].first)
			++cur;
		arr.pb(vec[cur].second-lol+1);
		++cur;
	}
	//for(auto A:arr)
	//	cout<<A<<" o ";
	res+=cal(arr);
	res%=mod;
	return res;
}

/*signed main()
{
	ios_base::sync_with_stdio(false);

	int X[]={1,1,2,2};
	int Y[]={1,2,1,2};
	cout<<DistanceSum(4,X,Y);
	return 0;
}*/

Compilation message

city.cpp: In function 'long long int cal(std::vector<long long int>)':
city.cpp:21:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int A=1;A<arr.size();A++)
              ~^~~~~~~~~~~
city.cpp:23:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int A=1;A<arr.size();A++)
              ~^~~~~~~~~~~
city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:42:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(cur<vec.size())
        ~~~^~~~~~~~~~~
city.cpp:45:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(cur+1<vec.size() and vec[cur+1].first==vec[cur].first)
         ~~~~~^~~~~~~~~~~
city.cpp:59:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(cur<vec.size())
        ~~~^~~~~~~~~~~
city.cpp:62:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(cur+1<vec.size() and vec[cur+1].first==vec[cur].first)
         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1284 KB Output is correct
2 Correct 13 ms 1488 KB Output is correct
3 Correct 43 ms 2624 KB Output is correct
4 Correct 30 ms 3048 KB Output is correct
5 Correct 55 ms 5232 KB Output is correct
6 Correct 60 ms 5968 KB Output is correct
7 Correct 57 ms 6836 KB Output is correct
8 Correct 49 ms 7584 KB Output is correct
9 Correct 52 ms 8304 KB Output is correct
10 Correct 65 ms 9424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 9424 KB Output isn't correct
2 Halted 0 ms 0 KB -