Submission #124992

#TimeUsernameProblemLanguageResultExecution timeMemory
124992RockyBIdeal city (IOI12_city)C++17
0 / 100
51 ms3320 KiB
#include <bits/stdc++.h> #define f first #define s second using namespace std; const int mod = (int)1e9; int n; int ans; map < pair <int, int>, int> used, a; void dfs(int x, int y) { int len = 0; vector < pair <int, int > > go; int ptr = y - 1; while (a.count({x, ptr + 1})) { ++len, ++ptr; for (int i = -1; i <= 1; i += 2) { if (a.count({x + i, ptr}) && !used.count({x + i, ptr})) { go.push_back({x + i, ptr}); } } used[{x, ptr}] = 1; } ptr = y; while (a.count({x, ptr - 1})) { ++len, --ptr; for (int i = -1; i <= 1; i += 2) { if (a.count({x + i, ptr}) && !used.count({x + i, ptr})) { go.push_back({x + i, ptr}); } } used[{x, ptr}] = 1; } for (auto it : go) { if (!used.count(it)) { dfs(it.f, it.s); } } ans += len * 1ll * (n - len) % mod; ans %= mod; } void dfs1(int x, int y) { int len = 0; vector < pair <int, int > > go; int ptr = x - 1; while (a.count({ptr + 1, y})) { ++len, ++ptr; for (int i = -1; i <= 1; i += 2) { if (a.count({ptr, y + i}) && !used.count({ptr, y + i})) { go.push_back({ptr, y + i}); } } used[{ptr, y}] = 1; } ptr = x; while (a.count({ptr - 1, y})) { ++len, --ptr; for (int i = -1; i <= 1; i += 2) { if (a.count({ptr, y + i}) && !used.count({ptr, y + i})) { go.push_back({ptr, y + i}); } } used[{ptr, y}] = 1; } for (auto it : go) { if (!used.count(it)) { dfs1(it.f, it.s); } } ans += len * 1ll * (n - len) % mod; ans %= mod; } int DistanceSum(int N, int *X, int *Y) { n = N; // copy finished for (int i = 0; i < N; i++) { a[{X[i], Y[i]}] = 1; } dfs(X[0], Y[0]); used.clear(); dfs1(X[0], Y[0]); return ans / 2; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...