답안 #61395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61395 2018-07-25T17:23:26 Z zetapi 이상적인 도시 (IOI12_city) C++14
컴파일 오류
0 ms 0 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<int,int>  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;
}*/#include <bits/stdc++.h>
using namespace std;

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

typedef pair<int,int>  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)
         ~~~~~^~~~~~~~~~~
city.cpp: At global scope:
city.cpp:92:10: error: redefinition of 'const long long int MAX'
 const ll MAX=1e6;
          ^~~
city.cpp:11:10: note: 'const long long int MAX' previously defined here
 const ll MAX=1e6;
          ^~~
city.cpp:93:10: error: redefinition of 'const long long int mod'
 const ll mod=1e9;
          ^~~
city.cpp:12:10: note: 'const long long int mod' previously defined here
 const ll mod=1e9;
          ^~~
city.cpp:95:13: error: redefinition of 'std::vector<std::pair<int, int> > vec'
 vector<pii> vec;
             ^~~
city.cpp:14:13: note: 'std::vector<std::pair<int, int> > vec' previously declared here
 vector<pii> vec;
             ^~~
city.cpp:97:11: error: redefinition of 'long long int pre [1000000]'
 ll pre[MAX];
           ^
city.cpp:16:4: note: 'long long int pre [1000000]' previously declared here
 ll pre[MAX];
    ^~~
city.cpp: In function 'long long int cal(std::vector<long long int>)':
city.cpp:99:4: error: redefinition of 'long long int cal(std::vector<long long int>)'
 ll cal(vector<ll> arr)
    ^~~
city.cpp:18:4: note: 'long long int cal(std::vector<long long int>)' previously defined here
 ll cal(vector<ll> arr)
    ^~~
city.cpp:102:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int A=1;A<arr.size();A++)
              ~^~~~~~~~~~~
city.cpp:104: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:114:5: error: redefinition of 'int DistanceSum(int, int*, int*)'
 int DistanceSum(int N, int *X, int *Y) 
     ^~~~~~~~~~~
city.cpp:33:5: note: 'int DistanceSum(int, int*, int*)' previously defined here
 int DistanceSum(int N, int *X, int *Y) 
     ^~~~~~~~~~~
city.cpp:123:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(cur<vec.size())
        ~~~^~~~~~~~~~~
city.cpp:126: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:140:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(cur<vec.size())
        ~~~^~~~~~~~~~~
city.cpp:143:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(cur+1<vec.size() and vec[cur+1].first==vec[cur].first)
         ~~~~~^~~~~~~~~~~