Submission #287229

#TimeUsernameProblemLanguageResultExecution timeMemory
287229stoyan_malininIdeal city (IOI12_city)C++14
32 / 100
1091 ms3064 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; } }; 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<=2000) return Subtask2::solve()/2; }

Compilation message (stderr)

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:107:1: warning: control reaches end of non-void function [-Wreturn-type]
  107 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...