Submission #163141

#TimeUsernameProblemLanguageResultExecution timeMemory
163141mhy908Ideal city (IOI12_city)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; const LL llinf=987654321987654321; const int inf=987654321; int a, tx, ty, tmp, t, x[100010], y[100010]; LL sum, mod=1e9, sz[100010]; vector<int> grid[100002], edge[100010]; struct data{ int num, s, e; }; vector<data> T[100010]; void dfs(int r, int par){ for(int k=0; k<edge[r].size(); k++){ if(par==edge[r][k])continue; dfs(edge[r][k], r); sz[r]+=sz[edge[r][k]]; } sum+=sz[r]*(LL)(a-sz[r]); } void func() { t=0; for(i=0; i<=a; i++)grid[i].clear(), T[i].clear(), edge[i].clear(); for(i=1; i<=a; i++)grid[x[i]].push_back(y[i]); for(i=0; grid[i].size(); i++)sort(grid[i].begin(), grid[i].end()); for(i=0; grid[i].size(); i++){ tmp=grid[i][0]; for(j=0; j<grid[i].size(); j++){ if(j==grid[i].size()-1||grid[i][j]+1!=grid[i][j+1]){ T[i].push_back({t++, tmp, grid[i][j]}); sz[t-1]=grid[i][j]-tmp+1; if(j!=grid[i].size()-1)tmp=grid[i][j+1]; } } } for(i=1; T[i].size(); i++){ int p=0, q=0; while(p<T[i-1].size()&&q<T[i].size()){ if(!(T[i-1][p].e<T[i][q].s||T[i][q].e<T[i-1][p].s)){ edge[T[i-1][p].num].push_back(T[i][q].num); edge[T[i][q].num].push_back(T[i-1][p].num); } if(T[i-1][p].e<T[i][q].e)p++; else q++; } } dfs(0, -1); } int DistanceSum(int N, int *X, int *Y) { a=N; tx=inf; ty=inf; for(i=1; i<=a; i++)x[i]=X[i-1], y[i]=Y[i-1]; for(i=1; i<=a; i++)tx=min(tx,x[i]), ty=min(ty,y[i]); for(i=1; i<=a; i++)x[i]-=tx, y[i]-=ty; func(); for(i=1; i<=a; i++)t=x[i], x[i]=y[i], y[i]=t; func(); return sum%mod; }

Compilation message (stderr)

city.cpp: In function 'void dfs(int, int)':
city.cpp:22:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int k=0; k<edge[r].size(); k++){
                  ~^~~~~~~~~~~~~~~
city.cpp: In function 'void func()':
city.cpp:32:9: error: 'i' was not declared in this scope
     for(i=0; i<=a; i++)grid[i].clear(), T[i].clear(), edge[i].clear();
         ^
city.cpp:33:9: error: 'i' was not declared in this scope
     for(i=1; i<=a; i++)grid[x[i]].push_back(y[i]);
         ^
city.cpp:34:9: error: 'i' was not declared in this scope
     for(i=0; grid[i].size(); i++)sort(grid[i].begin(), grid[i].end());
         ^
city.cpp:35:9: error: 'i' was not declared in this scope
     for(i=0; grid[i].size(); i++){
         ^
city.cpp:37:13: error: 'j' was not declared in this scope
         for(j=0; j<grid[i].size(); j++){
             ^
city.cpp:45:9: error: 'i' was not declared in this scope
     for(i=1; T[i].size(); i++){
         ^
city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:63:9: error: 'i' was not declared in this scope
     for(i=1; i<=a; i++)x[i]=X[i-1], y[i]=Y[i-1];
         ^
city.cpp:64:9: error: 'i' was not declared in this scope
     for(i=1; i<=a; i++)tx=min(tx,x[i]), ty=min(ty,y[i]);
         ^
city.cpp:65:9: error: 'i' was not declared in this scope
     for(i=1; i<=a; i++)x[i]-=tx, y[i]-=ty;
         ^
city.cpp:67:9: error: 'i' was not declared in this scope
     for(i=1; i<=a; i++)t=x[i], x[i]=y[i], y[i]=t;
         ^