Submission #569662

#TimeUsernameProblemLanguageResultExecution timeMemory
569662hoanghq2004Hexagonal Territory (APIO21_hexagon)C++14
41 / 100
737 ms191140 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include "hexagon.h" using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; const int mod = 1e9 + 7; const int N = 2e5 + 10; struct Vector { long long x, y; Vector operator - (const Vector& other) const { return {x - other.x, y - other.y}; } long long operator * (const Vector& other) const { return x * other.y - y * other.x; } } P[N]; int dx[6] = {0, 1, 1, 0, -1, -1}; int dy[6] = {1, 1, 0, -1, -1, 0}; int power(int a, int n) { int ans = 1; for (; n; n >>= 1, a = 1LL * a * a % mod) if (n & 1) ans = 1LL * ans * a % mod; return ans; } const int M = 4010; int vis[M][M]; int ok[M][M], d[M][M]; int draw_territory(int N, int A, int B, vector<int> D, vector<int> L) { if (B == 0) { vector <Vector> P = {{0, 0}}; long long x = 0, y = 0, b = 0; for (int i = 0; i < N; ++i) { --D[i]; x += L[i] * dx[D[i]]; y += L[i] * dy[D[i]]; b = (b + L[i]) % mod; P.push_back({x, y}); } long long S = 0; for (int i = 1; i < P.size(); ++i) S += P[i - 1] * P[i]; S = abs(S); S %= mod; long long i = ((1LL * (S - b + 2 + mod) * power(2, mod - 2)) + b) % mod; return i * A % mod; } else { int x = 2005, y = 2005; int delta = 0; for (int i = 0; i < D.size(); ++i) { --D[i]; delta += L[i]; for (int j = 0; j < L[i]; ++j) { x += dx[D[i]]; y += dy[D[i]]; vis[x][y] = 1; } } auto bfs = [&](int x, int y) { int reach = 0; queue <pair <int, int>> q; q.push({x, y}); ok[x][y] = 1; vector <pair <int, int>> s; while (q.size()) { auto [x, y] = q.front(); s.push_back({x, y}); ok[x][y] = 1; q.pop(); for (int i = 0; i < 6; ++i) { int u = x + dx[i]; int v = y + dy[i]; if (u < 0 || u >= M || v < 0 || v >= M) { reach = 1; continue; } if (vis[u][v] || ok[u][v]) continue; ok[u][v] = 1; q.push({u, v}); } } if (reach) return; for (auto [x, y]: s) vis[x][y] = 1; }; for (int i = 0; i < M; ++i) for (int j = 0; j < M; ++j) if (vis[i][j] == 0 && ok[i][j] == 0) bfs(i, j); queue <pair <int, int>> q; q.push({x, y}); memset(d, -1, sizeof(d)); d[x][y] = 0; while (q.size()) { auto [x, y] = q.front(); q.pop(); for (int i = 0; i < 6; ++i) { int u = x + dx[i]; int v = y + dy[i]; if (vis[u][v] == 0 || d[u][v] != -1) continue; d[u][v] = d[x][y] + 1; q.push({u, v}); } } int ans = 0; for (int i = 0; i < M; ++i) for (int j = 0; j < M; ++j) if (d[i][j] != -1) ans = (ans + 1LL * B * d[i][j] + A) % mod; return ans; } } // //int main() { // int N, A, B; // assert(3 == scanf("%d %d %d", &N, &A, &B)); // std::vector<int> D(N), L(N); // for (int i = 0; i < N; ++i) { // assert(2 == scanf("%d %d", &D[i], &L[i])); // } // // int result = draw_territory(N, A, B, D, L); // printf("%d\n", result); // return 0; //} // //

Compilation message (stderr)

hexagon.cpp: In function 'int draw_territory(int, int, int, std::vector<int>, std::vector<int>)':
hexagon.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Vector>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int i = 1; i < P.size(); ++i) S += P[i - 1] * P[i];
      |                         ~~^~~~~~~~~~
hexagon.cpp:62:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for (int i = 0; i < D.size(); ++i) {
      |                         ~~^~~~~~~~~~
hexagon.cpp: In lambda function:
hexagon.cpp:78:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   78 |                 auto [x, y] = q.front();
      |                      ^
hexagon.cpp:95:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   95 |             for (auto [x, y]: s) vis[x][y] = 1;
      |                       ^
hexagon.cpp: In function 'int draw_territory(int, int, int, std::vector<int>, std::vector<int>)':
hexagon.cpp:105:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  105 |             auto [x, y] = q.front();
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...