Submission #592865

#TimeUsernameProblemLanguageResultExecution timeMemory
592865skittles1412Ideal city (IOI12_city)C++17
32 / 100
1092 ms3448 KiB
#include "bits/extc++.h" using namespace std; template <typename T> void dbgh(const T& t) { cerr << t << endl; } template <typename T, typename... U> void dbgh(const T& t, const U&... u) { cerr << t << " | "; dbgh(u...); } #ifdef DEBUG #define dbg(...) \ cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \ dbgh(__VA_ARGS__); #else #define dbg(...) #define cerr \ if (false) \ cerr #endif #define endl "\n" #define long int64_t #define sz(x) int((x).size()) const long mod = 1e9; const int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1}; int bf(int n, int* arrx, int* arry) { map<pair<int, int>, int> m; for (int i = 0; i < n; i++) { m[{arrx[i], arry[i]}] = i; } vector<int> graph[n]; for (int i = 0; i < n; i++) { int x = arrx[i], y = arry[i]; for (int k = 0; k < 4; k++) { auto it = m.find({x + dx[k], y + dy[k]}); if (it != m.end()) { int u = it->second; graph[i].push_back(u); graph[u].push_back(i); } } } long ans = 0; for (int i = 0; i < n; i++) { int dist[n]; memset(dist, -1, sizeof(dist)); queue<int> q; auto push = [&](int u, int d) -> void { if (dist[u] == -1) { dist[u] = d; q.push(u); } }; push(i, 0); while (sz(q)) { int u = q.front(); q.pop(); for (auto& v : graph[u]) { push(v, dist[u] + 1); } } ans += accumulate(dist, dist + n, 0); } return ans / 2 % mod; } int DistanceSum(int n, int *arrx, int *arry) { if (n <= 2000) { return bf(n, arrx, arry); } }

Compilation message (stderr)

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