제출 #109522

#제출 시각아이디문제언어결과실행 시간메모리
109522pamaj이상적인 도시 (IOI12_city)C++14
0 / 100
8 ms1024 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 10; typedef long long ll; ll prefx[maxn], prefy[maxn]; ll get_sum(int i, int j) { ll s = 0; s = prefx[j] + prefy[j] - prefx[i - 1] - prefy[i - 1]; return s; } int DistanceSum(int N, int *X, int *Y) { ll x[maxn]; ll y[maxn]; for(int i = 0; i < N; i++) { x[i] = X[i]; y[i] = Y[i]; } sort(x, x + N); sort(y, y + N); for(int i = 0; i < N; i++) { if(i == 0) prefx[i] = x[i], prefy[i] = y[i]; else prefx[i] = x[i] + prefx[i - 1], prefy[i] = y[i] + prefy[i - 1]; } ll sum = 0; for(int i = 0; i < N - 1; i++) { sum += get_sum(i + 1, N - 1) - (ll)(N - i - 1)*(x[i] + y[i]); } return sum; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...