Submission #287233

#TimeUsernameProblemLanguageResultExecution timeMemory
287233stoyan_malininIdeal city (IOI12_city)C++14
23 / 100
98 ms6508 KiB
//#include "grader.cpp" #include <set> #include <map> #include <queue> #include <vector> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int mod = 1e9; struct Point { long long x, y; Point(){} Point(long long x, long long y) { this->x = x; this->y = y; } }; int n; vector <Point> v; void init() { int ind = 0; set <int> s; map <int, int> code; for(Point p: v) s.insert(p.x); for(int x: s) code[x] = ind, ind++; for(Point &p: v) p.x = code[p.x]; //----------------------- ind = 0; s.clear(); code.clear(); for(Point p: v) s.insert(p.y); for(int y: s) code[y] = ind, ind++; for(Point &p: v) p.y = code[p.y]; } namespace Subtask2 { const vector <pair <int, int>> jumps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; const int MAXN = 2005; bool exists[MAXN][MAXN]; int dist[MAXN][MAXN]; void bfs(Point p) { queue <Point> q; for(Point p: v) dist[p.x][p.y] = -1; q.push(p); dist[p.x][p.y] = 0; while(q.empty()==false) { p = q.front(); q.pop(); for(pair <int, int> j: jumps) { if(p.x+j.first>=0 && p.y+j.second>=0 && dist[p.x+j.first][p.y+j.second]==-1 && exists[p.x+j.first][p.y+j.second]==true) { q.push(Point(p.x+j.first, p.y+j.second)); dist[p.x+j.first][p.y+j.second] = dist[p.x][p.y] + 1; } } } } long long solve() { for(Point p: v) exists[p.x][p.y] = true; long long answer = 0; for(Point p: v) { bfs(p); for(Point other: v) answer = (answer + dist[other.x][other.y])%mod; } return answer; } }; namespace Subtask3 { long long solve() { long long answer = 0; sort(v.begin(), v.end(), [&](Point A, Point B) { if(A.x!=B.x) return A.x<B.x; return A.y<B.y; }); long long sum = 0; for(int i = 0;i<n;i++) { answer = (answer + (i*1LL*v[i].x - sum))%mod; sum += v[i].x; } sort(v.begin(), v.end(), [&](Point A, Point B) { if(A.y!=B.y) return A.y<B.y; return A.x<B.x; }); sum = 0; for(int i = 0;i<n;i++) { answer = (answer + (i*1LL*v[i].y - sum))%mod; sum += v[i].y; } return answer; } }; int DistanceSum(int N, int *X, int *Y) { n = N; for(int i = 0;i<n;i++) v.push_back(Point(X[i], Y[i])); init(); //if(n<=2*1000) return Subtask2::solve()/2; return Subtask3::solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...