답안 #155414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155414 2019-09-28T02:44:53 Z aer0park 이상적인 도시 (IOI12_city) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define f first
#define s second
 
using namespace std;
 
typedef int ll;
typedef pair<ll,ll> pi;
//간선 연결후 tree dp해보자  
ll x[100005],y[100005,]sz[100005],num[100005],cnt,anw,n;
const long long mod=1e9;
vector<ll> g[100005];
vector<pi> ar;
 
ll dfs(ll a,ll p)
{
	ll ret=sz[a];
	for(int i=0;i<g[a].size();i++)
		if(g[a][i]!=p)
			ret+=dfs(g[a][i],a);	
	anw=(anw+(long long)ret*(n-ret))%mod;
	return ret;
}
 
void add(ll a,ll b)
{
	g[a].push_back(b),g[b].push_back(a);
}
 
void calc()
{
	sort(ar.begin(),ar.end());  //점 0부터. 
	for(int i=0;i<=n;i++)
		g[i].clear(),sz[i]=0;
	cnt=0;
	num[0]=++cnt,sz[cnt]=1;
	for(int i=1;i<ar.size();i++)
	{
		if(ar[i-1].s+1==ar[i].s) num[i]=cnt;
		else num[i]=++cnt;
		sz[cnt]++;
	}
	ll j=0,i=0;
	while(ar[j].f!=ar[0].f) j++;
	for(int j=0;j<n;j++)
	{
		while(j<n&&ar[i].f+1!=ar[j].f)
		{
			if(ar[i].f>=ar[j].f) j++;
			else i++;
		}
		while(j<n&&ar[i].f+1==ar[j].f&&ar[i].s!=ar[j].s)
		{
			if(ar[i].s>ar[j].s) j++;
			else i++;
		}
		if(num[i]==num[j]) break;
		add(num[i],num[j]);
		ll ck=num[i],ck2=num[j];
		while(j+1<n&&num[i+1]==ck&&num[j+1]==ck2) i++,j++;
	}
	dfs(1,-1);
}
 
int DistanceSum (int N, int *X, int *Y)
{
	n=N;
	for(int i=n;i>=1;i++)
		x[i]=X[i-1],y[i]=Y[i-1];
	for(int i=1;i<=n;i++)
		ar.push_back({X[i],Y[i]});
	calc();
	for(int i=0;i<n;i++)
		swap(ar[i].f,ar[i].s);
	calc();
	return anw;
}

Compilation message

city.cpp:10:22: error: expected ']' before ',' token
 ll x[100005],y[100005,]sz[100005],num[100005],cnt,anw,n;
                      ^
city.cpp:10:23: error: expected unqualified-id before ']' token
 ll x[100005],y[100005,]sz[100005],num[100005],cnt,anw,n;
                       ^
city.cpp: In function 'll dfs(ll, ll)':
city.cpp:17:9: error: 'sz' was not declared in this scope
  ll ret=sz[a];
         ^~
city.cpp:17:9: note: suggested alternative: 's'
  ll ret=sz[a];
         ^~
         s
city.cpp:18:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[a].size();i++)
              ~^~~~~~~~~~~~
city.cpp:21:2: error: 'anw' was not declared in this scope
  anw=(anw+(long long)ret*(n-ret))%mod;
  ^~~
city.cpp:21:27: error: 'n' was not declared in this scope
  anw=(anw+(long long)ret*(n-ret))%mod;
                           ^
city.cpp: In function 'void calc()':
city.cpp:33:17: error: 'n' was not declared in this scope
  for(int i=0;i<=n;i++)
                 ^
city.cpp:34:16: error: 'sz' was not declared in this scope
   g[i].clear(),sz[i]=0;
                ^~
city.cpp:34:16: note: suggested alternative: 's'
   g[i].clear(),sz[i]=0;
                ^~
                s
city.cpp:35:2: error: 'cnt' was not declared in this scope
  cnt=0;
  ^~~
city.cpp:35:2: note: suggested alternative: 'int'
  cnt=0;
  ^~~
  int
city.cpp:36:2: error: 'num' was not declared in this scope
  num[0]=++cnt,sz[cnt]=1;
  ^~~
city.cpp:36:2: note: suggested alternative: 'enum'
  num[0]=++cnt,sz[cnt]=1;
  ^~~
  enum
city.cpp:36:15: error: 'sz' was not declared in this scope
  num[0]=++cnt,sz[cnt]=1;
               ^~
city.cpp:36:15: note: suggested alternative: 's'
  num[0]=++cnt,sz[cnt]=1;
               ^~
               s
city.cpp:37:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1;i<ar.size();i++)
              ~^~~~~~~~~~
city.cpp:45:16: error: 'n' was not declared in this scope
  for(int j=0;j<n;j++)
                ^
city.cpp:60:40: error: 'ck2' was not declared in this scope
   while(j+1<n&&num[i+1]==ck&&num[j+1]==ck2) i++,j++;
                                        ^~~
city.cpp:60:40: note: suggested alternative: 'ck'
   while(j+1<n&&num[i+1]==ck&&num[j+1]==ck2) i++,j++;
                                        ^~~
                                        ck
city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:67:2: error: 'n' was not declared in this scope
  n=N;
  ^
city.cpp:69:15: error: 'y' was not declared in this scope
   x[i]=X[i-1],y[i]=Y[i-1];
               ^
city.cpp:76:9: error: 'anw' was not declared in this scope
  return anw;
         ^~~