제출 #134618

#제출 시각아이디문제언어결과실행 시간메모리
134618sealnot123이상적인 도시 (IOI12_city)C++14
0 / 100
1077 ms262148 KiB
#include<bits/stdc++.h> #define x first #define y second #define pb push_back #define eb emplace_back #define all(a) (a).begin(),(a).end() #define SZ(a) (int)(a).size() using namespace std; typedef long long LL; typedef pair<LL,LL> PLL; typedef pair<int,int> PII; typedef double D; typedef long double LD; const int N = 100005; vector<int> compx, compy; int lastx[N], lasty[N]; int orderx[N], ordery[N]; vector<int> g[N]; LL ans; LL dp[N], sz[N]; int n; int *XX, *YY; void add_edge(int a, int b){ g[a].pb(b); g[b].pb(a); } bool cmpx(int a, int b){ return XX[a] < XX[b]; } bool cmpy(int a, int b){ return YY[a] < YY[b]; } void dfs(int u, int v){ /*printf("%d\n",u);*/ for(int e : g[u]){ if(e == v) continue; dfs(e, u); ans += (dp[e]+sz[e])*sz[u] + dp[u]*sz[e]; dp[u] += dp[e] + sz[e]; sz[u] += sz[e]; } } int DistanceSum(int nn, int *X, int *Y) { n = nn; XX = X; YY = Y; int i,j,k,l,a,b,c,d; for(i=0;i<n;i++) compx.pb(X[i]), compy.pb(Y[i]); sort(all(compx)); sort(all(compy)); compx.erase(unique(all(compx)), compx.end()); compy.erase(unique(all(compy)), compy.end()); for(i=0;i<n;i++) orderx[i] = ordery[i] = i; sort(orderx,orderx+n,cmpx); sort(ordery,ordery+n,cmpy); memset(lastx, -1, sizeof lastx); memset(lasty, -1, sizeof lasty); for(i = 0; i < n; i++){ b = orderx[i]; /* printf("%d ",b);*/ c = lower_bound(all(compx), X[b]) - compx.begin(); a = lower_bound(all(compy), Y[b]) - compy.begin(); if(lasty[a] != -1) add_edge(lasty[a], c); lasty[a] = c; sz[b]++; } /* printf("\n");*/ dfs(0,0); for(i=0;i<n;i++) g[i].clear(); memset(dp, 0, sizeof dp); memset(sz, 0, sizeof sz); for(i = 0; i < n; i++){ b = ordery[i]; /* printf("%d ",b);*/ c = lower_bound(all(compy), Y[b]) - compy.begin(); a = lower_bound(all(compx), X[b]) - compx.begin(); if(lastx[a] != -1) add_edge(lastx[a], c); lastx[a] = c; sz[b]++; } /* printf("\n");*/ dfs(0,0); return ans; } /* 4 0 0 0 1 0 2 0 3 (10) 4 1 1 1 2 2 1 2 2 */

컴파일 시 표준 에러 (stderr) 메시지

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:53:8: warning: unused variable 'j' [-Wunused-variable]
  int i,j,k,l,a,b,c,d;
        ^
city.cpp:53:10: warning: unused variable 'k' [-Wunused-variable]
  int i,j,k,l,a,b,c,d;
          ^
city.cpp:53:12: warning: unused variable 'l' [-Wunused-variable]
  int i,j,k,l,a,b,c,d;
            ^
city.cpp:53:20: warning: unused variable 'd' [-Wunused-variable]
  int i,j,k,l,a,b,c,d;
                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...