#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;
}
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 {
set <pair <int, int>> vis, ok;
int x = 0, y = 0;
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.insert({x, y});
}
}
// cout << N << "sadfdsgf\n";
auto bfs = [&](int x, int y) {
int reach = 0;
queue <pair <int, int>> q;
q.push({x, y});
ok.insert({x, y});
vector <pair <int, int>> s;
while (q.size()) {
auto [x, y] = q.front();
s.push_back({x, y});
ok.insert({x, y});
q.pop();
for (int i = 0; i < 6; ++i) {
int u = x + dx[i];
int v = y + dy[i];
if (vis.find({u, v}) != vis.end()) continue;
if (ok.find({u, v}) != ok.end()) continue;
if (u < - delta || u > delta || v < - delta || v > delta) {
reach = 1;
continue;
}
ok.insert({u, v});
q.push({u, v});
}
}
if (reach) return;
// cout << s.size() << "sdgdsgffg\n";
// cout << s[0].first << ' ' << s[0].second << "vv\n";
for (auto [x, y]: s) vis.insert({x, y});
};
for (int i = - delta; i <= delta; ++i)
for (int j = - delta; j <= delta; ++j)
if (ok.find({i, j}) == ok.end()) bfs(i, j);
queue <pair <int, int>> q;
q.push({0, 0});
map <pair <int, int>, int> d;
d[{0, 0}] = 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.find({u, v}) == vis.end() || d.find({u, v}) != d.end()) continue;
d[{u, v}] = d[{x, y}] + 1;
q.push({u, v});
}
}
// cout << vis.size() << '\n';
int ans = 0;
for (auto [_, val]: d) ans = (ans + 1LL * B * val + A) % mod;
// cout << d.size() << '\n';
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
hexagon.cpp: In function 'int draw_territory(int, int, int, std::vector<int>, std::vector<int>)':
hexagon.cpp:49:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Vector>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int i = 1; i < P.size(); ++i) S += P[i - 1] * P[i];
| ~~^~~~~~~~~~
hexagon.cpp:58:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int i = 0; i < D.size(); ++i) {
| ~~^~~~~~~~~~
hexagon.cpp: In lambda function:
hexagon.cpp:75:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
75 | 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.insert({x, y});
| ^
hexagon.cpp: In function 'int draw_territory(int, int, int, std::vector<int>, std::vector<int>)':
hexagon.cpp:106:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
106 | auto [x, y] = q.front();
| ^
hexagon.cpp:118:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
118 | for (auto [_, val]: d) ans = (ans + 1LL * B * val + A) % mod;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
2103 ms |
301392 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Execution timed out |
2096 ms |
100732 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
6 ms |
1360 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
9 ms |
2168 KB |
Output is correct |
12 |
Correct |
9 ms |
2252 KB |
Output is correct |
13 |
Correct |
8 ms |
2212 KB |
Output is correct |
14 |
Correct |
9 ms |
2252 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
516 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
6 ms |
1452 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
9 ms |
2124 KB |
Output is correct |
14 |
Correct |
9 ms |
2240 KB |
Output is correct |
15 |
Correct |
10 ms |
2212 KB |
Output is correct |
16 |
Correct |
9 ms |
2256 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
13 ms |
3748 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
19 ms |
4168 KB |
Output is correct |
24 |
Correct |
28 ms |
7228 KB |
Output is correct |
25 |
Correct |
29 ms |
7356 KB |
Output is correct |
26 |
Correct |
15 ms |
3828 KB |
Output is correct |
27 |
Correct |
11 ms |
2380 KB |
Output is correct |
28 |
Correct |
7 ms |
2124 KB |
Output is correct |
29 |
Correct |
35 ms |
7620 KB |
Output is correct |
30 |
Correct |
32 ms |
7620 KB |
Output is correct |
31 |
Correct |
33 ms |
7616 KB |
Output is correct |
32 |
Correct |
35 ms |
7620 KB |
Output is correct |
33 |
Correct |
18 ms |
3996 KB |
Output is correct |
34 |
Correct |
9 ms |
2124 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Execution timed out |
2101 ms |
98092 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
2101 ms |
334868 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Execution timed out |
2104 ms |
325544 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |